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:
@@ -865,16 +865,20 @@ async function loadActivityImages(row: ActivityDto) {
|
||||
clearImageUrls();
|
||||
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 blob =
|
||||
data.type && data.type !== 'application/octet-stream' && !data.type.includes('json')
|
||||
? data
|
||||
: new Blob([data], { type: mime });
|
||||
next.push({
|
||||
id: image.id,
|
||||
name: image.fileName,
|
||||
url: URL.createObjectURL(data),
|
||||
url: URL.createObjectURL(blob),
|
||||
kind,
|
||||
createdAt: image.createdAt,
|
||||
});
|
||||
@@ -885,6 +889,20 @@ async function loadActivityImages(row: ActivityDto) {
|
||||
imageUrls.value = next;
|
||||
}
|
||||
|
||||
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 loadUsers() {
|
||||
try {
|
||||
@@ -1004,8 +1022,12 @@ async function postponeTo(iso: string) {
|
||||
}
|
||||
}
|
||||
|
||||
async function submitComment(payload: { text: string; photoOnly: boolean }) {
|
||||
const body = payload.text.trim() || (payload.photoOnly ? 'عکس پیوست شد.' : '');
|
||||
async function submitComment(payload: {
|
||||
text: string;
|
||||
photoOnly: boolean;
|
||||
attachmentIds?: string[];
|
||||
}) {
|
||||
const body = payload.text.trim() || (payload.photoOnly ? 'فایل پیوست شد.' : '');
|
||||
if (!id.value || !activity.value || !body) return;
|
||||
saving.value = true;
|
||||
error.value = '';
|
||||
@@ -1014,7 +1036,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}`;
|
||||
const next = prev ? `${prev}\n\n${entry}` : entry;
|
||||
await api.patch(`/activities/${id.value}`, { description: next });
|
||||
commentOpen.value = false;
|
||||
@@ -1663,7 +1687,11 @@ onUnmounted(() => {
|
||||
</div>
|
||||
<ul v-if="entry.media.some((image) => image.kind === 'file')" class="note-files">
|
||||
<li v-for="image in entry.media.filter((item) => item.kind === 'file')" :key="image.id">
|
||||
<a :href="image.url" :download="image.name">{{ image.name }}</a>
|
||||
<span class="note-file-name">{{ image.name }}</span>
|
||||
<span class="note-file-actions">
|
||||
<button type="button" class="note-file-btn" @click="viewMedia(image)">مشاهده</button>
|
||||
<button type="button" class="note-file-btn" @click="downloadMedia(image)">دانلود</button>
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
@@ -1746,7 +1774,11 @@ onUnmounted(() => {
|
||||
</div>
|
||||
<ul v-if="looseMedia.some((image) => image.kind === 'file')" class="note-files">
|
||||
<li v-for="image in looseMedia.filter((item) => item.kind === 'file')" :key="image.id">
|
||||
<a :href="image.url" :download="image.name">{{ image.name }}</a>
|
||||
<span class="note-file-name">{{ image.name }}</span>
|
||||
<span class="note-file-actions">
|
||||
<button type="button" class="note-file-btn" @click="viewMedia(image)">مشاهده</button>
|
||||
<button type="button" class="note-file-btn" @click="downloadMedia(image)">دانلود</button>
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -2677,8 +2709,35 @@ dd {
|
||||
gap: 0.35rem;
|
||||
}
|
||||
|
||||
.note-files a {
|
||||
.note-files li {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.note-file-name {
|
||||
color: #0f766e;
|
||||
font-weight: 600;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.note-file-actions {
|
||||
display: inline-flex;
|
||||
gap: 0.35rem;
|
||||
}
|
||||
|
||||
.note-file-btn {
|
||||
border: 1px solid #99f6e4;
|
||||
background: #fff;
|
||||
color: #0f766e;
|
||||
border-radius: 0.45rem;
|
||||
font: inherit;
|
||||
font-size: 0.85rem;
|
||||
font-weight: 700;
|
||||
padding: 0.2rem 0.55rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.dock {
|
||||
|
||||
Reference in New Issue
Block a user