mirror of
https://codeberg.org/keyoxide/keyoxide-web.git
synced 2024-12-23 07:19:28 -07:00
Check for repo instead of domain
When checking if url is GitLab proof, check if it points to a gitlab_proof repo instad of the gitlab.com domain. This way self hosted instances could be added. Also go back to searching for user first and then for the repo since repo search is unreliable.
This commit is contained in:
parent
5df81166ed
commit
be2cf693b1
1 changed files with 22 additions and 8 deletions
|
@ -616,24 +616,38 @@ async function verifyProof(url, fingerprint) {
|
|||
}
|
||||
}
|
||||
// GitLab
|
||||
if (/^https:\/\/gitlab.com/.test(url)) {
|
||||
if (/\/gitlab_proof$/.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`;
|
||||
match = url.match(/https:\/\/(.*)\/(.*)\/gitlab_proof/);
|
||||
output.display = match[2];
|
||||
output.url = `https://${match[1]}/${match[2]}`;
|
||||
output.proofUrlFetch = `https://gitlab.com/api/v4/users?username=${match[2]}`;
|
||||
// output.proofUrlFetch = `https://gitlab.com/api/v4/projects?custom_attributes[search]=${match[2]}/gitlab_proof&custom_attributes[search_namespaces]=true`;
|
||||
try {
|
||||
response = await fetch(output.proofUrlFetch, {
|
||||
const opts = {
|
||||
headers: {
|
||||
Accept: 'application/json'
|
||||
},
|
||||
credentials: 'omit'
|
||||
});
|
||||
};
|
||||
// Get user
|
||||
response = await fetch(output.proofUrlFetch, opts);
|
||||
if (!response.ok) {
|
||||
throw new Error('Response failed: ' + response.status);
|
||||
}
|
||||
json = await response.json();
|
||||
let project = json.find(proj => proj.web_url === url);
|
||||
const user = json.find(user => user.username === match[2]);
|
||||
if (!user) {
|
||||
throw new Error('No user with username ' + match[2]);
|
||||
}
|
||||
// Get project
|
||||
output.proofUrlFetch = `https://gitlab.com/api/v4/users/${user.id}/projects`;
|
||||
response = await fetch(output.proofUrlFetch, opts);
|
||||
if (!response.ok) {
|
||||
throw new Error('Response failed: ' + response.status);
|
||||
}
|
||||
json = await response.json();
|
||||
const project = json.find(proj => proj.path === 'gitlab_proof');
|
||||
if (!project) {
|
||||
throw new Error('No project at ' + url);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue