fix loading of objects at a path when url is shared opened elsewhere (#2944)

- fix loading of objects at a path when url is shared and opened elsewhere
- fix bug when a path is created and objects are uploaded it is not refreshed
This commit is contained in:
Prakash Senthil Vel
2023-07-17 21:33:31 +05:30
committed by GitHub
parent 6d81a1b1f8
commit d1069ed359
3 changed files with 34 additions and 14 deletions

View File

@@ -434,12 +434,27 @@ export const representationNumber = (number: number | undefined) => {
return `${returnValue}${unit}`;
};
/** Ref https://developer.mozilla.org/en-US/docs/Glossary/Base64 */
const base64ToBytes = (base64: any): Uint8Array => {
const binString: any = atob(base64);
// @ts-ignore
return Uint8Array.from(binString, (m) => m.codePointAt(0));
};
const bytesToBase64 = (bytes: any) => {
const binString = Array.from(bytes, (x: any) => String.fromCodePoint(x)).join(
""
);
return btoa(binString);
};
export const encodeURLString = (name: string | null) => {
if (!name) {
return "";
}
try {
return btoa(unescape(encodeURIComponent(name)));
return bytesToBase64(new TextEncoder().encode(name));
} catch (err) {
return "";
}
@@ -447,7 +462,7 @@ export const encodeURLString = (name: string | null) => {
export const decodeURLString = (text: string) => {
try {
return decodeURIComponent(escape(window.atob(text)));
return new TextDecoder().decode(base64ToBytes(text));
} catch (err) {
return text;
}

View File

@@ -291,18 +291,6 @@ const BrowserHandler = () => {
[bucketName, rewindEnabled, showDeleted, dispatch, onMessageCallBack]
);
useEffect(() => {
// when a bucket param changes, (i.e /browser/:bucketName), re-init e.g with KBar, this should not apply for resources prefixes.
const permitItems = permissionItems(bucketName, "", allowResources || []);
if (bucketName && (!permitItems || permitItems.length === 0)) {
dispatch(resetMessages());
dispatch(setLoadingRecords(true));
dispatch(setLoadingObjects(true));
initWSRequest("", new Date());
}
}, [bucketName, dispatch, initWSRequest, allowResources]);
useEffect(() => {
return () => {
const request: WebsocketRequest = {
@@ -480,6 +468,18 @@ const BrowserHandler = () => {
}
}, [bucketName, loadingLocking, dispatch, displayListObjects]);
useEffect(() => {
// when a bucket param changes, (i.e /browser/:bucketName), re-init e.g with KBar, this should not apply for resources prefixes.
const permitItems = permissionItems(bucketName, "", allowResources || []);
if (bucketName && (!permitItems || permitItems.length === 0)) {
dispatch(resetMessages());
dispatch(setLoadingRecords(true));
dispatch(setLoadingObjects(true));
initWSRequest("", new Date());
}
}, [bucketName, dispatch, initWSRequest, allowResources]);
return (
<Fragment>
{!anonymousMode && <OBHeader bucketName={bucketName} />}

View File

@@ -103,9 +103,14 @@ const CreatePathModal = ({
.filter((splitItem) => splitItem.trim() !== "")
.join("/");
if (folderPath.slice(0, 1) === "/") {
folderPath = folderPath.slice(1); //trim '/'
}
const newPath = `/browser/${bucketName}/${encodeURLString(
`${folderPath}${cleanPathURL}/`
)}`;
navigate(newPath);
onClose();
};