remove server.log setting item

This commit is contained in:
undefined committed 2020-07-25 19:23:48 +08:00
1 parent e62e7b49a3
commit ee78271a84
27 files changed
+159 -114

No files matched your search

+11 -1
View File
@@ -4,6 +4,11 @@ import { Bdoc } from '../interface';
const coll = db.collection('blacklist');
export async function add(ip: string): Promise<Bdoc> {
/**
* Add a ip into blacklist.
* @param {string} ip
* @returns {Promise<Bdoc>}
*/
const expireAt = new Date(new Date().getTime() + 365 * 24 * 60 * 60 * 1000);
const res = await coll.findOneAndUpdate(
{ _id: ip },
@@ -13,7 +18,12 @@ export async function add(ip: string): Promise<Bdoc> {
return res.value;
}
export function get(ip: string): Promise<Bdoc> {
export function get(ip: string): Promise<Bdoc | null> {
/**
* Get a ip, return null if not.
* @param {string} ip
* @returns {Promise<Bdoc>}
*/
return coll.findOne({ _id: ip });
}
+18 -10
View File
@@ -5,6 +5,7 @@ import * as training from './training';
import * as document from './document';
import { PERM } from './builtin';
import { DocumentNotFoundError } from '../error';
import { Ddoc, Drdoc, Drrdoc } from '../interface';
export const typeDisplay = {
[document.TYPE_PROBLEM]: 'problem',
@@ -18,7 +19,7 @@ export function add(
domainId: string, parentType: number, parentId: ObjectID | number | string,
owner: number, title: string, content: string,
ip: string | null = null, highlight: boolean = false,
) {
): Promise<ObjectID> {
return document.add(
domainId, content, owner, document.TYPE_DISCUSSION,
null, parentType, parentId,
@@ -33,14 +34,14 @@ export function add(
);
}
export function get(domainId: string, did: ObjectID) {
export function get(domainId: string, did: ObjectID): Promise<Ddoc | null> {
return document.get(domainId, document.TYPE_DISCUSSION, did);
}
export function edit(
domainId: string, did: ObjectID,
title: string, content: string, highlight: boolean,
) {
): Promise<Ddoc | null> {
return document.set(domainId, document.TYPE_DISCUSSION, did, { title, content, highlight });
}
@@ -65,7 +66,7 @@ export function getMulti(domainId: string, query: any = {}) {
export async function addReply(
domainId: string, did: ObjectID, owner: number,
content: string, ip: string,
) {
): Promise<Drdoc> {
const [drdoc] = await Promise.all([
document.add(
domainId, content, owner, document.TYPE_DISCUSSION_REPLY,
@@ -76,11 +77,13 @@ export async function addReply(
return drdoc;
}
export function getReply(domainId: string, drid: ObjectID) {
export function getReply(domainId: string, drid: ObjectID): Promise<Drdoc | null> {
return document.get(domainId, document.TYPE_DISCUSSION_REPLY, drid);
}
export async function editReply(domainId: string, drid: ObjectID, content: string) {
export async function editReply(
domainId: string, drid: ObjectID, content: string,
): Promise<Drdoc | null> {
return document.set(domainId, document.TYPE_DISCUSSION_REPLY, drid, { content });
}
@@ -100,14 +103,14 @@ export function getMultiReply(domainId: string, did: ObjectID) {
).sort('_id', -1);
}
export function getListReply(domainId: string, did: ObjectID) {
export function getListReply(domainId: string, did: ObjectID): Promise<Drdoc[]> {
return getMultiReply(domainId, did).toArray();
}
export async function addTailReply(
domainId: string, drid: ObjectID,
owner: number, content: string, ip: string,
) {
): Promise<[Drdoc, ObjectID]> {
let drdoc = await document.get(domainId, document.TYPE_DISCUSSION_REPLY, drid);
const sid = new ObjectID();
[drdoc] = await Promise.all([
@@ -117,11 +120,16 @@ export async function addTailReply(
return [drdoc, sid];
}
export function getTailReply(domainId: string, drid: ObjectID, drrid: ObjectID) {
export function getTailReply(
domainId: string, drid: ObjectID, drrid: ObjectID,
): Promise<[Drdoc, Drrdoc] | [null, null]> {
// @ts-ignore
return document.getSub(domainId, document.TYPE_DISCUSSION_REPLY, drid, 'reply', drrid);
}
export function editTailReply(domainId: string, drid: ObjectID, drrid: ObjectID, content: string) {
export function editTailReply(
domainId: string, drid: ObjectID, drrid: ObjectID, content: string,
): Promise<Drrdoc> {
return document.setSub(domainId, document.TYPE_DISCUSSION_REPLY, drid, 'reply', drrid, { content });
}
+2 -2
View File
@@ -27,7 +27,7 @@ export async function send(
return mdoc;
}
export async function get(_id: ObjectID): Promise<Mdoc> {
export async function get(_id: ObjectID): Promise<Mdoc | null> {
return await coll.findOne({ _id });
}
@@ -41,7 +41,7 @@ export async function getMany(query: any, sort: any, page: number, limit: number
.toArray();
}
export async function setFlag(messageId: ObjectID, flag: number) {
export async function setFlag(messageId: ObjectID, flag: number): Promise<Mdoc | null> {
const result = await coll.findOneAndUpdate(
{ _id: messageId },
{ $bit: { flag: { xor: flag } } },
+6 -4
View File
@@ -77,7 +77,7 @@ export function edit(domainId: string, _id: number, $set: any): Promise<Pdoc> {
return document.set(domainId, document.TYPE_PROBLEM, _id, $set);
}
export function inc(domainId: string, _id: number, field: string, n: number) {
export function inc(domainId: string, _id: number, field: string, n: number): Promise<Pdoc> {
return document.inc(domainId, document.TYPE_PROBLEM, _id, field, n);
}
@@ -85,7 +85,7 @@ export function count(domainId: string, query: any) {
return document.count(domainId, document.TYPE_PROBLEM, query);
}
export async function random(domainId: string, query: any) {
export async function random(domainId: string, query: any): Promise<string | null> {
const cursor = document.getMulti(domainId, document.TYPE_PROBLEM, query);
const pcount = await cursor.count();
if (pcount) {
@@ -100,16 +100,18 @@ export async function getList(
): Promise<Pdict> {
pids = Array.from(new Set(pids));
const r = {};
const l = {};
const q: any = { $or: [{ docId: { $in: pids } }, { pid: { $in: pids } }] };
if (!getHidden) q.hidden = false;
const pdocs = await document.getMulti(domainId, document.TYPE_PROBLEM, q).toArray();
for (const pdoc of pdocs) {
r[pdoc.docId] = pdoc;
r[pdoc.pid] = pdoc;
l[pdoc.pid] = pdoc;
}
// TODO enhance
if (pdocs.length !== pids.length) {
for (const pid of pids) {
if (!r[pid]) {
if (!(r[pid] || l[pid])) {
if (doThrow) {
throw new ProblemNotFoundError(domainId, pid);
} else {
-2
View File
@@ -1,5 +1,3 @@
import _ from 'lodash';
import yaml from 'js-yaml';
import { ObjectID } from 'mongodb';
import { STATUS } from './builtin';
import * as task from './task';
-1
View File
@@ -121,7 +121,6 @@ SystemSetting(
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', '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'),
-1
View File
@@ -1,4 +1,3 @@
import { ValidationError } from '../error';
import * as db from '../service/db';
const coll = db.collection('token');