From 28d2d38fce7012c6f9d48dc52a0bf2efd1e8c652 Mon Sep 17 00:00:00 2001 From: otofune Date: Tue, 14 Nov 2017 05:26:27 +0900 Subject: server - multerがテンポラリディレクトリにファイルを展開するように MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DiskStorageをオプション無しで呼ぶといい感じになる またチェーンを改行するようにし、デバッグ表示にパスが出るようにした --- src/api/common/add-file-to-drive.ts | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'src/api/common') diff --git a/src/api/common/add-file-to-drive.ts b/src/api/common/add-file-to-drive.ts index 7defbc631a..9ed5e88744 100644 --- a/src/api/common/add-file-to-drive.ts +++ b/src/api/common/add-file-to-drive.ts @@ -40,7 +40,7 @@ const addFile = async ( folderId: mongodb.ObjectID = null, force: boolean = false ) => { - log(`registering ${name} (user: ${user.username})`); + log(`registering ${name} (user: ${user.username}, path: ${path})`); // Calculate hash, get content type and get file size const [hash, [mime, ext], size] = await Promise.all([ @@ -210,18 +210,19 @@ export default (user: any, file: string | stream.Readable, ...args) => new Promi .catch(rej); } rej(new Error('un-compatible file.')); - }).then(([path, remove]): Promise => new Promise((res, rej) => { - addFile(user, path, ...args) - .then(file => { - res(file); - if (remove) { - fs.unlink(path, (e) => { - if (e) log(e.stack); - }); - } - }) - .catch(rej); - })) + }) + .then(([path, remove]): Promise => new Promise((res, rej) => { + addFile(user, path, ...args) + .then(file => { + res(file); + if (remove) { + fs.unlink(path, (e) => { + if (e) log(e.stack); + }); + } + }) + .catch(rej); + })) .then(file => { log(`drive file has been created ${file._id}`); resolve(file); -- cgit v1.2.3-freya