Skip to content

fix: correct HEIC/HEIF/AVIF preview URL for local/FTP files#759

Open
guideuhome wants to merge 1 commit into
kekingcn:masterfrom
guideuhome:fix/issue-664-heic-preview-url
Open

fix: correct HEIC/HEIF/AVIF preview URL for local/FTP files#759
guideuhome wants to merge 1 commit into
kekingcn:masterfrom
guideuhome:fix/issue-664-heic-preview-url

Conversation

@guideuhome

Copy link
Copy Markdown

Summary

Fixes two issues in HEIC/HEIF/AVIF file preview implementation:

Bug Fix: Wrong URL for local/FTP files

When previewing HEIC/HEIF/AVIF files from file:// or ftp:// URLs, PictureFilePreviewImpl was setting imgUrls to fileAttribute.getName() (just the filename). However, super.filePreviewHandle() downloads the file and stores the actual relative path in model.currentUrl. The heic.ftl template uses imgUrls to construct image URLs, so a bare filename would produce incorrect URLs like ${baseUrl}photo.heic instead of the correct downloaded file path.

Fix: Use model.getAttribute("currentUrl") — the actual downloaded file path — with a fallback to fileAttribute.getName() if currentUrl is null.

Enhancement: Add AVIF suffix routing

The wasm_heif.js decoder in static/heic/src/worker.js already supports AVIF decoding (it detects AVIF by checking array[8] == 0x61). FileType.java also already lists avif in PICTURE_TYPES. However, the suffix check in PictureFilePreviewImpl didn't route AVIF to the HEIC template, causing AVIF files to use the generic picture template without client-side conversion support.

Fix: Add suffix.equalsIgnoreCase("avif") to the HEIC template routing condition.

Testing

  • HEIC/HEIF/AVIF files from HTTP URLs: unchanged, client-side WASM decoding via error handler
  • HEIC/HEIF/AVIF files from file:///FTP URLs: now correctly uses downloaded file path
  • AVIF files: now properly routed to heic.ftl template with WASM decoder

Closes #664

- Use currentUrl from model instead of fileAttribute.getName() for
  file/ftp URLs. After super.filePreviewHandle() downloads the file,
  the actual path is stored as currentUrl in the model. Using just
  the filename causes the heic.ftl template to construct incorrect
  image URLs.
- Add avif suffix to HEIC template routing. The wasm_heif.js decoder
  in static/heic/src/worker.js already supports AVIF decoding, and
  FileType.java already lists avif in PICTURE_TYPES. This ensures
  AVIF files also benefit from client-side conversion.

Closes kekingcn#664

@klboke klboke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guideuhome thanks for the fix. The currentUrl change for file/ftp HEIC/HEIF previews looks reasonable, but I do not think this PR is safe to merge as-is because of the AVIF routing change.

Blocking issue:

PictureFilePreviewImpl.java now routes avif to HEIC_FILE_PREVIEW_PAGE, but the current HEIC worker cannot actually decode AVIF in this repo state.

Details:

  • server/src/main/resources/static/heic/src/worker.js only imports /heic/src/wasm_heif.js.
  • The AVIF branch later references wasm_avif, which is not loaded, so AVIF preview will fail with ReferenceError.
  • The repository has wasm_avif.js, but does not include the required wasm_avif.wasm; wasm_avif.js attempts to load wasm_avif.wasm at runtime.

This means AVIF files may regress from browser-native preview to a broken HEIC template path.

Suggested fix:

  • If this PR is mainly for issue #664 HEIC/HEIF file/ftp URL handling, remove the avif routing change and keep only the currentUrl fix.
  • If AVIF support is intended here, please also load wasm_avif.js, add the matching wasm_avif.wasm asset, and add at least a small fixture/test or static resource assertion covering AVIF.

Validation I ran locally:

  • mvn -q -pl server -DskipTests compile passes on the PR branch.

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.

请求支持 heic 格式图片

2 participants