mirror of
https://codeberg.org/keyoxide/doipjs.git
synced 2025-01-10 14:39:28 -07:00
Change serviceproviders to claimDefinitions
This commit is contained in:
parent
1bbf6511e4
commit
be0f660e85
18 changed files with 142 additions and 132 deletions
|
@ -17,10 +17,7 @@ const E = require('../enums')
|
|||
|
||||
const reURI = /^https:\/\/dev\.to\/(.*)\/(.*)\/?/
|
||||
|
||||
const processURI = (uri, opts) => {
|
||||
if (!opts) {
|
||||
opts = {}
|
||||
}
|
||||
const processURI = (uri) => {
|
||||
const match = uri.match(reURI)
|
||||
|
||||
return {
|
||||
|
@ -28,6 +25,10 @@ const processURI = (uri, opts) => {
|
|||
type: 'web',
|
||||
name: 'devto',
|
||||
},
|
||||
match: {
|
||||
regularExpression: reURI,
|
||||
isAmbiguous: false,
|
||||
},
|
||||
profile: {
|
||||
display: match[1],
|
||||
uri: `https://dev.to/${match[1]}`,
|
||||
|
@ -45,7 +46,6 @@ const processURI = (uri, opts) => {
|
|||
}
|
||||
},
|
||||
claim: {
|
||||
fingerprint: null,
|
||||
format: E.ClaimFormat.MESSAGE,
|
||||
relation: E.ClaimRelation.CONTAINS,
|
||||
path: ['body_markdown'],
|
|
@ -17,10 +17,7 @@ const E = require('../enums')
|
|||
|
||||
const reURI = /^https:\/\/(.*)\/u\/(.*)\/?/
|
||||
|
||||
const processURI = (uri, opts) => {
|
||||
if (!opts) {
|
||||
opts = {}
|
||||
}
|
||||
const processURI = (uri) => {
|
||||
const match = uri.match(reURI)
|
||||
|
||||
return {
|
||||
|
@ -28,6 +25,10 @@ const processURI = (uri, opts) => {
|
|||
type: 'web',
|
||||
name: 'discourse',
|
||||
},
|
||||
match: {
|
||||
regularExpression: reURI,
|
||||
isAmbiguous: true,
|
||||
},
|
||||
profile: {
|
||||
display: `${match[2]}@${match[1]}`,
|
||||
uri: uri,
|
||||
|
@ -45,7 +46,6 @@ const processURI = (uri, opts) => {
|
|||
}
|
||||
},
|
||||
claim: {
|
||||
fingerprint: null,
|
||||
format: E.ClaimFormat.MESSAGE,
|
||||
relation: E.ClaimRelation.CONTAINS,
|
||||
path: ['user', 'bio_raw'],
|
|
@ -17,10 +17,7 @@ const E = require('../enums')
|
|||
|
||||
const reURI = /^dns:([a-zA-Z0-9\.\-\_]*)(?:\?(.*))?/
|
||||
|
||||
const processURI = (uri, opts) => {
|
||||
if (!opts) {
|
||||
opts = {}
|
||||
}
|
||||
const processURI = (uri) => {
|
||||
const match = uri.match(reURI)
|
||||
|
||||
return {
|
||||
|
@ -28,6 +25,10 @@ const processURI = (uri, opts) => {
|
|||
type: 'web',
|
||||
name: 'dns',
|
||||
},
|
||||
match: {
|
||||
regularExpression: reURI,
|
||||
isAmbiguous: false,
|
||||
},
|
||||
profile: {
|
||||
display: match[1],
|
||||
uri: `https://${match[1]}`,
|
||||
|
@ -45,7 +46,6 @@ const processURI = (uri, opts) => {
|
|||
}
|
||||
},
|
||||
claim: {
|
||||
fingerprint: null,
|
||||
format: E.ClaimFormat.URI,
|
||||
relation: E.ClaimRelation.CONTAINS,
|
||||
path: ['records', 'txt'],
|
|
@ -17,10 +17,7 @@ const E = require('../enums')
|
|||
|
||||
const reURI = /^https:\/\/(.*)\/users\/(.*)\/?/
|
||||
|
||||
const processURI = (uri, opts) => {
|
||||
if (!opts) {
|
||||
opts = {}
|
||||
}
|
||||
const processURI = (uri) => {
|
||||
const match = uri.match(reURI)
|
||||
|
||||
return {
|
||||
|
@ -28,6 +25,10 @@ const processURI = (uri, opts) => {
|
|||
type: 'web',
|
||||
name: 'fediverse',
|
||||
},
|
||||
match: {
|
||||
regularExpression: reURI,
|
||||
isAmbiguous: true,
|
||||
},
|
||||
profile: {
|
||||
display: `@${match[2]}@${match[1]}`,
|
||||
uri: uri,
|
||||
|
@ -45,7 +46,6 @@ const processURI = (uri, opts) => {
|
|||
}
|
||||
},
|
||||
claim: {
|
||||
fingerprint: null,
|
||||
format: E.ClaimFormat.FINGERPRINT,
|
||||
relation: E.ClaimRelation.CONTAINS,
|
||||
path: ['summary'],
|
|
@ -17,10 +17,7 @@ const E = require('../enums')
|
|||
|
||||
const reURI = /^https:\/\/(.*)\/(.*)\/gitea_proof\/?/
|
||||
|
||||
const processURI = (uri, opts) => {
|
||||
if (!opts) {
|
||||
opts = {}
|
||||
}
|
||||
const processURI = (uri) => {
|
||||
const match = uri.match(reURI)
|
||||
|
||||
return {
|
||||
|
@ -28,6 +25,10 @@ const processURI = (uri, opts) => {
|
|||
type: 'web',
|
||||
name: 'gitea',
|
||||
},
|
||||
match: {
|
||||
regularExpression: reURI,
|
||||
isAmbiguous: true,
|
||||
},
|
||||
profile: {
|
||||
display: `${match[2]}@${match[1]}`,
|
||||
uri: `https://${match[1]}/${match[2]}`,
|
||||
|
@ -45,7 +46,6 @@ const processURI = (uri, opts) => {
|
|||
}
|
||||
},
|
||||
claim: {
|
||||
fingerprint: null,
|
||||
format: E.ClaimFormat.MESSAGE,
|
||||
relation: E.ClaimRelation.EQUALS,
|
||||
path: ['description'],
|
|
@ -17,10 +17,7 @@ const E = require('../enums')
|
|||
|
||||
const reURI = /^https:\/\/gist\.github\.com\/(.*)\/(.*)\/?/
|
||||
|
||||
const processURI = (uri, opts) => {
|
||||
if (!opts) {
|
||||
opts = {}
|
||||
}
|
||||
const processURI = (uri) => {
|
||||
const match = uri.match(reURI)
|
||||
|
||||
return {
|
||||
|
@ -28,6 +25,10 @@ const processURI = (uri, opts) => {
|
|||
type: 'web',
|
||||
name: 'github',
|
||||
},
|
||||
match: {
|
||||
regularExpression: reURI,
|
||||
isAmbiguous: false,
|
||||
},
|
||||
profile: {
|
||||
display: match[1],
|
||||
uri: `https://github.com/${match[1]}`,
|
||||
|
@ -45,7 +46,6 @@ const processURI = (uri, opts) => {
|
|||
}
|
||||
},
|
||||
claim: {
|
||||
fingerprint: null,
|
||||
format: E.ClaimFormat.MESSAGE,
|
||||
relation: E.ClaimRelation.CONTAINS,
|
||||
path: ['files', 'openpgp.md', 'content'],
|
|
@ -17,10 +17,7 @@ const E = require('../enums')
|
|||
|
||||
const reURI = /^https:\/\/(.*)\/(.*)\/gitlab_proof\/?/
|
||||
|
||||
const processURI = (uri, opts) => {
|
||||
if (!opts) {
|
||||
opts = {}
|
||||
}
|
||||
const processURI = (uri) => {
|
||||
const match = uri.match(reURI)
|
||||
|
||||
return {
|
||||
|
@ -28,6 +25,10 @@ const processURI = (uri, opts) => {
|
|||
type: 'web',
|
||||
name: 'gitlab',
|
||||
},
|
||||
match: {
|
||||
regularExpression: reURI,
|
||||
isAmbiguous: true,
|
||||
},
|
||||
profile: {
|
||||
display: `${match[2]}@${match[1]}`,
|
||||
uri: `https://${match[1]}/${match[2]}`,
|
||||
|
@ -46,7 +47,6 @@ const processURI = (uri, opts) => {
|
|||
}
|
||||
},
|
||||
claim: {
|
||||
fingerprint: null,
|
||||
format: E.ClaimFormat.MESSAGE,
|
||||
relation: E.ClaimRelation.EQUALS,
|
||||
path: ['description'],
|
|
@ -17,10 +17,7 @@ const E = require('../enums')
|
|||
|
||||
const reURI = /^https:\/\/news\.ycombinator\.com\/user\?id=(.*)\/?/
|
||||
|
||||
const processURI = (uri, opts) => {
|
||||
if (!opts) {
|
||||
opts = {}
|
||||
}
|
||||
const processURI = (uri) => {
|
||||
const match = uri.match(reURI)
|
||||
|
||||
return {
|
||||
|
@ -28,6 +25,10 @@ const processURI = (uri, opts) => {
|
|||
type: 'web',
|
||||
name: 'hackernews',
|
||||
},
|
||||
match: {
|
||||
regularExpression: reURI,
|
||||
isAmbiguous: false,
|
||||
},
|
||||
profile: {
|
||||
display: match[1],
|
||||
uri: uri,
|
||||
|
@ -45,7 +46,6 @@ const processURI = (uri, opts) => {
|
|||
}
|
||||
},
|
||||
claim: {
|
||||
fingerprint: null,
|
||||
format: E.ClaimFormat.URI,
|
||||
relation: E.ClaimRelation.CONTAINS,
|
||||
path: ['about'],
|
57
src/claimDefinitions/index.js
Normal file
57
src/claimDefinitions/index.js
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
Copyright 2021 Yarmo Mackenbach
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
const list = [
|
||||
'dns',
|
||||
'irc',
|
||||
'xmpp',
|
||||
'matrix',
|
||||
'twitter',
|
||||
'reddit',
|
||||
'liberapay',
|
||||
'hackernews',
|
||||
'lobsters',
|
||||
'devto',
|
||||
'gitea',
|
||||
'gitlab',
|
||||
'github',
|
||||
'mastodon',
|
||||
'fediverse',
|
||||
'discourse',
|
||||
'owncast',
|
||||
]
|
||||
|
||||
const data = {
|
||||
dns: require('./dns'),
|
||||
irc: require('./irc'),
|
||||
xmpp: require('./xmpp'),
|
||||
matrix: require('./matrix'),
|
||||
twitter: require('./twitter'),
|
||||
reddit: require('./reddit'),
|
||||
liberapay: require('./liberapay'),
|
||||
hackernews: require('./hackernews'),
|
||||
lobsters: require('./lobsters'),
|
||||
devto: require('./devto'),
|
||||
gitea: require('./gitea'),
|
||||
gitlab: require('./gitlab'),
|
||||
github: require('./github'),
|
||||
mastodon: require('./mastodon'),
|
||||
fediverse: require('./fediverse'),
|
||||
discourse: require('./discourse'),
|
||||
owncast: require('./owncast'),
|
||||
}
|
||||
|
||||
exports.list = list
|
||||
exports.data = data
|
|
@ -17,10 +17,7 @@ const E = require('../enums')
|
|||
|
||||
const reURI = /^irc\:\/\/(.*)\/([a-zA-Z0-9]*)/
|
||||
|
||||
const processURI = (uri, opts) => {
|
||||
if (!opts) {
|
||||
opts = {}
|
||||
}
|
||||
const processURI = (uri) => {
|
||||
const match = uri.match(reURI)
|
||||
|
||||
return {
|
||||
|
@ -28,6 +25,10 @@ const processURI = (uri, opts) => {
|
|||
type: 'communication',
|
||||
name: 'irc',
|
||||
},
|
||||
match: {
|
||||
regularExpression: reURI,
|
||||
isAmbiguous: false,
|
||||
},
|
||||
profile: {
|
||||
display: `irc://${match[1]}/${match[2]}`,
|
||||
uri: uri,
|
||||
|
@ -46,7 +47,6 @@ const processURI = (uri, opts) => {
|
|||
}
|
||||
},
|
||||
claim: {
|
||||
fingerprint: null,
|
||||
format: E.ClaimFormat.URI,
|
||||
relation: E.ClaimRelation.CONTAINS,
|
||||
path: [],
|
|
@ -17,10 +17,7 @@ const E = require('../enums')
|
|||
|
||||
const reURI = /^https:\/\/liberapay\.com\/(.*)\/?/
|
||||
|
||||
const processURI = (uri, opts) => {
|
||||
if (!opts) {
|
||||
opts = {}
|
||||
}
|
||||
const processURI = (uri) => {
|
||||
const match = uri.match(reURI)
|
||||
|
||||
return {
|
||||
|
@ -28,6 +25,10 @@ const processURI = (uri, opts) => {
|
|||
type: 'web',
|
||||
name: 'liberapay',
|
||||
},
|
||||
match: {
|
||||
regularExpression: reURI,
|
||||
isAmbiguous: false,
|
||||
},
|
||||
profile: {
|
||||
display: match[1],
|
||||
uri: uri,
|
||||
|
@ -45,7 +46,6 @@ const processURI = (uri, opts) => {
|
|||
}
|
||||
},
|
||||
claim: {
|
||||
fingerprint: null,
|
||||
format: E.ClaimFormat.MESSAGE,
|
||||
relation: E.ClaimRelation.CONTAINS,
|
||||
path: ['statements', 'content'],
|
|
@ -17,10 +17,7 @@ const E = require('../enums')
|
|||
|
||||
const reURI = /^https:\/\/lobste\.rs\/u\/(.*)\/?/
|
||||
|
||||
const processURI = (uri, opts) => {
|
||||
if (!opts) {
|
||||
opts = {}
|
||||
}
|
||||
const processURI = (uri) => {
|
||||
const match = uri.match(reURI)
|
||||
|
||||
return {
|
||||
|
@ -28,6 +25,10 @@ const processURI = (uri, opts) => {
|
|||
type: 'web',
|
||||
name: 'lobsters',
|
||||
},
|
||||
match: {
|
||||
regularExpression: reURI,
|
||||
isAmbiguous: false,
|
||||
},
|
||||
profile: {
|
||||
display: match[1],
|
||||
uri: uri,
|
||||
|
@ -45,7 +46,6 @@ const processURI = (uri, opts) => {
|
|||
}
|
||||
},
|
||||
claim: {
|
||||
fingerprint: null,
|
||||
format: E.ClaimFormat.MESSAGE,
|
||||
relation: E.ClaimRelation.CONTAINS,
|
||||
path: ['about'],
|
|
@ -17,10 +17,7 @@ const E = require('../enums')
|
|||
|
||||
const reURI = /^https:\/\/(.*)\/@(.*)\/?/
|
||||
|
||||
const processURI = (uri, opts) => {
|
||||
if (!opts) {
|
||||
opts = {}
|
||||
}
|
||||
const processURI = (uri) => {
|
||||
const match = uri.match(reURI)
|
||||
|
||||
return {
|
||||
|
@ -28,6 +25,10 @@ const processURI = (uri, opts) => {
|
|||
type: 'web',
|
||||
name: 'mastodon',
|
||||
},
|
||||
match: {
|
||||
regularExpression: reURI,
|
||||
isAmbiguous: true,
|
||||
},
|
||||
profile: {
|
||||
display: `@${match[2]}@${match[1]}`,
|
||||
uri: uri,
|
||||
|
@ -45,7 +46,6 @@ const processURI = (uri, opts) => {
|
|||
}
|
||||
},
|
||||
claim: {
|
||||
fingerprint: null,
|
||||
format: E.ClaimFormat.FINGERPRINT,
|
||||
relation: E.ClaimRelation.CONTAINS,
|
||||
path: ['attachment', 'value'],
|
|
@ -18,10 +18,7 @@ const queryString = require('query-string')
|
|||
|
||||
const reURI = /^matrix\:u\/(?:\@)?([^@:]*\:[^?]*)(\?.*)?/
|
||||
|
||||
const processURI = (uri, opts) => {
|
||||
if (!opts) {
|
||||
opts = {}
|
||||
}
|
||||
const processURI = (uri) => {
|
||||
const match = uri.match(reURI)
|
||||
|
||||
if (!match[2]) {
|
||||
|
@ -42,6 +39,10 @@ const processURI = (uri, opts) => {
|
|||
type: 'communication',
|
||||
name: 'matrix',
|
||||
},
|
||||
match: {
|
||||
regularExpression: reURI,
|
||||
isAmbiguous: false,
|
||||
},
|
||||
profile: {
|
||||
display: `@${match[1]}`,
|
||||
uri: profileUrl,
|
||||
|
@ -60,7 +61,6 @@ const processURI = (uri, opts) => {
|
|||
}
|
||||
},
|
||||
claim: {
|
||||
fingerprint: null,
|
||||
format: E.ClaimFormat.MESSAGE,
|
||||
relation: E.ClaimRelation.CONTAINS,
|
||||
path: ['data', 'content', 'body'],
|
|
@ -17,10 +17,7 @@ const E = require('../enums')
|
|||
|
||||
const reURI = /^https:\/\/(.*)/
|
||||
|
||||
const processURI = (uri, opts) => {
|
||||
if (!opts) {
|
||||
opts = {}
|
||||
}
|
||||
const processURI = (uri) => {
|
||||
const match = uri.match(reURI)
|
||||
|
||||
return {
|
||||
|
@ -28,6 +25,10 @@ const processURI = (uri, opts) => {
|
|||
type: 'web',
|
||||
name: 'owncast',
|
||||
},
|
||||
match: {
|
||||
regularExpression: reURI,
|
||||
isAmbiguous: true,
|
||||
},
|
||||
profile: {
|
||||
display: match[1],
|
||||
uri: uri,
|
||||
|
@ -45,7 +46,6 @@ const processURI = (uri, opts) => {
|
|||
}
|
||||
},
|
||||
claim: {
|
||||
fingerprint: null,
|
||||
format: E.ClaimFormat.FINGERPRINT,
|
||||
relation: E.ClaimRelation.CONTAINS,
|
||||
path: ['socialHandles', 'url'],
|
|
@ -17,10 +17,7 @@ const E = require('../enums')
|
|||
|
||||
const reURI = /^https:\/\/(?:www\.)?reddit\.com\/user\/(.*)\/comments\/(.*)\/(.*)\/?/
|
||||
|
||||
const processURI = (uri, opts) => {
|
||||
if (!opts) {
|
||||
opts = {}
|
||||
}
|
||||
const processURI = (uri) => {
|
||||
const match = uri.match(reURI)
|
||||
|
||||
return {
|
||||
|
@ -28,6 +25,10 @@ const processURI = (uri, opts) => {
|
|||
type: 'web',
|
||||
name: 'reddit',
|
||||
},
|
||||
match: {
|
||||
regularExpression: reURI,
|
||||
isAmbiguous: false,
|
||||
},
|
||||
profile: {
|
||||
display: match[1],
|
||||
uri: `https://www.reddit.com/user/${match[1]}`,
|
||||
|
@ -45,7 +46,6 @@ const processURI = (uri, opts) => {
|
|||
}
|
||||
},
|
||||
claim: {
|
||||
fingerprint: null,
|
||||
format: E.ClaimFormat.MESSAGE,
|
||||
relation: E.ClaimRelation.CONTAINS,
|
||||
path: ['data', 'children', 'data', 'selftext'],
|
|
@ -14,60 +14,10 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
const E = require('../enums')
|
||||
const bent = require('bent')
|
||||
const req = bent('GET')
|
||||
const serviceproviders = require('../serviceproviders')
|
||||
const utils = require('../utils')
|
||||
|
||||
const reURI = /^https:\/\/twitter\.com\/(.*)\/status\/([0-9]*)(?:\?.*)?/
|
||||
|
||||
const customRequestHandler = async (spData, opts) => {
|
||||
const match = spData.proof.uri.match(reURI)
|
||||
|
||||
// Attempt direct verification if policy allows it
|
||||
if (opts.proxyPolicy !== 'always') {
|
||||
if ('twitterBearerToken' in opts && opts.twitterBearerToken) {
|
||||
const res = await req(
|
||||
`https://api.twitter.com/1.1/statuses/show.json?id=${match[2]}`,
|
||||
null,
|
||||
{
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${opts.twitterBearerToken}`,
|
||||
}
|
||||
)
|
||||
const json = await res.json()
|
||||
return json.text
|
||||
} else if ('nitterInstance' in opts && opts.nitterInstance) {
|
||||
spData.proof.fetch = `https://${opts.nitterInstance}/${match[1]}/status/${match[2]}`
|
||||
const res = await serviceproviders.proxyRequestHandler(spData, opts)
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
||||
// Attempt proxy verification if policy allows it
|
||||
if (opts.proxyPolicy !== 'never' && spData.proof.fetch) {
|
||||
return req(utils.generateProxyURL('twitter', match[2], opts), null, {
|
||||
Accept: 'application/json',
|
||||
})
|
||||
.then(async (res) => {
|
||||
return await res.json()
|
||||
})
|
||||
.then((res) => {
|
||||
return res.data.text
|
||||
})
|
||||
.catch((e) => {
|
||||
reject(e)
|
||||
})
|
||||
}
|
||||
|
||||
// No verification
|
||||
return null
|
||||
}
|
||||
|
||||
const processURI = (uri, opts) => {
|
||||
if (!opts) {
|
||||
opts = {}
|
||||
}
|
||||
const processURI = (uri) => {
|
||||
const match = uri.match(reURI)
|
||||
|
||||
return {
|
||||
|
@ -75,6 +25,10 @@ const processURI = (uri, opts) => {
|
|||
type: 'web',
|
||||
name: 'twitter',
|
||||
},
|
||||
match: {
|
||||
regularExpression: reURI,
|
||||
isAmbiguous: false,
|
||||
},
|
||||
profile: {
|
||||
display: `@${match[1]}`,
|
||||
uri: `https://twitter.com/${match[1]}`,
|
||||
|
@ -92,7 +46,6 @@ const processURI = (uri, opts) => {
|
|||
}
|
||||
},
|
||||
claim: {
|
||||
fingerprint: null,
|
||||
format: E.ClaimFormat.MESSAGE,
|
||||
relation: E.ClaimRelation.CONTAINS,
|
||||
path: [],
|
|
@ -17,10 +17,7 @@ const E = require('../enums')
|
|||
|
||||
const reURI = /^xmpp:([a-zA-Z0-9\.\-\_]*)@([a-zA-Z0-9\.\-\_]*)(?:\?(.*))?/
|
||||
|
||||
const processURI = (uri, opts) => {
|
||||
if (!opts) {
|
||||
opts = {}
|
||||
}
|
||||
const processURI = (uri) => {
|
||||
const match = uri.match(reURI)
|
||||
|
||||
return {
|
||||
|
@ -28,6 +25,10 @@ const processURI = (uri, opts) => {
|
|||
type: 'communication',
|
||||
name: 'xmpp',
|
||||
},
|
||||
match: {
|
||||
regularExpression: reURI,
|
||||
isAmbiguous: false,
|
||||
},
|
||||
profile: {
|
||||
display: `${match[1]}@${match[2]}`,
|
||||
uri: uri,
|
||||
|
@ -46,7 +47,6 @@ const processURI = (uri, opts) => {
|
|||
}
|
||||
},
|
||||
claim: {
|
||||
fingerprint: null,
|
||||
format: E.ClaimFormat.MESSAGE,
|
||||
relation: E.ClaimRelation.CONTAINS,
|
||||
path: [],
|
Loading…
Reference in a new issue