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

[stable27] Refactor attachment loading #5087

Merged
merged 26 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a437b83
refactor(AttachmentService): Some code style cleanup
mejo- Oct 25, 2023
d331a36
chore(attachments): Remove support for obsolete `text://` format
mejo- Oct 31, 2023
0aa69d7
feat(attachments): API endpoint to get list of attachments for a docu…
mejo- Oct 25, 2023
a282b70
chore(attachments): Remove obsolete metadata API endpoint
mejo- Nov 15, 2023
29c79f8
feat(attachments): Use getAttachmentList API endpoint in resolver
mejo- Oct 31, 2023
a3ecdb1
fix(attachment): Remove candidate logic from ImageView node
mejo- Nov 15, 2023
af29e57
fix(attachments): Fix some issues with the showimage modal
mejo- Nov 21, 2023
a6fcc87
chore(attachments): Remove obsolete code
mejo- Nov 21, 2023
95ef57d
feat(editor): Allow to pass fileId to MarkdownContentEditor
mejo- Nov 21, 2023
969b85c
feat(attachments): Allow to get attachments without document session
mejo- Nov 22, 2023
4441e7a
chore(attachments): Remove special-handling for preview URLs
mejo- Nov 22, 2023
3703ea1
fix(attachments): Open non-image attachments in viewer or download
mejo- Nov 22, 2023
c2a7fea
fix(AttachmentController): Set fileName of returned attachments
mejo- Nov 27, 2023
95c6734
chore(composer): Update autoloader maps
mejo- Nov 27, 2023
e2b2c16
fix(attachments): Fix encoding of attachment URI component
mejo- Nov 27, 2023
463b55f
test(cy): Test to open image in modal and download attachment
mejo- Nov 28, 2023
cd51248
chore(middleware): Rename to RequireDocumentSessionOrUserOrShareToken
mejo- Nov 28, 2023
d135f9d
fix(attachments): use `getRelativePath` from userFolder for `davPath`
mejo- Nov 28, 2023
112e399
test(AttachmentResolver): Refactor jest tests after parent class refa…
mejo- Nov 28, 2023
cf30cde
fix(attachments): Show all loaded images in ShowImageModal
mejo- Nov 28, 2023
99ac897
fix(SessionMiddleware): Check if user/share have access to document
mejo- Nov 29, 2023
64b7639
fix(AttachmentResolver): Require either fileId or session
mejo- Nov 29, 2023
a4cafdc
reactor(ImageView): Simplify attachmentType/isMediaAttachment logic
mejo- Nov 29, 2023
febbd11
fix(deps): Update to cypress 13
mejo- Dec 5, 2023
70b5a89
chore(deps): Move `cypress-visual-regression` to dev dependencies
mejo- Dec 5, 2023
8b67f07
chore(assets): Recompile assets
nextcloud-command Dec 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

return [
'routes' => [
/** @see Controller\AttachmentController::getAttachmentFile() */
['name' => 'Attachment#getAttachmentList', 'url' => '/attachments', 'verb' => 'POST'],
/** @see Controller\AttachmentController::insertAttachmentFile() */
['name' => 'Attachment#insertAttachmentFile', 'url' => '/attachment/filepath', 'verb' => 'POST'],
/** @see Controller\AttachmentController::uploadAttachment() */
Expand All @@ -39,8 +41,6 @@
['name' => 'Attachment#getMediaFile', 'url' => '/media', 'verb' => 'GET'],
/** @see Controller\AttachmentController::getMediaFilePreview() */
['name' => 'Attachment#getMediaFilePreview', 'url' => '/mediaPreview', 'verb' => 'GET'],
/** @see Controller\AttachmentController::getMediaFileMetadata() */
['name' => 'Attachment#getMediaFileMetadata', 'url' => '/mediaMetadata', 'verb' => 'GET'],

/** @see Controller\SessionController::create() */
['name' => 'Session#create', 'url' => '/session/create', 'verb' => 'PUT'],
Expand Down
1 change: 1 addition & 0 deletions composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
'OCA\\Text\\Listeners\\NodeCopiedListener' => $baseDir . '/../lib/Listeners/NodeCopiedListener.php',
'OCA\\Text\\Listeners\\RegisterDirectEditorEventListener' => $baseDir . '/../lib/Listeners/RegisterDirectEditorEventListener.php',
'OCA\\Text\\Middleware\\Attribute\\RequireDocumentSession' => $baseDir . '/../lib/Middleware/Attribute/RequireDocumentSession.php',
'OCA\\Text\\Middleware\\Attribute\\RequireDocumentSessionOrUserOrShareToken' => $baseDir . '/../lib/Middleware/Attribute/RequireDocumentSessionOrUserOrShareToken.php',
'OCA\\Text\\Middleware\\SessionMiddleware' => $baseDir . '/../lib/Middleware/SessionMiddleware.php',
'OCA\\Text\\Migration\\ResetSessionsBeforeYjs' => $baseDir . '/../lib/Migration/ResetSessionsBeforeYjs.php',
'OCA\\Text\\Migration\\Version010000Date20190617184535' => $baseDir . '/../lib/Migration/Version010000Date20190617184535.php',
Expand Down
1 change: 1 addition & 0 deletions composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class ComposerStaticInitText
'OCA\\Text\\Listeners\\NodeCopiedListener' => __DIR__ . '/..' . '/../lib/Listeners/NodeCopiedListener.php',
'OCA\\Text\\Listeners\\RegisterDirectEditorEventListener' => __DIR__ . '/..' . '/../lib/Listeners/RegisterDirectEditorEventListener.php',
'OCA\\Text\\Middleware\\Attribute\\RequireDocumentSession' => __DIR__ . '/..' . '/../lib/Middleware/Attribute/RequireDocumentSession.php',
'OCA\\Text\\Middleware\\Attribute\\RequireDocumentSessionOrUserOrShareToken' => __DIR__ . '/..' . '/../lib/Middleware/Attribute/RequireDocumentSessionOrUserOrShareToken.php',
'OCA\\Text\\Middleware\\SessionMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/SessionMiddleware.php',
'OCA\\Text\\Migration\\ResetSessionsBeforeYjs' => __DIR__ . '/..' . '/../lib/Migration/ResetSessionsBeforeYjs.php',
'OCA\\Text\\Migration\\Version010000Date20190617184535' => __DIR__ . '/..' . '/../lib/Migration/Version010000Date20190617184535.php',
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/attachments.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const checkAttachment = (documentId, fileName, fileId, index, isImage = true) =>
.find('img')
.should('have.attr', 'src')
.should('contain', 'apps/text/' + srcPathEnd + '?documentId=' + documentId)
.should('contain', srcFileNameParam + '=' + encodeURIComponent(fileName))
.should('contain', srcFileNameParam + '=' + fixedEncodeURIComponent(fileName))

return isImage
? cy.wrap($el)
Expand Down
59 changes: 42 additions & 17 deletions cypress/e2e/nodes/ImageView.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,6 @@ describe('Image View', () => {
.should('have.attr', 'src')
.should('contain', `/dav/files/${user.userId}/github.png`)
})

it('with preview', () => {
cy.get('.files-fileList tr[data-file="github.png"]')
.should('have.attr', 'data-id')
.then(imageId => {
const fileName = `${Cypress.currentTest.title}.md`

createMarkdown(fileName, `# from image id\n\n ![${imageId}](github.png?fileId=${imageId}&hasPreview=true)`)

cy.openFile(fileName, { force: true })

cy.getContent()
.find('[data-component="image-view"] img')
.should('have.attr', 'src')
.should('contains', `core/preview?fileId=${imageId}&file=${encodeURIComponent('/github.png')}`, { timeout: 5000 })
})
})
})

