From fd06fd4dc18313100db3f06e771c3c4258f24176 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 10 Sep 2018 01:51:46 +0900 Subject: [PATCH] Resolve #2560 --- src/server/api/endpoints/notes/create.ts | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/server/api/endpoints/notes/create.ts b/src/server/api/endpoints/notes/create.ts index 47b53c943b..96745132a3 100644 --- a/src/server/api/endpoints/notes/create.ts +++ b/src/server/api/endpoints/notes/create.ts @@ -132,25 +132,14 @@ export default (params: any, user: ILocalUser, app: IApp) => new Promise(async ( let files: IDriveFile[] = []; const fileIds = ps.fileIds != null ? ps.fileIds : ps.mediaIds != null ? ps.mediaIds : null; if (fileIds != null) { - // Fetch files - // forEach だと途中でエラーなどがあっても return できないので - // 敢えて for を使っています。 - for (const fileId of fileIds) { - // Fetch file - // SELECT _id - const entity = await DriveFile.findOne({ + files = await Promise.all(fileIds.map(fileId => { + return DriveFile.findOne({ _id: fileId, 'metadata.userId': user._id }); + })); - if (entity === null) { - return rej('file not found'); - } else { - files.push(entity); - } - } - } else { - files = null; + files = files.filter(file => file != null); } let renote: INote = null;