RSNewWebUI/webui-src/app/files/files_proxy.js
2026-02-19 10:51:57 +01:00

30 lines
778 B
JavaScript

const m = require('mithril');
const rs = require('rswebui');
const futil = require('files/files_util');
const fileProxyObj = futil.createProxy({}, () => {
m.redraw();
});
rs.events[rs.RsEventsType.FILE_TRANSFER] = {
handler: (event) => {
// if request item doesn't already exists in Object then create new item
if (!Object.prototype.hasOwnProperty.call(fileProxyObj, event.mRequestId)) {
fileProxyObj[event.mRequestId] = [];
}
event.mResults.forEach((newRes) => {
const isAlt = fileProxyObj[event.mRequestId].some(
(oldRes) => oldRes.fHash === newRes.fHash && oldRes.fName === newRes.fName
);
if (!isAlt) {
fileProxyObj[event.mRequestId].push(newRes);
}
});
},
};
module.exports = {
fileProxyObj,
};