From 5df81166edde5b70d7b651986899d60284543c70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Simi=C4=87?= Date: Tue, 18 Aug 2020 20:02:16 +0200 Subject: [PATCH] Implement first GitLab proof logic I've just hacked up a simple solution for GitLab proof. It's using a project (repository) as a proof method since it's the easiest to do with api. It's a very hacky solution and it relies on GitLab being able to find the project using search. --- static/scripts.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/static/scripts.js b/static/scripts.js index 95f2a12..7281794 100644 --- a/static/scripts.js +++ b/static/scripts.js @@ -615,6 +615,37 @@ async function verifyProof(url, fingerprint) { return output; } } + // GitLab + if (/^https:\/\/gitlab.com/.test(url)) { + output.type = "gitlab"; + match = url.match(/https:\/\/gitlab.com\/(.*)\/(.*)/); + output.display = match[1]; + output.url = `https://gitlab.com/${match[1]}`; + output.proofUrlFetch = `https://gitlab.com/api/v4/projects?custom_attributes[search]=${match[1]}/${match[2]}&custom_attributes[search_namespaces]=true`; + try { + response = await fetch(output.proofUrlFetch, { + headers: { + Accept: 'application/json' + }, + credentials: 'omit' + }); + if (!response.ok) { + throw new Error('Response failed: ' + response.status); + } + json = await response.json(); + let project = json.find(proj => proj.web_url === url); + if (!project) { + throw new Error('No project at ' + url); + } + reVerify = new RegExp(`[Verifying my OpenPGP key: openpgp4fpr:${fingerprint}]`, 'i'); + if (reVerify.test(project.descroption)) { + output.isVerified = true; + } + } catch (e) { + } finally { + return output; + } + } // Lobsters if (/^https:\/\/lobste.rs/.test(url)) { output.type = "lobsters";