diff --git a/plugins/any-of.js b/plugins/any-of.js index 2b5c823346bed1e49d506452d69c896f714736cc..1b6f30f630008a4fb7204b35838db23807ab1d51 100644 --- a/plugins/any-of.js +++ b/plugins/any-of.js @@ -15,6 +15,9 @@ // sane defaults let defaultConfig = { + // name of this plugin + // should not be changed + name: "any-of", // list of plugins to run simultaneously plugins: { "alt-fetch": {}, @@ -23,13 +26,13 @@ } // merge the defaults with settings from SamizdatConfig - let config = {...defaultConfig, ...self.SamizdatConfig.plugins["any-of"]} + let config = {...defaultConfig, ...self.SamizdatConfig.plugins[defaultConfig.name]} /** * getting content using regular HTTP(S) fetch() */ let fetchContent = (url) => { - console.log(`Samizdat: any-of: [${Object.keys(config.plugins).join(', ')}]!`) + console.log(`Samizdat: ${config.name} plugin using: [${Object.keys(config.plugins).join(', ')}]!`) return Promise.any( SamizdatPlugins .filter(p=>Object.keys(config.plugins).includes(p.name)) @@ -40,7 +43,7 @@ // and add ourselves to it // with some additional metadata self.SamizdatPlugins.push({ - name: 'any-of', + name: config.name, description: `Running simultaneously: [${Object.keys(config.plugins).join(', ')}]`, version: 'COMMIT_UNKNOWN', fetch: fetchContent, diff --git a/plugins/cache.js b/plugins/cache.js index 1f689c065fb263c187a87975f2826bc5ce8f1ed6..93207b893b91bdbdcc22542fc5031fc8ef4a38a8 100644 --- a/plugins/cache.js +++ b/plugins/cache.js @@ -6,9 +6,19 @@ (function () { /* - * this plugin has no config settings + * plugin config settings */ + // sane defaults + let defaultConfig = { + // name of this plugin + // should not be changed + name: "cache" + } + + // merge the defaults with settings from SamizdatConfig + let config = {...defaultConfig, ...self.SamizdatConfig.plugins[defaultConfig.name]} + /** * getting content from cache */ @@ -123,7 +133,7 @@ // and add ourselves to it // with some additional metadata self.SamizdatPlugins.push({ - name: 'cache', + name: config.name, description: 'Locally cached responses, using the Cache API.', version: 'COMMIT_UNKNOWN', fetch: getContentFromCache, diff --git a/plugins/fetch.js b/plugins/fetch.js index a0253eca2f431b6760c8ec2f3ed599b0659bf971..d34c3021d8ac3b49dee1fb960f3a9332b1c42549 100644 --- a/plugins/fetch.js +++ b/plugins/fetch.js @@ -10,9 +10,18 @@ (function () { /* - * this plugin has no config settings + * plugin config settings */ - + + // sane defaults + let defaultConfig = { + // name of this plugin + // should not be changed + name: "fetch" + } + + // merge the defaults with settings from SamizdatConfig + let config = {...defaultConfig, ...self.SamizdatConfig.plugins[defaultConfig.name]} /** * getting content using regular HTTP(S) fetch() */ @@ -41,7 +50,7 @@ }); // add the X-Samizdat-* headers to the mix - init.headers['X-Samizdat-Method'] = 'fetch' + init.headers['X-Samizdat-Method'] = config.name init.headers['X-Samizdat-ETag'] = response.headers.get('ETag') // return the new response, using the Blob from the original one @@ -59,7 +68,7 @@ // and add ourselves to it // with some additional metadata self.SamizdatPlugins.push({ - name: 'fetch', + name: config.name, description: 'Just a regular HTTP(S) fetch()', version: 'COMMIT_UNKNOWN', fetch: fetchContent diff --git a/plugins/gun-ipfs.js b/plugins/gun-ipfs.js index 1e57a3963f62ba12bcee1d745472571169ea434d..fbda9b5e7002703fcdb25d1ebb532599fe092e7b 100644 --- a/plugins/gun-ipfs.js +++ b/plugins/gun-ipfs.js @@ -20,6 +20,9 @@ // sane defaults let defaultConfig = { + // name of this plugin + // should not be changed + name: "gun-ipfs", // the pubkey of the preconfigured Gun user; always needs to be set in config.js gunPubkey: null, // the IPFS gateway we're using for verification when publishing; default is usually ok @@ -27,7 +30,7 @@ } // merge the defaults with settings from SamizdatConfig - let config = {...defaultConfig, ...self.SamizdatConfig.plugins["gun-ipfs"]} + let config = {...defaultConfig, ...self.SamizdatConfig.plugins[defaultConfig.name]} // reality check: Gun pubkey needs to be set to a non-empty string if (typeof(config.gunPubkey) !== "string" || config.gunPubkey === "") { @@ -211,7 +214,7 @@ 'headers': { 'Content-Type': contentType, 'ETag': file.value.path, - 'X-Samizdat-Method': 'gun-ipfs', + 'X-Samizdat-Method': config.name, 'X-Samizdat-ETag': file.value.path } } @@ -444,7 +447,7 @@ // and add ourselves to it // with some additional metadata self.SamizdatPlugins.push({ - name: 'gun-ipfs', + name: config.name, description: 'Decentralized resource fetching using Gun for address resolution and IPFS for content delivery.', version: 'COMMIT_UNKNOWN', fetch: getContentFromGunAndIPFS, diff --git a/plugins/ipns-ipfs.js b/plugins/ipns-ipfs.js index c4ad9b61bc2ee1ca4385c0a997504852951d9127..f4e141b6f7e8019675145e092e8a673a68cd8c25 100644 --- a/plugins/ipns-ipfs.js +++ b/plugins/ipns-ipfs.js @@ -25,6 +25,9 @@ // sane defaults let defaultConfig = { + // name of this plugin + // should not be changed + name: "ipns-ipfs", // the pubkey of the preconfigured IPNS node; always needs to be set in config.js ipnsPubkey: null, // the IPFS gateway we're using for verification when publishing; default is usually ok @@ -32,7 +35,7 @@ } // merge the defaults with settings from SamizdatConfig - let config = {...defaultConfig, ...self.SamizdatConfig.plugins["ipns-ipfs"]} + let config = {...defaultConfig, ...self.SamizdatConfig.plugins[defaultConfig.name]} // reality check: Gun pubkey needs to be set to a non-empty string if (typeof(config.ipnsPubkey) !== "string" || config.ipnsPubkey === "") { @@ -168,7 +171,7 @@ 'headers': { 'Content-Type': contentType, 'ETag': file.value.path, - 'X-Samizdat-Method': 'ipns-ipfs', + 'X-Samizdat-Method': config.name, 'X-Samizdat-ETag': file.value.path } } @@ -328,7 +331,7 @@ // and add ourselves to it // with some additional metadata self.SamizdatPlugins.push({ - name: 'ipns-ipfs', + name: config.name, description: 'Decentralized resource fetching using IPNS for address resolution and IPFS for content delivery.', version: 'COMMIT_UNKNOWN', fetch: getContentFromIPNSAndIPFS,