api doesnt work with default page image
This commit is contained in:
1 parent
193e8e3ca2
commit
96328a1236
3 files changed
-60
No files matched your search
@@ -1,6 +1,5 @@
|
|||||||
import Data from './Data'
|
import Data from './Data'
|
||||||
import Image from './Image'
|
import Image from './Image'
|
||||||
import Config from './Config'
|
|
||||||
import { find, findOne, total } from '../lib/store'
|
import { find, findOne, total } from '../lib/store'
|
||||||
import { Tag } from './Tag'
|
import { Tag } from './Tag'
|
||||||
|
|
||||||
@@ -101,13 +100,6 @@ const previewFromImage = (imgs = []) => imgs.length
|
|||||||
? imgs[0]
|
? imgs[0]
|
||||||
: null
|
: null
|
||||||
|
|
||||||
async function resolveDefaultPreview() {
|
|
||||||
const config = await Config.findConfig()
|
|
||||||
if (!config) return null
|
|
||||||
|
|
||||||
return Image.findByFile(config.articleCardDefaultPreview)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function processArticle(article) {
|
async function processArticle(article) {
|
||||||
let preview = null
|
let preview = null
|
||||||
const previewId = article.preview
|
const previewId = article.preview
|
||||||
@@ -116,8 +108,6 @@ async function processArticle(article) {
|
|||||||
|
|
||||||
if (previewId) {
|
if (previewId) {
|
||||||
preview = await Image.findById(previewId)
|
preview = await Image.findById(previewId)
|
||||||
} else {
|
|
||||||
preview = await resolveDefaultPreview()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Article({
|
return new Article({
|
||||||
|
|||||||
@@ -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)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
import Data from './Data'
|
import Data from './Data'
|
||||||
import { find as storeFind, findOne, total } from '../lib/store'
|
import { find as storeFind, findOne, total } from '../lib/store'
|
||||||
import Image from './Image'
|
import Image from './Image'
|
||||||
import Config from './Config'
|
|
||||||
|
|
||||||
const store = () => Data.getStore('Page')
|
const store = () => Data.getStore('Page')
|
||||||
|
|
||||||
@@ -80,13 +79,6 @@ const previewFromImage = (imgs = []) => imgs.length
|
|||||||
? imgs[0]
|
? imgs[0]
|
||||||
: null
|
: null
|
||||||
|
|
||||||
async function resolveDefaultPreview() {
|
|
||||||
const config = await Config.findConfig()
|
|
||||||
if (!config) return null
|
|
||||||
|
|
||||||
return Image.findByFile(config.articleCardDefaultPreview)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function processPage(article) {
|
async function processPage(article) {
|
||||||
let preview = null
|
let preview = null
|
||||||
const previewId = article.preview
|
const previewId = article.preview
|
||||||
@@ -95,8 +87,6 @@ async function processPage(article) {
|
|||||||
|
|
||||||
if (previewId) {
|
if (previewId) {
|
||||||
preview = await Image.findById(previewId)
|
preview = await Image.findById(previewId)
|
||||||
} else {
|
|
||||||
preview = await resolveDefaultPreview()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Page({
|
return new Page({
|
||||||
|
|||||||
Reference in new issue
Block a user