Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions node_helper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require("url"); // for nextcloud
const https = require("https"); // for nextcloud
const fs = require("fs"); // for localdirectory
const {XMLParser} = require('fast-xml-parser'); //for nextcloud response parsing

const NodeHelper = require("node_helper");

Expand Down Expand Up @@ -94,14 +95,8 @@ module.exports = NodeHelper.create({
body += data;
});
response.on("end", function() {
imageList = body.match(/href>\/[^<]+/g);
imageList.shift(); // delete first array entry, because it contains the link to the current folder
imageList = self.extractImagesFromResponse(body, urlParts);
if (imageList && imageList.length > 0) {
imageList.forEach(function(item, index) {
// remove clutter and the pathing from the entry -> only save file name
imageList[index] = item.replace("href>" + urlParts.pathname, "");
//console.log("[" + self.name + "] Found entry: " + imageList[index]);
});
self.sendSocketNotification("IMAGE_LIST", imageList);
return;
} else {
Expand All @@ -116,6 +111,32 @@ module.exports = NodeHelper.create({
});
},

extractImagesFromResponse: function(body, urlParts) {
var imageList = [];

const options = {
ignoreDeclaration: true,
processEntities: false,
removeNSPrefix: true,
};

const parser = new XMLParser(options);
let jObj = parser.parse(body).multistatus.response;
for (const item in jObj) {
if (Object.hasOwnProperty.call(jObj, item)) {
const element = jObj[item];
if (element.propstat[0]) {
if (element.propstat[0].prop) {
if (element.propstat[0].prop.getcontenttype && element.propstat[0].prop.getcontenttype.startsWith('image/')) {
imageList.push(element.href.replace(urlParts.pathname, ''));
}
}
}
}
}
return imageList;
},


fetchEncodedImage: async function(passedImageName) {
var self = this;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"author": "skuethe",
"license": "ISC",
"dependencies": {
"fast-xml-parser": "^4.0.5",
"jquery": "^3.1.0"
}
}