update
This commit is contained in:
@@ -2,7 +2,11 @@ package backend_golang
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/cavaliergopher/grab/v3"
|
||||
)
|
||||
@@ -42,16 +46,46 @@ func (a *App) FileExists(fileName string) (bool, error) {
|
||||
return false, err
|
||||
}
|
||||
|
||||
func (a *App) FileInfo(fileName string) (any, error) {
|
||||
type FileInfo struct {
|
||||
Name string `json:"name"`
|
||||
Size int64 `json:"size"`
|
||||
IsDir bool `json:"isDir"`
|
||||
ModTime string `json:"modTime"`
|
||||
}
|
||||
|
||||
func (a *App) ReadFileInfo(fileName string) (FileInfo, error) {
|
||||
info, err := os.Stat(fileName)
|
||||
if err != nil {
|
||||
return FileInfo{}, err
|
||||
}
|
||||
return FileInfo{
|
||||
Name: info.Name(),
|
||||
Size: info.Size(),
|
||||
IsDir: info.IsDir(),
|
||||
ModTime: info.ModTime().Format(time.RFC3339),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a *App) ListDirFiles(dirPath string) ([]FileInfo, error) {
|
||||
files, err := os.ReadDir(dirPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return map[string]any{
|
||||
"name": info.Name(),
|
||||
"size": info.Size(),
|
||||
"isDir": info.IsDir(),
|
||||
}, nil
|
||||
|
||||
var filesInfo []FileInfo
|
||||
for _, file := range files {
|
||||
info, err := file.Info()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
filesInfo = append(filesInfo, FileInfo{
|
||||
Name: info.Name(),
|
||||
Size: info.Size(),
|
||||
IsDir: info.IsDir(),
|
||||
ModTime: info.ModTime().Format(time.RFC3339),
|
||||
})
|
||||
}
|
||||
return filesInfo, nil
|
||||
}
|
||||
|
||||
func (a *App) DownloadFile(path string, url string) error {
|
||||
@@ -61,3 +95,19 @@ func (a *App) DownloadFile(path string, url string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) OpenFileFolder(path string) error {
|
||||
switch os := runtime.GOOS; os {
|
||||
case "windows":
|
||||
cmd := exec.Command("explorer", "/select,", path)
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case "darwin":
|
||||
fmt.Println("Running on macOS")
|
||||
case "linux":
|
||||
fmt.Println("Running on Linux")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
)
|
||||
|
||||
func (a *App) StartServer(strategy string, modelPath string) (string, error) {
|
||||
//cmd := exec.Command(`explorer`, `/select,`, `e:\RWKV-4-Raven-7B-v10-Eng49%25-Chn50%25-Other1%25-20230420-ctx4096.pth`)
|
||||
cmd := exec.Command("cmd-helper", "python", "./backend-python/main.py", strategy, modelPath)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user