[WIKI-181] chore: asset check endpoint added #7140
This commit is contained in:
parent
0f828fd5e0
commit
151fc8389e
7 changed files with 38 additions and 0 deletions
|
|
@ -12,6 +12,7 @@ from plane.app.views import (
|
||||||
AssetRestoreEndpoint,
|
AssetRestoreEndpoint,
|
||||||
ProjectAssetEndpoint,
|
ProjectAssetEndpoint,
|
||||||
ProjectBulkAssetEndpoint,
|
ProjectBulkAssetEndpoint,
|
||||||
|
AssetCheckEndpoint,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -81,5 +82,11 @@ urlpatterns = [
|
||||||
path(
|
path(
|
||||||
"assets/v2/workspaces/<str:slug>/projects/<uuid:project_id>/<uuid:entity_id>/bulk/",
|
"assets/v2/workspaces/<str:slug>/projects/<uuid:project_id>/<uuid:entity_id>/bulk/",
|
||||||
ProjectBulkAssetEndpoint.as_view(),
|
ProjectBulkAssetEndpoint.as_view(),
|
||||||
|
name="bulk-asset-update",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"assets/v2/workspaces/<str:slug>/check/<uuid:asset_id>/",
|
||||||
|
AssetCheckEndpoint.as_view(),
|
||||||
|
name="asset-check",
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,7 @@ from .asset.v2 import (
|
||||||
AssetRestoreEndpoint,
|
AssetRestoreEndpoint,
|
||||||
ProjectAssetEndpoint,
|
ProjectAssetEndpoint,
|
||||||
ProjectBulkAssetEndpoint,
|
ProjectBulkAssetEndpoint,
|
||||||
|
AssetCheckEndpoint,
|
||||||
)
|
)
|
||||||
from .issue.base import (
|
from .issue.base import (
|
||||||
IssueListEndpoint,
|
IssueListEndpoint,
|
||||||
|
|
|
||||||
|
|
@ -707,3 +707,14 @@ class ProjectBulkAssetEndpoint(BaseAPIView):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
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,4 +1,5 @@
|
||||||
export type TReadOnlyFileHandler = {
|
export type TReadOnlyFileHandler = {
|
||||||
|
checkIfAssetExists: (assetId: string) => Promise<boolean>;
|
||||||
getAssetSrc: (path: string) => Promise<string>;
|
getAssetSrc: (path: string) => Promise<string>;
|
||||||
restore: (assetSrc: string) => Promise<void>;
|
restore: (assetSrc: string) => Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ export const getReadOnlyEditorFileHandlers = (args: Pick<TArgs, "anchor" | "work
|
||||||
const { anchor, workspaceId } = args;
|
const { anchor, workspaceId } = args;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
checkIfAssetExists: async () => true,
|
||||||
getAssetSrc: async (path) => {
|
getAssetSrc: async (path) => {
|
||||||
if (!path) return "";
|
if (!path) return "";
|
||||||
if (path?.startsWith("http")) {
|
if (path?.startsWith("http")) {
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,10 @@ export const useEditorConfig = () => {
|
||||||
const { projectId, workspaceId, workspaceSlug } = args;
|
const { projectId, workspaceId, workspaceSlug } = args;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
checkIfAssetExists: async (assetId: string) => {
|
||||||
|
const res = await fileService.checkIfAssetExists(workspaceSlug, assetId);
|
||||||
|
return res?.exists ?? false;
|
||||||
|
},
|
||||||
getAssetSrc: async (path) => {
|
getAssetSrc: async (path) => {
|
||||||
if (!path) return "";
|
if (!path) return "";
|
||||||
if (path?.startsWith("http")) {
|
if (path?.startsWith("http")) {
|
||||||
|
|
|
||||||
|
|
@ -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> {
|
async restoreOldEditorAsset(workspaceId: string, src: string): Promise<void> {
|
||||||
const assetKey = getAssetIdFromUrl(src);
|
const assetKey = getAssetIdFromUrl(src);
|
||||||
return this.post(`/api/workspaces/file-assets/${workspaceId}/${assetKey}/restore/`)
|
return this.post(`/api/workspaces/file-assets/${workspaceId}/${assetKey}/restore/`)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue