mirror of
https://github.com/makeplane/plane.git
synced 2025-12-24 23:59:40 +01:00
* chore: new asset duplicate endpoint added * chore: change the type in url * chore: added rate limiting for image duplication endpoint * chore: added rate limiting per asset id * chore: added throttle class * chore: added validations for entity * chore: added extra validations * chore: removed the comment * chore: reverted the frontend code * chore: added the response key * feat: handle image duplication for web * feat: custom image duplication update * fix: remove paste logic for image * fix : remove entity validation * refactor: remove entity id for duplication * feat: handle duplication in utils * feat: add asset duplication registry * chore: update the set attribute method * fix: add ref for api check * chore :remove logs * chore : add entity types types * refactor: rename duplication success status value * chore: update attribute to enums * chore: update variable name * chore: set uploading state * chore : update enum name * chore : update replace command * chore: fix retry UI * chore: remove default logic * refactor: optimize imports in custom image extension files and improve error handling in image duplication * fix:type error * Update packages/editor/src/core/extensions/custom-image/components/node-view.tsx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix: enhance asset duplication handler to ignore HTTP sources --------- Co-authored-by: NarayanBavisetti <narayan3119@gmail.com> Co-authored-by: Bavisetti Narayan <72156168+NarayanBavisetti@users.noreply.github.com> Co-authored-by: VipinDevelops <vipinchaudhary1809@gmail.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
70 lines
2.0 KiB
TypeScript
70 lines
2.0 KiB
TypeScript
// plane imports
|
|
import { MAX_FILE_SIZE } from "@plane/constants";
|
|
import type { TFileHandler } from "@plane/editor";
|
|
import { SitesFileService } from "@plane/services";
|
|
import { getFileURL } from "@plane/utils";
|
|
// services
|
|
const sitesFileService = new SitesFileService();
|
|
|
|
/**
|
|
* @description generate the file source using assetId
|
|
* @param {string} anchor
|
|
*/
|
|
export const getEditorAssetSrc = (anchor: string, assetId: string): string | undefined => {
|
|
const url = getFileURL(`/api/public/assets/v2/anchor/${anchor}/${assetId}/`);
|
|
return url;
|
|
};
|
|
|
|
type TArgs = {
|
|
anchor: string;
|
|
uploadFile: TFileHandler["upload"];
|
|
workspaceId: string;
|
|
};
|
|
|
|
/**
|
|
* @description this function returns the file handler required by the editors
|
|
* @param {TArgs} args
|
|
*/
|
|
export const getEditorFileHandlers = (args: TArgs): TFileHandler => {
|
|
const { anchor, uploadFile, workspaceId } = args;
|
|
|
|
const getAssetSrc = async (path: string) => {
|
|
if (!path) return "";
|
|
if (path?.startsWith("http")) {
|
|
return path;
|
|
} else {
|
|
return getEditorAssetSrc(anchor, path) ?? "";
|
|
}
|
|
};
|
|
|
|
return {
|
|
checkIfAssetExists: async () => true,
|
|
assetsUploadStatus: {},
|
|
getAssetDownloadSrc: getAssetSrc,
|
|
getAssetSrc: getAssetSrc,
|
|
upload: uploadFile,
|
|
delete: async (src: string) => {
|
|
if (src?.startsWith("http")) {
|
|
await sitesFileService.deleteOldEditorAsset(workspaceId, src);
|
|
} else {
|
|
await sitesFileService.deleteNewAsset(getEditorAssetSrc(anchor, src) ?? "");
|
|
}
|
|
},
|
|
cancel: sitesFileService.cancelUpload,
|
|
restore: async (src: string) => {
|
|
if (src?.startsWith("http")) {
|
|
await sitesFileService.restoreOldEditorAsset(workspaceId, src);
|
|
} else {
|
|
await sitesFileService.restoreNewAsset(anchor, src);
|
|
}
|
|
},
|
|
duplicate: async (assetId: string) =>
|
|
// Duplication is not supported for sites/space app
|
|
// Return the same assetId as a fallback
|
|
assetId,
|
|
validation: {
|
|
maxFileSize: MAX_FILE_SIZE,
|
|
},
|
|
};
|
|
};
|