feat: add type to fs read api
This commit is contained in:
@ -1,12 +1,12 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/alist-org/alist/v3/internal/conf"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/conf"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -49,3 +49,24 @@ func CreateTempFile(r io.ReadCloser) (*os.File, error) {
|
||||
}
|
||||
return f, nil
|
||||
}
|
||||
|
||||
// GetFileType get file type
|
||||
func GetFileType(filename string) int {
|
||||
ext := Ext(filename)
|
||||
if SliceContains(conf.TypesMap[conf.OfficeTypes], ext) {
|
||||
return conf.OFFICE
|
||||
}
|
||||
if SliceContains(conf.TypesMap[conf.AudioTypes], ext) {
|
||||
return conf.AUDIO
|
||||
}
|
||||
if SliceContains(conf.TypesMap[conf.VideoTypes], ext) {
|
||||
return conf.VIDEO
|
||||
}
|
||||
if SliceContains(conf.TypesMap[conf.ImageTypes], ext) {
|
||||
return conf.IMAGE
|
||||
}
|
||||
if SliceContains(conf.TypesMap[conf.TextTypes], ext) {
|
||||
return conf.TEXT
|
||||
}
|
||||
return conf.UNKNOWN
|
||||
}
|
||||
|
@ -1,15 +1,16 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
|
||||
json "github.com/json-iterator/go"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
var Json = json.ConfigCompatibleWithStandardLibrary
|
||||
|
||||
// WriteToJson write struct to json file
|
||||
func WriteToJson(src string, conf interface{}) bool {
|
||||
// WriteJsonToFile write struct to json file
|
||||
func WriteJsonToFile(src string, conf interface{}) bool {
|
||||
data, err := Json.MarshalIndent(conf, "", " ")
|
||||
if err != nil {
|
||||
log.Errorf("failed convert Conf to []byte:%s", err.Error())
|
||||
|
@ -1,5 +1,6 @@
|
||||
package utils
|
||||
|
||||
// SliceEqual check if two slices are equal
|
||||
func SliceEqual[T comparable](a, b []T) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
@ -12,6 +13,7 @@ func SliceEqual[T comparable](a, b []T) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// SliceContains check if slice contains element
|
||||
func SliceContains[T comparable](arr []T, v T) bool {
|
||||
for _, vv := range arr {
|
||||
if vv == v {
|
||||
@ -21,9 +23,10 @@ func SliceContains[T comparable](arr []T, v T) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// SliceConvert convert slice to another type slice
|
||||
func SliceConvert[S any, D any](srcS []S, convert func(src S) (D, error)) ([]D, error) {
|
||||
var res []D
|
||||
for i, _ := range srcS {
|
||||
for i := range srcS {
|
||||
dst, err := convert(srcS[i])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Reference in New Issue
Block a user