π The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.
Vue dockergolangkanbanknowledge-baseknowledge-managementmarkdownnote-takingnotesnotes-appnotionnuxtnuxtjsoffline-firstoidcpwaselfhostedssovuevuejswiki
Improve code style: use exported helpers
Smaug673946b50f7452d8
diff --git a/frontend/app/helpers/ressources.ts b/frontend/app/helpers/ressources.tsindex dd9aed71..b898ef7f 100644--- a/frontend/app/helpers/ressources.ts+++ b/frontend/app/helpers/ressources.ts@@ -16,6 +16,9 @@ const readableFileSize = (bytes: number): string => {/** Check if a filetype MIME string represents an image */const isImageFile = (filetype: string): boolean => filetype.startsWith('image/');+/** Check if a filetype MIME string represents a PDF */+const isPdfFile = (filetype: string): boolean => filetype.startsWith('application/pdf');+/** Get the CDN preview URL for a resource node */const resolvePreviewUrl = (node: Node): string => {const { CDN } = useApi();@@ -25,4 +28,4 @@ const resolvePreviewUrl = (node: Node): string => {return '/file_placeholder.png';};-export { readableFileSize, resolvePreviewUrl, isImageFile };+export { readableFileSize, resolvePreviewUrl, isImageFile, isPdfFile };diff --git a/frontend/app/pages/dashboard/cdn/[id]/preview.vue b/frontend/app/pages/dashboard/cdn/[id]/preview.vueindex 785b51b8..7b3219f6 100644--- a/frontend/app/pages/dashboard/cdn/[id]/preview.vue+++ b/frontend/app/pages/dashboard/cdn/[id]/preview.vue@@ -1,29 +1,18 @@<template><div class="card"><template v-if="ressource">- <header style="display: flex; align-items: center; justify-content: space-between">+ <header><h1>Preview <tag yellow>Beta</tag> β’ {{ ressource.name }}</h1><div class="actions">- <AppSelect- v-if="(ressource?.metadata?.filetype as string)?.startsWith('application/pdf')"- v-model="scale"- :items="PDF_SCALES"- :searchable="false"- label="Scale"- style="margin-right: 12px"- />+ <AppSelect v-if="isPdfFile(mimeType)" v-model="scale" :items="PDF_SCALES" :searchable="false" label="Scale" style="margin-right: 12px" /><NuxtLink :to="`/dashboard/cdn/${ressource.id}`"><AppButton type="primary">Edit</AppButton></NuxtLink><AppButton type="secondary" @click="copyLink">Copy link</AppButton></div></header><div class="preview">- <img- v-if="(ressource?.metadata?.filetype as string)?.startsWith('image/')"- :src="`${CDN}/${ressource!.user_id}/${ressource!.metadata?.transformed_path || ressource!.content}`"- alt="Preview"- />+ <img v-if="isImageFile(mimeType)" :src="`${CDN}/${ressource!.user_id}/${ressource!.metadata?.transformed_path || ressource!.content}`" alt="Preview" /><LazyPDFViewer- v-else-if="(ressource?.metadata?.filetype as string)?.startsWith('application/pdf')"+ v-else-if="isPdfFile(mimeType)":src="`${CDN}/${ressource!.user_id}/${ressource!.metadata?.transformed_path || ressource!.content}`":scale="scale"/>@@ -35,6 +24,7 @@<script setup lang="ts">import { PDF_SCALES, DEFAULT_PDF_SCALE } from '~/helpers/constants';+import { isImageFile, isPdfFile } from '~/helpers/ressources';definePageMeta({ breadcrumb: 'Preview' });@@ -44,6 +34,7 @@ const { isMobile } = useDevice();const scale = ref(isMobile.value ? DEFAULT_PDF_SCALE.mobile : DEFAULT_PDF_SCALE.desktop);const ressource = computed(() => useNodesStore().getById(useRoute().params.id as string));+const mimeType = computed(() => ressource.value?.metadata?.filetype || '');const copyLink = () => {const link = `${CDN}/${ressource.value?.user_id}/${ressource.value?.metadata?.transformed_path || ressource.value?.content}`;@@ -57,6 +48,12 @@ const copyLink = () => {height: 100%;}+header {+ display: flex;+ align-items: center;+ justify-content: space-between;+}+.actions {display: flex;align-items: center;