api doesnt work with default page image

This commit is contained in:
tmshv committed 2020-02-27 15:57:14 +03:00
1 parent 193e8e3ca2
commit 96328a1236
3 files changed
-60

No files matched your search

-10
View File
@@ -1,6 +1,5 @@
import Data from './Data'
import Image from './Image'
import Config from './Config'
import { find, findOne, total } from '../lib/store'
import { Tag } from './Tag'
@@ -101,13 +100,6 @@ const previewFromImage = (imgs = []) => imgs.length
? imgs[0]
: null
async function resolveDefaultPreview() {
const config = await Config.findConfig()
if (!config) return null
return Image.findByFile(config.articleCardDefaultPreview)
}
async function processArticle(article) {
let preview = null
const previewId = article.preview
@@ -116,8 +108,6 @@ async function processArticle(article) {
if (previewId) {
preview = await Image.findById(previewId)
} else {
preview = await resolveDefaultPreview()
}
return new Article({
-40
View File
@@ -1,40 +0,0 @@
import Data from './Data'
import { findOne } from '../lib/store'
const store = () => Data.getStore('Settings')
export default class Config {
static async findConfig() {
const config = await Config.findById('settings')
return config || new Config({} as any)
}
static async findById(id: string) {
const data = await findOne(store(), { id })
if (!data) return null
return new Config(data)
}
public hash: any
public file: any
public server: any
public articlesPerPage: any
public articleCardDefaultPreview: any
public collectiveImage: any
public redirect: any
constructor({ hash, file, ...data }) {
this.hash = hash
this.file = file
this.server = data.server
this.articlesPerPage = data.articlesPerPage || 5
this.articleCardDefaultPreview = data.articleCardDefaultPreview
this.collectiveImage = data.collectiveImage
const redirect = data.redirect || {}
this.redirect = new Map(Object
.entries(redirect)
)
}
}
-10
View File
@@ -1,7 +1,6 @@
import Data from './Data'
import { find as storeFind, findOne, total } from '../lib/store'
import Image from './Image'
import Config from './Config'
const store = () => Data.getStore('Page')
@@ -80,13 +79,6 @@ const previewFromImage = (imgs = []) => imgs.length
? imgs[0]
: null
async function resolveDefaultPreview() {
const config = await Config.findConfig()
if (!config) return null
return Image.findByFile(config.articleCardDefaultPreview)
}
async function processPage(article) {
let preview = null
const previewId = article.preview
@@ -95,8 +87,6 @@ async function processPage(article) {
if (previewId) {
preview = await Image.findById(previewId)
} else {
preview = await resolveDefaultPreview()
}
return new Page({