fix: handle secure attachment downloads and fix invalid storage URLs

This commit is contained in:
dyzulk
2026-01-04 19:29:46 +07:00
parent fbc26298d2
commit a230ee5890
3 changed files with 3 additions and 3 deletions

View File

@@ -216,7 +216,7 @@ export default function AdminTicketDetailsClient() {
{reply.attachments.map((att: any) => ( {reply.attachments.map((att: any) => (
<a <a
key={att.id} key={att.id}
href={getAttachmentUrl(att.file_path)} href={att.download_url || getAttachmentUrl(att.file_path)}
target="_blank" target="_blank"
rel="noopener noreferrer" rel="noopener noreferrer"
className={`flex items-center gap-2 p-2 rounded-lg text-xs transition-colors ${ className={`flex items-center gap-2 p-2 rounded-lg text-xs transition-colors ${

View File

@@ -230,7 +230,7 @@ export default function TicketDetailsClient() {
{reply.attachments.map((att: any) => ( {reply.attachments.map((att: any) => (
<a <a
key={att.id} key={att.id}
href={getAttachmentUrl(att.file_path)} href={att.download_url || getAttachmentUrl(att.file_path)}
target="_blank" target="_blank"
rel="noopener noreferrer" rel="noopener noreferrer"
className={`flex items-center gap-2 p-2 rounded-lg text-xs transition-colors ${ className={`flex items-center gap-2 p-2 rounded-lg text-xs transition-colors ${

View File

@@ -76,7 +76,7 @@ export const parseApiError = (error: any, defaultMessage: string = "An error occ
* Handles both old relative paths and new absolute R2 URLs. * Handles both old relative paths and new absolute R2 URLs.
*/ */
export const getAttachmentUrl = (filePath: string) => { export const getAttachmentUrl = (filePath: string) => {
if (!filePath) return "#"; if (!filePath || filePath === "0" || filePath === "null") return "#";
// If it's already a full URL (R2), return it as is // If it's already a full URL (R2), return it as is
if (filePath.startsWith("http://") || filePath.startsWith("https://")) { if (filePath.startsWith("http://") || filePath.startsWith("https://")) {