25 lines
783 B
TypeScript
25 lines
783 B
TypeScript
import getApiDynamic from "./api/getdb.dyn.js";
|
|
import getSqliteDynamic from "./sqlite/getdb.dyn.js";
|
|
import type { GetDbDynamic, GetDbStatic } from "./types/GetDb.js";
|
|
|
|
const dynamicSources: GetDbDynamic[] = [getSqliteDynamic, getApiDynamic];
|
|
export async function getDbSources(url: string): Promise<GetDbStatic[]> {
|
|
const urlObj = new URL(url);
|
|
const dbSources: GetDbStatic[] = [];
|
|
const promises: Promise<void>[] = [];
|
|
for (const source of dynamicSources) {
|
|
if (source.protocols.includes(urlObj.protocol)) {
|
|
promises.push(
|
|
source
|
|
.getSource(url)
|
|
.catch(() => null)
|
|
.then((dbSource) => {
|
|
if (dbSource) dbSources.push(dbSource);
|
|
})
|
|
);
|
|
}
|
|
}
|
|
await Promise.all(promises);
|
|
return dbSources;
|
|
}
|