docs/ext/extensionRepos.data.ts
740 lines · 22327 bytes
1import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'
2import { dirname, join } from 'node:path'
3import { fileURLToPath } from 'node:url'
4
5const IGNORED_DIRS = new Set(['node_modules', '.vitepress', '.git'])
6
7export type Rating = 'safe' | 'suggestive' | 'nsfw'
8
9export interface RepoSite {
10 name: string
11 lang: string
12 icon: string
13 url: string
14 rating: Rating
15 contentType?: string
16 streamType?: string
17 quality?: string
18 isBroken?: boolean
19 installUrl?: string
20}
21
22export interface RepoData {
23 sites: RepoSite[]
24 suwatteV6?: boolean
25 suwatteListUrl?: string
26}
27
28interface MihonSource {
29 name: string
30 lang: string
31 baseUrl: string
32}
33
34interface MihonExtension {
35 pkg: string
36 nsfw?: number
37 sources?: MihonSource[]
38}
39
40interface AidokuSource {
41 name: string
42 iconURL: string
43 languages?: string[]
44 contentRating?: number
45 baseURL: string
46}
47
48interface AidokuIndex {
49 sources: AidokuSource[]
50}
51
52interface AidokuLegacySource {
53 name: string
54 icon: string
55 lang: string
56 nsfw?: number
57}
58
59interface PaperbackSource {
60 id: string
61 name: string
62 icon: string
63 language?: string
64 contentRating?: string
65 websiteBaseURL?: string
66}
67
68interface PaperbackIndex {
69 sources: PaperbackSource[]
70 builtWith?: { toolchain?: string }
71}
72
73interface CloudstreamRepo {
74 pluginLists: string[]
75}
76
77interface CloudstreamPlugin {
78 name: string
79 iconUrl?: string
80 language?: string
81}
82
83interface HayaseExtension {
84 name: string
85 icon?: string
86 languages?: string[]
87}
88
89interface LegadoBookSource {
90 bookSourceName: string
91 bookSourceUrl: string
92 bookSourceGroup?: string
93}
94
95interface LNReaderPlugin {
96 name: string
97 lang: string
98 url: string
99 iconUrl?: string
100}
101
102interface MangayomiSource {
103 name: string
104 lang: string
105 baseUrl: string
106 iconUrl?: string
107 isNsfw?: boolean
108}
109
110interface IReaderSource {
111 pkg: string
112 apk: string
113 name: string
114 lang: string
115 nsfw?: boolean
116}
117
118interface SuwatteCatalogSource {
119 name: string
120 website?: string
121 languages?: string[]
122 thumbnail?: string
123 path?: string
124}
125
126interface SuwatteCatalogIndex {
127 listUrl?: string
128 catalogVersion?: number
129 sources: SuwatteCatalogSource[]
130}
131
132// For kotatsu
133interface KotatsuSite {
134 name: string
135 lang: string
136 url: string
137 icon: string
138 contentType: string
139 isBroken: boolean
140}
141
142interface KotatsuIndex {
143 sites: KotatsuSite[]
144}
145
146interface SoraRepoIndexEntry {
147 slug: string
148 name: string
149 source: string
150 path?: string
151 totalSources?: number
152 error?: string
153}
154
155interface SoraRepoIndex {
156 repos: SoraRepoIndexEntry[]
157}
158
159interface SoraModule {
160 sourceName: string
161 iconUrl?: string
162 iconURL?: string
163 language?: string
164 baseUrl?: string
165 scriptUrl?: string
166 scriptURL?: string
167 wotaku_sourceName?: string
168 wotaku_language?: string[]
169 wotaku_type?: string[]
170 wotaku_streamType?: string[]
171 wotaku_quality?: string[]
172}
173
174export interface SoraAuthorRepo {
175 label: string
176 repoUrl?: string
177 indexUrl: string
178}
179
180interface EchoExtension {
181 id: string
182 type: string
183 name: string
184 subtitle?: string
185 iconUrl?: string
186 updateUrl: string
187}
188
189export interface EchoAuthorRepo {
190 label: string
191 repoUrl?: string
192 indexUrl: string
193}
194
195const EXT_DIR = dirname(fileURLToPath(import.meta.url))
196const DOCS_DIR = join(EXT_DIR, '..')
197const CACHE_DIR = join(EXT_DIR, '../.vitepress/cache/extension-repos')
198const CACHE_TTL_MS = 6 * 60 * 60 * 1000
199
200function findMarkdownFiles(dir: string): string[] {
201 const files: string[] = []
202 for (const entry of readdirSync(dir, { withFileTypes: true })) {
203 if (entry.isDirectory()) {
204 if (!IGNORED_DIRS.has(entry.name)) files.push(...findMarkdownFiles(join(dir, entry.name)))
205 } else if (entry.name.endsWith('.md')) {
206 files.push(join(dir, entry.name))
207 }
208 }
209 return files
210}
211
212function collectIndexUrls(): string[] {
213 const urls = new Set<string>()
214 const blockRe = /:::\s*extrepo[^\n]*\n([\s\S]*?)\n\s*:::/g
215 const rowRe = /^\s*-\s*(?:raw|manga|anime|novel)\s*:\s*(https?:\/\/\S+)\s*$/gim
216
217 for (const file of findMarkdownFiles(DOCS_DIR)) {
218 const src = readFileSync(file, 'utf-8')
219
220 let block: RegExpExecArray | null
221 blockRe.lastIndex = 0
222 while ((block = blockRe.exec(src))) {
223 rowRe.lastIndex = 0
224 let row: RegExpExecArray | null
225 while ((row = rowRe.exec(block[1]))) urls.add(row[1].trim())
226 }
227 }
228 return [...urls]
229}
230
231function cachePathFor(url: string): string {
232 return join(CACHE_DIR, `${Buffer.from(url).toString('base64url')}.json`)
233}
234
235async function fetchIndex(url: string): Promise<unknown> {
236 const cachePath = cachePathFor(url)
237 if (existsSync(cachePath) && Date.now() - statSync(cachePath).mtimeMs < CACHE_TTL_MS) {
238 return JSON.parse(readFileSync(cachePath, 'utf-8'))
239 }
240
241 try {
242 const res = await fetch(url)
243 if (!res.ok) throw new Error(`${res.status} ${res.statusText}`)
244 const json = await res.json()
245 mkdirSync(CACHE_DIR, { recursive: true })
246 writeFileSync(cachePath, JSON.stringify(json))
247 return json
248 } catch (err) {
249 if (existsSync(cachePath)) return JSON.parse(readFileSync(cachePath, 'utf-8'))
250 console.warn(`[extrepo] failed to fetch ${url}: ${(err as Error).message}`)
251 return []
252 }
253}
254
255function ratingFromLevel(level: number): Rating {
256 if (level >= 2) return 'nsfw'
257 if (level >= 1) return 'suggestive'
258 return 'safe'
259}
260
261const LANG_ALIASES: Record<string, string> = {
262 jp: 'ja',
263 english: 'en',
264 'bahasa indonesia': 'id',
265 español: 'es',
266 français: 'fr',
267 polski: 'pl',
268 português: 'pt',
269 'tiếng việt': 'vi',
270 türkçe: 'tr',
271 русский: 'ru',
272 українська: 'uk',
273 ไทย: 'th',
274 العربية: 'ar',
275 chinese: 'zh',
276 japanese: 'ja',
277 korean: 'ko',
278 french: 'fr',
279 german: 'de',
280 greek: 'el',
281 indonesian: 'id',
282 italian: 'it',
283 spanish: 'es',
284 turkish: 'tr',
285 polish: 'pl',
286 russian: 'ru',
287 portuguese: 'pt',
288 arabic: 'ar',
289 tamil: 'ta',
290 ukrainian: 'uk',
291 vietnamese: 'vi',
292 thai: 'th',
293 hindi: 'hi',
294 malay: 'ms',
295 serbian: 'sr'
296}
297
298const LANG_SUBSTRING_ALIASES: [RegExp, string][] = [
299 [/日语原版/, 'ja'],
300 [/中文|汉语|漢語|轻小说/, 'zh'],
301 [/日本語/, 'ja'],
302 [/한국어|조선말/, 'ko']
303]
304
305function normalizeLang(lang: string): string {
306 // Strip bidi control marks (e.g. U+200E/U+200F) some indices prepend to lang names.
307 const cleaned = lang.replace(/[]/g, '').trim()
308 if (cleaned === '') return 'all'
309 const exact = LANG_ALIASES[cleaned.toLowerCase()]
310 if (exact) return exact
311 for (const [re, code] of LANG_SUBSTRING_ALIASES) {
312 if (re.test(cleaned)) return code
313 }
314 const key = cleaned.toLowerCase()
315 return key === 'multi' ? 'all' : key
316}
317
318function toRepoDataMihon(iconBase: string, extensions: MihonExtension[]): RepoSite[] {
319 const seen = new Set<string>()
320 const sites: RepoSite[] = []
321
322 for (const ext of extensions) {
323 const icon = `${iconBase}/icon/${ext.pkg}.png`
324 for (const source of ext.sources ?? []) {
325 const key = `${source.name}::${source.lang}::${source.baseUrl}`
326 if (seen.has(key)) continue
327 seen.add(key)
328 sites.push({ name: source.name, lang: source.lang, icon, url: source.baseUrl, rating: ext.nsfw === 1 ? 'nsfw' : 'safe' })
329 }
330 }
331
332 return sites
333}
334
335function toRepoDataAidoku(iconBase: string, index: AidokuIndex): RepoSite[] {
336 const seen = new Set<string>()
337 const sites: RepoSite[] = []
338
339 for (const source of index.sources ?? []) {
340 const icon = `${iconBase}/${source.iconURL}`
341 const rating = ratingFromLevel(source.contentRating ?? 0)
342 const langs = source.languages?.length ? source.languages : ['all']
343 for (const rawLang of langs) {
344 const lang = normalizeLang(rawLang)
345 const key = `${source.name}::${lang}::${source.baseURL}`
346 if (seen.has(key)) continue
347 seen.add(key)
348 sites.push({ name: source.name, lang, icon, url: source.baseURL, rating })
349 }
350 }
351
352 return sites
353}
354
355function toRepoDataPaperback(iconBase: string, index: PaperbackIndex): RepoSite[] {
356 const seen = new Set<string>()
357 const sites: RepoSite[] = []
358 // Legacy 0.8.x toolchain builds serve icons under `<id>/includes/`
359 const iconDir = index.builtWith?.toolchain?.startsWith('0.8') ? 'includes' : 'static'
360
361 for (const source of index.sources ?? []) {
362 const lang = normalizeLang(source.language ?? 'all')
363 const key = `${source.id}::${lang}`
364 if (seen.has(key)) continue
365 seen.add(key)
366 const icon = `${iconBase}/${source.id}/${iconDir}/${source.icon}`
367 const rating: Rating = source.contentRating === 'ADULT' ? 'nsfw' : source.contentRating === 'MATURE' ? 'suggestive' : 'safe'
368 sites.push({ name: source.name, lang, icon, url: source.websiteBaseURL ?? '', rating })
369 }
370
371 return sites
372}
373
374function normalizeGoogleFaviconUrl(url: string): string {
375 return url.replace('%size%', '64')
376}
377
378async function toRepoDataCloudstream(repo: CloudstreamRepo): Promise<RepoSite[]> {
379 const seen = new Set<string>()
380 const sites: RepoSite[] = []
381
382 const lists = await Promise.all(repo.pluginLists.map(url => fetchIndex(url)))
383 for (const list of lists) {
384 if (!Array.isArray(list)) continue
385 for (const plugin of list as CloudstreamPlugin[]) {
386 if (seen.has(plugin.name)) continue
387 seen.add(plugin.name)
388 const lang = normalizeLang(plugin.language ?? 'all')
389 const icon = plugin.iconUrl ? normalizeGoogleFaviconUrl(plugin.iconUrl) : ''
390 sites.push({ name: plugin.name, lang, icon, url: '', rating: 'safe' })
391 }
392 }
393
394 return sites
395}
396
397function toRepoDataAidokuLegacy(iconBase: string, sources: AidokuLegacySource[]): RepoSite[] {
398 const seen = new Set<string>()
399 const sites: RepoSite[] = []
400
401 for (const source of sources) {
402 const lang = normalizeLang(source.lang)
403 const key = `${source.name}::${lang}`
404 if (seen.has(key)) continue
405 seen.add(key)
406 sites.push({ name: source.name, lang, icon: `${iconBase}/icons/${source.icon}`, url: '', rating: ratingFromLevel(source.nsfw ?? 0) })
407 }
408
409 return sites
410}
411
412function toRepoDataHayase(extensions: HayaseExtension[]): RepoSite[] {
413 const seen = new Set<string>()
414 const sites: RepoSite[] = []
415
416 for (const ext of extensions) {
417 const langs = ext.languages?.length ? ext.languages : ['all']
418 for (const rawLang of langs) {
419 const lang = normalizeLang(rawLang)
420 const key = `${ext.name}::${lang}`
421 if (seen.has(key)) continue
422 seen.add(key)
423 sites.push({ name: ext.name, lang, icon: ext.icon ?? '', url: '', rating: 'safe' })
424 }
425 }
426
427 return sites
428}
429
430function toRepoDataLegado(sources: LegadoBookSource[]): RepoSite[] {
431 const seen = new Set<string>()
432 const sites: RepoSite[] = []
433
434 for (const source of sources) {
435 const lang = normalizeLang(source.bookSourceGroup ?? 'all')
436 const key = `${source.bookSourceName}::${lang}`
437 if (seen.has(key)) continue
438 seen.add(key)
439 sites.push({ name: source.bookSourceName, lang, icon: '', url: source.bookSourceUrl, rating: 'safe' })
440 }
441
442 return sites
443}
444
445function toRepoDataMangayomi(sources: MangayomiSource[]): RepoSite[] {
446 const seen = new Set<string>()
447 const sites: RepoSite[] = []
448
449 for (const source of sources) {
450 const lang = normalizeLang(source.lang)
451 const key = `${source.name}::${lang}`
452 if (seen.has(key)) continue
453 seen.add(key)
454 sites.push({ name: source.name, lang, icon: source.iconUrl ?? '', url: source.baseUrl, rating: source.isNsfw ? 'nsfw' : 'safe' })
455 }
456
457 return sites
458}
459
460function toRepoDataIReader(sources: IReaderSource[]): RepoSite[] {
461 const seen = new Set<string>()
462 const sites: RepoSite[] = []
463
464 for (const source of sources) {
465 const lang = normalizeLang(source.lang)
466 const key = `${source.name}::${lang}`
467 if (seen.has(key)) continue
468 seen.add(key)
469 // No confirmed icon path convention in this repo's format — omit rather than guess wrong.
470 sites.push({ name: source.name, lang, icon: '', url: '', rating: source.nsfw ? 'nsfw' : 'safe' })
471 }
472
473 return sites
474}
475
476function toRepoDataSuwatte(iconBase: string, index: SuwatteCatalogIndex): { sites: RepoSite[]; listUrl: string } {
477 const seen = new Set<string>()
478 const sites: RepoSite[] = []
479
480 const listUrl = index.listUrl ?? iconBase
481 const isV6 = index.catalogVersion === undefined
482
483 for (const source of index.sources ?? []) {
484 const langs = source.languages?.length ? source.languages : ['all']
485 const icon = source.thumbnail
486 ? (/^https?:\/\//i.test(source.thumbnail) ? source.thumbnail : `${iconBase}/assets/${source.thumbnail}`)
487 : ''
488 const installUrl = source.path
489 ? (isV6
490 ? `suwatte://runner?url=${listUrl}&runner=${source.path}`
491 : `suwatte://AddSourceFromList?list=${listUrl}&source=${source.path}`)
492 : undefined
493 for (const rawLang of langs) {
494 const lang = normalizeLang(rawLang)
495 const key = `${source.name}::${lang}`
496 if (seen.has(key)) continue
497 seen.add(key)
498 sites.push({ name: source.name, lang, icon, url: source.website ?? '', rating: 'safe', installUrl })
499 }
500 }
501
502 return { sites, listUrl }
503}
504
505function toRepoDataKotatsu(index: KotatsuIndex): RepoSite[] {
506 const seen = new Set<string>()
507 const sites: RepoSite[] = []
508
509 for (const site of index.sites) {
510 const lang = normalizeLang(site.lang)
511 const key = `${site.name}::${lang}::${site.url}`
512 if (seen.has(key)) continue
513 seen.add(key)
514 const rating: Rating = site.contentType.includes('HENTAI') ? 'nsfw' : 'safe'
515 sites.push({ name: site.name, lang, icon: site.icon, url: site.url, rating, contentType: site.contentType, isBroken: site.isBroken || undefined })
516 }
517
518 return sites
519}
520
521function isSoraRepoIndex(json: unknown): json is SoraRepoIndex {
522 return !!json && typeof json === 'object' && Array.isArray((json as SoraRepoIndex).repos)
523}
524
525function normalizeSoraLang(language: string | undefined): string {
526 const stripped = (language ?? '').replace(/\s*\([^)]*\)\s*$/, '').trim()
527 if (stripped.toLowerCase().startsWith('multi')) return 'all'
528 return normalizeLang(stripped)
529}
530
531function toRepoDataSoraModules(modules: SoraModule[]): RepoSite[] {
532 const seen = new Set<string>()
533 const sites: RepoSite[] = []
534
535 for (const mod of modules) {
536 const name = mod.wotaku_sourceName ?? mod.sourceName
537 const langs = mod.wotaku_language?.length ? mod.wotaku_language : [mod.language]
538 const scriptUrl = mod.scriptUrl ?? mod.scriptURL
539 const installUrl = scriptUrl?.replace(/\.js$/i, '.json')
540 for (const rawLang of langs) {
541 const lang = normalizeSoraLang(rawLang)
542 const key = `${name}::${lang}::${installUrl ?? ''}`
543 if (seen.has(key)) continue
544 seen.add(key)
545 sites.push({
546 name,
547 lang,
548 icon: mod.iconUrl ?? mod.iconURL ?? '',
549 url: mod.baseUrl ?? '',
550 rating: 'safe',
551 contentType: mod.wotaku_type?.[0],
552 streamType: mod.wotaku_streamType?.[0],
553 quality: mod.wotaku_quality?.[0],
554 installUrl: installUrl ? `sora://module?url=${installUrl}` : undefined
555 })
556 }
557 }
558
559 sites.sort((a, b) => a.name.localeCompare(b.name))
560 return sites
561}
562
563async function loadSoraRepoIndex(indexUrl: string, index: SoraRepoIndex): Promise<{ sites: RepoSite[]; authorRepos: SoraAuthorRepo[]; sitesByAuthor: Record<string, RepoData> }> {
564 const seen = new Set<string>()
565 const sites: RepoSite[] = []
566 const authorRepos: SoraAuthorRepo[] = []
567 const sitesByAuthor: Record<string, RepoData> = {}
568
569 const entries = index.repos.filter(repo => repo.path && !repo.error)
570 const fileUrls = entries.map(repo => new URL(repo.path!, indexUrl).toString())
571 const moduleLists = await Promise.all(fileUrls.map(url => fetchIndex(url)))
572
573 entries.forEach((repo, i) => {
574 const modules = moduleLists[i]
575 const authorSites = Array.isArray(modules) ? toRepoDataSoraModules(modules as SoraModule[]) : []
576 const fileUrl = fileUrls[i]
577 sitesByAuthor[fileUrl] = { sites: authorSites }
578 authorRepos.push({ label: repo.name, repoUrl: repo.source?.replace(/\.git$/, ''), indexUrl: fileUrl })
579 for (const site of authorSites) {
580 const key = `${site.name}::${site.lang}::${site.installUrl ?? ''}`
581 if (seen.has(key)) continue
582 seen.add(key)
583 sites.push(site)
584 }
585 })
586
587 authorRepos.sort((a, b) => a.label.localeCompare(b.label))
588 sites.sort((a, b) => a.name.localeCompare(b.name))
589 return { sites, authorRepos, sitesByAuthor }
590}
591
592function isEchoExtensionList(json: unknown): json is EchoExtension[] {
593 if (!Array.isArray(json) || json.length === 0) return false
594 const first = json[0] as Record<string, unknown>
595 return typeof first.updateUrl === 'string' && typeof first.subtitle === 'string' && !('lang' in first) && !('baseUrl' in first)
596}
597
598function parseEchoRepo(updateUrl: string): { owner: string; repo: string } | undefined {
599 const match = updateUrl.match(/^https:\/\/api\.github\.com\/repos\/([^/]+)\/([^/]+)\/releases$/)
600 if (!match) return undefined
601 return { owner: match[1], repo: match[2] }
602}
603
604function toRepoDataEchoExtensions(extensions: EchoExtension[]): RepoSite[] {
605 const seen = new Set<string>()
606 const sites: RepoSite[] = []
607
608 for (const ext of extensions) {
609 const key = `${ext.id}::${ext.updateUrl}`
610 if (seen.has(key)) continue
611 seen.add(key)
612 const repo = parseEchoRepo(ext.updateUrl)
613 const repoUrl = repo ? `https://github.com/${repo.owner}/${repo.repo}` : undefined
614 sites.push({
615 name: ext.name,
616 lang: 'all',
617 icon: ext.iconUrl ?? '',
618 url: repoUrl ?? '',
619 rating: 'safe',
620 contentType: ext.type,
621 installUrl: repoUrl
622 })
623 }
624
625 sites.sort((a, b) => a.name.localeCompare(b.name))
626 return sites
627}
628
629function loadEchoExtensionList(indexUrl: string, extensions: EchoExtension[]): { sites: RepoSite[]; authorRepos: EchoAuthorRepo[]; sitesByAuthor: Record<string, RepoData> } {
630 const byAuthor = new Map<string, EchoExtension[]>()
631 for (const ext of extensions) {
632 const owner = parseEchoRepo(ext.updateUrl)?.owner ?? 'Unknown'
633 const bucket = byAuthor.get(owner)
634 if (bucket) bucket.push(ext)
635 else byAuthor.set(owner, [ext])
636 }
637
638 const authorRepos: EchoAuthorRepo[] = []
639 const sitesByAuthor: Record<string, RepoData> = {}
640 for (const [owner, exts] of byAuthor) {
641 const authorIndexUrl = `${indexUrl}#${owner}`
642 sitesByAuthor[authorIndexUrl] = { sites: toRepoDataEchoExtensions(exts) }
643 authorRepos.push({ label: owner, repoUrl: `https://github.com/${owner}`, indexUrl: authorIndexUrl })
644 }
645
646 authorRepos.sort((a, b) => a.label.localeCompare(b.label))
647 return { sites: toRepoDataEchoExtensions(extensions), authorRepos, sitesByAuthor }
648}
649
650function toRepoDataLNReader(plugins: LNReaderPlugin[]): RepoSite[] {
651 const seen = new Set<string>()
652 const sites: RepoSite[] = []
653
654 for (const plugin of plugins) {
655 const lang = normalizeLang(plugin.lang)
656 const key = `${plugin.name}::${lang}`
657 if (seen.has(key)) continue
658 seen.add(key)
659 sites.push({ name: plugin.name, lang, icon: plugin.iconUrl ?? '', url: plugin.url, rating: 'safe' })
660 }
661
662 return sites
663}
664
665async function toRepoData(indexUrl: string, json: unknown): Promise<RepoData> {
666 const iconBase = indexUrl.slice(0, indexUrl.lastIndexOf('/'))
667 let sites: RepoSite[]
668 let suwatteV6: boolean | undefined
669 let suwatteListUrl: string | undefined
670 if (Array.isArray(json)) {
671 const first = json[0] as Record<string, unknown> | undefined
672 if (first && 'bookSourceUrl' in first) {
673 sites = toRepoDataLegado(json as LegadoBookSource[])
674 } else if (first && 'manifestVersion' in first) {
675 sites = toRepoDataHayase(json as HayaseExtension[])
676 } else if (first && 'iconUrl' in first && 'site' in first) {
677 sites = toRepoDataLNReader(json as LNReaderPlugin[])
678 } else if (first && 'sources' in first) {
679 sites = toRepoDataMihon(iconBase, json as MihonExtension[])
680 } else if (first && 'pkg' in first && 'apk' in first) {
681 sites = toRepoDataIReader(json as IReaderSource[])
682 } else if (first && 'iconUrl' in first && 'baseUrl' in first) {
683 sites = toRepoDataMangayomi(json as MangayomiSource[])
684 } else {
685 sites = toRepoDataAidokuLegacy(iconBase, json as AidokuLegacySource[])
686 }
687 } else if (Array.isArray((json as CloudstreamRepo).pluginLists)) {
688 sites = await toRepoDataCloudstream(json as CloudstreamRepo)
689 } else if ((json as AidokuIndex).sources?.length && 'iconURL' in (json as AidokuIndex).sources[0]) {
690 sites = toRepoDataAidoku(iconBase, json as AidokuIndex)
691 } else if ((json as SuwatteCatalogIndex).sources?.length && 'thumbnail' in (json as SuwatteCatalogIndex).sources[0]) {
692 const result = toRepoDataSuwatte(iconBase, json as SuwatteCatalogIndex)
693 sites = result.sites
694 suwatteListUrl = result.listUrl
695 suwatteV6 = (json as SuwatteCatalogIndex).catalogVersion === undefined
696 } else if (Array.isArray((json as KotatsuIndex).sites)) {
697 sites = toRepoDataKotatsu(json as KotatsuIndex)
698 } else {
699 sites = toRepoDataPaperback(iconBase, json as PaperbackIndex)
700 }
701 sites.sort((a, b) => a.name.localeCompare(b.name))
702 return { sites, suwatteV6, suwatteListUrl }
703}
704
705export interface ExtensionRepoData {
706 sites: Record<string, RepoData>
707 soraAuthors: Record<string, SoraAuthorRepo[]>
708 echoAuthors: Record<string, EchoAuthorRepo[]>
709}
710
711export declare const data: ExtensionRepoData
712
713export default {
714 watch: ['../**/*.md'],
715 async load(): Promise<ExtensionRepoData> {
716 const urls = collectIndexUrls()
717 const sites: Record<string, RepoData> = {}
718 const soraAuthors: Record<string, SoraAuthorRepo[]> = {}
719 const echoAuthors: Record<string, EchoAuthorRepo[]> = {}
720 await Promise.all(urls.map(async url => {
721 const json = await fetchIndex(url)
722 if (isSoraRepoIndex(json)) {
723 const result = await loadSoraRepoIndex(url, json)
724 sites[url] = { sites: result.sites }
725 soraAuthors[url] = result.authorRepos
726 Object.assign(sites, result.sitesByAuthor)
727 return
728 }
729 if (isEchoExtensionList(json)) {
730 const result = loadEchoExtensionList(url, json)
731 sites[url] = { sites: result.sites }
732 echoAuthors[url] = result.authorRepos
733 Object.assign(sites, result.sitesByAuthor)
734 return
735 }
736 sites[url] = await toRepoData(url, json)
737 }))
738 return { sites, soraAuthors, echoAuthors }
739 }
740}