From 28d2d38fce7012c6f9d48dc52a0bf2efd1e8c652 Mon Sep 17 00:00:00 2001 From: otofune Date: Tue, 14 Nov 2017 05:26:27 +0900 Subject: [PATCH 1/2] =?UTF-8?q?server=20-=20multer=E3=81=8C=E3=83=86?= =?UTF-8?q?=E3=83=B3=E3=83=9D=E3=83=A9=E3=83=AA=E3=83=87=E3=82=A3=E3=83=AC?= =?UTF-8?q?=E3=82=AF=E3=83=88=E3=83=AA=E3=81=AB=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E3=82=92=E5=B1=95=E9=96=8B=E3=81=99=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB?= 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 ++++++++++++++------------- src/api/server.ts | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-) 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); diff --git a/src/api/server.ts b/src/api/server.ts index 3de32d9eab..026357b465 100644 --- a/src/api/server.ts +++ b/src/api/server.ts @@ -40,7 +40,7 @@ app.get('/', (req, res) => { endpoints.forEach(endpoint => endpoint.withFile ? app.post(`/${endpoint.name}`, - endpoint.withFile ? multer({ dest: 'uploads/' }).single('file') : null, + endpoint.withFile ? multer({ storage: multer.diskStorage({}) }).single('file') : null, require('./api-handler').default.bind(null, endpoint)) : app.post(`/${endpoint.name}`, require('./api-handler').default.bind(null, endpoint)) From 7f2400ae0009ab0468cbcda795e33a51660cdb93 Mon Sep 17 00:00:00 2001 From: otofune Date: Tue, 14 Nov 2017 05:30:05 +0900 Subject: [PATCH 2/2] =?UTF-8?q?.gitignore=20-=20uploads=20=E3=82=92?= =?UTF-8?q?=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit もう作られることはない --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 2ae0f98c5e..a51e70381e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ /.vscode /node_modules /built -/uploads /data npm-debug.log *.pem