mirror of
https://github.com/gosticks/plane.git
synced 2025-10-16 12:45:33 +00:00
* chore(repo): migrate to pnpm * chore(repo): cleanup pnpm integration with turbo * chore(repo): run lint * chore(repo): cleanup tsconfigs * chore: align TypeScript to 5.8.3 across monorepo; update pnpm override and catalog; pnpm install to update lockfile * chore(repo): revert logger.ts changes * fix: type errors * fix: build errors * fix: pnpm home setup in dockerfiles --------- Co-authored-by: sriramveeraghanta <veeraghanta.sriram@gmail.com> Co-authored-by: Prateek Shourya <prateekshourya29@gmail.com>
50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
import { API_BASE_URL } from "@plane/constants";
|
|
import { TFileMetaDataLite, TFileSignedURLResponse } from "@plane/types";
|
|
|
|
/**
|
|
* @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 combine the file path with the base URL
|
|
* @param {string} path
|
|
* @returns {string} final URL with the base URL
|
|
*/
|
|
export const getFileURL = (path: string): string | undefined => {
|
|
if (!path) return undefined;
|
|
const isValidURL = path.startsWith("http");
|
|
if (isValidURL) return path;
|
|
return `${API_BASE_URL}${path}`;
|
|
};
|
|
|
|
/**
|
|
* @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
|
|
* @returns {string} assetId
|
|
*/
|
|
export const getAssetIdFromUrl = (src: string): string => {
|
|
const sourcePaths = src.split("/");
|
|
const assetUrl = sourcePaths[sourcePaths.length - 1];
|
|
return assetUrl ?? "";
|
|
};
|