diff --git a/src/services/discord.service.ts b/src/services/discord.service.ts index 06af65b..9763410 100644 --- a/src/services/discord.service.ts +++ b/src/services/discord.service.ts @@ -233,49 +233,66 @@ export class DiscordService { content = content.replaceAll(/```.*```/gs, ''); - const shortMatches = content.matchAll(/(((?[\w\-.,_]*)\/)?(?[\w\-.,_]+))?#(?\d+)/g); - for (const match of shortMatches) { + const longMatches = content.matchAll( + /https:\/\/github\.com\/(?[\w\-.,]+)\/(?[\w\-.,]+)\/(?(pull|issue|discussion))\/(?\d+)/g, + ); + for (const match of longMatches) { if (!match || !match.groups) { continue; } - const { org, repo, num } = match.groups; + const { org, repo, category, num } = match.groups; const id = Number(num); if (Number.isNaN(id)) { continue; } - if (!org && !repo && id < 1000) { - continue; - } - - links.push({ org: org || GithubOrg.ImmichApp, repo: repo || GithubRepo.Immich, id }); + links.push({ + id, + org: org || GithubOrg.ImmichApp, + repo: repo || GithubRepo.Immich, + type: category as LinkType, + }); } - const longMatches = content.matchAll( - /https:\/\/github\.com\/(?[\w\-.,]+)\/(?[\w\-.,]+)\/(?(pull|issue|discussion))\/(?\d+)/g, - ); - for (const match of longMatches) { + const shortMatches = content.matchAll(/(((?[\w\-.,_]*)\/)?(?[\w\-.,_]+))?#(?\d+)/g); + for (const match of shortMatches) { if (!match || !match.groups) { continue; } - const { org, repo, category, num } = match.groups; + const { org, repo, num } = match.groups; const id = Number(num); if (Number.isNaN(id)) { continue; } + if (!org && !repo && id < 1000) { + continue; + } + links.push({ - id, org: org || GithubOrg.ImmichApp, repo: repo || GithubRepo.Immich, - type: category as LinkType, + id, }); } + const keys: Set = new Set(); + const requests: GithubLink[] = []; + + for (const { id, org, repo, type } of links) { + const key = id + org + repo; + if (keys.has(key)) { + continue; + } + + requests.push({ id, org, repo, type }); + keys.add(key); + } + const results = await Promise.all( - links.map(async ({ org, repo, id, type }) => { + requests.map(async ({ org, repo, id, type }) => { switch (type) { case 'issue': case 'pull':