Commit 2f5dd968 authored by Michał "rysiek" Woźniak's avatar Michał "rysiek" Woźniak 🔒
Browse files

each plugin now uses config.name as its name (relevant for #72)

parent 645d2d6f
Pipeline #47061 failed with stage
in 2 minutes and 16 seconds
......@@ -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,
......
......@@ -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,
......
......@@ -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
......
......@@ -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,
......
......@@ -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,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment