Browse Source

增加文章类型字段与地址字段

zhy 1 week ago
parent
commit
bed6929b62
2 changed files with 12 additions and 5 deletions
  1. 7 0
      app/model/Content.js
  2. 5 5
      app/service/content.js

+ 7 - 0
app/model/Content.js

@@ -69,6 +69,13 @@ module.exports = app => {
       type: Number,
       default: 0,
     },
+    contentType: {
+      type: Number,
+      default: 0,
+    },
+    href: {
+      type: String,
+    },
   });
   return mongoose.model('Content', ContentSchema);
 };

+ 5 - 5
app/service/content.js

@@ -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('修改失败');