mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-06-10 14:44:40 +02:00
ENiGMA 1/2 WILL USE SPACES FROM THIS POINT ON VS TABS
* Really just to make GitHub formatting happy. Arg.
This commit is contained in:
parent
5ddf04c882
commit
e9787cee3e
135 changed files with 27397 additions and 27397 deletions
|
@ -7,72 +7,72 @@ const FileEntry = require('./file_entry.js');
|
|||
const { partition } = require('lodash');
|
||||
|
||||
module.exports = class DownloadQueue {
|
||||
constructor(client) {
|
||||
this.client = client;
|
||||
constructor(client) {
|
||||
this.client = client;
|
||||
|
||||
if(!Array.isArray(this.client.user.downloadQueue)) {
|
||||
if(this.client.user.properties.dl_queue) {
|
||||
this.loadFromProperty(this.client.user.properties.dl_queue);
|
||||
} else {
|
||||
this.client.user.downloadQueue = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!Array.isArray(this.client.user.downloadQueue)) {
|
||||
if(this.client.user.properties.dl_queue) {
|
||||
this.loadFromProperty(this.client.user.properties.dl_queue);
|
||||
} else {
|
||||
this.client.user.downloadQueue = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get items() {
|
||||
return this.client.user.downloadQueue;
|
||||
}
|
||||
get items() {
|
||||
return this.client.user.downloadQueue;
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.client.user.downloadQueue = [];
|
||||
}
|
||||
clear() {
|
||||
this.client.user.downloadQueue = [];
|
||||
}
|
||||
|
||||
toggle(fileEntry, systemFile=false) {
|
||||
if(this.isQueued(fileEntry)) {
|
||||
this.client.user.downloadQueue = this.client.user.downloadQueue.filter(e => fileEntry.fileId !== e.fileId);
|
||||
} else {
|
||||
this.add(fileEntry, systemFile);
|
||||
}
|
||||
}
|
||||
toggle(fileEntry, systemFile=false) {
|
||||
if(this.isQueued(fileEntry)) {
|
||||
this.client.user.downloadQueue = this.client.user.downloadQueue.filter(e => fileEntry.fileId !== e.fileId);
|
||||
} else {
|
||||
this.add(fileEntry, systemFile);
|
||||
}
|
||||
}
|
||||
|
||||
add(fileEntry, systemFile=false) {
|
||||
this.client.user.downloadQueue.push({
|
||||
fileId : fileEntry.fileId,
|
||||
areaTag : fileEntry.areaTag,
|
||||
fileName : fileEntry.fileName,
|
||||
path : fileEntry.filePath,
|
||||
byteSize : fileEntry.meta.byte_size || 0,
|
||||
systemFile : systemFile,
|
||||
});
|
||||
}
|
||||
add(fileEntry, systemFile=false) {
|
||||
this.client.user.downloadQueue.push({
|
||||
fileId : fileEntry.fileId,
|
||||
areaTag : fileEntry.areaTag,
|
||||
fileName : fileEntry.fileName,
|
||||
path : fileEntry.filePath,
|
||||
byteSize : fileEntry.meta.byte_size || 0,
|
||||
systemFile : systemFile,
|
||||
});
|
||||
}
|
||||
|
||||
removeItems(fileIds) {
|
||||
if(!Array.isArray(fileIds)) {
|
||||
fileIds = [ fileIds ];
|
||||
}
|
||||
removeItems(fileIds) {
|
||||
if(!Array.isArray(fileIds)) {
|
||||
fileIds = [ fileIds ];
|
||||
}
|
||||
|
||||
const [ remain, removed ] = partition(this.client.user.downloadQueue, e => ( -1 === fileIds.indexOf(e.fileId) ));
|
||||
this.client.user.downloadQueue = remain;
|
||||
return removed;
|
||||
}
|
||||
const [ remain, removed ] = partition(this.client.user.downloadQueue, e => ( -1 === fileIds.indexOf(e.fileId) ));
|
||||
this.client.user.downloadQueue = remain;
|
||||
return removed;
|
||||
}
|
||||
|
||||
isQueued(entryOrId) {
|
||||
if(entryOrId instanceof FileEntry) {
|
||||
entryOrId = entryOrId.fileId;
|
||||
}
|
||||
isQueued(entryOrId) {
|
||||
if(entryOrId instanceof FileEntry) {
|
||||
entryOrId = entryOrId.fileId;
|
||||
}
|
||||
|
||||
return this.client.user.downloadQueue.find(e => entryOrId === e.fileId) ? true : false;
|
||||
}
|
||||
return this.client.user.downloadQueue.find(e => entryOrId === e.fileId) ? true : false;
|
||||
}
|
||||
|
||||
toProperty() { return JSON.stringify(this.client.user.downloadQueue); }
|
||||
toProperty() { return JSON.stringify(this.client.user.downloadQueue); }
|
||||
|
||||
loadFromProperty(prop) {
|
||||
try {
|
||||
this.client.user.downloadQueue = JSON.parse(prop);
|
||||
} catch(e) {
|
||||
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');
|
||||
}
|
||||
}
|
||||
this.client.log.error( { error : e.message, property : prop }, 'Failed parsing download queue property');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue