mirror of
https://codeberg.org/keyoxide/doipjs.git
synced 2024-12-22 22:49:28 -07:00
Add Twitter service provider
This commit is contained in:
parent
74d92511ec
commit
638eecee46
3 changed files with 67 additions and 1 deletions
|
@ -16,9 +16,11 @@ limitations under the License.
|
|||
exports.serviceprovidersList = [
|
||||
'dns',
|
||||
'xmpp',
|
||||
'twitter',
|
||||
]
|
||||
|
||||
exports.serviceproviders = {
|
||||
dns: require('./serviceproviders/dns'),
|
||||
xmpp: require('./serviceproviders/xmpp')
|
||||
xmpp: require('./serviceproviders/xmpp'),
|
||||
twitter: require('./serviceproviders/twitter'),
|
||||
}
|
||||
|
|
58
src/serviceproviders/twitter.js
Normal file
58
src/serviceproviders/twitter.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
Copyright 2020 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 reURI = /^https:\/\/twitter\.com\/(.*)\/status\/([0-9]*)(?:\?.*)?/
|
||||
|
||||
const processURI = (uri, opts) => {
|
||||
if (!opts) { opts = {} }
|
||||
const match = uri.match(reURI)
|
||||
|
||||
return {
|
||||
type: "twitter",
|
||||
profile: {
|
||||
display: `@${match[1]}`,
|
||||
uri: `https://twitter.com/${match[1]}`
|
||||
},
|
||||
proof: {
|
||||
uri: uri,
|
||||
fetch: 'DOIP_PROXY_SERVER_DOMAIN' in opts
|
||||
? `${opts.DOIP_PROXY_SERVER_DOMAIN}/server/verify/twitter
|
||||
?tweetId=${encodeURIComponent(match[2])}
|
||||
&account=${encodeURIComponent(match[1])}
|
||||
&fingerprint=${fingerprint}`
|
||||
: null
|
||||
},
|
||||
qr: null
|
||||
}
|
||||
}
|
||||
|
||||
const tests = [
|
||||
{
|
||||
uri: 'https://twitter.com/alice/status/1234567890123456789',
|
||||
shouldMatch: true
|
||||
},
|
||||
{
|
||||
uri: 'https://twitter.com/alice/status/1234567890123456789/',
|
||||
shouldMatch: true
|
||||
},
|
||||
{
|
||||
uri: 'https://domain.org/alice/status/1234567890123456789',
|
||||
shouldMatch: false
|
||||
}
|
||||
]
|
||||
|
||||
exports.reURI = reURI
|
||||
exports.processURI = processURI
|
||||
exports.tests = tests
|
|
@ -39,4 +39,10 @@ describe('verify', () => {
|
|||
expect(matches).to.be.length(1)
|
||||
expect(matches[0].type).to.be.equal('xmpp')
|
||||
})
|
||||
it('should match "https://twitter.com/alice/status/1234567890123456789" to the Twitter service provider', () => {
|
||||
const matches = doipjs.verify('https://twitter.com/alice/status/1234567890123456789', null, {returnMatchesOnly: true})
|
||||
expect(matches).to.be.a('array')
|
||||
expect(matches).to.be.length(1)
|
||||
expect(matches[0].type).to.be.equal('twitter')
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue