This commit is contained in:
Zheng Kai
2023-03-30 16:41:44 +08:00
parent 049277f1f6
commit af429a393a
13 changed files with 155 additions and 29 deletions

View File

@@ -4,16 +4,31 @@ import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"project/config"
"project/zj"
"strings"
"github.com/zhengkai/zu"
"google.golang.org/protobuf/proto"
)
// DownloadFunc ...
type DownloadFunc func(url string) (ab []byte, err error)
// CacheName ...
func CacheName(hash [16]byte) string {
s := fmt.Sprintf(`cache/%x/%x/%x`, hash[0:2], hash[2:4], hash[4:])
os.MkdirAll(StaticFile(filepath.Dir(s)), 0755)
return s
}
// FileExists ...
func FileExists(filename string) bool {
filename = fmt.Sprintf(`%s/%s`, config.StaticDir, filename)
return zu.FileExists(filename)
}
// IsURL ...
func IsURL(s string) bool {
return strings.HasPrefix(s, `https://`) || strings.HasPrefix(s, `http://`)