WIP
This commit is contained in:
parent
2d9d8782f6
commit
75601a80ec
90
core/fse.js
90
core/fse.js
|
@ -26,12 +26,19 @@ const { getAddressedToInfo } = require('./mail_util.js');
|
||||||
const Events = require('./events.js');
|
const Events = require('./events.js');
|
||||||
const UserProps = require('./user_property.js');
|
const UserProps = require('./user_property.js');
|
||||||
const SysProps = require('./system_property.js');
|
const SysProps = require('./system_property.js');
|
||||||
|
const FileArea = require('./file_base_area.js');
|
||||||
|
const FileEntry = require('./file_entry.js');
|
||||||
|
const DownloadQueue = require('./download_queue.js');
|
||||||
|
|
||||||
// deps
|
// deps
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
|
const fse = require('fs-extra');
|
||||||
|
const fs = require('graceful-fs');
|
||||||
|
const paths = require('path');
|
||||||
|
const sanatizeFilename = require('sanitize-filename');
|
||||||
|
|
||||||
exports.moduleInfo = {
|
exports.moduleInfo = {
|
||||||
name : 'Full Screen Editor (FSE)',
|
name : 'Full Screen Editor (FSE)',
|
||||||
|
@ -255,7 +262,12 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
|
||||||
viewModeMenuHelp : function(formData, extraArgs, cb) {
|
viewModeMenuHelp : function(formData, extraArgs, cb) {
|
||||||
self.viewControllers.footerView.setFocus(false);
|
self.viewControllers.footerView.setFocus(false);
|
||||||
return self.displayHelp(cb);
|
return self.displayHelp(cb);
|
||||||
}
|
},
|
||||||
|
|
||||||
|
addToDownloadQueue : (formData, extraArgs, cb) => {
|
||||||
|
this.viewControllers.footerView.setFocus(false);
|
||||||
|
return this.addToDownloadQueue(cb);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -905,6 +917,82 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addToDownloadQueue(cb) {
|
||||||
|
this.client.term.rawWrite(ansi.resetScreen());
|
||||||
|
|
||||||
|
const sysTempDownloadArea = FileArea.getFileAreaByTag(FileArea.WellKnownAreaTags.TempDownloads);
|
||||||
|
const sysTempDownloadDir = FileArea.getAreaDefaultStorageDirectory(sysTempDownloadArea);
|
||||||
|
|
||||||
|
const msgInfo = this.getHeaderFormatObj();
|
||||||
|
|
||||||
|
const outputFileName = paths.join(
|
||||||
|
sysTempDownloadDir,
|
||||||
|
sanatizeFilename(
|
||||||
|
`(${msgInfo.messageId}) ${msgInfo.subject}_(${this.message.modTimestamp.format('YYYY-MM-DD')}).txt`)
|
||||||
|
);
|
||||||
|
|
||||||
|
async.waterfall(
|
||||||
|
[
|
||||||
|
(callback) => {
|
||||||
|
const messageBody = this.viewControllers.body
|
||||||
|
.getView(MciViewIds.body.message)
|
||||||
|
.getData( { forceLineTerms : true } );
|
||||||
|
|
||||||
|
fse.mkdirs(sysTempDownloadDir, err => {
|
||||||
|
return callback(err, messageBody);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
(messageBody, callback) => {
|
||||||
|
return fs.writeFile(outputFileName, messageBody, 'utf8', callback);
|
||||||
|
},
|
||||||
|
(callback) => {
|
||||||
|
fs.stat(outputFileName, (err, stats) => {
|
||||||
|
return callback(err, stats.size);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
(fileSize, callback) => {
|
||||||
|
const newEntry = new FileEntry({
|
||||||
|
areaTag : sysTempDownloadArea.areaTag,
|
||||||
|
fileName : paths.basename(outputFileName),
|
||||||
|
storageTag : sysTempDownloadArea.storageTags[0],
|
||||||
|
meta : {
|
||||||
|
upload_by_username : this.client.user.username,
|
||||||
|
upload_by_user_id : this.client.user.userId,
|
||||||
|
byte_size : fileSize,
|
||||||
|
session_temp_dl : 1, // download is valid until session is over
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
newEntry.desc = `${msgInfo.messageId} - ${msgInfo.subject}`;
|
||||||
|
|
||||||
|
newEntry.persist(err => {
|
||||||
|
if(!err) {
|
||||||
|
// queue it!
|
||||||
|
DownloadQueue.get(this.client).addTemporaryDownload(newEntry);
|
||||||
|
}
|
||||||
|
return callback(err);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
(callback) => {
|
||||||
|
theme.displayThemeArt(
|
||||||
|
{ name : this.menuConfig.config.art.dlQueueAdd || 'msg_add_dl_queue', client : this.client },
|
||||||
|
() => {
|
||||||
|
this.client.waitForKeyPress( () => {
|
||||||
|
this.redrawScreen( () => {
|
||||||
|
this.viewControllers[this.getFooterName()].setFocus(true);
|
||||||
|
return callback(null);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
],
|
||||||
|
err => {
|
||||||
|
return cb(err);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
displayQuoteBuilder() {
|
displayQuoteBuilder() {
|
||||||
//
|
//
|
||||||
// Clear body area
|
// Clear body area
|
||||||
|
|
|
@ -102,11 +102,10 @@ exports.getModule = class AreaViewFSEModule extends FullScreenEditorModule {
|
||||||
|
|
||||||
self.client.log(extraArgs, 'Missing extraArgs.menu');
|
self.client.log(extraArgs, 'Missing extraArgs.menu');
|
||||||
return cb(null);
|
return cb(null);
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
loadMessageByUuid(uuid, cb) {
|
loadMessageByUuid(uuid, cb) {
|
||||||
const msg = new Message();
|
const msg = new Message();
|
||||||
msg.load( { uuid : uuid, user : this.client.user }, () => {
|
msg.load( { uuid : uuid, user : this.client.user }, () => {
|
||||||
|
|
Loading…
Reference in New Issue