enigma-bbs/core/download_queue.js
Bryan Ashby a7c0f2b7b0 * Add FileBaseFilters
* Add HTTP(S) file web server with temp URLs
* Get temp web d/l from file list
* Add File area filter editor (all file area stuff will be rename to file "base" later)
* Concept of "listening servers" vs "login servers"
* Ability to get servers by their package name
* New MCI: %FN: File Base active filter name
* Some ES6 updates
* VC resetInitialFocus() to set focus to explicit/detected initial focus field
* Limit what is dumped out when logging form data
2016-10-24 21:49:45 -06:00

49 lines
1.1 KiB
JavaScript

/* jslint node: true */
'use strict';
const FileEntry = require('./file_entry.js');
module.exports = class DownloadQueue {
constructor(client) {
this.client = client;
this.loadFromProperty(client);
}
toggle(fileEntry) {
if(this.isQueued(fileEntry)) {
this.client.user.downloadQueue = this.client.user.downloadQueue.filter(e => fileEntry.fileId !== e.fileId);
} else {
this.add(fileEntry);
}
}
add(fileEntry) {
this.client.user.downloadQueue.push({
fileId : fileEntry.fileId,
areaTag : fileEntry.areaTag,
fileName : fileEntry.fileName,
byteSize : fileEntry.meta.byteSize || 0,
});
}
isQueued(entryOrId) {
if(entryOrId instanceof FileEntry) {
entryOrId = entryOrId.fileId;
}
return this.client.user.downloadQueue.find(e => entryOrId === e.fileId) ? true : false;
}
toProperty() { return JSON.stringify(this.client.user.downloadQueue); }
loadFromProperty(prop) {
try {
this.client.user.downloadQueue = JSON.parse(prop);
} catch(e) {
this.client.user.downloadQueue = [];
this.client.log.error( { error : e.message, property : prop }, 'Failed parsing download queue property');
}
}
};