mirror of
https://codeberg.org/keyoxide/keyoxide-web.git
synced 2024-12-22 23:09:29 -07:00
Add data to API output
This commit is contained in:
parent
a5b9eeea8e
commit
f3b513a5f5
2 changed files with 73 additions and 1 deletions
|
@ -134,6 +134,16 @@ const apiProfileSchema = {
|
||||||
verification: {
|
verification: {
|
||||||
type: "object"
|
type: "object"
|
||||||
},
|
},
|
||||||
|
summary: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
profileName: { type: "string" },
|
||||||
|
profileURL: { type: "string" },
|
||||||
|
serviceProviderName: { type: "string" },
|
||||||
|
isVerificationDone: { type: "boolean" },
|
||||||
|
isVerified: { type: "boolean" },
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -153,6 +163,12 @@ const apiProfileSchema = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
keyoxide: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
url: { type: "string" },
|
||||||
|
}
|
||||||
|
},
|
||||||
extra: {
|
extra: {
|
||||||
type: "object",
|
type: "object",
|
||||||
properties: {
|
properties: {
|
||||||
|
@ -163,7 +179,7 @@ const apiProfileSchema = {
|
||||||
type: "array"
|
type: "array"
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
required: ["keyData", "extra", "errors"],
|
required: ["keyData", "keyoxide", "extra", "errors"],
|
||||||
additionalProperties: false
|
additionalProperties: false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,6 +253,33 @@ const sanitize = (data) => {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const addSummaryToClaims = (data) => {
|
||||||
|
// To be removed when data is added by DOIP library
|
||||||
|
for (let userIndex = 0; userIndex < data.keyData.users.length; userIndex++) {
|
||||||
|
const user = data.keyData.users[userIndex]
|
||||||
|
|
||||||
|
for (let claimIndex = 0; claimIndex < user.claims.length; claimIndex++) {
|
||||||
|
const claim = user.claims[claimIndex]
|
||||||
|
|
||||||
|
const isVerificationDone = claim.status === "verified"
|
||||||
|
const isVerified = isVerificationDone ? claim.verification.result : false
|
||||||
|
const isAmbiguous = isVerified
|
||||||
|
? false
|
||||||
|
: claim.matches.length > 1 || claim.matches[0].match.isAmbiguous
|
||||||
|
|
||||||
|
data.keyData.users[userIndex].claims[claimIndex].summary = {
|
||||||
|
profileName: !isAmbiguous ? claim.matches[0].profile.display : claim.uri,
|
||||||
|
profileURL: !isAmbiguous ? claim.matches[0].profile.uri : "",
|
||||||
|
serviceProviderName: !isAmbiguous ? claim.matches[0].serviceprovider.name : "",
|
||||||
|
isVerificationDone: isVerificationDone,
|
||||||
|
isVerified: isVerified,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
router.get('/profile/fetch',
|
router.get('/profile/fetch',
|
||||||
check('query').exists(),
|
check('query').exists(),
|
||||||
check('protocol').optional().toLowerCase().isIn(["hkp", "wkd"]),
|
check('protocol').optional().toLowerCase().isIn(["hkp", "wkd"]),
|
||||||
|
@ -291,6 +334,9 @@ router.get('/profile/fetch',
|
||||||
data.extra = {}
|
data.extra = {}
|
||||||
data.errors = [error.message]
|
data.errors = [error.message]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add missing data
|
||||||
|
data = addSummaryToClaims(data)
|
||||||
|
|
||||||
let statusCode = 200
|
let statusCode = 200
|
||||||
if (data.errors.length > 0) {
|
if (data.errors.length > 0) {
|
||||||
|
@ -321,6 +367,9 @@ router.get('/profile/verify',
|
||||||
data.extra = {}
|
data.extra = {}
|
||||||
data.errors = [error.message]
|
data.errors = [error.message]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add missing data
|
||||||
|
data = addSummaryToClaims(data)
|
||||||
|
|
||||||
let statusCode = 200
|
let statusCode = 200
|
||||||
if (data.errors.length > 0) {
|
if (data.errors.length > 0) {
|
||||||
|
|
|
@ -41,9 +41,13 @@ const generateWKDProfile = async (id) => {
|
||||||
keyData.key.data = {}
|
keyData.key.data = {}
|
||||||
keyData = processKeyData(keyData)
|
keyData = processKeyData(keyData)
|
||||||
|
|
||||||
|
let keyoxideData = {}
|
||||||
|
keyoxideData.url = `https://${process.env.DOMAIN}/wkd/${id}`
|
||||||
|
|
||||||
return {
|
return {
|
||||||
key: key,
|
key: key,
|
||||||
keyData: keyData,
|
keyData: keyData,
|
||||||
|
keyoxide: keyoxideData,
|
||||||
extra: await computeExtraData(key, keyData),
|
extra: await computeExtraData(key, keyData),
|
||||||
errors: []
|
errors: []
|
||||||
}
|
}
|
||||||
|
@ -52,6 +56,7 @@ const generateWKDProfile = async (id) => {
|
||||||
return {
|
return {
|
||||||
key: {},
|
key: {},
|
||||||
keyData: {},
|
keyData: {},
|
||||||
|
keyoxide: {},
|
||||||
extra: {},
|
extra: {},
|
||||||
errors: [err.message]
|
errors: [err.message]
|
||||||
}
|
}
|
||||||
|
@ -68,9 +73,17 @@ const generateHKPProfile = async (id, keyserverDomain) => {
|
||||||
keyData.key.data = {}
|
keyData.key.data = {}
|
||||||
keyData = processKeyData(keyData)
|
keyData = processKeyData(keyData)
|
||||||
|
|
||||||
|
let keyoxideData = {}
|
||||||
|
if (!keyserverDomain || keyserverDomain === 'keys.openpgp.org') {
|
||||||
|
keyoxideData.url = `https://${process.env.DOMAIN}/hkp/${id}`
|
||||||
|
} else {
|
||||||
|
keyoxideData.url = `https://${process.env.DOMAIN}/hkp/${keyserverDomain}/${id}`
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
key: key,
|
key: key,
|
||||||
keyData: keyData,
|
keyData: keyData,
|
||||||
|
keyoxide: keyoxideData,
|
||||||
extra: await computeExtraData(key, keyData),
|
extra: await computeExtraData(key, keyData),
|
||||||
errors: []
|
errors: []
|
||||||
}
|
}
|
||||||
|
@ -79,6 +92,7 @@ const generateHKPProfile = async (id, keyserverDomain) => {
|
||||||
return {
|
return {
|
||||||
key: {},
|
key: {},
|
||||||
keyData: {},
|
keyData: {},
|
||||||
|
keyoxide: {},
|
||||||
extra: {},
|
extra: {},
|
||||||
errors: [err.message]
|
errors: [err.message]
|
||||||
}
|
}
|
||||||
|
@ -94,9 +108,12 @@ const generateSignatureProfile = async (signature) => {
|
||||||
keyData.key.data = {}
|
keyData.key.data = {}
|
||||||
keyData = processKeyData(keyData)
|
keyData = processKeyData(keyData)
|
||||||
|
|
||||||
|
let keyoxideData = {}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
key: key,
|
key: key,
|
||||||
keyData: keyData,
|
keyData: keyData,
|
||||||
|
keyoxide: keyoxideData,
|
||||||
extra: await computeExtraData(key, keyData),
|
extra: await computeExtraData(key, keyData),
|
||||||
errors: []
|
errors: []
|
||||||
}
|
}
|
||||||
|
@ -105,6 +122,7 @@ const generateSignatureProfile = async (signature) => {
|
||||||
return {
|
return {
|
||||||
key: {},
|
key: {},
|
||||||
keyData: {},
|
keyData: {},
|
||||||
|
keyoxide: {},
|
||||||
extra: {},
|
extra: {},
|
||||||
errors: [err.message]
|
errors: [err.message]
|
||||||
}
|
}
|
||||||
|
@ -121,9 +139,13 @@ const generateKeybaseProfile = async (username, fingerprint) => {
|
||||||
keyData.key.data = {}
|
keyData.key.data = {}
|
||||||
keyData = processKeyData(keyData)
|
keyData = processKeyData(keyData)
|
||||||
|
|
||||||
|
let keyoxideData = {}
|
||||||
|
keyoxideData.url = `https://${process.env.DOMAIN}/keybase/${username}/${fingerprint}`
|
||||||
|
|
||||||
return {
|
return {
|
||||||
key: key,
|
key: key,
|
||||||
keyData: keyData,
|
keyData: keyData,
|
||||||
|
keyoxide: keyoxideData,
|
||||||
extra: await computeExtraData(key, keyData),
|
extra: await computeExtraData(key, keyData),
|
||||||
errors: []
|
errors: []
|
||||||
}
|
}
|
||||||
|
@ -132,6 +154,7 @@ const generateKeybaseProfile = async (username, fingerprint) => {
|
||||||
return {
|
return {
|
||||||
key: {},
|
key: {},
|
||||||
keyData: {},
|
keyData: {},
|
||||||
|
keyoxide: {},
|
||||||
extra: {},
|
extra: {},
|
||||||
errors: [err.message]
|
errors: [err.message]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue