1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- 'use strict';
- const {
- isFunc,
- debugLog,
- moveFile,
- promiseCallback,
- checkAndMakeDir,
- saveBufferToFile
- } = require('./utilities');
- const moveFromTemp = (filePath, options, fileUploadOptions) => (resolve, reject) => {
- debugLog(fileUploadOptions, `Moving temporary file ${options.tempFilePath} to ${filePath}`);
- moveFile(options.tempFilePath, filePath, promiseCallback(resolve, reject));
- };
- const moveFromBuffer = (filePath, options, fileUploadOptions) => (resolve, reject) => {
- debugLog(fileUploadOptions, `Moving uploaded buffer to ${filePath}`);
- saveBufferToFile(options.buffer, filePath, promiseCallback(resolve, reject));
- };
- module.exports = (options, fileUploadOptions = {}) => {
-
-
-
-
-
-
- return {
- name: options.name,
- data: options.buffer,
- size: options.size,
- encoding: options.encoding,
- tempFilePath: options.tempFilePath,
- truncated: options.truncated,
- mimetype: options.mimetype,
- md5: options.hash,
- mv: (filePath, callback) => {
-
- const moveFunc = fileUploadOptions.useTempFiles
- ? moveFromTemp(filePath, options, fileUploadOptions)
- : moveFromBuffer(filePath, options, fileUploadOptions);
-
- checkAndMakeDir(fileUploadOptions, filePath);
-
- return isFunc(callback) ? moveFunc(callback) : new Promise(moveFunc);
- }
- };
- };
|