mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
每日签到功能
This commit is contained in:
1 parent
06847d9b19
commit
9887deca6a
7 files changed
+52
-11
No files matched your search
@@ -6,6 +6,4 @@ pdoc.secretConfig?
|
|||||||
message.markAsRead
|
message.markAsRead
|
||||||
Handle OAuth Map !important
|
Handle OAuth Map !important
|
||||||
基于document的model难以lint,建议拆分
|
基于document的model难以lint,建议拆分
|
||||||
写test! !important
|
写test! !important
|
||||||
每日签到
|
|
||||||
rp.delta
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.12.15",
|
"version": "2.12.16",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "dist/loader.js",
|
"main": "dist/loader.js",
|
||||||
"typings": "dist/loader.d.ts",
|
"typings": "dist/loader.d.ts",
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class DomainRankHandler extends Handler {
|
|||||||
@param('page', Types.PositiveInt, true)
|
@param('page', Types.PositiveInt, true)
|
||||||
async get(domainId: string, page = 1) {
|
async get(domainId: string, page = 1) {
|
||||||
const [dudocs, upcount, ucount] = await paginate(
|
const [dudocs, upcount, ucount] = await paginate(
|
||||||
domain.getMultiInDomain(domainId).sort({ rp: -1 }),
|
domain.getMultiUserInDomain(domainId).sort({ rp: -1 }),
|
||||||
page,
|
page,
|
||||||
100,
|
100,
|
||||||
);
|
);
|
||||||
@@ -84,7 +84,7 @@ class DomainUserHandler extends ManageHandler {
|
|||||||
async get({ domainId }) {
|
async get({ domainId }) {
|
||||||
const rudocs = {};
|
const rudocs = {};
|
||||||
const [dudocs, roles] = await Promise.all([
|
const [dudocs, roles] = await Promise.all([
|
||||||
domain.getMultiInDomain(domainId, {
|
domain.getMultiUserInDomain(domainId, {
|
||||||
$and: [
|
$and: [
|
||||||
{ role: { $ne: 'default' } },
|
{ role: { $ne: 'default' } },
|
||||||
{ role: { $ne: null } },
|
{ 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 {
|
class SwitchLanguageHandler extends Handler {
|
||||||
@param('lang', Types.String)
|
@param('lang', Types.String)
|
||||||
async get(domainId: string, lang: 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('file_upload', '/fs/upload', FileUploadHandler, PRIV.PRIV_CREATE_FILE);
|
||||||
Route('status', '/status', StatusHandler);
|
Route('status', '/status', StatusHandler);
|
||||||
Route('status_update', '/status/update', StatusUpdateHandler);
|
Route('status_update', '/status/update', StatusUpdateHandler);
|
||||||
|
Route('check_in', '/checkin', CheckInHandler, PRIV.PRIV_USER_PROFILE);
|
||||||
Route('switch_language', '/language/:lang', SwitchLanguageHandler);
|
Route('switch_language', '/language/:lang', SwitchLanguageHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ export function setMultiUserInDomain(domainId: string, query: any, params: any)
|
|||||||
return collUser.updateMany({ domainId, ...query }, { $set: params });
|
return collUser.updateMany({ domainId, ...query }, { $set: params });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getMultiInDomain(domainId: string, query: any = {}) {
|
export function getMultiUserInDomain(domainId: string, query: any = {}) {
|
||||||
return collUser.find({ domainId, ...query });
|
return collUser.find({ domainId, ...query });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +212,7 @@ global.Hydro.model.domain = {
|
|||||||
setMultiUserInDomain,
|
setMultiUserInDomain,
|
||||||
setUserInDomain,
|
setUserInDomain,
|
||||||
incUserInDomain,
|
incUserInDomain,
|
||||||
getMultiInDomain,
|
getMultiUserInDomain,
|
||||||
getDictUserByDomainId,
|
getDictUserByDomainId,
|
||||||
getJoinSettings,
|
getJoinSettings,
|
||||||
getPrefixSearch,
|
getPrefixSearch,
|
||||||
|
|||||||
@@ -95,6 +95,8 @@ AccountSetting(
|
|||||||
'/components/profile/backgrounds/1.jpg', 'text', 'Profile Background Image',
|
'/components/profile/backgrounds/1.jpg', 'text', 'Profile Background Image',
|
||||||
'Choose the background image in your profile page.'),
|
'Choose the background image in your profile page.'),
|
||||||
Setting('setting_storage', 'usage', null, 0, 'number', 'Userfile Usage', null, FLAG_DISABLED | FLAG_HIDDEN),
|
Setting('setting_storage', 'usage', null, 0, 'number', 'Userfile Usage', null, FLAG_DISABLED | FLAG_HIDDEN),
|
||||||
|
Setting('setting_storage', 'checkincnt', null, 0, 'number', 'Check In Counter', null, FLAG_DISABLED | FLAG_HIDDEN),
|
||||||
|
Setting('setting_storage', 'lastcheckin', null, 0, 'number', 'Last checkin time', null, FLAG_DISABLED | FLAG_HIDDEN),
|
||||||
);
|
);
|
||||||
|
|
||||||
DomainSetting(
|
DomainSetting(
|
||||||
@@ -110,6 +112,7 @@ DomainUserSetting(
|
|||||||
Setting('setting_storage', 'nSubmit', null, 0, 'number', 'nSubmit', null, FLAG_HIDDEN | FLAG_DISABLED),
|
Setting('setting_storage', 'nSubmit', null, 0, 'number', 'nSubmit', null, FLAG_HIDDEN | FLAG_DISABLED),
|
||||||
Setting('setting_storage', 'nLike', null, 0, 'number', 'nLike', null, FLAG_HIDDEN | FLAG_DISABLED),
|
Setting('setting_storage', 'nLike', null, 0, 'number', 'nLike', null, FLAG_HIDDEN | FLAG_DISABLED),
|
||||||
Setting('setting_storage', 'rp', null, 1500, 'number', 'RP', null, FLAG_HIDDEN | FLAG_DISABLED),
|
Setting('setting_storage', 'rp', null, 1500, 'number', 'RP', null, FLAG_HIDDEN | FLAG_DISABLED),
|
||||||
|
Setting('setting_storage', 'rpdelta', null, 0, 'number', 'RP.delta', null, FLAG_HIDDEN | FLAG_DISABLED),
|
||||||
Setting('setting_storage', 'level', null, 0, 'number', 'level', null, FLAG_HIDDEN | FLAG_DISABLED),
|
Setting('setting_storage', 'level', null, 0, 'number', 'level', null, FLAG_HIDDEN | FLAG_DISABLED),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,8 @@ async function runContest(...arg: any[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function calcLevel(domainId: string, report: Function) {
|
export async function calcLevel(domainId: string, report: Function) {
|
||||||
const dudocs = await domain.getMultiInDomain(domainId).sort('rp', -1).toArray();
|
const dudocs = await domain.getMultiUserInDomain(domainId).sort('rp', -1).toArray();
|
||||||
|
if (!dudocs.length) return;
|
||||||
let last = { rp: null };
|
let last = { rp: null };
|
||||||
let rank = 0;
|
let rank = 0;
|
||||||
let count = 0;
|
let count = 0;
|
||||||
@@ -97,8 +98,8 @@ export async function calcLevel(domainId: string, report: Function) {
|
|||||||
bulk.find({ _id: dudoc._id }).updateOne({ $set: { rank } });
|
bulk.find({ _id: dudoc._id }).updateOne({ $set: { rank } });
|
||||||
last = dudoc;
|
last = dudoc;
|
||||||
if (count % 1000 === 0) report({ message: `#${count}: Rank ${rank}` });
|
if (count % 1000 === 0) report({ message: `#${count}: Rank ${rank}` });
|
||||||
await bulk.execute();
|
|
||||||
}
|
}
|
||||||
|
await bulk.execute();
|
||||||
if (!rank) {
|
if (!rank) {
|
||||||
report({ message: 'No one has rp' });
|
report({ message: 'No one has rp' });
|
||||||
return;
|
return;
|
||||||
@@ -120,6 +121,11 @@ export async function calcLevel(domainId: string, report: Function) {
|
|||||||
|
|
||||||
async function runInDomain(domainId: string, isSub: boolean, report: Function) {
|
async function runInDomain(domainId: string, isSub: boolean, report: Function) {
|
||||||
const udict: ND = {};
|
const udict: ND = {};
|
||||||
|
const deltaudict: ND = {};
|
||||||
|
const dudocs = await domain.getMultiUserInDomain(domainId).toArray();
|
||||||
|
for (const dudoc of dudocs) {
|
||||||
|
deltaudict[dudoc.uid] = dudoc.rpdelta || 0;
|
||||||
|
}
|
||||||
const contests = await contest.getMulti(domainId, { rated: true }, -1).sort('endAt', -1).toArray();
|
const contests = await contest.getMulti(domainId, { rated: true }, -1).sort('endAt', -1).toArray();
|
||||||
await report({ message: `Found ${contests.length} contests in ${domainId}` });
|
await report({ message: `Found ${contests.length} contests in ${domainId}` });
|
||||||
for (const i in contests) {
|
for (const i in contests) {
|
||||||
@@ -146,7 +152,11 @@ async function runInDomain(domainId: string, isSub: boolean, report: Function) {
|
|||||||
await domain.setMultiUserInDomain(domainId, {}, { rp: 1500 });
|
await domain.setMultiUserInDomain(domainId, {}, { rp: 1500 });
|
||||||
const tasks = [];
|
const tasks = [];
|
||||||
for (const uid in udict) {
|
for (const uid in udict) {
|
||||||
tasks.push(domain.setUserInDomain(domainId, parseInt(uid, 10), { rp: udict[uid] }));
|
tasks.push(
|
||||||
|
domain.setUserInDomain(
|
||||||
|
domainId, parseInt(uid, 10), { rp: udict[uid] + (deltaudict[uid] || 0) },
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
await Promise.all(tasks);
|
await Promise.all(tasks);
|
||||||
await calcLevel(domainId, report);
|
await calcLevel(domainId, report);
|
||||||
|
|||||||
Reference in new issue
Block a user