diff --git a/src/const/options.json b/src/const/options.json index 6d23bcad409d2c7c0bb3d8fd075d6a72b4d81b17..4e80c4b484912a185dacc7d65a35a73adc33ac5c 100644 --- a/src/const/options.json +++ b/src/const/options.json @@ -351,7 +351,7 @@ "help": "Detect and apply all settings from .env to profile" }, "formatProfile": { - "name": "format", + "name": "formatProfile", "type": "bool", "help": "Clear all settings from profile before applying from .env" }, diff --git a/src/lib/profile.js b/src/lib/profile.js index b525dbbb1b0dcfed493ffe7234f780d5317795c9..707309bd77d2a364d138d0da2786f1958689fcc1 100644 --- a/src/lib/profile.js +++ b/src/lib/profile.js @@ -1,5 +1,5 @@ -import { writeFile } from "fs"; -import { readFile, unlink } from "fs/promises"; +// import { writeFile } from "fs"; +import { readFile, unlink, writeFile } from "fs/promises"; import { resolve } from "path"; import { findProfile } from "../bin/populate_mongo.js"; const TWITTER_ACCESS_TOKEN_KEY = "TWITTER_ACCESS_TOKEN_KEY"; @@ -64,8 +64,18 @@ const TWEET_KEYS = [ TWEET_DEPTH, TWEET_TRIM_NAME, ]; -const OLD_TWITTER_KEYS = ["CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_TOKEN_KEY", "ACCESS_TOKEN_SECRET"]; -const OLD_MASTODON_KEYS = ["CLIENT_KEY", "CLIENT_SECRET", "ACCESS_TOKEN", "MASTODON_URL"]; +const OLD_TWITTER_KEYS = [ + "CONSUMER_KEY", + "CONSUMER_SECRET", + "ACCESS_TOKEN_KEY", + "ACCESS_TOKEN_SECRET" +]; +const OLD_MASTODON_KEYS = [ + "CLIENT_KEY", + "CLIENT_SECRET", + "ACCESS_TOKEN", + "MASTODON_URL" +]; const FRAME_KEYS = [INTERVAL]; function setToProfile(a, b, keys) { diff --git a/src/profile.js b/src/profile.js index 6484ab8e7d8254361e71ecfd0d339de46b61060a..45399b4444a08c60d9f6bf22df86da12299058b1 100644 --- a/src/profile.js +++ b/src/profile.js @@ -79,10 +79,11 @@ const options = [ } } - // save the profile locally if it was fetched + // save profile to local and return if download requested if (foundProfile && opts.download) { await saveProfile(location, opts.name, profile); console.log('saved profile to ' + location); + return; } if (foundProfile && opts.formatProfile) { @@ -90,10 +91,12 @@ const options = [ console.log('cleared profile settings'); } - const source = detectSourceSetting(profile); + // expect to have a profile at this point + // proceed to apply settings FROM .env TO profile + + const source = detectSourceSetting(); if (!source) { console.error('Unable to detect "SOURCE" setting in .env'); - console.error(profile); return; } @@ -102,20 +105,18 @@ const options = [ } else if (source === "S3") { await updateS3Settings(location, profile); } else { - console.error(`Invalid "SOURCE" value in profile: "${source}"`); - console.error(profile); + console.error(`Invalid "SOURCE": "${source}"`); return; } - const socials = detectSocialSetting(profile); + const socials = detectSocialSetting(); if (!socials) { - console.error('Unable to detect "SOCIAL" setting in profile'); - console.error(profile); + console.error('Unable to detect "SOCIAL" setting in .env'); return; } await updateSocialSettings(location, profile); - const folder = detectFolderSetting(profile); + const folder = detectFolderSetting(); if (!folder) { console.error('Unable to detect "FOLDER" setting in profile'); console.error(profile); @@ -135,5 +136,8 @@ const options = [ if (opts.sync) { await syncProfile(profile); + } else { + await saveProfile(location, opts.name, profile); + console.log(`Updated profile at ${location}`); } })();