Initialize share client when helper starts
This commit is contained in:
+11
-5
@@ -11,7 +11,7 @@ module.exports = NodeHelper.create({
|
||||
this.state = { active: false, recipeId: null, recipe: null, error: null };
|
||||
this.recipeCache = { expires: 0, recipes: [] };
|
||||
this.stateFile = path.join(process.cwd(), "config", "MMM-NextcloudCookbook-state.json");
|
||||
this.client = null;
|
||||
this.configureClient();
|
||||
this.registerRoutes();
|
||||
this.stateReady = this.loadState().catch((error) => this.setError(error));
|
||||
},
|
||||
@@ -19,16 +19,22 @@ module.exports = NodeHelper.create({
|
||||
socketNotificationReceived(notification, payload) {
|
||||
if (notification !== "CONFIG") return;
|
||||
this.config = { ...this.config, ...payload };
|
||||
this.client = new NextcloudPublicShare({
|
||||
shareUrl: process.env.SECRET_NEXTCLOUD_COOKBOOK_SHARE_URL,
|
||||
password: process.env.SECRET_NEXTCLOUD_COOKBOOK_SHARE_PASSWORD || ""
|
||||
});
|
||||
this.stateReady.then(async () => {
|
||||
this.sendSocketNotification("STATE", this.publicState());
|
||||
await this.restoreRecipe();
|
||||
}).catch((error) => this.setError(error));
|
||||
},
|
||||
|
||||
configureClient() {
|
||||
const shareUrl = process.env.SECRET_NEXTCLOUD_COOKBOOK_SHARE_URL;
|
||||
this.client = shareUrl
|
||||
? new NextcloudPublicShare({
|
||||
shareUrl,
|
||||
password: process.env.SECRET_NEXTCLOUD_COOKBOOK_SHARE_PASSWORD || ""
|
||||
})
|
||||
: null;
|
||||
},
|
||||
|
||||
registerRoutes() {
|
||||
this.expressApp.use("/MMM-NextcloudCookbook/api", express.json({ limit: "16kb" }));
|
||||
this.expressApp.get("/MMM-NextcloudCookbook/control", (_request, response) => {
|
||||
|
||||
Reference in New Issue
Block a user