Skip to content

Commit

Permalink
Merge branch 'chore-private-bucket' of github.com:makeplane/plane int…
Browse files Browse the repository at this point in the history
…o chore-private-bucket
  • Loading branch information
pablohashescobar committed Oct 11, 2024
2 parents 2dda046 + f095cac commit ab14a5e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
9 changes: 7 additions & 2 deletions web/core/components/core/modals/user-image-upload-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Button, TOAST_TYPE, setToast } from "@plane/ui";
import { MAX_STATIC_FILE_SIZE } from "@/constants/common";
// helpers
import { getAssetIdFromUrl, getFileURL } from "@/helpers/file.helper";
import { checkURLValidity } from "@/helpers/string.helper";
// services
import { FileService } from "@/services/file.service";
const fileService = new FileService();
Expand Down Expand Up @@ -77,10 +78,14 @@ export const UserImageUploadModal: React.FC<Props> = observer((props) => {

const handleImageRemove = async () => {
if (!value) return;
const assetID = getAssetIdFromUrl(value);
setIsRemoving(true);
try {
await fileService.deleteUserAsset(assetID);
if (checkURLValidity(value)) {
await fileService.deleteOldUserAsset(value);
} else {
const assetId = getAssetIdFromUrl(value);
await fileService.deleteUserAsset(assetId);
}
await handleRemove();
} catch (error) {
console.log("Error in uploading user asset:", error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Button } from "@plane/ui";
import { MAX_STATIC_FILE_SIZE } from "@/constants/common";
// helpers
import { getAssetIdFromUrl, getFileURL } from "@/helpers/file.helper";
import { checkURLValidity } from "@/helpers/string.helper";
// hooks
import { useWorkspace } from "@/hooks/store";
// services
Expand Down Expand Up @@ -84,10 +85,14 @@ export const WorkspaceImageUploadModal: React.FC<Props> = observer((props) => {

const handleImageRemove = async () => {
if (!workspaceSlug || !value) return;
const assetId = getAssetIdFromUrl(value);
setIsRemoving(true);
try {
await fileService.deleteWorkspaceAsset(workspaceSlug.toString(), assetId);
if (checkURLValidity(value)) {
await fileService.deleteOldWorkspaceAsset(currentWorkspace?.id ?? "", value);
} else {
const assetId = getAssetIdFromUrl(value);
await fileService.deleteWorkspaceAsset(workspaceSlug.toString(), assetId);
}
await handleRemove();
handleClose();
} catch (error) {
Expand Down
11 changes: 10 additions & 1 deletion web/core/services/file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class FileService extends APIService {
});
}

async deleteOldEditorAsset(workspaceId: string, src: string): Promise<any> {
async deleteOldWorkspaceAsset(workspaceId: string, src: string): Promise<any> {
const assetKey = getAssetIdFromUrl(src);
return this.delete(`/api/workspaces/file-assets/${workspaceId}/${assetKey}/`)
.then((response) => response?.status)
Expand All @@ -192,6 +192,15 @@ export class FileService extends APIService {
});
}

async deleteOldUserAsset(src: string): Promise<any> {
const assetKey = getAssetIdFromUrl(src);
return this.delete(`/api/users/file-assets/${assetKey}/`)
.then((response) => response?.status)
.catch((error) => {
throw error?.response?.data;
});
}

async restoreNewAsset(workspaceSlug: string, src: string): Promise<void> {
// remove the last slash and get the asset id
const assetId = getAssetIdFromUrl(src);
Expand Down
2 changes: 1 addition & 1 deletion web/helpers/editor.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const getEditorFileHandlers = (args: TArgs): TFileHandler => {
upload: uploadFile,
delete: async (src: string) => {
if (checkURLValidity(src)) {
await fileService.deleteOldEditorAsset(workspaceId, src);
await fileService.deleteOldWorkspaceAsset(workspaceId, src);
} else {
await fileService.deleteNewAsset(
getEditorAssetSrc({
Expand Down

0 comments on commit ab14a5e

Please sign in to comment.