add file upload for issue
Gitea Actions Demo / Deploy (push) Successful in 36s

This commit is contained in:
vadim committed 2026-10-08 18:38:25 +03:00
1 parent 5b2fbb46ef
commit 0d310c2732
5 files changed
+289 -2

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
import { apiClient } from '@/lib/api-client.ts'
export interface StoredFile {
id: string
fileName: string
mimeType: string
size: number
/** null — the uploader deleted their account */
uploaderId: string | null
createdAt: string
}
export interface IssueAttachment {
issueId: number
file: StoredFile
/** When the file was attached to the issue (may differ from file.createdAt) */
attachedAt: string
}
/** The server serves only these types inline, everything else as a download */
const INLINE_IMAGE_TYPES = ['image/png', 'image/jpeg', 'image/gif', 'image/webp']
export function isPreviewable(file: StoredFile) {
return INLINE_IMAGE_TYPES.includes(file.mimeType)
}
export function downloadUrl(fileId: string) {
return `/api/files/${fileId}/download`
}
// CLIENT REQUEST
/** Uploads a file without an owner; it must be attached afterwards or GC removes it */
export async function fileUpload(file: File) {
const form = new FormData()
form.append('file', file)
return apiClient.upload<StoredFile>('/api/files', form)
}
export async function attachmentsList(issueId: number) {
return apiClient.get<IssueAttachment[]>(`/api/issues/${issueId}/attachments`)
}
export async function attachmentCreate(issueId: number, fileId: string) {
return apiClient.post<IssueAttachment>(`/api/issues/${issueId}/attachments`, { fileId })
}
export async function attachmentDelete(issueId: number, fileId: string) {
await apiClient.delete(`/api/issues/${issueId}/attachments/${fileId}`)
return true
}