Skip to content

Commit 31e48c5

Browse files
committed
src: remove useless base model
1 parent c9571be commit 31e48c5

File tree

13 files changed

+18
-56
lines changed

13 files changed

+18
-56
lines changed

app/common/base_model.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

app/common/tools.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
'use strict';
22

33
const bcrypt = require('bcryptjs');
4-
const moment = require('moment');
5-
6-
moment.locale('zh-cn'); // 使用中文
7-
8-
// 格式化时间
9-
exports.formatDate = (date, friendly) => {
10-
date = moment(date);
11-
12-
if (friendly) {
13-
return date.fromNow();
14-
}
15-
16-
return date.format('YYYY-MM-DD HH:mm');
17-
};
184

195
exports.validateId = str => {
206
return /^[a-zA-Z0-9\-_]+$/i.test(str);

app/common/upload.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
const util = require('util');
44
const qn = require('qn');
55

6-
exports = function qnUpload(options) {
6+
module.exports = function qnUpload(options) {
77
// 7牛 client
88
let qnClient;
99
if (options.qn_access && options.qn_access.secretKey !== 'your secret key') {
1010
qnClient = qn.create(options.qn_access);
1111
}
12-
const qnUpload = util.promisify(qnClient.upload);
13-
return qnUpload;
12+
return util.promisify(qnClient.upload);
1413
};

app/extend/helper.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
const MarkdownIt = require('markdown-it');
44
const validator = require('validator');
55
const jsxss = require('xss');
6+
const moment = require('moment');
7+
8+
moment.locale('zh-cn'); // 使用中文
69

710
// Set default options
811
const md = new MarkdownIt();
@@ -90,3 +93,9 @@ exports.proxy = function(url) {
9093
// 当 google 和 github 封锁严重时,则需要通过服务器代理访问它们的静态资源
9194
// return '/agent?url=' + encodeURIComponent(url);
9295
};
96+
97+
exports.ago = function(date) {
98+
date = moment(date);
99+
100+
return date.fromNow();
101+
};

app/model/message.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
const BaseModel = require('../common/base_model');
4-
53
module.exports = app => {
64
const mongoose = app.mongoose;
75
const Schema = mongoose.Schema;
@@ -17,7 +15,6 @@ module.exports = app => {
1715
create_at: { type: Date, default: Date.now },
1816
});
1917

20-
MessageSchema.plugin(BaseModel);
2118
MessageSchema.index({ master_id: 1, has_read: -1, create_at: -1 });
2219

2320
return mongoose.model('Message', MessageSchema);

app/model/reply.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
const BaseModel = require('../common/base_model');
4-
53
module.exports = app => {
64
const mongoose = app.mongoose;
75
const Schema = mongoose.Schema;
@@ -21,7 +19,6 @@ module.exports = app => {
2119
usePushEach: true,
2220
});
2321

24-
ReplySchema.plugin(BaseModel);
2522
ReplySchema.index({ topic_id: 1 });
2623
ReplySchema.index({ author_id: 1, create_at: -1 });
2724

app/model/topic.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
const BaseModel = require('../common/base_model');
4-
53
module.exports = app => {
64
const mongoose = app.mongoose;
75
const Schema = mongoose.Schema;
@@ -27,7 +25,6 @@ module.exports = app => {
2725
deleted: { type: Boolean, default: false },
2826
});
2927

30-
TopicSchema.plugin(BaseModel);
3128
TopicSchema.index({ create_at: -1 });
3229
TopicSchema.index({ top: -1, last_reply_at: -1 });
3330
TopicSchema.index({ author_id: 1, create_at: -1 });

app/model/topic_collect.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
const BaseModel = require('../common/base_model');
4-
53
module.exports = app => {
64
const mongoose = app.mongoose;
75
const Schema = mongoose.Schema;
@@ -13,7 +11,6 @@ module.exports = app => {
1311
create_at: { type: Date, default: Date.now },
1412
});
1513

16-
TopicCollectSchema.plugin(BaseModel);
1714
TopicCollectSchema.index({ user_id: 1, topic_id: 1 }, { unique: true });
1815

1916
return mongoose.model('TopicCollect', TopicCollectSchema);

app/model/user.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
const utility = require('utility');
4-
const BaseModel = require('../common/base_model');
54

65
module.exports = app => {
76
const mongoose = app.mongoose;
@@ -47,8 +46,6 @@ module.exports = app => {
4746
accessToken: { type: String },
4847
});
4948

50-
UserSchema.plugin(BaseModel);
51-
5249
UserSchema.index({ loginname: 1 }, { unique: true });
5350
UserSchema.index({ email: 1 }, { unique: true });
5451
UserSchema.index({ score: -1 });

app/view/reply/reply.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<div class='user_info'>
99
<a class='dark reply_author' href="/user/<%= reply.author.loginname %>"><%= reply.author.loginname %></a>
10-
<a class="reply_time" href="#<%= reply._id %>"><%= indexInCollection + 1 %>楼•<%= reply.create_at_ago()
10+
<a class="reply_time" href="#<%= reply._id %>"><%= indexInCollection + 1 %>楼•<%= helper.ago(reply.create_at)
1111
%></a>
1212
<% if (reply.author.loginname == topic.author.loginname) { %>
1313
<span class="reply_by_author">作者</span>

0 commit comments

Comments
 (0)