From ca4f026533adcab9ad0fcae0dd5d4549362e9458 Mon Sep 17 00:00:00 2001
From: MeiMei <30769358+mei23@users.noreply.github.com>
Date: Tue, 16 Mar 2021 12:50:07 +0900
Subject: [PATCH] =?UTF-8?q?DB=E4=B8=8A=E3=81=A7=E5=A3=8A=E3=82=8C=E3=81=9F?=
 =?UTF-8?q?=E3=83=89=E3=83=A9=E3=82=A4=E3=83=96=E3=83=95=E3=82=A1=E3=82=A4?=
 =?UTF-8?q?=E3=83=AB=E3=82=92=E7=84=A1=E8=A6=96=E3=81=99=E3=82=8B=E3=82=88?=
 =?UTF-8?q?=E3=81=86=E3=81=AB=20(#7345)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/models/repositories/drive-file.ts | 30 ++++++++++++++-------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/src/models/repositories/drive-file.ts b/src/models/repositories/drive-file.ts
index bc1e37489c..62416f69ea 100644
--- a/src/models/repositories/drive-file.ts
+++ b/src/models/repositories/drive-file.ts
@@ -12,6 +12,12 @@ import { fetchMeta } from '../../misc/fetch-meta';
 
 export type PackedDriveFile = SchemaType<typeof packedDriveFileSchema>;
 
+type PackOptions = {
+	detail?: boolean,
+	self?: boolean,
+	withUser?: boolean,
+};
+
 @EntityRepository(DriveFile)
 export class DriveFileRepository extends Repository<DriveFile> {
 	public validateFileName(name: string): boolean {
@@ -89,20 +95,19 @@ export class DriveFileRepository extends Repository<DriveFile> {
 		return parseInt(sum, 10) || 0;
 	}
 
+	public async pack(src: DriveFile['id'], options?: PackOptions): Promise<PackedDriveFile | null>;
+	public async pack(src: DriveFile, options?: PackOptions): Promise<PackedDriveFile>;
 	public async pack(
 		src: DriveFile['id'] | DriveFile,
-		options?: {
-			detail?: boolean,
-			self?: boolean,
-			withUser?: boolean,
-		}
-	): Promise<PackedDriveFile> {
+		options?: PackOptions
+	): Promise<PackedDriveFile | null> {
 		const opts = Object.assign({
 			detail: false,
 			self: false
 		}, options);
 
-		const file = typeof src === 'object' ? src : await this.findOneOrFail(src);
+		const file = typeof src === 'object' ? src : await this.findOne(src);
+		if (file == null) return null;
 
 		const meta = await fetchMeta();
 
@@ -128,15 +133,12 @@ export class DriveFileRepository extends Repository<DriveFile> {
 		});
 	}
 
-	public packMany(
+	public async packMany(
 		files: any[],
-		options?: {
-			detail?: boolean
-			self?: boolean,
-			withUser?: boolean,
-		}
+		options?: PackOptions
 	) {
-		return Promise.all(files.map(f => this.pack(f, options)));
+		const items = await Promise.all(files.map(f => this.pack(f, options)));
+		return items.filter(x => x != null);
 	}
 }
 
-- 
GitLab