Skip to content

armgit / plane

Public Imported from GitHub
0

πŸ”₯πŸ”₯πŸ”₯ Open-source Jira, Linear, Monday, and ClickUp alternative. Plane is a modern project management platform to manage tasks, sprints, docs, and triage.

[WIKI-181] chore: asset check endpoint added #7140

Aaryan Khandelwal151fc8389e71
diff --git a/apiserver/plane/app/urls/asset.py b/apiserver/plane/app/urls/asset.py
index ec0f41b627..77dd3d00ef 100644
--- a/apiserver/plane/app/urls/asset.py
+++ b/apiserver/plane/app/urls/asset.py
@@ -12,6 +12,7 @@ from plane.app.views import (
AssetRestoreEndpoint,
ProjectAssetEndpoint,
ProjectBulkAssetEndpoint,
+ AssetCheckEndpoint,
)
@@ -81,5 +82,11 @@ urlpatterns = [
path(
"assets/v2/workspaces/<str:slug>/projects/<uuid:project_id>/<uuid:entity_id>/bulk/",
ProjectBulkAssetEndpoint.as_view(),
+ name="bulk-asset-update",
+ ),
+ path(
+ "assets/v2/workspaces/<str:slug>/check/<uuid:asset_id>/",
+ AssetCheckEndpoint.as_view(),
+ name="asset-check",
),
]
diff --git a/apiserver/plane/app/views/__init__.py b/apiserver/plane/app/views/__init__.py
index 98dcab84fd..55642a5335 100644
--- a/apiserver/plane/app/views/__init__.py
+++ b/apiserver/plane/app/views/__init__.py
@@ -106,6 +106,7 @@ from .asset.v2 import (
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 46e988be29..aecba04b8c 100644
--- a/apiserver/plane/app/views/asset/v2.py
+++ b/apiserver/plane/app/views/asset/v2.py
@@ -707,3 +707,14 @@ class ProjectBulkAssetEndpoint(BaseAPIView):
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 b72e3dcf65..ace2220ed0 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<boolean>;
getAssetSrc: (path: string) => Promise<string>;
restore: (assetSrc: string) => Promise<void>;
};
diff --git a/space/helpers/editor.helper.ts b/space/helpers/editor.helper.ts
index 5126b99c7b..cde842c725 100644
--- a/space/helpers/editor.helper.ts
+++ b/space/helpers/editor.helper.ts
@@ -29,6 +29,7 @@ export const getReadOnlyEditorFileHandlers = (args: Pick<TArgs, "anchor" | "work
const { anchor, workspaceId } = args;
return {
+ checkIfAssetExists: async () => 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 166df1d5b3..00eff17527 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 2c9c82a6da..cbf7ae5974 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<void> {
const assetKey = getAssetIdFromUrl(src);
return this.post(`/api/workspaces/file-assets/${workspaceId}/${assetKey}/restore/`)