[WIKI-419] chore: new asset duplicate endpoint added (#7172)
* 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>
This commit is contained in:
parent
d462546055
commit
83679806fd
33 changed files with 581 additions and 55 deletions
40
packages/editor/src/ce/helpers/asset-duplication.ts
Normal file
40
packages/editor/src/ce/helpers/asset-duplication.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { v4 as uuidv4 } from "uuid";
|
||||
import { ECustomImageAttributeNames, ECustomImageStatus } from "@/extensions/custom-image/types";
|
||||
|
||||
export type AssetDuplicationContext = {
|
||||
element: Element;
|
||||
originalHtml: string;
|
||||
};
|
||||
|
||||
export type AssetDuplicationResult = {
|
||||
modifiedHtml: string;
|
||||
shouldProcess: boolean;
|
||||
};
|
||||
|
||||
export type AssetDuplicationHandler = (context: AssetDuplicationContext) => AssetDuplicationResult;
|
||||
|
||||
const imageComponentHandler: AssetDuplicationHandler = ({ element, originalHtml }) => {
|
||||
const src = element.getAttribute("src");
|
||||
|
||||
if (!src || src.startsWith("http")) {
|
||||
return { modifiedHtml: originalHtml, shouldProcess: false };
|
||||
}
|
||||
|
||||
// Capture the original HTML BEFORE making any modifications
|
||||
const originalTag = element.outerHTML;
|
||||
|
||||
// Use setAttribute to update attributes
|
||||
const newId = uuidv4();
|
||||
element.setAttribute(ECustomImageAttributeNames.STATUS, ECustomImageStatus.DUPLICATING);
|
||||
element.setAttribute(ECustomImageAttributeNames.ID, newId);
|
||||
|
||||
// Get the modified HTML AFTER the changes
|
||||
const modifiedTag = element.outerHTML;
|
||||
const modifiedHtml = originalHtml.replaceAll(originalTag, modifiedTag);
|
||||
|
||||
return { modifiedHtml, shouldProcess: true };
|
||||
};
|
||||
|
||||
export const assetDuplicationHandlers: Record<string, AssetDuplicationHandler> = {
|
||||
"image-component": imageComponentHandler,
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue