fix base64 encode/edcode.

This commit is contained in:
xuyue committed 2023-02-02 11:20:38 +08:00
1 parent f098c54afb
commit b84d03f52f
4 files changed
+15 -14

No files matched your search

+9 -9
View File
@@ -4,17 +4,17 @@ import { Code } from "./types"
const http = axios.create({ baseURL: "https://judge0api.hyyz.izhai.net" })
function encode(str: string) {
return btoa(unescape(encodeURIComponent(str ?? "")))
function encode(string?: string) {
return btoa(String.fromCharCode(...new TextEncoder().encode(string ?? "")))
}
function decode(bytes: string) {
let escaped = escape(atob(bytes ?? ""))
try {
return decodeURIComponent(escaped)
} catch (e) {
return unescape(escaped)
}
function decode(bytes?: string) {
const latin = atob(bytes ?? "")
return new TextDecoder("utf-8").decode(
Uint8Array.from({ length: latin.length }, (_, index) =>
latin.charCodeAt(index)
)
)
}
export async function createTestSubmission(code: Code, input: string) {