some change
This commit is contained in:
parent
d4a1492d56
commit
313f1def49
38 changed files with 475 additions and 401 deletions
22
src/app/media/mediaService.ts
Normal file
22
src/app/media/mediaService.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
import client from '../api/client.ts'
|
||||
|
||||
export class MediaService {
|
||||
constructor() {}
|
||||
async uploadFile(file: File): Promise<{ mediaId: string; url: URL }> {
|
||||
const body = new FormData()
|
||||
body.append('file', file)
|
||||
|
||||
const response = await client.POST('/media', {
|
||||
// @ts-expect-error this endpoint takes multipart/form-data which means passing a FormData as the body
|
||||
// maybe openapi-fetch only wants to handle JSON? who knows
|
||||
body,
|
||||
credentials: 'include',
|
||||
})
|
||||
|
||||
if (!response.data) {
|
||||
throw new Error('Failed to upload file')
|
||||
}
|
||||
|
||||
return { mediaId: response.data.mediaId, url: new URL(response.data.url) }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue