forked from misskey-dev/misskey
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #352 from merge-upstream
- Loading branch information
Showing
25 changed files
with
1,949 additions
and
1,210 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
24 changes: 24 additions & 0 deletions
24
packages/backend/migration/1704959805077-bubble-game-record.js
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,24 @@ | ||
/* | ||
* SPDX-FileCopyrightText: syuilo and other misskey contributors | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
export class BubbleGameRecord1704959805077 { | ||
name = 'BubbleGameRecord1704959805077' | ||
|
||
async up(queryRunner) { | ||
await queryRunner.query(`CREATE TABLE "bubble_game_record" ("id" character varying(32) NOT NULL, "userId" character varying(32) NOT NULL, "seededAt" TIMESTAMP WITH TIME ZONE NOT NULL, "seed" character varying(1024) NOT NULL, "gameVersion" integer NOT NULL, "gameMode" character varying(128) NOT NULL, "score" integer NOT NULL, "logs" jsonb NOT NULL DEFAULT '[]', "isVerified" boolean NOT NULL DEFAULT false, CONSTRAINT "PK_a75395fe404b392e2893b50d7ea" PRIMARY KEY ("id"))`); | ||
await queryRunner.query(`CREATE INDEX "IDX_75276757070d21fdfaf4c05290" ON "bubble_game_record" ("userId") `); | ||
await queryRunner.query(`CREATE INDEX "IDX_4ae7053179014915d1432d3f40" ON "bubble_game_record" ("seededAt") `); | ||
await queryRunner.query(`CREATE INDEX "IDX_26d4ee490b5a487142d35466ee" ON "bubble_game_record" ("score") `); | ||
await queryRunner.query(`ALTER TABLE "bubble_game_record" ADD CONSTRAINT "FK_75276757070d21fdfaf4c052909" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); | ||
} | ||
|
||
async down(queryRunner) { | ||
await queryRunner.query(`ALTER TABLE "bubble_game_record" DROP CONSTRAINT "FK_75276757070d21fdfaf4c052909"`); | ||
await queryRunner.query(`DROP INDEX "public"."IDX_26d4ee490b5a487142d35466ee"`); | ||
await queryRunner.query(`DROP INDEX "public"."IDX_4ae7053179014915d1432d3f40"`); | ||
await queryRunner.query(`DROP INDEX "public"."IDX_75276757070d21fdfaf4c05290"`); | ||
await queryRunner.query(`DROP TABLE "bubble_game_record"`); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* SPDX-FileCopyrightText: syuilo and other misskey contributors | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
import { PrimaryColumn, Entity, Index, JoinColumn, Column, ManyToOne } from 'typeorm'; | ||
import { id } from './util/id.js'; | ||
import { MiUser } from './User.js'; | ||
|
||
@Entity('bubble_game_record') | ||
export class MiBubbleGameRecord { | ||
@PrimaryColumn(id()) | ||
public id: string; | ||
|
||
@Index() | ||
@Column({ | ||
...id(), | ||
}) | ||
public userId: MiUser['id']; | ||
|
||
@ManyToOne(type => MiUser, { | ||
onDelete: 'CASCADE', | ||
}) | ||
@JoinColumn() | ||
public user: MiUser | null; | ||
|
||
@Index() | ||
@Column('timestamp with time zone') | ||
public seededAt: Date; | ||
|
||
@Column('varchar', { | ||
length: 1024, | ||
}) | ||
public seed: string; | ||
|
||
@Column('integer') | ||
public gameVersion: number; | ||
|
||
@Column('varchar', { | ||
length: 128, | ||
}) | ||
public gameMode: string; | ||
|
||
@Index() | ||
@Column('integer') | ||
public score: number; | ||
|
||
@Column('jsonb', { | ||
default: [], | ||
}) | ||
public logs: any[]; | ||
|
||
@Column('boolean', { | ||
default: false, | ||
}) | ||
public isVerified: boolean; | ||
} |
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
73 changes: 73 additions & 0 deletions
73
packages/backend/src/server/api/endpoints/bubble-game/ranking.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,73 @@ | ||
/* | ||
* SPDX-FileCopyrightText: syuilo and other misskey contributors | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
import { Inject, Injectable } from '@nestjs/common'; | ||
import { MoreThan } from 'typeorm'; | ||
import { Endpoint } from '@/server/api/endpoint-base.js'; | ||
import type { BubbleGameRecordsRepository } from '@/models/_.js'; | ||
import { DI } from '@/di-symbols.js'; | ||
import { UserEntityService } from '@/core/entities/UserEntityService.js'; | ||
|
||
export const meta = { | ||
allowGet: true, | ||
cacheSec: 60, | ||
|
||
errors: { | ||
}, | ||
|
||
res: { | ||
type: 'array', | ||
optional: false, nullable: false, | ||
items: { | ||
type: 'object', | ||
optional: false, nullable: false, | ||
properties: { | ||
id: { type: 'string', format: 'misskey:id' }, | ||
score: { type: 'integer' }, | ||
user: { ref: 'UserLite' }, | ||
}, | ||
}, | ||
}, | ||
} as const; | ||
|
||
export const paramDef = { | ||
type: 'object', | ||
properties: { | ||
gameMode: { type: 'string' }, | ||
}, | ||
required: ['gameMode'], | ||
} as const; | ||
|
||
@Injectable() | ||
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export | ||
constructor( | ||
@Inject(DI.bubbleGameRecordsRepository) | ||
private bubbleGameRecordsRepository: BubbleGameRecordsRepository, | ||
|
||
private userEntityService: UserEntityService, | ||
) { | ||
super(meta, paramDef, async (ps) => { | ||
const records = await this.bubbleGameRecordsRepository.find({ | ||
where: { | ||
gameMode: ps.gameMode, | ||
seededAt: MoreThan(new Date(Date.now() - 1000 * 60 * 60 * 24 * 7)), | ||
}, | ||
order: { | ||
score: 'DESC', | ||
}, | ||
take: 10, | ||
relations: ['user'], | ||
}); | ||
|
||
const users = await this.userEntityService.packMany(records.map(r => r.user!), null, { detail: false }); | ||
|
||
return records.map(r => ({ | ||
id: r.id, | ||
score: r.score, | ||
user: users.find(u => u.id === r.user!.id), | ||
})); | ||
}); | ||
} | ||
} |
Oops, something went wrong.