Commit a16a50444a
Unsigned
Layout: unified · split
docs/ext/extensionRepos.data.ts +30 −15
| @@ -183,6 +183,7 @@ interface EchoExtension { | |||
| 183 | name: string | 183 | name: string |
| 184 | subtitle?: string | 184 | subtitle?: string |
| 185 | iconUrl?: string | 185 | iconUrl?: string |
| 186 | url?: string | ||
| 186 | updateUrl: string | 187 | updateUrl: string |
| 187 | } | 188 | } |
| 188 | 189 | ||
| @@ -595,10 +596,24 @@ function isEchoExtensionList(json: unknown): json is EchoExtension[] { | |||
| 595 | return typeof first.updateUrl === 'string' && typeof first.subtitle === 'string' && !('lang' in first) && !('baseUrl' in first) | 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 | function parseEchoRepo(updateUrl: string): { host: string; owner: string; repo: string; repoUrl: string; ownerUrl: string } | undefined { |
| 599 | const match = updateUrl.match(/^https:\/\/api\.github\.com\/repos\/([^/]+)\/([^/]+)\/releases$/) | 600 | const githubMatch = updateUrl.match(/^https:\/\/api\.github\.com\/repos\/([^/]+)\/([^/]+)\/releases$/) |
| 600 | if (!match) return undefined | 601 | if (githubMatch) { |
| 601 | return { owner: match[1], repo: match[2] } | 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 | function toRepoDataEchoExtensions(extensions: EchoExtension[]): RepoSite[] { | 619 | function toRepoDataEchoExtensions(extensions: EchoExtension[]): RepoSite[] { |
| @@ -610,15 +625,14 @@ function toRepoDataEchoExtensions(extensions: EchoExtension[]): RepoSite[] { | |||
| 610 | if (seen.has(key)) continue | 625 | if (seen.has(key)) continue |
| 611 | seen.add(key) | 626 | seen.add(key) |
| 612 | const repo = parseEchoRepo(ext.updateUrl) | 627 | const repo = parseEchoRepo(ext.updateUrl) |
| 613 | const repoUrl = repo ? `https://github.com/${repo.owner}/${repo.repo}` : undefined | ||
| 614 | sites.push({ | 628 | sites.push({ |
| 615 | name: ext.name, | 629 | name: ext.name, |
| 616 | lang: 'all', | 630 | lang: 'all', |
| 617 | icon: ext.iconUrl ?? '', | 631 | icon: ext.iconUrl ?? '', |
| 618 | url: repoUrl ?? '', | 632 | url: ext.url ?? repo?.repoUrl ?? '', |
| 619 | rating: 'safe', | 633 | rating: 'safe', |
| 620 | contentType: ext.type, | 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 | function loadEchoExtensionList(indexUrl: string, extensions: EchoExtension[]): { sites: RepoSite[]; authorRepos: EchoAuthorRepo[]; sitesByAuthor: Record<string, RepoData> } { | 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 | for (const ext of extensions) { | 645 | for (const ext of extensions) { |
| 632 | const owner = parseEchoRepo(ext.updateUrl)?.owner ?? 'Unknown' | 646 | const repo = parseEchoRepo(ext.updateUrl) |
| 633 | const bucket = byAuthor.get(owner) | 647 | const key = repo ? `${repo.host}:${repo.owner}` : 'Unknown' |
| 634 | if (bucket) bucket.push(ext) | 648 | const bucket = byAuthor.get(key) |
| 635 | else byAuthor.set(owner, [ext]) | 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 | const authorRepos: EchoAuthorRepo[] = [] | 653 | const authorRepos: EchoAuthorRepo[] = [] |
| 639 | const sitesByAuthor: Record<string, RepoData> = {} | 654 | const sitesByAuthor: Record<string, RepoData> = {} |
| 640 | for (const [owner, exts] of byAuthor) { | 655 | for (const [key, { label, ownerUrl, exts }] of byAuthor) { |
| 641 | const authorIndexUrl = `${indexUrl}#${owner}` | 656 | const authorIndexUrl = `${indexUrl}#${key}` |
| 642 | sitesByAuthor[authorIndexUrl] = { sites: toRepoDataEchoExtensions(exts) } | 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 | authorRepos.sort((a, b) => a.label.localeCompare(b.label)) | 661 | authorRepos.sort((a, b) => a.label.localeCompare(b.label)) |