api Page update

This commit is contained in:
tmshv committed 2020-03-02 00:36:22 +03:00
1 parent af7f32b1c0
commit 68b7f4225d
3 files changed
+56 -21

No files matched your search

+5 -15
View File
@@ -1,6 +1,7 @@
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 { Tag } from './Tag'
const store = () => Data.getStore('Page') const store = () => Data.getStore('Page')
@@ -37,6 +38,8 @@ export default class Page {
public url: string public url: string
public content: any public content: any
public title: any public title: any
public date: Date
public tags: Tag[]
public data: any public data: any
public images: any public images: any
public documents: any public documents: any
@@ -52,27 +55,14 @@ export default class Page {
this.content = data.content this.content = data.content
this.title = data.title this.title = data.title
this.data = data.data this.data = data.data
this.date = data.date
this.images = data.images this.images = data.images
this.documents = data.documents this.documents = data.documents
this.preview = data.preview this.preview = data.preview
this.tokens = data.tokens this.tokens = data.tokens
this.tags = (data.tags || []).map(x => new Tag(x))
this.description = data.description this.description = data.description
} }
plain() {
return {
id: this.id,
images: this.images,
documents: this.documents,
data: this.data,
title: this.title,
content: this.content,
hash: this.hash,
file: this.file,
preview: this.preview,
url: this.url,
}
}
} }
const previewFromImage = (imgs = []) => imgs.length const previewFromImage = (imgs = []) => imgs.length
+26 -3
View File
@@ -1,6 +1,29 @@
import ImageArtifactType from '../core/ImageArtifactType' import ImageArtifactType from '../core/ImageArtifactType'
export function encodeImage(image) { export type ImageArtifactDto = {
height: number
width: number
src: string
set: Array<{
density: number
url: string
}>
}
export type ImageDto = {
artifacts: {
original: ImageArtifactDto,
large: ImageArtifactDto,
big: ImageArtifactDto,
medium: ImageArtifactDto,
small: ImageArtifactDto,
fb: ImageArtifactDto,
},
hash: string
file: string
}
export function encodeImage(image): ImageDto {
const artifacts = [ const artifacts = [
ImageArtifactType.SMALL, ImageArtifactType.SMALL,
ImageArtifactType.MEDIUM, ImageArtifactType.MEDIUM,
@@ -17,8 +40,8 @@ export function encodeImage(image) {
}, {}) }, {})
return { return {
artifacts, artifacts: artifacts as any,
hash: image.hash, hash: image.hash,
file: image.file, file: image.file,
} }
} }
+25 -3
View File
@@ -1,9 +1,29 @@
import { encodeImage } from './image' import { encodeImage, ImageDto } from './image'
import Page from '../core/Page' import Page from '../core/Page'
import { Breadcrumb } from '../types' import { Breadcrumb } from '../types'
import { Tag } from '../core/Tag'
export function encodePage(page: Page, breadcrumb: Breadcrumb) { type Token = {
token: string
data: any
}
type PageDto = {
id: string
title: string
date?: string
url: string
data: string
description: string
preview?: ImageDto
tokens: Token[]
tags: Tag[]
breadcrumb: Breadcrumb
}
export function encodePage(page: Page, breadcrumb: Breadcrumb): PageDto {
const preview = page.preview ? encodeImage(page.preview) : null const preview = page.preview ? encodeImage(page.preview) : null
const date = page.date ? page.date.toString() : null
return { return {
id: page.id, id: page.id,
@@ -11,8 +31,10 @@ export function encodePage(page: Page, breadcrumb: Breadcrumb) {
url: page.url, url: page.url,
data: page.data, data: page.data,
description: page.description, description: page.description,
preview,
tokens: page.tokens, tokens: page.tokens,
tags: page.tags,
preview,
date,
breadcrumb, breadcrumb,
} }
} }