Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit df96d6e

Browse files
fix: ensure dir existed
1 parent 6f8c7d5 commit df96d6e

File tree

6 files changed

+49
-1
lines changed

6 files changed

+49
-1
lines changed

‎server/api/articles.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ router.get('/api/front/article/detail', async (req, res) => {
4444
const ip = getIp(req)
4545
try {
4646
const detail = await db.article.find({ publish: 1, articleId }, project)
47+
if (!detail.length) {
48+
res.json({
49+
status: 102,
50+
info: '文章不存在或已删除'
51+
})
52+
return
53+
}
4754
// 查询访问ip是否点赞过即将获取的文章
4855
const existed = await db.commentIp.find({ ip, type: 2, like: 1, msgid: detail[0]._id })
4956
let liked = 0

‎server/db/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,32 @@ const initUser = async () => {
7575
console.log()
7676
}
7777
}
78+
// TODO: 后续会增加分类管理
79+
const initCategorys = async () => {
80+
const category = await db.category.find({})
7881

82+
if (!category.length) {
83+
await new db.category({
84+
name: '技术文档',
85+
total: 0,
86+
createTime: new Date()
87+
}).save()
88+
await new db.category({
89+
name: '生活感悟',
90+
total: 0,
91+
createTime: new Date()
92+
}).save()
93+
console.log()
94+
console.log('you have created category now!')
95+
console.log()
96+
}
97+
}
7998
// 建立连接
8099
mongoose.Promise = global.Promise
81100
mongoose.connection.openUri(`mongodb://${dbSecret.user}:${dbSecret.pwd}@localhost:27017/${dbSecret.db}`)
82101
mongoose.connection.once('open', () => {
83102
initUser()
103+
initCategorys()
84104
})
85105

86106
module.exports = db

‎server/utils/schedule.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ const schedule = require('node-schedule')
77
const DoubanSpider = require('douban-spider-v')
88
const fs = require('fs-extra')
99
const path = require('path')
10+
// 确保文件目录存在
11+
fs.ensureDirSync(path.join(__dirname, '../files/movies/collect'))
12+
fs.ensureDirSync(path.join(__dirname, '../files/movies/wish'))
13+
fs.ensureDirSync(path.join(__dirname, '../files/movies/do'))
14+
1015
const moviesPath = {
1116
getMovieCollect: path.join(__dirname, '../files/movies/collect'),
1217
getMovieWish: path.join(__dirname, '../files/movies/wish'),

‎src/utils/errorCode.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export function errorCode(code) {
1313
case 101:
1414
_message('warning', '您已经点过赞了 ~')
1515
break
16+
case 102:
17+
_message('warning', '文章不存在或已删除 ~')
18+
break
1619
case 429:
1720
_message('warning', '访问次数超限,请稍后再试 ~')
1821
break

‎src/views/article/articleDetail.vue

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
<p>{{ article.abstract }}</p>
4040
</note>
4141
<div v-html="article.content" class="article-detail__body"></div>
42+
<div class="article-detail__update">
43+
<span>最后编辑于:{{ article.updateTime | formatDate }}</span>
44+
</div>
4245
<div class="article-detail__like">
4346
<el-button type="primary" :plain="article.liked === 0" @click="likeArticle">👍🏻 {{ likeText }}</el-button>
4447
</div>
@@ -363,15 +366,25 @@ export default {
363366
}
364367
365368
&__info {
369+
padding: 0 12px;
366370
@include themeify() {
367371
color: themed('color-navbar');
368372
}
369373
}
370374
.info-2 {
371375
margin-top: 8px;
372376
}
377+
&__update {
378+
margin-top: 20px;
379+
padding: 14px;
380+
text-align: right;
381+
@include themeify() {
382+
color: themed('color-ele-holder');
383+
}
384+
}
373385
&__like {
374-
padding: 20px 12px 12px;
386+
margin-top: 20px;
387+
padding: 14px;
375388
text-align: center;
376389
}
377390
&__copyright {

‎static/img/cover/default.jpg

88.8 KB
Loading[フレーム]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /