mirror of
https://codeberg.org/keyoxide/doipjs.git
synced 2024-12-22 14:39:28 -07:00
feat: add discord support
This commit is contained in:
parent
6d2606c8a9
commit
689117ac98
2 changed files with 99 additions and 1 deletions
96
src/serviceProviders/discord.js
Normal file
96
src/serviceProviders/discord.js
Normal file
|
@ -0,0 +1,96 @@
|
||||||
|
/*
|
||||||
|
Copyright 2024 Bram Hagens
|
||||||
|
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Discord service provider
|
||||||
|
* @module serviceProviders/discord
|
||||||
|
* @example
|
||||||
|
* import { ServiceProviderDefinitions } from 'doipjs';
|
||||||
|
* const sp = ServiceProviderDefinitions.data.discord.processURI('https://discord.com/invite/AbCdEf');
|
||||||
|
*/
|
||||||
|
|
||||||
|
import * as E from '../enums.js'
|
||||||
|
import { ServiceProvider } from '../serviceProvider.js'
|
||||||
|
|
||||||
|
export const reURI = /^https:\/\/discord\.com\/invite\/(.+)/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @function
|
||||||
|
* @param {string} uri - Claim URI to process
|
||||||
|
* @returns {ServiceProvider} The service provider information based on the claim URI
|
||||||
|
*/
|
||||||
|
export function processURI (uri) {
|
||||||
|
const match = uri.match(reURI)
|
||||||
|
|
||||||
|
return new ServiceProvider({
|
||||||
|
about: {
|
||||||
|
id: 'discord',
|
||||||
|
name: 'Discord',
|
||||||
|
homepage: 'https://discord.com'
|
||||||
|
},
|
||||||
|
profile: {
|
||||||
|
display: null,
|
||||||
|
uri: null,
|
||||||
|
qr: null
|
||||||
|
},
|
||||||
|
claim: {
|
||||||
|
uriRegularExpression: reURI.toString(),
|
||||||
|
uriIsAmbiguous: false
|
||||||
|
},
|
||||||
|
proof: {
|
||||||
|
request: {
|
||||||
|
uri: `https://discord.com/api/v9/invites/${match[1]}`,
|
||||||
|
fetcher: E.Fetcher.HTTP,
|
||||||
|
accessRestriction: E.ProofAccessRestriction.NOCORS,
|
||||||
|
data: {
|
||||||
|
url: `https://discord.com/api/v9/invites/${match[1]}`,
|
||||||
|
format: E.ProofFormat.JSON
|
||||||
|
}
|
||||||
|
},
|
||||||
|
response: {
|
||||||
|
format: E.ProofFormat.JSON
|
||||||
|
},
|
||||||
|
target: [{
|
||||||
|
format: E.ClaimFormat.FINGERPRINT,
|
||||||
|
encoding: E.EntityEncodingFormat.PLAIN,
|
||||||
|
relation: E.ClaimRelation.EQUALS,
|
||||||
|
path: ['guild', 'description']
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const functions = {
|
||||||
|
postprocess: async (claimData, proofData, opts) => {
|
||||||
|
claimData.profile.display = proofData.result.inviter.username
|
||||||
|
|
||||||
|
return { claimData, proofData }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const tests = [
|
||||||
|
{
|
||||||
|
uri: 'https://discord.com/invite/AbCdEf',
|
||||||
|
shouldMatch: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
uri: 'https://discord.com/invite/AbCdEfGh',
|
||||||
|
shouldMatch: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
uri: 'https://domain.com/invite/AbCdEf',
|
||||||
|
shouldMatch: false
|
||||||
|
}
|
||||||
|
]
|
|
@ -38,6 +38,7 @@ import * as stackexchange from './stackexchange.js'
|
||||||
import * as keybase from './keybase.js'
|
import * as keybase from './keybase.js'
|
||||||
import * as opencollective from './opencollective.js'
|
import * as opencollective from './opencollective.js'
|
||||||
import * as orcid from './orcid.js'
|
import * as orcid from './orcid.js'
|
||||||
|
import * as discord from './discord.js'
|
||||||
|
|
||||||
const _data = {
|
const _data = {
|
||||||
aspe,
|
aspe,
|
||||||
|
@ -64,7 +65,8 @@ const _data = {
|
||||||
stackexchange,
|
stackexchange,
|
||||||
keybase,
|
keybase,
|
||||||
opencollective,
|
opencollective,
|
||||||
orcid
|
orcid,
|
||||||
|
discord
|
||||||
}
|
}
|
||||||
|
|
||||||
export const list = Object.keys(_data)
|
export const list = Object.keys(_data)
|
||||||
|
|
Loading…
Reference in a new issue