Add support for generating and uploading files via presigned URLs
Some checks failed
Build and Push Docker Images / changes (push) Successful in 4s
Build and Push Docker Images / build-backend (push) Has been skipped
Build and Push Docker Images / build-frontend (push) Failing after 48s

Introduces schemas, types, and API endpoints for managing file uploads using presigned URLs. Includes request and response models, React Query hooks, and client SDK functionality for generating and consuming presigned URLs.
This commit is contained in:
2025-03-13 07:34:53 +01:00
parent 03f643895d
commit 6397cfae49
4 changed files with 327 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ import {
type TDataShape,
type Client,
urlSearchParamsBodySerializer,
formDataBodySerializer,
} from "@hey-api/client-axios";
import type {
RootGetData,
@@ -63,6 +64,11 @@ import type {
GetEventBySlugData,
GetEventBySlugResponse,
GetEventBySlugError,
GeneratePresignedUrlApiV1UploadsPresignedUrlPostData,
GeneratePresignedUrlApiV1UploadsPresignedUrlPostResponse,
GeneratePresignedUrlApiV1UploadsPresignedUrlPostError,
UploadFileApiV1UploadsTokenPostData,
UploadFileApiV1UploadsTokenPostError,
} from "./types.gen";
import { client as _heyApiClient } from "./client.gen";
@@ -270,7 +276,6 @@ export const listEventThemes = <ThrowOnError extends boolean = false>(
/**
* Create Theme
* Create new event theme.
*/
export const createEventTheme = <ThrowOnError extends boolean = false>(
options: Options<CreateEventThemeData, ThrowOnError>,
@@ -280,6 +285,12 @@ export const createEventTheme = <ThrowOnError extends boolean = false>(
CreateEventThemeError,
ThrowOnError
>({
security: [
{
scheme: "bearer",
type: "http",
},
],
url: "/api/v1/event_themes/",
...options,
headers: {
@@ -331,7 +342,6 @@ export const getEventTheme = <ThrowOnError extends boolean = false>(
/**
* Update Theme
* Update specific theme by ID.
*/
export const updateEventTheme = <ThrowOnError extends boolean = false>(
options: Options<UpdateEventThemeData, ThrowOnError>,
@@ -341,6 +351,12 @@ export const updateEventTheme = <ThrowOnError extends boolean = false>(
UpdateEventThemeError,
ThrowOnError
>({
security: [
{
scheme: "bearer",
type: "http",
},
],
url: "/api/v1/event_themes/{theme_id}",
...options,
headers: {
@@ -535,3 +551,65 @@ export const getEventBySlug = <ThrowOnError extends boolean = false>(
...options,
});
};
/**
* Generate Presigned Url
* Generate a presigned URL for uploading a file.
*
* This endpoint creates a secure token that allows direct upload to the storage system.
* After successful upload, the file will be accessible at the returned file_url.
*/
export const generatePresignedUrlApiV1UploadsPresignedUrlPost = <
ThrowOnError extends boolean = false,
>(
options: Options<
GeneratePresignedUrlApiV1UploadsPresignedUrlPostData,
ThrowOnError
>,
) => {
return (options.client ?? _heyApiClient).post<
GeneratePresignedUrlApiV1UploadsPresignedUrlPostResponse,
GeneratePresignedUrlApiV1UploadsPresignedUrlPostError,
ThrowOnError
>({
security: [
{
scheme: "bearer",
type: "http",
},
],
url: "/api/v1/uploads/presigned-url",
...options,
headers: {
"Content-Type": "application/json",
...options?.headers,
},
});
};
/**
* Upload File
* Upload a file using a presigned URL token.
*
* This endpoint handles the actual file upload after a presigned URL is generated.
* The token validates the upload permissions and destination.
*/
export const uploadFileApiV1UploadsTokenPost = <
ThrowOnError extends boolean = false,
>(
options: Options<UploadFileApiV1UploadsTokenPostData, ThrowOnError>,
) => {
return (options.client ?? _heyApiClient).post<
unknown,
UploadFileApiV1UploadsTokenPostError,
ThrowOnError
>({
...formDataBodySerializer,
url: "/api/v1/uploads/{token}",
...options,
headers: {
"Content-Type": null,
...options?.headers,
},
});
};