mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-06 22:07:58 +03:00
Get stuff a user did in the last (16) hours
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import crypto from "crypto";
|
||||
import { ONE_HOUR } from "lib/constants/time";
|
||||
import { TachiConfig } from "lib/setup/config";
|
||||
import { Game, GamePTConfig, GetGameConfig, Playtypes } from "tachi-common";
|
||||
import { Game, GamePTConfig, GetGameConfig, Playtypes, integer } from "tachi-common";
|
||||
|
||||
// https://github.com/sindresorhus/escape-string-regexp/blob/main/index.js
|
||||
// the developer of this has migrated everything to Force ES6 style modules,
|
||||
@@ -128,3 +129,7 @@ export function IsValidURL(string: string) {
|
||||
export function Sleep(ms: number) {
|
||||
return new Promise<void>((resolve) => setTimeout(() => resolve(), ms));
|
||||
}
|
||||
|
||||
export function GetTimeXHoursAgo(hours: integer) {
|
||||
return Date.now() - ONE_HOUR * hours;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import db from "external/mongo/db";
|
||||
import { integer } from "tachi-common";
|
||||
import { GetTimeXHoursAgo } from "utils/misc";
|
||||
|
||||
// Various utils related to the player summary endpoint.
|
||||
const REASONABLE_HOURS_AGO = 16;
|
||||
|
||||
export function GetRecentPlaycount(userID: integer) {
|
||||
const time = GetTimeXHoursAgo(REASONABLE_HOURS_AGO);
|
||||
|
||||
return db.scores.count({ userID, timeAchieved: { $gte: time } });
|
||||
}
|
||||
|
||||
export function GetRecentSessions(userID: integer) {
|
||||
const time = GetTimeXHoursAgo(REASONABLE_HOURS_AGO);
|
||||
|
||||
return db.sessions.find({
|
||||
userID,
|
||||
timeEnded: { $gte: time },
|
||||
});
|
||||
}
|
||||
|
||||
export async function GetRecentlyViewedFoldersAnyGPT(userID: integer) {
|
||||
const time = GetTimeXHoursAgo(REASONABLE_HOURS_AGO);
|
||||
|
||||
const views = await db["recent-folder-views"].find(
|
||||
{
|
||||
userID,
|
||||
lastViewed: { $gte: time },
|
||||
},
|
||||
{
|
||||
sort: {
|
||||
lastViewed: -1,
|
||||
},
|
||||
limit: 4,
|
||||
}
|
||||
);
|
||||
|
||||
const folders = await db.folders.find({
|
||||
folderID: { $in: views.map((e) => e.folderID) },
|
||||
});
|
||||
|
||||
// TODO: Sort recently viewed folders based on how recently viewed
|
||||
// they were.
|
||||
|
||||
return folders;
|
||||
}
|
||||
Reference in New Issue
Block a user