api image update
This commit is contained in:
1 parent
ed1a924156
commit
8d67fbefd1
2 files changed
+26
-3
No files matched your search
+2
-3
@@ -1,6 +1,6 @@
|
|||||||
import { connect } from '../../src/core/db'
|
import { connect } from '../../src/core/db'
|
||||||
import Image from '../../src/core/Image'
|
import Image from '../../src/core/Image'
|
||||||
import ImageArtifactType from '../../src/core/ImageArtifactType'
|
import { encodeImage } from '../../src/api/image'
|
||||||
|
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
await connect()
|
await connect()
|
||||||
@@ -9,8 +9,7 @@ export default async (req, res) => {
|
|||||||
const image = await Image.findByFile(file)
|
const image = await Image.findByFile(file)
|
||||||
|
|
||||||
if (image) {
|
if (image) {
|
||||||
const data = image.getPicture(ImageArtifactType.LARGE)
|
res.json(encodeImage(image))
|
||||||
res.json(data)
|
|
||||||
} else {
|
} else {
|
||||||
res.status(404)
|
res.status(404)
|
||||||
res.json({
|
res.json({
|
||||||
|
|||||||
@@ -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,
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user