api

package
v1.13.1-3 Latest Latest
Warning

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

Go to latest
Published: May 1, 2025 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClusterDisconnected = iota
	ClusterConnecting
	ClusterDisabled
	ClusterEnabling
	ClusterEnabled
)
View Source
const (
	RealAddrCtxKey       = "handle.real.addr"
	RealPathCtxKey       = "handle.real.path"
	AccessLogExtraCtxKey = "handle.access.extra"
)

Variables

View Source
var (
	ErrStopIter = errors.New("stop iteration")
	ErrNotFound = errors.New("Item not found")
	ErrExist    = errors.New("Item is already exist")
)
View Source
var ErrPreconditionFailed = errors.New("Precondition Failed")

Functions

func GetRequestRealAddr

func GetRequestRealAddr(req *http.Request) string

func GetRequestRealPath

func GetRequestRealPath(req *http.Request) string

func SetAccessInfo

func SetAccessInfo(req *http.Request, key string, value any)

Types

type AccessStatData

type AccessStatData struct {
	Date statTime `json:"date"`
	AccessStatHistoryData
	Prev  AccessStatHistoryData   `json:"prev"`
	Years map[string]StatInstData `json:"years"`

	Accesses map[string]int `json:"accesses"`
}

func NewAccessStatData

func NewAccessStatData() *AccessStatData

func (*AccessStatData) Clone

func (d *AccessStatData) Clone() *AccessStatData

func (*AccessStatData) Update

func (d *AccessStatData) Update(newData *StatInstData)

type AccessStatHistoryData

type AccessStatHistoryData struct {
	Hours  StatDataHours  `json:"hours"`
	Days   StatDataDays   `json:"days"`
	Months StatDataMonths `json:"months"`
}

type Cluster

type Cluster interface {
	Name() string
	ID() string
	Secret() string
	Host() string
	Port() uint16
	PublicHosts() []string
	Options() *config.ClusterOptions

	Status() ClusterStatus
	Connect(context.Context) error
	Disconnect(context.Context) error
	Enable(context.Context) error
	Disable(context.Context) error

	GetFileList(ctx context.Context, fileMap map[string]*StorageFileInfo, forceAll bool) error
	ReportDownload(ctx context.Context, response *http.Response, err error) error
}

type ClusterManager

type ClusterManager interface {
	GetClusters() []Cluster
	GetCluster(name string) Cluster
	AddCluster(name string, opts *config.ClusterOptions) error
	UpdateCluster(name string, opts *config.ClusterOptions) error
	RemoveCluster(name string) bool
}

type ClusterStatus

type ClusterStatus int32

func (ClusterStatus) Connected

func (s ClusterStatus) Connected() bool

Connected returns true if the cluster is connected to the central server

func (ClusterStatus) Disconnected

func (s ClusterStatus) Disconnected() bool

Disconnected returns true if the cluster is disconnected from the central server

func (ClusterStatus) Enabled

func (s ClusterStatus) Enabled() bool

Enabled returns true if the cluster is enabled or enabling

func (ClusterStatus) Running

func (s ClusterStatus) Running() bool

Running returns true if the cluster is completely enabled

type ConfigHandler

type ConfigHandler interface {
	GetConfig() *config.Config

	MarshalJSON() (data []byte, err error)
	UnmarshalJSON(data []byte) error
	UnmarshalYAML(data []byte) error
	MarshalJSONPath(path string) (data []byte, err error)
	UnmarshalJSONPath(path string, data []byte) error

	DoReadLockedAction(callback func(ConfigHandler) error) error
	DoWriteLockedAction(callback func(ConfigHandler) error) error
}

type EmailSubscriptionRecord

type EmailSubscriptionRecord struct {
	User    string             `json:"user"`
	Addr    string             `json:"addr"`
	Scopes  NotificationScopes `json:"scopes"`
	Enabled bool               `json:"enabled"`
}

type NotificationScopes

