forked from misskey-dev/misskey
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance(reversi): improve desync handling
- Loading branch information
1 parent
88b0ad6
commit 2f71b5a
Showing
17 changed files
with
206 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/backend/src/server/api/endpoints/reversi/verify.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* SPDX-FileCopyrightText: syuilo and other misskey contributors | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
import { Injectable } from '@nestjs/common'; | ||
import { Endpoint } from '@/server/api/endpoint-base.js'; | ||
import { ReversiService } from '@/core/ReversiService.js'; | ||
import { ReversiGameEntityService } from '@/core/entities/ReversiGameEntityService.js'; | ||
import { ApiError } from '../../error.js'; | ||
|
||
export const meta = { | ||
errors: { | ||
noSuchGame: { | ||
message: 'No such game.', | ||
code: 'NO_SUCH_GAME', | ||
id: '8fb05624-b525-43dd-90f7-511852bdfeee', | ||
}, | ||
}, | ||
|
||
res: { | ||
type: 'object', | ||
optional: false, nullable: false, | ||
properties: { | ||
desynced: { type: 'boolean' }, | ||
game: { | ||
type: 'object', | ||
optional: true, nullable: true, | ||
ref: 'ReversiGameDetailed', | ||
}, | ||
}, | ||
}, | ||
} as const; | ||
|
||
export const paramDef = { | ||
type: 'object', | ||
properties: { | ||
gameId: { type: 'string', format: 'misskey:id' }, | ||
crc32: { type: 'string' }, | ||
}, | ||
required: ['gameId', 'crc32'], | ||
} as const; | ||
|
||
@Injectable() | ||
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export | ||
constructor( | ||
private reversiService: ReversiService, | ||
private reversiGameEntityService: ReversiGameEntityService, | ||
) { | ||
super(meta, paramDef, async (ps, me) => { | ||
const game = await this.reversiService.checkCrc(ps.gameId, ps.crc32); | ||
if (game) { | ||
return { | ||
desynced: true, | ||
game: await this.reversiGameEntityService.packDetail(game), | ||
}; | ||
} else { | ||
return { | ||
desynced: false, | ||
}; | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.