mirror of
https://codeberg.org/keyoxide/doipjs.git
synced 2025-04-23 23:01:31 -06:00
Merge pull request 'Add YouTube' (#125) from quokka/doipjs:youtube into dev
This commit is contained in:
commit
a4d7aa7750
3 changed files with 1152 additions and 58 deletions
src/serviceProviders
|
@ -44,6 +44,7 @@ import * as bsky from './bsky.js'
|
|||
import * as sourcehut from './sourcehut.js'
|
||||
import * as pronounspage from './pronounspage.js'
|
||||
import * as mediawiki from './mediawiki.js'
|
||||
import * as youtube from './youtube.js'
|
||||
|
||||
const _data = {
|
||||
aspe,
|
||||
|
@ -76,6 +77,7 @@ const _data = {
|
|||
discord,
|
||||
bsky,
|
||||
sourcehut,
|
||||
youtube,
|
||||
mediawiki
|
||||
}
|
||||
|
||||
|
|
|
@ -21,35 +21,35 @@ limitations under the License.
|
|||
* const sp = ServiceProviderDefinitions.data.matrix.processURI('http(s)://domain.tld/script_path/index.php?title=TITLE&revid=REVID');
|
||||
*/
|
||||
|
||||
import * as E from "../enums.js";
|
||||
import { ServiceProvider } from "../serviceProvider.js";
|
||||
import * as E from '../enums.js'
|
||||
import { ServiceProvider } from '../serviceProvider.js'
|
||||
|
||||
// [1] - MediaWiki script path
|
||||
// [2] - Revision ID
|
||||
export const reURI = /^(https?:\/\/[^/]+\/(?:[^/]+\/)*)index\.php\?(?:[^&]*&)*(?:oldid|revid)=([^&#]+)(?:&.*)?$/;
|
||||
export const reURI = /^(https?:\/\/[^/]+\/(?:[^/]+\/)*)index\.php\?(?:[^&]*&)*(?:oldid|revid)=([^&#]+)(?:&.*)?$/
|
||||
|
||||
/**
|
||||
* @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);
|
||||
export function processURI (uri) {
|
||||
const match = uri.match(reURI)
|
||||
|
||||
return new ServiceProvider({
|
||||
about: {
|
||||
id: "mediawiki",
|
||||
name: "MediaWiki Wiki",
|
||||
homepage: null,
|
||||
id: 'mediawiki',
|
||||
name: 'MediaWiki Wiki',
|
||||
homepage: null
|
||||
},
|
||||
profile: {
|
||||
display: "Unknown username",
|
||||
display: 'Unknown username',
|
||||
uri: null,
|
||||
qr: null,
|
||||
qr: null
|
||||
},
|
||||
claim: {
|
||||
uriRegularExpression: reURI.toString(),
|
||||
uriIsAmbiguous: true,
|
||||
uriIsAmbiguous: true
|
||||
},
|
||||
proof: {
|
||||
request: {
|
||||
|
@ -58,99 +58,99 @@ export function processURI(uri) {
|
|||
accessRestriction: E.ProofAccessRestriction.NOCORS,
|
||||
data: {
|
||||
url: `${match[1]}api.php?action=query&format=json&formatversion=2&prop=revisions&&revids=${match[2]}&rvprop=user%7Ccontent%7Ccomment&meta=siteinfo&siprop=general%7Cnamespaces`,
|
||||
format: E.ProofFormat.JSON,
|
||||
},
|
||||
format: E.ProofFormat.JSON
|
||||
}
|
||||
},
|
||||
response: {
|
||||
format: E.ProofFormat.JSON,
|
||||
format: E.ProofFormat.JSON
|
||||
},
|
||||
target: [
|
||||
{
|
||||
format: E.ClaimFormat.URI,
|
||||
encoding: E.EntityEncodingFormat.PLAIN,
|
||||
relation: E.ClaimRelation.EQUALS,
|
||||
path: ["query", "pages", "revisions", "content"],
|
||||
path: ['query', 'pages', 'revisions', 'content']
|
||||
},
|
||||
{
|
||||
format: E.ClaimFormat.URI,
|
||||
encoding: E.EntityEncodingFormat.PLAIN,
|
||||
relation: E.ClaimRelation.EQUALS,
|
||||
path: ["query", "pages", "revisions", "comment"],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
path: ['query', 'pages', 'revisions', 'comment']
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const functions = {
|
||||
postprocess: async (claimData, proofData, opts) => {
|
||||
const match = claimData.proof.request.uri.match(reURI);
|
||||
const match = claimData.proof.request.uri.match(reURI)
|
||||
|
||||
claimData.about.name = proofData.result.query.general.sitename;
|
||||
claimData.about.homepage = proofData.result.query.general.base;
|
||||
claimData.about.name = proofData.result.query.general.sitename
|
||||
claimData.about.homepage = proofData.result.query.general.base
|
||||
|
||||
const userName = `${proofData.result.query.namespaces["2"].name}:${proofData.result.query.pages[0].revisions[0].user}`;
|
||||
const userName = `${proofData.result.query.namespaces['2'].name}:${proofData.result.query.pages[0].revisions[0].user}`
|
||||
|
||||
claimData.profile.display = userName;
|
||||
claimData.profile.display = userName
|
||||
claimData.profile.uri = `${match[1]}index.php?title=${encodeURIComponent(
|
||||
userName.replace(/ /g, "_")
|
||||
)}`;
|
||||
userName.replace(/ /g, '_')
|
||||
)}`
|
||||
|
||||
return { claimData, proofData };
|
||||
},
|
||||
};
|
||||
return { claimData, proofData }
|
||||
}
|
||||
}
|
||||
|
||||
export const tests = [
|
||||
{
|
||||
uri: "https://somewiki.tld/w/index.php?oldid=1234",
|
||||
shouldMatch: true,
|
||||
uri: 'https://somewiki.tld/w/index.php?oldid=1234',
|
||||
shouldMatch: true
|
||||
},
|
||||
{
|
||||
uri: "https://somewiki.tld/index.php?oldid=1234",
|
||||
shouldMatch: true,
|
||||
uri: 'https://somewiki.tld/index.php?oldid=1234',
|
||||
shouldMatch: true
|
||||
},
|
||||
{
|
||||
uri: "https://somewiki.tld/w/index.php?title=Some_title&oldid=1234",
|
||||
shouldMatch: true,
|
||||
uri: 'https://somewiki.tld/w/index.php?title=Some_title&oldid=1234',
|
||||
shouldMatch: true
|
||||
},
|
||||
{
|
||||
uri: "https://somewiki.tld/w/index.php?oldid=1234&title=Some_title",
|
||||
shouldMatch: true,
|
||||
uri: 'https://somewiki.tld/w/index.php?oldid=1234&title=Some_title',
|
||||
shouldMatch: true
|
||||
},
|
||||
{
|
||||
uri: "https://somewiki.tld/w/index.php?revid=1234",
|
||||
shouldMatch: true,
|
||||
uri: 'https://somewiki.tld/w/index.php?revid=1234',
|
||||
shouldMatch: true
|
||||
},
|
||||
{
|
||||
uri: "https://somewiki.tld/index.php?revid=1234",
|
||||
shouldMatch: true,
|
||||
uri: 'https://somewiki.tld/index.php?revid=1234',
|
||||
shouldMatch: true
|
||||
},
|
||||
{
|
||||
uri: "https://somewiki.tld/w/index.php?title=Some_title&revid=1234",
|
||||
shouldMatch: true,
|
||||
uri: 'https://somewiki.tld/w/index.php?title=Some_title&revid=1234',
|
||||
shouldMatch: true
|
||||
},
|
||||
{
|
||||
uri: "https://somewiki.tld/w/index.php?revid=1234&title=Some_title",
|
||||
shouldMatch: true,
|
||||
uri: 'https://somewiki.tld/w/index.php?revid=1234&title=Some_title',
|
||||
shouldMatch: true
|
||||
},
|
||||
{
|
||||
uri: "https://somewiki.tld/w/index.php?title=Some_title",
|
||||
shouldMatch: false,
|
||||
uri: 'https://somewiki.tld/w/index.php?title=Some_title',
|
||||
shouldMatch: false
|
||||
},
|
||||
{
|
||||
uri: "https://somewiki.tld/wiki/Some_title",
|
||||
shouldMatch: false,
|
||||
uri: 'https://somewiki.tld/wiki/Some_title',
|
||||
shouldMatch: false
|
||||
},
|
||||
{
|
||||
uri: "https://somewiki.tld/wiki/Some_title?oldid=1234",
|
||||
shouldMatch: false,
|
||||
uri: 'https://somewiki.tld/wiki/Some_title?oldid=1234',
|
||||
shouldMatch: false
|
||||
},
|
||||
{
|
||||
uri: "https://somewiki.tld/wiki/Some_title?revid=1234",
|
||||
shouldMatch: false,
|
||||
uri: 'https://somewiki.tld/wiki/Some_title?revid=1234',
|
||||
shouldMatch: false
|
||||
},
|
||||
{
|
||||
uri: "https://somewiki.tld/",
|
||||
shouldMatch: false,
|
||||
},
|
||||
];
|
||||
uri: 'https://somewiki.tld/',
|
||||
shouldMatch: false
|
||||
}
|
||||
]
|
||||
|
|
1092
src/serviceProviders/youtube.js
Normal file
1092
src/serviceProviders/youtube.js
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue