mirror of
https://codeberg.org/keyoxide/doipjs.git
synced 2024-12-23 06:59:29 -07:00
Merge pull request 'Add Stack Exchange service provider' (#23) from cherryblossom/doipjs:stack-exchange into main
Reviewed-on: https://codeberg.org/keyoxide/doipjs/pulls/23
This commit is contained in:
commit
24b06d5d4c
2 changed files with 121 additions and 2 deletions
|
@ -32,7 +32,8 @@ const list = [
|
||||||
'mastodon',
|
'mastodon',
|
||||||
'pleroma',
|
'pleroma',
|
||||||
'discourse',
|
'discourse',
|
||||||
'owncast'
|
'owncast',
|
||||||
|
'stackexchange'
|
||||||
]
|
]
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
|
@ -54,7 +55,8 @@ const data = {
|
||||||
mastodon: require('./mastodon'),
|
mastodon: require('./mastodon'),
|
||||||
pleroma: require('./pleroma'),
|
pleroma: require('./pleroma'),
|
||||||
discourse: require('./discourse'),
|
discourse: require('./discourse'),
|
||||||
owncast: require('./owncast')
|
owncast: require('./owncast'),
|
||||||
|
stackexchange: require('./stackexchange')
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.list = list
|
exports.list = list
|
||||||
|
|
117
src/claimDefinitions/stackexchange.js
Normal file
117
src/claimDefinitions/stackexchange.js
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
/*
|
||||||
|
Copyright 2022 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 E = require('../enums')
|
||||||
|
|
||||||
|
const reURI = /^https:\/\/(.*(?:askubuntu|mathoverflow|serverfault|stackapps|stackoverflow)|.+\.stackexchange)\.com\/users\/(\d+)/
|
||||||
|
const reStackExchange = /\.stackexchange$/
|
||||||
|
|
||||||
|
const processURI = (uri) => {
|
||||||
|
const [, domain, id] = uri.match(reURI)
|
||||||
|
const site = domain.replace(reStackExchange, '')
|
||||||
|
|
||||||
|
return {
|
||||||
|
serviceprovider: {
|
||||||
|
type: 'web',
|
||||||
|
name: 'stackexchange'
|
||||||
|
},
|
||||||
|
match: {
|
||||||
|
regularExpression: reURI,
|
||||||
|
isAmbiguous: false
|
||||||
|
},
|
||||||
|
profile: {
|
||||||
|
display: `${id}@${site}`,
|
||||||
|
uri: uri,
|
||||||
|
qr: null
|
||||||
|
},
|
||||||
|
proof: {
|
||||||
|
uri: `https://${domain}.com/users/${id}?tab=profile`,
|
||||||
|
request: {
|
||||||
|
fetcher: E.Fetcher.HTTP,
|
||||||
|
access: E.ProofAccess.GENERIC,
|
||||||
|
format: E.ProofFormat.JSON,
|
||||||
|
data: {
|
||||||
|
url: `https://api.stackexchange.com/2.3/users/${id}?site=${site}&filter=!AH)b5JqVyImf`,
|
||||||
|
format: E.ProofFormat.JSON
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
claim: {
|
||||||
|
format: E.ClaimFormat.MESSAGE,
|
||||||
|
relation: E.ClaimRelation.CONTAINS,
|
||||||
|
path: ['items', 'about_me']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const tests = [
|
||||||
|
{
|
||||||
|
uri: 'https://stackoverflow.com/users/1234',
|
||||||
|
shouldMatch: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
uri: 'https://stackoverflow.com/users/1234/alice',
|
||||||
|
shouldMatch: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
uri: 'https://stackoverflow.com/users/1234?tab=topactivity',
|
||||||
|
shouldMatch: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
uri: 'https://stackoverflow.com/users/1234/alice?tab=profile',
|
||||||
|
shouldMatch: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
uri: 'https://meta.stackoverflow.com/users/1234',
|
||||||
|
shouldMatch: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
uri: 'https://pt.stackoverflow.com/users/1234',
|
||||||
|
shouldMatch: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
uri: 'https://pt.meta.stackoverflow.com/users/1234',
|
||||||
|
shouldMatch: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
uri: 'https://serverfault.com/users/1234',
|
||||||
|
shouldMatch: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
uri: 'https://meta.stackexchange.com/users/1234',
|
||||||
|
shouldMatch: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
uri: 'https://gaming.meta.stackexchange.com/users/1234',
|
||||||
|
shouldMatch: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
uri: 'https://stackexchange.com/users/1234',
|
||||||
|
shouldMatch: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
uri: 'https://domain.com/users/1234',
|
||||||
|
shouldMatch: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
uri: 'https://meta.domain.com/users/1234',
|
||||||
|
shouldMatch: false
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
exports.reURI = reURI
|
||||||
|
exports.processURI = processURI
|
||||||
|
exports.tests = tests
|
Loading…
Reference in a new issue