每日签到功能

This commit is contained in:
undefined committed 2020-08-13 13:03:33 +08:00
1 parent 06847d9b19
commit 9887deca6a
7 files changed
+52 -11

No files matched your search

+30
View File
@@ -92,6 +92,35 @@ class StatusUpdateHandler extends Handler {
}
}
class CheckInHandler extends Handler {
async prepare() {
const { checkincnt, lastcheckin } = this.user;
const today = new Date();
today.setHours(0);
today.setMinutes(0);
today.setSeconds(0);
today.setMilliseconds(0);
if (lastcheckin === today.getTime()) throw new BadRequestError("You've already checked in today!");
this.user.checkincnt++;
this.user.lastcheckin = today.getTime();
await Promise.all([
user.setById(this.user._id, { checkincnt, lastcheckin }),
user.inc(this.user._id, 'rpdelta', Math.round(Math.sqrt(checkincnt))),
]);
}
async get() {
this.response.redirect = '/';
}
async post() {
this.response.body = {
cnt: this.user.checkincnt,
last: this.user.lastcheckin,
};
}
}
class SwitchLanguageHandler extends Handler {
@param('lang', Types.String)
async get(domainId: string, lang: string) {
@@ -108,6 +137,7 @@ export async function apply() {
Route('file_upload', '/fs/upload', FileUploadHandler, PRIV.PRIV_CREATE_FILE);
Route('status', '/status', StatusHandler);
Route('status_update', '/status/update', StatusUpdateHandler);
Route('check_in', '/checkin', CheckInHandler, PRIV.PRIV_USER_PROFILE);
Route('switch_language', '/language/:lang', SwitchLanguageHandler);
}