73 lines
1.9 KiB
TypeScript
73 lines
1.9 KiB
TypeScript
import { ChunithmAmazon } from "./130-amazon";
|
|
import { ChunithmUserFavoriteItem } from "external/db/entity/chunithm/item";
|
|
import CreateLogCtx from "lib/logger/logger";
|
|
import { ParseStrInt } from "servers/titles/utils/string-checks";
|
|
import { LessThanOrEqual } from "typeorm";
|
|
import type { Request, Response } from "express";
|
|
|
|
const logger = CreateLogCtx(__filename);
|
|
|
|
export class ChunithmAmazonPlus extends ChunithmAmazon {
|
|
constructor(gameCode?: string, version?: string, servletName?: string) {
|
|
super(gameCode ?? "SDBT", version ?? "135", servletName ?? "ChuniServlet");
|
|
}
|
|
|
|
override createGetGameSettingsApiResponse(req: Request, res: Response) {
|
|
const resp = super.createGetGameSettingsApiResponse(req, res);
|
|
|
|
resp.gameSetting.dataVersion = "1.35.00";
|
|
|
|
return resp;
|
|
}
|
|
|
|
/**
|
|
* @since AMAZON PLUS
|
|
*/
|
|
handle_GetUserFavoriteMusicApi(req: Request, res: Response) {
|
|
// TODO: Add a web UI for favorites
|
|
|
|
return res.send({
|
|
userId: req.safeBody.userId,
|
|
length: "0",
|
|
userFavoriteMusicList: [],
|
|
});
|
|
}
|
|
|
|
async handle_GetUserFavoriteItemApi(req: Request, res: Response) {
|
|
const userId = ParseStrInt(req.safeBody.userId);
|
|
const kind = ParseStrInt(req.safeBody.kind);
|
|
|
|
if (!userId || !kind) {
|
|
logger.error("Invalid request: received userId/kind is not a number.", {
|
|
userId: req.safeBody.userId,
|
|
kind: req.safeBody.kind,
|
|
});
|
|
|
|
return res.send({ returnCode: "1" });
|
|
}
|
|
|
|
const favorites = await ChunithmUserFavoriteItem.find({
|
|
where: {
|
|
card: {
|
|
id: userId,
|
|
},
|
|
version: LessThanOrEqual(this.numericVersion),
|
|
favKind: kind,
|
|
},
|
|
});
|
|
|
|
const maxVersion = Math.max(...favorites.map((f) => f.version));
|
|
const userFavoriteItemList = favorites
|
|
.filter((f) => f.version === maxVersion)
|
|
.map((f) => ({ id: f.favId }));
|
|
|
|
return res.send({
|
|
userId,
|
|
length: userFavoriteItemList.length,
|
|
kind,
|
|
nextIndex: -1,
|
|
userFavoriteItemList,
|
|
});
|
|
}
|
|
}
|