From a5d87edeca03d3e63c1c15308bdc0e078dddf1ff Mon Sep 17 00:00:00 2001 From: dumbmoron Date: Wed, 10 Jul 2024 16:14:54 +0000 Subject: [PATCH] version.json: correct parsing for https clones --- web/src/routes/version.json/+server.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/web/src/routes/version.json/+server.ts b/web/src/routes/version.json/+server.ts index 3fa01ca5..b13626ee 100644 --- a/web/src/routes/version.json/+server.ts +++ b/web/src/routes/version.json/+server.ts @@ -38,11 +38,18 @@ export async function GET() { ?.replace(/^ref: refs\/heads\//, '') ?.trim(); - const remote = (await readGit('.git/config')) + let remote = (await readGit('.git/config')) ?.split('\n') ?.find(line => line.includes('url = ') && line.endsWith('.git')) - ?.split(':')[1] - ?.replace(/\.git$/, ''); + ?.split('url = ')[1]; + + if (remote?.startsWith('git@')) { + remote = remote.split(':')[1]; + } else if (remote?.startsWith('http')) { + remote = new URL(remote).pathname.substring(1); + } + + remote = remote?.replace(/\.git$/, ''); const { version } = JSON.parse( await readFile(join(pack, 'package.json'), 'utf8')