From 8a443b17875dc497bf80477ae6ce70a3f182ad3d Mon Sep 17 00:00:00 2001 From: tycrek Date: Wed, 25 Aug 2021 19:01:14 -0600 Subject: [PATCH 01/12] only ask for S3 info if user is using S3 --- setup.js | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/setup.js b/setup.js index 6cf7449..b16217f 100755 --- a/setup.js +++ b/setup.js @@ -14,6 +14,10 @@ const config = { saveAsOriginal: true, mediaStrict: false, s3enabled: false, +}; + +// Default S3 config +const s3config = { s3endpoint: 'sfo3.digitaloceanspaces.com', s3bucket: 'bucket-name', s3usePathStyle: false, @@ -34,7 +38,10 @@ function doSetup() { // Override default config with existing config to allow migrating configs try { const existingConfig = require('./config.json'); - Object.keys(existingConfig).forEach((key) => Object.prototype.hasOwnProperty.call(config, key) && (config[key] = existingConfig[key])) + Object.keys(existingConfig).forEach((key) => // Replace default configs with existing configs + Object.prototype.hasOwnProperty.call(config, key) && (config[key] = existingConfig[key]) && + Object.prototype.hasOwnProperty.call(s3config, key) && (s3config[key] = existingConfig[key]) + ); } catch (ex) { if (ex.code !== 'MODULE_NOT_FOUND' && !ex.toString().includes('Unexpected end')) log.error(ex); } @@ -132,36 +139,41 @@ function doSetup() { type: 'boolean', default: config.s3enabled, required: false - }, + } + } + }; + + const s3schema = { + properties: { s3endpoint: { description: 'S3 Endpoint URL to upload objects to', type: 'string', default: config.s3endpoint, - required: false + required: true }, s3bucket: { description: 'S3 Bucket name to upload objects to', type: 'string', default: config.s3bucket, - required: false + required: true }, s3usePathStyle: { description: 'S3 path endpoint, otherwise uses subdomain endpoint', type: 'boolean', default: config.s3usePathStyle, - required: false + required: true }, s3accessKey: { description: 'Access key for the specified S3 API', type: 'string', default: config.s3accessKey, - required: false + required: true }, s3secretKey: { description: 'Secret key for the specified S3 API', type: 'string', default: config.s3secretKey, - required: false + required: true }, } }; @@ -187,6 +199,10 @@ function doSetup() { prompt.get(setupSchema) .then((r) => results = r) // skipcq: JS-0086 + // Check if using S3 + .then(() => results.s3enabled ? prompt.get(s3schema) : s3config) + .then((r) => Object.entries(r).forEach(([key, value]) => results[key] = value)) + // Verify information is correct .then(() => log .blank() From 55880b9558bdb181b1cd8298842aa37bb467fcc6 Mon Sep 17 00:00:00 2001 From: tycrek Date: Wed, 25 Aug 2021 19:01:45 -0600 Subject: [PATCH 02/12] added function for making more confirm schemas --- setup.js | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/setup.js b/setup.js index b16217f..0aa4100 100755 --- a/setup.js +++ b/setup.js @@ -179,19 +179,7 @@ function doSetup() { }; // Schema for confirm prompt. User must enter 'y' or 'n' (case-insensitive) - const confirmSchema = { - properties: { - confirm: { - description: '\nIs the above information correct? (y/n)', - type: 'string', - pattern: /^[y|n]/gim, - message: 'Must respond with either \'y\' or \'n\'', - default: 'y', - required: false, - before: (value) => value.toLowerCase().startsWith('y') - } - } - }; + const confirmSchema = getConfirmSchema('\nIs the above information correct? (y/n)'); log.blank().blank().blank().blank() .info('<<< ass setup >>>').blank(); @@ -247,6 +235,22 @@ function doSetup() { .catch((err) => log.blank().error(err)); } +function getConfirmSchema(description) { + return { + properties: { + confirm: { + description, + type: 'string', + pattern: /^[y|n]/gim, + message: 'Must respond with either \'y\' or \'n\'', + default: 'y', + required: false, + before: (value) => value.toLowerCase().startsWith('y') + } + } + }; +} + module.exports = { doSetup, config From 276b46ba017a6ff5c93b8217c5024edafbc92877 Mon Sep 17 00:00:00 2001 From: tycrek Date: Wed, 25 Aug 2021 19:07:17 -0600 Subject: [PATCH 03/12] improved wording & order of some setup items --- setup.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/setup.js b/setup.js index 0aa4100..15ea6e0 100755 --- a/setup.js +++ b/setup.js @@ -55,7 +55,7 @@ function doSetup() { const setupSchema = { properties: { host: { - description: 'Local IP to listen on', + description: 'Local IP to bind to', type: 'string', default: config.host, required: false @@ -73,36 +73,36 @@ function doSetup() { message: 'You must input a valid domain name or IP to continue' }, maxUploadSize: { - description: `Max allowable uploaded filesize, in megabytes`, + description: `Maximum size for uploaded files, in megabytes`, type: 'integer', default: config.maxUploadSize, require: false }, - useSsl: { - description: 'Use SSL (requires reverse proxy!)', - type: 'boolean', - default: config.useSsl, - required: false - }, isProxied: { description: 'Will you be running through a reverse proxy', type: 'boolean', default: config.isProxied, required: false }, + useSsl: { + description: 'Use HTTPS (must be configured with reverse proxy)', + type: 'boolean', + default: config.useSsl, + required: false + }, resourceIdSize: { - description: 'Resource ID length (length of ID\'s for your files, recommended: 6-15. Higher = more uploads)', + description: 'URL length (length of ID\'s for your files, recommended: 6-15. Higher = more uploads, but longer URLs)', type: 'integer', default: config.resourceIdSize, required: false }, resourceIdType: { - description: 'Resource ID type (determines what kind of URL your uploads are visible at. Can be one of: original, zws, random, gfycat)', + description: 'URL type (can be one of: zws, random, gfycat, original)', type: 'string', default: config.resourceIdType, require: false, pattern: /(original|zws|random|gfycat)/gi, // skipcq: JS-0113 - message: 'Must be one of: original, zws, random, gfycat' + message: 'Must be one of: zws, random, gfycat, original' }, gfyIdSize: { description: 'Adjective count for "gfycat" Resource ID type', From aabae5c3a1d28149e534d633dd2ce92932c85901 Mon Sep 17 00:00:00 2001 From: tycrek Date: Wed, 25 Aug 2021 19:11:09 -0600 Subject: [PATCH 04/12] changed some defaults - `resourceIdType` is now `random` instead of `zws` - `saveWithDate` is now `true` - `saveAsOriginal` is now `false` --- setup.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.js b/setup.js index 15ea6e0..ca5f463 100755 --- a/setup.js +++ b/setup.js @@ -8,10 +8,10 @@ const config = { isProxied: true, resourceIdSize: 12, gfyIdSize: 2, - resourceIdType: 'zws', + resourceIdType: 'random', diskFilePath: 'uploads/', - saveWithDate: false, - saveAsOriginal: true, + saveWithDate: true, + saveAsOriginal: false, mediaStrict: false, s3enabled: false, }; From 11b3c2055cae86aff361c17ce863a88f48106b0b Mon Sep 17 00:00:00 2001 From: tycrek Date: Wed, 25 Aug 2021 19:28:52 -0600 Subject: [PATCH 05/12] removed potentially dangerous config options from setup - `diskFilePath` - `saveWithDate` (some systems don't like dirs with massive amounts of files) - `saveAsOriginal` (prone to conflicts, which ass doesn't handle) These options will still exist for backwards compatibility if existing hosts have edited these options in their configs. --- setup.js | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/setup.js b/setup.js index ca5f463..6558486 100755 --- a/setup.js +++ b/setup.js @@ -9,9 +9,6 @@ const config = { resourceIdSize: 12, gfyIdSize: 2, resourceIdType: 'random', - diskFilePath: 'uploads/', - saveWithDate: true, - saveAsOriginal: false, mediaStrict: false, s3enabled: false, }; @@ -25,6 +22,17 @@ const s3config = { s3secretKey: 'secretKey', }; +// Redacted configs from previous versions +const oldConfig = { + // Note for people manually editing config.json + __WARNING__: "The following configs are no longer used and are here for backwards compatibility. For optimal use, DO NOT edit them.", + + // Removed in 0.8.4 + diskFilePath: 'uploads/', + saveWithDate: true, // Some systems don't like dirs with massive amounts of files + saveAsOriginal: false, // Prone to conflicts, which ass doesn't handle +}; + // If directly called on the command line, run setup script function doSetup() { const path = (...paths) => require('path').join(__dirname, ...paths); @@ -35,13 +43,15 @@ function doSetup() { const log = new TLog({ level: 'debug', timestamp: { enabled: false } }); - // Override default config with existing config to allow migrating configs + // Override default configs with existing configs to allow migrating configs + // Now that's a lot of configs! try { const existingConfig = require('./config.json'); - Object.keys(existingConfig).forEach((key) => // Replace default configs with existing configs - Object.prototype.hasOwnProperty.call(config, key) && (config[key] = existingConfig[key]) && - Object.prototype.hasOwnProperty.call(s3config, key) && (s3config[key] = existingConfig[key]) - ); + Object.keys(existingConfig).forEach((key) => { + Object.prototype.hasOwnProperty.call(config, key) && (config[key] = existingConfig[key]); + Object.prototype.hasOwnProperty.call(s3config, key) && (s3config[key] = existingConfig[key]); + Object.prototype.hasOwnProperty.call(oldConfig, key) && (oldConfig[key] = existingConfig[key]); + }); } catch (ex) { if (ex.code !== 'MODULE_NOT_FOUND' && !ex.toString().includes('Unexpected end')) log.error(ex); } @@ -110,24 +120,6 @@ function doSetup() { default: config.gfyIdSize, required: false }, - diskFilePath: { - description: 'Relative path to save uploads to', - type: 'string', - default: config.diskFilePath, - required: false - }, - saveWithDate: { - description: 'Use date folder structure (e.x. uploads/2021-04/image.png)', - type: 'boolean', - default: config.saveWithDate, - required: false - }, - saveAsOriginal: { - description: 'Save as original file name instead of random', - type: 'boolean', - default: config.saveAsOriginal, - required: false - }, mediaStrict: { description: 'Only allow uploads of media files (images, videos, audio)', type: 'boolean', @@ -198,6 +190,9 @@ function doSetup() { .callback(() => Object.entries(results).forEach(([setting, value]) => log.info(`--> ${setting}`, `${value}`))) .blank()) + // Apply old configs + .then(() => Object.entries(oldConfig).forEach(([setting, value]) => (results[setting] === undefined) && (results[setting] = value))) + // Confirm .then(() => prompt.get(confirmSchema)) .then(({ confirm }) => (confirm ? fs.writeJson(path('config.json'), results, { spaces: 4 }) : process.exit(1))) From bb4b0656d16f46484c449dbeecdb3f7c29aac999 Mon Sep 17 00:00:00 2001 From: tycrek Date: Wed, 25 Aug 2021 19:31:47 -0600 Subject: [PATCH 06/12] Added message for aborting setup --- setup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.js b/setup.js index 6558486..f822b31 100755 --- a/setup.js +++ b/setup.js @@ -195,7 +195,7 @@ function doSetup() { // Confirm .then(() => prompt.get(confirmSchema)) - .then(({ confirm }) => (confirm ? fs.writeJson(path('config.json'), results, { spaces: 4 }) : process.exit(1))) + .then(({ confirm }) => (confirm ? fs.writeJson(path('config.json'), results, { spaces: 4 }) : log.error('Setup aborted').callback(process.exit, 1))) // Other setup tasks .then(() => { From 2e1a05572b0588ea62a7d73a331466f88c251f23 Mon Sep 17 00:00:00 2001 From: tycrek Date: Wed, 25 Aug 2021 19:32:00 -0600 Subject: [PATCH 07/12] removed default confirmation, user must explicitly provide input --- setup.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup.js b/setup.js index f822b31..1bc2465 100755 --- a/setup.js +++ b/setup.js @@ -238,8 +238,7 @@ function getConfirmSchema(description) { type: 'string', pattern: /^[y|n]/gim, message: 'Must respond with either \'y\' or \'n\'', - default: 'y', - required: false, + required: true, before: (value) => value.toLowerCase().startsWith('y') } } From 7c02205774196b6bc7b28bfdf7b6bb435da1935d Mon Sep 17 00:00:00 2001 From: tycrek Date: Wed, 25 Aug 2021 19:32:48 -0600 Subject: [PATCH 08/12] fixed wording --- setup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.js b/setup.js index 1bc2465..442aeb4 100755 --- a/setup.js +++ b/setup.js @@ -115,7 +115,7 @@ function doSetup() { message: 'Must be one of: zws, random, gfycat, original' }, gfyIdSize: { - description: 'Adjective count for "gfycat" Resource ID type', + description: 'Adjective count for "gfycat" URL type', type: 'integer', default: config.gfyIdSize, required: false From 4049964d2305dd613276b8215daa7863ce0b5cc7 Mon Sep 17 00:00:00 2001 From: tycrek Date: Wed, 25 Aug 2021 20:28:29 -0600 Subject: [PATCH 09/12] Fixed variable used before definition (JS-0129) --- setup.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/setup.js b/setup.js index 442aeb4..69c9849 100755 --- a/setup.js +++ b/setup.js @@ -33,6 +33,21 @@ const oldConfig = { saveAsOriginal: false, // Prone to conflicts, which ass doesn't handle }; +function getConfirmSchema(description) { + return { + properties: { + confirm: { + description, + type: 'string', + pattern: /^[y|n]/gim, + message: 'Must respond with either \'y\' or \'n\'', + required: true, + before: (value) => value.toLowerCase().startsWith('y') + } + } + }; +} + // If directly called on the command line, run setup script function doSetup() { const path = (...paths) => require('path').join(__dirname, ...paths); @@ -230,21 +245,6 @@ function doSetup() { .catch((err) => log.blank().error(err)); } -function getConfirmSchema(description) { - return { - properties: { - confirm: { - description, - type: 'string', - pattern: /^[y|n]/gim, - message: 'Must respond with either \'y\' or \'n\'', - required: true, - before: (value) => value.toLowerCase().startsWith('y') - } - } - }; -} - module.exports = { doSetup, config From f7d87d29982351e3734b0069e6fa4d98f37a8460 Mon Sep 17 00:00:00 2001 From: tycrek Date: Wed, 25 Aug 2021 20:30:32 -0600 Subject: [PATCH 10/12] Fixed found `undefined` as an Identifier (JS-0127) --- setup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.js b/setup.js index 69c9849..602fa0e 100755 --- a/setup.js +++ b/setup.js @@ -206,7 +206,7 @@ function doSetup() { .blank()) // Apply old configs - .then(() => Object.entries(oldConfig).forEach(([setting, value]) => (results[setting] === undefined) && (results[setting] = value))) + .then(() => Object.entries(oldConfig).forEach(([setting, value]) => (typeof results[setting] === 'undefined') && (results[setting] = value))) // Confirm .then(() => prompt.get(confirmSchema)) From 3ab246e676abe3769849649b6d8d7dfcef8fd4a8 Mon Sep 17 00:00:00 2001 From: tycrek Date: Wed, 25 Aug 2021 20:31:53 -0600 Subject: [PATCH 11/12] Suppress JS-0093, JS-0229, JS-0086 false positives --- setup.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/setup.js b/setup.js index 602fa0e..daf6455 100755 --- a/setup.js +++ b/setup.js @@ -63,9 +63,9 @@ function doSetup() { try { const existingConfig = require('./config.json'); Object.keys(existingConfig).forEach((key) => { - Object.prototype.hasOwnProperty.call(config, key) && (config[key] = existingConfig[key]); - Object.prototype.hasOwnProperty.call(s3config, key) && (s3config[key] = existingConfig[key]); - Object.prototype.hasOwnProperty.call(oldConfig, key) && (oldConfig[key] = existingConfig[key]); + Object.prototype.hasOwnProperty.call(config, key) && (config[key] = existingConfig[key]); // skipcq: JS-0093 + Object.prototype.hasOwnProperty.call(s3config, key) && (s3config[key] = existingConfig[key]); // skipcq: JS-0093 + Object.prototype.hasOwnProperty.call(oldConfig, key) && (oldConfig[key] = existingConfig[key]); // skipcq: JS-0093 }); } catch (ex) { if (ex.code !== 'MODULE_NOT_FOUND' && !ex.toString().includes('Unexpected end')) log.error(ex); @@ -195,8 +195,8 @@ function doSetup() { .then((r) => results = r) // skipcq: JS-0086 // Check if using S3 - .then(() => results.s3enabled ? prompt.get(s3schema) : s3config) - .then((r) => Object.entries(r).forEach(([key, value]) => results[key] = value)) + .then(() => results.s3enabled ? prompt.get(s3schema) : s3config) // skipcq: JS-0229 + .then((r) => Object.entries(r).forEach(([key, value]) => results[key] = value)) // skipcq: JS-0086 // Verify information is correct .then(() => log From 36fbc4f7a64721196ec43b1b250ea5a8e3e63153 Mon Sep 17 00:00:00 2001 From: tycrek Date: Wed, 25 Aug 2021 20:43:37 -0600 Subject: [PATCH 12/12] improved result summary --- setup.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup.js b/setup.js index daf6455..d6aba98 100755 --- a/setup.js +++ b/setup.js @@ -201,8 +201,7 @@ function doSetup() { // Verify information is correct .then(() => log .blank() - .warn('Please verify your information', '') - .callback(() => Object.entries(results).forEach(([setting, value]) => log.info(`--> ${setting}`, `${value}`))) + .info('Please verify your information', '\n'.concat(Object.entries(results).map(([setting, value]) => `${' '}${log.chalk.dim.gray('-->')} ${log.chalk.bold.white(`${setting}:`)} ${log.chalk.white(value)}`).join('\n'))) .blank()) // Apply old configs