|
|
@@ -69,7 +69,10 @@ let downloadQueue = queue(3, function(job, done) {
|
|
|
async function checkFalse() {
|
|
|
//下载,下载队列为空,把所有状态为downloading的状态改为ERROR
|
|
|
let downloadList = (await db.Download.findAll({
|
|
|
- where: { status: DownloadStatus.DOWNLOADING, status: DownloadStatus.WAITING },
|
|
|
+ where: {
|
|
|
+ status: DownloadStatus.DOWNLOADING,
|
|
|
+ status: DownloadStatus.WAITING,
|
|
|
+ },
|
|
|
})).map(i => i.get());
|
|
|
downloadList.forEach(async i => {
|
|
|
await db.Download.update(
|
|
|
@@ -85,9 +88,9 @@ async function checkFalse() {
|
|
|
});
|
|
|
|
|
|
//上传
|
|
|
- let fileList = (await db.File.findAll({ where: { status: UploadStatus.UPLOADING } })).map(i =>
|
|
|
- i.get(),
|
|
|
- );
|
|
|
+ let fileList = (await db.File.findAll({
|
|
|
+ where: { status: UploadStatus.UPLOADING },
|
|
|
+ })).map(i => i.get());
|
|
|
fileList.forEach(async i => {
|
|
|
await db.File.update(
|
|
|
{
|
|
|
@@ -116,6 +119,10 @@ const init = async () => {
|
|
|
resume();
|
|
|
|
|
|
initiated = true;
|
|
|
+
|
|
|
+ setTimeout(() => {
|
|
|
+ deleteUploadedFile();
|
|
|
+ }, 0 * 1000);
|
|
|
};
|
|
|
|
|
|
const PromiseQueue = arr => {
|
|
|
@@ -412,7 +419,9 @@ const uploadOrder = async (topDir, prefixes, userId, clientOrderId) => {
|
|
|
let archiveFile = await archive(topDir, outPath);
|
|
|
let info = fs.statSync(archiveFile);
|
|
|
await sequelize.query(`UPDATE SubOrders
|
|
|
- SET size = ( SELECT SUM( size ) FROM Files WHERE subOrderId = ${subOrder.id} )
|
|
|
+ SET size = ( SELECT SUM( size ) FROM Files WHERE subOrderId = ${
|
|
|
+ subOrder.id
|
|
|
+ } )
|
|
|
WHERE id = ${subOrder.id}`);
|
|
|
await db.File.update(
|
|
|
{
|
|
|
@@ -449,8 +458,17 @@ const uploadOrder = async (topDir, prefixes, userId, clientOrderId) => {
|
|
|
progress: 0,
|
|
|
status: UploadStatus.PREPARING,
|
|
|
})).get();
|
|
|
- await readDir(path.resolve(topDir, child), orderId, subOrder.id, child, prefix);
|
|
|
- let archiveFile = await archive(path.resolve(topDir, child), outPath);
|
|
|
+ await readDir(
|
|
|
+ path.resolve(topDir, child),
|
|
|
+ orderId,
|
|
|
+ subOrder.id,
|
|
|
+ child,
|
|
|
+ prefix,
|
|
|
+ );
|
|
|
+ let archiveFile = await archive(
|
|
|
+ path.resolve(topDir, child),
|
|
|
+ outPath,
|
|
|
+ );
|
|
|
let info = fs.statSync(archiveFile);
|
|
|
await db.File.update(
|
|
|
{
|
|
|
@@ -483,12 +501,27 @@ const uploadOrder = async (topDir, prefixes, userId, clientOrderId) => {
|
|
|
);
|
|
|
} else {
|
|
|
let filepath = path.resolve(dir, child);
|
|
|
- const buffer = readChunk.sync(filepath, 0, fileType.minimumBytes);
|
|
|
+ const buffer = readChunk.sync(
|
|
|
+ filepath,
|
|
|
+ 0,
|
|
|
+ fileType.minimumBytes,
|
|
|
+ );
|
|
|
let type = fileType(buffer);
|
|
|
let src = filepath;
|
|
|
let dst = currRelative;
|
|
|
if (type && type.mime.startsWith('image')) {
|
|
|
- src = await ImageUtils.makeThumbnail(filepath);
|
|
|
+ if (/tif|bmp|gif/i.test(type.ext)) {
|
|
|
+ let tmpFile = path.resolve(
|
|
|
+ app.getPath('userData'),
|
|
|
+ 'tmp',
|
|
|
+ uuidv1() + '.jpg',
|
|
|
+ );
|
|
|
+ fs.copyFileSync(filepath, tmpFile);
|
|
|
+ src = tmpFile;
|
|
|
+ } else {
|
|
|
+ src = await ImageUtils.makeThumbnail(filepath);
|
|
|
+ }
|
|
|
+
|
|
|
// dst = orderId + "/" + relative + '/' + transferFilename(path.basename(currRelative))
|
|
|
dst =
|
|
|
prefix +
|
|
|
@@ -527,7 +560,9 @@ const archive = async (dir, outPath) => {
|
|
|
// 'close' event is fired only when a file descriptor is involved
|
|
|
output.on('close', function() {
|
|
|
console.log(archive.pointer() + ' total bytes');
|
|
|
- console.log('archiver has been finalized and the output file descriptor has closed.');
|
|
|
+ console.log(
|
|
|
+ 'archiver has been finalized and the output file descriptor has closed.',
|
|
|
+ );
|
|
|
resolve(outPath);
|
|
|
});
|
|
|
|
|
|
@@ -645,7 +680,13 @@ async function getFilePath(pathName, i) {
|
|
|
return _path;
|
|
|
}
|
|
|
|
|
|
-const downloadFile = async (objectName, orderName, userId, quantity, userOrderId) => {
|
|
|
+const downloadFile = async (
|
|
|
+ objectName,
|
|
|
+ orderName,
|
|
|
+ userId,
|
|
|
+ quantity,
|
|
|
+ userOrderId,
|
|
|
+) => {
|
|
|
let pathName = await getFilePath(userOrderId + '_' + orderName, 0);
|
|
|
let download = (await db.Download.create({
|
|
|
dst: objectName,
|