Commit 0a806a01 authored by nanahira's avatar nanahira

add post score nonce

parent 76ff2157
Pipeline #39768 failed with stages
in 2 minutes and 4 seconds
This diff is collapsed.
......@@ -42,11 +42,18 @@ import { AccountService } from './account/account.service';
import { CodeResponseDto } from './dto/CodeResponse.dto';
import { PayExpDto } from './dto/PayExp.dto';
import { UserHistoricalRecord } from './entities/mycard/UserHistoricalRecord';
import { Aragami, CacheKey, CacheTTL } from 'aragami';
const attrOffset = 1010;
const raceOffset = 1020;
const typeOffset = 1050;
@CacheTTL(3600000)
class ProcessedPostNonce {
@CacheKey()
nonce: string;
}
const ygoproConstants = {
TYPES: {
TYPE_MONSTER: 1,
......@@ -140,6 +147,16 @@ export class AppService {
}
}
private aragami = new Aragami(
config.redisUrl
? {
redis: {
uri: config.redisUrl,
},
}
: {},
);
private async monthlyJob() {
this.log.log(
`The scheduleJob run on first day of every month: ${moment().format(
......@@ -296,11 +313,11 @@ export class AppService {
const from_time = (inputFrom_time
? moment(inputFrom_time)
: moment().startOf('day')
).toDate()
).toDate();
const to_time = (inputTo_time
? moment(inputTo_time)
: moment().startOf('day').add(1, 'day')
).toDate()
).toDate();
try {
const [
{ entertainTotal },
......@@ -549,6 +566,25 @@ export class AppService {
}
async postScore(body: any): Promise<string> {
const nonce = body.nonce;
if (!nonce) {
return this.postScore(body);
}
const exist = () => this.aragami.has(ProcessedPostNonce, nonce);
if (await exist()) return;
return this.aragami.lock(`postScoreLock:${nonce}`, async () => {
if (await exist()) return;
const result = await this.postScoreProcess(body);
if (!result) {
const nonceObj = new ProcessedPostNonce();
nonceObj.nonce = nonce;
await this.aragami.set(nonceObj);
}
return result;
});
}
async postScoreProcess(body: any): Promise<string> {
let usernameA: string = body.usernameA;
let usernameB: string = body.usernameB;
const userscoreA = parseInt(body.userscoreA) || 0;
......
......@@ -9,6 +9,7 @@ export interface Config {
analyzerHost: string;
enableSchedule: boolean;
accountsUrl: string;
redisUrl: string;
}
export const athleticCheckConfig = {
......@@ -34,4 +35,5 @@ export const config: Config = {
enableSchedule: !process.env.NO_SCHEDULE,
accountsUrl:
process.env.ACCOUNTS_URL || 'https://sapi.moecube.com:444/accounts',
redisUrl: process.env.REDIS_URL,
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment