Initialize share client when helper starts

This commit is contained in:
2026-08-03 15:29:28 -05:00
parent 464ae4159d
commit 91a027eac8
+11 -5
View File
@@ -11,7 +11,7 @@ module.exports = NodeHelper.create({
this.state = { active: false, recipeId: null, recipe: null, error: null }; this.state = { active: false, recipeId: null, recipe: null, error: null };
this.recipeCache = { expires: 0, recipes: [] }; this.recipeCache = { expires: 0, recipes: [] };
this.stateFile = path.join(process.cwd(), "config", "MMM-NextcloudCookbook-state.json"); this.stateFile = path.join(process.cwd(), "config", "MMM-NextcloudCookbook-state.json");
this.client = null; this.configureClient();
this.registerRoutes(); this.registerRoutes();
this.stateReady = this.loadState().catch((error) => this.setError(error)); this.stateReady = this.loadState().catch((error) => this.setError(error));
}, },
@@ -19,16 +19,22 @@ module.exports = NodeHelper.create({
socketNotificationReceived(notification, payload) { socketNotificationReceived(notification, payload) {
if (notification !== "CONFIG") return; if (notification !== "CONFIG") return;
this.config = { ...this.config, ...payload }; 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.stateReady.then(async () => {
this.sendSocketNotification("STATE", this.publicState()); this.sendSocketNotification("STATE", this.publicState());
await this.restoreRecipe(); await this.restoreRecipe();
}).catch((error) => this.setError(error)); }).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() { registerRoutes() {
this.expressApp.use("/MMM-NextcloudCookbook/api", express.json({ limit: "16kb" })); this.expressApp.use("/MMM-NextcloudCookbook/api", express.json({ limit: "16kb" }));
this.expressApp.get("/MMM-NextcloudCookbook/control", (_request, response) => { this.expressApp.get("/MMM-NextcloudCookbook/control", (_request, response) => {