article api preview update
This commit is contained in:
1 parent
d29bfbff89
commit
33ee2d218e
2 files changed
+10
-1
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { connect } from '../../../src/core/db'
|
||||
import Article from '../../../src/core/Article'
|
||||
import { encodeArticle } from '../../../src/api/articles'
|
||||
|
||||
export default async (req, res) => {
|
||||
await connect()
|
||||
@@ -11,7 +12,7 @@ export default async (req, res) => {
|
||||
const article = await Article.findById(id)
|
||||
|
||||
if (article) {
|
||||
res.json(article)
|
||||
res.json(encodeArticle(article))
|
||||
} else {
|
||||
res.status(404)
|
||||
res.json({
|
||||
|
||||
@@ -2,6 +2,7 @@ import Article from '../core/Article'
|
||||
import ImageArtifactType from '../core/ImageArtifactType'
|
||||
import { sortBy } from '../utils/sort'
|
||||
import { timestamp } from '../lib/date'
|
||||
import { encodeImage } from './image'
|
||||
|
||||
export const sortArticleByDate = sortBy(
|
||||
x => timestamp(new Date(x.date))
|
||||
@@ -60,4 +61,11 @@ export async function findArticles(page, pageSize) {
|
||||
nextPage,
|
||||
totalPages,
|
||||
}
|
||||
}
|
||||
|
||||
export function encodeArticle(article) {
|
||||
return {
|
||||
...article,
|
||||
preview: encodeImage(article.preview),
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user