|
@@ -4,10 +4,10 @@ const Service = require('egg').Service;
|
|
|
const assert = require('assert');
|
|
|
const moment = require('moment');
|
|
|
class ContentService extends Service {
|
|
|
- async create({ title, thumbnail, annex, content, istop, menus, date, annexname, term, sort, columns }) {
|
|
|
+ async create({ title, thumbnail, annex, content, istop, menus, date, annexname, term, sort, columns, contentType, href }) {
|
|
|
assert(title, '标题不存在');
|
|
|
// assert(thumbnail, '缩略图不存在');
|
|
|
- assert(content, '内容不存在');
|
|
|
+ // assert(content, '内容不存在');
|
|
|
const { Content: model } = this.ctx.model;
|
|
|
const createAt = moment().format('x');
|
|
|
let text = content.replace(new RegExp('</?[^>]+>', 'gm'), '');
|
|
@@ -16,13 +16,13 @@ class ContentService extends Service {
|
|
|
const slug = text.substring(0, 200);
|
|
|
try {
|
|
|
const year = date.slice(0, 4) + '年';
|
|
|
- await model.create({ title, slug, thumbnail, annex, content, istop, menus, createAt, year, date, annexname, term, hits: 0, sort, columns });
|
|
|
+ await model.create({ title, slug, thumbnail, annex, content, istop, menus, createAt, year, date, annexname, term, hits: 0, sort, columns, contentType, href });
|
|
|
return { errmsg: '', errcode: 0 };
|
|
|
} catch (error) {
|
|
|
throw new Error('添加失败');
|
|
|
}
|
|
|
}
|
|
|
- async update({ title, thumbnail, annex, content, istop, menus, date, annexname, term, _id, sort, columns }) {
|
|
|
+ async update({ title, thumbnail, annex, content, istop, menus, date, annexname, term, _id, sort, columns, contentType, href }) {
|
|
|
assert(_id, 'id不存在');
|
|
|
const { Content: model } = this.ctx.model;
|
|
|
let text = content.replace(new RegExp('</?[^>]+>', 'gm'), '');
|
|
@@ -30,7 +30,7 @@ class ContentService extends Service {
|
|
|
const slug = text.substring(0, 200);
|
|
|
const year = date.slice(0, 4) + '年';
|
|
|
try {
|
|
|
- await model.findById(_id).update({ title, slug, thumbnail, annex, content, istop, menus, year, date, annexname, term, sort, columns });
|
|
|
+ await model.findById(_id).update({ title, slug, thumbnail, annex, content, istop, menus, year, date, annexname, term, sort, columns, contentType, href });
|
|
|
return { errmsg: '', errcode: 0 };
|
|
|
} catch (error) {
|
|
|
throw new Error('修改失败');
|