uploader
This commit is contained in:
@@ -0,0 +1,14 @@
|
|||||||
|
import { useMutation } from "@tanstack/react-query";
|
||||||
|
import * as api from "../service/UploaderService";
|
||||||
|
|
||||||
|
export const useSingleUpload = () => {
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: api.singleUpload,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useMultipleUpload = () => {
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: api.multipleUpload,
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import axios from "@/config/axios";
|
||||||
|
import type {
|
||||||
|
SingleUploadResponse,
|
||||||
|
MultipleUploadResponse,
|
||||||
|
} from "../types/Types";
|
||||||
|
|
||||||
|
export const singleUpload = async (
|
||||||
|
file: File
|
||||||
|
): Promise<SingleUploadResponse> => {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append("file", file);
|
||||||
|
const { data } = await axios.post<SingleUploadResponse>(
|
||||||
|
`/admin/single-file`,
|
||||||
|
formData
|
||||||
|
);
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const multipleUpload = async (
|
||||||
|
files: File[]
|
||||||
|
): Promise<MultipleUploadResponse> => {
|
||||||
|
const formData = new FormData();
|
||||||
|
files.forEach((file) => {
|
||||||
|
formData.append("files", file);
|
||||||
|
});
|
||||||
|
const { data } = await axios.post<MultipleUploadResponse>(
|
||||||
|
`/admin/multi-file`,
|
||||||
|
formData
|
||||||
|
);
|
||||||
|
return data;
|
||||||
|
};
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import type { BaseResponse } from "@/shared/types/SharedTypes";
|
||||||
|
|
||||||
|
export type UploadedFile = {
|
||||||
|
key: string;
|
||||||
|
url: string;
|
||||||
|
bucket: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SingleUploadResponseData = {
|
||||||
|
file: UploadedFile;
|
||||||
|
url: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SingleUploadResponse = BaseResponse<SingleUploadResponseData>;
|
||||||
|
|
||||||
|
export type MultipleUploadResponse = BaseResponse<SingleUploadResponseData[]>;
|
||||||
Reference in New Issue
Block a user