core: feat: blog

This commit is contained in:
undefined committed 2021-12-19 20:55:48 +08:00
1 parent f43c1bc8c9
commit 79aca189d1
10 files changed
+36 -31

No files matched your search

+3
View File
@@ -92,6 +92,9 @@ Begin Time: 开始时间
Belongs to: 属于
Bio Visibility: 个人简介可见性
Bio: 个人简介
blog_detail: 博客详情
blog_edit: 编辑博客
blog_main: 博客
Blog: 博客
Bold: 加粗
Boom!: 炸了!
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "3.2.22",
"version": "3.2.23",
"bin": "bin/hydrooj.js",
"main": "src/loader",
"module": "src/loader",
+7 -10
View File
@@ -1,11 +1,11 @@
import { ObjectID } from 'mongodb';
import { DiscussionNotFoundError } from '../error';
import { DiscussionNotFoundError, ForbiddenError } from '../error';
import { BlogDoc } from '../interface';
import paginate from '../lib/paginate';
import * as blog from '../model/blog';
import { PERM, PRIV } from '../model/builtin';
import * as discussion from '../model/discussion';
import { PRIV } from '../model/builtin';
import * as oplog from '../model/oplog';
import * as system from '../model/system';
import user from '../model/user';
import {
Handler, param, Route, Types,
@@ -16,7 +16,7 @@ class BlogHandler extends Handler {
@param('did', Types.ObjectID, true)
async _prepare(domainId: string, did: ObjectID) {
this.checkPerm(PERM.PERM_VIEW_DISCUSSION);
if (!system.get('server.blog')) throw new ForbiddenError('Blog is disabled');
if (did) {
this.ddoc = await blog.get(did);
if (!this.ddoc) throw new DiscussionNotFoundError(domainId, did);
@@ -89,7 +89,6 @@ class BlogEditHandler extends BlogHandler {
@param('title', Types.Title)
@param('content', Types.Content)
async postCreate(domainId: string, title: string, content: string) {
this.checkPerm(PERM.PERM_CREATE_DISCUSSION);
await this.limitRate('add_blog', 3600, 60);
const did = await blog.add(this.user._id, title, content, this.request.ip);
this.response.body = { did };
@@ -100,8 +99,7 @@ class BlogEditHandler extends BlogHandler {
@param('title', Types.Title)
@param('content', Types.Content)
async postUpdate(domainId: string, did: ObjectID, title: string, content: string) {
if (!this.user.own(this.ddoc)) this.checkPerm(PERM.PERM_EDIT_DISCUSSION);
else this.checkPerm(PERM.PERM_EDIT_DISCUSSION_SELF);
if (!this.user.own(this.ddoc)) this.checkPriv(PRIV.PRIV_EDIT_SYSTEM);
await blog.edit(did, title, content);
await oplog.add({
...this.ddoc, operator: this.user._id, type: 'edit',
@@ -112,9 +110,8 @@ class BlogEditHandler extends BlogHandler {
@param('did', Types.ObjectID)
async postDelete(domainId: string, did: ObjectID) {
if (!this.user.own(this.ddoc)) this.checkPerm(PERM.PERM_DELETE_DISCUSSION);
else this.checkPerm(PERM.PERM_DELETE_DISCUSSION_SELF);
await discussion.del(domainId, did);
if (!this.user.own(this.ddoc)) this.checkPriv(PRIV.PRIV_EDIT_SYSTEM);
await blog.del(did);
await oplog.add({
...this.ddoc, operator: this.user._id, operateIp: this.request.ip, type: 'delete',
});
+1
View File
@@ -201,6 +201,7 @@ SystemSetting(
Setting('setting_server', 'server.language', 'zh_CN', langRange, 'server.language', 'Default display language'),
Setting('setting_server', 'server.login', true, 'boolean', 'server.login', 'Allow builtin-login', FLAG_PRO),
Setting('setting_server', 'server.message', true, 'boolean', 'server.message', 'Allow users send messages'),
Setting('setting_server', 'server.blog', true, 'boolean', 'server.blog', 'Allow users post blog'),
Setting('setting_server', 'server.ignoreUA', ignoreUA, 'textarea', 'server.ignoreUA', 'ignoredUA'),
ServerLangSettingNode,
Setting('setting_limits', 'limit.problem_files_max', 100, 'number', 'limit.problem_files_max', 'Max files per problem'),