diff --git a/src/redux/thunks/viewer.ts b/src/redux/thunks/viewer.ts index 50de8dc..6cac49c 100644 --- a/src/redux/thunks/viewer.ts +++ b/src/redux/thunks/viewer.ts @@ -34,6 +34,7 @@ import { Viewers, ViewersByID } from "../siteConfigSlice.ts"; import { AppThunk } from "../store.ts"; import { askSaveAs, askStaleVersionAction } from "./dialog.ts"; import { longRunningTaskWithSnackbar, refreshSingleFileSymbolicLinks } from "./file.ts"; +import { base64Encode } from "../../util/base64.ts"; export interface ExpandedViewerSetting { [key: string]: Viewer[]; @@ -273,7 +274,7 @@ export function openCustomViewer(file: FileResponse, viewer: Viewer, preferredVe const vars: { [key: string]: string } = { src: encodeURIComponent(entityUrl.urls[0].url), src_raw: entityUrl.urls[0].url, - src_raw_base64: btoa(entityUrl.urls[0].url), + src_raw_base64: base64Encode(entityUrl.urls[0].url), name: encodeURIComponent(file.name), version: preferredVersion ? preferredVersion : "", id: file.id, diff --git a/src/util/base64.ts b/src/util/base64.ts new file mode 100644 index 0000000..d833870 --- /dev/null +++ b/src/util/base64.ts @@ -0,0 +1,13 @@ +export function base64Encode(data: string | Uint8Array): string { + const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data; + const binary = Array.from(bytes, (b) => String.fromCharCode(b)).join(""); + return btoa(binary); +} + +export function base64Decode(data: string): Uint8Array { + return Uint8Array.from(atob(data), (c) => c.charCodeAt(0)); +} + +export function base64DecodeToString(data: string): string { + return new TextDecoder().decode(base64Decode(data)); +}