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:
@@ -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(() => {
|
||||
|
||||
17
web/src/utils/common/base64.ts
Normal file
17
web/src/utils/common/base64.ts
Normal 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)
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from './base64'
|
||||
export * from './color'
|
||||
export * from './common'
|
||||
export * from './icon'
|
||||
|
||||
@@ -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
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user