feat: initial commit
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user