add factory
This commit is contained in:
1 parent
df2f979b55
commit
80b5297215
8 files changed
+89
-4
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { Request, Response } from 'express'
|
||||
import Document from '../core/Document'
|
||||
import { encodeFile } from '../api/files'
|
||||
import { encodeFile } from '../factory/files'
|
||||
|
||||
export async function getItem(req: Request, res: Response) {
|
||||
const id = req.params.slug
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Image from '../core/Image'
|
||||
import { encodeImage } from '../api/image'
|
||||
import { encodeImage } from '../factory/image'
|
||||
import { Request, Response } from 'express'
|
||||
|
||||
export async function getItem(req: Request, res: Response) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Request, Response } from 'express'
|
||||
import Page from '../core/Page'
|
||||
import { getPathWithNoTrailingSlash } from '../lib/url'
|
||||
import { encodePage } from '../api/page'
|
||||
import { encodePage } from '../factory/page'
|
||||
|
||||
export async function getItem(req: Request, res: Response) {
|
||||
const id = req.params.slug
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Teacher from '../core/Teacher'
|
||||
import { encodePerson } from '../api/persons'
|
||||
import { encodePerson } from '../factory/persons'
|
||||
import { Request, Response } from 'express'
|
||||
import { prioritySort } from '../lib/sort'
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import ImageArtifactType from '../core/ImageArtifactType'
|
||||
|
||||
const sizes = [
|
||||
ImageArtifactType.MEDIUM,
|
||||
ImageArtifactType.BIG,
|
||||
ImageArtifactType.ORIGIN,
|
||||
]
|
||||
|
||||
export function encodeFilePreview(file, sizes) {
|
||||
const preview = file.preview
|
||||
if (!preview) return null
|
||||
|
||||
const image = preview.findArtifact(sizes)
|
||||
if (!image) return null
|
||||
|
||||
return image.url
|
||||
}
|
||||
|
||||
export function encodeFile(file) {
|
||||
const imageUrl = encodeFilePreview(file, sizes)
|
||||
const category = (file.category || '')
|
||||
.replace('Documents/', '')
|
||||
.replace('Pages/', '')
|
||||
.replace('Albums/', '')
|
||||
.replace('Articles /', '')
|
||||
|
||||
return {
|
||||
imageUrl,
|
||||
category,
|
||||
title: file.title,
|
||||
fileName: file.fileInfo.name,
|
||||
fileSize: file.fileInfo.size,
|
||||
fileUrl: file.url,
|
||||
url: file.viewUrl,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import ImageArtifactType from '../core/ImageArtifactType'
|
||||
|
||||
export function encodeImage(image) {
|
||||
const artifacts = [
|
||||
ImageArtifactType.SMALL,
|
||||
ImageArtifactType.MEDIUM,
|
||||
ImageArtifactType.BIG,
|
||||
ImageArtifactType.LARGE,
|
||||
ImageArtifactType.ORIGIN,
|
||||
ImageArtifactType.ORIGINAL,
|
||||
ImageArtifactType.FACEBOOK = 'fb'
|
||||
].reduce((acc, size) => {
|
||||
return {
|
||||
...acc,
|
||||
[size]: image.getPicture(size),
|
||||
}
|
||||
}, {})
|
||||
|
||||
return {
|
||||
artifacts,
|
||||
hash: image.hash,
|
||||
file: image.file,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { encodeImage } from './image'
|
||||
|
||||
export function encodePage(page) {
|
||||
return {
|
||||
id: page.id,
|
||||
title: page.title,
|
||||
url: page.url,
|
||||
data: page.data,
|
||||
preview: encodeImage(page.preview),
|
||||
tokens: page.tokens,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import ImageArtifactType from '../core/ImageArtifactType'
|
||||
import { encodeImage } from './image'
|
||||
const profilePicture = profile => profile.picture.getPicture(ImageArtifactType.BIG)
|
||||
|
||||
export function encodePerson(person) {
|
||||
return {
|
||||
...person,
|
||||
shortName: person.shortName(),
|
||||
name: person.splitName(),
|
||||
picture: profilePicture(person),
|
||||
preview: encodeImage(person.picture),
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user