chore: gif support for editor (#6219)

This commit is contained in:
Aaryan Khandelwal 2024-12-18 13:17:05 +05:30 committed by GitHub
parent e33bae2125
commit 5773c2bde3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 25 additions and 6 deletions

View file

@ -126,7 +126,13 @@ class UserAssetsV2Endpoint(BaseAPIView):
) )
# Check if the file type is allowed # Check if the file type is allowed
allowed_types = ["image/jpeg", "image/png", "image/webp", "image/jpg"] allowed_types = [
"image/jpeg",
"image/png",
"image/webp",
"image/jpg",
"image/gif",
]
if type not in allowed_types: if type not in allowed_types:
return Response( return Response(
{ {

View file

@ -86,7 +86,13 @@ class EntityAssetEndpoint(BaseAPIView):
) )
# Check if the file type is allowed # Check if the file type is allowed
allowed_types = ["image/jpeg", "image/png", "image/webp"] allowed_types = [
"image/jpeg",
"image/png",
"image/webp",
"image/jpg",
"image/gif",
]
if type not in allowed_types: if type not in allowed_types:
return Response( return Response(
{ {

View file

@ -5,3 +5,6 @@ export const DEFAULT_DISPLAY_CONFIG: TDisplayConfig = {
fontSize: "large-font", fontSize: "large-font",
fontStyle: "sans-serif", fontStyle: "sans-serif",
}; };
export const ACCEPTED_FILE_MIME_TYPES = ["image/jpeg", "image/jpg", "image/png", "image/webp", "image/gif"];
export const ACCEPTED_FILE_EXTENSIONS = ACCEPTED_FILE_MIME_TYPES.map((type) => `.${type.split("/")[1]}`);

View file

@ -2,6 +2,8 @@ import { ChangeEvent, useCallback, useEffect, useMemo, useRef } from "react";
import { ImageIcon } from "lucide-react"; import { ImageIcon } from "lucide-react";
// plane utils // plane utils
import { cn } from "@plane/utils"; import { cn } from "@plane/utils";
// constants
import { ACCEPTED_FILE_EXTENSIONS } from "@/constants/config";
// hooks // hooks
import { useUploader, useDropZone, uploadFirstImageAndInsertRemaining } from "@/hooks/use-file-upload"; import { useUploader, useDropZone, uploadFirstImageAndInsertRemaining } from "@/hooks/use-file-upload";
// extensions // extensions
@ -166,7 +168,7 @@ export const CustomImageUploader = (props: CustomImageUploaderProps) => {
ref={fileInputRef} ref={fileInputRef}
hidden hidden
type="file" type="file"
accept=".jpg,.jpeg,.png,.webp" accept={ACCEPTED_FILE_EXTENSIONS.join(",")}
onChange={onFileChange} onChange={onFileChange}
multiple multiple
/> />

View file

@ -1,3 +1,6 @@
// constants
import { ACCEPTED_FILE_MIME_TYPES } from "@/constants/config";
type TArgs = { type TArgs = {
file: File; file: File;
maxFileSize: number; maxFileSize: number;
@ -11,9 +14,8 @@ export const isFileValid = (args: TArgs): boolean => {
return false; return false;
} }
const allowedTypes = ["image/jpeg", "image/jpg", "image/png", "image/webp"]; if (!ACCEPTED_FILE_MIME_TYPES.includes(file.type)) {
if (!allowedTypes.includes(file.type)) { alert("Invalid file type. Please select a JPEG, JPG, PNG, WEBP or GIF file.");
alert("Invalid file type. Please select a JPEG, JPG, PNG, or WEBP image file.");
return false; return false;
} }