添加addon-ts.md,添加defaultUdoc

This commit is contained in:
undefined committed 2020-09-09 22:39:38 +08:00
1 parent 8b956575ee
commit d458c231a4
5 files changed
+230 -23

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.13.7",
"version": "2.13.8",
"bin": "bin/hydrooj.js",
"main": "dist/loader.js",
"typings": "dist/loader.d.ts",
+2 -1
View File
@@ -304,10 +304,11 @@ class HomeMessagesHandler extends Handler {
async get() {
// TODO(iceboy): projection, pagination.
const messages = await message.getByUser(this.user._id);
const udict = await user.getList('system', [
const uids = new Set<number>([
...messages.map((mdoc) => mdoc.from),
...messages.map((mdoc) => mdoc.to),
]);
const udict = await user.getList('system', Array.from(uids));
// TODO(twd2): improve here:
const parsed = {};
for (const m of messages) {
+19 -1
View File
@@ -22,6 +22,23 @@ export async function setPassword(uid: number, password: string): Promise<Udoc>
return res.value;
}
export const defaultUser: Udoc = {
_id: 0,
uname: 'Unknown User',
unameLower: 'unknown user',
gravatar: 'unknown@hydro.local',
mail: 'unknown@hydro.local',
mailLower: 'unknown@hydro.local',
salt: '',
hash: '',
hashType: 'hydro',
priv: 0,
regat: new Date('2000-01-01'),
loginat: new Date('2000-01-01'),
regip: '127.0.0.1',
loginip: '127.0.0.1',
};
export class User implements _User {
udoc: () => any;
@@ -125,7 +142,7 @@ export async function getList(domainId: string, uids: number[]): Promise<Udict>
const _uids = new Set(uids);
const r = {};
// eslint-disable-next-line no-await-in-loop
for (const uid of _uids) r[uid] = await getById(domainId, uid);
for (const uid of _uids) r[uid] = (await getById(domainId, uid)) || defaultUser;
return r;
}
@@ -252,6 +269,7 @@ function ensureIndexes() {
bus.once('app/started', ensureIndexes);
global.Hydro.model.user = {
User,
defaultUser,
create,
getByEmail,
getById,