From 4713db9adcc1ce95254b24d4bdb2b162dddd9351 Mon Sep 17 00:00:00 2001 From: Shane H Date: Sat, 31 Dec 2022 04:02:55 -0500 Subject: [PATCH] fix: display error if attachments exceed limit (#666) --- components/publish/PublishWidget.vue | 28 ++++++++++++++++++++-------- locales/en-GB.json | 1 + locales/en-US.json | 1 + 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/components/publish/PublishWidget.vue b/components/publish/PublishWidget.vue index 64f73953..4256deef 100644 --- a/components/publish/PublishWidget.vue +++ b/components/publish/PublishWidget.vue @@ -54,6 +54,7 @@ const currentVisibility = $computed(() => { }) let isUploading = $ref(false) +let isExceedingAttachmentLimit = $ref(false) let failed = $ref([]) async function handlePaste(evt: ClipboardEvent) { @@ -92,17 +93,25 @@ async function uploadAttachments(files: File[]) { isUploading = true failed = [] // TODO: display some kind of message if too many media are selected + // DONE const limit = currentInstance.value!.configuration.statuses.maxMediaAttachments || 4 for (const file of files.slice(0, limit)) { - try { - const attachment = await masto.mediaAttachments.create({ - file, - }) - draft.attachments.push(attachment) + if (draft.attachments.length < limit) { + isExceedingAttachmentLimit = false + try { + const attachment = await masto.mediaAttachments.create({ + file, + }) + draft.attachments.push(attachment) + } + catch (e) { + // TODO: add some human-readable error message, problem is that masto api will not return response code + console.error(e) + failed = [...failed, file] + } } - catch (e) { - // TODO: add some human-readable error message, problem is that masto api will not return response code - console.error(e) + else { + isExceedingAttachmentLimit = true failed = [...failed, file] } } @@ -246,6 +255,9 @@ defineExpose({ +
+ {{ $t('state.attachments_exceed_server_limit') }} +
  1. {{ file.name }} diff --git a/locales/en-GB.json b/locales/en-GB.json index cae4d546..453028e2 100644 --- a/locales/en-GB.json +++ b/locales/en-GB.json @@ -260,6 +260,7 @@ } }, "state": { + "attachments_exceed_server_limit": "The number of attachments exceeded the limit per post.", "edited": "(Edited)", "editing": "Editing", "loading": "Loading...", diff --git a/locales/en-US.json b/locales/en-US.json index 26c821ef..25f74bfe 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -260,6 +260,7 @@ } }, "state": { + "attachments_exceed_server_limit": "The number of attachments exceeded the limit per post.", "edited": "(Edited)", "editing": "Editing", "loading": "Loading...",