From c01083d696a22c588c77c25be6584ff5d7410514 Mon Sep 17 00:00:00 2001 From: alexandre Date: Thu, 15 Jun 2023 13:51:39 +0200 Subject: [PATCH 01/24] refs #5576 wip symlink --- back/model-config.json | 3 +++ back/models/image-config.json | 27 ++++++++++++++++++++++ back/models/image.js | 25 ++++++++++++++++++-- db/changes/232601/00-hederaImageConfig.sql | 4 ++++ db/dump/fixtures.sql | 4 ++++ 5 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 back/models/image-config.json create mode 100644 db/changes/232601/00-hederaImageConfig.sql diff --git a/back/model-config.json b/back/model-config.json index ff2bf5850b..a39cdb014e 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -59,6 +59,9 @@ "ImageCollectionSize": { "dataSource": "vn" }, + "ImageConfig": { + "dataSource": "vn" + }, "ImageContainer": { "dataSource": "imageStorage" }, diff --git a/back/models/image-config.json b/back/models/image-config.json new file mode 100644 index 0000000000..325859d916 --- /dev/null +++ b/back/models/image-config.json @@ -0,0 +1,27 @@ +{ + "name": "ImageConfig", + "base": "VnModel", + "options": { + "mysql": { + "table": "hedera.imageConfig" + } + }, + "properties": { + "id": { + "type": "number", + "id": true + }, + "maxSize": { + "type": "number" + }, + "useXsendfile": { + "type": "number" + }, + "url": { + "type": "string" + }, + "dirLevels": { + "type": "number" + } + } +} diff --git a/back/models/image.js b/back/models/image.js index e13f9e100c..58e26a7348 100644 --- a/back/models/image.js +++ b/back/models/image.js @@ -1,6 +1,7 @@ const fs = require('fs-extra'); const path = require('path'); const gm = require('gm'); +const crypto = require('crypto'); module.exports = Self => { require('../methods/image/download')(Self); @@ -31,6 +32,14 @@ module.exports = Self => { // Insert image row const imageName = path.parse(fileName).name; + const shasum = crypto.createHash('sha1'); + shasum.update(imageName); + const hash = shasum.digest('hex'); + const pairs = hash.match(/(..?)/g); + const imageConfig = await models.ImageConfig.findOne({fields: ['dirLevels']}); + const firstPairs = pairs.slice(0, imageConfig.dirLevels).reverse(); + const dstDir = firstPairs.join('/'); + await models.Image.upsertWithWhere( { name: imageName, @@ -64,8 +73,10 @@ module.exports = Self => { // To max size const {maxWidth, maxHeight} = collection; - const fullSizePath = path.join(collectionDir, 'full'); + const fullSizePath = path.join(collectionDir, `full/${dstDir}`); + const fullSizeOriginalPath = path.join(collectionDir, `full`); const toFullSizePath = `${fullSizePath}/${fileName}`; + const toFullSizeOriginalPath = `${fullSizeOriginalPath}/${fileName}`; await fs.mkdir(fullSizePath, {recursive: true}); await new Promise((resolve, reject) => { @@ -78,13 +89,19 @@ module.exports = Self => { if (!err) resolve(); }); }); + try { + await fs.unlink(toFullSizeOriginalPath); + } catch (e) {} + await fs.symlink(toFullSizeOriginalPath, toFullSizePath, 'file'); // To collection sizes for (const size of collection.sizes()) { const {width, height} = size; - const sizePath = path.join(collectionDir, `${width}x${height}`); + const sizePath = path.join(collectionDir, `${width}x${height}/${dstDir}`); const toSizePath = `${sizePath}/${fileName}`; + const sizeOriginalPath = path.join(collectionDir, `${width}x${height}`); + const toSizeOriginalPath = `${sizeOriginalPath}/${fileName}`; await fs.mkdir(sizePath, {recursive: true}); await new Promise((resolve, reject) => { @@ -107,6 +124,10 @@ module.exports = Self => { if (!err) resolve(); }); }); + try { + await fs.unlink(toSizeOriginalPath); + } catch (e) {} + await fs.symlink(toSizePath, toSizeOriginalPath); } }; }; diff --git a/db/changes/232601/00-hederaImageConfig.sql b/db/changes/232601/00-hederaImageConfig.sql new file mode 100644 index 0000000000..f1cdd44ead --- /dev/null +++ b/db/changes/232601/00-hederaImageConfig.sql @@ -0,0 +1,4 @@ +ALTER TABLE `hedera`.`imageConfig` ADD dirLevels INT UNSIGNED NOT NULL DEFAULT 2; +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES + ('ImageConfig', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 4441ec19c0..a9bd05092b 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2897,3 +2897,7 @@ INSERT INTO `vn`.`travelConfig` (`id`, `warehouseInFk`, `warehouseOutFk`, `agenc INSERT INTO `vn`.`buyConfig` (`id`, `monthsAgo`) VALUES (1, 6); + +INSERT INTO `hedera`.`imageConfig` (`maxSize`, `dirLevels`) + VALUES + (20, 2); -- 2.40.1 From 3a1520cfea5ef053ea2e9458353f1dc3a27b30d8 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 20 Nov 2023 14:56:01 +0100 Subject: [PATCH 02/24] refs #5576 feat: add symbolLink in folder when original is bigger than folder --- back/models/image.js | 282 ++++++++++++++++++++++++++++--------------- 1 file changed, 186 insertions(+), 96 deletions(-) diff --git a/back/models/image.js b/back/models/image.js index 58e26a7348..f7fb08bfae 100644 --- a/back/models/image.js +++ b/back/models/image.js @@ -2,132 +2,222 @@ const fs = require('fs-extra'); const path = require('path'); const gm = require('gm'); const crypto = require('crypto'); - +const {models} = require('vn-loopback/server/server'); +const PNG = 'png'; +const FORMAT = PNG; +const DEFAULT_GRAVITY = 'Center'; +const DEFAULT_QUALITY = 100; +const SIZE_UNIT = 'x'; +const formatWidthHeight = (width, height) => `${width}${SIZE_UNIT}${height}`; +const parseSize = value => formatWidthHeight(value.width, value.height).split(SIZE_UNIT); module.exports = Self => { require('../methods/image/download')(Self); require('../methods/image/upload')(Self); require('../methods/image/scrub')(Self); - - Self.resize = async function({collectionName, srcFile, fileName, entityId}) { - const models = Self.app.models; - - const collection = await models.ImageCollection.findOne( - { - fields: [ - 'id', - 'maxWidth', - 'maxHeight', - 'model', - 'property', - ], - where: {name: collectionName}, - include: { - relation: 'sizes', - scope: { - fields: ['width', 'height', 'crop'], - }, - }, - } - ); - + Self.handleFolderDestination = async fileName => { // Insert image row - const imageName = path.parse(fileName).name; - const shasum = crypto.createHash('sha1'); - shasum.update(imageName); - const hash = shasum.digest('hex'); + const {name} = path.parse(fileName); + const hash = crypto.createHash('sha1').update(name).digest('hex'); const pairs = hash.match(/(..?)/g); - const imageConfig = await models.ImageConfig.findOne({fields: ['dirLevels']}); - const firstPairs = pairs.slice(0, imageConfig.dirLevels).reverse(); - const dstDir = firstPairs.join('/'); + const {dirLevels} = await models.ImageConfig.findOne({ + fields: ['dirLevels'], + }); + const dstDir = pairs.slice(0, dirLevels).reverse().join('/'); - await models.Image.upsertWithWhere( - { - name: imageName, - collectionFk: collectionName + return {name, dstDir}; + }; + Self.getCollection = async collectionName => { + const collection = await models.ImageCollection.findOne({ + fields: ['id', 'maxWidth', 'maxHeight', 'model', 'property'], + where: {name: collectionName}, + include: { + relation: 'sizes', + scope: { + fields: ['width', 'height', 'crop'], + }, + }, + }); + + return collection; + }; + + Self.getCollectionDir = async collectionName => { + const container = await models.ImageContainer.container(collectionName); + const rootPath = container.client.root; + const collectionDir = path.join(rootPath, collectionName); + return collectionDir; + }; + + Self.getFullSizePath = (fileName, collectionDir, dstDir) => { + const fullSizePath = path.join(collectionDir, `full/${dstDir}`); + const fullSizeOriginalPath = path.join(collectionDir, `full`); + const toFullSizePath = `${fullSizePath}/${fileName}`; + const toFullSizeOriginalPath = `${fullSizeOriginalPath}/${fileName}`; + return { + fullSizePath, + toFullSizePath, + toFullSizeOriginalPath + }; + }; + Self.removeLink = async(child, parent = null) => { + try { + await fs.unlink(child); + } catch (e) { + throw new Error(e); + } + try { + await fs.symlink(parent, child); + } catch (e) { + throw new Error(e); + } + }; + Self.createLink = async(parent, child = null) => { + try { + const exists = await fs.exists(parent); + if (exists) + await fs.unlink(parent); + } catch (e) { + throw new Error(e); + } + try { + await fs.symlink(child, parent); + const link = await fs.readlink(parent); + console.log(link); + } catch (e) { + throw new Error(e); + } + }; + + Self.resize = async function({ + collectionName, + srcFile, + fileName, + entityId, + }) { + const {name, dstDir} = await Self.handleFolderDestination(fileName); + try { + await models.Image.upsertWithWhere({ + name, + collectionFk: collectionName, }, { - name: imageName, + name, collectionFk: collectionName, updated: Date.vnNow() / 1000, - } - ); + }); + } catch (e) { + debugger; + throw new Error(e); + } + const collection = await Self.getCollection(collectionName); + const {maxWidth, maxHeight} = collection; // Update entity image file name const model = models[collection.model]; if (!model) throw new Error('No matching model found'); const entity = await model.findById(entityId); - if (entity) { - await entity.updateAttribute( - collection.property, - imageName - ); - } + if (entity) + await entity.updateAttribute(collection.property, name); // Resize - const container = await models.ImageContainer.container( - collectionName - ); - const rootPath = container.client.root; - const collectionDir = path.join(rootPath, collectionName); + const collectionDir = await Self.getCollectionDir(collectionName); // To max size - const {maxWidth, maxHeight} = collection; - const fullSizePath = path.join(collectionDir, `full/${dstDir}`); - const fullSizeOriginalPath = path.join(collectionDir, `full`); - const toFullSizePath = `${fullSizePath}/${fileName}`; - const toFullSizeOriginalPath = `${fullSizeOriginalPath}/${fileName}`; + const _fullSizePath = Self.getFullSizePath(fileName, collectionDir, dstDir); - await fs.mkdir(fullSizePath, {recursive: true}); - await new Promise((resolve, reject) => { - gm(srcFile) - .resize(maxWidth, maxHeight, '>') - .setFormat('png') - .quality(100) - .write(toFullSizePath, function(err) { - if (err) reject(err); - if (!err) resolve(); - }); + const {fullSizePath, toFullSizePath, toFullSizeOriginalPath} = _fullSizePath; + try { + await fs.mkdir(fullSizePath, {recursive: true}); + } catch (e) { + debugger; + throw new Error(e); + } + const gmInstance = gm(srcFile); + let fileWidth = null; + let fileHeight = null; + + gmInstance.size(function(err, size) { + if (err) console.error(err); + [fileWidth, fileHeight] = parseSize(size); }); try { - await fs.unlink(toFullSizeOriginalPath); - } catch (e) {} - await fs.symlink(toFullSizeOriginalPath, toFullSizePath, 'file'); - - // To collection sizes - for (const size of collection.sizes()) { - const {width, height} = size; - - const sizePath = path.join(collectionDir, `${width}x${height}/${dstDir}`); - const toSizePath = `${sizePath}/${fileName}`; - const sizeOriginalPath = path.join(collectionDir, `${width}x${height}`); - const toSizeOriginalPath = `${sizeOriginalPath}/${fileName}`; - - await fs.mkdir(sizePath, {recursive: true}); await new Promise((resolve, reject) => { - const gmInstance = gm(srcFile); - - if (size.crop) { - gmInstance - .resize(width, height, '^') - .gravity('Center') - .crop(width, height); - } - - if (!size.crop) gmInstance.resize(width, height, '>'); - gmInstance - .setFormat('png') - .quality(100) - .write(toSizePath, function(err) { + .resize(maxWidth, maxHeight, '>') + .setFormat(PNG) + .quality(DEFAULT_QUALITY) + .write(toFullSizePath + `.${FORMAT}`, function(err, data) { if (err) reject(err); - if (!err) resolve(); + if (!err) resolve(data); }); }); + } catch (e) { + debugger; + throw new Error(e); + } + + await Self.createLink(toFullSizeOriginalPath, toFullSizePath); + /* try { + await fs.unlink(toFullSizeOriginalPath); + } catch (e) { + debugger; + throw new Error(e); + } + try { + await fs.symlink(toFullSizeOriginalPath, toFullSizePath, 'file'); + } catch (e) { + debugger; + throw new Error(e); + }*/ + // To collection sizes + for (const size of collection.sizes()) { + const [width, height] = parseSize(size); + + const sizePath = path.join( + collectionDir, + `${formatWidthHeight(width, height)}/${dstDir}` + ); + try { - await fs.unlink(toSizeOriginalPath); - } catch (e) {} - await fs.symlink(toSizePath, toSizeOriginalPath); + await fs.mkdir(sizePath, {recursive: true}); + } catch (e) { + debugger; + throw new Error(e); + } + + const toSizePath = `${sizePath}/${fileName}`; + if (+fileWidth < +width && +fileHeight < +height) { + await new Promise((resolve, reject) => { + if (size.crop) { + gmInstance + .resize(width, height, '^') + .gravity(DEFAULT_GRAVITY) + .crop(width, height).res(function(err, data) { + if (err) reject(err); + if (!err) resolve(data); + }); + } else gmInstance.resize(width, height, '>'); + + gmInstance + .setFormat(PNG) + .quality(DEFAULT_QUALITY) + .write(toSizePath + `.${FORMAT}`, function(err, data) { + if (err) reject(err); + if (!err) resolve(data); + }); + }); + } + + const sizeOriginalPath = path.join( + collectionDir, + formatWidthHeight(width, height) + ); + + const toSizeOriginalPath = `${sizeOriginalPath}/${fileName}`; + + // if (fileWidth > width && fileHeight < height) + await Self.createLink(toSizeOriginalPath, toSizePath); } }; }; -- 2.40.1 From 18701abda6cded601a70a37c24769c6f0309a4cb Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 20 Nov 2023 14:56:51 +0100 Subject: [PATCH 03/24] refs #5576 test: image resize --- back/models/specs/images.spec.js | 106 +++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 back/models/specs/images.spec.js diff --git a/back/models/specs/images.spec.js b/back/models/specs/images.spec.js new file mode 100644 index 0000000000..a374fc0c06 --- /dev/null +++ b/back/models/specs/images.spec.js @@ -0,0 +1,106 @@ +/* eslint-disable no-console */ +const fs = require('fs-extra'); +const models = require('vn-loopback/server/server').models; +const LoopBackContext = require('loopback-context'); +const nameItem = 'Pallet'; +const collectionName = 'user'; +let obj = {}; +const STORAGE_IMAGE_USER = 'storage/image/user'; +const _23_F2 = '23/f2'; +const FULL_23_F2 = `full/${_23_F2}`; +fdescribe('loopback model Image', () => { + const userId = 1107; + + const activeCtx = { + accessToken: {userId: userId}, + http: { + req: { + headers: {origin: 'http://localhost'}, + }, + }, + }; + beforeAll(async() => { + const {name: fileName, id: entityId} = await models.Item.findOne({where: {name: nameItem}}); + obj = { + collectionName, + srcFile: 'front/core/directives/no-image.png', + fileName, + entityId, + }; + }); + + beforeEach(() => { + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: activeCtx, + }); + }); + + it('should handle folder destination', async() => { + const {name, dstDir} = await models.Image.handleFolderDestination(obj.fileName); + + expect(name).toEqual(nameItem); + expect(dstDir).toEqual(`${_23_F2}`); + const collectionDir = await models.Image.getCollectionDir(collectionName); + + expect(collectionDir).toEqual(`${STORAGE_IMAGE_USER}`); + }); + + it('should handle full size path', async() => { + const {dstDir} = await models.Image.handleFolderDestination(obj.fileName); + const collectionDir = await models.Image.getCollectionDir(collectionName); + const _fullSizePath = models.Image.getFullSizePath(obj.fileName, collectionDir, dstDir); + const {fullSizePath, toFullSizePath, toFullSizeOriginalPath} = _fullSizePath; + + expect(fullSizePath).toEqual(`${STORAGE_IMAGE_USER}/${FULL_23_F2}`); + expect(toFullSizePath).toEqual(`${STORAGE_IMAGE_USER}/${FULL_23_F2}/${nameItem}`); + expect(toFullSizeOriginalPath).toEqual(`${STORAGE_IMAGE_USER}/full/${nameItem}`); + }); + + it('should resize', async() => { + try { + await models.Image.resize(obj); + const fileExists = await fs.exists(`${STORAGE_IMAGE_USER}/${FULL_23_F2}/${nameItem}.png`); + + expect(fileExists).toBeTrue(); + + const linkExists = await fs.readlink(`${STORAGE_IMAGE_USER}/full/${nameItem}`); + + expect(linkExists).toEqual(`${STORAGE_IMAGE_USER}/${FULL_23_F2}/${nameItem}`); + } catch (e) { + throw new Error(e); + } + }); + + afterAll(async() => { + await fs.unlink(`${STORAGE_IMAGE_USER}/full/${nameItem}`); + + try { + await fs.unlink(`${STORAGE_IMAGE_USER}/160x160/${nameItem}`); + } catch (e) { + expect(e).toBeDefined(); + } + // fs.stat(`${STORAGE_IMAGE_USER}/160x160/${_23_F2}/${nameItem}.png`, (err, data) => { + // if (err) console.error(err); + // fs.unlink(`${STORAGE_IMAGE_USER}/160x160/${_23_F2}/${nameItem}.png`); + // }); + // console.info('deleted'); + await fs.unlink(`${STORAGE_IMAGE_USER}/520x520/${nameItem}`); + + await fs.unlink(`${STORAGE_IMAGE_USER}/1600x1600/${nameItem}`); + /* fs.access(`${STORAGE_IMAGE_USER}/1600x1600/${_23_F2}/${nameItem}.png`, (err, data) => { + if (err) console.error(err); + fs.unlink(`${STORAGE_IMAGE_USER}/1600x1600/${_23_F2}/${nameItem}.png`); + console.info('deleted'); + }); + fs.stat(`${STORAGE_IMAGE_USER}/520x520/${_23_F2}/${nameItem}.png`, (err, data) => { + if (err) console.error(err); + fs.unlink(`${STORAGE_IMAGE_USER}/520x520/${_23_F2}/${nameItem}.png`); + console.info('deleted'); + }); + fs.stat(`${STORAGE_IMAGE_USER}/${FULL_23_F2}/${nameItem}.png`, (err, data) => { + if (err) console.error(err); + fs.unlink(`${STORAGE_IMAGE_USER}/${FULL_23_F2}/${nameItem}.png`); + console.info('deleted'); + });*/ + }); +}); -- 2.40.1 From 776055f167d3bf365a3b714e6a30de189d1b1899 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 20 Nov 2023 14:58:04 +0100 Subject: [PATCH 04/24] refs #5576 test: image resize --- back/models/specs/images.spec.js | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/back/models/specs/images.spec.js b/back/models/specs/images.spec.js index a374fc0c06..465ffc624f 100644 --- a/back/models/specs/images.spec.js +++ b/back/models/specs/images.spec.js @@ -1,4 +1,3 @@ -/* eslint-disable no-console */ const fs = require('fs-extra'); const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); @@ -8,7 +7,7 @@ let obj = {}; const STORAGE_IMAGE_USER = 'storage/image/user'; const _23_F2 = '23/f2'; const FULL_23_F2 = `full/${_23_F2}`; -fdescribe('loopback model Image', () => { +describe('loopback model Image', () => { const userId = 1107; const activeCtx = { @@ -74,33 +73,8 @@ fdescribe('loopback model Image', () => { afterAll(async() => { await fs.unlink(`${STORAGE_IMAGE_USER}/full/${nameItem}`); - try { - await fs.unlink(`${STORAGE_IMAGE_USER}/160x160/${nameItem}`); - } catch (e) { - expect(e).toBeDefined(); - } - // fs.stat(`${STORAGE_IMAGE_USER}/160x160/${_23_F2}/${nameItem}.png`, (err, data) => { - // if (err) console.error(err); - // fs.unlink(`${STORAGE_IMAGE_USER}/160x160/${_23_F2}/${nameItem}.png`); - // }); - // console.info('deleted'); await fs.unlink(`${STORAGE_IMAGE_USER}/520x520/${nameItem}`); await fs.unlink(`${STORAGE_IMAGE_USER}/1600x1600/${nameItem}`); - /* fs.access(`${STORAGE_IMAGE_USER}/1600x1600/${_23_F2}/${nameItem}.png`, (err, data) => { - if (err) console.error(err); - fs.unlink(`${STORAGE_IMAGE_USER}/1600x1600/${_23_F2}/${nameItem}.png`); - console.info('deleted'); - }); - fs.stat(`${STORAGE_IMAGE_USER}/520x520/${_23_F2}/${nameItem}.png`, (err, data) => { - if (err) console.error(err); - fs.unlink(`${STORAGE_IMAGE_USER}/520x520/${_23_F2}/${nameItem}.png`); - console.info('deleted'); - }); - fs.stat(`${STORAGE_IMAGE_USER}/${FULL_23_F2}/${nameItem}.png`, (err, data) => { - if (err) console.error(err); - fs.unlink(`${STORAGE_IMAGE_USER}/${FULL_23_F2}/${nameItem}.png`); - console.info('deleted'); - });*/ }); }); -- 2.40.1 From 3a265a7add4282d0431ea5aba283e521cf1b1e96 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 28 Nov 2023 14:51:34 +0100 Subject: [PATCH 05/24] refs #5576 perf: move files --- storage/image/Dockerfile | 30 +++++++++++++++++++++++ storage/image/mi-configuracion-httpd.conf | 24 ++++++++++++++++++ storage/image/move.sh | 15 ++++++++++++ storage/image/reestructure.sh | 13 ++++++++++ 4 files changed, 82 insertions(+) create mode 100644 storage/image/Dockerfile create mode 100644 storage/image/mi-configuracion-httpd.conf create mode 100644 storage/image/move.sh create mode 100644 storage/image/reestructure.sh diff --git a/storage/image/Dockerfile b/storage/image/Dockerfile new file mode 100644 index 0000000000..91a39b44f2 --- /dev/null +++ b/storage/image/Dockerfile @@ -0,0 +1,30 @@ +# Usa la imagen oficial de Apache +FROM httpd:latest + +# Añade configuración del MPM prefork +# RUN echo "LoadModule mpm_prefork_module modules/mod_mpm_prefork.so" >> /usr/local/apache2/conf/httpd.conf +# RUN echo "LoadModule mpm_worker_module modules/mod_mpm_worker.so" >> /usr/local/apache2/conf/httpd.conf + +# Copia tu archivo de configuración personalizado (si lo tienes) +# COPY ./mi-configuracion-httpd.conf /usr/local/apache2/conf/httpd.conf +COPY ./image.png /usr/local/apache2/htdocs/ +COPY ./image.png /usr/local/apache2/htdocs/welcome.png +COPY ./.htaccess /usr/local/apache2/htdocs/ +RUN { \ + echo 'IncludeOptional conf.d/*.conf'; \ +} >> /usr/local/apache2/conf/httpd.conf \ + && mkdir /usr/local/apache2/conf.d + # Copy .htaccess into DocumentRoot +COPY ./.htaccess /var/www/html/ +# Habilita el módulo mod_rewrite +RUN sed -i 's/#LoadModule rewrite_module/LoadModule rewrite_module/' /usr/local/apache2/conf/httpd.conf +# RUN sed -i 's/#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so' /usr/local/apache2/conf/httpd.conf +# RUN sed -i 's/#LoadModule mpm_prefork_module/LoadModule mpm_prefork_module/' /usr/local/apache2/conf/httpd.conf +# RUN sed -i 's/#LoadModule mpm_worker_module modules/mod_mpm_worker.so' /usr/local/apache2/conf/httpd.conf +# RUN sed -i 's/#LoadModule mpm_worker_module/LoadModule mpm_worker_module/' /usr/local/apache2/conf/httpd.conf + +# Establece el propietario del directorio del servidor a www-data (usuario de Apache) +RUN chown -R www-data:www-data /usr/local/apache2/htdocs/ + +# Expón el puerto 80 para que sea accesible desde fuera del contenedor +EXPOSE 80 diff --git a/storage/image/mi-configuracion-httpd.conf b/storage/image/mi-configuracion-httpd.conf new file mode 100644 index 0000000000..8f29543320 --- /dev/null +++ b/storage/image/mi-configuracion-httpd.conf @@ -0,0 +1,24 @@ +# +# LoadModule mpm_prefork_module modules/mod_mpm_prefork.so +# + + + LoadModule mpm_worker_module modules/mod_mpm_worker.so + + + + + RewriteEngine On + + # Asegúrate de que el módulo crypto esté disponible + RewriteCond %{LA-U:CRYPTO:crypto} ^$ + + # Obtén el nombre del archivo sin la extensión + RewriteCond %{REQUEST_FILENAME} !-f + RewriteCond %{REQUEST_FILENAME} !-d + RewriteRule ^(.+)\.png$ - [E=FILENAME_NO_EXT:$1] + + # Calcula el hash del nombre del archivo + RewriteCond %{LA-U:CRYPTO:crypto} ^(.+)$ + RewriteRule ^(.+)\.png$ /images/%1.png [L] + diff --git a/storage/image/move.sh b/storage/image/move.sh new file mode 100644 index 0000000000..14e288830a --- /dev/null +++ b/storage/image/move.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +for collection in */ ; do + for size in "$collection"*/ ; do + for image in "$size"* ; do + fileName=$(basename "$image") + imageName="${fileName%.*}" + hash=$(echo -n "$imageName" | sha1sum | awk '{print $1}') + path=$(dirname "$image")/${hash:2:2}/${hash:0:2} + mkdir -p $path + mv $image $path/$fileName + ln -s $path/$fileName $fileName + done + done +done diff --git a/storage/image/reestructure.sh b/storage/image/reestructure.sh new file mode 100644 index 0000000000..06786bffd8 --- /dev/null +++ b/storage/image/reestructure.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +for collection in */ ; do + for size in "$collection"*/ ; do + for image in "$size"* ; do + fileName=$(basename "$image") + imageName="${fileName%.*}" + hash=$(echo -n "$imageName" | sha1sum | awk '{print $1}') + mkdir -p $(dirname "$image")/${hash:2:2}/${hash:0:2} + ln -s $image $(dirname "$image")/${hash:2:2}/${hash:0:2}/$fileName + done + done +done -- 2.40.1 From 7cd7502a9f4d43dffe4b97a8d92e5e41ed286b9c Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 29 Nov 2023 07:47:08 +0100 Subject: [PATCH 06/24] refs #5576 feat sh to generate symbolic links --- storage/image/move.sh | 16 +++++++++------- storage/image/prod.sh | 27 +++++++++++++++++++++++++++ storage/image/script.sh | 22 ++++++++++++++++++++++ 3 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 storage/image/prod.sh create mode 100644 storage/image/script.sh diff --git a/storage/image/move.sh b/storage/image/move.sh index 14e288830a..49f8487673 100644 --- a/storage/image/move.sh +++ b/storage/image/move.sh @@ -3,13 +3,15 @@ for collection in */ ; do for size in "$collection"*/ ; do for image in "$size"* ; do - fileName=$(basename "$image") - imageName="${fileName%.*}" - hash=$(echo -n "$imageName" | sha1sum | awk '{print $1}') - path=$(dirname "$image")/${hash:2:2}/${hash:0:2} - mkdir -p $path - mv $image $path/$fileName - ln -s $path/$fileName $fileName + if [ -f "$image" ]; then + fileName=$(basename "$image") + imageName="${fileName%.*}" + hash=$(echo -n "$imageName" | sha1sum | awk '{print $1}') + path=$(dirname "$image")/${hash:2:2}/${hash:0:2} + mkdir -p $path + ln -s "$image" "$fileName" + mv $image $path/$fileName + fi done done done diff --git a/storage/image/prod.sh b/storage/image/prod.sh new file mode 100644 index 0000000000..9d7972e1d8 --- /dev/null +++ b/storage/image/prod.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Directorio que contiene las carpetas con las fotos +directorio_principal=$1 + +# Iterar a través de cada carpeta en el directorio principal +for image in "$directorio_principal"/*; do + # Verificar si es un directorio + # if [ -d "$image" ]; then + # Iterar a través de cada imagen en la subcarpeta + # for image in "$image"/*.png; do + # Verificar si es un archivo + if [ -f "$image" ]; then + # Obtener el nombre de la imagen + fileName=$(basename "$image") + imageName="${fileName%.*}" + hash=$(echo -n "$imageName" | sha1sum | awk '{print $1}') + path=$(dirname "$image")/${hash:2:2}/${hash:0:2} + mkdir -p $path + # Crear un enlace simbólico en la carpeta principal + ln -s "$image" "$fileName" + + mv $image $path/$fileName + fi + # done + # fi +done diff --git a/storage/image/script.sh b/storage/image/script.sh new file mode 100644 index 0000000000..6c7a3edd0e --- /dev/null +++ b/storage/image/script.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Directorio que contiene las carpetas con las fotos +directorio_principal=$1 + +# Iterar a través de cada carpeta en el directorio principal +for carpeta in "$directorio_principal"/*; do + # Verificar si es un directorio + if [ -d "$carpeta" ]; then + # Iterar a través de cada imagen en la subcarpeta + for imagen in "$carpeta"/*.png; do + # Verificar si es un archivo + if [ -f "$imagen" ]; then + # Obtener el nombre de la imagen + nombre_imagen=$(basename "$imagen") + + # Crear un enlace simbólico en la carpeta principal + ln -s "$imagen" "$1/_$nombre_imagen" + fi + done + fi +done -- 2.40.1 From fc96038125cd8fa0f9705f7ab6ec8ee5e84f1c6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Segarra=20Mart=C3=ADnez?= Date: Fri, 15 Dec 2023 21:55:38 +0100 Subject: [PATCH 07/24] approach --- images/.htaccess | 8 ++++++++ images/Dockerfile | 20 ++++++++++++++++++++ images/cgi-bin/.htaccess | 2 ++ images/cgi-bin/hola_mundo.pl | 8 ++++++++ images/cgi-bin/mostrar-md5.pl | 18 ++++++++++++++++++ images/cgi-bin/script.pl | 27 +++++++++++++++++++++++++++ images/docker-compose.yml | 8 ++++++++ storage/image/prod.sh | 6 ++++-- storage/image/reestructure.sh | 2 ++ 9 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 images/.htaccess create mode 100644 images/Dockerfile create mode 100644 images/cgi-bin/.htaccess create mode 100644 images/cgi-bin/hola_mundo.pl create mode 100644 images/cgi-bin/mostrar-md5.pl create mode 100644 images/cgi-bin/script.pl create mode 100644 images/docker-compose.yml diff --git a/images/.htaccess b/images/.htaccess new file mode 100644 index 0000000000..6b16a3dd68 --- /dev/null +++ b/images/.htaccess @@ -0,0 +1,8 @@ +Options +ExecCGI +AddHandler cgi-script .pl + + + RewriteEngine On + RewriteBase /images/ + RewriteRule ^(.*)$ /cgi-bin/script.pl?nombre=$1 [L,QSA,NC] + diff --git a/images/Dockerfile b/images/Dockerfile new file mode 100644 index 0000000000..3b3a5e19c8 --- /dev/null +++ b/images/Dockerfile @@ -0,0 +1,20 @@ +FROM httpd:latest + +# Habilita mod_cgi y configura Apache para ejecutar scripts CGI +RUN sed -i '/mod_cgi/s/^#//g' /usr/local/apache2/conf/httpd.conf +RUN echo "AddHandler cgi-script .cgi .pl" >> /usr/local/apache2/conf/httpd.conf +RUN echo "ScriptAlias /cgi-bin/ /usr/local/apache2/cgi-bin/" >> /usr/local/apache2/conf/httpd.conf +RUN chmod -R 755 /usr/local/apache2/cgi-bin/ + +# Habilita mod_rewrite +RUN sed -i '/mod_rewrite/s/^#//g' /usr/local/apache2/conf/httpd.conf + +# Copia el script CGI al directorio /usr/local/apache2/cgi-bin/ +COPY cgi-bin/ /usr/local/apache2/cgi-bin/ +RUN chmod +x /usr/local/apache2/cgi-bin/script.pl + +# Copia las imágenes al directorio htdocs/images +COPY images/ /usr/local/apache2/htdocs/images/ + +# Copia el archivo .htaccess para configurar el directorio htdocs/images +COPY .htaccess /usr/local/apache2/htdocs/images/.htaccess diff --git a/images/cgi-bin/.htaccess b/images/cgi-bin/.htaccess new file mode 100644 index 0000000000..c4e0a039a8 --- /dev/null +++ b/images/cgi-bin/.htaccess @@ -0,0 +1,2 @@ +Options +ExecCGI +AddHandler cgi-script .pl diff --git a/images/cgi-bin/hola_mundo.pl b/images/cgi-bin/hola_mundo.pl new file mode 100644 index 0000000000..cc65e14795 --- /dev/null +++ b/images/cgi-bin/hola_mundo.pl @@ -0,0 +1,8 @@ +#!/usr/bin/perl +use strict; +use warnings; + +print "Content-type: text/html\n\n"; +print "Hola Mundo en Perl"; +print "

