Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e903edf
refactor(AttachmentService): Some code style cleanup
mejo- Oct 25, 2023
8682d60
chore(attachments): Remove support for obsolete `text://` format
mejo- Oct 31, 2023
75ec895
feat(attachments): API endpoint to get list of attachments for a docu…
mejo- Oct 25, 2023
264aa76
chore(attachments): Remove obsolete metadata API endpoint
mejo- Nov 15, 2023
2f78829
feat(attachments): Use getAttachmentList API endpoint in resolver
mejo- Oct 31, 2023
b288c85
fix(attachment): Remove candidate logic from ImageView node
mejo- Nov 15, 2023
13cea83
fix(attachments): Fix some issues with the showimage modal
mejo- Nov 21, 2023
d8842a6
chore(attachments): Remove obsolete code
mejo- Nov 21, 2023
0bc3556
feat(editor): Allow to pass fileId to MarkdownContentEditor
mejo- Nov 21, 2023
0f2b874
feat(attachments): Allow to get attachments without document session
mejo- Nov 22, 2023
9b9e876
chore(attachments): Remove special-handling for preview URLs
mejo- Nov 22, 2023
d95d6b2
fix(attachments): Open non-image attachments in viewer or download
mejo- Nov 22, 2023
337724d
fix(AttachmentController): Set fileName of returned attachments
mejo- Nov 27, 2023
7a32d8e
chore(composer): Update autoloader maps
mejo- Nov 27, 2023
597b8d5
fix(attachments): Fix encoding of attachment URI component
mejo- Nov 27, 2023
98a47c3
test(cy): Test to open image in modal and download attachment
mejo- Nov 28, 2023
adf5fe8
chore(middleware): Rename to RequireDocumentSessionOrUserOrShareToken
mejo- Nov 28, 2023
88c8810
fix(attachments): use `getRelativePath` from userFolder for `davPath`
mejo- Nov 28, 2023
6864890
test(AttachmentResolver): Refactor jest tests after parent class refa…
mejo- Nov 28, 2023
6a46001
fix(attachments): Show all loaded images in ShowImageModal
mejo- Nov 28, 2023
e632d72
fix(SessionMiddleware): Check if user/share have access to document
mejo- Nov 29, 2023
b3be90a
fix(AttachmentResolver): Require either fileId or session
mejo- Nov 29, 2023
e391298
reactor(ImageView): Simplify attachmentType/isMediaAttachment logic
mejo- Nov 29, 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- authored and backportbot-nextcloud[bot] committed Nov 29, 2023
commit d8842a61c7f563693dcbd286346464a74ab5a055
17 changes: 0 additions & 17 deletions cypress/e2e/nodes/ImageView.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,6 @@ describe('Image View', () => {
.should('have.attr', 'src')
.should('contain', `/dav/files/${user.userId}/github.png`)
})

it('with preview', () => {
cy.getFile('github.png')
.should('have.attr', 'data-cy-files-list-row-fileid')
.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 (!OC.appswebroots?.richdocuments && !OC.appswebroots?.onlyoffice) {
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 @@ -109,13 +109,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 @@ -141,12 +134,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 @@ -163,6 +155,7 @@ const getQueryVariable = (src, variable) => {
}
}
}
*/

class LoadImageError extends Error {

Expand Down Expand Up @@ -221,29 +214,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 @@ -274,14 +261,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])
}
}
}