mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
修复windows下路径的问题,添加设置项,完善翻译
This commit is contained in:
1 parent
5980080302
commit
6ad41dc2ae
29 files changed
+368
-278
No files matched your search
@@ -5,14 +5,17 @@ import * as db from '../service/db';
|
||||
const coll = db.collection('message');
|
||||
|
||||
export const FLAG_UNREAD = 1;
|
||||
export const FLAG_NOTIFICATION = 2;
|
||||
export const FLAG_ALERT = 2;
|
||||
|
||||
export async function send(from: number, to: number, content: string, flag: number): Promise<Mdoc> {
|
||||
export async function send(
|
||||
from: number, to: number,
|
||||
content: string, flag: number = FLAG_UNREAD,
|
||||
): Promise<Mdoc> {
|
||||
const res = await coll.insertOne({
|
||||
from, to, content, flag: FLAG_UNREAD | flag,
|
||||
from, to, content, flag,
|
||||
});
|
||||
return {
|
||||
from, to, content, _id: res.insertedId, flag: FLAG_UNREAD | flag,
|
||||
from, to, content, _id: res.insertedId, flag,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -60,7 +63,7 @@ export function ensureIndexes() {
|
||||
|
||||
global.Hydro.model.message = {
|
||||
FLAG_UNREAD,
|
||||
FLAG_NOTIFICATION,
|
||||
FLAG_ALERT,
|
||||
|
||||
count,
|
||||
get,
|
||||
|
||||
@@ -46,7 +46,7 @@ export interface JudgeTask {
|
||||
type?: string,
|
||||
}
|
||||
|
||||
export async function add(domainId: string, data: RdocBase, addTask = true) {
|
||||
export async function add(domainId: string, data: RdocBase, addTask: boolean) {
|
||||
_.defaults(data, {
|
||||
status: STATUS.STATUS_WAITING,
|
||||
type: 'judge',
|
||||
|
||||
@@ -117,13 +117,15 @@ SystemSetting(
|
||||
Setting('setting_server', 'server.hostname', null, null, 'text', 'Server Hostname'),
|
||||
Setting('setting_server', 'server.host', null, null, 'text', 'Server Host'),
|
||||
Setting('setting_server', 'server.url', null, null, 'text', 'Server BaseURL'),
|
||||
Setting('setting_server', 'server.cdn', null, '/', 'text', 'CDN Prefix', 'Ends with /'),
|
||||
Setting('setting_server', 'server.port', null, 8888, 'number', 'Server Port'),
|
||||
Setting('setting_server', 'server.xff', null, null, 'text', 'IP Header'),
|
||||
Setting('setting_server', 'server.xff', null, null, 'text', 'IP Header', 'e.g. x-forwarded-for (lowercase)'),
|
||||
Setting('setting_server', 'server.log', null, false, 'boolean', 'Disable Access Log'),
|
||||
Setting('setting_session', 'session.keys', null, [String.random(32)], 'text', 'session.keys', null, FLAG_DISABLED | FLAG_HIDDEN),
|
||||
Setting('setting_session', 'session.secure', null, false, 'boolean', 'session.secure'),
|
||||
Setting('setting_session', 'session.saved_expire_seconds', null, 3600 * 24 * 30, 'number', 'Saved session expire seconds'),
|
||||
Setting('setting_session', 'session.unsaved_expire_seconds', null, 3600 * 3, 'number', 'Unsaved session expire seconds'),
|
||||
Setting('setting_ui', 'ui.name', null, 'Hydro', 'text', 'Site Name'),
|
||||
Setting('setting_ui', 'ui.header_logo', null, '/components/header/header-logo.png', 'text', 'Header Logo'),
|
||||
Setting('setting_ui', 'ui.header_logo_2x', null, '/components/header/header-logo@2x.png', 'text', 'Header Logo@2x'),
|
||||
Setting('setting_ui', 'ui.header_background', null, '/components/header/header-background.png', 'text', 'Header Background'),
|
||||
|
||||
+33
-12
@@ -1,15 +1,31 @@
|
||||
import { FindOneAndUpdateOption } from 'mongodb';
|
||||
import Lru from 'lru-cache';
|
||||
import * as db from '../service/db';
|
||||
|
||||
const coll = db.collection('system');
|
||||
const cache = new Lru({
|
||||
maxAge: 5000,
|
||||
});
|
||||
|
||||
export async function get(_id: string) {
|
||||
const res = cache.get(_id);
|
||||
if (res !== undefined) return res;
|
||||
const doc = await coll.findOne({ _id });
|
||||
if (doc) return doc.value;
|
||||
if (doc) {
|
||||
cache.set(_id, doc.value);
|
||||
return doc.value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function getMany(keys: string[]): Promise<any[]> {
|
||||
const r = [];
|
||||
let success = true;
|
||||
for (const key of keys) {
|
||||
const res = cache.get(key);
|
||||
if (res !== undefined) r.push(res);
|
||||
else success = false;
|
||||
}
|
||||
if (success) return r;
|
||||
const docs = await coll.find({ _id: { $in: keys } }).toArray();
|
||||
const dict = {};
|
||||
const res = [];
|
||||
@@ -22,24 +38,29 @@ export async function getMany(keys: string[]): Promise<any[]> {
|
||||
return res;
|
||||
}
|
||||
|
||||
export async function update(_id: string, operation: any, config: FindOneAndUpdateOption) {
|
||||
await coll.findOneAndUpdate({ _id }, operation, config);
|
||||
return get(_id);
|
||||
}
|
||||
|
||||
export async function set(_id: string, value: any) {
|
||||
await coll.findOneAndUpdate({ _id }, { $set: { value } }, { upsert: true });
|
||||
return get(_id);
|
||||
cache.set(_id, value);
|
||||
const res = await coll.findOneAndUpdate(
|
||||
{ _id },
|
||||
{ $set: { value } },
|
||||
{ upsert: true, returnOriginal: false },
|
||||
);
|
||||
return res.value.value;
|
||||
}
|
||||
|
||||
export function inc(field: string) {
|
||||
return update(field, { $inc: { value: 1 } }, { upsert: true });
|
||||
export async function inc(_id: string) {
|
||||
const res = await coll.findOneAndUpdate(
|
||||
{ _id },
|
||||
{ $inc: { value: 1 } },
|
||||
{ upsert: true, returnOriginal: false },
|
||||
);
|
||||
cache.set(_id, res.value.value);
|
||||
return res.value.value;
|
||||
}
|
||||
|
||||
global.Hydro.model.system = {
|
||||
get,
|
||||
getMany,
|
||||
update,
|
||||
inc,
|
||||
set,
|
||||
};
|
||||
Reference in new issue
Block a user