type NotificationScopes struct {
	Disabled    bool `json:"disabled"`
	Enabled     bool `json:"enabled"`
	SyncBegin   bool `json:"syncbegin"`
	SyncDone    bool `json:"syncdone"`
	Updates     bool `json:"updates"`
	DailyReport bool `json:"dailyreport"`
}

func (*NotificationScopes) FromInt64

func (ns *NotificationScopes) FromInt64(v int64)

func (*NotificationScopes) FromStrings

func (ns *NotificationScopes) FromStrings(scopes []string)

func (*NotificationScopes) Scan

func (ns *NotificationScopes) Scan(src any) error

func (NotificationScopes) ToInt64

func (ns NotificationScopes) ToInt64() (v int64)

func (*NotificationScopes) UnmarshalJSON

func (ns *NotificationScopes) UnmarshalJSON(data []byte) (err error)

func (NotificationScopes) Value

func (ns NotificationScopes) Value() (driver.Value, error)

type PermissionFlag

type PermissionFlag uint32
const (
	// BasicPerm includes majority client side actions, such as login, which do not have a significant impact on the server
	BasicPerm PermissionFlag = 1 << iota
	// SubscribePerm allows the user to subscribe server status & other posts
	SubscribePerm
	// LogPerm allows the user to view non-debug logs & download access logs
	LogPerm
	// DebugPerm allows the user to access debug settings & download debug logs
	DebugPerm
	// FullConfigPerm allows the user to access all config values
	FullConfigPerm
	// ClusterPerm allows the user to configure clusters' settings & stop/start clusters
	ClusterPerm
	// StoragePerm allows the user to configure storages' settings & decides to manually start storages' sync process
	StoragePerm
	// BypassLimitPerm allows the user to ignore API access limit
	BypassLimitPerm
	// RootPerm user can add/remove users, reset their password, and change their permission flags
	RootPerm PermissionFlag = 1 << 31

	AllPerm = ^(PermissionFlag)(0)
)

type RequestPath

type RequestPath struct {
	*http.Request
	Cluster Cluster
	Path    string
}

type Schedule

type Schedule struct {
	Hour   int
	Minute int
}

func (*Schedule) MarshalJSON

func (s *Schedule) MarshalJSON() (buf []byte, err error)

func (Schedule) ReadySince

func (s Schedule) ReadySince(last, now time.Time) bool

func (*Schedule) Scan

func (s *Schedule) Scan(src any) error

func (Schedule) String

func (s Schedule) String() string

func (*Schedule) UnmarshalJSON

func (s *Schedule) UnmarshalJSON(buf []byte) (err error)

func (*Schedule) UnmarshalText

func (s *Schedule) UnmarshalText(buf []byte) (err error)

func (Schedule) Value

func (s Schedule) Value() (driver.Value, error)

type StatDataDays

type StatDataDays = [31]StatInstData

type StatDataHours

type StatDataHours = [24]StatInstData

type StatDataMonths

type StatDataMonths = [12]StatInstData

type StatInstData

type StatInstData struct {
	Hits  int32 `json:"hits"`
	Bytes int64 `json:"bytes"`
}

type StatsManager

type StatsManager interface {
	GetStatus() StatusData
	// returns a cluster's stat data
	// if name is empty then gets the overall access data
	GetClusterAccessStat(name string) *AccessStatData
	// returns a storage's stat data
	// if name is empty then gets the overall access data
	GetStorageAccessStat(name string) *AccessStatData
}

type StatusData

type StatusData struct {
	StartAt  time.Time `json:"startAt"`
	Clusters []string  `json:"clusters"`
	Storages []string  `json:"storages"`
}

type StorageFileInfo

type StorageFileInfo struct {
	Hash     string
	Size     int64
	Storages []storage.Storage
	URLs     map[string]RequestPath
}

type SubscribeRecord

