fix: validation of public and private assets (#5878)

This commit is contained in:
M. Palanikannan 2024-10-21 15:59:44 +05:30 committed by GitHub
parent 6f8df3279c
commit c940a2921e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 11 deletions

View file

@ -248,7 +248,7 @@ export const CustomImageBlock: React.FC<CustomImageBlockProps> = (props) => {
try { try {
setHasErroredOnFirstLoad(true); setHasErroredOnFirstLoad(true);
// this is a type error from tiptap, don't remove await until it's fixed // this is a type error from tiptap, don't remove await until it's fixed
await editor?.commands.restoreImage?.(remoteImageSrc); await editor?.commands.restoreImage?.(node.attrs.src);
imageRef.current.src = remoteImageSrc; imageRef.current.src = remoteImageSrc;
} catch { } catch {
// if the image failed to even restore, then show the error state // if the image failed to even restore, then show the error state

View file

@ -4,7 +4,6 @@ import { TFileHandler } from "@plane/editor";
import { MAX_FILE_SIZE } from "@/constants/common"; import { MAX_FILE_SIZE } from "@/constants/common";
// helpers // helpers
import { getFileURL } from "@/helpers/file.helper"; import { getFileURL } from "@/helpers/file.helper";
import { checkURLValidity } from "@/helpers/string.helper";
// services // services
import { FileService } from "@/services/file.service"; import { FileService } from "@/services/file.service";
const fileService = new FileService(); const fileService = new FileService();
@ -34,7 +33,7 @@ export const getEditorFileHandlers = (args: TArgs): TFileHandler => {
return { return {
getAssetSrc: (path) => { getAssetSrc: (path) => {
if (!path) return ""; if (!path) return "";
if (checkURLValidity(path)) { if (path?.startsWith("http")) {
return path; return path;
} else { } else {
return getEditorAssetSrc(anchor, path) ?? ""; return getEditorAssetSrc(anchor, path) ?? "";
@ -42,14 +41,14 @@ export const getEditorFileHandlers = (args: TArgs): TFileHandler => {
}, },
upload: uploadFile, upload: uploadFile,
delete: async (src: string) => { delete: async (src: string) => {
if (checkURLValidity(src)) { if (src?.startsWith("http")) {
await fileService.deleteOldEditorAsset(workspaceId, src); await fileService.deleteOldEditorAsset(workspaceId, src);
} else { } else {
await fileService.deleteNewAsset(getEditorAssetSrc(anchor, src) ?? ""); await fileService.deleteNewAsset(getEditorAssetSrc(anchor, src) ?? "");
} }
}, },
restore: async (src: string) => { restore: async (src: string) => {
if (checkURLValidity(src)) { if (src?.startsWith("http")) {
await fileService.restoreOldEditorAsset(workspaceId, src); await fileService.restoreOldEditorAsset(workspaceId, src);
} else { } else {
await fileService.restoreNewAsset(anchor, src); await fileService.restoreNewAsset(anchor, src);
@ -73,7 +72,7 @@ export const getReadOnlyEditorFileHandlers = (
return { return {
getAssetSrc: (path) => { getAssetSrc: (path) => {
if (!path) return ""; if (!path) return "";
if (checkURLValidity(path)) { if (path?.startsWith("http")) {
return path; return path;
} else { } else {
return getEditorAssetSrc(anchor, path) ?? ""; return getEditorAssetSrc(anchor, path) ?? "";

View file

@ -2,7 +2,6 @@
import { TFileHandler } from "@plane/editor"; import { TFileHandler } from "@plane/editor";
// helpers // helpers
import { getBase64Image, getFileURL } from "@/helpers/file.helper"; import { getBase64Image, getFileURL } from "@/helpers/file.helper";
import { checkURLValidity } from "@/helpers/string.helper";
// services // services
import { FileService } from "@/services/file.service"; import { FileService } from "@/services/file.service";
const fileService = new FileService(); const fileService = new FileService();
@ -46,7 +45,7 @@ export const getEditorFileHandlers = (args: TArgs): TFileHandler => {
return { return {
getAssetSrc: (path) => { getAssetSrc: (path) => {
if (!path) return ""; if (!path) return "";
if (checkURLValidity(path)) { if (path?.startsWith("http")) {
return path; return path;
} else { } else {
return ( return (
@ -60,7 +59,7 @@ export const getEditorFileHandlers = (args: TArgs): TFileHandler => {
}, },
upload: uploadFile, upload: uploadFile,
delete: async (src: string) => { delete: async (src: string) => {
if (checkURLValidity(src)) { if (src?.startsWith("http")) {
await fileService.deleteOldWorkspaceAsset(workspaceId, src); await fileService.deleteOldWorkspaceAsset(workspaceId, src);
} else { } else {
await fileService.deleteNewAsset( await fileService.deleteNewAsset(
@ -73,7 +72,7 @@ export const getEditorFileHandlers = (args: TArgs): TFileHandler => {
} }
}, },
restore: async (src: string) => { restore: async (src: string) => {
if (checkURLValidity(src)) { if (src?.startsWith("http")) {
await fileService.restoreOldEditorAsset(workspaceId, src); await fileService.restoreOldEditorAsset(workspaceId, src);
} else { } else {
await fileService.restoreNewAsset(workspaceSlug, src); await fileService.restoreNewAsset(workspaceSlug, src);
@ -97,7 +96,7 @@ export const getReadOnlyEditorFileHandlers = (
return { return {
getAssetSrc: (path) => { getAssetSrc: (path) => {
if (!path) return ""; if (!path) return "";
if (checkURLValidity(path)) { if (path?.startsWith("http")) {
return path; return path;
} else { } else {
return ( return (