Hola Mundo desde Perl

"; +print ""; diff --git a/images/cgi-bin/mostrar-md5.pl b/images/cgi-bin/mostrar-md5.pl new file mode 100644 index 0000000000..c432547c9d --- /dev/null +++ b/images/cgi-bin/mostrar-md5.pl @@ -0,0 +1,18 @@ +#!/usr/bin/perl +use strict; +use warnings; +use Digest::MD5; + +# Leer el nombre del archivo desde la consulta +my $archivo = $ENV{'QUERY_STRING'}; + +# Calcular el MD5 del nombre del archivo +my $md5 = Digest::MD5->new; +$md5->add($archivo); +my $hash = $md5->hexdigest; + +# Imprimir el resultado +print "Content-type: text/html\n\n"; +print "MD5 del nombre del archivo"; +print "

MD5 del nombre del archivo: $hash

"; +print ""; diff --git a/images/cgi-bin/script.pl b/images/cgi-bin/script.pl new file mode 100644 index 0000000000..9852460f66 --- /dev/null +++ b/images/cgi-bin/script.pl @@ -0,0 +1,27 @@ +#!/usr/bin/perl +use strict; +use warnings; +use Digest::MD5; +use File::Basename; + +sub calcular_hash { + my ($archivo) = @_; + + # Obtener solo el nombre del archivo sin la ruta + my $nombre_archivo = fileparse($archivo); + + # Calcular el hash MD5 del nombre del archivo + my $md5 = Digest::MD5->new; + $md5->add($nombre_archivo); + my $hash = $md5->hexdigest; + + return $hash; +} + +# Obtener el nombre del archivo de la URL +my $archivo_url = $ENV{'REQUEST_URI'}; +my $hash_archivo = calcular_hash($archivo_url); + +# Imprimir el hash como respuesta +print "Content-type: text/plain\n\n"; +print "Hash del nombre del archivo: $hash_archivo\n"; diff --git a/images/docker-compose.yml b/images/docker-compose.yml new file mode 100644 index 0000000000..46402d9583 --- /dev/null +++ b/images/docker-compose.yml @@ -0,0 +1,8 @@ +version: '3' +services: + apache: + build: + context: . + dockerfile: Dockerfile + ports: + - "8080:80" diff --git a/storage/image/prod.sh b/storage/image/prod.sh index 9d7972e1d8..52dd6ae6cf 100644 --- a/storage/image/prod.sh +++ b/storage/image/prod.sh @@ -15,12 +15,14 @@ for image in "$directorio_principal"/*; do fileName=$(basename "$image") imageName="${fileName%.*}" hash=$(echo -n "$imageName" | sha1sum | awk '{print $1}') +echo "$(dirname "$image")/${hash:0:2}/${hash:2:2}" + path=$(dirname "$image")/${hash:2:2}/${hash:0:2} mkdir -p $path # Crear un enlace simbólico en la carpeta principal - ln -s "$image" "$fileName" - mv $image $path/$fileName + ln -s "$image" "$1/$fileName" + fi # done # fi diff --git a/storage/image/reestructure.sh b/storage/image/reestructure.sh index 06786bffd8..3f569e63ce 100644 --- a/storage/image/reestructure.sh +++ b/storage/image/reestructure.sh @@ -6,6 +6,8 @@ for collection in */ ; do fileName=$(basename "$image") imageName="${fileName%.*}" hash=$(echo -n "$imageName" | sha1sum | awk '{print $1}') + echo $image + echo ${hash:2:2}/${hash:0:2} mkdir -p $(dirname "$image")/${hash:2:2}/${hash:0:2} ln -s $image $(dirname "$image")/${hash:2:2}/${hash:0:2}/$fileName done -- 2.40.1 From 838c56d77075162f2a4421ba599ba70c1e150872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Segarra=20Mart=C3=ADnez?= Date: Sat, 16 Dec 2023 22:52:12 +0100 Subject: [PATCH 08/24] approach --- images/.htaccess | 6 +---- images/Dockerfile | 46 ++++++++++++++++++++++++++++++++------ images/_.htaccess | 17 ++++++++++++++ images/apache2.conf | 17 ++++++++++++++ images/docker-compose.yml | 13 ++++++----- images/httpd.conf | 22 ++++++++++++++++++ images/www/index.html | 2 ++ images/www/nuevo_script.js | 4 ++++ images/www/script.js | 8 +++++++ images/www/script.pl | 42 ++++++++++++++++++++++++++++++++++ 10 files changed, 159 insertions(+), 18 deletions(-) create mode 100644 images/_.htaccess create mode 100644 images/apache2.conf create mode 100644 images/httpd.conf create mode 100644 images/www/index.html create mode 100644 images/www/nuevo_script.js create mode 100644 images/www/script.js create mode 100644 images/www/script.pl diff --git a/images/.htaccess b/images/.htaccess index 6b16a3dd68..57cde653f3 100644 --- a/images/.htaccess +++ b/images/.htaccess @@ -1,8 +1,4 @@ -Options +ExecCGI -AddHandler cgi-script .pl - RewriteEngine On - RewriteBase /images/ - RewriteRule ^(.*)$ /cgi-bin/script.pl?nombre=$1 [L,QSA,NC] + RewriteRule ^(.+)\.(jpg|png|jpeg)$ script.pl?name=$1&ext=$2 [L,QSA] diff --git a/images/Dockerfile b/images/Dockerfile index 3b3a5e19c8..27cd1308dd 100644 --- a/images/Dockerfile +++ b/images/Dockerfile @@ -1,20 +1,52 @@ FROM httpd:latest -# Habilita mod_cgi y configura Apache para ejecutar scripts CGI +# Habilitar mod_rewrite y configurar Apache + +RUN apt-get update && apt-get install -y curl libcgi-pm-perl +# Habilitar mod_rewrite y mod_cgi +RUN sed -i '/mod_rewrite/s/^#//g' /usr/local/apache2/conf/httpd.conf RUN sed -i '/mod_cgi/s/^#//g' /usr/local/apache2/conf/httpd.conf RUN echo "AddHandler cgi-script .cgi .pl" >> /usr/local/apache2/conf/httpd.conf -RUN echo "ScriptAlias /cgi-bin/ /usr/local/apache2/cgi-bin/" >> /usr/local/apache2/conf/httpd.conf -RUN chmod -R 755 /usr/local/apache2/cgi-bin/ +RUN echo "Include conf/extra/httpd-vhosts.conf" >> /usr/local/apache2/conf/httpd.conf +# Habilitar mod_cgi +RUN sed -i '/mod_cgi/s/^#//g' /usr/local/apache2/conf/httpd.conf +RUN echo "LoadModule cgid_module modules/mod_cgid.so" >> /usr/local/apache2/conf/httpd.conf -# Habilita mod_rewrite +# Habilitar mod_rewrite si aún no está habilitado RUN sed -i '/mod_rewrite/s/^#//g' /usr/local/apache2/conf/httpd.conf -# Copia el script CGI al directorio /usr/local/apache2/cgi-bin/ +# Configurar Apache para ejecutar scripts CGI +# RUN echo "ScriptAlias /cgi-bin/ \"/usr/local/apache2/cgi-bin/\"" >> /usr/local/apache2/conf/httpd.conf +# RUN echo "" >> /usr/local/apache2/conf/httpd.conf +# RUN echo " AllowOverride None" >> /usr/local/apache2/conf/httpd.conf +# RUN echo " Options +ExecCGI" >> /usr/local/apache2/conf/httpd.conf +# RUN echo " Require all granted" >> /usr/local/apache2/conf/httpd.conf +# RUN echo "" >> /usr/local/apache2/conf/httpd.conf + +# Configurar Apache para ejecutar scripts CGI +# RUN echo "" >> /usr/local/apache2/conf/httpd.conf +# RUN echo " Options +ExecCGI" >> /usr/local/apache2/conf/httpd.conf +# RUN echo " AllowOverride None" >> /usr/local/apache2/conf/httpd.conf +# RUN echo " AddHandler cgi-script .cgi .pl" >> /usr/local/apache2/conf/httpd.conf +# RUN echo " Require all granted" >> /usr/local/apache2/conf/httpd.conf +# RUN echo "" >> /usr/local/apache2/conf/httpd.conf +# Copiar scripts CGI al directorio correspondiente COPY cgi-bin/ /usr/local/apache2/cgi-bin/ -RUN chmod +x /usr/local/apache2/cgi-bin/script.pl + + +# Copiar la configuración de Apache2 y los archivos del sitio +COPY apache2.conf /usr/local/apache2/conf/extra/httpd-vhosts.conf +# RUN chmod +x www/script.pl +COPY www/ /usr/local/apache2/htdocs/ # Copia las imágenes al directorio htdocs/images COPY images/ /usr/local/apache2/htdocs/images/ # Copia el archivo .htaccess para configurar el directorio htdocs/images -COPY .htaccess /usr/local/apache2/htdocs/images/.htaccess +COPY .htaccess /usr/local/apache2/htdocs/ +RUN chmod +x /usr/local/apache2/htdocs/script.pl +RUN chmod +x /usr/local/apache2/cgi-bin/script.pl + +# Habilitar reescritura y reiniciar Apache2 +RUN echo "RewriteEngine On" >> /usr/local/apache2/conf/extra/httpd-vhosts.conf +RUN echo "Include conf/extra/httpd-vhosts.conf" >> /usr/local/apache2/conf/httpd.conf diff --git a/images/_.htaccess b/images/_.htaccess new file mode 100644 index 0000000000..ac787882ab --- /dev/null +++ b/images/_.htaccess @@ -0,0 +1,17 @@ + + + Options +ExecCGI +AddHandler cgi-script .pl + + + RewriteEngine On + RewriteBase /images/ + RewriteRule ^(.*)$ /cgi-bin/script.pl?nombre=$1 [L,QSA,NC] + + + diff --git a/images/apache2.conf b/images/apache2.conf new file mode 100644 index 0000000000..de6efeac23 --- /dev/null +++ b/images/apache2.conf @@ -0,0 +1,17 @@ +# apache2.conf + + ServerAdmin webmaster@localhost + DocumentRoot /usr/local/apache2/htdocs + + Options +ExecCGI + AddHandler cgi-script .cgi .pl + Require all granted + + + Options Indexes FollowSymLinks + AllowOverride All + Require all granted + Options +ExecCGI + AddHandler cgi-script .cgi .pl + + diff --git a/images/docker-compose.yml b/images/docker-compose.yml index 46402d9583..2cb335a4ac 100644 --- a/images/docker-compose.yml +++ b/images/docker-compose.yml @@ -1,8 +1,9 @@ version: '3' services: - apache: - build: - context: . - dockerfile: Dockerfile - ports: - - "8080:80" + apache: + build: + context: . + dockerfile: Dockerfile + ports: + - "8080:80" + diff --git a/images/httpd.conf b/images/httpd.conf new file mode 100644 index 0000000000..78e9218f2f --- /dev/null +++ b/images/httpd.conf @@ -0,0 +1,22 @@ +# # httpd.conf +# +# AllowOverride All +# Options +ExecCGI +# Require all granted +# + +# # httpd.conf +# +# StartServers 5 +# MinSpareServers 5 +# MaxSpareServers 10 +# MaxClients 150 +# MaxRequestsPerChild 0 +# + + +# # httpd.conf +# +# AllowOverride All +# Require all granted +# diff --git a/images/www/index.html b/images/www/index.html new file mode 100644 index 0000000000..7e72cbd382 --- /dev/null +++ b/images/www/index.html @@ -0,0 +1,2 @@ + + diff --git a/images/www/nuevo_script.js b/images/www/nuevo_script.js new file mode 100644 index 0000000000..0dee10bfab --- /dev/null +++ b/images/www/nuevo_script.js @@ -0,0 +1,4 @@ +console.log('adios'); + +window.onload = function() { +}; diff --git a/images/www/script.js b/images/www/script.js new file mode 100644 index 0000000000..3d1fc098b8 --- /dev/null +++ b/images/www/script.js @@ -0,0 +1,8 @@ +console.log('hola'); +window.onload = function() { + // document.body = ''; + let img = document.createElement('img'); + img.src = '../../images/_DSC5302.jpg'; + let src = document.getElementById('header'); + src.appendChild(img); +}; diff --git a/images/www/script.pl b/images/www/script.pl new file mode 100644 index 0000000000..ad4327359d --- /dev/null +++ b/images/www/script.pl @@ -0,0 +1,42 @@ +#!/usr/bin/perl +use strict; +use warnings; + +use CGI; +use Digest::MD5 qw(md5_hex); + +my $cgi = CGI->new; + +print "Content-type: text/html\n\n"; +# print $cgi->header('text/javascript'); +my $name = $cgi->param('name') || 'default'; +my $ext = $cgi->param('ext') || 'default'; +my $param = $cgi->param('param') || 'default'; + +# Obtén el string desde la línea de comandos o proporciona un valor predeterminado +my $input_string = $cgi->param('name') || "Hola, mundo!"; + +# Calcula el valor hash MD5 del string +my $hash_value = md5_hex($input_string); +# Obtiene solo los 2 primeros caracteres del hash MD5 +my $first_characters = substr($hash_value, 0, 2); +# Obtiene solo los 2 primeros caracteres del hash MD5 +my $second_characters = substr($hash_value, 2, 2); +# Imprime el resultado +print "String: $input_string\n"; +print "Hash MD5: $hash_value\n"; +# Contenido HTML o cualquier otra salida del script +print " +

