ディレクトリ再編
This commit is contained in:
parent
cb924ff92b
commit
85d471efbb
45 changed files with 204 additions and 41 deletions
15
src/backend/controllers/meta.ts
Normal file
15
src/backend/controllers/meta.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
/**
|
||||
* バージョン情報など、サーバーのメタデータを返すAPI
|
||||
* @author Xeltica
|
||||
*/
|
||||
|
||||
import { Get, JsonController } from 'routing-controllers';
|
||||
|
||||
@JsonController('/meta')
|
||||
export class MetaController {
|
||||
@Get() get() {
|
||||
return {
|
||||
honi: 'ほに',
|
||||
};
|
||||
}
|
||||
}
|
31
src/backend/controllers/ranking.ts
Normal file
31
src/backend/controllers/ranking.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
/**
|
||||
* ランキング一覧取得API
|
||||
* @author Xeltica
|
||||
*/
|
||||
|
||||
import { Get, JsonController, QueryParam } from 'routing-controllers';
|
||||
import { getRanking } from '../functions/ranking';
|
||||
import { getUserCount } from '../functions/users';
|
||||
import { getState } from '../store';
|
||||
|
||||
@JsonController('/ranking')
|
||||
export class RankingController {
|
||||
@Get()
|
||||
async get(@QueryParam('limit', { required: false }) limit?: string) {
|
||||
return this.getResponse(getState().nowCalculating, limit ? Number(limit) : undefined);
|
||||
}
|
||||
|
||||
private async getResponse(isCalculating: boolean, limit?: number) {
|
||||
const ranking = isCalculating ? [] : (await getRanking(limit)).map((u) => ({
|
||||
id: u.id,
|
||||
username: u.username,
|
||||
host: u.host,
|
||||
rating: u.rating,
|
||||
}));
|
||||
return {
|
||||
isCalculating,
|
||||
userCount: await getUserCount(),
|
||||
ranking,
|
||||
};
|
||||
}
|
||||
}
|
14
src/backend/controllers/session.ts
Normal file
14
src/backend/controllers/session.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
/**
|
||||
* トークンを必要とするセッションAPI
|
||||
* @author Xeltica
|
||||
*/
|
||||
|
||||
import { CurrentUser, Get, JsonController } from 'routing-controllers';
|
||||
import { User } from '../models/entities/user';
|
||||
|
||||
@JsonController('/session')
|
||||
export class SessionController {
|
||||
@Get() get(@CurrentUser({ required: true }) user: User) {
|
||||
return user;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue