From 5831230d1391afc71768f49477c9b9611207fc8e Mon Sep 17 00:00:00 2001 From: MrMatiz2 Date: Tue, 22 Jul 2025 08:19:06 -0500 Subject: [PATCH] new folder structure --- .gitignore | 1 + local-files/automations/generate_zip.py | 51 +++++++++ local-files/automations/videos_search.py | 39 +++++++ local-files/images/queue.json | 1 + nodes/S4DSMain/ApiHelper.ts | 41 +++++-- nodes/S4DSMain/S4DSMain.node.ts | 4 +- .../actions/authentication/generateToken.json | 16 +++ .../actions/customers/createCustomer.json | 18 +++ .../customers/getCustomerByDocument.json | 29 +++++ .../actions/customers/updateCustomer.json | 18 +++ .../actions/products/getProductCount.json | 14 +++ nodes/S4DSMain/api-definitions.json | 106 ++++-------------- package-lock.json | 19 ++++ package.json | 1 + 14 files changed, 262 insertions(+), 96 deletions(-) create mode 100644 local-files/automations/generate_zip.py create mode 100644 local-files/automations/videos_search.py create mode 100644 local-files/images/queue.json create mode 100644 nodes/S4DSMain/actions/authentication/generateToken.json create mode 100644 nodes/S4DSMain/actions/customers/createCustomer.json create mode 100644 nodes/S4DSMain/actions/customers/getCustomerByDocument.json create mode 100644 nodes/S4DSMain/actions/customers/updateCustomer.json create mode 100644 nodes/S4DSMain/actions/products/getProductCount.json diff --git a/.gitignore b/.gitignore index 7e72963..b5237a2 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ dist npm-debug.log* yarn.lock .vscode/launch.json +.env \ No newline at end of file diff --git a/local-files/automations/generate_zip.py b/local-files/automations/generate_zip.py new file mode 100644 index 0000000..fc79ec4 --- /dev/null +++ b/local-files/automations/generate_zip.py @@ -0,0 +1,51 @@ +from pathlib import Path +from zipfile import ZipFile +import datetime +import os + +# ====== CONFIGURACIÓN ====== +carpeta_origen = Path(r"D:\Users\aleja\Code\n8n-nodes-starter-s4ds\local-files\images") +archivo_zip = carpeta_origen.parent / f"queue_{datetime.date.today()}.zip" + +# Extensiones de imagen a eliminar después del zip +extensiones_imagen = {".jpg", ".jpeg", ".png", ".gif", ".bmp", ".webp", ".tiff"} + +# ====== OBTENER ARCHIVOS ====== +archivos_a_comprimir = list(carpeta_origen.glob("*")) # Solo archivos del nivel actual + +archivo_queue_json = carpeta_origen / "queue.json" + +# ====== CREAR ZIP ====== +if archivos_a_comprimir: + with ZipFile(archivo_zip, 'w') as zipf: + for archivo in archivos_a_comprimir: + if archivo.is_file(): + zipf.write(archivo, arcname=archivo.name) + print(f"📦 Añadido al zip: {archivo.name}") + print(f"\n✅ ZIP creado en: {archivo_zip}") +else: + print("⚠️ No hay archivos para comprimir.") + exit() + +# ====== ELIMINAR IMÁGENES ====== +eliminados = 0 +for archivo in archivos_a_comprimir: + if archivo.suffix.lower() in extensiones_imagen: + try: + archivo.unlink() + print(f"🗑️ Imagen eliminada: {archivo.name}") + eliminados += 1 + except Exception as e: + print(f"❌ Error al eliminar {archivo.name}: {e}") + +print(f"\n🧹 Eliminación finalizada. Total imágenes eliminadas: {eliminados}") + +# ====== LIMPIAR queue.json ====== +if archivo_queue_json.exists(): + try: + archivo_queue_json.write_text("[]", encoding="utf-8") + print(f"\n✅ queue.json limpiado correctamente.") + except Exception as e: + print(f"❌ Error al limpiar queue.json: {e}") +else: + print("⚠️ queue.json no se encontró en la carpeta.") \ No newline at end of file diff --git a/local-files/automations/videos_search.py b/local-files/automations/videos_search.py new file mode 100644 index 0000000..b8bd7ea --- /dev/null +++ b/local-files/automations/videos_search.py @@ -0,0 +1,39 @@ +from pathlib import Path +from datetime import datetime, timedelta +import shutil + +# ====== CONFIGURACIÓN ====== +carpeta_base = Path(r"D:\Users\aleja\AppData\Local\Temp\gradio") +carpeta_destino = Path(r"D:\Users\aleja\Code\n8n-nodes-starter-s4ds\local-files\videos") +buscar_recursivamente = True + +# ====== CALCULAR HORA LÍMITE ====== +ahora = datetime.now() +una_hora_atras = ahora - timedelta(hours=1) + +# ====== BÚSQUEDA ====== +archivos = carpeta_base.rglob("*.mp4") if buscar_recursivamente else carpeta_base.glob("*.mp4") +encontrados = [] + +for archivo in archivos: + try: + modificado = datetime.fromtimestamp(archivo.stat().st_mtime) + if modificado >= una_hora_atras: + encontrados.append(archivo) + except Exception as e: + print(f"⚠️ Error al leer {archivo.name}: {e}") + +# ====== COPIAR ARCHIVOS ====== +if encontrados: + carpeta_destino.mkdir(parents=True, exist_ok=True) + print(f"\n🎯 Archivos .mp4 modificados en la última hora:\n") + + for archivo in encontrados: + destino = carpeta_destino / archivo.name + try: + shutil.copy2(archivo, destino) + print(f"✅ Copiado: {archivo.name}") + except Exception as e: + print(f"❌ Error al copiar {archivo.name}: {e}") +else: + print("\n⚠️ No se encontraron archivos .mp4 recientes.") diff --git a/local-files/images/queue.json b/local-files/images/queue.json new file mode 100644 index 0000000..0637a08 --- /dev/null +++ b/local-files/images/queue.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/nodes/S4DSMain/ApiHelper.ts b/nodes/S4DSMain/ApiHelper.ts index a1b732d..c76117f 100644 --- a/nodes/S4DSMain/ApiHelper.ts +++ b/nodes/S4DSMain/ApiHelper.ts @@ -1,6 +1,14 @@ +// If you see type errors for 'fs' or 'path', install @types/node as a dev dependency. +// npm install --save-dev @types/node import { INodeProperties, NodePropertyTypes } from 'n8n-workflow'; -import * as apiDefinitions from './api-definitions.json'; import * as dtoDefinitions from './dto-definitions.json'; +// Remove fs and path imports +// Import all service JSON files directly +import generateToken from './actions/authentication/generateToken.json'; +import getProductCount from './actions/products/getProductCount.json'; +import getCustomerByDocument from './actions/customers/getCustomerByDocument.json'; +import createCustomer from './actions/customers/createCustomer.json'; +import updateCustomer from './actions/customers/updateCustomer.json'; export interface ApiDefinition { method: string; @@ -42,10 +50,30 @@ export interface DtoDefinition { properties: Record; } +// Build static API definitions object +const staticApiDefinitions: Record> = { + authentication: { + generateToken: generateToken as ApiDefinition, + }, + products: { + getProductCount: getProductCount as ApiDefinition, + }, + customers: { + getCustomerByDocument: getCustomerByDocument as ApiDefinition, + createCustomer: createCustomer as ApiDefinition, + updateCustomer: updateCustomer as ApiDefinition, + }, +}; + export class ApiHelper { - static getApiDefinitions(): Record> { - return apiDefinitions as any; - } + // Return the static API definitions + static getApiDefinitions(): Record> { + return staticApiDefinitions; + } + // Return a single API definition + static getApiDefinition(group: string, service: string): ApiDefinition | null { + return staticApiDefinitions[group]?.[service] || null; + } static getResources(): INodeProperties[] { const definitions = this.getApiDefinitions(); @@ -259,11 +287,6 @@ export class ApiHelper { .trim(); } - static getApiDefinition(resource: string, operation: string): ApiDefinition | null { - const definitions = this.getApiDefinitions(); - return definitions[resource]?.[operation] || null; - } - static getDtoDefinitions(): Record { return dtoDefinitions as any; } diff --git a/nodes/S4DSMain/S4DSMain.node.ts b/nodes/S4DSMain/S4DSMain.node.ts index 1fb32a7..aa29910 100644 --- a/nodes/S4DSMain/S4DSMain.node.ts +++ b/nodes/S4DSMain/S4DSMain.node.ts @@ -45,8 +45,8 @@ export class S4DSMain implements INodeType { const resource = this.getNodeParameter('resource', i) as string; const operation = this.getNodeParameter('operation', i) as string; - // Obtener definición de la API - const apiDefinition = ApiHelper.getApiDefinition(resource, operation); + // Get API definition (now async) + const apiDefinition = await ApiHelper.getApiDefinition(resource, operation); if (!apiDefinition) { throw new Error(`API definition not found for resource: ${resource}, operation: ${operation}`); } diff --git a/nodes/S4DSMain/actions/authentication/generateToken.json b/nodes/S4DSMain/actions/authentication/generateToken.json new file mode 100644 index 0000000..1d75863 --- /dev/null +++ b/nodes/S4DSMain/actions/authentication/generateToken.json @@ -0,0 +1,16 @@ +{ + "name": "generateToken", + "method": "POST", + "endpoint": "/login/generateToken", + "description": "Generate authentication token using credentials.", + "parameters": [], + "requiresAuth": false, + "response": { + "type": "object", + "properties": { + "token": "string", + "token_type": "string", + "expires_in": "number" + } + } +} \ No newline at end of file diff --git a/nodes/S4DSMain/actions/customers/createCustomer.json b/nodes/S4DSMain/actions/customers/createCustomer.json new file mode 100644 index 0000000..a9024ed --- /dev/null +++ b/nodes/S4DSMain/actions/customers/createCustomer.json @@ -0,0 +1,18 @@ +{ + "name": "createCustomer", + "method": "POST", + "endpoint": "/customer", + "description": "Create a new customer.", + "parameters": [], + "requiresAuth": true, + "requestBody": { + "schema": "SetNewCustomerDTO", + "required": true + }, + "response": { + "type": "object", + "properties": { + "customer": "object" + } + } +} \ No newline at end of file diff --git a/nodes/S4DSMain/actions/customers/getCustomerByDocument.json b/nodes/S4DSMain/actions/customers/getCustomerByDocument.json new file mode 100644 index 0000000..9b4fc41 --- /dev/null +++ b/nodes/S4DSMain/actions/customers/getCustomerByDocument.json @@ -0,0 +1,29 @@ +{ + "name": "getCustomerByDocument", + "method": "GET", + "endpoint": "/customer/specificCustomer", + "description": "Get customer information by document ID and type.", + "parameters": [ + { + "name": "documentId", + "type": "string", + "required": false, + "description": "Document ID of the customer.", + "in": "query" + }, + { + "name": "documentType", + "type": "string", + "required": false, + "description": "Type of document (e.g., CC, CE, NIT).", + "in": "query" + } + ], + "requiresAuth": true, + "response": { + "type": "object", + "properties": { + "customer": "object" + } + } +} \ No newline at end of file diff --git a/nodes/S4DSMain/actions/customers/updateCustomer.json b/nodes/S4DSMain/actions/customers/updateCustomer.json new file mode 100644 index 0000000..15ab315 --- /dev/null +++ b/nodes/S4DSMain/actions/customers/updateCustomer.json @@ -0,0 +1,18 @@ +{ + "name": "updateCustomer", + "method": "PATCH", + "endpoint": "/customer", + "description": "Update an existing customer.", + "parameters": [], + "requiresAuth": true, + "requestBody": { + "schema": "SetNewCustomerDTO", + "required": true + }, + "response": { + "type": "object", + "properties": { + "result": "object" + } + } +} \ No newline at end of file diff --git a/nodes/S4DSMain/actions/products/getProductCount.json b/nodes/S4DSMain/actions/products/getProductCount.json new file mode 100644 index 0000000..959a0ec --- /dev/null +++ b/nodes/S4DSMain/actions/products/getProductCount.json @@ -0,0 +1,14 @@ +{ + "name": "getProductCount", + "method": "GET", + "endpoint": "/product/count", + "description": "Get the total count of products.", + "parameters": [], + "requiresAuth": true, + "response": { + "type": "object", + "properties": { + "count": "number" + } + } +} \ No newline at end of file diff --git a/nodes/S4DSMain/api-definitions.json b/nodes/S4DSMain/api-definitions.json index a2010d0..1c88076 100644 --- a/nodes/S4DSMain/api-definitions.json +++ b/nodes/S4DSMain/api-definitions.json @@ -1,98 +1,34 @@ { "authentication": { - "generateToken": { - "method": "POST", - "endpoint": "/login/generateToken", - "description": "Generate authentication token using credentials", - "parameters": [], - "requiresAuth": false, - "response": { - "type": "object", - "properties": { - "token": "string", - "token_type": "string", - "expires_in": "number" - } + "services": [ + { + "name": "generateToken", + "file": "actions/authentication/generateToken.json" } - } + ] }, "products": { - "getProductCount": { - "method": "GET", - "endpoint": "/product/count", - "description": "Get the total count of products", - "parameters": [], - "requiresAuth": true, - "response": { - "type": "object", - "properties": { - "count": "number" - } + "services": [ + { + "name": "getProductCount", + "file": "actions/products/getProductCount.json" } - } + ] }, "customers": { - "getCustomerByDocument": { - "method": "GET", - "endpoint": "/customer/specificCustomer", - "description": "Get customer information by document ID and type", - "parameters": [ - { - "name": "documentId", - "type": "string", - "required": false, - "description": "Document ID of the customer", - "in": "query" - }, - { - "name": "documentType", - "type": "string", - "required": false, - "description": "Type of document (e.g., CC, CE, NIT)", - "in": "query" - } - ], - "requiresAuth": true, - "response": { - "type": "object", - "properties": { - "customer": "object" - } - } - }, - "createCustomer": { - "method": "POST", - "endpoint": "/customer", - "description": "Create a new customer", - "parameters": [], - "requiresAuth": true, - "requestBody": { - "schema": "SetNewCustomerDTO", - "required": true + "services": [ + { + "name": "getCustomerByDocument", + "file": "actions/customers/getCustomerByDocument.json" }, - "response": { - "type": "object", - "properties": { - "customer": "object" - } - } - }, - "updateCustomer": { - "method": "PATCH", - "endpoint": "/customer", - "description": "Update an existing customer", - "parameters": [], - "requiresAuth": true, - "requestBody": { - "schema": "SetNewCustomerDTO", - "required": true + { + "name": "createCustomer", + "file": "actions/customers/createCustomer.json" }, - "response": { - "type": "object", - "properties": { - "result": "object" - } + { + "name": "updateCustomer", + "file": "actions/customers/updateCustomer.json" } - } + ] } } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 00b8c13..98fc1c2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,10 +9,12 @@ "version": "0.1.0", "license": "MIT", "devDependencies": { + "@types/node": "^24.1.0", "@typescript-eslint/parser": "~8.32.0", "eslint": "^8.57.0", "eslint-plugin-n8n-nodes-base": "^1.16.3", "gulp": "^4.0.2", + "gulp-cli": "^2.3.0", "prettier": "^3.5.3", "typescript": "^5.8.2" }, @@ -288,6 +290,16 @@ "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", "dev": true }, + "node_modules/@types/node": { + "version": "24.1.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-24.1.0.tgz", + "integrity": "sha512-ut5FthK5moxFKH2T1CUOC6ctR67rQRvvHdFLCD2Ql6KXmMuCrjsSsRI9UsLCm9M18BMwClv4pn327UvB7eeO1w==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~7.8.0" + } + }, "node_modules/@types/semver": { "version": "7.7.0", "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.7.0.tgz", @@ -6851,6 +6863,13 @@ "integrity": "sha512-Ia0sQNrMPXXkqVFt6w6M1n1oKo3NfKs+mvaV811Jwir7vAk9a6PVV9VPYf6X3BU97QiLEmuW3uXH9u87zDFfdw==", "dev": true }, + "node_modules/undici-types": { + "version": "7.8.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.8.0.tgz", + "integrity": "sha512-9UJ2xGDvQ43tYyVMpuHlsgApydB8ZKfVYTsLDhXkFL/6gfkp+U8xTGdh8pMJv1SpZna0zxG1DwsKZsreLbXBxw==", + "dev": true, + "license": "MIT" + }, "node_modules/union-value": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz", diff --git a/package.json b/package.json index 5d8c8c1..99c45f0 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ ] }, "devDependencies": { + "@types/node": "^24.1.0", "@typescript-eslint/parser": "~8.32.0", "eslint": "^8.57.0", "eslint-plugin-n8n-nodes-base": "^1.16.3",