basic structure

This commit is contained in:
微凉
2021-10-26 22:28:37 +08:00
parent d68a4048da
commit fb7e67724d
25 changed files with 615 additions and 45 deletions

View File

@ -2,6 +2,7 @@ package utils
import (
"encoding/json"
"github.com/Xhofe/alist/conf"
log "github.com/sirupsen/logrus"
"io/ioutil"
"os"
@ -18,6 +19,36 @@ func Exists(name string) bool {
return true
}
// IsDir determine whether the file is dir
func IsDir(path string) bool {
s, err := os.Stat(path)
if err != nil {
return false
}
return s.IsDir()
}
// GetFileType get file type
func GetFileType(ext string) int {
if ext == "" {
return conf.UNKNOWN
}
ext = ext[1:]
if IsContain(conf.OfficeTypes,ext) {
return conf.OFFICE
}
if IsContain(conf.AudioTypes,ext) {
return conf.AUDIO
}
if IsContain(conf.VideoTypes,ext) {
return conf.VIDEO
}
if IsContain(conf.TextTypes,ext) {
return conf.TEXT
}
return conf.UNKNOWN
}
// CreatNestedFile create nested file
func CreatNestedFile(path string) (*os.File, error) {
basePath := filepath.Dir(path)

10
utils/slice.go Normal file
View File

@ -0,0 +1,10 @@
package utils
func IsContain(items []string, item string) bool {
for _, eachItem := range items {
if eachItem == item {
return true
}
}
return false
}