From cc2580aedbc8a91a0fcf0b65ac6f69b97162e992 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Thu, 27 Feb 2020 11:25:17 +0300 Subject: [PATCH] drop album support from api --- modules/hudozka-api/src/controllers/album.ts | 47 -------------- modules/hudozka-api/src/core/Album.ts | 65 -------------------- modules/hudozka-api/src/db.ts | 1 - modules/hudozka-api/src/factory/file.ts | 1 - modules/hudozka-api/src/server.ts | 5 -- 5 files changed, 119 deletions(-) delete mode 100644 modules/hudozka-api/src/controllers/album.ts delete mode 100644 modules/hudozka-api/src/core/Album.ts diff --git a/modules/hudozka-api/src/controllers/album.ts b/modules/hudozka-api/src/controllers/album.ts deleted file mode 100644 index 4b1734e0..00000000 --- a/modules/hudozka-api/src/controllers/album.ts +++ /dev/null @@ -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` - }) - } -} diff --git a/modules/hudozka-api/src/core/Album.ts b/modules/hudozka-api/src/core/Album.ts deleted file mode 100644 index b34b6497..00000000 --- a/modules/hudozka-api/src/core/Album.ts +++ /dev/null @@ -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 { - 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}`, - } -} diff --git a/modules/hudozka-api/src/db.ts b/modules/hudozka-api/src/db.ts index bd3705e4..8816e724 100644 --- a/modules/hudozka-api/src/db.ts +++ b/modules/hudozka-api/src/db.ts @@ -28,7 +28,6 @@ function init(db: Db) { Data.setStore('Page', db.collection('pages')) Data.setStore('Article', db.collection('articles')) - Data.setStore('Album', db.collection('albums')) Data.setStore('Image', db.collection('images')) Data.setStore('Document', db.collection('documents')) Data.setStore('Settings', db.collection('settings')) diff --git a/modules/hudozka-api/src/factory/file.ts b/modules/hudozka-api/src/factory/file.ts index 1866de43..02b465f3 100644 --- a/modules/hudozka-api/src/factory/file.ts +++ b/modules/hudozka-api/src/factory/file.ts @@ -21,7 +21,6 @@ export function encodeFile(file) { const category = (file.category || '') .replace('Documents/', '') .replace('Pages/', '') - .replace('Albums/', '') .replace('Articles /', '') return { diff --git a/modules/hudozka-api/src/server.ts b/modules/hudozka-api/src/server.ts index 5d6f28f6..d0dfdb6e 100644 --- a/modules/hudozka-api/src/server.ts +++ b/modules/hudozka-api/src/server.ts @@ -2,7 +2,6 @@ import { config } from 'dotenv' import express from 'express' import { connect } from './db' import * as article from './controllers/article' -import * as album from './controllers/album' import * as schedule from './controllers/schedule' import * as file from './controllers/file' import * as page from './controllers/page' @@ -28,10 +27,6 @@ async function main() { app.get('/articles/urls', article.getUrls) 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/urls', file.getUrls) app.get('/files/:slug', file.getItem)