allow screenshot from game as thumbnail header
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import sharp from 'sharp';
|
||||
sharp.cache({ files : 0 });
|
||||
|
||||
const collection = 'games';
|
||||
/**
|
||||
@@ -11,7 +13,7 @@ class GamesManager{
|
||||
* @param {App} app Class initializer, основна апликация
|
||||
*/
|
||||
init(app){
|
||||
const {db, am} = app;
|
||||
const {db, am, config} = app;
|
||||
|
||||
/**
|
||||
* Creates a new game definition, създаване на нова игрова дефиниция
|
||||
@@ -69,6 +71,14 @@ class GamesManager{
|
||||
project: { name:1, id:1, thumb: 1}
|
||||
});
|
||||
}
|
||||
|
||||
this.setHeader = async function(ctx, id, file){
|
||||
await sharp(file.path).resize({height: 500}).webp({quality: 75}).toFile(`${config.fs.repo}/thumb/${id}.webp`);
|
||||
await sharp(file.path).webp({quality: 75}).toFile(`${config.fs.repo}/default/${id}.webp`);
|
||||
let object = await this.read(id);
|
||||
object.thumb = id;
|
||||
await this.update(ctx, object);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import express from 'express';
|
||||
import multipart from 'connect-multiparty';
|
||||
|
||||
const multipartMiddleware = multipart();
|
||||
|
||||
/**
|
||||
* GamesController. API for the games manager, граничен клас за комуникация с модула за игрови дефиниции
|
||||
@@ -35,6 +38,19 @@ class GamesController{
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/:id/header', multipartMiddleware, async (req, res)=>{
|
||||
try{
|
||||
let id = parseInt(req.params.id);
|
||||
await game.setHeader(req, id, req.files.file);
|
||||
res.json({status: 'OK'});
|
||||
am.audit(req, `game-header-set`, id);
|
||||
}catch(err){
|
||||
console.error(err);
|
||||
res.status(500).json({status: 'ERR', err});
|
||||
am.audit(req, `game-header-error`, id, {e: err});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* API: POST /api/game/ List games by given criteria, търсене в игрови дефиниции
|
||||
* @function list
|
||||
|
||||
Reference in New Issue
Block a user