1
0
Fork 1
mirror of https://codeberg.org/keyoxide/doipjs.git synced 2025-04-23 14:51:32 -06:00

Videos → Playlists; Style changes.

This commit is contained in:
Daniel Levi 2025-03-09 21:56:32 +02:00
parent 565807f4dc
commit d74861d447
No known key found for this signature in database
GPG key ID: D267DF29810DBDD5
2 changed files with 996 additions and 114 deletions
src/serviceProviders

View file

@ -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
}
]

File diff suppressed because it is too large Load diff