diff --git a/changelog/unreleased/bugfix-epub-library-copy-link.md b/changelog/unreleased/bugfix-epub-library-copy-link.md new file mode 100644 index 00000000000..cf33fb46e74 --- /dev/null +++ b/changelog/unreleased/bugfix-epub-library-copy-link.md @@ -0,0 +1,11 @@ +Bugfix: fixed copy link failing in the EPUB library book details + +Clicking "Copy link" in the details of a book in the EPUB library showed +a "The link could not be copied" error whenever the book had been found +through the server-side search, because those search results carry no +link to the file. + +The link is now built from the id of the file when the search result does +not provide one, so copying the link works for all books. + +https://github.com/owncloud/ocis/pull/13239 diff --git a/web/packages/web-app-epub-reader/src/composables/useLibrary.ts b/web/packages/web-app-epub-reader/src/composables/useLibrary.ts index 55a3646c196..1d9df6a63ca 100644 --- a/web/packages/web-app-epub-reader/src/composables/useLibrary.ts +++ b/web/packages/web-app-epub-reader/src/composables/useLibrary.ts @@ -5,6 +5,7 @@ import { useCapabilityStore, useClientService, useClipboard, + useConfigStore, useDownloadFile, useFolderLink, useMessages, @@ -34,6 +35,7 @@ export function useLibrary() { const { showErrorMessage } = useMessages() const clientService = useClientService() const capabilityStore = useCapabilityStore() + const configStore = useConfigStore() const spacesStore = useSpacesStore() const router = useRouter() const { downloadFile } = useDownloadFile() @@ -253,7 +255,10 @@ export function useLibrary() { } async function copyBookLink(book: LibraryBook): Promise { - const privateLink = book.resource.privateLink + // search REPORT results don't carry oc:privatelink, so build it from the file id + const fileId = book.resource.fileId || book.resource.id + const privateLink = + book.resource.privateLink || (fileId ? `${configStore.serverUrl}f/${fileId}` : '') if (!privateLink) { showErrorMessage({ title: $gettext('The link could not be copied') }) return false diff --git a/web/packages/web-app-epub-reader/tests/unit/useLibrary.spec.ts b/web/packages/web-app-epub-reader/tests/unit/useLibrary.spec.ts index 27474b3a70e..6436b57a3a8 100644 --- a/web/packages/web-app-epub-reader/tests/unit/useLibrary.spec.ts +++ b/web/packages/web-app-epub-reader/tests/unit/useLibrary.spec.ts @@ -216,7 +216,7 @@ describe('useLibrary', () => { }) }) - it('reports an error when no private link is available', async () => { + it('builds the link from the file id when the resource has no private link', async () => { await withLibrary({ searchAvailable: true }, async ({ library }) => { const book = { resource: epubResource({ privateLink: undefined }), @@ -225,6 +225,21 @@ describe('useLibrary', () => { const success = await library.copyBookLink(book) + expect(success).toBe(true) + expect(copyToClipboard).toHaveBeenCalledWith(expect.stringMatching(/\/f\/file-1$/)) + expect(showErrorMessage).not.toHaveBeenCalled() + }) + }) + + it('reports an error when no link can be built', async () => { + await withLibrary({ searchAvailable: true }, async ({ library }) => { + const book = { + resource: epubResource({ privateLink: undefined, fileId: undefined, id: undefined }), + space: personalSpace + } as never + + const success = await library.copyBookLink(book) + expect(success).toBe(false) expect(copyToClipboard).not.toHaveBeenCalled() expect(showErrorMessage).toHaveBeenCalled()