Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions apiserver/plane/app/urls/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
AssetRestoreEndpoint,
ProjectAssetEndpoint,
ProjectBulkAssetEndpoint,
AssetCheckEndpoint,
)


Expand Down Expand Up @@ -81,5 +82,11 @@
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",
),
]
1 change: 1 addition & 0 deletions apiserver/plane/app/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
AssetRestoreEndpoint,
ProjectAssetEndpoint,
ProjectBulkAssetEndpoint,
AssetCheckEndpoint,
)
from .issue.base import (
IssueListEndpoint,
Expand Down
11 changes: 11 additions & 0 deletions apiserver/plane/app/views/asset/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions packages/editor/src/core/types/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type TReadOnlyFileHandler = {
checkIfAssetExists: (assetId: string) => Promise<boolean>;
getAssetSrc: (path: string) => Promise<string>;
restore: (assetSrc: string) => Promise<void>;
};
Expand Down
1 change: 1 addition & 0 deletions space/helpers/editor.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
4 changes: 4 additions & 0 deletions web/core/hooks/editor/use-editor-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
13 changes: 13 additions & 0 deletions web/core/services/file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/`)
Expand Down