mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
每日签到功能
This commit is contained in:
1 parent
06847d9b19
commit
9887deca6a
7 files changed
+52
-11
No files matched your search
@@ -18,7 +18,7 @@ class DomainRankHandler extends Handler {
|
||||
@param('page', Types.PositiveInt, true)
|
||||
async get(domainId: string, page = 1) {
|
||||
const [dudocs, upcount, ucount] = await paginate(
|
||||
domain.getMultiInDomain(domainId).sort({ rp: -1 }),
|
||||
domain.getMultiUserInDomain(domainId).sort({ rp: -1 }),
|
||||
page,
|
||||
100,
|
||||
);
|
||||
@@ -84,7 +84,7 @@ class DomainUserHandler extends ManageHandler {
|
||||
async get({ domainId }) {
|
||||
const rudocs = {};
|
||||
const [dudocs, roles] = await Promise.all([
|
||||
domain.getMultiInDomain(domainId, {
|
||||
domain.getMultiUserInDomain(domainId, {
|
||||
$and: [
|
||||
{ role: { $ne: 'default' } },
|
||||
{ role: { $ne: null } },
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user