describe('fail to load', () => {
Expand Down Expand Up @@ -127,4 +110,46 @@ describe('Image View', () => {
.should('have.value', 'yaha')
})
})

describe('native attachments', () => {
before(() => {
cy.login(user)
cy.visit('/apps/files')
const fileName = 'native attachments.md'
createMarkdown(fileName, '# open image in modal\n\n ![git](.attachments.123/github.png)\n\n ![file.txt.gz](.attachments.123/file.txt.gz)')

cy.getFileId(fileName).then((fileId) => {
const attachmentsFolder = `.attachments.${fileId}`
cy.createFolder(attachmentsFolder)
cy.uploadFile('github.png', 'image/png', `${attachmentsFolder}/github.png`)
cy.uploadFile('file.txt.gz', 'application/gzip', `${attachmentsFolder}/file.txt.gz`)
})
})

it('open image in modal', () => {
const fileName = 'native attachments.md'
cy.openFile(fileName)

cy.getContent()
.find('[data-component="image-view"][data-src=".attachments.123/github.png"] img')
.click()

cy.get('.modal__content img')
.should('have.attr', 'src')
.should('contain', 'imageFileName=github.png')
})

it('download non-image gzip attachment', () => {
const fileName = 'native attachments.md'
cy.openFile(fileName)

cy.getContent()
.find('[data-component="image-view"][data-src=".attachments.123/file.txt.gz"] img')
.click()

const downloadsFolder = Cypress.config('downloadsFolder')
cy.log(`downloadsFolder: ${downloadsFolder}`)
cy.readFile(`${downloadsFolder}/file.txt.gz`)
})
})
})
5 changes: 5 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@ Cypress.Commands.add('openFolder', (name) => {
cy.wait(`@open-${name}`)
})

Cypress.Commands.add('getFileId', (fileName, params = {}) => {
return cy.get(`.files-fileList tr[data-file="${fileName}"]`)
.invoke('attr', 'data-id')
})

Cypress.Commands.add('openFile', (fileName, params = {}) => {
cy.get(`.files-fileList tr[data-file="${fileName}"] a.name`).click(params)
})
Expand Down
4 changes: 2 additions & 2 deletions js/editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/editor.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-editors.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions js/text-editors.js.LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/

/*!
* Vue.js v2.7.15
* (c) 2014-2023 Evan You
Expand All @@ -31,6 +38,8 @@
* @license MIT
*/

/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */

/**
* @copyright Copyright (c) 2022 Vinicius Reis <[email protected]>
*
Expand Down
2 changes: 1 addition & 1 deletion js/text-editors.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-files.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-files.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-public.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-text.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions js/text-text.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/

/*!
* Vue.js v2.7.15
* (c) 2014-2023 Evan You
Expand All @@ -10,6 +17,8 @@
* @license MIT
*/

/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */

/**
* @copyright Copyright (c) 2022 Vinicius Reis <[email protected]>
*
Expand Down
2 changes: 1 addition & 1 deletion js/text-text.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-viewer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-viewer.js.map

Large diffs are not rendered by default.

Loading
Loading