Refactor file upload and presigned URL types and method names
Simplify and standardize type and function names for uploadFile and generatePresignedUrl operations. This change improves readability and aligns naming conventions across the codebase. No functional behavior was altered.
This commit is contained in:
@@ -22,8 +22,8 @@ import {
|
|||||||
getEvent,
|
getEvent,
|
||||||
updateEvent,
|
updateEvent,
|
||||||
getEventBySlug,
|
getEventBySlug,
|
||||||
generatePresignedUrlApiV1UploadsPresignedUrlPost,
|
generatePresignedUrl,
|
||||||
uploadFileApiV1UploadsTokenPost,
|
uploadFile,
|
||||||
} from "../sdk.gen";
|
} from "../sdk.gen";
|
||||||
import { queryOptions, type UseMutationOptions } from "@tanstack/react-query";
|
import { queryOptions, type UseMutationOptions } from "@tanstack/react-query";
|
||||||
import type {
|
import type {
|
||||||
@@ -67,11 +67,11 @@ import type {
|
|||||||
UpdateEventError,
|
UpdateEventError,
|
||||||
UpdateEventResponse,
|
UpdateEventResponse,
|
||||||
GetEventBySlugData,
|
GetEventBySlugData,
|
||||||
GeneratePresignedUrlApiV1UploadsPresignedUrlPostData,
|
GeneratePresignedUrlData,
|
||||||
GeneratePresignedUrlApiV1UploadsPresignedUrlPostError,
|
GeneratePresignedUrlError,
|
||||||
GeneratePresignedUrlApiV1UploadsPresignedUrlPostResponse,
|
GeneratePresignedUrlResponse,
|
||||||
UploadFileApiV1UploadsTokenPostData,
|
UploadFileData,
|
||||||
UploadFileApiV1UploadsTokenPostError,
|
UploadFileError,
|
||||||
} from "../types.gen";
|
} from "../types.gen";
|
||||||
import type { AxiosError } from "axios";
|
import type { AxiosError } from "axios";
|
||||||
import { client as _heyApiClient } from "../client.gen";
|
import { client as _heyApiClient } from "../client.gen";
|
||||||
@@ -629,17 +629,16 @@ export const getEventBySlugOptions = (options: Options<GetEventBySlugData>) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const generatePresignedUrlApiV1UploadsPresignedUrlPostQueryKey = (
|
export const generatePresignedUrlQueryKey = (
|
||||||
options: Options<GeneratePresignedUrlApiV1UploadsPresignedUrlPostData>,
|
options: Options<GeneratePresignedUrlData>,
|
||||||
) =>
|
) => createQueryKey("generatePresignedUrl", options);
|
||||||
createQueryKey("generatePresignedUrlApiV1UploadsPresignedUrlPost", options);
|
|
||||||
|
|
||||||
export const generatePresignedUrlApiV1UploadsPresignedUrlPostOptions = (
|
export const generatePresignedUrlOptions = (
|
||||||
options: Options<GeneratePresignedUrlApiV1UploadsPresignedUrlPostData>,
|
options: Options<GeneratePresignedUrlData>,
|
||||||
) => {
|
) => {
|
||||||
return queryOptions({
|
return queryOptions({
|
||||||
queryFn: async ({ queryKey, signal }) => {
|
queryFn: async ({ queryKey, signal }) => {
|
||||||
const { data } = await generatePresignedUrlApiV1UploadsPresignedUrlPost({
|
const { data } = await generatePresignedUrl({
|
||||||
...options,
|
...options,
|
||||||
...queryKey[0],
|
...queryKey[0],
|
||||||
signal,
|
signal,
|
||||||
@@ -647,22 +646,20 @@ export const generatePresignedUrlApiV1UploadsPresignedUrlPostOptions = (
|
|||||||
});
|
});
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
queryKey: generatePresignedUrlApiV1UploadsPresignedUrlPostQueryKey(options),
|
queryKey: generatePresignedUrlQueryKey(options),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const generatePresignedUrlApiV1UploadsPresignedUrlPostMutation = (
|
export const generatePresignedUrlMutation = (
|
||||||
options?: Partial<
|
options?: Partial<Options<GeneratePresignedUrlData>>,
|
||||||
Options<GeneratePresignedUrlApiV1UploadsPresignedUrlPostData>
|
|
||||||
>,
|
|
||||||
) => {
|
) => {
|
||||||
const mutationOptions: UseMutationOptions<
|
const mutationOptions: UseMutationOptions<
|
||||||
GeneratePresignedUrlApiV1UploadsPresignedUrlPostResponse,
|
GeneratePresignedUrlResponse,
|
||||||
AxiosError<GeneratePresignedUrlApiV1UploadsPresignedUrlPostError>,
|
AxiosError<GeneratePresignedUrlError>,
|
||||||
Options<GeneratePresignedUrlApiV1UploadsPresignedUrlPostData>
|
Options<GeneratePresignedUrlData>
|
||||||
> = {
|
> = {
|
||||||
mutationFn: async (localOptions) => {
|
mutationFn: async (localOptions) => {
|
||||||
const { data } = await generatePresignedUrlApiV1UploadsPresignedUrlPost({
|
const { data } = await generatePresignedUrl({
|
||||||
...options,
|
...options,
|
||||||
...localOptions,
|
...localOptions,
|
||||||
throwOnError: true,
|
throwOnError: true,
|
||||||
@@ -673,16 +670,13 @@ export const generatePresignedUrlApiV1UploadsPresignedUrlPostMutation = (
|
|||||||
return mutationOptions;
|
return mutationOptions;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const uploadFileApiV1UploadsTokenPostQueryKey = (
|
export const uploadFileQueryKey = (options: Options<UploadFileData>) =>
|
||||||
options: Options<UploadFileApiV1UploadsTokenPostData>,
|
createQueryKey("uploadFile", options);
|
||||||
) => createQueryKey("uploadFileApiV1UploadsTokenPost", options);
|
|
||||||
|
|
||||||
export const uploadFileApiV1UploadsTokenPostOptions = (
|
export const uploadFileOptions = (options: Options<UploadFileData>) => {
|
||||||
options: Options<UploadFileApiV1UploadsTokenPostData>,
|
|
||||||
) => {
|
|
||||||
return queryOptions({
|
return queryOptions({
|
||||||
queryFn: async ({ queryKey, signal }) => {
|
queryFn: async ({ queryKey, signal }) => {
|
||||||
const { data } = await uploadFileApiV1UploadsTokenPost({
|
const { data } = await uploadFile({
|
||||||
...options,
|
...options,
|
||||||
...queryKey[0],
|
...queryKey[0],
|
||||||
signal,
|
signal,
|
||||||
@@ -690,20 +684,20 @@ export const uploadFileApiV1UploadsTokenPostOptions = (
|
|||||||
});
|
});
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
queryKey: uploadFileApiV1UploadsTokenPostQueryKey(options),
|
queryKey: uploadFileQueryKey(options),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const uploadFileApiV1UploadsTokenPostMutation = (
|
export const uploadFileMutation = (
|
||||||
options?: Partial<Options<UploadFileApiV1UploadsTokenPostData>>,
|
options?: Partial<Options<UploadFileData>>,
|
||||||
) => {
|
) => {
|
||||||
const mutationOptions: UseMutationOptions<
|
const mutationOptions: UseMutationOptions<
|
||||||
unknown,
|
unknown,
|
||||||
AxiosError<UploadFileApiV1UploadsTokenPostError>,
|
AxiosError<UploadFileError>,
|
||||||
Options<UploadFileApiV1UploadsTokenPostData>
|
Options<UploadFileData>
|
||||||
> = {
|
> = {
|
||||||
mutationFn: async (localOptions) => {
|
mutationFn: async (localOptions) => {
|
||||||
const { data } = await uploadFileApiV1UploadsTokenPost({
|
const { data } = await uploadFile({
|
||||||
...options,
|
...options,
|
||||||
...localOptions,
|
...localOptions,
|
||||||
throwOnError: true,
|
throwOnError: true,
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ export const Body_login_oauthSchema = {
|
|||||||
title: "Body_login_oauth",
|
title: "Body_login_oauth",
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export const Body_upload_file_api_v1_uploads__token__postSchema = {
|
export const Body_upload_fileSchema = {
|
||||||
properties: {
|
properties: {
|
||||||
file: {
|
file: {
|
||||||
type: "string",
|
type: "string",
|
||||||
@@ -81,7 +81,7 @@ export const Body_upload_file_api_v1_uploads__token__postSchema = {
|
|||||||
},
|
},
|
||||||
type: "object",
|
type: "object",
|
||||||
required: ["file"],
|
required: ["file"],
|
||||||
title: "Body_upload_file_api_v1_uploads__token__post",
|
title: "Body_upload_file",
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export const EventCreateSchema = {
|
export const EventCreateSchema = {
|
||||||
|
|||||||
@@ -64,11 +64,11 @@ import type {
|
|||||||
GetEventBySlugData,
|
GetEventBySlugData,
|
||||||
GetEventBySlugResponse,
|
GetEventBySlugResponse,
|
||||||
GetEventBySlugError,
|
GetEventBySlugError,
|
||||||
GeneratePresignedUrlApiV1UploadsPresignedUrlPostData,
|
GeneratePresignedUrlData,
|
||||||
GeneratePresignedUrlApiV1UploadsPresignedUrlPostResponse,
|
GeneratePresignedUrlResponse,
|
||||||
GeneratePresignedUrlApiV1UploadsPresignedUrlPostError,
|
GeneratePresignedUrlError,
|
||||||
UploadFileApiV1UploadsTokenPostData,
|
UploadFileData,
|
||||||
UploadFileApiV1UploadsTokenPostError,
|
UploadFileError,
|
||||||
} from "./types.gen";
|
} from "./types.gen";
|
||||||
import { client as _heyApiClient } from "./client.gen";
|
import { client as _heyApiClient } from "./client.gen";
|
||||||
|
|
||||||
@@ -559,17 +559,12 @@ export const getEventBySlug = <ThrowOnError extends boolean = false>(
|
|||||||
* This endpoint creates a secure token that allows direct upload to the storage system.
|
* 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.
|
* After successful upload, the file will be accessible at the returned file_url.
|
||||||
*/
|
*/
|
||||||
export const generatePresignedUrlApiV1UploadsPresignedUrlPost = <
|
export const generatePresignedUrl = <ThrowOnError extends boolean = false>(
|
||||||
ThrowOnError extends boolean = false,
|
options: Options<GeneratePresignedUrlData, ThrowOnError>,
|
||||||
>(
|
|
||||||
options: Options<
|
|
||||||
GeneratePresignedUrlApiV1UploadsPresignedUrlPostData,
|
|
||||||
ThrowOnError
|
|
||||||
>,
|
|
||||||
) => {
|
) => {
|
||||||
return (options.client ?? _heyApiClient).post<
|
return (options.client ?? _heyApiClient).post<
|
||||||
GeneratePresignedUrlApiV1UploadsPresignedUrlPostResponse,
|
GeneratePresignedUrlResponse,
|
||||||
GeneratePresignedUrlApiV1UploadsPresignedUrlPostError,
|
GeneratePresignedUrlError,
|
||||||
ThrowOnError
|
ThrowOnError
|
||||||
>({
|
>({
|
||||||
security: [
|
security: [
|
||||||
@@ -594,14 +589,12 @@ export const generatePresignedUrlApiV1UploadsPresignedUrlPost = <
|
|||||||
* This endpoint handles the actual file upload after a presigned URL is generated.
|
* This endpoint handles the actual file upload after a presigned URL is generated.
|
||||||
* The token validates the upload permissions and destination.
|
* The token validates the upload permissions and destination.
|
||||||
*/
|
*/
|
||||||
export const uploadFileApiV1UploadsTokenPost = <
|
export const uploadFile = <ThrowOnError extends boolean = false>(
|
||||||
ThrowOnError extends boolean = false,
|
options: Options<UploadFileData, ThrowOnError>,
|
||||||
>(
|
|
||||||
options: Options<UploadFileApiV1UploadsTokenPostData, ThrowOnError>,
|
|
||||||
) => {
|
) => {
|
||||||
return (options.client ?? _heyApiClient).post<
|
return (options.client ?? _heyApiClient).post<
|
||||||
unknown,
|
unknown,
|
||||||
UploadFileApiV1UploadsTokenPostError,
|
UploadFileError,
|
||||||
ThrowOnError
|
ThrowOnError
|
||||||
>({
|
>({
|
||||||
...formDataBodySerializer,
|
...formDataBodySerializer,
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export type BodyLoginOauth = {
|
|||||||
client_secret?: string | null;
|
client_secret?: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type BodyUploadFileApiV1UploadsTokenPost = {
|
export type BodyUploadFile = {
|
||||||
file: Blob | File;
|
file: Blob | File;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -796,35 +796,35 @@ export type GetEventBySlugResponses = {
|
|||||||
export type GetEventBySlugResponse =
|
export type GetEventBySlugResponse =
|
||||||
GetEventBySlugResponses[keyof GetEventBySlugResponses];
|
GetEventBySlugResponses[keyof GetEventBySlugResponses];
|
||||||
|
|
||||||
export type GeneratePresignedUrlApiV1UploadsPresignedUrlPostData = {
|
export type GeneratePresignedUrlData = {
|
||||||
body: PresignedUrlRequest;
|
body: PresignedUrlRequest;
|
||||||
path?: never;
|
path?: never;
|
||||||
query?: never;
|
query?: never;
|
||||||
url: "/api/v1/uploads/presigned-url";
|
url: "/api/v1/uploads/presigned-url";
|
||||||
};
|
};
|
||||||
|
|
||||||
export type GeneratePresignedUrlApiV1UploadsPresignedUrlPostErrors = {
|
export type GeneratePresignedUrlErrors = {
|
||||||
/**
|
/**
|
||||||
* Validation Error
|
* Validation Error
|
||||||
*/
|
*/
|
||||||
422: HttpValidationError;
|
422: HttpValidationError;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type GeneratePresignedUrlApiV1UploadsPresignedUrlPostError =
|
export type GeneratePresignedUrlError =
|
||||||
GeneratePresignedUrlApiV1UploadsPresignedUrlPostErrors[keyof GeneratePresignedUrlApiV1UploadsPresignedUrlPostErrors];
|
GeneratePresignedUrlErrors[keyof GeneratePresignedUrlErrors];
|
||||||
|
|
||||||
export type GeneratePresignedUrlApiV1UploadsPresignedUrlPostResponses = {
|
export type GeneratePresignedUrlResponses = {
|
||||||
/**
|
/**
|
||||||
* Successful Response
|
* Successful Response
|
||||||
*/
|
*/
|
||||||
200: PresignedUrlResponse;
|
200: PresignedUrlResponse;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type GeneratePresignedUrlApiV1UploadsPresignedUrlPostResponse =
|
export type GeneratePresignedUrlResponse =
|
||||||
GeneratePresignedUrlApiV1UploadsPresignedUrlPostResponses[keyof GeneratePresignedUrlApiV1UploadsPresignedUrlPostResponses];
|
GeneratePresignedUrlResponses[keyof GeneratePresignedUrlResponses];
|
||||||
|
|
||||||
export type UploadFileApiV1UploadsTokenPostData = {
|
export type UploadFileData = {
|
||||||
body: BodyUploadFileApiV1UploadsTokenPost;
|
body: BodyUploadFile;
|
||||||
path: {
|
path: {
|
||||||
token: string;
|
token: string;
|
||||||
};
|
};
|
||||||
@@ -832,17 +832,16 @@ export type UploadFileApiV1UploadsTokenPostData = {
|
|||||||
url: "/api/v1/uploads/{token}";
|
url: "/api/v1/uploads/{token}";
|
||||||
};
|
};
|
||||||
|
|
||||||
export type UploadFileApiV1UploadsTokenPostErrors = {
|
export type UploadFileErrors = {
|
||||||
/**
|
/**
|
||||||
* Validation Error
|
* Validation Error
|
||||||
*/
|
*/
|
||||||
422: HttpValidationError;
|
422: HttpValidationError;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type UploadFileApiV1UploadsTokenPostError =
|
export type UploadFileError = UploadFileErrors[keyof UploadFileErrors];
|
||||||
UploadFileApiV1UploadsTokenPostErrors[keyof UploadFileApiV1UploadsTokenPostErrors];
|
|
||||||
|
|
||||||
export type UploadFileApiV1UploadsTokenPostResponses = {
|
export type UploadFileResponses = {
|
||||||
/**
|
/**
|
||||||
* Successful Response
|
* Successful Response
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user