feat(proxy): add more handling

This commit is contained in:
vulet 2021-01-15 01:10:53 +08:00
parent 01e43916f2
commit 9e17440abc
2 changed files with 4 additions and 2 deletions

View file

@ -47,8 +47,10 @@ exports.runQuery = async (client, room, userInput, registrar) => {
try { try {
const url = new URL(userInput); const url = new URL(userInput);
if(!registrar.config.invidious.domains.includes(url.hostname)) throw ''; if(!registrar.config.invidious.domains.includes(url.hostname)) throw '';
if(/^\/[\w-]{11}$/.test(url.pathname))
return await run(client, room, url.pathname.slice(1), registrar);
const params = new URLSearchParams(url.search).get("v"); const params = new URLSearchParams(url.search).get("v");
if(!/([a-z0-9_-]{11})?$/.test(params)) throw ''; if(!/^[\w-]{11}$/.test(params)) throw '';
return await run(client, room, params, registrar); return await run(client, room, params, registrar);
} catch(e) { } catch(e) {
return client.sendHtmlNotice(room.roomId, 'Sad!', `<strong>Sad!</strong>`).catch(()=>{}); return client.sendHtmlNotice(room.roomId, 'Sad!', `<strong>Sad!</strong>`).catch(()=>{});

View file

@ -27,6 +27,6 @@ module.exports = {
invidious: { invidious: {
domain: 'invidious.fdn.fr', domain: 'invidious.fdn.fr',
userAgent: 'Mozilla/4.0 (compatible; Beep Boop)', userAgent: 'Mozilla/4.0 (compatible; Beep Boop)',
domains: [ 'invidious.snopyta.org', 'invidious.xyz', 'youtube.com', 'www.youtube.com' ] domains: [ 'invidious.snopyta.org', 'invidious.xyz', 'youtube.com', 'www.youtube.com', 'youtu.be' ]
} }
}; };