$ext

+

$input_string

+

$hash_value

+

$first_characters

+

$second_characters

+ "; -- 2.40.1 From 0da816ca35d8efd0d9eeecdcb6aaaf51c03087e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Segarra=20Mart=C3=ADnez?= Date: Sun, 17 Dec 2023 00:07:33 +0100 Subject: [PATCH 09/24] approach --- images/.htaccess | 2 +- images/Dockerfile | 5 ++- images/_.htaccess | 2 +- images/docker-compose.yml | 3 ++ images/www/script.pl | 65 ++++++++++++++++++++++++++------------- 5 files changed, 52 insertions(+), 25 deletions(-) diff --git a/images/.htaccess b/images/.htaccess index 57cde653f3..84c8c997be 100644 --- a/images/.htaccess +++ b/images/.htaccess @@ -1,4 +1,4 @@ RewriteEngine On - RewriteRule ^(.+)\.(jpg|png|jpeg)$ script.pl?name=$1&ext=$2 [L,QSA] + RewriteRule ^(.+)\.(jpg|png|jpeg)$ script.pl?name=$1 [L,QSA] diff --git a/images/Dockerfile b/images/Dockerfile index 27cd1308dd..f6f8077956 100644 --- a/images/Dockerfile +++ b/images/Dockerfile @@ -40,7 +40,7 @@ COPY apache2.conf /usr/local/apache2/conf/extra/httpd-vhosts.conf COPY www/ /usr/local/apache2/htdocs/ # Copia las imágenes al directorio htdocs/images -COPY images/ /usr/local/apache2/htdocs/images/ +# COPY images/ /usr/local/apache2/htdocs/images/ # Copia el archivo .htaccess para configurar el directorio htdocs/images COPY .htaccess /usr/local/apache2/htdocs/ @@ -50,3 +50,6 @@ RUN chmod +x /usr/local/apache2/cgi-bin/script.pl # Habilitar reescritura y reiniciar Apache2 RUN echo "RewriteEngine On" >> /usr/local/apache2/conf/extra/httpd-vhosts.conf RUN echo "Include conf/extra/httpd-vhosts.conf" >> /usr/local/apache2/conf/httpd.conf + +# CMD y ENTRYPOINT para iniciar Apache2, según la imagen original +CMD ["httpd-foreground"] diff --git a/images/_.htaccess b/images/_.htaccess index ac787882ab..4a5135d8ea 100644 --- a/images/_.htaccess +++ b/images/_.htaccess @@ -1,4 +1,4 @@ - + Options +ExecCGI AddHandler cgi-script .pl diff --git a/images/docker-compose.yml b/images/docker-compose.yml index 2cb335a4ac..42f1e31a4d 100644 --- a/images/docker-compose.yml +++ b/images/docker-compose.yml @@ -1,6 +1,9 @@ version: '3' services: apache: + volumes: + - ./images:/usr/local/apache2/htdocs/images/ + build: context: . dockerfile: Dockerfile diff --git a/images/www/script.pl b/images/www/script.pl index ad4327359d..eb67254d5c 100644 --- a/images/www/script.pl +++ b/images/www/script.pl @@ -1,42 +1,63 @@ #!/usr/bin/perl use strict; use warnings; +use Cwd qw(abs_path); +my $script_path = abs_path($0); use CGI; -use Digest::MD5 qw(md5_hex); - +use Digest::SHA qw(sha1_hex); +my $pwd = `pwd`; my $cgi = CGI->new; +my $query_string = $ENV{'QUERY_STRING'}; +# print "Content-type: text/html\n\n"; -print "Content-type: text/html\n\n"; # print $cgi->header('text/javascript'); my $name = $cgi->param('name') || 'default'; my $ext = $cgi->param('ext') || 'default'; my $param = $cgi->param('param') || 'default'; # Obtén el string desde la línea de comandos o proporciona un valor predeterminado +# print "Ruta del script Perl: "; my $input_string = $cgi->param('name') || "Hola, mundo!"; # Calcula el valor hash MD5 del string -my $hash_value = md5_hex($input_string); +my $hash_value = sha1_hex($input_string); # Obtiene solo los 2 primeros caracteres del hash MD5 -my $first_characters = substr($hash_value, 0, 2); +my $first_characters = substr($hash_value, 2, 2); # Obtiene solo los 2 primeros caracteres del hash MD5 -my $second_characters = substr($hash_value, 2, 2); +my $second_characters = substr($hash_value, 0, 2); +my $request_path = $ENV{'REQUEST_PATH'} || ''; +my $new_path ="../../images/transform/$first_characters/$second_characters/$input_string"; # Imprime el resultado -print "String: $input_string\n"; -print "Hash MD5: $hash_value\n"; +# print "String: $input_string\n"; +# print "Hash MD5: $hash_value\n"; # Contenido HTML o cualquier otra salida del script -print " -

