Skip to content

Alinear los adjuntos JPG/JPEG de AiScan con el flujo privado de MyFiles de FacturaScripts#29

Merged
erseco merged 1 commit into
mainfrom
copilot/investigate-myfiles-myft-token-issue
May 31, 2026
Merged

Alinear los adjuntos JPG/JPEG de AiScan con el flujo privado de MyFiles de FacturaScripts#29
erseco merged 1 commit into
mainfrom
copilot/investigate-myfiles-myft-token-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 2, 2026

Resuelve el #28: los adjuntos JPG/JPEG importados por AiScan fallaban al abrirse con la URL privada myft (El token de acceso ... no es válido o ha caducado), mientras que los PDF subidos manualmente sí funcionaban.

Causa

AiScan registraba el AttachedFile apuntando a la subcarpeta MyFiles/aiscan_tmp/, en lugar de preparar el fichero en la raíz de MyFiles/ como hace el flujo de subida del core de FacturaScripts. Esa diferencia de ruta provocaba que el servido privado por token funcionara distinto entre las imágenes de AiScan y los adjuntos manuales.

Qué hace

AttachmentService ahora alinea el adjunto con el flujo del core:

  1. Mueve el fichero preparado a la raíz de MyFiles/ con nombres a prueba de colisiones (fichero_1.jpg, etc.).
  2. Deja que AttachedFile lo reubique en la carpeta fechada estándar (MyFiles/2026/05/…), igual que una subida manual.
  3. Conserva el nombre original como filename amigable del AttachedFile.
  4. Si el guardado falla, limpia el fichero preparado.

Así, las imágenes importadas se comportan exactamente como los adjuntos manuales y la URL myft funciona igual para JPG/JPEG que para PDF. Documenta además las comprobaciones del lado del hosting (caché de LiteSpeed, conservación del parámetro myft) por si el fallo es externo al plugin.

Relación con #36 / #39

Como efecto colateral, los adjuntos dejan de aparecer bajo aiscan_tmp/ y pasan a las carpetas fechadas estándar de MyFiles/, por lo que también resuelve la petición del #36 (evitar el confuso aiscan_tmp). Por eso esta solución sustituye al #39 (que solo renombraba la carpeta sin arreglar el problema real de las imágenes): se cierra el #39 en favor de este PR.

Verificación

  • Tests unitarios de AttachmentService (colisiones, saneamiento de nombre, nombre amigable).
  • CI: lint + suite PHPUnit en PHP 8.1–8.5.

Relates to #28 (se mantiene abierto hasta confirmar si el fallo residual es de hosting)

Copilot AI linked an issue May 2, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Investigate invalid MyFiles myft token for JPG/JPEG attachments Align AiScan JPG/JPEG attachments with FacturaScripts private MyFiles flow May 2, 2026
Copilot finished work on behalf of erseco May 2, 2026 06:24
Copilot AI requested a review from erseco May 2, 2026 06:24
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 2, 2026

FacturaScripts Playground Preview

Open this PR in FacturaScripts Playground
Try this PR in your browser

This preview is generated automatically for the copilot/investigate-myfiles-myft-token-issue branch and loads the plugin directly from the PR branch ZIP in FacturaScripts Playground.

@erseco erseco force-pushed the copilot/investigate-myfiles-myft-token-issue branch from 5255007 to a41f91e Compare May 31, 2026 19:41
@erseco erseco changed the title Align AiScan JPG/JPEG attachments with FacturaScripts private MyFiles flow Alinear los adjuntos JPG/JPEG de AiScan con el flujo privado de MyFiles de FacturaScripts May 31, 2026
JPG/JPEG attachments imported by AiScan failed to open through the private
'myft' URL while manually uploaded PDFs worked (#28). The cause was that
AiScan registered the AttachedFile pointing into the 'aiscan_tmp' subfolder
instead of staging the file at the MyFiles root like the core upload flow.

Now AttachmentService moves the staged file to the MyFiles root (with
collision-safe naming) and lets AttachedFile relocate it to the standard
dated folder, so imported images behave exactly like manual uploads. The
original file name is preserved as a friendly AttachedFile filename, and a
failed save cleans up the staged file.

Also documents the hosting-side checks (LiteSpeed cache, myft query param)
for cases where the failure is outside the plugin.
@erseco
Copy link
Copy Markdown
Owner

erseco commented May 31, 2026

Recomendación tras la revisión a fondo:

Es seguro de mezclar y aporta mejora real: nombres de fichero limpios (antes el filename arrastraba el prefijo aiscan_tmp/), staging alineado con el flujo del core de FacturaScripts y tests. No migra ni toca adjuntos existentes, así que todo lo ya importado se sigue abriendo igual (los adjuntos ya viven en las carpetas fechadas estándar MyFiles/AAAA/MM/; aiscan_tmp solo era staging).

Pero no cuentes con que cierre #28. Validándolo con tests sobre la clase real MyFilesToken del core, la generación/validación del token myft es idéntica para JPG y PDF (solo depende del path, no de la extensión). El fallo "JPG no abre / PDF sí" es de la capa de hosting (LiteSpeed), no de AiScan. Por eso cambié Closes #28Relates to #28: al mezclar no se autocierra. Detalle del diagnóstico en #28.

@erseco erseco merged commit 5a4197d into main May 31, 2026
8 checks passed
@erseco erseco deleted the copilot/investigate-myfiles-myft-token-issue branch May 31, 2026 20:07
erseco added a commit that referenced this pull request May 31, 2026
…S.md (#54)

- Document the live upload -> AI extraction -> review -> import flow (make up,
  port, login, provider selection, fixtures) so the merged features can be
  exercised against a real provider, mirroring the ScheduledMail recipe.
- Add Test/e2e-smoke.php: a non-interactive helper that runs the extraction +
  map + import path over the fixtures and reports invoice/attachment/warnings.
- Fix outdated CI matrix references (8.1-8.4 -> 8.1-8.5 after the 8.5 addition).
- Exclude the dev-only smoke helper from PHPCS, like the other Test/ scripts.

No functional defects were found end-to-end testing today's merged PRs
(#27 keyboard nav, #29 image attachments, #46 stock/purchase data, #48 payment
method, #41 localized warnings, #31 tax-inclusive receipts); this PR only adds
the validation guide, the smoke helper and the doc fixes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Investigar token myft inválido en adjuntos JPG/JPEG generados por AiScan

2 participants