- fix: resizing image uploaded
- add: mybachecas
This commit is contained in:
@@ -11,6 +11,8 @@ const sendemail = require('../sendemail');
|
||||
|
||||
const resizer = require('node-image-resizer');
|
||||
|
||||
const sharp = require('sharp');
|
||||
|
||||
const {authenticate, authenticate_noerror} = require(
|
||||
'../middleware/authenticate');
|
||||
|
||||
@@ -90,6 +92,8 @@ const actions = require('./api/actions');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const globalTables = require('../tools/globalTables');
|
||||
|
||||
const UserCost = {
|
||||
FIELDS_REQUISITI: [
|
||||
'verified_email',
|
||||
@@ -216,124 +220,22 @@ router.post(process.env.LINK_UPDATE_PWD, (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
function getTableByTableName(tablename) {
|
||||
router.post('/testServer', (req, res) => {
|
||||
|
||||
let mytable = '';
|
||||
if (tablename === 'users')
|
||||
mytable = User;
|
||||
else if (tablename === 'mygroups')
|
||||
mytable = MyGroup;
|
||||
else if (tablename === 'tessitura')
|
||||
mytable = Tessitura;
|
||||
// else if (tablename === 'extralist')
|
||||
// mytable = ExtraList;
|
||||
else if (tablename === 'bookings')
|
||||
mytable = Booking;
|
||||
else if (tablename === 'operators')
|
||||
mytable = Operator;
|
||||
else if (tablename === 'products')
|
||||
mytable = Product;
|
||||
else if (tablename === 'storehouses')
|
||||
mytable = Storehouse;
|
||||
else if (tablename === 'departments')
|
||||
mytable = Department;
|
||||
else if (tablename === 'sharewithus')
|
||||
mytable = ShareWithUs;
|
||||
else if (tablename === 'sites')
|
||||
mytable = Site;
|
||||
else if (tablename === 'iscritticonacreis')
|
||||
mytable = IscrittiConacreis;
|
||||
else if (tablename === 'groups')
|
||||
mytable = Group;
|
||||
else if (tablename === 'todos')
|
||||
mytable = Todo;
|
||||
else if (tablename === 'hours')
|
||||
mytable = Hours;
|
||||
else if (tablename === 'orders')
|
||||
mytable = Order;
|
||||
else if (tablename === 'cashs')
|
||||
mytable = Cash;
|
||||
else if (tablename === 'cashCategorys')
|
||||
mytable = CashCategory;
|
||||
else if (tablename === 'cashSubCategorys')
|
||||
mytable = CashSubCategory;
|
||||
else if (tablename === 'producers')
|
||||
mytable = Producer;
|
||||
else if (tablename === 'carts')
|
||||
mytable = Cart;
|
||||
else if (tablename === 'orderscart')
|
||||
mytable = OrdersCart;
|
||||
else if (tablename === 'sendmsgs')
|
||||
mytable = SendMsg;
|
||||
else if (tablename === 'wheres')
|
||||
mytable = Where;
|
||||
else if (tablename === 'myevents')
|
||||
mytable = MyEvent;
|
||||
else if (tablename === 'contribtypes')
|
||||
mytable = Contribtype;
|
||||
else if (tablename === 'contribtype')
|
||||
mytable = Contribtype;
|
||||
else if (tablename === 'paymenttypes')
|
||||
mytable = PaymentType;
|
||||
else if (tablename === 'disciplines')
|
||||
mytable = Discipline;
|
||||
else if (tablename === 'newstosent')
|
||||
mytable = Newstosent;
|
||||
else if (tablename === 'gallery')
|
||||
mytable = Gallery;
|
||||
else if (tablename === 'mypage')
|
||||
mytable = MyPage;
|
||||
else if (tablename === 'mybots')
|
||||
mytable = MyBot;
|
||||
else if (tablename === 'calzoom')
|
||||
mytable = CalZoom;
|
||||
else if (tablename === 'templemail')
|
||||
mytable = TemplEmail;
|
||||
else if (tablename === 'opzemail')
|
||||
mytable = OpzEmail;
|
||||
else if (tablename === 'settings')
|
||||
mytable = Settings;
|
||||
else if (tablename === 'permissions')
|
||||
mytable = Permission;
|
||||
else if (tablename === 'mailinglist')
|
||||
mytable = MailingList;
|
||||
else if (tablename === 'msg_templates')
|
||||
mytable = MsgTemplate;
|
||||
else if (tablename === 'navepersistente')
|
||||
mytable = NavePersistente;
|
||||
// else if (tablename === 'listaingressos')
|
||||
// mytable = ListaIngresso;
|
||||
else if (tablename === 'graduatorias')
|
||||
mytable = Graduatoria;
|
||||
else if (tablename === 'skills')
|
||||
mytable = Skill;
|
||||
else if (tablename === 'subskills')
|
||||
mytable = SubSkill;
|
||||
else if (tablename === 'myskills')
|
||||
mytable = MySkill;
|
||||
else if (tablename === 'statusSkills')
|
||||
mytable = StatusSkill;
|
||||
else if (tablename === 'cities')
|
||||
mytable = City;
|
||||
else if (tablename === 'provinces')
|
||||
mytable = Province;
|
||||
else if (tablename === 'sectors')
|
||||
mytable = Sector;
|
||||
else if (tablename === 'catgrps')
|
||||
mytable = CatGrp;
|
||||
else if (tablename === 'levels')
|
||||
mytable = Level;
|
||||
else if (shared_consts.TablePickup.includes(tablename))
|
||||
mytable = Pickup;
|
||||
//else if (shared_consts.TableCities.includes(tablename))
|
||||
// mytable = City;
|
||||
try {
|
||||
const test = req.body.test;
|
||||
let ris = {test};
|
||||
|
||||
return mytable;
|
||||
}
|
||||
return res.send(ris);
|
||||
} catch (e) {
|
||||
return res.status(400).send(e);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
router.post('/settable', authenticate, (req, res) => {
|
||||
const params = req.body;
|
||||
const mytable = getTableByTableName(params.table);
|
||||
const mytable = globalTables.getTableByTableName(params.table);
|
||||
const mydata = req.body.data;
|
||||
|
||||
const fieldsvalue = {'ALL': 1};
|
||||
@@ -404,7 +306,7 @@ router.post('/settable', authenticate, (req, res) => {
|
||||
let mytablerec = new mytable(mydata);
|
||||
// console.log('mytablerec', mytablerec);
|
||||
|
||||
const mytablestrutt = getTableByTableName(params.table);
|
||||
const mytablestrutt = globalTables.getTableByTableName(params.table);
|
||||
|
||||
if (mydata['_id'] !== undefined && mydata['_id'] !== 0) {
|
||||
mytablerec.isNew = false;
|
||||
@@ -461,7 +363,7 @@ router.post('/settable', authenticate, (req, res) => {
|
||||
|
||||
router.post('/setsubrec', authenticate, (req, res) => {
|
||||
const params = req.body;
|
||||
const mytable = getTableByTableName(params.table);
|
||||
const mytable = globalTables.getTableByTableName(params.table);
|
||||
const mydata = req.body.data;
|
||||
|
||||
mydata.idapp = req.user.idapp;
|
||||
@@ -469,7 +371,7 @@ router.post('/setsubrec', authenticate, (req, res) => {
|
||||
let mytablerec = new mytable(mydata);
|
||||
// console.log('mytablerec', mytablerec);
|
||||
|
||||
const mytablestrutt = getTableByTableName(params.table);
|
||||
const mytablestrutt = globalTables.getTableByTableName(params.table);
|
||||
|
||||
const rec = mytablestrutt.createNewSubRecord(mydata.idapp, req).then(rec => {
|
||||
// tools.mylog('rec', rec);
|
||||
@@ -510,7 +412,7 @@ router.post('/setsubrec', authenticate, (req, res) => {
|
||||
|
||||
router.post('/gettable', authenticate, (req, res) => {
|
||||
const params = req.body;
|
||||
const mytable = getTableByTableName(params.table);
|
||||
const mytable = globalTables.getTableByTableName(params.table);
|
||||
// console.log('mytable', mytable);
|
||||
if (!mytable) {
|
||||
console.log(`Table ${params.table} not found`);
|
||||
@@ -529,7 +431,7 @@ router.post('/gettable', authenticate, (req, res) => {
|
||||
|
||||
router.post('/pickup', authenticate, (req, res) => {
|
||||
const params = req.body;
|
||||
let mytable = getTableByTableName(params.table);
|
||||
let mytable = globalTables.getTableByTableName(params.table);
|
||||
// console.log('mytable', mytable);
|
||||
if (!mytable) {
|
||||
console.log(`Table ${params.table} not found`);
|
||||
@@ -592,7 +494,7 @@ router.patch('/chval', authenticate, async (req, res) => {
|
||||
const idapp = req.body.idapp;
|
||||
const mydata = req.body.data;
|
||||
|
||||
const mytable = getTableByTableName(mydata.table);
|
||||
const mytable = globalTables.getTableByTableName(mydata.table);
|
||||
const fieldsvalue = mydata.fieldsvalue;
|
||||
const unset = mydata.unset;
|
||||
|
||||
@@ -802,7 +704,7 @@ router.patch('/askfunz', authenticate, async (req, res) => {
|
||||
if (!!userfree)
|
||||
return res.send({code: server_constants.RIS_CODE_OK, out: userfree});
|
||||
/*} else if (mydata.myfunc === shared_consts.CallFunz.GET_VALBYTABLE) {
|
||||
const mytable = getTableByTableName(mydata.table);
|
||||
const mytable = globalTables.getTableByTableName(mydata.table);
|
||||
const coltoshow = {
|
||||
[mydata.coltoshow]: 1
|
||||
};
|
||||
@@ -811,7 +713,7 @@ router.patch('/askfunz', authenticate, async (req, res) => {
|
||||
|
||||
return ris;
|
||||
} else if (mydata.myfunc === shared_consts.CallFunz.SET_VALBYTABLE) {
|
||||
const mytable = getTableByTableName(mydata.table);
|
||||
const mytable = globalTables.getTableByTableName(mydata.table);
|
||||
const value = mydata.value;
|
||||
const coltoset = {
|
||||
[mydata.coltoshow]: value
|
||||
@@ -892,7 +794,7 @@ router.get('/copyfromapptoapp/:idapporig/:idappdest', async (req, res) => {
|
||||
// try {
|
||||
// let numrectot = 0;
|
||||
// for (const table of mytablesstr) {
|
||||
// const mytable = getTableByTableName(table);
|
||||
// const mytable = globalTables.getTableByTableName(table);
|
||||
//
|
||||
// tools.mylogshow('copyfromapptoapp: ', table, mytable);
|
||||
//
|
||||
@@ -919,7 +821,7 @@ router.delete('/delrec/:table/:id', authenticate, async (req, res) => {
|
||||
|
||||
console.log('id', id, 'table', tablename);
|
||||
|
||||
const mytable = getTableByTableName(tablename);
|
||||
const mytable = globalTables.getTableByTableName(tablename);
|
||||
|
||||
const fields = {'ALL': 1};
|
||||
|
||||
@@ -991,7 +893,7 @@ router.post('/duprec/:table/:id', authenticate, (req, res) => {
|
||||
|
||||
console.log('id', id, 'table', tablename);
|
||||
|
||||
const mytable = getTableByTableName(tablename);
|
||||
const mytable = globalTables.getTableByTableName(tablename);
|
||||
|
||||
if (!req.user) {
|
||||
return res.status(404).
|
||||
@@ -1439,44 +1341,42 @@ function uploadFile(req, res, version) {
|
||||
|
||||
// Move in the folder application !
|
||||
// tools.move(oldpath, newname, (err) => {
|
||||
tools.move(oldpath, newname, async (err) => {
|
||||
tools.move(oldpath, newname, (err) => {
|
||||
if (err)
|
||||
console.log('err:', err);
|
||||
|
||||
const setup_image_compress = {
|
||||
all: {
|
||||
path: mydir + '/',
|
||||
quality: 80,
|
||||
},
|
||||
versions: [
|
||||
{
|
||||
prefix: server_constants.PREFIX_IMG,
|
||||
width: 512,
|
||||
height: 512,
|
||||
}, {
|
||||
quality: 100,
|
||||
prefix: server_constants.PREFIX_IMG_SMALL,
|
||||
width: 64,
|
||||
height: 64,
|
||||
}],
|
||||
};
|
||||
|
||||
// Salva le immagini in formato compresso
|
||||
try {
|
||||
const ris = await resizer(newname, setup_image_compress);
|
||||
console.log('resizer', newname);
|
||||
if (ris) {
|
||||
if (tools.isFileExists(resized_img)) {
|
||||
tools.delete(newname, false, () => {});
|
||||
let resized_img_small = tools.extractFilePath(newname) + '/' +
|
||||
server_constants.PREFIX_IMG_SMALL +
|
||||
tools.extractFileName(newname);
|
||||
// SMALL
|
||||
sharp(newname).
|
||||
resize(64, 64).
|
||||
toFile(resized_img_small);
|
||||
|
||||
tools.move(resized_img, newname, (err) => {
|
||||
if (err)
|
||||
console.error('err', err);
|
||||
else
|
||||
console.log('move', newname);
|
||||
// MEDIUM
|
||||
let resized_img = tools.extractFilePath(newname) + '/' +
|
||||
server_constants.PREFIX_IMG + tools.extractFileName(newname);
|
||||
sharp(newname).
|
||||
resize(512, 512).
|
||||
toFile(resized_img, function(err) {
|
||||
|
||||
if (tools.isFileExists(resized_img)) {
|
||||
// DELETE THE ORIGINAL BIG
|
||||
tools.delete(newname, false, () => {});
|
||||
|
||||
// RENAME THE MEDIUM IN THE ORIGINAL NAME
|
||||
tools.move(resized_img, newname, (err) => {
|
||||
if (err)
|
||||
console.error('err', err);
|
||||
else
|
||||
console.log('move', newname);
|
||||
});
|
||||
}
|
||||
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('newname', e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user