[WEB-5093] improvement: adds content-based MIME type detection for uploads #7925

- Refactored file upload utilities to use async functions for better handling of file metadata.
- Introduced MIME type detection using the file-type library.
- Updated file service methods to await metadata retrieval.
- Added new dependencies for file-type and updated package.json accordingly.
- Removed deprecated file handling code from utils and adjusted imports across services.
This commit is contained in:
Prateek Shourya 2025-10-09 12:22:43 +05:30 committed by GitHub
parent f2539c5051
commit 0b257c8693
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 352 additions and 82 deletions

View file

@ -1,6 +1,5 @@
// plane imports
import { API_BASE_URL } from "@plane/constants";
import { TFileMetaDataLite, TFileSignedURLResponse } from "@plane/types";
/**
* @description combine the file path with the base URL
@ -14,30 +13,6 @@ export const getFileURL = (path: string): string | undefined => {
return `${API_BASE_URL}${path}`;
};
/**
* @description from the provided signed URL response, generate a payload to be used to upload the file
* @param {TFileSignedURLResponse} signedURLResponse
* @param {File} file
* @returns {FormData} file upload request payload
*/
export const generateFileUploadPayload = (signedURLResponse: TFileSignedURLResponse, file: File): FormData => {
const formData = new FormData();
Object.entries(signedURLResponse.upload_data.fields).forEach(([key, value]) => formData.append(key, value));
formData.append("file", file);
return formData;
};
/**
* @description returns the necessary file meta data to upload a file
* @param {File} file
* @returns {TFileMetaDataLite} payload with file info
*/
export const getFileMetaDataForUpload = (file: File): TFileMetaDataLite => ({
name: file.name,
size: file.size,
type: file.type,
});
/**
* @description this function returns the assetId from the asset source
* @param {string} src