fix: run scripts path erro r from local dev and prod env
This commit is contained in:
@@ -6,14 +6,15 @@ import (
|
||||
"strconv"
|
||||
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/engigu/baihu-panel/internal/constant"
|
||||
"github.com/engigu/baihu-panel/internal/database"
|
||||
"github.com/engigu/baihu-panel/internal/models"
|
||||
"github.com/engigu/baihu-panel/internal/services"
|
||||
"github.com/engigu/baihu-panel/internal/services/tasks"
|
||||
"github.com/engigu/baihu-panel/internal/utils"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/shirou/gopsutil/v3/process"
|
||||
@@ -164,6 +165,14 @@ func (sc *SettingsController) UpdateSchedulerSettings(c *gin.Context) {
|
||||
utils.SuccessMsg(c, "保存成功")
|
||||
}
|
||||
|
||||
// GetPaths 获取系统路径信息
|
||||
func (sc *SettingsController) GetPaths(c *gin.Context) {
|
||||
absScriptsDir, _ := filepath.Abs(constant.ScriptsWorkDir)
|
||||
utils.Success(c, gin.H{
|
||||
"scripts_dir": absScriptsDir,
|
||||
})
|
||||
}
|
||||
|
||||
// GetAbout 获取关于信息
|
||||
func (sc *SettingsController) GetAbout(c *gin.Context) {
|
||||
var taskCount, logCount, envCount int64
|
||||
|
||||
@@ -182,6 +182,7 @@ func Setup(c *Controllers) *gin.Engine {
|
||||
settings.POST("/password", c.Settings.ChangePassword)
|
||||
settings.GET("/site", c.Settings.GetSiteSettings)
|
||||
settings.PUT("/site", c.Settings.UpdateSiteSettings)
|
||||
settings.GET("/paths", c.Settings.GetPaths)
|
||||
settings.GET("/scheduler", c.Settings.GetSchedulerSettings)
|
||||
settings.PUT("/scheduler", c.Settings.UpdateSchedulerSettings)
|
||||
settings.GET("/about", c.Settings.GetAbout)
|
||||
|
||||
@@ -122,6 +122,7 @@ export const api = {
|
||||
getScheduler: () => request<SchedulerSettings>('/settings/scheduler'),
|
||||
updateScheduler: (data: SchedulerSettings) =>
|
||||
request('/settings/scheduler', { method: 'PUT', body: JSON.stringify(data) }),
|
||||
getPaths: () => request<{ scripts_dir: string }>('/settings/paths'),
|
||||
getAbout: () => request<AboutInfo>('/settings/about'),
|
||||
getLoginLogs: (params?: { page?: number; page_size?: number; username?: string }) => {
|
||||
const query = new URLSearchParams()
|
||||
|
||||
@@ -44,6 +44,16 @@ const hasChanges = computed(() => fileContent.value !== originalContent.value)
|
||||
const showTerminalDialog = ref(false)
|
||||
const terminalRef = ref<InstanceType<typeof XTerminal> | null>(null)
|
||||
const runCommand = ref('')
|
||||
const scriptsDir = ref('')
|
||||
|
||||
async function fetchPaths() {
|
||||
try {
|
||||
const res = await api.settings.getPaths()
|
||||
scriptsDir.value = res.scripts_dir
|
||||
} catch {
|
||||
scriptsDir.value = PATHS.SCRIPTS_DIR
|
||||
}
|
||||
}
|
||||
|
||||
// Monaco Editor 实例引用
|
||||
const editorRef = shallowRef()
|
||||
@@ -188,10 +198,11 @@ async function runScript() {
|
||||
const cmd = runner ? `${runner} ${fileName}` : `./${fileName}`
|
||||
|
||||
// 构建完整命令
|
||||
const baseDir = scriptsDir.value || PATHS.SCRIPTS_DIR
|
||||
if (dirPath) {
|
||||
runCommand.value = `cd ${PATHS.SCRIPTS_DIR}/${dirPath} && ${cmd}`
|
||||
runCommand.value = `cd ${baseDir}/${dirPath} && ${cmd}`
|
||||
} else {
|
||||
runCommand.value = `cd ${PATHS.SCRIPTS_DIR} && ${cmd}`
|
||||
runCommand.value = `cd ${baseDir} && ${cmd}`
|
||||
}
|
||||
|
||||
showTerminalDialog.value = true
|
||||
@@ -346,7 +357,10 @@ async function initFromUrl() {
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(initFromUrl)
|
||||
onMounted(() => {
|
||||
initFromUrl()
|
||||
fetchPaths()
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
window.addEventListener('resize', handleResize)
|
||||
|
||||
Reference in New Issue
Block a user