Checkpoint first-party source parser pilot
This commit is contained in:
1 parent
605fa5b9d8
commit
c5a92282a9
9 files changed
+320
-43
No files matched your search
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
// Reviewed first-party modules only. No filesystem scanning or runtime installs.
|
||||
const { manifests } = require('./manifest');
|
||||
const plugins = Object.freeze({ weebcentral: require('./weebcentral') });
|
||||
|
||||
function parse(plugin, operation, input) {
|
||||
const manifest = manifests[plugin];
|
||||
const handler = manifest?.operations.includes(operation) ? plugins[plugin]?.[operation] : null;
|
||||
if (typeof handler !== 'function') throw new Error('Unknown source plugin or operation');
|
||||
if (!input || typeof input !== 'object' || typeof input.html !== 'string' || typeof input.url !== 'string') {
|
||||
throw new Error('Invalid parser input');
|
||||
}
|
||||
const url = new URL(input.url);
|
||||
if (!['https:', 'http:'].includes(url.protocol)) throw new Error('Invalid source URL');
|
||||
if (!manifest.sourceHosts.includes(url.hostname)) throw new Error('Source URL does not belong to plugin');
|
||||
return handler({ html: input.html, url: url.href });
|
||||
}
|
||||
|
||||
module.exports = { parse, manifests };
|
||||
Reference in new issue
Block a user