diff --git a/backend/app/bl/GamesManager.js b/backend/app/bl/GamesManager.js
index 3c99129..0ea694b 100644
--- a/backend/app/bl/GamesManager.js
+++ b/backend/app/bl/GamesManager.js
@@ -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);
+ }
}
/**
diff --git a/backend/controllers/api/GamesController.js b/backend/controllers/api/GamesController.js
index 5768dfa..5665c3e 100644
--- a/backend/controllers/api/GamesController.js
+++ b/backend/controllers/api/GamesController.js
@@ -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
diff --git a/src/components/GamePreview/GamePreview.vue b/src/components/GamePreview/GamePreview.vue
index 993c32f..2bae938 100644
--- a/src/components/GamePreview/GamePreview.vue
+++ b/src/components/GamePreview/GamePreview.vue
@@ -17,7 +17,9 @@