Fix activity comment file attach text and download.

Link uploaded attachment ids to the comment entry, label photo-only notes as file attached, and expose view/download actions for non-image files.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-17 11:09:14 +03:30
co-authored by Cursor
parent 70524f4f2c
commit abaf012342
3 changed files with 170 additions and 23 deletions
@@ -309,17 +309,35 @@ function apiMessage(e: unknown, fallback: string) {
return fallback;
}
function viewMedia(item: NoteMedia) {
window.open(item.url, '_blank', 'noopener,noreferrer');
}
function downloadMedia(item: NoteMedia) {
const link = document.createElement('a');
link.href = item.url;
link.download = item.name || 'file';
link.rel = 'noopener';
document.body.appendChild(link);
link.click();
link.remove();
}
async function loadNoteMedia(row: ActivityDto) {
clearNoteMedia();
const next: NoteMedia[] = [];
for (const image of row.images ?? []) {
const mime = image.mimeType.toLowerCase();
const mime = (image.mimeType || 'application/octet-stream').toLowerCase();
const kind = mime.startsWith('audio/') ? 'audio' : mime.startsWith('image/') ? 'image' : 'file';
try {
const { data } = await api.get<Blob>(`/activities/${row.id}/images/${image.id}`, {
responseType: 'blob',
});
const url = URL.createObjectURL(data);
const blob =
data.type && data.type !== 'application/octet-stream' && !data.type.includes('json')
? data
: new Blob([data], { type: mime });
const url = URL.createObjectURL(blob);
if (props.activityId !== row.id) {
URL.revokeObjectURL(url);
continue;
@@ -455,10 +473,14 @@ async function postponeTo(iso: string) {
}
}
async function submitComment(payload: { text: string; photoOnly: boolean }) {
async function submitComment(payload: {
text: string;
photoOnly: boolean;
attachmentIds?: string[];
}) {
const id = props.activityId;
const row = activity.value;
const body = payload.text.trim() || (payload.photoOnly ? 'عکس پیوست شد.' : '');
const body = payload.text.trim() || (payload.photoOnly ? 'فایل پیوست شد.' : '');
if (!id || !row || !body) return;
saving.value = true;
error.value = '';
@@ -467,7 +489,9 @@ async function submitComment(payload: { text: string; photoOnly: boolean }) {
const now = new Date();
const author = auth.user?.fullName?.trim();
const stamp = `[${formatJalaliNumeric(now)} ساعت ${formatClockFa(now)}${author ? ` — ${author}` : ''}]`;
const entry = `${stamp}\n${body}`;
const ids = [...new Set((payload.attachmentIds ?? []).filter(Boolean))];
const attachLine = ids.length ? `\n[[attachments:${ids.join(',')}]]` : '';
const entry = `${stamp}\n${body}${attachLine}`;
await api.patch(`/activities/${id}`, { description: prev ? `${prev}\n\n${entry}` : entry });
commentOpen.value = false;
await load(id);
@@ -597,11 +621,60 @@ function openFull() {
:preview="{ zIndex: 1300 }"
/>
</a-flex>
<a-flex
v-if="entry.media.some((item) => item.kind === 'audio')"
vertical
:gap="8"
:style="{ marginTop: '8px' }"
>
<audio
v-for="voice in entry.media.filter((item) => item.kind === 'audio')"
:key="voice.id"
:src="voice.url"
controls
preload="metadata"
style="width: 100%"
/>
</a-flex>
<a-flex
v-if="entry.media.some((item) => item.kind === 'file')"
vertical
:gap="4"
:style="{ marginTop: '8px' }"
>
<a-flex
v-for="file in entry.media.filter((item) => item.kind === 'file')"
:key="file.id"
align="center"
justify="space-between"
:gap="8"
wrap="wrap"
>
<a-typography-text>{{ file.name }}</a-typography-text>
<a-space :size="4">
<a-button type="link" @click="viewMedia(file)">مشاهده</a-button>
<a-button type="link" @click="downloadMedia(file)">دانلود</a-button>
</a-space>
</a-flex>
</a-flex>
</div>
<div v-for="image in threadBlocks.loose.filter((item) => item.kind === 'image')" :key="image.id" :style="noteBubbleStyle">
<a-image :src="image.url" :alt="image.name" :width="72"
:height="72" :preview="{ zIndex: 1300 }" />
</div>
<div
v-for="file in threadBlocks.loose.filter((item) => item.kind === 'file')"
:key="file.id"
:style="noteBubbleStyle"
>
<a-flex align="center" justify="space-between" :gap="8" wrap="wrap">
<a-typography-text>{{ file.name }}</a-typography-text>
<a-space :size="4">
<a-button type="link" @click="viewMedia(file)">مشاهده</a-button>
<a-button type="link" @click="downloadMedia(file)">دانلود</a-button>
</a-space>
</a-flex>
</div>
</a-flex>
<div v-else-if="plainNote || looseImages.length" :style="noteBubbleStyle">
<a-typography-paragraph v-if="plainNote" :style="{ margin: 0, whiteSpace: 'pre-wrap' }">