$ext

-

$input_string

-

$hash_value

-

$first_characters

-

$second_characters

- "; +# print " +#

$ext

+#

$script_path

+#

$new_path

+#

$input_string

+#

$pwd

+#

$query_string

+#

$request_path

+#

$hash_value

+#

$first_characters

+#

$second_characters

+# Abre la imagen en modo binario +print "Content-type: image/jpeg\n\n" +open my $imagen, '<', '../images/_DSC5308.jpg' or die "No se pudo abrir la imagen: $!"; + +# Imprime los bytes de la imagen directamente en la salida estándar +binmode STDOUT; +print while <$imagen>; + +# Cierra el archivo +close $imagen; + # print ""; -- 2.40.1 From 166f25470d1b6a6a4b1e3406efaba6ce7f5ad7be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Segarra=20Mart=C3=ADnez?= Date: Sun, 17 Dec 2023 00:33:52 +0100 Subject: [PATCH 10/24] done --- images/.htaccess | 2 +- images/www/script.pl | 48 ++++++++------------------------------------ 2 files changed, 9 insertions(+), 41 deletions(-) diff --git a/images/.htaccess b/images/.htaccess index 84c8c997be..2b778acaf1 100644 --- a/images/.htaccess +++ b/images/.htaccess @@ -1,4 +1,4 @@ RewriteEngine On - RewriteRule ^(.+)\.(jpg|png|jpeg)$ script.pl?name=$1 [L,QSA] + RewriteRule ^(.+)\.(jpg|png|jpeg)$ script.pl?value=$1.$2&name=$1 [L,QSA] diff --git a/images/www/script.pl b/images/www/script.pl index eb67254d5c..5e3515e05c 100644 --- a/images/www/script.pl +++ b/images/www/script.pl @@ -1,53 +1,27 @@ #!/usr/bin/perl use strict; use warnings; -use Cwd qw(abs_path); -my $script_path = abs_path($0); use CGI; use Digest::SHA qw(sha1_hex); -my $pwd = `pwd`; + my $cgi = CGI->new; -my $query_string = $ENV{'QUERY_STRING'}; -# print "Content-type: text/html\n\n"; - -# print $cgi->header('text/javascript'); -my $name = $cgi->param('name') || 'default'; -my $ext = $cgi->param('ext') || 'default'; -my $param = $cgi->param('param') || 'default'; - -# Obtén el string desde la línea de comandos o proporciona un valor predeterminado -# print "Ruta del script Perl: "; my $input_string = $cgi->param('name') || "Hola, mundo!"; +my $input_value = $cgi->param('value') || "Hola, mundo!"; # Calcula el valor hash MD5 del string my $hash_value = sha1_hex($input_string); # Obtiene solo los 2 primeros caracteres del hash MD5 my $first_characters = substr($hash_value, 2, 2); -# Obtiene solo los 2 primeros caracteres del hash MD5 +# Obtiene solo los 2 segundos caracteres del hash MD5 my $second_characters = substr($hash_value, 0, 2); -my $request_path = $ENV{'REQUEST_PATH'} || ''; -my $new_path ="../../images/transform/$first_characters/$second_characters/$input_string"; +my $new_path ="images/transform/$first_characters/$second_characters/$input_value"; # Imprime el resultado -# print "String: $input_string\n"; -# print "Hash MD5: $hash_value\n"; -# Contenido HTML o cualquier otra salida del script -# print " -#

$ext

-#

$script_path

-#

$new_path

-#

$input_string

-#

$pwd

-#

$query_string

-#

$request_path

-#

$hash_value

-#

$first_characters

-#

$second_characters

+# Establecer el tipo de contenido a imagen JPEG +print "Content-type: image/jpeg\n\n"; + # Abre la imagen en modo binario -print "Content-type: image/jpeg\n\n" -open my $imagen, '<', '../images/_DSC5308.jpg' or die "No se pudo abrir la imagen: $!"; +open my $imagen, '<', $new_path or die "No se pudo abrir la imagen: $!"; # Imprime los bytes de la imagen directamente en la salida estándar binmode STDOUT; @@ -55,9 +29,3 @@ print while <$imagen>; # Cierra el archivo close $imagen; - # print ""; -- 2.40.1 From b1d5a62aa5e0e69d02e7d27b8f14dbc3bf59df6a Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 18 Dec 2023 10:33:45 +0100 Subject: [PATCH 11/24] refs #5576 perf update script.pl --- images/www/script.pl | 75 ++++++++++++++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 20 deletions(-) diff --git a/images/www/script.pl b/images/www/script.pl index 5e3515e05c..005c2f9c11 100644 --- a/images/www/script.pl +++ b/images/www/script.pl @@ -2,30 +2,65 @@ use strict; use warnings; -use CGI; use Digest::SHA qw(sha1_hex); +use CGI; my $cgi = CGI->new; -my $input_string = $cgi->param('name') || "Hola, mundo!"; -my $input_value = $cgi->param('value') || "Hola, mundo!"; +my $input_name = $cgi->param('name') || "default"; +my $input_value = $cgi->param('value') || "default"; +my $new_path; -# Calcula el valor hash MD5 del string -my $hash_value = sha1_hex($input_string); -# Obtiene solo los 2 primeros caracteres del hash MD5 -my $first_characters = substr($hash_value, 2, 2); -# Obtiene solo los 2 segundos caracteres del hash MD5 -my $second_characters = substr($hash_value, 0, 2); -my $new_path ="images/transform/$first_characters/$second_characters/$input_value"; -# Imprime el resultado -# Establecer el tipo de contenido a imagen JPEG -print "Content-type: image/jpeg\n\n"; +# Dividir la ruta usando el símbolo "/" para extraaer el nombre del archivo SIN extension +my $fileName= (split('/', $input_name))[-1]; +# Dividir la ruta usando el símbolo "/" para extraaer el nombre del archivo CON extension +my $file= (split('/', $input_value))[-1]; +my $exists = -e "$input_value"; +# print $exists; +# $exists = -e "$input_value"; +# print $exists; +if($exists) { + # print "Content-type: text/html\n\n"; + $new_path ="$input_value"; + # print "

$new_path

"; +} else { + # Calcula el valor hash MD5 del string + my $hash_value = sha1_hex($fileName); + # Obtiene solo los 2 primeros caracteres del hash MD5 + my $first_characters = substr($hash_value, 0, 2); + # Obtiene solo los 2 segundos caracteres del hash MD5 + my $second_characters = substr($hash_value, 1, 2); + $new_path ="images/$first_characters/$second_characters/$file"; + # Imprime el resultado + # Establecer el tipo de contenido a imagen JPEG + # print "Content-type: text/html\n\n"; + # print "

Ultimo elemento es: $fileName

"; + # print "

input_name==>$input_name

"; + # print "

input_value==>$input_value

"; + # print "

fileName==>$fileName

"; + # print "

file==>$file

"; + # print "

hash_value==>$hash_value

"; + # print "

first_characters==>$first_characters/$second_characters/$input_value

"; + # print "

new_path==>$new_path

"; -# Abre la imagen en modo binario -open my $imagen, '<', $new_path or die "No se pudo abrir la imagen: $!"; + # Abre la imagen en modo binario -# Imprime los bytes de la imagen directamente en la salida estándar -binmode STDOUT; -print while <$imagen>; + # open my $imagen, '<', $new_path or die "No se pudo abrir la imagen: $!"; -# Cierra el archivo -close $imagen; +} +# Verifica si $imagen está definida antes de intentar usarla +if (defined $new_path) { + abrir_imagen($new_path); + # print "

HOLA

