diff options
| author | かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com> | 2024-08-16 21:02:12 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-16 21:02:12 +0900 |
| commit | a8810af8d9a78c0819781001ab045a9c8cf9d171 (patch) | |
| tree | 5394547362eba377f244d39a28fd9e943caa8302 /packages/backend/src/core/ReversiService.ts | |
| parent | enhance(frontend): improve usability (diff) | |
| download | sharkey-a8810af8d9a78c0819781001ab045a9c8cf9d171.tar.gz sharkey-a8810af8d9a78c0819781001ab045a9c8cf9d171.tar.bz2 sharkey-a8810af8d9a78c0819781001ab045a9c8cf9d171.zip | |
fix(backend): リバーシの設定変更が反映されないのを修正 (#14404)
* fix(backend): リバーシの設定変更が反映されないのを修正
* Update Changelog
* add bindthis
Diffstat (limited to 'packages/backend/src/core/ReversiService.ts')
| -rw-r--r-- | packages/backend/src/core/ReversiService.ts | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/packages/backend/src/core/ReversiService.ts b/packages/backend/src/core/ReversiService.ts index 7f939b99c7..51dca3da59 100644 --- a/packages/backend/src/core/ReversiService.ts +++ b/packages/backend/src/core/ReversiService.ts @@ -6,6 +6,7 @@ import { Inject, Injectable } from '@nestjs/common'; import * as Redis from 'ioredis'; import { ModuleRef } from '@nestjs/core'; +import { reversiUpdateKeys } from 'misskey-js'; import * as Reversi from 'misskey-reversi'; import { IsNull, LessThan, MoreThan } from 'typeorm'; import type { @@ -399,7 +400,33 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit { } @bindThis - public async updateSettings(gameId: MiReversiGame['id'], user: MiUser, key: string, value: any) { + public isValidReversiUpdateKey(key: unknown): key is typeof reversiUpdateKeys[number] { + if (typeof key !== 'string') return false; + return (reversiUpdateKeys as string[]).includes(key); + } + + @bindThis + public isValidReversiUpdateValue<K extends typeof reversiUpdateKeys[number]>(key: K, value: unknown): value is MiReversiGame[K] { + switch (key) { + case 'map': + return Array.isArray(value) && value.every(row => typeof row === 'string'); + case 'bw': + return typeof value === 'string' && ['random', '1', '2'].includes(value); + case 'isLlotheo': + return typeof value === 'boolean'; + case 'canPutEverywhere': + return typeof value === 'boolean'; + case 'loopedBoard': + return typeof value === 'boolean'; + case 'timeLimitForEachTurn': + return typeof value === 'number' && value >= 0; + default: + return false; + } + } + + @bindThis + public async updateSettings<K extends typeof reversiUpdateKeys[number]>(gameId: MiReversiGame['id'], user: MiUser, key: K, value: MiReversiGame[K]) { const game = await this.get(gameId); if (game == null) throw new Error('game not found'); if (game.isStarted) return; @@ -407,10 +434,6 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit { if ((game.user1Id === user.id) && game.user1Ready) return; if ((game.user2Id === user.id) && game.user2Ready) return; - if (!['map', 'bw', 'isLlotheo', 'canPutEverywhere', 'loopedBoard', 'timeLimitForEachTurn'].includes(key)) return; - - // TODO: より厳格なバリデーション - const updatedGame = { ...game, [key]: value, |