Commit a16a50444a
Unsigned
Layout: unified · split
docs/ext/extensionRepos.data.ts +30 −15
| @@ -183,6 +183,7 @@ interface EchoExtension { | ||
| 183 | 183 | name: string |
| 184 | 184 | subtitle?: string |
| 185 | 185 | iconUrl?: string |
| 186 | url?: string | |
| 186 | 187 | updateUrl: string |
| 187 | 188 | } |
| 188 | 189 | |
| @@ -595,10 +596,24 @@ function isEchoExtensionList(json: unknown): json is EchoExtension[] { | ||
| 595 | 596 | return typeof first.updateUrl === 'string' && typeof first.subtitle === 'string' && !('lang' in first) && !('baseUrl' in first) |
| 596 | 597 | } |
| 597 | 598 | |
| 598 | function 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] } | |
| 599 | function 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 | |
| 602 | 617 | } |
| 603 | 618 | |
| 604 | 619 | function toRepoDataEchoExtensions(extensions: EchoExtension[]): RepoSite[] { |
| @@ -610,15 +625,14 @@ function toRepoDataEchoExtensions(extensions: EchoExtension[]): RepoSite[] { | ||
| 610 | 625 | if (seen.has(key)) continue |
| 611 | 626 | seen.add(key) |
| 612 | 627 | const repo = parseEchoRepo(ext.updateUrl) |
| 613 | const repoUrl = repo ? `https://github.com/${repo.owner}/${repo.repo}` : undefined | |
| 614 | 628 | sites.push({ |
| 615 | 629 | name: ext.name, |
| 616 | 630 | lang: 'all', |
| 617 | 631 | icon: ext.iconUrl ?? '', |
| 618 | url: repoUrl ?? '', | |
| 632 | url: ext.url ?? repo?.repoUrl ?? '', | |
| 619 | 633 | rating: 'safe', |
| 620 | 634 | contentType: ext.type, |
| 621 | installUrl: repoUrl | |
| 635 | installUrl: repo?.repoUrl | |
| 622 | 636 | }) |
| 623 | 637 | } |
| 624 | 638 | |
| @@ -627,20 +641,21 @@ function toRepoDataEchoExtensions(extensions: EchoExtension[]): RepoSite[] { | ||
| 627 | 641 | } |
| 628 | 642 | |
| 629 | 643 | function 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[] }>() | |
| 631 | 645 | 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] }) | |
| 636 | 651 | } |
| 637 | 652 | |
| 638 | 653 | const authorRepos: EchoAuthorRepo[] = [] |
| 639 | 654 | 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}` | |
| 642 | 657 | 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 }) | |
| 644 | 659 | } |
| 645 | 660 | |
| 646 | 661 | authorRepos.sort((a, b) => a.label.localeCompare(b.label)) |