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 { connect } from '../../../src/core/db'
|
||||||
import Article from '../../../src/core/Article'
|
import Article from '../../../src/core/Article'
|
||||||
|
import { encodeArticle } from '../../../src/api/articles'
|
||||||
|
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
await connect()
|
await connect()
|
||||||
@@ -11,7 +12,7 @@ export default async (req, res) => {
|
|||||||
const article = await Article.findById(id)
|
const article = await Article.findById(id)
|
||||||
|
|
||||||
if (article) {
|
if (article) {
|
||||||
res.json(article)
|
res.json(encodeArticle(article))
|
||||||
} else {
|
} else {
|
||||||
res.status(404)
|
res.status(404)
|
||||||
res.json({
|
res.json({
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import Article from '../core/Article'
|
|||||||
import ImageArtifactType from '../core/ImageArtifactType'
|
import ImageArtifactType from '../core/ImageArtifactType'
|
||||||
import { sortBy } from '../utils/sort'
|
import { sortBy } from '../utils/sort'
|
||||||
import { timestamp } from '../lib/date'
|
import { timestamp } from '../lib/date'
|
||||||
|
import { encodeImage } from './image'
|
||||||
|
|
||||||
export const sortArticleByDate = sortBy(
|
export const sortArticleByDate = sortBy(
|
||||||
x => timestamp(new Date(x.date))
|
x => timestamp(new Date(x.date))
|
||||||
@@ -61,3 +62,10 @@ export async function findArticles(page, pageSize) {
|
|||||||
totalPages,
|
totalPages,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function encodeArticle(article) {
|
||||||
|
return {
|
||||||
|
...article,
|
||||||
|
preview: encodeImage(article.preview),
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user