Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor attachment loading #5042

Merged
merged 23 commits into from
Nov 29, 2023
Merged

Refactor attachment loading #5042

merged 23 commits into from
Nov 29, 2023

Conversation

mejo-
Copy link
Member

@mejo- mejo- commented Nov 27, 2023

📝 Summary

Introduces an API endpoint to fetch a list of native attachments (all files in .attachments.<fileId> folder). Frontend fetches this list when AttachmentResolver is initialized and uses it when resolving attachments.

The main advantage is that all metadata about native attachments is available instantaneously. This obsoletes the logic to iterate through candidates in the frontend code for determining whether it's an image or non-image attachment.

Additionally, it allows to decide in frontend what to do with non-image attachments. When viewer is available and not in use, supports the attachment mimetype and we're not in a public share, we open the attachment in viewer now. Otherwise we download the attachment.

The editor API now uses MarkdownContentEditor.vue when fileId is passed along with useSession = false. We need the fileId in MarkdownContentEditor.vue for using the AttachmentResolver in a meaningful way. Also required: the backend allows to get the attachment list without a document session.

Also:

🚧 TODO

  • fallback in frontend resolver: update list if attachment is not found
  • generate full image/media URL in backend
  • generate preview (image/mediaPreview) URL in backend
  • get rid of getMediaMetadataUrl in frontend
  • Move to RequireDocumentSessionUserOrShareToken in all read-only endpoints of
    AttachmentController.
  • Check access of user/shareToken to document in SessionMiddleware

additional scenarios

  • In public share (Editor.vue)
  • Read-only in public share (Editor.vue)
  • Without session (MarkdownContentEditor.vue)
  • Without session in public share (MarkdownContentEditor.vue)
  • Attachment is added during session (Editor.vue)
  • Delete and re-add attachment in session, works for other clients?
  • Upload several attachments at once
  • Test direct URL (image & media) to full URL on same instance
  • Test URL with .attachments/<wrongId>
  • [-] Test data:... image
    • [-] Text opening in modal
  • Test all scenarios with missing attachments file (image & media)
  • Test opening image (image modal)
    • In Editor.vue with session and user in Text/Viewer
    • In Editor.vue with session and user in Collectives
    • In Editor.vue with session and public share in Text/Viewer
    • In Editor.vue with session and public share in Text standalone (single-file share)
    • In Editor.vue with session and public share in Collectives
    • In MarkdownEditor.vue without session with user in Collectives
    • In MarkdownEditor.vue without session in public share in Collectives
  • Test attachment with (pdf) & without viewer support (tar.gz)
    • In Editor.vue with session and user in Text/Viewer
    • In Editor.vue with session and user in Collectives
    • In Editor.vue with session and public share in Text/Viewer
    • In Editor.vue with session and public share in Text standalone (single-file share)
    • In Editor.vue with session and public share in Collectives
    • In MarkdownEditor.vue without session with user in Collectives
    • In MarkdownEditor.vue without session in public share in Collectives

questions

  • what is this hasPreview=true URL parameter about?

further

  • Delete legacy text:// syntax support
  • Delete &hasPreview=true support
  • Get rid of imageFileId(), getQueryVariable(), isSupportedImage() in ImageView.vue
  • Error message in caption on image load error
  • open non-native images in ShowImageModal
  • ensure correct order (similar to in document) in ShowImageModal
  • open non-image attachments in viewer/new tab
    • Get rid of internalLinkOrImage() in ImageView.vue
    • Open in public share

tests

  • mock AttachmentController response and test AttachmentService logic
  • open image in Text in viewer (->image modal)
  • open tar.gz attachment in Text in viewer (->download)

🏁 Checklist

  • Code is properly formatted (npm run lint / npm run stylelint / composer run cs:check)
  • Sign-off message is added to all commits
  • Tests (unit, integration and/or end-to-end) passing and the changes are covered with tests
  • Documentation is not required

@mejo- mejo- force-pushed the feat/attachments_controller branch 2 times, most recently from e49e197 to 0c32f8a Compare November 27, 2023 13:25
mejo- added a commit to nextcloud/collectives that referenced this pull request Nov 27, 2023
Only do this if editor API is version 1.1 or newer to not break usage
with older Text versions.

This builds on nextcloud/text#5042.

Signed-off-by: Jonas <[email protected]>
mejo- added a commit to nextcloud/collectives that referenced this pull request Nov 27, 2023
Only do this if editor API is version 1.1 or newer to not break usage
with older Text versions.

This builds on nextcloud/text#5042.

Fixes: #620
Fixes: #964

Signed-off-by: Jonas <[email protected]>
@mejo- mejo- force-pushed the feat/attachments_controller branch from 0c32f8a to 99520ae Compare November 27, 2023 14:00
Copy link
Member

@juliusknorr juliusknorr left a comment

Choose a reason for hiding this comment

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

Some first feedback :)

lib/Controller/AttachmentController.php Show resolved Hide resolved
lib/Controller/AttachmentController.php Show resolved Hide resolved
lib/Service/AttachmentService.php Outdated Show resolved Hide resolved
@mejo- mejo- force-pushed the feat/attachments_controller branch 3 times, most recently from 8bdc322 to c893b43 Compare November 28, 2023 15:41
@juliusknorr juliusknorr mentioned this pull request Nov 28, 2023
5 tasks
@mejo- mejo- force-pushed the feat/attachments_controller branch 3 times, most recently from 5469eab to a40b537 Compare November 28, 2023 18:34
Copy link
Member

@juliusknorr juliusknorr left a comment

Choose a reason for hiding this comment

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

Some more comments, but look great so far already.

When viewer is available, not in use and supports the mimetype, and
we're not in a public share, open the attachment in viewer. Otherwise,
download the attachment.

Fixes: #3849
Fixes: #4723
Fixes: #5030

Signed-off-by: Jonas <[email protected]>
Also don't set any davPath at all in public share. We probably don't
have DAV access there anyway.

Signed-off-by: Jonas <[email protected]>
Instead of just opening native image attachments, query the HTML
document to get all loaded attachments (regardless whether native, via
direct URL or via DAV) and list them.

Signed-off-by: Jonas <[email protected]>
@juliusknorr
Copy link
Member

/backport to stable28

@juliusknorr
Copy link
Member

/backport to stable27

@juliusknorr juliusknorr added the bug Something isn't working label Nov 29, 2023
@juliusknorr juliusknorr added this to the Nextcloud 29 milestone Nov 29, 2023
@juliusknorr juliusknorr merged commit a0273e6 into main Nov 29, 2023
47 checks passed
@juliusknorr juliusknorr deleted the feat/attachments_controller branch November 29, 2023 12:57
mejo- added a commit to nextcloud/collectives that referenced this pull request Dec 5, 2023
Only do this if editor API is version 1.1 or newer to not break usage
with older Text versions.

This builds on nextcloud/text#5042.

Fixes: #620
Fixes: #964

Signed-off-by: Jonas <[email protected]>
mejo- added a commit to nextcloud/collectives that referenced this pull request Dec 5, 2023
Only do this if editor API is version 1.1 or newer to not break usage
with older Text versions.

This builds on nextcloud/text#5042.

Fixes: #620
Fixes: #964

Signed-off-by: Jonas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review bug Something isn't working
Projects
None yet
2 participants