api updates
This commit is contained in:
1 parent
ad2c0367d0
commit
0b3194a281
5 files changed
+24
-23
No files matched your search
@@ -2,7 +2,6 @@ import Article from '../core/Article'
|
||||
import ImageArtifactType from '../core/ImageArtifactType'
|
||||
import { sortBy } from '../utils/sort'
|
||||
import { timestamp } from '../lib/date'
|
||||
import { encodeImage } from '../factory/image'
|
||||
|
||||
export const sortArticleByDate = sortBy(
|
||||
x => timestamp(new Date(x.date))
|
||||
@@ -24,16 +23,17 @@ export async function findArticles(page: number, pageSize: number) {
|
||||
const limit = pageSize
|
||||
const skip = (page - 1) * pageSize
|
||||
|
||||
const pinnedArticles = page === 1
|
||||
? await Article.findPinned()
|
||||
: []
|
||||
// const pinnedArticles = page === 1
|
||||
// ? await Article.findPinned()
|
||||
// : []
|
||||
|
||||
const total = await Article.total()
|
||||
const totalPages = Math.ceil(total / pageSize)
|
||||
|
||||
const id = i => i._id
|
||||
const pinnedIds = pinnedArticles.map(id)
|
||||
const articles = await findArticlesNin(pinnedIds, skip, limit, { date: -1 })
|
||||
// const pinnedIds = pinnedArticles.map(id)
|
||||
// const articles = await findArticlesNin(pinnedIds, skip, limit, { date: -1 })
|
||||
const articles = await Article.find({}, { skip, limit, sort: { date: -1 } })
|
||||
|
||||
const prevPage = page > 1
|
||||
? page - 1
|
||||
@@ -44,16 +44,8 @@ export async function findArticles(page: number, pageSize: number) {
|
||||
: null
|
||||
|
||||
const items = [
|
||||
...pinnedArticles.sort(sortArticleByDate),
|
||||
...articles
|
||||
]
|
||||
.map(x => x.plain())
|
||||
.map(x => ({
|
||||
...x,
|
||||
preview: !x.preview ? null : (
|
||||
x.preview.getPicture(ImageArtifactType.MEDIUM)
|
||||
)
|
||||
}))
|
||||
|
||||
return {
|
||||
items,
|
||||
@@ -62,10 +54,3 @@ export async function findArticles(page: number, pageSize: number) {
|
||||
totalPages,
|
||||
}
|
||||
}
|
||||
|
||||
export function encodeArticle(article) {
|
||||
return {
|
||||
...article,
|
||||
preview: encodeImage(article.preview),
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user