drop album support from api
This commit is contained in:
1 parent
8b810d7817
commit
cc2580aedb
5 files changed
-119
No files matched your search
@@ -1,47 +0,0 @@
|
|||||||
import { Response, Request } from 'express'
|
|
||||||
import Album from '../core/Album'
|
|
||||||
|
|
||||||
export async function getItem(req: Request, res: Response) {
|
|
||||||
const id = req.params.slug
|
|
||||||
const album = await Album.findById(id)
|
|
||||||
|
|
||||||
if (album) {
|
|
||||||
res.json(album)
|
|
||||||
} else {
|
|
||||||
res.status(404)
|
|
||||||
res.json({
|
|
||||||
error: `Resource ${id} not found`
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getAll(req: Request, res: Response) {
|
|
||||||
const data = await Album.find({}, { sort: { date: -1 } })
|
|
||||||
|
|
||||||
if (data) {
|
|
||||||
res.json({
|
|
||||||
items: data,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
res.status(404)
|
|
||||||
res.json({
|
|
||||||
error: `Not found`
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getUrls (req: Request, res: Response) {
|
|
||||||
const data = await Album.find({})
|
|
||||||
|
|
||||||
if (data) {
|
|
||||||
const items = data.map(x => `/album/${x.id}`)
|
|
||||||
res.json({
|
|
||||||
items
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
res.status(404)
|
|
||||||
res.json({
|
|
||||||
error: `Not found`
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
import Data from './Data'
|
|
||||||
import Image from './Image'
|
|
||||||
import ImageArtifactType from './ImageArtifactType'
|
|
||||||
import { find, findOne } from '../lib/store'
|
|
||||||
|
|
||||||
const previewTypes = [
|
|
||||||
ImageArtifactType.SMALL,
|
|
||||||
ImageArtifactType.MEDIUM,
|
|
||||||
ImageArtifactType.BIG,
|
|
||||||
ImageArtifactType.ORIGIN,
|
|
||||||
]
|
|
||||||
const store = () => Data.getStore('Album')
|
|
||||||
|
|
||||||
export default class Album {
|
|
||||||
public id: string
|
|
||||||
|
|
||||||
static async find(query, options = {}): Promise<Album[]> {
|
|
||||||
const items = await find(store(), query, options as any)
|
|
||||||
|
|
||||||
return Promise.all(items.map(processAlbum))
|
|
||||||
}
|
|
||||||
|
|
||||||
static async findById(id) {
|
|
||||||
const item = await findOne(store(), { id })
|
|
||||||
|
|
||||||
return !item
|
|
||||||
? null
|
|
||||||
: processAlbum(item)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const previewFromImage = (imgs = []) => imgs.length
|
|
||||||
? imgs[0]
|
|
||||||
: null
|
|
||||||
|
|
||||||
const processAlbum = async album => {
|
|
||||||
let preview = {}
|
|
||||||
// {
|
|
||||||
// data: [
|
|
||||||
// {
|
|
||||||
// url: null,
|
|
||||||
// width: 0,
|
|
||||||
// height: 0,
|
|
||||||
// }
|
|
||||||
// ]
|
|
||||||
// }
|
|
||||||
|
|
||||||
const previewImageId = album.preview ? album.preview : previewFromImage(album.images)
|
|
||||||
if (previewImageId) {
|
|
||||||
const image = await Image.findById(previewImageId)
|
|
||||||
if (image) {
|
|
||||||
// const imageArtifacts = image.findArtifact(previewTypes)
|
|
||||||
// if (imageArtifacts) {
|
|
||||||
// preview = imageArtifacts
|
|
||||||
// }
|
|
||||||
preview = image.getPicture(ImageArtifactType.SMALL)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
...album,
|
|
||||||
preview,
|
|
||||||
url: `/album/${album.id}`,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -28,7 +28,6 @@ function init(db: Db) {
|
|||||||
|
|
||||||
Data.setStore('Page', db.collection('pages'))
|
Data.setStore('Page', db.collection('pages'))
|
||||||
Data.setStore('Article', db.collection('articles'))
|
Data.setStore('Article', db.collection('articles'))
|
||||||
Data.setStore('Album', db.collection('albums'))
|
|
||||||
Data.setStore('Image', db.collection('images'))
|
Data.setStore('Image', db.collection('images'))
|
||||||
Data.setStore('Document', db.collection('documents'))
|
Data.setStore('Document', db.collection('documents'))
|
||||||
Data.setStore('Settings', db.collection('settings'))
|
Data.setStore('Settings', db.collection('settings'))
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ export function encodeFile(file) {
|
|||||||
const category = (file.category || '')
|
const category = (file.category || '')
|
||||||
.replace('Documents/', '')
|
.replace('Documents/', '')
|
||||||
.replace('Pages/', '')
|
.replace('Pages/', '')
|
||||||
.replace('Albums/', '')
|
|
||||||
.replace('Articles /', '')
|
.replace('Articles /', '')
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { config } from 'dotenv'
|
|||||||
import express from 'express'
|
import express from 'express'
|
||||||
import { connect } from './db'
|
import { connect } from './db'
|
||||||
import * as article from './controllers/article'
|
import * as article from './controllers/article'
|
||||||
import * as album from './controllers/album'
|
|
||||||
import * as schedule from './controllers/schedule'
|
import * as schedule from './controllers/schedule'
|
||||||
import * as file from './controllers/file'
|
import * as file from './controllers/file'
|
||||||
import * as page from './controllers/page'
|
import * as page from './controllers/page'
|
||||||
@@ -28,10 +27,6 @@ async function main() {
|
|||||||
app.get('/articles/urls', article.getUrls)
|
app.get('/articles/urls', article.getUrls)
|
||||||
app.get('/articles/:slug', article.getItem)
|
app.get('/articles/:slug', article.getItem)
|
||||||
|
|
||||||
app.get('/albums', album.getAll)
|
|
||||||
app.get('/albums/urls', album.getUrls)
|
|
||||||
app.get('/albums/:slug', album.getItem)
|
|
||||||
|
|
||||||
app.get('/files', file.getAll)
|
app.get('/files', file.getAll)
|
||||||
app.get('/files/urls', file.getUrls)
|
app.get('/files/urls', file.getUrls)
|
||||||
app.get('/files/:slug', file.getItem)
|
app.get('/files/:slug', file.getItem)
|
||||||
|
|||||||
Reference in new issue
Block a user