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

ファイルサイズが上限を超えたらエラートーストを出すように #4049

Merged
merged 6 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 1 addition & 1 deletion public/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
},
isRootChannelSelectableAsParentChannel: false,
showQrCodeButton: true,
tooLargeFileMessage: '大きい%sの共有にはDriveを使用してください',
tooLargeFileMessage: '大きいファイルの共有にはDriveを使用してください',
showWidgetCopyButton: true,
inlineReplyDisableChannels: ['#general', '#random'],
iosPwaInfoLink: 'https://wiki.trap.jp/SysAd/docs/traQ-S/PWA'
Expand Down
28 changes: 17 additions & 11 deletions src/components/Main/MainView/MessageElement/MessageEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,24 @@ const useAttachmentsEditor = (
if (isPosting.value) return

isPosting.value = true
const attachmentFile = await getResizedFile(file)
const { data } = await apis.postFile(attachmentFile, props.channelId, {
/**
* https://github.com/axios/axios#request-config
*/
onUploadProgress(e: ProgressEvent) {
progress.value = e.loaded / e.total
}
})
try {
const attachmentFile = await getResizedFile(file)
const { data } = await apis.postFile(attachmentFile, props.channelId, {
/**
* https://github.com/axios/axios#request-config
*/
onUploadProgress(e: ProgressEvent) {
progress.value = e.loaded / e.total
}
})

const fileUrl = buildFilePathForPost(data.id)
text.value = text.value !== '' ? `${text.value}\n${fileUrl}` : fileUrl
const fileUrl = buildFilePathForPost(data.id)
text.value = text.value !== '' ? `${text.value}\n${fileUrl}` : fileUrl
} catch (err) {
if (err instanceof Error) {
addErrorToast(err.message)
}
}
progress.value = 0
isPosting.value = false
}
Expand Down
1 change: 1 addition & 0 deletions src/components/Toast/AToast.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,6 @@ const iconName = computed(() => iconNameMap[props.toast.type])
.text {
margin: 4px;
word-break: break-all;
white-space: pre-wrap;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const useMessageInputStateAttachment = (
file: attachmentFile
})
} catch (e) {
if (typeof e === 'string') {
onError(e)
if (e instanceof Error) {
onError(e.message)
}
}
}
Expand Down
15 changes: 2 additions & 13 deletions src/lib/resize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,17 @@ const resize = async (
}
}

const IMAGE_SIZE_LIMIT = 20 * 1000 * 1000 // 20MB
const FILE_SIZE_LIMIT = 30 * 1000 * 1000 // 30MB
mehm8128 marked this conversation as resolved.
Show resolved Hide resolved

const tooLargeFileMessage =
window.traQConfig.tooLargeFileMessage ??
'大きい%sの共有には別のサービスを利用してください。'
'大きいファイルの共有には別のサービスを利用してください。'

const IMAGE_MAX_SIZE_EXCEEDED_MESSAGE = `画像サイズは20MBまでです\n${tooLargeFileMessage.replace(
'%s',
'画像'
)}`
const FILE_MAX_SIZE_EXCEEDED_MESSAGE = `ファイルサイズは30MBまでです\n${tooLargeFileMessage.replace(
'%s',
'ファイル'
)}`
const FILE_MAX_SIZE_EXCEEDED_MESSAGE = `ファイルサイズは30MBまでです\n${tooLargeFileMessage}`

export const getResizedFile = async (file: File) => {
const fileType = mimeToFileType(file.type)

if (fileType === 'image' && file.size > IMAGE_SIZE_LIMIT) {
throw new Error(IMAGE_MAX_SIZE_EXCEEDED_MESSAGE)
}
if (file.size > FILE_SIZE_LIMIT) {
throw new Error(FILE_MAX_SIZE_EXCEEDED_MESSAGE)
}
Expand Down
3 changes: 1 addition & 2 deletions src/types/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ export type Config = Readonly<{
showQrCodeButton?: boolean
/**
* 大きなファイルサイズのファイルを送信した際に表示される補足メッセージ
* `%s`の部分には「画像」または「ファイル」が入る
* @default '大きい%sの共有には別のサービスを利用してください。'
* @default '大きいファイルの共有には別のサービスを利用してください。'
*/
tooLargeFileMessage?: string
/**
Expand Down