feat: add album and media management features, including album creation, media upload, and routing

This commit is contained in:
2025-11-16 01:19:17 +01:00
parent 252491bd2f
commit 43157cef4e
18 changed files with 814 additions and 8 deletions

View File

@@ -0,0 +1,56 @@
import type { Media, PaginatedResponse } from "@/domain/types"
import apiClient from "@/services/api-client"
type MediaListParams = {
page: number
limit: number
}
/**
* Fetches a paginated list of media.
*/
export const getMediaList = async ({
page,
limit,
}: MediaListParams): Promise<PaginatedResponse<Media>> => {
const { data } = await apiClient.get('/media', {
params: { page, limit },
})
// we need to append base url to file_url and thumbnail_url
const prefix = import.meta.env.VITE_PREFIX_PATH || apiClient.defaults.baseURL;
data.data = data.data.map((media: Media) => ({
...media,
file_url: `${prefix}${media.file_url}`,
thumbnail_url: media.thumbnail_url
? `${prefix}${media.thumbnail_url}`
: null,
}))
return data
}
/**
* Uploads a new media file.
*/
export const uploadMedia = async (
file: File,
onProgress: (progress: number) => void,
): Promise<Media> => {
const formData = new FormData()
formData.append('file', file)
const { data } = await apiClient.post('/media', formData, {
headers: {
'Content-Type': 'multipart/form-data',
},
onUploadProgress: (progressEvent) => {
const percentCompleted = Math.round(
(progressEvent.loaded * 100) / (progressEvent.total ?? 100),
)
onProgress(percentCompleted)
},
})
return data
}