| @@ -182,6 +182,36 @@ interface KotatsuIndex { |
| 182 | sites: KotatsuSite[] |
182 | sites: KotatsuSite[] |
| 183 | } |
183 | } |
| 184 | |
184 | |
| |
185 | interface SoraRepoIndexEntry { |
| |
186 | name: string |
| |
187 | source: string |
| |
188 | path?: string |
| |
189 | error?: string |
| |
190 | } |
| |
191 | |
| |
192 | interface SoraRepoIndex { |
| |
193 | repos: SoraRepoIndexEntry[] |
| |
194 | } |
| |
195 | |
| |
196 | interface SoraModule { |
| |
197 | sourceName: string |
| |
198 | iconUrl?: string |
| |
199 | iconURL?: string |
| |
200 | language?: string |
| |
201 | baseUrl?: string |
| |
202 | scriptUrl?: string |
| |
203 | scriptURL?: string |
| |
204 | wotaku_sourceName?: string |
| |
205 | wotaku_language?: string[] |
| |
206 | wotaku_type?: string[] |
| |
207 | } |
| |
208 | |
| |
209 | export interface SoraAuthorRepo { |
| |
210 | label: string |
| |
211 | repoUrl?: string |
| |
212 | indexUrl: string |
| |
213 | } |
| |
214 | |
| 185 | interface EchoExtension { |
215 | interface EchoExtension { |
| 186 | id: string |
216 | id: string |
| 187 | type: string |
217 | type: string |
| @@ -789,6 +819,98 @@ function loadEchoExtensionList( |
| 789 | } |
819 | } |
| 790 | } |
820 | } |
| 791 | |
821 | |
| |
822 | function isSoraRepoIndex(json: unknown): json is SoraRepoIndex { |
| |
823 | return !!json && typeof json === 'object' && |
| |
824 | Array.isArray((json as SoraRepoIndex).repos) |
| |
825 | } |
| |
826 | |
| |
827 | function normalizeSoraLang(language: string | undefined): string { |
| |
828 | const stripped = (language ?? '').replace(/\s*\([^)]*\)\s*$/, '').trim() |
| |
829 | if (stripped.toLowerCase().startsWith('multi')) return 'all' |
| |
830 | return normalizeLang(stripped) |
| |
831 | } |
| |
832 | |
| |
833 | function toRepoDataSoraModules(modules: SoraModule[]): RepoSite[] { |
| |
834 | const seen = new Set<string>() |
| |
835 | const sites: RepoSite[] = [] |
| |
836 | |
| |
837 | for (const mod of modules) { |
| |
838 | const name = mod.wotaku_sourceName ?? mod.sourceName |
| |
839 | const langs = mod.wotaku_language?.length |
| |
840 | ? mod.wotaku_language |
| |
841 | : [mod.language] |
| |
842 | const scriptUrl = mod.scriptUrl ?? mod.scriptURL |
| |
843 | const installUrl = scriptUrl?.replace(/\.js$/i, '.json') |
| |
844 | for (const rawLang of langs) { |
| |
845 | const lang = normalizeSoraLang(rawLang) |
| |
846 | const key = `${name}::${lang}::${installUrl ?? ''}` |
| |
847 | if (seen.has(key)) continue |
| |
848 | seen.add(key) |
| |
849 | sites.push({ |
| |
850 | name, |
| |
851 | lang, |
| |
852 | icon: mod.iconUrl ?? mod.iconURL ?? '', |
| |
853 | url: mod.baseUrl ?? '', |
| |
854 | rating: 'safe', |
| |
855 | contentType: mod.wotaku_type?.[0], |
| |
856 | installUrl: installUrl ? `sora://module?url=${installUrl}` : undefined |
| |
857 | }) |
| |
858 | } |
| |
859 | } |
| |
860 | |
| |
861 | return sortSites(sites) |
| |
862 | } |
| |
863 | |
| |
864 | async function loadSoraRepoIndex( |
| |
865 | indexUrl: string, |
| |
866 | index: SoraRepoIndex, |
| |
867 | fetchJson: FetchJson |
| |
868 | ): Promise<{ |
| |
869 | sites: RepoSite[] |
| |
870 | authorRepos: SoraAuthorRepo[] |
| |
871 | sitesByAuthor: Record<string, RepoData> |
| |
872 | }> { |
| |
873 | const seen = new Set<string>() |
| |
874 | const sites: RepoSite[] = [] |
| |
875 | const authorRepos: SoraAuthorRepo[] = [] |
| |
876 | const sitesByAuthor: Record<string, RepoData> = {} |
| |
877 | |
| |
878 | const entries = index.repos.filter(repo => repo.path && !repo.error) |
| |
879 | const fileUrls = entries.map(repo => new URL(repo.path!, indexUrl).toString()) |
| |
880 | const moduleLists = await mapLimit( |
| |
881 | fileUrls, |
| |
882 | FETCH_CONCURRENCY, |
| |
883 | url => fetchJson(url) |
| |
884 | ) |
| |
885 | |
| |
886 | entries.forEach((repo, i) => { |
| |
887 | const modules = moduleLists[i] |
| |
888 | const authorSites = Array.isArray(modules) |
| |
889 | ? toRepoDataSoraModules(modules as SoraModule[]) |
| |
890 | : [] |
| |
891 | const fileUrl = fileUrls[i] |
| |
892 | sitesByAuthor[fileUrl] = { sites: authorSites } |
| |
893 | authorRepos.push({ |
| |
894 | label: repo.name, |
| |
895 | repoUrl: repo.source?.replace(/\.git$/, ''), |
| |
896 | indexUrl: fileUrl |
| |
897 | }) |
| |
898 | for (const site of authorSites) { |
| |
899 | const key = `${site.name}::${site.lang}::${site.installUrl ?? ''}` |
| |
900 | if (seen.has(key)) continue |
| |
901 | seen.add(key) |
| |
902 | sites.push(site) |
| |
903 | } |
| |
904 | }) |
| |
905 | |
| |
906 | authorRepos.sort((a, b) => a.label.localeCompare(b.label)) |
| |
907 | return { |
| |
908 | sites: sortSites(sites), |
| |
909 | authorRepos, |
| |
910 | sitesByAuthor |
| |
911 | } |
| |
912 | } |
| |
913 | |
| 792 | function toRepoDataLNReader(plugins: LNReaderPlugin[]): RepoSite[] { |
914 | function toRepoDataLNReader(plugins: LNReaderPlugin[]): RepoSite[] { |
| 793 | const seen = new Set<string>() |
915 | const seen = new Set<string>() |
| 794 | const sites: RepoSite[] = [] |
916 | const sites: RepoSite[] = [] |
| @@ -934,6 +1056,7 @@ async function toRepoData( |
| 934 | |
1056 | |
| 935 | export interface ExtensionRepoData { |
1057 | export interface ExtensionRepoData { |
| 936 | sites: Record<string, RepoData> |
1058 | sites: Record<string, RepoData> |
| |
1059 | soraAuthors: Record<string, SoraAuthorRepo[]> |
| 937 | echoAuthors: Record<string, EchoAuthorRepo[]> |
1060 | echoAuthors: Record<string, EchoAuthorRepo[]> |
| 938 | repoLists: Record<string, RepoListEntry[]> |
1061 | repoLists: Record<string, RepoListEntry[]> |
| 939 | } |
1062 | } |
| @@ -945,6 +1068,7 @@ export async function assembleSchemeData( |
| 945 | ): Promise<ExtensionRepoData> { |
1068 | ): Promise<ExtensionRepoData> { |
| 946 | const listUrlSet = new Set(listUrls) |
1069 | const listUrlSet = new Set(listUrls) |
| 947 | const sites: Record<string, RepoData> = {} |
1070 | const sites: Record<string, RepoData> = {} |
| |
1071 | const soraAuthors: Record<string, SoraAuthorRepo[]> = {} |
| 948 | const echoAuthors: Record<string, EchoAuthorRepo[]> = {} |
1072 | const echoAuthors: Record<string, EchoAuthorRepo[]> = {} |
| 949 | const repoLists: Record<string, RepoListEntry[]> = {} |
1073 | const repoLists: Record<string, RepoListEntry[]> = {} |
| 950 | const pendingByAuthor: Record<string, RepoData> = {} |
1074 | const pendingByAuthor: Record<string, RepoData> = {} |
| @@ -1021,6 +1145,13 @@ export async function assembleSchemeData( |
| 1021 | const url = remaining[i] |
1145 | const url = remaining[i] |
| 1022 | const json = jsons[i] |
1146 | const json = jsons[i] |
| 1023 | if (json === undefined) continue |
1147 | if (json === undefined) continue |
| |
1148 | if (isSoraRepoIndex(json)) { |
| |
1149 | const result = await loadSoraRepoIndex(url, json, fetchJson) |
| |
1150 | sites[url] = { sites: result.sites } |
| |
1151 | soraAuthors[url] = result.authorRepos |
| |
1152 | Object.assign(pendingByAuthor, result.sitesByAuthor) |
| |
1153 | continue |
| |
1154 | } |
| 1024 | if (isEchoExtensionList(json)) { |
1155 | if (isEchoExtensionList(json)) { |
| 1025 | const result = loadEchoExtensionList(url, json) |
1156 | const result = loadEchoExtensionList(url, json) |
| 1026 | sites[url] = { sites: result.sites } |
1157 | sites[url] = { sites: result.sites } |
| @@ -1031,5 +1162,5 @@ export async function assembleSchemeData( |
| 1031 | sites[url] = await toRepoData(url, json, fetchJson) |
1162 | sites[url] = await toRepoData(url, json, fetchJson) |
| 1032 | } |
1163 | } |
| 1033 | Object.assign(sites, pendingByAuthor) |
1164 | Object.assign(sites, pendingByAuthor) |
| 1034 | return { sites, echoAuthors, repoLists } |
1165 | return { sites, soraAuthors, echoAuthors, repoLists } |
| 1035 | } |
1166 | } |