|
@@ -1,42 +1,48 @@ |
|
|
import * as KanjidicImpl from './sources/kanjidic'; |
|
|
|
|
|
import * as JMdictImpl from './sources/jmdict'; |
|
|
|
|
|
import * as JMnedictImpl from './sources/jmnedict'; |
|
|
|
|
|
import * as RadKFileImpl from './sources/radkfile'; |
|
|
|
|
|
import * as KRadFileImpl from './sources/kradfile'; |
|
|
|
|
|
|
|
|
|
|
|
const SUPPORTED_SOURCES = [ |
|
|
|
|
|
KanjidicImpl, |
|
|
|
|
|
JMdictImpl, |
|
|
|
|
|
JMnedictImpl, |
|
|
|
|
|
RadKFileImpl, |
|
|
|
|
|
KRadFileImpl, |
|
|
|
|
|
] as const; |
|
|
|
|
|
|
|
|
import * as SupportedSources from './sources'; |
|
|
|
|
|
import * as SupportedAdapters from './adapters'; |
|
|
|
|
|
|
|
|
|
|
|
export * as Sources from './sources'; |
|
|
|
|
|
export * as Adapters from './adapters'; |
|
|
|
|
|
export * from './streams'; |
|
|
|
|
|
|
|
|
export type CreateDownloaderParams = ( |
|
|
export type CreateDownloaderParams = ( |
|
|
KanjidicImpl.CreateDownloaderParams |
|
|
|
|
|
| JMdictImpl.CreateDownloaderParams |
|
|
|
|
|
| JMnedictImpl.CreateDownloaderParams |
|
|
|
|
|
| RadKFileImpl.CreateDownloaderParams |
|
|
|
|
|
| KRadFileImpl.CreateDownloaderParams |
|
|
|
|
|
|
|
|
SupportedSources.Kanjidic.CreateDownloaderParams |
|
|
|
|
|
| SupportedSources.JMdict.CreateDownloaderParams |
|
|
|
|
|
| SupportedSources.JMnedict.CreateDownloaderParams |
|
|
|
|
|
| SupportedSources.RadKFile.CreateDownloaderParams |
|
|
|
|
|
| SupportedSources.KRadFile.CreateDownloaderParams |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
export * as Kanjidic from './sources/kanjidic'; |
|
|
|
|
|
export * as JMdict from './sources/jmdict'; |
|
|
|
|
|
export * as JMnedict from './sources/jmnedict'; |
|
|
|
|
|
export * as RadKFile from './sources/radkfile'; |
|
|
|
|
|
export * as KRadFile from './sources/kradfile'; |
|
|
|
|
|
export * from './streams'; |
|
|
|
|
|
|
|
|
|
|
|
export const createDownloader = (params: CreateDownloaderParams) => { |
|
|
export const createDownloader = (params: CreateDownloaderParams) => { |
|
|
const { type: sourceType, ...etcParams } = params; |
|
|
const { type: sourceType, ...etcParams } = params; |
|
|
|
|
|
const theSupportedSources = Object.values(SupportedSources); |
|
|
|
|
|
|
|
|
const theSourceModule = SUPPORTED_SOURCES |
|
|
|
|
|
|
|
|
const theSourceModule = theSupportedSources |
|
|
.find((videoTypeModule) => videoTypeModule.SOURCE_ID === sourceType); |
|
|
.find((videoTypeModule) => videoTypeModule.SOURCE_ID === sourceType); |
|
|
|
|
|
|
|
|
if (!theSourceModule) { |
|
|
if (!theSourceModule) { |
|
|
const validSourceTypes = SUPPORTED_SOURCES.map((videoTypeModule) => videoTypeModule.SOURCE_ID).join(', '); |
|
|
|
|
|
|
|
|
const validSourceTypes = theSupportedSources.map((videoTypeModule) => videoTypeModule.SOURCE_ID).join(', '); |
|
|
throw new TypeError(`Invalid source type: "${sourceType}". Valid values are: ${validSourceTypes}`); |
|
|
throw new TypeError(`Invalid source type: "${sourceType}". Valid values are: ${validSourceTypes}`); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return theSourceModule.createDownloader(etcParams); |
|
|
return theSourceModule.createDownloader(etcParams); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export type CreateAdapterParams = ( |
|
|
|
|
|
SupportedAdapters.FileJsonl.CreateAdapterParams |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
export const createAdapter = (params: CreateAdapterParams) => { |
|
|
|
|
|
const { type: adapterType, ...etcParams } = params; |
|
|
|
|
|
const theSupportedAdapters = Object.values(SupportedAdapters); |
|
|
|
|
|
|
|
|
|
|
|
const theAdapterModule = theSupportedAdapters |
|
|
|
|
|
.find((adapterTypeModule) => adapterTypeModule.ADAPTER_ID === adapterType); |
|
|
|
|
|
|
|
|
|
|
|
if (!theAdapterModule) { |
|
|
|
|
|
const validAdapterTypes = theSupportedAdapters.map((adapterTypeModule) => adapterTypeModule.ADAPTER_ID).join(', '); |
|
|
|
|
|
throw new TypeError(`Invalid adapter type: "${adapterType}". Valid values are: ${validAdapterTypes}`); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return theAdapterModule.createAdapter(etcParams); |
|
|
|
|
|
}; |