type SubscribeRecord struct {
	User       string              `json:"user"`
	Client     string              `json:"client"`
	EndPoint   string              `json:"endpoint"`
	Keys       SubscribeRecordKeys `json:"keys"`
	Scopes     NotificationScopes  `json:"scopes"`
	ReportAt   Schedule            `json:"report_at"`
	LastReport sql.NullTime        `json:"-"`
}

type SubscribeRecordKeys

type SubscribeRecordKeys struct {
	Auth   string `json:"auth"`
	P256dh string `json:"p256dh"`
}

func (*SubscribeRecordKeys) Scan

func (sk *SubscribeRecordKeys) Scan(src any) error

func (SubscribeRecordKeys) Value

func (sk SubscribeRecordKeys) Value() (driver.Value, error)

type SubscriptionManager

type SubscriptionManager interface {
	GetWebPushKey() string

	GetSubscribe(user string, client string) (*SubscribeRecord, error)
	SetSubscribe(SubscribeRecord) error
	RemoveSubscribe(user string, client string) error
	ForEachSubscribe(cb func(*SubscribeRecord) error) error

	GetEmailSubscription(user string, addr string) (*EmailSubscriptionRecord, error)
	AddEmailSubscription(EmailSubscriptionRecord) error
	UpdateEmailSubscription(EmailSubscriptionRecord) error
	RemoveEmailSubscription(user string, addr string) error
	ForEachEmailSubscription(cb func(*EmailSubscriptionRecord) error) error
	ForEachUsersEmailSubscription(user string, cb func(*EmailSubscriptionRecord) error) error
	ForEachEnabledEmailSubscription(cb func(*EmailSubscriptionRecord) error) error

	GetWebhook(user string, id uuid.UUID) (*WebhookRecord, error)
	AddWebhook(WebhookRecord) error
	UpdateWebhook(WebhookRecord) error
	UpdateEnableWebhook(user string, id uuid.UUID, enabled bool) error
	RemoveWebhook(user string, id uuid.UUID) error
	ForEachWebhook(cb func(*WebhookRecord) error) error
	ForEachUsersWebhook(user string, cb func(*WebhookRecord) error) error
	ForEachEnabledWebhook(cb func(*WebhookRecord) error) error
}

type TokenManager

type TokenManager interface {
	TokenVerifier
	GenerateChallengeToken(clientId string, action string) (token string, err error)
	GenerateAuthToken(clientId string, userId string) (token string, err error)
	GenerateAPIToken(clientId string, userId string, path string, query map[string]string) (token string, err error)
	InvalidToken(tokenId string) error
}

type TokenVerifier

type TokenVerifier interface {
	VerifyChallengeToken(clientId string, token string, action string) (err error)
	VerifyAuthToken(clientId string, token string) (tokenId string, userId string, err error)
	VerifyAPIToken(clientId string, token string, path string, query url.Values) (userId string, err error)
}

type User

type User struct {
	Username    string
	Password    string // as sha256
	Permissions PermissionFlag
}

func (*User) HasPerm

func (u *User) HasPerm(perm PermissionFlag) bool

type UserManager

type UserManager interface {
	GetUsers() []*User
	GetUser(id string) *User
	AddUser(*User) error
	RemoveUser(id string) error
	ForEachUser(cb func(*User) error) error
	UpdateUserPassword(username string, password string) error
	UpdateUserPermissions(username string, permissions PermissionFlag) error

	VerifyUserPassword(userId string, comparator func(password string) bool) error
}

type WebhookRecord

type WebhookRecord struct {
	User     string             `json:"user"`
	Id       uuid.UUID          `json:"id"`
	Name     string             `json:"name"`
	EndPoint string             `json:"endpoint"`
	Auth     *string            `json:"auth,omitempty"`
	AuthHash string             `json:"authHash,omitempty"`
	Scopes   NotificationScopes `json:"scopes"`
	Enabled  bool               `json:"enabled"`
}

func (*WebhookRecord) CovertAuthHash

func (rec *WebhookRecord) CovertAuthHash()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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