From ac54ac5d2815201e337d88394eb585ddbcf2297b Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal Date: Fri, 30 May 2025 17:35:43 +0530 Subject: [PATCH] chore: asset check endpoint added --- apiserver/plane/app/urls/asset.py | 7 +++++++ apiserver/plane/app/views/__init__.py | 1 + apiserver/plane/app/views/asset/v2.py | 11 +++++++++++ packages/editor/src/core/types/config.ts | 1 + space/helpers/editor.helper.ts | 1 + web/core/hooks/editor/use-editor-config.ts | 4 ++++ web/core/services/file.service.ts | 13 +++++++++++++ 7 files changed, 38 insertions(+) diff --git a/apiserver/plane/app/urls/asset.py b/apiserver/plane/app/urls/asset.py index ec0f41b6278..77dd3d00efa 100644 --- a/apiserver/plane/app/urls/asset.py +++ b/apiserver/plane/app/urls/asset.py @@ -12,6 +12,7 @@ AssetRestoreEndpoint, ProjectAssetEndpoint, ProjectBulkAssetEndpoint, + AssetCheckEndpoint, ) @@ -81,5 +82,11 @@ path( "assets/v2/workspaces//projects///bulk/", ProjectBulkAssetEndpoint.as_view(), + name="bulk-asset-update", + ), + path( + "assets/v2/workspaces//check//", + AssetCheckEndpoint.as_view(), + name="asset-check", ), ] diff --git a/apiserver/plane/app/views/__init__.py b/apiserver/plane/app/views/__init__.py index 98dcab84fdb..55642a53358 100644 --- a/apiserver/plane/app/views/__init__.py +++ b/apiserver/plane/app/views/__init__.py @@ -106,6 +106,7 @@ AssetRestoreEndpoint, ProjectAssetEndpoint, ProjectBulkAssetEndpoint, + AssetCheckEndpoint, ) from .issue.base import ( IssueListEndpoint, diff --git a/apiserver/plane/app/views/asset/v2.py b/apiserver/plane/app/views/asset/v2.py index 46e988be297..aecba04b8c3 100644 --- a/apiserver/plane/app/views/asset/v2.py +++ b/apiserver/plane/app/views/asset/v2.py @@ -707,3 +707,14 @@ def post(self, request, slug, project_id, entity_id): pass return Response(status=status.HTTP_204_NO_CONTENT) + + +class AssetCheckEndpoint(BaseAPIView): + """Endpoint to check if an asset exists.""" + + @allow_permission([ROLE.ADMIN, ROLE.MEMBER, ROLE.GUEST], level="WORKSPACE") + def get(self, request, slug, asset_id): + asset = FileAsset.all_objects.filter( + id=asset_id, workspace__slug=slug, deleted_at__isnull=True + ).exists() + return Response({"exists": asset}, status=status.HTTP_200_OK) diff --git a/packages/editor/src/core/types/config.ts b/packages/editor/src/core/types/config.ts index b72e3dcf654..ace2220ed00 100644 --- a/packages/editor/src/core/types/config.ts +++ b/packages/editor/src/core/types/config.ts @@ -1,4 +1,5 @@ export type TReadOnlyFileHandler = { + checkIfAssetExists: (assetId: string) => Promise; getAssetSrc: (path: string) => Promise; restore: (assetSrc: string) => Promise; }; diff --git a/space/helpers/editor.helper.ts b/space/helpers/editor.helper.ts index 5126b99c7b2..cde842c7251 100644 --- a/space/helpers/editor.helper.ts +++ b/space/helpers/editor.helper.ts @@ -29,6 +29,7 @@ export const getReadOnlyEditorFileHandlers = (args: Pick true, getAssetSrc: async (path) => { if (!path) return ""; if (path?.startsWith("http")) { diff --git a/web/core/hooks/editor/use-editor-config.ts b/web/core/hooks/editor/use-editor-config.ts index 166df1d5b32..00eff17527d 100644 --- a/web/core/hooks/editor/use-editor-config.ts +++ b/web/core/hooks/editor/use-editor-config.ts @@ -29,6 +29,10 @@ export const useEditorConfig = () => { const { projectId, workspaceId, workspaceSlug } = args; return { + checkIfAssetExists: async (assetId: string) => { + const res = await fileService.checkIfAssetExists(workspaceSlug, assetId); + return res?.exists ?? false; + }, getAssetSrc: async (path) => { if (!path) return ""; if (path?.startsWith("http")) { diff --git a/web/core/services/file.service.ts b/web/core/services/file.service.ts index 2c9c82a6daa..cbf7ae59742 100644 --- a/web/core/services/file.service.ts +++ b/web/core/services/file.service.ts @@ -236,6 +236,19 @@ export class FileService extends APIService { }); } + async checkIfAssetExists( + workspaceSlug: string, + assetId: string + ): Promise<{ + exists: boolean; + }> { + return this.get(`/api/assets/v2/workspaces/${workspaceSlug}/check/${assetId}/`) + .then((response) => response?.data) + .catch((error) => { + throw error?.response?.data; + }); + } + async restoreOldEditorAsset(workspaceId: string, src: string): Promise { const assetKey = getAssetIdFromUrl(src); return this.post(`/api/workspaces/file-assets/${workspaceId}/${assetKey}/restore/`)