fix
This commit is contained in:
parent
dd1d0b02b9
commit
30f1e4768a
|
|
@ -55,7 +55,7 @@ export const API_ROUTES = {
|
||||||
GET_PRODUCTS: "api/v1/products",
|
GET_PRODUCTS: "api/v1/products",
|
||||||
GET_PRODUCT: (id: string) => `api/v1/products/${id}`,
|
GET_PRODUCT: (id: string) => `api/v1/products/${id}`,
|
||||||
CREATE_PRODUCT: "api/v1/products",
|
CREATE_PRODUCT: "api/v1/products",
|
||||||
UPDATE_PRODUCT: (id: string) => `api/v1/products/${id}`,
|
UPDATE_PRODUCT: (id: string) => `products/${id}`,
|
||||||
DELETE_PRODUCT: (id: string) => `api/v1/products/${id}`,
|
DELETE_PRODUCT: (id: string) => `api/v1/products/${id}`,
|
||||||
GET_PRODUCT_VARIANTS: (id: string) => `api/v1/products/${id}/variants`,
|
GET_PRODUCT_VARIANTS: (id: string) => `api/v1/products/${id}/variants`,
|
||||||
CREATE_PRODUCT_VARIANT: (id: string) => `api/v1/products/${id}/variants`,
|
CREATE_PRODUCT_VARIANT: (id: string) => `api/v1/products/${id}/variants`,
|
||||||
|
|
@ -67,6 +67,7 @@ export const API_ROUTES = {
|
||||||
// Files APIs
|
// Files APIs
|
||||||
GET_FILES: "files",
|
GET_FILES: "files",
|
||||||
UPLOAD_FILE: "files",
|
UPLOAD_FILE: "files",
|
||||||
|
UPLOAD_USER_FILE: "api/v1/users/files",
|
||||||
GET_FILE: (id: string) => `files/${id}`,
|
GET_FILE: (id: string) => `files/${id}`,
|
||||||
UPDATE_FILE: (id: string) => `files/${id}`,
|
UPDATE_FILE: (id: string) => `files/${id}`,
|
||||||
DELETE_FILE: (id: string) => `files/${id}`,
|
DELETE_FILE: (id: string) => `files/${id}`,
|
||||||
|
|
|
||||||
|
|
@ -21,20 +21,13 @@ interface UploadResponse {
|
||||||
export const useFileUpload = () => {
|
export const useFileUpload = () => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: async (file: File): Promise<{ id: string; url: string; mimeType?: string }> => {
|
mutationFn: async (file: File): Promise<{ id: string; url: string; mimeType?: string }> => {
|
||||||
const formData = new FormData();
|
const contentType =
|
||||||
formData.append("file", file);
|
file.type && file.type.startsWith("video") ? "video/mp4" : "image/png";
|
||||||
formData.append("name", "uploaded-file");
|
|
||||||
|
|
||||||
console.log("Uploading file:", file.name);
|
|
||||||
|
|
||||||
const response = await httpPostRequest<UploadResponse>(
|
const response = await httpPostRequest<UploadResponse>(
|
||||||
APIUrlGenerator(API_ROUTES.UPLOAD_FILE),
|
APIUrlGenerator(API_ROUTES.UPLOAD_USER_FILE, undefined, undefined, false),
|
||||||
formData,
|
file,
|
||||||
{
|
{ headers: { "Content-Type": contentType, Accept: "application/json" } }
|
||||||
headers: {
|
|
||||||
"Content-Type": "multipart/form-data",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log("Upload response:", response);
|
console.log("Upload response:", response);
|
||||||
|
|
|
||||||
|
|
@ -105,8 +105,7 @@ export const updateProduct = async (data: UpdateProductRequest) => {
|
||||||
APIUrlGenerator(
|
APIUrlGenerator(
|
||||||
API_ROUTES.UPDATE_PRODUCT(data.id.toString()),
|
API_ROUTES.UPDATE_PRODUCT(data.id.toString()),
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined
|
||||||
false
|
|
||||||
),
|
),
|
||||||
data
|
data
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ const toPublicUrl = (img: any): ProductImage => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const IMAGE_MAX_SIZE = 2 * 1024 * 1024;
|
const IMAGE_MAX_SIZE = 2 * 1024 * 1024;
|
||||||
const VIDEO_MAX_SIZE = 25 * 1024 * 1024;
|
const VIDEO_MAX_SIZE = 50 * 1024 * 1024;
|
||||||
|
|
||||||
const isImageFile = (file: File) => file.type?.startsWith('image/');
|
const isImageFile = (file: File) => file.type?.startsWith('image/');
|
||||||
const isVideoFile = (file: File) => file.type?.startsWith('video/');
|
const isVideoFile = (file: File) => file.type?.startsWith('video/');
|
||||||
|
|
@ -104,10 +104,16 @@ const validateMediaFile = async (file: File, options?: { requireSquare?: boolean
|
||||||
|
|
||||||
const validateExplorerFile = async (file: File) => {
|
const validateExplorerFile = async (file: File) => {
|
||||||
if (isImageFile(file)) {
|
if (isImageFile(file)) {
|
||||||
|
if (file.size > IMAGE_MAX_SIZE) {
|
||||||
|
throw new Error('حجم تصویر نباید بیشتر از ۲ مگابایت باشد');
|
||||||
|
}
|
||||||
await ensureSquareImage(file);
|
await ensureSquareImage(file);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isVideoFile(file)) {
|
if (isVideoFile(file)) {
|
||||||
|
if (file.size > VIDEO_MAX_SIZE) {
|
||||||
|
throw new Error('حجم ویدیو نباید بیشتر از ۵۰ مگابایت باشد');
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new Error('فقط تصاویر یا ویدیو مجاز است');
|
throw new Error('فقط تصاویر یا ویدیو مجاز است');
|
||||||
|
|
@ -606,11 +612,11 @@ const ProductFormPage = () => {
|
||||||
onUpload={handleFileUpload}
|
onUpload={handleFileUpload}
|
||||||
onRemove={handleFileRemove}
|
onRemove={handleFileRemove}
|
||||||
acceptedTypes={['image/*', 'video/*']}
|
acceptedTypes={['image/*', 'video/*']}
|
||||||
maxFileSize={25 * 1024 * 1024}
|
maxFileSize={50 * 1024 * 1024}
|
||||||
maxFiles={10}
|
maxFiles={10}
|
||||||
mode="multi"
|
mode="multi"
|
||||||
label=""
|
label=""
|
||||||
description="تصاویر یا ویدیوهای محصول را آپلود کنید (حداکثر ۲ مگ برای تصویر و ۲۵ مگ برای ویدیو)"
|
description="تصاویر یا ویدیوهای محصول را آپلود کنید (حداکثر ۲ مگ برای تصویر و ۵۰ مگ برای ویدیو)"
|
||||||
onUploadStart={() => setIsUploading(true)}
|
onUploadStart={() => setIsUploading(true)}
|
||||||
onUploadComplete={() => setIsUploading(false)}
|
onUploadComplete={() => setIsUploading(false)}
|
||||||
/>
|
/>
|
||||||
|
|
@ -667,11 +673,11 @@ const ProductFormPage = () => {
|
||||||
onUpload={handleExplorerUpload}
|
onUpload={handleExplorerUpload}
|
||||||
onRemove={handleExplorerRemove}
|
onRemove={handleExplorerRemove}
|
||||||
acceptedTypes={['image/*', 'video/*']}
|
acceptedTypes={['image/*', 'video/*']}
|
||||||
maxFileSize={0}
|
maxFileSize={50 * 1024 * 1024}
|
||||||
maxFiles={5}
|
maxFiles={5}
|
||||||
mode="multi"
|
mode="multi"
|
||||||
label=""
|
label=""
|
||||||
description="فایلهای Explorer را آپلود کنید (تصاویر باید مربعی باشند)"
|
description="فایلهای Explorer را آپلود کنید (تصویر: ۲ مگ، ویدیو: ۵۰ مگ، تصاویر باید مربعی باشند)"
|
||||||
onUploadStart={() => setIsExplorerUploading(true)}
|
onUploadStart={() => setIsExplorerUploading(true)}
|
||||||
onUploadComplete={() => setIsExplorerUploading(false)}
|
onUploadComplete={() => setIsExplorerUploading(false)}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue