Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore(attachments): Remove obsolete code
* `getMetadata()` from AttachmentResolver class.
* `isSupportedImage` logic from ImageView node. Was never used.
* `hasPreview=true` logic from AttachmentResolver class.

Signed-off-by: Jonas <[email protected]>
  • Loading branch information
mejo- committed Dec 5, 2023
commit a6fcc87271ee230d31d6a2433e6ea18f9518f95e
17 changes: 0 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
13 changes: 0 additions & 13 deletions src/helpers/mime.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@
*
*/

const mimetypesImages = [
'image/png',
'image/jpeg',
'image/jpg',
'image/gif',
'image/x-xbitmap',
'image/x-ms-bmp',
'image/bmp',
'image/svg+xml',
'image/webp',
]

const openMimetypesMarkdown = [
'text/markdown',
]
Expand Down Expand Up @@ -68,7 +56,6 @@ if (!window.oc_appswebroots?.richdocuments && !window.oc_appswebroots?.onlyoffic
const openMimetypes = [...openMimetypesMarkdown, ...openMimetypesPlainText]

export {
mimetypesImages,
openMimetypes,
openMimetypesMarkdown,
openMimetypesPlainText,
Expand Down
29 changes: 4 additions & 25 deletions src/nodes/ImageView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,6 @@
</div>
<div v-else class="image-view__cant_display">
<transition name="fade">
<div v-show="loaded">
<a :href="internalLinkOrImage" target="_blank">
<span v-if="!isSupportedImage">{{ alt }}</span>
</a>
</div>
</transition>
<transition v-if="isSupportedImage" name="fade">
<div v-show="loaded" class="image__caption">
<input ref="altInput"
type="text"
Expand All @@ -139,12 +132,11 @@ import { showError } from '@nextcloud/dialogs'
import ShowImageModal from '../components/ImageView/ShowImageModal.vue'
import store from '../mixins/store.js'
import { useAttachmentResolver } from '../components/Editor.provider.js'
import { mimetypesImages as IMAGE_MIMES } from '../helpers/mime.js'
import { emit } from '@nextcloud/event-bus'
import { generateUrl } from '@nextcloud/router'
import { NodeViewWrapper } from '@tiptap/vue-2'
import { Image as ImageIcon, Delete as DeleteIcon } from '../components/icons.js'

/*
const getQueryVariable = (src, variable) => {
const query = src.split('?')[1]
if (typeof query === 'undefined') {
Expand All @@ -161,6 +153,7 @@ const getQueryVariable = (src, variable) => {
}
}
}
*/

class LoadImageError extends Error {

Expand Down Expand Up @@ -219,29 +212,23 @@ export default {
return this.showDeleteIcon && !this.isMediaAttachment
},
canDisplayImage() {
if (!this.isSupportedImage) {
return false
}

if (this.failed && this.loaded) {
return true
}

return this.loaded && this.imageLoaded
},
/*
imageFileId() {
return getQueryVariable(this.src, 'fileId')
},
isSupportedImage() {
return typeof this.mime === 'undefined'
|| IMAGE_MIMES.indexOf(this.mime) !== -1
},
internalLinkOrImage() {
if (this.imageFileId) {
return generateUrl('/f/' + this.imageFileId)
}
return this.src
},
*/
src: {
get() {
return this.node.attrs.src || ''
Expand Down Expand Up @@ -272,14 +259,6 @@ export default {
this.editor.on('update', ({ editor }) => {
this.isEditable = editor.isEditable
})
if (!this.isSupportedImage) {
// TODO check if hasPreview and render a file preview if available
this.failed = true
this.imageLoaded = false
this.loaded = true
this.errorMessage = t('text', 'Unsupported image type')
return
}
this.loadPreview()
.catch(this.onImageLoadFailure)
},
Expand Down
99 changes: 0 additions & 99 deletions src/services/AttachmentResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@

import { generateUrl, generateRemoteUrl } from '@nextcloud/router'
import pathNormalize from 'path-normalize'
import axios from '@nextcloud/axios'
import { formatFileSize } from '@nextcloud/files'

import { logger } from '../helpers/logger.js'
import store from '../store/index.js'

const setAttachmentList = (val) => store.dispatch('text/setAttachmentList', val)
Expand Down Expand Up @@ -80,13 +77,6 @@ export default class AttachmentResolver {
attachment = findAttachment(imageFileName)
}

if (!attachment) {
// Native attachment not found. Let's stop here.
return []
}
}

if (attachment) {
return attachment
}

Expand All @@ -98,14 +88,6 @@ export default class AttachmentResolver {
}
}

if (hasPreview(src)) { // && this.#mime !== 'image/gif') {
return {
isImage: true,
previewUrl: this.#previewUrl(src),
fullUrl: src,
}
}

// Fallback: Return DAV url
return {
isImage: true,
Expand All @@ -114,40 +96,6 @@ export default class AttachmentResolver {
}
}

#textApiParams() {
if (this.#session) {
return {
documentId: this.#session.documentId,
sessionId: this.#session.id,
sessionToken: this.#session.token,
}
}

return {}
}

#previewUrl(src) {
const imageFileId = getQueryVariable(src, 'fileId')
const path = this.#filePath(src)
const fileQuery = `file=${encodeURIComponent(path)}`
const query = fileQuery + '&x=1024&y=1024&a=true'

if (this.#user && imageFileId) {
return generateUrl(`/core/preview?fileId=${imageFileId}&${query}`)
}

if (this.#user) {
return generateUrl(`/core/preview.png?${query}`)
}

if (this.#shareToken) {
return generateUrl(`/apps/files_sharing/publicpreview/${this.#shareToken}?${query}`)
}

logger.error('No way to authenticate image retrival - need to be logged in or provide a token')
return src
}

#davUrl(src) {
if (this.#user) {
const uid = this.#user.uid
Expand Down Expand Up @@ -184,17 +132,6 @@ export default class AttachmentResolver {
return pathNormalize(f)
}

async getMetadata(src) {
const headResponse = await axios.head(src)
const mimeType = headResponse.headers['content-type']
const size = formatFileSize(headResponse.headers['content-length'])
return { mimeType, size }
}

getMimeUrl(mimeType) {
return mimeType ? OC.MimeType.getIconUrl(mimeType) : null
}

}

/**
Expand All @@ -212,39 +149,3 @@ function isDirectUrl(src) {
|| src.match(/^(\/index.php)?\/core\/preview/)
|| src.match(/^(\/index.php)?\/apps\/files_sharing\/publicpreview\//)
}

/**
* Check if the given url has a preview
*
* @param {string} src - the url to check
*/
function hasPreview(src) {
return getQueryVariable(src, 'hasPreview') === 'true'
}

/**
* Extract the value of a query variable from the given url
*
* @param {string} src - the url to extract query variable from
* @param {string} variable - name of the variable to read out
*/
function getQueryVariable(src, variable) {
const query = src.split('?')[1]

if (typeof query === 'undefined') {
return
}

const vars = query.split(/[&#]/)

if (typeof vars === 'undefined') {
return
}

for (let i = 0; i < vars.length; i++) {
const pair = vars[i].split('=')
if (decodeURIComponent(pair[0]) === variable) {
return decodeURIComponent(pair[1])
}
}
}