You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OneAuth/file/main.go

49 lines
1.4 KiB
Go

3 years ago
package file
import (
"github.com/veypi/OneAuth/cfg"
"github.com/veypi/OneAuth/libs/fs"
"github.com/veypi/OneBD"
"github.com/veypi/OneBD/rfc"
3 years ago
"github.com/veypi/utils"
3 years ago
"github.com/veypi/utils/log"
)
/**
* @name: main
* @author: veypi <i@veypi.com>
* @date: 2021-11-27 16:27
* @descriptionmain
**/
func Router(r OneBD.Router) {
3 years ago
// 用户私有文件
3 years ago
usrF := fs.FS{
3 years ago
RootDir: utils.PathJoin(cfg.CFG.FireDir, "usr"),
UrlRoot: utils.PathJoin(cfg.CFG.FileUrlPrefix, "usr"),
3 years ago
MountFunc: userFileChecker,
}
log.Info().Msgf("start file server on %s", cfg.CFG.Host)
r.Set("/usr/", usrF.ServeHTTP, rfc.MethodAll)
r.Set("/usr/*", usrF.ServeHTTP, rfc.MethodAll)
3 years ago
// 应用存储文件
3 years ago
appF := fs.FS{
3 years ago
RootDir: utils.PathJoin(cfg.CFG.FireDir, "app"),
UrlRoot: utils.PathJoin(cfg.CFG.FileUrlPrefix, "app"),
3 years ago
MountFunc: appFileChecker,
DisabledAlert: true,
}
r.Set("/app/:uuid/", appF.ServeHTTP, rfc.MethodAll)
3 years ago
r.Set("/app/:uuid/*prefix", appF.ServeHTTP, rfc.MethodAll)
3 years ago
r.Set("/ursapp/:id/:uuid/*prefix", nil)
3 years ago
// 公共文件 读取无需权限
pubF := fs.FS{
RootDir: utils.PathJoin(cfg.CFG.FireDir, "public"),
UrlRoot: utils.PathJoin(cfg.CFG.FileUrlPrefix, "public"),
MountFunc: pubFileChecker,
DisabledAlert: true,
}
r.Set("/public/app/:uuid/*prefix", pubF.ServeHTTP, rfc.MethodAll)
r.Set("/public/*prefix", pubF.ServeHTTP, rfc.MethodAll)
3 years ago
}