2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 12:40:25 +08:00

fix: base64 decode

This commit is contained in:
耗子
2024-11-28 20:45:22 +08:00
parent 1dc0042507
commit fec09652b7
4 changed files with 22 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
<script setup lang="ts">
import file from '@/api/panel/file'
import { decodeBase64 } from '@/utils'
import { languageByPath } from '@/utils/file'
import Editor from '@guolao/vue-monaco-editor'
@@ -21,7 +22,7 @@ const get = async () => {
await file
.content(props.path)
.then((res) => {
data.value = atob(res.data.content)
data.value = decodeBase64(res.data.content)
window.$message.success('获取成功')
})
.catch(() => {

View File

@@ -0,0 +1,17 @@
export function decodeBase64(base64: string): string {
const binary = atob(base64)
const bytes = new Uint8Array(binary.length)
for (let i = 0; i < binary.length; i++) {
bytes[i] = binary.charCodeAt(i)
}
return new TextDecoder('utf-8').decode(bytes)
}
export function encodeBase64(str: string): string {
const bytes = new TextEncoder().encode(str)
let binary = ''
for (let i = 0; i < bytes.length; i++) {
binary += String.fromCharCode(bytes[i])
}
return btoa(binary)
}

View File

@@ -1,3 +1,4 @@
export * from './base64'
export * from './color'
export * from './common'
export * from './icon'

View File

@@ -7,7 +7,7 @@ import { NButton, NDataTable, NInput, NPopconfirm, NSwitch, NTag } from 'naive-u
import cron from '@/api/panel/cron'
import file from '@/api/panel/file'
import { formatDateTime, renderIcon } from '@/utils'
import { decodeBase64, formatDateTime, renderIcon } from '@/utils'
import type { CronTask } from '@/views/task/types'
import { CronNaive } from '@vue-js-cron/naive-ui'
@@ -209,7 +209,7 @@ const handleEdit = async (row: any) => {
editTask.value.id = row.id
editTask.value.name = row.name
editTask.value.time = row.time
editTask.value.script = atob(res.data.content)
editTask.value.script = decodeBase64(res.data.content)
editModal.value = true
})
})