Commit a16a50444a

a16a50444a22e8c78ffeebe3adb23c145a9a0d52

parent: 4ec4a95091

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-07-24 06:27 UTC

Update extensionRepos.data.ts

Layout: unified · split

docs/ext/extensionRepos.data.ts +30 −15
@@ -183,6 +183,7 @@ interface EchoExtension {
183183 name: string
184184 subtitle?: string
185185 iconUrl?: string
186 url?: string
186187 updateUrl: string
187188}
188189
@@ -595,10 +596,24 @@ function isEchoExtensionList(json: unknown): json is EchoExtension[] {
595596 return typeof first.updateUrl === 'string' && typeof first.subtitle === 'string' && !('lang' in first) && !('baseUrl' in first)
596597}
597598
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] }
599function parseEchoRepo(updateUrl: string): { host: string; owner: string; repo: string; repoUrl: string; ownerUrl: string } | undefined {
600 const githubMatch = updateUrl.match(/^https:\/\/api\.github\.com\/repos\/([^/]+)\/([^/]+)\/releases$/)
601 if (githubMatch) {
602 const [, owner, repo] = githubMatch
603 return { host: 'github.com', owner, repo, repoUrl: `https://github.com/${owner}/${repo}`, ownerUrl: `https://github.com/${owner}` }
604 }
605
606 const gitlabMatch = updateUrl.match(/^https:\/\/(gitlab\.com)\/api\/v4\/projects\/([^/]+)\/releases\b/)
607 if (gitlabMatch) {
608 const [, host, encodedPath] = gitlabMatch
609 const path = decodeURIComponent(encodedPath)
610 const owner = path.slice(0, path.lastIndexOf('/'))
611 const repo = path.slice(path.lastIndexOf('/') + 1)
612 if (!owner || !repo) return undefined
613 return { host, owner, repo, repoUrl: `https://${host}/${path}`, ownerUrl: `https://${host}/${owner}` }
614 }
615
616 return undefined
602617}
603618
604619function toRepoDataEchoExtensions(extensions: EchoExtension[]): RepoSite[] {
@@ -610,15 +625,14 @@ function toRepoDataEchoExtensions(extensions: EchoExtension[]): RepoSite[] {
610625 if (seen.has(key)) continue
611626 seen.add(key)
612627 const repo = parseEchoRepo(ext.updateUrl)
613 const repoUrl = repo ? `https://github.com/${repo.owner}/${repo.repo}` : undefined
614628 sites.push({
615629 name: ext.name,
616630 lang: 'all',
617631 icon: ext.iconUrl ?? '',
618 url: repoUrl ?? '',
632 url: ext.url ?? repo?.repoUrl ?? '',
619633 rating: 'safe',
620634 contentType: ext.type,
621 installUrl: repoUrl
635 installUrl: repo?.repoUrl
622636 })
623637 }
624638
@@ -627,20 +641,21 @@ function toRepoDataEchoExtensions(extensions: EchoExtension[]): RepoSite[] {
627641}
628642
629643function loadEchoExtensionList(indexUrl: string, extensions: EchoExtension[]): { sites: RepoSite[]; authorRepos: EchoAuthorRepo[]; sitesByAuthor: Record<string, RepoData> } {
630 const byAuthor = new Map<string, EchoExtension[]>()
644 const byAuthor = new Map<string, { label: string; ownerUrl?: string; exts: EchoExtension[] }>()
631645 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])
646 const repo = parseEchoRepo(ext.updateUrl)
647 const key = repo ? `${repo.host}:${repo.owner}` : 'Unknown'
648 const bucket = byAuthor.get(key)
649 if (bucket) bucket.exts.push(ext)
650 else byAuthor.set(key, { label: repo?.owner ?? 'Unknown', ownerUrl: repo?.ownerUrl, exts: [ext] })
636651 }
637652
638653 const authorRepos: EchoAuthorRepo[] = []
639654 const sitesByAuthor: Record<string, RepoData> = {}
640 for (const [owner, exts] of byAuthor) {
641 const authorIndexUrl = `${indexUrl}#${owner}`
655 for (const [key, { label, ownerUrl, exts }] of byAuthor) {
656 const authorIndexUrl = `${indexUrl}#${key}`
642657 sitesByAuthor[authorIndexUrl] = { sites: toRepoDataEchoExtensions(exts) }
643 authorRepos.push({ label: owner, repoUrl: `https://github.com/${owner}`, indexUrl: authorIndexUrl })
658 authorRepos.push({ label, repoUrl: ownerUrl, indexUrl: authorIndexUrl })
644659 }
645660
646661 authorRepos.sort((a, b) => a.label.localeCompare(b.label))