common

package
v4.2.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: AGPL-3.0 Imports: 30 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFailedLdapAuth = errors.New("failed to auth")
View Source
var SecretKey []byte

Functions

func CanAccess

func CanAccess(user *model.User, meta *model.Meta, reqPath string, password string) bool

func CanRead added in v4.2.0

func CanRead(user *model.User, meta *model.Meta, path string) bool

func CanWrite

func CanWrite(user *model.User, meta *model.Meta, path string) bool

func CanWriteContentBypassUserPerms added in v4.2.0

func CanWriteContentBypassUserPerms(meta *model.Meta, path string) bool

func ContentWithValues added in v4.2.2

func ContentWithValues(ctx context.Context, keyAndValue ...any) context.Context

func ErrorPage added in v4.1.2

func ErrorPage(c *gin.Context, err error, code int, l ...bool)

ErrorPage is used to return error page HTML. It also returns standard HTTP status code. @param l: if true, log error

func ErrorResp

func ErrorResp(c *gin.Context, err error, code int, l ...bool)

ErrorResp is used to return error response @param l: if true, log error

func ErrorStrResp

func ErrorStrResp(c *gin.Context, str string, code int, l ...bool)

func ErrorWithDataResp

func ErrorWithDataResp(c *gin.Context, err error, code int, data interface{}, l ...bool)

func GenerateDownProxyURL added in v4.0.9

func GenerateDownProxyURL(storage *model.Storage, reqPath string) string

func GenerateToken

func GenerateToken(user *model.User) (tokenString string, err error)

func GetApiUrl

func GetApiUrl(ctx context.Context) string

func GetApiUrlFromRequest added in v4.0.9

func GetApiUrlFromRequest(r *http.Request) string

func GetEtag

func GetEtag(file model.Obj, size int64) string

func GetPlaybackBase added in v4.2.10

func GetPlaybackBase(r *http.Request) string

GetPlaybackBase 返回要拼进「返回给前端的播放地址」的站点前缀。

与 GetApiUrlFromRequest 的区别只在一种场景:站点没有显式配置 SiteURL, 且请求 Host 是回环地址(127.0.0.1 / localhost / ::1)。这时返回空串, 让调用方生成相对路径(/d/... 、/p/...),由浏览器按当前页面的 origin 解析。 否则播放器会拿到 http://127.0.0.1:5244/...,在反向代理、容器映射端口或 其它设备访问时都会指向错误的主机。

func GinAppendValues added in v4.2.2

func GinAppendValues(c *gin.Context, keyAndValue ...any)

GinAppendValues 向当前请求上下文追加键值,提供类似 gin.Context Set/Get 的可变语义。 同一请求内,已持有的上下文引用会同步看到后续更新。

func HandleLdapLogin added in v4.1.9

func HandleLdapLogin(username, password string) error

func InvalidateToken

func InvalidateToken(tokenString string) error

func IsStorageSignEnabled

func IsStorageSignEnabled(rawPath string) bool

func IsTokenInvalidated

func IsTokenInvalidated(tokenString string) bool

func LdapRegister added in v4.1.9

func LdapRegister(username string) (*model.User, error)

func MetaCoversPath added in v4.2.0

func MetaCoversPath(metaPath, reqPath string, applyToSubFolder bool) bool

func Pluralize

func Pluralize(count int, singular, plural string) string

func Proxy

func Proxy(w http.ResponseWriter, r *http.Request, link *model.Link, file model.Obj) error

func ProxyRange

func ProxyRange(ctx context.Context, link *model.Link, size int64) *model.Link

func ShouldProxy

func ShouldProxy(storage driver.Driver, filename string) bool

ShouldProxy TODO need optimize when should be proxy? 1. config.MustProxy() 2. storage.WebProxy 3. proxy_types

func Sign

func Sign(obj model.Obj, parent string, encrypt bool) string

func SuccessResp

func SuccessResp(c *gin.Context, data ...interface{})

func SuccessWithMsgResp

func SuccessWithMsgResp(c *gin.Context, msg string, data ...interface{})

Types

type InterceptResponseWriter

type InterceptResponseWriter struct {
	http.ResponseWriter
	io.Writer
}

func (*InterceptResponseWriter) Write

func (iw *InterceptResponseWriter) Write(p []byte) (int, error)

type PageResp

type PageResp struct {
	Content interface{} `json:"content"`
	Total   int64       `json:"total"`
}

type Resp

type Resp[T any] struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    T      `json:"data"`
}

type UserClaims

type UserClaims struct {
	Username string `json:"username"`
	PwdTS    int64  `json:"pwd_ts"`
	jwt.RegisteredClaims
}

func ParseToken

func ParseToken(tokenString string) (*UserClaims, error)

type WrittenResponseWriter

type WrittenResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func (*WrittenResponseWriter) IsWritten

func (ww *WrittenResponseWriter) IsWritten() bool

func (*WrittenResponseWriter) Write

func (ww *WrittenResponseWriter) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL