rename most frontend image stuff to attachment (except the Tiptap node)

Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
This commit is contained in:
Julien Veyssier 2022-08-23 13:04:13 +02:00
Родитель f5a34ceef7
Коммит 22f70c9541
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4141FEE162030638
13 изменённых файлов: 70 добавлений и 62 удалений

Просмотреть файл

@ -13,7 +13,7 @@
OC = { webroot: '/OC_WEBROOT' }
</script>
<script type="module">
import { RichTextReader, ImageResolver, IMAGE_RESOLVER } from './src/package.js'
import { RichTextReader, AttachmentResolver, ATTACHMENT_RESOLVER } from './src/package.js'
import Vue from 'vue'
import content from './src/tests/fixtures/basic.md?raw'
const app = new Vue({
@ -25,7 +25,7 @@
provide() {
const val = {}
Object.defineProperties(val, {
[IMAGE_RESOLVER]: { get: () => this.$imageResolver },
[ATTACHMENT_RESOLVER]: { get: () => this.$attachmentResolver },
})
return val
},
@ -47,7 +47,7 @@
}),
]),
created() {
this.$imageResolver = new ImageResolver({
this.$attachmentResolver = new AttachmentResolver({
currentDirectory: '/dir/',
shareToken: 'SHARE_TOKEN',
user: { uid: 'USER_UID' },

Просмотреть файл

@ -61,7 +61,7 @@ class Application extends App implements IBootstrap {
$context->registerEventListener(LoadViewer::class, LoadViewerListener::class);
$context->registerEventListener(LoadAdditionalScriptsEvent::class, FilesLoadAdditionalScriptsListener::class);
$context->registerEventListener(BeforeTemplateRenderedEvent::class, FilesSharingLoadAdditionalScriptsListener::class);
// for image attachments
// for attachments
$context->registerEventListener(NodeCopiedEvent::class, NodeCopiedListener::class);
$context->registerEventListener(BeforeNodeRenamedEvent::class, BeforeNodeRenamedListener::class);
$context->registerEventListener(BeforeNodeDeletedEvent::class, BeforeNodeDeletedListener::class);

Просмотреть файл

@ -287,8 +287,8 @@ class AttachmentController extends Controller {
}
} catch (Exception $e) {
$this->logger->error('getMediaFilePreview error', ['exception' => $e]);
return new DataResponse('', Http::STATUS_NOT_FOUND);
}
return new DataResponse('', Http::STATUS_NOT_FOUND);
}
/**

Просмотреть файл

@ -22,7 +22,7 @@
export const EDITOR = Symbol('tiptap:editor')
export const FILE = Symbol('editor:file')
export const IMAGE_RESOLVER = Symbol('image:resolver')
export const ATTACHMENT_RESOLVER = Symbol('attachment:resolver')
export const IS_MOBILE = Symbol('editor:is-mobile')
export const IS_PUBLIC = Symbol('editor:is-public')
export const IS_RICH_EDITOR = Symbol('editor:is-rich-editor')
@ -78,10 +78,10 @@ export const useFileMixin = {
},
}
export const useImageResolver = {
export const useAttachmentResolver = {
inject: {
$imageResolver: {
from: IMAGE_RESOLVER,
$attachmentResolver: {
from: ATTACHMENT_RESOLVER,
default: {
resolve(src) {
console.warn('No image resolver provided. Some image sources cannot be resolved.')

Просмотреть файл

@ -77,7 +77,7 @@ import { loadState } from '@nextcloud/initial-state'
import {
EDITOR,
FILE,
IMAGE_RESOLVER,
ATTACHMENT_RESOLVER,
IS_MOBILE,
IS_PUBLIC,
IS_RICH_EDITOR,
@ -86,7 +86,7 @@ import {
} from './Editor.provider.js'
import { SyncService, ERROR_TYPE, IDLE_TIMEOUT } from './../services/SyncService.js'
import ImageResolver from './../services/ImageResolver.js'
import AttachmentResolver from './../services/AttachmentResolver.js'
import { extensionHighlight } from '../helpers/mappings.js'
import { createEditor, serializePlainText, loadSyntaxHighlight } from './../EditorFactory.js'
import { createMarkdownSerializer } from './../extensions/Markdown.js'
@ -139,8 +139,8 @@ export default {
[FILE]: {
get: () => this.fileData,
},
[IMAGE_RESOLVER]: {
get: () => this.$imageResolver,
[ATTACHMENT_RESOLVER]: {
get: () => this.$attachmentResolver,
},
[IS_PUBLIC]: {
get: () => this.isPublic,
@ -291,7 +291,7 @@ export default {
created() {
this.$editor = null
this.$syncService = null
this.$imageResolver = null
this.$attachmentResolver = null
this.saveStatusPolling = setInterval(() => {
this.updateLastSavedStatus()
}, 2000)
@ -449,7 +449,7 @@ export default {
this.lock = this.$syncService.lock
localStorage.setItem('nick', this.currentSession.guestName)
this.$store.dispatch('setCurrentSession', this.currentSession)
this.$imageResolver = new ImageResolver({
this.$attachmentResolver = new AttachmentResolver({
session: this.currentSession,
user: getCurrentUser(),
shareToken: this.shareToken,

Просмотреть файл

@ -68,7 +68,7 @@ import {
} from '../Editor/MediaHandler.provider.js'
export default {
name: 'ActionImageUpload',
name: 'ActionAttachmentUpload',
components: {
NcActions,
NcActionButton,

Просмотреть файл

@ -48,7 +48,7 @@ import {
Images,
} from '../icons.js'
import EmojiPickerAction from './EmojiPickerAction.vue'
import ActionImageUpload from './ActionImageUpload.vue'
import ActionAttachmentUpload from './ActionAttachmentUpload.vue'
import { MODIFIERS } from './keys.js'
@ -322,7 +322,7 @@ export default [
key: 'insert-image',
label: t('text', 'Insert image'),
icon: Images,
component: ActionImageUpload,
component: ActionAttachmentUpload,
priority: 2,
},
{

Просмотреть файл

@ -107,7 +107,7 @@ import { NodeViewWrapper } from '@tiptap/vue-2'
import ClickOutside from 'vue-click-outside'
import { Image as ImageIcon, Delete as DeleteIcon } from '../components/icons.js'
import store from './../mixins/store.js'
import { useImageResolver } from './../components/Editor.provider.js'
import { useAttachmentResolver } from './../components/Editor.provider.js'
import { mimetypesImages as IMAGE_MIMES } from '../helpers/mime.js'
@ -150,7 +150,7 @@ export default {
},
mixins: [
store,
useImageResolver,
useAttachmentResolver,
],
props: ['editor', 'node', 'extension', 'updateAttributes', 'deleteNode'], // eslint-disable-line
data() {
@ -167,7 +167,7 @@ export default {
},
computed: {
isMediaAttachment() {
return this.attachmentType === this.$imageResolver.ATTACHMENT_TYPE_MEDIA
return this.attachmentType === this.$attachmentResolver.ATTACHMENT_TYPE_MEDIA
},
canDisplayImage() {
if (!this.isSupportedImage) {
@ -235,7 +235,7 @@ export default {
},
methods: {
async init() {
const candidates = this.$imageResolver.resolve(this.src)
const candidates = this.$attachmentResolver.resolve(this.src)
return this.load(candidates)
},
async load(candidates) {
@ -256,7 +256,7 @@ export default {
this.imageLoaded = true
this.loaded = true
this.attachmentType = attachmentType
if (attachmentType === this.$imageResolver.ATTACHMENT_TYPE_MEDIA) {
if (attachmentType === this.$attachmentResolver.ATTACHMENT_TYPE_MEDIA) {
this.loadMediaMetadata(name)
}
resolve(imageUrl)
@ -268,7 +268,7 @@ export default {
})
},
loadMediaMetadata(name) {
this.$imageResolver.getMediaMetadata(name).then((response) => {
this.$attachmentResolver.getMediaMetadata(name).then((response) => {
this.attachmentMetadata = response.data
})
},

Просмотреть файл

@ -21,7 +21,7 @@
*/
import RichTextReader from './components/RichTextReader.vue'
import ImageResolver from './services/ImageResolver.js'
import { IMAGE_RESOLVER } from './components/Editor.provider.js'
import AttachmentResolver from './services/AttachmentResolver.js'
import { ATTACHMENT_RESOLVER } from './components/Editor.provider.js'
export { RichTextReader, ImageResolver, IMAGE_RESOLVER }
export { RichTextReader, AttachmentResolver, ATTACHMENT_RESOLVER }

Просмотреть файл

@ -24,7 +24,7 @@ import { generateUrl, generateRemoteUrl } from '@nextcloud/router'
import axios from '@nextcloud/axios'
import pathNormalize from 'path-normalize'
export default class ImageResolver {
export default class AttachmentResolver {
#session
#user

Просмотреть файл

@ -1,4 +1,4 @@
import ImageResolver from './../../services/ImageResolver.js'
import AttachmentResolver from './../../services/AttachmentResolver.js'
describe('Image resolver', () => {
@ -15,20 +15,20 @@ describe('Image resolver', () => {
const shareToken = 'myShareToken'
it('is a class with one constructor argument', () => {
const resolver = new ImageResolver({})
expect(resolver).toBeInstanceOf(ImageResolver)
const resolver = new AttachmentResolver({})
expect(resolver).toBeInstanceOf(AttachmentResolver)
})
it('handles text:// urls via Text API', () => {
const src = 'text://image?imageFileName=group%20pic.jpg'
const resolver = new ImageResolver({ session })
const resolver = new AttachmentResolver({ session })
const [url] = resolver.resolve(src)
expect(url).toBe('/nc-webroot/apps/text/image?documentId=4173&sessionId=456&sessionToken=mySessionToken&imageFileName=group%20pic.jpg')
})
it('handles text:// urls with token via Text API', () => {
const src = 'text://image?imageFileName=group%20pic.jpg'
const resolver = new ImageResolver({
const resolver = new AttachmentResolver({
session,
shareToken: 'myShareToken',
})
@ -38,7 +38,7 @@ describe('Image resolver', () => {
it('uses user auth over token auth', () => {
const src = 'text://image?imageFileName=group%20pic.jpg'
const resolver = new ImageResolver({
const resolver = new AttachmentResolver({
session,
user,
shareToken: 'myShareToken',
@ -49,14 +49,14 @@ describe('Image resolver', () => {
it('handles .attachments urls via Text API', () => {
const src = `.attachments.${session.documentId}/group%20pic.jpg`
const resolver = new ImageResolver({ session })
const resolver = new AttachmentResolver({ session })
const [url] = resolver.resolve(src)
expect(url).toBe('/nc-webroot/apps/text/image?documentId=4173&sessionId=456&sessionToken=mySessionToken&imageFileName=group%20pic.jpg')
})
it('handles .attachments urls with token via Text API', () => {
const src = `.attachments.${session.documentId}/group%20pic.jpg`
const resolver = new ImageResolver({
const resolver = new AttachmentResolver({
session,
shareToken,
})
@ -72,7 +72,7 @@ describe('Image resolver', () => {
'/core/preview.png?file=pic.jpg&x=1024&y=1024&a=true',
'/apps/files_sharing/publicpreview/ASDFWERASDF?x=1024&y=1024&a=true',
]
const resolver = new ImageResolver({ })
const resolver = new AttachmentResolver({ })
for (const src of sources) {
const [url] = resolver.resolve(src)
expect(url).toBe(src)
@ -81,21 +81,21 @@ describe('Image resolver', () => {
it('uses fileId for preview', () => {
const src = '/Media/photo.jpeg?fileId=7#mimetype=image%2Fjpeg&hasPreview=true'
const resolver = new ImageResolver({ user })
const resolver = new AttachmentResolver({ user })
const [url] = resolver.resolve(src)
expect(url).toContain('/core/preview?fileId=7')
})
it('uses .png endpoint if no fileId is given', () => {
const src = '/Media/photo.jpeg?mimetype=image%2Fjpeg&hasPreview=true'
const resolver = new ImageResolver({ user })
const resolver = new AttachmentResolver({ user })
const [url] = resolver.resolve(src)
expect(url).toBe('/nc-webroot/core/preview.png?file=%2FMedia%2Fphoto.jpeg&x=1024&y=1024&a=true')
})
it('retrieves public preview by path', () => {
const src = '/Media/photo.jpeg?fileId=7#mimetype=image%2Fjpeg&hasPreview=true'
const resolver = new ImageResolver({
const resolver = new AttachmentResolver({
shareToken: 'SHARE_TOKEN'
})
const [url] = resolver.resolve(src)
@ -104,7 +104,7 @@ describe('Image resolver', () => {
it('handles old .attachments urls via webdav with text API fallback', () => {
const src = `.attachments.${session.documentId + 1}/group%20pic.jpg`
const resolver = new ImageResolver({ session, user, currentDirectory })
const resolver = new AttachmentResolver({ session, user, currentDirectory })
const [url, fallback] = resolver.resolve(src)
expect(url).toBe('http://localhost/nc-webroot/remote.php/dav/files/user-uid/parentDir/.attachments.4174/group%20pic.jpg')
expect(fallback).toBe('/nc-webroot/apps/text/image?documentId=4173&sessionId=456&sessionToken=mySessionToken&imageFileName=group%20pic.jpg')
@ -114,7 +114,7 @@ describe('Image resolver', () => {
it('resolves text:// urls as authenticated dav', () => {
const src = 'text://image?imageFileName=group%20pic.jpg'
const resolver = new ImageResolver({
const resolver = new AttachmentResolver({
fileId: 4173,
user,
currentDirectory,
@ -125,7 +125,7 @@ describe('Image resolver', () => {
it('resolves text:// urls as share token download', () => {
const src = 'text://image?imageFileName=group%20pic.jpg'
const resolver = new ImageResolver({
const resolver = new AttachmentResolver({
fileId,
shareToken,
currentDirectory,
@ -136,7 +136,7 @@ describe('Image resolver', () => {
it('handles .attachments urls for other fileIds via webdav with webdav fallback', () => {
const src = `.attachments.${session.documentId + 1}/group%20pic.jpg`
const resolver = new ImageResolver({ user, currentDirectory, fileId })
const resolver = new AttachmentResolver({ user, currentDirectory, fileId })
const [url, fallback] = resolver.resolve(src)
expect(url).toBe('http://localhost/nc-webroot/remote.php/dav/files/user-uid/parentDir/.attachments.4174/group%20pic.jpg')
expect(fallback).toBe('http://localhost/nc-webroot/remote.php/dav/files/user-uid/parentDir/.attachments.4173/group%20pic.jpg')

Просмотреть файл

@ -86,7 +86,15 @@
<code>ConnectException</code>
<code>ServerException</code>
</UndefinedClass>
<UndefinedDocblockClass occurrences="8">
<UndefinedDocblockClass occurrences="16">
<code>\OC\User\NoUserException</code>
<code>\OC\User\NoUserException</code>
<code>\OC\User\NoUserException</code>
<code>\OC\User\NoUserException</code>
<code>\OC\User\NoUserException</code>
<code>\OC\User\NoUserException</code>
<code>\OC\User\NoUserException</code>
<code>\OC\User\NoUserException</code>
<code>\OC\User\NoUserException</code>
<code>\OC\User\NoUserException</code>
<code>\OC\User\NoUserException</code>