mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-07-30 22:46:17 +02:00
Code cleanup, use some defaults
This commit is contained in:
parent
ee992278e8
commit
9174b7b710
4 changed files with 81 additions and 69 deletions
|
@ -1,11 +1,12 @@
|
|||
/* jslint node: true */
|
||||
'use strict';
|
||||
|
||||
const FileEntry = require('./file_entry.js');
|
||||
const UserProps = require('./user_property.js');
|
||||
const FileEntry = require('./file_entry');
|
||||
const UserProps = require('./user_property');
|
||||
const Events = require('./events');
|
||||
|
||||
// deps
|
||||
const { partition } = require('lodash');
|
||||
const _ = require('lodash');
|
||||
|
||||
module.exports = class DownloadQueue {
|
||||
constructor(client) {
|
||||
|
@ -20,6 +21,10 @@ module.exports = class DownloadQueue {
|
|||
}
|
||||
}
|
||||
|
||||
static get(client) {
|
||||
return new DownloadQueue(client);
|
||||
}
|
||||
|
||||
get items() {
|
||||
return this.client.user.downloadQueue;
|
||||
}
|
||||
|
@ -52,7 +57,7 @@ module.exports = class DownloadQueue {
|
|||
fileIds = [ fileIds ];
|
||||
}
|
||||
|
||||
const [ remain, removed ] = partition(this.client.user.downloadQueue, e => ( -1 === fileIds.indexOf(e.fileId) ));
|
||||
const [ remain, removed ] = _.partition(this.client.user.downloadQueue, e => ( -1 === fileIds.indexOf(e.fileId) ));
|
||||
this.client.user.downloadQueue = remain;
|
||||
return removed;
|
||||
}
|
||||
|
@ -76,4 +81,23 @@ module.exports = class DownloadQueue {
|
|||
this.client.log.error( { error : e.message, property : prop }, 'Failed parsing download queue property');
|
||||
}
|
||||
}
|
||||
|
||||
addTemporaryDownload(entry) {
|
||||
this.add(entry, true); // true=systemFile
|
||||
|
||||
// clean up after ourselves when the session ends
|
||||
const thisClientId = this.client.session.id;
|
||||
Events.once(Events.getSystemEvents().ClientDisconnected, evt => {
|
||||
if(thisClientId === _.get(evt, 'client.session.id')) {
|
||||
FileEntry.removeEntry(entry, { removePhysFile : true }, err => {
|
||||
const Log = require('./logger').log;
|
||||
if(err) {
|
||||
Log.warn( { fileId : entry.fileId, path : outputFileName }, 'Failed removing temporary session download' );
|
||||
} else {
|
||||
Log.debug( { fileId : entry.fileId, path : outputFileName }, 'Removed temporary session download item' );
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue