mirror of
https://github.com/cloudreve/frontend.git
synced 2025-12-26 04:02:47 +00:00
fix: non-ascii characters compatible in {$src_raw_base64}
This commit is contained in:
parent
2ac5263363
commit
b29ddea4f2
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
Loading…
Reference in New Issue