"; +} +sub abrir_imagen { + my ($ruta) = @_; + print "Content-type: image/jpeg\n\n"; + open my $imagen, '<', $ruta or die "No se pudo abrir la imagen: $!"; + + # Imprime los bytes de la imagen directamente en la salida estándar + binmode STDOUT; + print while <$imagen>; + + # Cierra el archivo + close $imagen; +} -- 2.40.1 From f4f2333d36aaa3d1436dd68aa68e4710c04009fb Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 18 Dec 2023 11:33:28 +0100 Subject: [PATCH 12/24] refs #5576 perf update scripts sh --- storage/image/move.sh | 6 ++++-- storage/image/prod.sh | 20 +++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/storage/image/move.sh b/storage/image/move.sh index 49f8487673..a981eab8f0 100644 --- a/storage/image/move.sh +++ b/storage/image/move.sh @@ -1,5 +1,5 @@ #!/bin/bash - +DIR_LEVELS=2 for collection in */ ; do for size in "$collection"*/ ; do for image in "$size"* ; do @@ -7,7 +7,9 @@ for collection in */ ; do fileName=$(basename "$image") imageName="${fileName%.*}" hash=$(echo -n "$imageName" | sha1sum | awk '{print $1}') - path=$(dirname "$image")/${hash:2:2}/${hash:0:2} + first=$(echo "$hash" | cut -c"$inicio"-"$DIR_LEVELS") + second=$(echo "$hash" | cut -c"$DIR_LEVELS"-"$fin") + path=$(dirname "$image")/${first}/${second} mkdir -p $path ln -s "$image" "$fileName" mv $image $path/$fileName diff --git a/storage/image/prod.sh b/storage/image/prod.sh index 52dd6ae6cf..9c6ab66c98 100644 --- a/storage/image/prod.sh +++ b/storage/image/prod.sh @@ -1,27 +1,29 @@ #!/bin/bash - +MIN_DIR_LEVELS=0 +DIR_LEVELS=2 +START=1 +END=3 # Directorio que contiene las carpetas con las fotos -directorio_principal=$1 +MAIN_DIR=$1 # Iterar a través de cada carpeta en el directorio principal -for image in "$directorio_principal"/*; do +for image in "$MAIN_DIR"/*; do # Verificar si es un directorio - # if [ -d "$image" ]; then # Iterar a través de cada imagen en la subcarpeta - # for image in "$image"/*.png; do # Verificar si es un archivo if [ -f "$image" ]; then # Obtener el nombre de la imagen fileName=$(basename "$image") imageName="${fileName%.*}" hash=$(echo -n "$imageName" | sha1sum | awk '{print $1}') -echo "$(dirname "$image")/${hash:0:2}/${hash:2:2}" - - path=$(dirname "$image")/${hash:2:2}/${hash:0:2} + first=$(echo "$hash" | cut -c"$START"-"$DIR_LEVELS") + echo "$first" + second=$(echo "$hash" | cut -c"$DIR_LEVELS"-"$END") + echo "$second" + path=$(dirname "$image")/${first}/${second} mkdir -p $path # Crear un enlace simbólico en la carpeta principal mv $image $path/$fileName - ln -s "$image" "$1/$fileName" fi # done -- 2.40.1 From c1e245c2eabda1a07253663567a0ff76c79f0c23 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 19 Dec 2023 08:44:11 +0100 Subject: [PATCH 13/24] refs #5576 perf: remove bad comments --- back/models/image.js | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/back/models/image.js b/back/models/image.js index f7fb08bfae..fd3535e463 100644 --- a/back/models/image.js +++ b/back/models/image.js @@ -74,15 +74,12 @@ module.exports = Self => { Self.createLink = async(parent, child = null) => { try { const exists = await fs.exists(parent); - if (exists) - await fs.unlink(parent); + exists && await fs.unlink(parent); } catch (e) { throw new Error(e); } try { await fs.symlink(child, parent); - const link = await fs.readlink(parent); - console.log(link); } catch (e) { throw new Error(e); } @@ -96,17 +93,16 @@ module.exports = Self => { }) { const {name, dstDir} = await Self.handleFolderDestination(fileName); try { - await models.Image.upsertWithWhere({ + const baseUpsert = { name, collectionFk: collectionName, - }, - { - name, - collectionFk: collectionName, - updated: Date.vnNow() / 1000, - }); + }; + await models.Image.upsertWithWhere(baseUpsert, + { + ...baseUpsert, + updated: Date.vnNow() / 1000, + }); } catch (e) { - debugger; throw new Error(e); } const collection = await Self.getCollection(collectionName); @@ -130,7 +126,6 @@ module.exports = Self => { try { await fs.mkdir(fullSizePath, {recursive: true}); } catch (e) { - debugger; throw new Error(e); } const gmInstance = gm(srcFile); @@ -138,7 +133,7 @@ module.exports = Self => { let fileHeight = null; gmInstance.size(function(err, size) { - if (err) console.error(err); + if (err) throw new Error(err); [fileWidth, fileHeight] = parseSize(size); }); try { @@ -153,23 +148,10 @@ module.exports = Self => { }); }); } catch (e) { - debugger; throw new Error(e); } await Self.createLink(toFullSizeOriginalPath, toFullSizePath); - /* try { - await fs.unlink(toFullSizeOriginalPath); - } catch (e) { - debugger; - throw new Error(e); - } - try { - await fs.symlink(toFullSizeOriginalPath, toFullSizePath, 'file'); - } catch (e) { - debugger; - throw new Error(e); - }*/ // To collection sizes for (const size of collection.sizes()) { const [width, height] = parseSize(size); @@ -182,7 +164,6 @@ module.exports = Self => { try { await fs.mkdir(sizePath, {recursive: true}); } catch (e) { - debugger; throw new Error(e); } @@ -216,7 +197,6 @@ module.exports = Self => { const toSizeOriginalPath = `${sizeOriginalPath}/${fileName}`; - // if (fileWidth > width && fileHeight < height) await Self.createLink(toSizeOriginalPath, toSizePath); } }; -- 2.40.1 From 1196b3214803fbfd4606bc02b99eab978d3a967a Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 22 Dec 2023 09:46:04 +0100 Subject: [PATCH 14/24] refs #5576 perf: remove bad code --- images/Dockerfile | 39 +++++------------------ images/_.htaccess | 17 ---------- images/apache2.conf | 6 ---- images/cgi-bin/.htaccess | 2 -- images/cgi-bin/hola_mundo.pl | 8 ----- images/cgi-bin/mostrar-md5.pl | 18 ----------- images/cgi-bin/script.pl | 27 ---------------- images/docker-compose.yml | 1 - images/httpd.conf | 22 ------------- images/www/index.html | 2 -- images/www/nuevo_script.js | 4 --- images/www/script.js | 8 ----- images/www/script.pl | 28 ++++------------ storage/image/Dockerfile | 30 ----------------- storage/image/mi-configuracion-httpd.conf | 24 -------------- 15 files changed, 14 insertions(+), 222 deletions(-) delete mode 100644 images/_.htaccess delete mode 100644 images/cgi-bin/.htaccess delete mode 100644 images/cgi-bin/hola_mundo.pl delete mode 100644 images/cgi-bin/mostrar-md5.pl delete mode 100644 images/cgi-bin/script.pl delete mode 100644 images/httpd.conf delete mode 100644 images/www/index.html delete mode 100644 images/www/nuevo_script.js delete mode 100644 images/www/script.js delete mode 100644 storage/image/Dockerfile delete mode 100644 storage/image/mi-configuracion-httpd.conf diff --git a/images/Dockerfile b/images/Dockerfile index f6f8077956..d267dcfce9 100644 --- a/images/Dockerfile +++ b/images/Dockerfile @@ -1,55 +1,32 @@ FROM httpd:latest -# Habilitar mod_rewrite y configurar Apache - RUN apt-get update && apt-get install -y curl libcgi-pm-perl -# Habilitar mod_rewrite y mod_cgi + +# Habilitar mod_rewrite RUN sed -i '/mod_rewrite/s/^#//g' /usr/local/apache2/conf/httpd.conf -RUN sed -i '/mod_cgi/s/^#//g' /usr/local/apache2/conf/httpd.conf RUN echo "AddHandler cgi-script .cgi .pl" >> /usr/local/apache2/conf/httpd.conf RUN echo "Include conf/extra/httpd-vhosts.conf" >> /usr/local/apache2/conf/httpd.conf + # Habilitar mod_cgi RUN sed -i '/mod_cgi/s/^#//g' /usr/local/apache2/conf/httpd.conf RUN echo "LoadModule cgid_module modules/mod_cgid.so" >> /usr/local/apache2/conf/httpd.conf -# Habilitar mod_rewrite si aún no está habilitado -RUN sed -i '/mod_rewrite/s/^#//g' /usr/local/apache2/conf/httpd.conf +# Habilitar reescritura +RUN echo "RewriteEngine On" >> /usr/local/apache2/conf/extra/httpd-vhosts.conf -# Configurar Apache para ejecutar scripts CGI -# RUN echo "ScriptAlias /cgi-bin/ \"/usr/local/apache2/cgi-bin/\"" >> /usr/local/apache2/conf/httpd.conf -# RUN echo "" >> /usr/local/apache2/conf/httpd.conf -# RUN echo " AllowOverride None" >> /usr/local/apache2/conf/httpd.conf -# RUN echo " Options +ExecCGI" >> /usr/local/apache2/conf/httpd.conf -# RUN echo " Require all granted" >> /usr/local/apache2/conf/httpd.conf -# RUN echo "" >> /usr/local/apache2/conf/httpd.conf - -# Configurar Apache para ejecutar scripts CGI -# RUN echo "" >> /usr/local/apache2/conf/httpd.conf -# RUN echo " Options +ExecCGI" >> /usr/local/apache2/conf/httpd.conf -# RUN echo " AllowOverride None" >> /usr/local/apache2/conf/httpd.conf -# RUN echo " AddHandler cgi-script .cgi .pl" >> /usr/local/apache2/conf/httpd.conf -# RUN echo " Require all granted" >> /usr/local/apache2/conf/httpd.conf -# RUN echo "" >> /usr/local/apache2/conf/httpd.conf -# Copiar scripts CGI al directorio correspondiente -COPY cgi-bin/ /usr/local/apache2/cgi-bin/ # Copiar la configuración de Apache2 y los archivos del sitio COPY apache2.conf /usr/local/apache2/conf/extra/httpd-vhosts.conf + # RUN chmod +x www/script.pl COPY www/ /usr/local/apache2/htdocs/ -# Copia las imágenes al directorio htdocs/images -# COPY images/ /usr/local/apache2/htdocs/images/ - # Copia el archivo .htaccess para configurar el directorio htdocs/images COPY .htaccess /usr/local/apache2/htdocs/ -RUN chmod +x /usr/local/apache2/htdocs/script.pl -RUN chmod +x /usr/local/apache2/cgi-bin/script.pl -# Habilitar reescritura y reiniciar Apache2 -RUN echo "RewriteEngine On" >> /usr/local/apache2/conf/extra/httpd-vhosts.conf -RUN echo "Include conf/extra/httpd-vhosts.conf" >> /usr/local/apache2/conf/httpd.conf +# Habilita permisos de ejecución +RUN chmod +x /usr/local/apache2/htdocs/script.pl # CMD y ENTRYPOINT para iniciar Apache2, según la imagen original CMD ["httpd-foreground"] diff --git a/images/_.htaccess b/images/_.htaccess deleted file mode 100644 index 4a5135d8ea..0000000000 --- a/images/_.htaccess +++ /dev/null @@ -1,17 +0,0 @@ - - - Options +ExecCGI -AddHandler cgi-script .pl - - - RewriteEngine On - RewriteBase /images/ - RewriteRule ^(.*)$ /cgi-bin/script.pl?nombre=$1 [L,QSA,NC] - - - diff --git a/images/apache2.conf b/images/apache2.conf index de6efeac23..9e5018bd31 100644 --- a/images/apache2.conf +++ b/images/apache2.conf @@ -1,12 +1,6 @@ # apache2.conf - ServerAdmin webmaster@localhost DocumentRoot /usr/local/apache2/htdocs - - Options +ExecCGI - AddHandler cgi-script .cgi .pl - Require all granted - Options Indexes FollowSymLinks AllowOverride All diff --git a/images/cgi-bin/.htaccess b/images/cgi-bin/.htaccess deleted file mode 100644 index c4e0a039a8..0000000000 --- a/images/cgi-bin/.htaccess +++ /dev/null @@ -1,2 +0,0 @@ -Options +ExecCGI -AddHandler cgi-script .pl diff --git a/images/cgi-bin/hola_mundo.pl b/images/cgi-bin/hola_mundo.pl deleted file mode 100644 index cc65e14795..0000000000 --- a/images/cgi-bin/hola_mundo.pl +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; - -print "Content-type: text/html\n\n"; -print "Hola Mundo en Perl"; -print "

Hola Mundo desde Perl

"; -print ""; diff --git a/images/cgi-bin/mostrar-md5.pl b/images/cgi-bin/mostrar-md5.pl deleted file mode 100644 index c432547c9d..0000000000 --- a/images/cgi-bin/mostrar-md5.pl +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; -use Digest::MD5; - -# Leer el nombre del archivo desde la consulta -my $archivo = $ENV{'QUERY_STRING'}; - -# Calcular el MD5 del nombre del archivo -my $md5 = Digest::MD5->new; -$md5->add($archivo); -my $hash = $md5->hexdigest; - -# Imprimir el resultado -print "Content-type: text/html\n\n"; -print "MD5 del nombre del archivo"; -print "

MD5 del nombre del archivo: $hash

"; -print ""; diff --git a/images/cgi-bin/script.pl b/images/cgi-bin/script.pl deleted file mode 100644 index 9852460f66..0000000000 --- a/images/cgi-bin/script.pl +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; -use Digest::MD5; -use File::Basename; - -sub calcular_hash { - my ($archivo) = @_; - - # Obtener solo el nombre del archivo sin la ruta - my $nombre_archivo = fileparse($archivo); - - # Calcular el hash MD5 del nombre del archivo - my $md5 = Digest::MD5->new; - $md5->add($nombre_archivo); - my $hash = $md5->hexdigest; - - return $hash; -} - -# Obtener el nombre del archivo de la URL -my $archivo_url = $ENV{'REQUEST_URI'}; -my $hash_archivo = calcular_hash($archivo_url); - -# Imprimir el hash como respuesta -print "Content-type: text/plain\n\n"; -print "Hash del nombre del archivo: $hash_archivo\n"; diff --git a/images/docker-compose.yml b/images/docker-compose.yml index 42f1e31a4d..651face426 100644 --- a/images/docker-compose.yml +++ b/images/docker-compose.yml @@ -3,7 +3,6 @@ services: apache: volumes: - ./images:/usr/local/apache2/htdocs/images/ - build: context: . dockerfile: Dockerfile diff --git a/images/httpd.conf b/images/httpd.conf deleted file mode 100644 index 78e9218f2f..0000000000 --- a/images/httpd.conf +++ /dev/null @@ -1,22 +0,0 @@ -# # httpd.conf -# -# AllowOverride All -# Options +ExecCGI -# Require all granted -# - -# # httpd.conf -# -# StartServers 5 -# MinSpareServers 5 -# MaxSpareServers 10 -# MaxClients 150 -# MaxRequestsPerChild 0 -# - - -# # httpd.conf -# -# AllowOverride All -# Require all granted -# diff --git a/images/www/index.html b/images/www/index.html deleted file mode 100644 index 7e72cbd382..0000000000 --- a/images/www/index.html +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/images/www/nuevo_script.js b/images/www/nuevo_script.js deleted file mode 100644 index 0dee10bfab..0000000000 --- a/images/www/nuevo_script.js +++ /dev/null @@ -1,4 +0,0 @@ -console.log('adios'); - -window.onload = function() { -}; diff --git a/images/www/script.js b/images/www/script.js deleted file mode 100644 index 3d1fc098b8..0000000000 --- a/images/www/script.js +++ /dev/null @@ -1,8 +0,0 @@ -console.log('hola'); -window.onload = function() { - // document.body = ''; - let img = document.createElement('img'); - img.src = '../../images/_DSC5302.jpg'; - let src = document.getElementById('header'); - src.appendChild(img); -}; diff --git a/images/www/script.pl b/images/www/script.pl index 005c2f9c11..0fc4a24c1a 100644 --- a/images/www/script.pl +++ b/images/www/script.pl @@ -12,45 +12,29 @@ my $new_path; # Dividir la ruta usando el símbolo "/" para extraaer el nombre del archivo SIN extension my $fileName= (split('/', $input_name))[-1]; + # Dividir la ruta usando el símbolo "/" para extraaer el nombre del archivo CON extension my $file= (split('/', $input_value))[-1]; my $exists = -e "$input_value"; -# print $exists; -# $exists = -e "$input_value"; -# print $exists; + +# Compruebo si existe el archivo en la caperta general o no if($exists) { - # print "Content-type: text/html\n\n"; $new_path ="$input_value"; - # print "

$new_path

"; } else { # Calcula el valor hash MD5 del string my $hash_value = sha1_hex($fileName); + # Obtiene solo los 2 primeros caracteres del hash MD5 my $first_characters = substr($hash_value, 0, 2); + # Obtiene solo los 2 segundos caracteres del hash MD5 my $second_characters = substr($hash_value, 1, 2); + $new_path ="images/$first_characters/$second_characters/$file"; - # Imprime el resultado - # Establecer el tipo de contenido a imagen JPEG - # print "Content-type: text/html\n\n"; - # print "

Ultimo elemento es: $fileName

"; - # print "

input_name==>$input_name

"; - # print "

input_value==>$input_value

"; - # print "

fileName==>$fileName

"; - # print "

file==>$file

"; - # print "

hash_value==>$hash_value

"; - # print "

first_characters==>$first_characters/$second_characters/$input_value

"; - # print "

new_path==>$new_path

"; - - # Abre la imagen en modo binario - - # open my $imagen, '<', $new_path or die "No se pudo abrir la imagen: $!"; - } # Verifica si $imagen está definida antes de intentar usarla if (defined $new_path) { abrir_imagen($new_path); - # print "

HOLA

