From 691fe711ffaa8dc273c0892288cff40685341d04 Mon Sep 17 00:00:00 2001 From: Nanashia Date: Fri, 6 Oct 2023 21:05:11 +0900 Subject: [PATCH 1/2] chore: Use pnpm@8.8.0 on DevContainer (#11975) --- .devcontainer/devcontainer.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 861b0008a0..a78d91900b 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -4,7 +4,9 @@ "service": "app", "workspaceFolder": "/workspace", "features": { - "ghcr.io/devcontainers-contrib/features/pnpm:2": {}, + "ghcr.io/devcontainers-contrib/features/pnpm:2": { + "version": "8.8.0" + }, "ghcr.io/devcontainers/features/node:1": { "version": "20.5.1" } From 11e657bdd7c3643451b09129d53a44295a3c6653 Mon Sep 17 00:00:00 2001 From: nenohi Date: Fri, 6 Oct 2023 21:05:44 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E7=B5=B5=E6=96=87=E5=AD=97=E9=87=8D?= =?UTF-8?q?=E8=A4=87=E3=83=81=E3=82=A7=E3=83=83=E3=82=AF=20(#11941)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 絵文字重複チェック * アップデート時のチェック * Update packages/backend/src/core/CustomEmojiService.ts Co-authored-by: syuilo * Update packages/backend/src/server/api/endpoints/admin/emoji/add.ts Co-authored-by: syuilo * Update packages/backend/src/server/api/endpoints/admin/emoji/update.ts Co-authored-by: syuilo --------- Co-authored-by: syuilo --- packages/backend/src/core/CustomEmojiService.ts | 14 ++++++++++++++ .../src/server/api/endpoints/admin/emoji/add.ts | 7 +++++++ .../src/server/api/endpoints/admin/emoji/update.ts | 9 +++++++++ 3 files changed, 30 insertions(+) diff --git a/packages/backend/src/core/CustomEmojiService.ts b/packages/backend/src/core/CustomEmojiService.ts index 9661a0aea3..617893450d 100644 --- a/packages/backend/src/core/CustomEmojiService.ts +++ b/packages/backend/src/core/CustomEmojiService.ts @@ -380,6 +380,20 @@ export class CustomEmojiService implements OnApplicationShutdown { } } + /** + * ローカル内の絵文字に重複がないかチェックします + * @param name 絵文字名 + */ + @bindThis + public checkDuplicate(name: string): Promise { + return this.emojisRepository.exist({ where: { name, host: IsNull() } }); + } + + @bindThis + public getEmojiById(id: string): Promise { + return this.emojisRepository.findOneBy({ id }); + } + @bindThis public dispose(): void { this.cache.dispose(); diff --git a/packages/backend/src/server/api/endpoints/admin/emoji/add.ts b/packages/backend/src/server/api/endpoints/admin/emoji/add.ts index 24d3a8a943..faab8ee608 100644 --- a/packages/backend/src/server/api/endpoints/admin/emoji/add.ts +++ b/packages/backend/src/server/api/endpoints/admin/emoji/add.ts @@ -23,6 +23,11 @@ export const meta = { code: 'NO_SUCH_FILE', id: 'fc46b5a4-6b92-4c33-ac66-b806659bb5cf', }, + duplicateName: { + message: 'Duplicate name.', + code: 'DUPLICATE_NAME', + id: 'f7a3462c-4e6e-4069-8421-b9bd4f4c3975', + }, }, } as const; @@ -64,6 +69,8 @@ export default class extends Endpoint { // eslint- super(meta, paramDef, async (ps, me) => { const driveFile = await this.driveFilesRepository.findOneBy({ id: ps.fileId }); if (driveFile == null) throw new ApiError(meta.errors.noSuchFile); + const isDuplicate = await this.customEmojiService.checkDuplicate(ps.name); + if (isDuplicate) throw new ApiError(meta.errors.duplicateName); const emoji = await this.customEmojiService.add({ driveFile, diff --git a/packages/backend/src/server/api/endpoints/admin/emoji/update.ts b/packages/backend/src/server/api/endpoints/admin/emoji/update.ts index 2d69857408..04226d8953 100644 --- a/packages/backend/src/server/api/endpoints/admin/emoji/update.ts +++ b/packages/backend/src/server/api/endpoints/admin/emoji/update.ts @@ -74,6 +74,15 @@ export default class extends Endpoint { // eslint- driveFile = await this.driveFilesRepository.findOneBy({ id: ps.fileId }); if (driveFile == null) throw new ApiError(meta.errors.noSuchFile); } + const emoji = await this.customEmojiService.getEmojiById(ps.id); + if (emoji != null) { + if (ps.name !== emoji.name) { + const isDuplicate = await this.customEmojiService.checkDuplicate(ps.name); + if (isDuplicate) throw new ApiError(meta.errors.sameNameEmojiExists); + } + } else { + throw new ApiError(meta.errors.noSuchEmoji); + } await this.customEmojiService.update(ps.id, { driveFile,