update import/export for attachments and new file paths (#22915)

* update import/export for attachments and new file paths

* add unit test

* update templates test

* temp checking

* cleanup

* cleanup

* more cleanup

* lint fixes

* cleanup some functions

* cleanup

* fix build breaks

* fix tests for changes

* move function to different file

* more cleanup, code movement

* unit test fixes

* add unit tests

* fix tests

* more unit test fixes

* test fix

* revert package-lock.json

* fixes from code review

* fix export image

* more fixes to remove attachmentId

* change from removed api

* update test

* lint fixes

* update for review comments

* fix tests

* test fix

* lint fix

* remove sprintf from logging, use mlog

* more lint fixes

* Update server/boards/app/files.go

Co-authored-by: Doug Lauder <wiggin77@warpmail.net>

* remove code

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Co-authored-by: Doug Lauder <wiggin77@warpmail.net>
Этот коммит содержится в:
Scott Bishel
2023-04-26 10:01:00 -06:00
коммит произвёл GitHub
родитель ac35bdff68
Коммит 81ef403230
16 изменённых файлов: 586 добавлений и 279 удалений

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

@@ -3,7 +3,7 @@
import {Block, createBlock} from './block'
type AttachmentBlockFields = {
attachmentId: string
fileId: string
}
type AttachmentBlock = Block & {
@@ -18,7 +18,7 @@ function createAttachmentBlock(block?: Block): AttachmentBlock {
...createBlock(block),
type: 'attachment',
fields: {
attachmentId: block?.fields.attachmentId || '',
fileId: block?.fields.attachmentId || block?.fields.fileId || '',
},
isUploading: false,
uploadingPercent: 0,

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

@@ -151,7 +151,7 @@ const CardDialog = (props: Props): JSX.Element => {
Utils.selectLocalFile(async (attachment) => {
const uploadingBlock = createBlock()
uploadingBlock.title = attachment.name
uploadingBlock.fields.attachmentId = attachment.name
uploadingBlock.fields.fileId = attachment.name
uploadingBlock.boardId = boardId
if (card) {
uploadingBlock.parentId = card.id
@@ -177,11 +177,11 @@ const CardDialog = (props: Props): JSX.Element => {
xhr.onload = () => {
if (xhr.status === 200 && xhr.readyState === 4) {
const json = JSON.parse(xhr.response)
const attachmentId = json.fileId
if (attachmentId) {
const fileId = json.fileId
if (fileId) {
removeUploadingAttachment(uploadingBlock)
const block = createAttachmentBlock()
block.fields.attachmentId = attachmentId || ''
block.fields.fileId = fileId || ''
block.title = attachment.name
sendFlashMessage({content: intl.formatMessage({id: 'AttachmentBlock.uploadSuccess', defaultMessage: 'Attachment uploaded.'}), severity: 'normal'})
resolve(block)

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

@@ -39,7 +39,7 @@ describe('component/content/FileBlock', () => {
type: 'attachment',
title: 'test-title',
fields: {
attachmentId: 'test.txt',
fileId: 'test.txt',
},
createdBy: 'test-user-id',
createAt: 0,

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

@@ -50,7 +50,7 @@ const AttachmentElement = (props: Props): JSX.Element|null => {
})
return
}
const attachmentInfo = await octoClient.getFileInfo(block.boardId, block.fields.attachmentId)
const attachmentInfo = await octoClient.getFileInfo(block.boardId, block.fields.fileId)
setFileInfo(attachmentInfo)
}
loadFile()
@@ -113,7 +113,7 @@ const AttachmentElement = (props: Props): JSX.Element|null => {
}
const attachmentDownloadHandler = async () => {
const attachment = await octoClient.getFileAsDataUrl(block.boardId, block.fields.attachmentId)
const attachment = await octoClient.getFileAsDataUrl(block.boardId, block.fields.fileId)
const anchor = document.createElement('a')
anchor.href = attachment.url || ''
anchor.download = fileInfo.name || ''