"; } sub abrir_imagen { my ($ruta) = @_; diff --git a/storage/image/Dockerfile b/storage/image/Dockerfile deleted file mode 100644 index 91a39b44f2..0000000000 --- a/storage/image/Dockerfile +++ /dev/null @@ -1,30 +0,0 @@ -# Usa la imagen oficial de Apache -FROM httpd:latest - -# Añade configuración del MPM prefork -# RUN echo "LoadModule mpm_prefork_module modules/mod_mpm_prefork.so" >> /usr/local/apache2/conf/httpd.conf -# RUN echo "LoadModule mpm_worker_module modules/mod_mpm_worker.so" >> /usr/local/apache2/conf/httpd.conf - -# Copia tu archivo de configuración personalizado (si lo tienes) -# COPY ./mi-configuracion-httpd.conf /usr/local/apache2/conf/httpd.conf -COPY ./image.png /usr/local/apache2/htdocs/ -COPY ./image.png /usr/local/apache2/htdocs/welcome.png -COPY ./.htaccess /usr/local/apache2/htdocs/ -RUN { \ - echo 'IncludeOptional conf.d/*.conf'; \ -} >> /usr/local/apache2/conf/httpd.conf \ - && mkdir /usr/local/apache2/conf.d - # Copy .htaccess into DocumentRoot -COPY ./.htaccess /var/www/html/ -# Habilita el módulo mod_rewrite -RUN sed -i 's/#LoadModule rewrite_module/LoadModule rewrite_module/' /usr/local/apache2/conf/httpd.conf -# RUN sed -i 's/#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so' /usr/local/apache2/conf/httpd.conf -# RUN sed -i 's/#LoadModule mpm_prefork_module/LoadModule mpm_prefork_module/' /usr/local/apache2/conf/httpd.conf -# RUN sed -i 's/#LoadModule mpm_worker_module modules/mod_mpm_worker.so' /usr/local/apache2/conf/httpd.conf -# RUN sed -i 's/#LoadModule mpm_worker_module/LoadModule mpm_worker_module/' /usr/local/apache2/conf/httpd.conf - -# Establece el propietario del directorio del servidor a www-data (usuario de Apache) -RUN chown -R www-data:www-data /usr/local/apache2/htdocs/ - -# Expón el puerto 80 para que sea accesible desde fuera del contenedor -EXPOSE 80 diff --git a/storage/image/mi-configuracion-httpd.conf b/storage/image/mi-configuracion-httpd.conf deleted file mode 100644 index 8f29543320..0000000000 --- a/storage/image/mi-configuracion-httpd.conf +++ /dev/null @@ -1,24 +0,0 @@ -# -# LoadModule mpm_prefork_module modules/mod_mpm_prefork.so -# - - - LoadModule mpm_worker_module modules/mod_mpm_worker.so - - - - - RewriteEngine On - - # Asegúrate de que el módulo crypto esté disponible - RewriteCond %{LA-U:CRYPTO:crypto} ^$ - - # Obtén el nombre del archivo sin la extensión - RewriteCond %{REQUEST_FILENAME} !-f - RewriteCond %{REQUEST_FILENAME} !-d - RewriteRule ^(.+)\.png$ - [E=FILENAME_NO_EXT:$1] - - # Calcula el hash del nombre del archivo - RewriteCond %{LA-U:CRYPTO:crypto} ^(.+)$ - RewriteRule ^(.+)\.png$ /images/%1.png [L] - -- 2.40.1 From 55b737f3761db335fdefc843727fc04034229d35 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 22 Dec 2023 09:57:27 +0100 Subject: [PATCH 15/24] refs #5576 perf: remove echo from sh files --- storage/image/prod.sh | 3 --- storage/image/reestructure.sh | 2 -- 2 files changed, 5 deletions(-) diff --git a/storage/image/prod.sh b/storage/image/prod.sh index 9c6ab66c98..d764c0dd48 100644 --- a/storage/image/prod.sh +++ b/storage/image/prod.sh @@ -17,14 +17,11 @@ for image in "$MAIN_DIR"/*; do imageName="${fileName%.*}" hash=$(echo -n "$imageName" | sha1sum | awk '{print $1}') first=$(echo "$hash" | cut -c"$START"-"$DIR_LEVELS") - echo "$first" second=$(echo "$hash" | cut -c"$DIR_LEVELS"-"$END") - echo "$second" path=$(dirname "$image")/${first}/${second} mkdir -p $path # Crear un enlace simbólico en la carpeta principal mv $image $path/$fileName - fi # done # fi diff --git a/storage/image/reestructure.sh b/storage/image/reestructure.sh index 3f569e63ce..06786bffd8 100644 --- a/storage/image/reestructure.sh +++ b/storage/image/reestructure.sh @@ -6,8 +6,6 @@ for collection in */ ; do fileName=$(basename "$image") imageName="${fileName%.*}" hash=$(echo -n "$imageName" | sha1sum | awk '{print $1}') - echo $image - echo ${hash:2:2}/${hash:0:2} mkdir -p $(dirname "$image")/${hash:2:2}/${hash:0:2} ln -s $image $(dirname "$image")/${hash:2:2}/${hash:0:2}/$fileName done -- 2.40.1 From 16cb42761e268b8734b2ff1fb7e97056bde9e4ad Mon Sep 17 00:00:00 2001 From: JAVIER SEGARRA MARTINEZ Date: Sat, 20 Jan 2024 11:22:41 +0000 Subject: [PATCH 16/24] refs #5576 perf: remove bad try/catch declarations --- back/models/image.js | 59 +++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/back/models/image.js b/back/models/image.js index fd3535e463..fec52759b1 100644 --- a/back/models/image.js +++ b/back/models/image.js @@ -62,10 +62,6 @@ module.exports = Self => { Self.removeLink = async(child, parent = null) => { try { await fs.unlink(child); - } catch (e) { - throw new Error(e); - } - try { await fs.symlink(parent, child); } catch (e) { throw new Error(e); @@ -75,10 +71,6 @@ module.exports = Self => { try { const exists = await fs.exists(parent); exists && await fs.unlink(parent); - } catch (e) { - throw new Error(e); - } - try { await fs.symlink(child, parent); } catch (e) { throw new Error(e); @@ -102,41 +94,36 @@ module.exports = Self => { ...baseUpsert, updated: Date.vnNow() / 1000, }); - } catch (e) { - throw new Error(e); - } - const collection = await Self.getCollection(collectionName); - const {maxWidth, maxHeight} = collection; + + const collection = await Self.getCollection(collectionName); + const {maxWidth, maxHeight} = collection; - // Update entity image file name - const model = models[collection.model]; - if (!model) throw new Error('No matching model found'); + // Update entity image file name + const model = models[collection.model]; + if (!model) throw new Error('No matching model found'); - const entity = await model.findById(entityId); - if (entity) - await entity.updateAttribute(collection.property, name); + const entity = await model.findById(entityId); + if (entity) + await entity.updateAttribute(collection.property, name); - // Resize - const collectionDir = await Self.getCollectionDir(collectionName); + // Resize + const collectionDir = await Self.getCollectionDir(collectionName); - // To max size - const _fullSizePath = Self.getFullSizePath(fileName, collectionDir, dstDir); + // To max size + const _fullSizePath = Self.getFullSizePath(fileName, collectionDir, dstDir); - const {fullSizePath, toFullSizePath, toFullSizeOriginalPath} = _fullSizePath; - try { + const {fullSizePath, toFullSizePath, toFullSizeOriginalPath} = _fullSizePath; + await fs.mkdir(fullSizePath, {recursive: true}); - } catch (e) { - throw new Error(e); - } - const gmInstance = gm(srcFile); - let fileWidth = null; - let fileHeight = null; + + const gmInstance = gm(srcFile); + let fileWidth = null; + let fileHeight = null; - gmInstance.size(function(err, size) { - if (err) throw new Error(err); - [fileWidth, fileHeight] = parseSize(size); - }); - try { + gmInstance.size(function(err, size) { + if (err) throw new Error(err); + [fileWidth, fileHeight] = parseSize(size); + }); await new Promise((resolve, reject) => { gmInstance .resize(maxWidth, maxHeight, '>') -- 2.40.1 From f6d0cf781774ad217fec90e9bb6f067ab69e0dfa Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 22 Jan 2024 12:47:11 +0100 Subject: [PATCH 17/24] refs #5576 feat update db/change version --- back/models/image.js | 110 +++++++++++---------- back/models/specs/images.spec.js | 42 +++++--- db/changes/240601/00-hederaImageConfig.sql | 4 + 3 files changed, 88 insertions(+), 68 deletions(-) create mode 100644 db/changes/240601/00-hederaImageConfig.sql diff --git a/back/models/image.js b/back/models/image.js index fec52759b1..41db43cae1 100644 --- a/back/models/image.js +++ b/back/models/image.js @@ -49,15 +49,19 @@ module.exports = Self => { }; Self.getFullSizePath = (fileName, collectionDir, dstDir) => { - const fullSizePath = path.join(collectionDir, `full/${dstDir}`); - const fullSizeOriginalPath = path.join(collectionDir, `full`); - const toFullSizePath = `${fullSizePath}/${fileName}`; - const toFullSizeOriginalPath = `${fullSizeOriginalPath}/${fileName}`; - return { - fullSizePath, - toFullSizePath, - toFullSizeOriginalPath - }; + try { + const fullSizePath = path.join(collectionDir, `full/${dstDir}`); + const fullSizeOriginalPath = path.join(collectionDir, `full`); + const toFullSizePath = `${fullSizePath}/${fileName}`; + const toFullSizeOriginalPath = `${fullSizeOriginalPath}/${fileName}`; + return { + fullSizePath, + toFullSizePath, + toFullSizeOriginalPath + }; + } catch (e) { + throw new Error(e); + } }; Self.removeLink = async(child, parent = null) => { try { @@ -94,7 +98,7 @@ module.exports = Self => { ...baseUpsert, updated: Date.vnNow() / 1000, }); - + const collection = await Self.getCollection(collectionName); const {maxWidth, maxHeight} = collection; @@ -113,9 +117,9 @@ module.exports = Self => { const _fullSizePath = Self.getFullSizePath(fileName, collectionDir, dstDir); const {fullSizePath, toFullSizePath, toFullSizeOriginalPath} = _fullSizePath; - + await fs.mkdir(fullSizePath, {recursive: true}); - + const gmInstance = gm(srcFile); let fileWidth = null; let fileHeight = null; @@ -134,57 +138,57 @@ module.exports = Self => { if (!err) resolve(data); }); }); - } catch (e) { - throw new Error(e); - } - await Self.createLink(toFullSizeOriginalPath, toFullSizePath); - // To collection sizes - for (const size of collection.sizes()) { - const [width, height] = parseSize(size); + await Self.createLink(toFullSizeOriginalPath, toFullSizePath); + // To collection sizes + for (const size of collection.sizes()) { + const [width, height] = parseSize(size); - const sizePath = path.join( - collectionDir, - `${formatWidthHeight(width, height)}/${dstDir}` - ); + const sizePath = path.join( + collectionDir, + `${formatWidthHeight(width, height)}/${dstDir}` + ); - try { - await fs.mkdir(sizePath, {recursive: true}); - } catch (e) { - throw new Error(e); - } + try { + await fs.mkdir(sizePath, {recursive: true}); + } catch (e) { + throw new Error(e); + } + + const toSizePath = `${sizePath}/${fileName}`; + if (+fileWidth < +width && +fileHeight < +height) { + await new Promise((resolve, reject) => { + if (size.crop) { + gmInstance + .resize(width, height, '^') + .gravity(DEFAULT_GRAVITY) + .crop(width, height).res(function(err, data) { + if (err) reject(err); + if (!err) resolve(data); + }); + } else gmInstance.resize(width, height, '>'); - const toSizePath = `${sizePath}/${fileName}`; - if (+fileWidth < +width && +fileHeight < +height) { - await new Promise((resolve, reject) => { - if (size.crop) { gmInstance - .resize(width, height, '^') - .gravity(DEFAULT_GRAVITY) - .crop(width, height).res(function(err, data) { + .setFormat(PNG) + .quality(DEFAULT_QUALITY) + .write(toSizePath + `.${FORMAT}`, function(err, data) { if (err) reject(err); if (!err) resolve(data); }); - } else gmInstance.resize(width, height, '>'); + }); + } - gmInstance - .setFormat(PNG) - .quality(DEFAULT_QUALITY) - .write(toSizePath + `.${FORMAT}`, function(err, data) { - if (err) reject(err); - if (!err) resolve(data); - }); - }); + const sizeOriginalPath = path.join( + collectionDir, + formatWidthHeight(width, height) + ); + + const toSizeOriginalPath = `${sizeOriginalPath}/${fileName}`; + + await Self.createLink(toSizeOriginalPath, toSizePath); } - - const sizeOriginalPath = path.join( - collectionDir, - formatWidthHeight(width, height) - ); - - const toSizeOriginalPath = `${sizeOriginalPath}/${fileName}`; - - await Self.createLink(toSizeOriginalPath, toSizePath); + } catch (e) { + throw new Error(e); } }; }; diff --git a/back/models/specs/images.spec.js b/back/models/specs/images.spec.js index 465ffc624f..2c8cb3f4dc 100644 --- a/back/models/specs/images.spec.js +++ b/back/models/specs/images.spec.js @@ -35,24 +35,32 @@ describe('loopback model Image', () => { }); it('should handle folder destination', async() => { - const {name, dstDir} = await models.Image.handleFolderDestination(obj.fileName); + try { + const {name, dstDir} = await models.Image.handleFolderDestination(obj.fileName); - expect(name).toEqual(nameItem); - expect(dstDir).toEqual(`${_23_F2}`); - const collectionDir = await models.Image.getCollectionDir(collectionName); + expect(name).toEqual(nameItem); + expect(dstDir).toEqual(`${_23_F2}`); + const collectionDir = await models.Image.getCollectionDir(collectionName); - expect(collectionDir).toEqual(`${STORAGE_IMAGE_USER}`); + expect(collectionDir).toEqual(`${STORAGE_IMAGE_USER}`); + } catch (e) { + throw new Error(e); + } }); it('should handle full size path', async() => { - const {dstDir} = await models.Image.handleFolderDestination(obj.fileName); - const collectionDir = await models.Image.getCollectionDir(collectionName); - const _fullSizePath = models.Image.getFullSizePath(obj.fileName, collectionDir, dstDir); - const {fullSizePath, toFullSizePath, toFullSizeOriginalPath} = _fullSizePath; + try { + const {dstDir} = await models.Image.handleFolderDestination(obj.fileName); + const collectionDir = await models.Image.getCollectionDir(collectionName); + const _fullSizePath = models.Image.getFullSizePath(obj.fileName, collectionDir, dstDir); + const {fullSizePath, toFullSizePath, toFullSizeOriginalPath} = _fullSizePath; - expect(fullSizePath).toEqual(`${STORAGE_IMAGE_USER}/${FULL_23_F2}`); - expect(toFullSizePath).toEqual(`${STORAGE_IMAGE_USER}/${FULL_23_F2}/${nameItem}`); - expect(toFullSizeOriginalPath).toEqual(`${STORAGE_IMAGE_USER}/full/${nameItem}`); + expect(fullSizePath).toEqual(`${STORAGE_IMAGE_USER}/${FULL_23_F2}`); + expect(toFullSizePath).toEqual(`${STORAGE_IMAGE_USER}/${FULL_23_F2}/${nameItem}`); + expect(toFullSizeOriginalPath).toEqual(`${STORAGE_IMAGE_USER}/full/${nameItem}`); + } catch (e) { + throw new Error(e); + } }); it('should resize', async() => { @@ -71,10 +79,14 @@ describe('loopback model Image', () => { }); afterAll(async() => { - await fs.unlink(`${STORAGE_IMAGE_USER}/full/${nameItem}`); + try { + await fs.unlink(`${STORAGE_IMAGE_USER}/full/${nameItem}`); - await fs.unlink(`${STORAGE_IMAGE_USER}/520x520/${nameItem}`); + await fs.unlink(`${STORAGE_IMAGE_USER}/520x520/${nameItem}`); - await fs.unlink(`${STORAGE_IMAGE_USER}/1600x1600/${nameItem}`); + await fs.unlink(`${STORAGE_IMAGE_USER}/1600x1600/${nameItem}`); + } catch (e) { + throw new Error(e); + } }); }); diff --git a/db/changes/240601/00-hederaImageConfig.sql b/db/changes/240601/00-hederaImageConfig.sql new file mode 100644 index 0000000000..f1cdd44ead --- /dev/null +++ b/db/changes/240601/00-hederaImageConfig.sql @@ -0,0 +1,4 @@ +ALTER TABLE `hedera`.`imageConfig` ADD dirLevels INT UNSIGNED NOT NULL DEFAULT 2; +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES + ('ImageConfig', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); -- 2.40.1 From b486469f98987874a02815e683686f9133213ed9 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 7 Mar 2024 12:43:08 +0100 Subject: [PATCH 18/24] solve fixtures.before.sql merge --- db/dump/fixtures.before.sql | 318 ++++++++++++++++++------------------ 1 file changed, 158 insertions(+), 160 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 685462e7f9..2bef66b863 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -2991,9 +2991,9 @@ INSERT INTO `vn`.`buyConfig` (`id`, `monthsAgo`) VALUES (1, 6); -INSERT INTO `hedera`.`imageConfig` (`maxSize`, `dirLevels`) +INSERT INTO `hedera`.`imageConfig` (`id`, `maxSize`, `useXsendfile`, `dirLevels`, `url`) VALUES - (20, 2); + (1, 20, 0, 2, 'marvel.com'); INSERT INTO `vn`.`invoiceInSerial` (`code`, `description`, `cplusTerIdNifFk`, `taxAreaFk`) VALUES @@ -3003,9 +3003,7 @@ INSERT INTO `vn`.`invoiceInSerial` (`code`, `description`, `cplusTerIdNifFk`, `t ('W', 'Vanaheim', 1, 'WORLD'); -INSERT INTO `hedera`.`imageConfig` (`id`, `maxSize`, `useXsendfile`, `url`) - VALUES - (1, 0, 0, 'marvel.com'); + INSERT INTO vn.XDiario (id, ASIEN, FECHA, SUBCTA, CONTRA, CONCEPTO, EURODEBE, EUROHABER, BASEEURO, SERIE, FACTURA, IVA, RECEQUIV, CLAVE, CAMBIO, DEBEME, HABERME, AUXILIAR, MONEDAUSO, TIPOOPE, NFACTICK, TERIDNIF, TERNIF, TERNOM, OPBIENES, L340, enlazado, FECHA_EX, LRECT349, empresa_id, LDIFADUAN, METAL, METALIMP, CLIENTE, METALEJE, FECHA_OP, FACTURAEX, TIPOCLAVE, TIPOEXENCI, TIPONOSUJE, TIPOFACT, TIPORECTIF, SERIE_RT, FACTU_RT, BASEIMP_RT, BASEIMP_RF, RECTIFICA, FECHA_RT, FECREGCON, enlazadoSage) VALUES @@ -3079,11 +3077,11 @@ INSERT INTO vn.packaging INSERT IGNORE INTO vn.intrastat - SET id = 44219999, - description = 'Manufacturas de madera', - taxClassFk = 1, + SET id = 44219999, + description = 'Manufacturas de madera', + taxClassFk = 1, taxCodeFk = 1; - + INSERT IGNORE INTO vn.warehouse SET id = 999, name = 'TestingWarehouse', @@ -3094,33 +3092,33 @@ INSERT IGNORE INTO vn.warehouse hasProduction = TRUE; INSERT IGNORE INTO vn.sector - SET id = 9991, - description = 'NormalSector', - warehouseFk = 999, - code = 'NS', - isPackagingArea = FALSE, - sonFk = NULL, - isMain = TRUE, + SET id = 9991, + description = 'NormalSector', + warehouseFk = 999, + code = 'NS', + isPackagingArea = FALSE, + sonFk = NULL, + isMain = TRUE, itemPackingTypeFk = NULL; INSERT IGNORE INTO vn.sector - SET id = 9992, - description = 'PreviousSector', - warehouseFk = 999, - code = 'PS', - isPackagingArea = FALSE, - sonFk = NULL, - isMain = TRUE, + SET id = 9992, + description = 'PreviousSector', + warehouseFk = 999, + code = 'PS', + isPackagingArea = FALSE, + sonFk = NULL, + isMain = TRUE, itemPackingTypeFk = NULL; INSERT IGNORE INTO vn.sector - SET id = 9993, - description = 'MezaninneSector', - warehouseFk = 999, - code = 'MS', - isPackagingArea = FALSE, - sonFk = 9991, - isMain = TRUE, + SET id = 9993, + description = 'MezaninneSector', + warehouseFk = 999, + code = 'MS', + isPackagingArea = FALSE, + sonFk = 9991, + isMain = TRUE, itemPackingTypeFk = NULL; @@ -3154,58 +3152,58 @@ INSERT IGNORE INTO vn.itemType SET id = 999, code = 'WOO', name = 'Wood Objects', - categoryFk = 3, + categoryFk = 3, workerFk = 103, isInventory = TRUE, life = 10, density = 250, - itemPackingTypeFk = NULL, + itemPackingTypeFk = NULL, temperatureFk = 'warm'; INSERT IGNORE INTO vn.travel - SET id = 99, - shipped = CURDATE(), + SET id = 99, + shipped = CURDATE(), landed = CURDATE(), - warehouseInFk = 999, - warehouseOutFk = 1, + warehouseInFk = 999, + warehouseOutFk = 1, isReceived = TRUE; INSERT INTO vn.entry SET id = 999, supplierFk = 791, - isConfirmed = TRUE, + isConfirmed = TRUE, dated = CURDATE(), - travelFk = 99, + travelFk = 99, companyFk = 442; INSERT INTO vn.ticket - SET id = 999999, + SET id = 999999, clientFk = 2, warehouseFk = 999, shipped = CURDATE(), - nickname = 'Cliente', + nickname = 'Cliente', addressFk = 1, - companyFk = 442, - agencyModeFk = 10, + companyFk = 442, + agencyModeFk = 10, landed = CURDATE(); INSERT INTO vn.collection - SET id = 10101010, + SET id = 10101010, workerFk = 9; - + INSERT IGNORE INTO vn.ticketCollection - SET id = 10101010, - ticketFk = 999999, + SET id = 10101010, + ticketFk = 999999, collectionFk = 10101010; - + INSERT INTO vn.item SET id = 999991, - name = 'Palito para pinchos', + name = 'Palito para pinchos', `size` = 25, - stems = NULL, - category = 'EXT', - typeFk = 999, - longName = 'Palito para pinchos', + stems = NULL, + category = 'EXT', + typeFk = 999, + longName = 'Palito para pinchos', itemPackingTypeFk = NULL, originFk = 1, weightByPiece = 6, @@ -3232,19 +3230,19 @@ INSERT INTO vn.sale SET id = 99991, itemFk = 999991, ticketFk = 999999, - concept = 'Palito para pinchos', - quantity = 3, - price = 1, + concept = 'Palito para pinchos', + quantity = 3, + price = 1, discount = 0; INSERT INTO vn.item SET id = 999992, - name = 'Madera verde', + name = 'Madera verde', `size` = 10, - stems = NULL, - category = 'EXT', - typeFk = 999, - longName = 'Madera verde', + stems = NULL, + category = 'EXT', + typeFk = 999, + longName = 'Madera verde', itemPackingTypeFk = NULL, originFk = 1, weightByPiece = 50, @@ -3271,19 +3269,19 @@ INSERT INTO vn.sale SET id = 99992, itemFk = 999992, ticketFk = 999999, - concept = 'Madera Verde', - quantity = 10, - price = 1, + concept = 'Madera Verde', + quantity = 10, + price = 1, discount = 0; INSERT INTO vn.item SET id = 999993, - name = 'Madera Roja/Morada', + name = 'Madera Roja/Morada', `size` = 12, - stems = 2, - category = 'EXT', - typeFk = 999, - longName = 'Madera Roja/Morada', + stems = 2, + category = 'EXT', + typeFk = 999, + longName = 'Madera Roja/Morada', itemPackingTypeFk = NULL, originFk = 1, weightByPiece = 35, @@ -3307,30 +3305,30 @@ INSERT INTO vn.buy weight = 25; INSERT INTO vn.itemShelving - SET id = 9931, - itemFk = 999993, - shelvingFk = 'NCC', - visible = 10, - `grouping` = 5, + SET id = 9931, + itemFk = 999993, + shelvingFk = 'NCC', + visible = 10, + `grouping` = 5, packing = 10; - + INSERT INTO vn.sale SET id = 99993, itemFk = 999993, ticketFk = 999999, - concept = 'Madera Roja/Morada', - quantity = 15, - price = 1, + concept = 'Madera Roja/Morada', + quantity = 15, + price = 1, discount = 0; INSERT INTO vn.item SET id = 999994, - name = 'Madera Naranja', + name = 'Madera Naranja', `size` = 18, - stems = 1, - category = 'EXT', - typeFk = 999, - longName = 'Madera Naranja', + stems = 1, + category = 'EXT', + typeFk = 999, + longName = 'Madera Naranja', itemPackingTypeFk = NULL, originFk = 1, weightByPiece = 160, @@ -3357,19 +3355,19 @@ INSERT INTO vn.sale SET id = 99994, itemFk = 999994, ticketFk = 999999, - concept = 'Madera Naranja', - quantity = 4, - price = 1, + concept = 'Madera Naranja', + quantity = 4, + price = 1, discount = 0; - + INSERT INTO vn.item SET id = 999995, - name = 'Madera Amarilla', + name = 'Madera Amarilla', `size` = 11, - stems = 5, - category = 'EXT', - typeFk = 999, - longName = 'Madera Amarilla', + stems = 5, + category = 'EXT', + typeFk = 999, + longName = 'Madera Amarilla', itemPackingTypeFk = NULL, originFk = 1, weightByPiece = 78, @@ -3396,20 +3394,20 @@ INSERT INTO vn.sale SET id = 99995, itemFk = 999995, ticketFk = 999999, - concept = 'Madera Amarilla', - quantity = 5, - price = 1, + concept = 'Madera Amarilla', + quantity = 5, + price = 1, discount = 0; - + -- Palito naranja INSERT INTO vn.item SET id = 999998, - name = 'Palito naranja', + name = 'Palito naranja', `size` = 11, - stems = 1, - category = 'EXT', - typeFk = 999, - longName = 'Palito naranja', + stems = 1, + category = 'EXT', + typeFk = 999, + longName = 'Palito naranja', itemPackingTypeFk = NULL, originFk = 1, weightByPiece = 78, @@ -3436,20 +3434,20 @@ INSERT INTO vn.sale SET id = 99998, itemFk = 999998, ticketFk = 999999, - concept = 'Palito naranja', - quantity = 60, - price = 1, + concept = 'Palito naranja', + quantity = 60, + price = 1, discount = 0; -- Palito amarillo INSERT INTO vn.item SET id = 999999, - name = 'Palito amarillo', + name = 'Palito amarillo', `size` = 11, - stems = 1, - category = 'EXT', - typeFk = 999, - longName = 'Palito amarillo', + stems = 1, + category = 'EXT', + typeFk = 999, + longName = 'Palito amarillo', itemPackingTypeFk = NULL, originFk = 1, weightByPiece = 78, @@ -3476,20 +3474,20 @@ INSERT INTO vn.sale SET id = 99999, itemFk = 999999, ticketFk = 999999, - concept = 'Palito amarillo', - quantity = 50, - price = 1, + concept = 'Palito amarillo', + quantity = 50, + price = 1, discount = 0; -- Palito azul INSERT INTO vn.item SET id = 1000000, - name = 'Palito azul', + name = 'Palito azul', `size` = 10, - stems = 1, - category = 'EXT', - typeFk = 999, - longName = 'Palito azul', + stems = 1, + category = 'EXT', + typeFk = 999, + longName = 'Palito azul', itemPackingTypeFk = NULL, originFk = 1, weightByPiece = 78, @@ -3516,20 +3514,20 @@ INSERT INTO vn.sale SET id = 100000, itemFk = 1000000, ticketFk = 999999, - concept = 'Palito azul', - quantity = 50, - price = 1, + concept = 'Palito azul', + quantity = 50, + price = 1, discount = 0; -- Palito rojo INSERT INTO vn.item SET id = 1000001, - name = 'Palito rojo', + name = 'Palito rojo', `size` = 10, - stems = NULL, - category = 'EXT', - typeFk = 999, - longName = 'Palito rojo', + stems = NULL, + category = 'EXT', + typeFk = 999, + longName = 'Palito rojo', itemPackingTypeFk = NULL, originFk = 1, weightByPiece = 78, @@ -3557,20 +3555,20 @@ INSERT INTO vn.sale SET id = 100001, itemFk = 1000001, ticketFk = 999999, - concept = 'Palito rojo', - quantity = 10, - price = 1, + concept = 'Palito rojo', + quantity = 10, + price = 1, discount = 0; - + -- Previa INSERT IGNORE INTO vn.item SET id = 999996, - name = 'Bolas de madera', + name = 'Bolas de madera', `size` = 2, - stems = 4, - category = 'EXT', - typeFk = 999, - longName = 'Bolas de madera', + stems = 4, + category = 'EXT', + typeFk = 999, + longName = 'Bolas de madera', itemPackingTypeFk = NULL, originFk = 1, weightByPiece = 20, @@ -3597,20 +3595,20 @@ INSERT vn.sale SET id = 99996, itemFk = 999996, ticketFk = 999999, - concept = 'Bolas de madera', - quantity = 4, - price = 7, + concept = 'Bolas de madera', + quantity = 4, + price = 7, discount = 0, isPicked = TRUE; INSERT IGNORE INTO vn.item SET id = 999997, - name = 'Palitos de polo MIX', + name = 'Palitos de polo MIX', `size` = 14, - stems = NULL, - category = 'EXT', - typeFk = 999, - longName = 'Palitos de polo MIX', + stems = NULL, + category = 'EXT', + typeFk = 999, + longName = 'Palitos de polo MIX', itemPackingTypeFk = NULL, originFk = 1, weightByPiece = 20, @@ -3637,9 +3635,9 @@ INSERT vn.sale SET id = 99997, itemFk = 999997, ticketFk = 999999, - concept = 'Palitos de polo MIX', - quantity = 5, - price = 7, + concept = 'Palitos de polo MIX', + quantity = 5, + price = 7, discount = 0; USE vn; @@ -3672,38 +3670,38 @@ VALUES -- Previous for Bolas de madera INSERT IGNORE INTO vn.sectorCollection - SET id = 99, - userFk = 1, + SET id = 99, + userFk = 1, sectorFk = 9992; INSERT IGNORE INTO vn.saleGroup - SET id = 4, - userFk = 1, - parkingFk = 9, + SET id = 4, + userFk = 1, + parkingFk = 9, sectorFk = 9992; INSERT IGNORE INTO vn.sectorCollectionSaleGroup SET id = 9999, - sectorCollectionFk = 99, + sectorCollectionFk = 99, saleGroupFk = 999; INSERT vn.saleGroupDetail - SET id = 99991, - saleFk = 99996, + SET id = 99991, + saleFk = 99996, saleGroupFk = 999; - + INSERT INTO vn.saleTracking SET id = 7, - saleFk = 99996, + saleFk = 99996, isChecked = TRUE, workerFk = 103, stateFk = 28; - + INSERT IGNORE INTO vn.itemShelvingSale - SET id = 991, - itemShelvingFk = 9962, - saleFk = 99996, - quantity = 5, + SET id = 991, + itemShelvingFk = 9962, + saleFk = 99996, + quantity = 5, userFk = 1; UPDATE vn.ticket @@ -3733,4 +3731,4 @@ UPDATE vn.buy SET itemOriginalFk = 1 WHERE id = 1; UPDATE vn.saleTracking SET stateFk = 26 WHERE id = 5; -INSERT INTO vn.report (name) VALUES ('LabelCollection'); \ No newline at end of file +INSERT INTO vn.report (name) VALUES ('LabelCollection'); -- 2.40.1 From ae64e9e1a1f20769955e640d564efc0830a56fee Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 12 Mar 2024 11:45:21 +0100 Subject: [PATCH 19/24] refs #5576 feat move CGI to #7022 --- images/.htaccess | 4 ---- images/Dockerfile | 32 ------------------------- images/apache2.conf | 11 --------- images/docker-compose.yml | 11 --------- images/www/script.pl | 50 --------------------------------------- 5 files changed, 108 deletions(-) delete mode 100644 images/.htaccess delete mode 100644 images/Dockerfile delete mode 100644 images/apache2.conf delete mode 100644 images/docker-compose.yml delete mode 100644 images/www/script.pl diff --git a/images/.htaccess b/images/.htaccess deleted file mode 100644 index 2b778acaf1..0000000000 --- a/images/.htaccess +++ /dev/null @@ -1,4 +0,0 @@ - - RewriteEngine On - RewriteRule ^(.+)\.(jpg|png|jpeg)$ script.pl?value=$1.$2&name=$1 [L,QSA] - diff --git a/images/Dockerfile b/images/Dockerfile deleted file mode 100644 index d267dcfce9..0000000000 --- a/images/Dockerfile +++ /dev/null @@ -1,32 +0,0 @@ -FROM httpd:latest - -RUN apt-get update && apt-get install -y curl libcgi-pm-perl - -# Habilitar mod_rewrite -RUN sed -i '/mod_rewrite/s/^#//g' /usr/local/apache2/conf/httpd.conf -RUN echo "AddHandler cgi-script .cgi .pl" >> /usr/local/apache2/conf/httpd.conf -RUN echo "Include conf/extra/httpd-vhosts.conf" >> /usr/local/apache2/conf/httpd.conf - -# Habilitar mod_cgi -RUN sed -i '/mod_cgi/s/^#//g' /usr/local/apache2/conf/httpd.conf -RUN echo "LoadModule cgid_module modules/mod_cgid.so" >> /usr/local/apache2/conf/httpd.conf - -# Habilitar reescritura -RUN echo "RewriteEngine On" >> /usr/local/apache2/conf/extra/httpd-vhosts.conf - - - -# Copiar la configuración de Apache2 y los archivos del sitio -COPY apache2.conf /usr/local/apache2/conf/extra/httpd-vhosts.conf - -# RUN chmod +x www/script.pl -COPY www/ /usr/local/apache2/htdocs/ - -# Copia el archivo .htaccess para configurar el directorio htdocs/images -COPY .htaccess /usr/local/apache2/htdocs/ - -# Habilita permisos de ejecución -RUN chmod +x /usr/local/apache2/htdocs/script.pl - -# CMD y ENTRYPOINT para iniciar Apache2, según la imagen original -CMD ["httpd-foreground"] diff --git a/images/apache2.conf b/images/apache2.conf deleted file mode 100644 index 9e5018bd31..0000000000 --- a/images/apache2.conf +++ /dev/null @@ -1,11 +0,0 @@ -# apache2.conf - - DocumentRoot /usr/local/apache2/htdocs - - Options Indexes FollowSymLinks - AllowOverride All - Require all granted - Options +ExecCGI - AddHandler cgi-script .cgi .pl - - diff --git a/images/docker-compose.yml b/images/docker-compose.yml deleted file mode 100644 index 651face426..0000000000 --- a/images/docker-compose.yml +++ /dev/null @@ -1,11 +0,0 @@ -version: '3' -services: - apache: - volumes: - - ./images:/usr/local/apache2/htdocs/images/ - build: - context: . - dockerfile: Dockerfile - ports: - - "8080:80" - diff --git a/images/www/script.pl b/images/www/script.pl deleted file mode 100644 index 0fc4a24c1a..0000000000 --- a/images/www/script.pl +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; - -use Digest::SHA qw(sha1_hex); -use CGI; - -my $cgi = CGI->new; -my $input_name = $cgi->param('name') || "default"; -my $input_value = $cgi->param('value') || "default"; -my $new_path; - -# Dividir la ruta usando el símbolo "/" para extraaer el nombre del archivo SIN extension -my $fileName= (split('/', $input_name))[-1]; - -# Dividir la ruta usando el símbolo "/" para extraaer el nombre del archivo CON extension -my $file= (split('/', $input_value))[-1]; -my $exists = -e "$input_value"; - -# Compruebo si existe el archivo en la caperta general o no -if($exists) { - $new_path ="$input_value"; -} else { - # Calcula el valor hash MD5 del string - my $hash_value = sha1_hex($fileName); - - # Obtiene solo los 2 primeros caracteres del hash MD5 - my $first_characters = substr($hash_value, 0, 2); - - # Obtiene solo los 2 segundos caracteres del hash MD5 - my $second_characters = substr($hash_value, 1, 2); - - $new_path ="images/$first_characters/$second_characters/$file"; -} -# Verifica si $imagen está definida antes de intentar usarla -if (defined $new_path) { - abrir_imagen($new_path); -} -sub abrir_imagen { - my ($ruta) = @_; - print "Content-type: image/jpeg\n\n"; - open my $imagen, '<', $ruta or die "No se pudo abrir la imagen: $!"; - - # Imprime los bytes de la imagen directamente en la salida estándar - binmode STDOUT; - print while <$imagen>; - - # Cierra el archivo - close $imagen; -} -- 2.40.1 From 3c791d7a201ed677f6d8bc88349197c5c46e2119 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 12 Mar 2024 11:45:55 +0100 Subject: [PATCH 20/24] refs #5576 feat: remove changes file --- db/changes/240601/00-hederaImageConfig.sql | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 db/changes/240601/00-hederaImageConfig.sql diff --git a/db/changes/240601/00-hederaImageConfig.sql b/db/changes/240601/00-hederaImageConfig.sql deleted file mode 100644 index f1cdd44ead..0000000000 --- a/db/changes/240601/00-hederaImageConfig.sql +++ /dev/null @@ -1,4 +0,0 @@ -ALTER TABLE `hedera`.`imageConfig` ADD dirLevels INT UNSIGNED NOT NULL DEFAULT 2; -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('ImageConfig', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); -- 2.40.1 From 68520e046a5f6e9dd7662eca535d14b0682fc7a8 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 1 Apr 2024 12:11:57 +0200 Subject: [PATCH 21/24] refs #5576 test: fix --- back/models/specs/images.spec.js | 47 +++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/back/models/specs/images.spec.js b/back/models/specs/images.spec.js index 2c8cb3f4dc..2c51d826df 100644 --- a/back/models/specs/images.spec.js +++ b/back/models/specs/images.spec.js @@ -7,7 +7,7 @@ let obj = {}; const STORAGE_IMAGE_USER = 'storage/image/user'; const _23_F2 = '23/f2'; const FULL_23_F2 = `full/${_23_F2}`; -describe('loopback model Image', () => { +fdescribe('loopback model Image', () => { const userId = 1107; const activeCtx = { @@ -26,6 +26,23 @@ describe('loopback model Image', () => { fileName, entityId, }; + cleanResources(); + // try { + // await fs.unlink(`${STORAGE_IMAGE_USER}/full/${FULL_23_F2}/${nameItem}`); + // await fs.unlink(`${STORAGE_IMAGE_USER}/160x100/${FULL_23_F2}/${nameItem}`); + + // await fs.unlink(`${STORAGE_IMAGE_USER}/520x520/${FULL_23_F2}/${nameItem}`); + + // await fs.unlink(`${STORAGE_IMAGE_USER}/1600x1600/${FULL_23_F2}/${nameItem}`); + // await fs.unlink(`${STORAGE_IMAGE_USER}/full/${nameItem}`); + // await fs.unlink(`${STORAGE_IMAGE_USER}/160x100/${nameItem}`); + + // await fs.unlink(`${STORAGE_IMAGE_USER}/520x520/${nameItem}`); + + // await fs.unlink(`${STORAGE_IMAGE_USER}/1600x1600/${nameItem}`); + // } catch (e) { + // console.warn(e); + // } }); beforeEach(() => { @@ -79,14 +96,24 @@ describe('loopback model Image', () => { }); afterAll(async() => { - try { - await fs.unlink(`${STORAGE_IMAGE_USER}/full/${nameItem}`); - - await fs.unlink(`${STORAGE_IMAGE_USER}/520x520/${nameItem}`); - - await fs.unlink(`${STORAGE_IMAGE_USER}/1600x1600/${nameItem}`); - } catch (e) { - throw new Error(e); - } + // cleanResources(); }); }); + +async function cleanResources() { + try { + await fs.unlink(`${STORAGE_IMAGE_USER}/160x160/${nameItem}`); + // await fs.unlink(`${STORAGE_IMAGE_USER}/160x160/${_23_F2}/${nameItem}`); + + await fs.unlink(`${STORAGE_IMAGE_USER}/520x520/${nameItem}`); + // await fs.unlink(`${STORAGE_IMAGE_USER}/520x520/${_23_F2}/${nameItem}`); + + await fs.unlink(`${STORAGE_IMAGE_USER}/1600x1600/${nameItem}`); + // await fs.unlink(`${STORAGE_IMAGE_USER}/1600x1600/${_23_F2}/${nameItem}`); + + await fs.unlink(`${STORAGE_IMAGE_USER}/full/${nameItem}`); + // await fs.unlink(`${STORAGE_IMAGE_USER}/full/${_23_F2}/${nameItem}`); + } catch (e) { + console.warn(e); + } +} -- 2.40.1 From d2b4c8a3dc1ecc7a85247e06d023889cdddcfda0 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 1 Apr 2024 12:19:31 +0200 Subject: [PATCH 22/24] updates --- back/models/specs/images.spec.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/back/models/specs/images.spec.js b/back/models/specs/images.spec.js index 2c51d826df..0c4dbeafad 100644 --- a/back/models/specs/images.spec.js +++ b/back/models/specs/images.spec.js @@ -26,6 +26,10 @@ fdescribe('loopback model Image', () => { fileName, entityId, }; + // Ruta del directorio y nombre del archivo que buscas + + // Llama a la función para mostrar el listado y verificar el archivo + mostrarListadoYVerificar(`${STORAGE_IMAGE_USER}/full`, nameItem); cleanResources(); // try { // await fs.unlink(`${STORAGE_IMAGE_USER}/full/${FULL_23_F2}/${nameItem}`); @@ -117,3 +121,25 @@ async function cleanResources() { console.warn(e); } } + +function mostrarListadoYVerificar(rutaDirectorio, archivoBuscado) { + // Lee el contenido del directorio + fs.readdir(rutaDirectorio, (err, archivos) => { + if (err) { + console.error('Error al leer el directorio:', err); + return; + } + + // Muestra el listado de archivos + console.log('Listado de archivos en el directorio:', rutaDirectorio); + archivos.forEach(archivo => { + console.log(archivo); + }); + + // Verifica si el archivo buscado está en el listado + if (archivos.includes(archivoBuscado)) + console.log(`El archivo "${archivoBuscado}" está presente en el directorio.`); + else + console.log(`El archivo "${archivoBuscado}" no está presente en el directorio.`); + }); +} -- 2.40.1 From cc510758daeb4fb80c3acdb4dfd576e90f5b0bc5 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 1 Apr 2024 12:26:06 +0200 Subject: [PATCH 23/24] refs #5576 test: updaload new image --- .gitignore | 2 -- storage/image/user/1600x1600/Pallet.png | Bin 0 -> 2162 bytes 2 files changed, 2 deletions(-) create mode 100644 storage/image/user/1600x1600/Pallet.png diff --git a/.gitignore b/.gitignore index 895a6a8dc4..6232a0e99e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ coverage node_modules dist -storage .idea npm-debug.log .eslintcache @@ -10,4 +9,3 @@ print.*.json db.json junit.xml .DS_Store -storage \ No newline at end of file diff --git a/storage/image/user/1600x1600/Pallet.png b/storage/image/user/1600x1600/Pallet.png new file mode 100644 index 0000000000000000000000000000000000000000..4eaa22de5d1fdc6bfea9d253aea65485faf537a3 GIT binary patch literal 2162 zcmZ`*e>~G$AOEUh#$_boN?$@vQr4}AtEOq2{JI#U;>wo%E=GRUY9z9TVcC$LN&z^Uah1Zizks zsLl|u7@x$UnbHwNkW{>jxwss|`F&NS!IMDpgzRlEL&U(WB94rkZW6(Ks5Csj zOJ4>9MzL{f01^gZ{>FU=#sGgC{aqNM`8QJ_&RC{ZULfr?%ZSs&+|0DmNFzl|BnYxH zh1)gYHNhyp)tbt>0t$-ae_)f#PjrnoFlzW>oo`7TJ`diuJu?$O5Pz+X{q@W?!H6|? ziN~<9e(yaV+X%sE=EkF*#2cFtc1D_By2>UkVTNJD>xXilz{4x!YvsigvjBY6S@6G(ZZB zutgGZXL^sYX~VwU!D`9qUjC=I!0ry=OaioI=ZMh|WZ&*SuOmD^n~v0^Mb+{G=&({9 zJp$}i;CzG~_hwR9!rT@&C5*4zm|R}^%cMeZ$%df|^WQcw9WQyOYGlv+ZqF z`rVe9YQX@fD~;n+!!``5y@m6ePMm2xtjFQ$cjoO<$4J_@Yh<6f8(B$NKw>23Le{hJ zsFb8nBm119o9h#N?ek|<-?BX3?^KgcWqfg9dbxaD`gx;cIl}4qnKGOm7CTf=5e)Rh z{F6)j0~RjSeS9o(3t>=?bl&#BAZe)stnR*$p!=_aa6g8OHd{kU8P+3s2|-iSq$}I3 z#{lp3&Pd*054WW#kH@w;T1+?Ryyot@77(%FSF;@a%2W%)+Kdm*_*h~)l(&J z69li&!kQkN32{SIw}XhSJdaZqXN~onNP6a^6s5q5d%%JNt9HJM9a9V^yU1#;|!W@?Cq=h3C^w>;iOl-IGFs;=8F&phLVxL9CV zm!ges)v=$xHXE2G-mB}Aw`jD@&F1g!M*lP5pg-G-NTk|t>CLmdc}yqBO`9B|VBfVm zXpn({?$XK|Ep4JpmgIBmUfx*oZaq6=`DeuZj!#KCQzb^4s<1)Jz_X#e@Q?~aT1|a; zbW_#Ak10AIpD_wZ33zY4)f`duh-N^*A4d zbJAStAXyWwM$d(|0e6}Np@A@lY_lW)jgxXbGiJEDvabRMrMY3w063(k|&>=iio+qTA~UMwNFK99}CQHu>~*&HzkeU}wm6>=oExlP1h}T7Qn=?0)w9KEuB8pzJMd$2NP;&WZ#!(gu3F-_ z7VJ;;Lt+*jXibB~aqdl3f(>;V!(i<2dz+l zi?P@>{U3{#LA`N;w;*Y4V*cI4VD1_8r(M0Ua z!f2`Olvy_#l0q)S@H}YxAZUsyODwaMdX`W02&BCPOFvp3NE9Rfr`G@1?QgyB!0=Un75Kjl`40Ri)11??(#0rsY&n;h z0{sRIsLmwn{+OsJN;DPNA4>_QQpn(`FzRs-M{x7>JEyr03IYhu?$|1)U+I4U3PG(N literal 0 HcmV?d00001 -- 2.40.1 From 778c1aee71533ad18046ff833d1ebc0cd6bfcd5b Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 1 Apr 2024 12:28:05 +0200 Subject: [PATCH 24/24] revert gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 6232a0e99e..c43834ac98 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ coverage node_modules dist +storage .idea npm-debug.log .eslintcache @@ -9,3 +10,4 @@ print.*.json db.json junit.xml .DS_Store +storage -- 2.40.1