From bdac16ee243e12cc2d2503759d3f8496014be3b9 Mon Sep 17 00:00:00 2001 From: fyears Date: Mon, 29 Nov 2021 01:03:17 +0800 Subject: [PATCH] define clientID or AppKey by env var --- esbuild.config.mjs | 6 ++++++ package.json | 1 + src/main.ts | 4 ++++ src/remoteForDropbox.ts | 2 +- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/esbuild.config.mjs b/esbuild.config.mjs index bce359b..7707616 100644 --- a/esbuild.config.mjs +++ b/esbuild.config.mjs @@ -1,3 +1,4 @@ +import dotenv from "dotenv/config"; import esbuild from "esbuild"; import process from "process"; // import builtins from 'builtin-modules' @@ -10,6 +11,8 @@ if you want to view the source, please visit the github repository of this plugi const prod = process.argv[2] === "production"; +const DEFAULT_DROPBOX_APP_KEY = process.env.DROPBOX_APP_KEY || ""; + esbuild .build({ banner: { @@ -31,5 +34,8 @@ esbuild treeShaking: true, minify: prod, outfile: "main.js", + define: { + "process.env.DEFAULT_DROPBOX_APP_KEY": `"${DEFAULT_DROPBOX_APP_KEY}"`, + }, }) .catch(() => process.exit(1)); diff --git a/package.json b/package.json index 3a747ba..1e8a775 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "chai": "^4.3.4", "chai-as-promised": "^7.1.1", "cross-env": "^7.0.3", + "dotenv": "^10.0.0", "esbuild": "^0.14.0", "mocha": "^9.1.3", "prettier": "^2.4.1", diff --git a/src/main.ts b/src/main.ts index 1c533ee..ef545f8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -11,6 +11,7 @@ import { TFolder, } from "obsidian"; import * as CodeMirror from "codemirror"; +import process from "process"; import { prepareDBs, destroyDBs, @@ -199,6 +200,9 @@ export default class RemotelySavePlugin extends Plugin { JSON.parse(JSON.stringify(DEFAULT_SETTINGS)) /* copy an object */, await this.loadData() ); + if (this.settings.dropbox.clientID === "") { + this.settings.dropbox.clientID = DEFAULT_SETTINGS.dropbox.clientID; + } } async saveSettings() { diff --git a/src/remoteForDropbox.ts b/src/remoteForDropbox.ts index 6327893..becc801 100644 --- a/src/remoteForDropbox.ts +++ b/src/remoteForDropbox.ts @@ -29,7 +29,7 @@ export interface DropboxConfig { export const DEFAULT_DROPBOX_CONFIG = { accessToken: "", - clientID: "", + clientID: process.env.DEFAULT_DROPBOX_APP_KEY, refreshToken: "", accessTokenExpiresInSeconds: 0, accessTokenExpiresAtTime: 0,