From 6ff0cf5fb3918514bd4098bfb2105b58a64e3b72 Mon Sep 17 00:00:00 2001 From: silverpill Date: Fri, 6 Jan 2023 17:39:41 +0000 Subject: [PATCH] Use media limits provided by the backend --- CHANGELOG.md | 1 + src/api/instance.ts | 10 +++++++++- src/components/PostEditor.vue | 19 +++++++++++++++---- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e2a91e..58cabe1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Added `/@username` routes for profile pages. - Allowed to attach image from clipboard. +- Started using media limits provided by the backend. ### Changed diff --git a/src/api/instance.ts b/src/api/instance.ts index 0f62616..843312f 100644 --- a/src/api/instance.ts +++ b/src/api/instance.ts @@ -31,8 +31,16 @@ export interface InstanceInfo { description_source: string; version: string; registrations: boolean; + configuration: { + statuses: { + max_characters: number, + max_media_attachments: number, + }, + media_attachments: { + supported_mime_types: string[], + }, + }, login_message: string; - post_character_limit: number; blockchains: BlockchainInfo[]; ipfs_gateway_url: string | null; } diff --git a/src/components/PostEditor.vue b/src/components/PostEditor.vue index 06fd3b0..b726ebb 100644 --- a/src/components/PostEditor.vue +++ b/src/components/PostEditor.vue @@ -52,7 +52,7 @@ @@ -143,7 +143,6 @@ import { setupAutoResize, triggerResize } from "@/utils/autoresize" import { fileToDataUrl, dataUrlToBase64 } from "@/utils/upload" const visibilityMap = Object.entries(VISIBILITY_MAP) -const ATTACHMENTS_MAX_NUM = 10 const POST_CONTENT_STORAGE_KEY = "post_content" const { currentUser, ensureAuthToken } = $(useCurrentUser()) @@ -225,7 +224,19 @@ async function onPaste(event: ClipboardEvent) { } function canAttachFile(): boolean { - return attachments.length < ATTACHMENTS_MAX_NUM + if (!instance) { + return false + } + return attachments.length < instance.configuration.statuses.max_media_attachments +} + +function getAcceptedMediaTypes(): string { + if (!instance) { + return "" + } + return instance.configuration.media_attachments.supported_mime_types + .filter(mediaType => mediaType.startsWith("image/")) + .join(",") } function selectAttachment() { @@ -269,7 +280,7 @@ function getCharacterCount(): number { if (!instance) { return 0 } - return (instance.post_character_limit - content.length) + return (instance.configuration.statuses.max_characters - content.length) } function canPreview(): boolean {