mirror of https://gitee.com/godoos/godoos.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.4 KiB
64 lines
1.4 KiB
package libs
|
|
|
|
import (
|
|
"errors"
|
|
"godocms/common"
|
|
"godocms/libs"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
)
|
|
|
|
func GetTempDir(pathname string) (string, error) {
|
|
tempDir, err := os.MkdirTemp("", pathname)
|
|
if err != nil {
|
|
log.Println("Failed to create temporary directory:", err)
|
|
return "./", err
|
|
}
|
|
|
|
log.Println("Temporary directory created:", tempDir)
|
|
return tempDir, nil
|
|
}
|
|
func getConvertDir() string {
|
|
runOsDir := common.GetRunOsDir()
|
|
return filepath.Join(runOsDir, "goconv")
|
|
}
|
|
func getRapidDir() (string, error) {
|
|
convertDir := getConvertDir()
|
|
var path string
|
|
if runtime.GOOS == "windows" {
|
|
path = filepath.Join(convertDir, "rapid", "RapidOcrOnnx.exe")
|
|
} else {
|
|
path = filepath.Join(convertDir, "rapid", "RapidOcrOnnx")
|
|
}
|
|
if libs.PathExists(path) {
|
|
return path, nil
|
|
} else {
|
|
return "", errors.New("RapidOcrOnnx not found")
|
|
}
|
|
}
|
|
|
|
func getRapidModelDir() (string, error) {
|
|
convertDir := getConvertDir()
|
|
path := filepath.Join(convertDir, "rapid", "models")
|
|
if libs.PathExists(path) {
|
|
return path, nil
|
|
} else {
|
|
return "", errors.New("RapidOcrOnnx model not found")
|
|
}
|
|
}
|
|
func getXpdfDir(exename string) (string, error) {
|
|
convertDir := getConvertDir()
|
|
var path string
|
|
if runtime.GOOS == "windows" {
|
|
path = filepath.Join(convertDir, "pdf", exename+".exe")
|
|
} else {
|
|
path = filepath.Join(convertDir, "pdf", exename)
|
|
}
|
|
if libs.PathExists(path) {
|
|
return path, nil
|
|
} else {
|
|
return "", errors.New("pdf convert exe not found")
|
|
}
|
|
}
|
|
|