I started to play around with MM² just some weeks ago, and am currently in the phase of modifying a Module which displays background images from different sources.
One of these sources is a webdav behind basic authentication. Another source would be a “local directory” on the raspberry pi.
My approach is currently the following:
- Start module, if source is set to “webdav” or “localdirectory” source, issue a
sendSocketNotification to node_helper.js
- node_helper is verifying the sources and creating an array of all images in that source. The array will contain the paths / URLs to each image, so f.e.:
imageList = [
- This array is returned via a new
sendSocketNotification to the module
- The module now has two different approaches:
4.1 if it is webdav WITHOUT authentication, get one of the image src from the array and use it in
4.2 Run a special function if it is webdav WITH authentication OR localdirectory. This special function is basically just base64 encoding one of the images from array and using that for the
4.2 is using base64 encoded images as
Question / Problem
My problem occurs with 4.2, actually running the function to encode the image. As I only return an array with all the image paths / urls from
node_helper and not the acutal images in base64 encoded data (which would probably blow up at some point, f.e. referencing a lot of 4k images), I have to encode them “just in time”. So on each request (images are just shown one at a time as background).
Now to my understanding (and testing) I am unable to add something like
const fs = require("fs"); inside the main module, right? How could I actually fetch local files from the main module then?
Or, if this is not possible, how can I send a request from main module to
node_helper and wait for its return / callback?
The same with the basic auth webdav option.
I tried using jQuery to inject basic auth header on image load, but that just fails with CORS (because the webdav solution currently has a bug with requiring
-X OPTIONS call to be authenticated - which is wrong).
Nevertheless, I could be able to “work around” this bug with using nodes
require("https"). But again, I am unable to include / load this into the main module and would need to wait for direct feedback of the
node_helper on “just in time encoding”.
Am I going into a completly wrong direction here? Any suggestions how to handle this?