server

package
v0.0.0-...-aa40251 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRedisAddr     = "localhost:6379"
	DefaultRedisPassword = ""
)
View Source
const (
	DefaultRootDirName     = "root"
	InvalidDirName         = "Invalid dir name"
	DirExists              = "Dir is exists"
	DisableRootDirCreation = "Root dir creation is not allowed"
	DisableRootDirRenaming = "Root dir renaming is not allowed"
	DisableRootDirDeletion = "Disable root dir deletion"
)
View Source
const (
	InternalServerError = "InternalServerError"
	NoPermission        = "no permission"
)
View Source
const (
	DirAlreadyLinked = "dir already linked"
	DirNotLinked     = "dir not linked"
)
View Source
const (
	UsernameAlreadyExists      = "Username already exists"
	UserDoesNotExist           = "User does not exist"
	PasswordVerificationFailed = "Password verification failed"
)
View Source
const (
	NoAuthorizationHeader      = "no authorization header"
	TokenAuthenticationFailure = "token authentication failure"
	TokenInvalid               = "invalid authorization"
	Unauthorized               = "unauthorized"
)
View Source
const (
	ContextUserIDKEY   = "UserID"
	ContextDeviceIDKEY = "DeviceID"
)
View Source
const (
	DeviceNotFound = "device not found"
)

Variables

This section is empty.

Functions

func CreateRootDirIfNot

func CreateRootDirIfNot(ctx *gin.Context, client *ent.Client) (*ent.Dirs, error)

func ErrorBadRequest

func ErrorBadRequest(c *gin.Context, message string)

func ErrorConflict

func ErrorConflict(c *gin.Context, message string)

func ErrorInternalServerError

func ErrorInternalServerError(c *gin.Context)

func ErrorJSONResponse

func ErrorJSONResponse(c *gin.Context, status int, message string)

func ErrorNoPermission

func ErrorNoPermission(c *gin.Context, message string)

func ErrorNotFound

func ErrorNotFound(c *gin.Context, message string)

func ErrorUnauthorized

func ErrorUnauthorized(c *gin.Context, message string)

func GetDeviceID

func GetDeviceID(ctx *gin.Context) string

func GetUserID

func GetUserID(ctx *gin.Context) uint64

func IPFSAddr

func IPFSAddr() string

func JWTIssues

func JWTIssues() string

func JWTSecret

func JWTSecret() string

func QueryFileByHash

func QueryFileByHash(ctx *gin.Context, client *ent.Client, hash string) (*ent.Files, error)

func QueryUserDirByID

func QueryUserDirByID(ctx *gin.Context, client *ent.Client, id uint64) (*ent.Dirs, error)

func QueryUserSavedByFileID

func QueryUserSavedByFileID(ctx *gin.Context, client *ent.Client, id uint64) (*ent.Saves, error)

func RedisAddr

func RedisAddr() string

func RedisPassword

func RedisPassword() string

func Success

func Success(c *gin.Context, resp any)

Types

type AddFileResponse

type AddFileResponse struct {
	Name string `json:"name"`
	Hash string `json:"hash"`
	Size string `json:"size"`
}

type AddSavedForm

type AddSavedForm struct {
	Hash    string `form:"hash" json:"hash" binding:"required"`
	Name    string `form:"name" json:"name" binding:"required"`
	Size    string `form:"size" json:"size" binding:"required"`
	Caption string `form:"caption" json:"caption" binding:"max=999"`
}

type Client

type Client interface {
	Post(path string) (*resty.Response, error)
}

type CreateSavesQuery

type CreateSavesQuery struct {
	DirID uint64 `form:"dir_id" json:"dir_id" binding:"numeric"`
}

type CreateUserForm

type CreateUserForm struct {
	Username string `form:"username" json:"username" binding:"required,min=4,max=32"`
	Password string `form:"password" json:"password" binding:"required,min=6,max=32"`
}

CreateUserForm create user form.

type DelSavedParams

type DelSavedParams struct {
	ID uint64 `uri:"id" binding:"numeric,required"`
}

type Device

type Device struct {
	ID         string    `json:"id"`
	CreateTime time.Time `json:"create_time"`
	UpdateTime time.Time `json:"update_time"`
	IP         string    `json:"ip"`
	Device     string    `json:"device"`
}

type DevicesServer

type DevicesServer interface {
	GetDevices() error

	DeleteDevice() error
}

type Dir

type Dir struct {
	ID         string    `json:"id"`
	CreateTime time.Time `json:"create_time"`
	UpdateTime time.Time `json:"update_time"`
	Name       string    `json:"name"`
	Subdirs    []*Subdir `json:"subdirs"`
	Saves      []*Saved  `json:"saves"`
}

type DirServer

type DirServer interface {
	ListDir() error

	ListDirs() error

	RenameDir() error

	MVDir() error

	RMDir() error
}

type EditSavedParams

type EditSavedParams struct {
	ID uint64 `form:"id" json:"id" binding:"numeric"`
}

type ErrorResponse

type ErrorResponse struct {
	Code  int    `json:"code"`
	Error string `json:"error"`
}

type File

type File struct {
	ID   string `json:"id"`
	Hash string `json:"hash"`
	Name string `json:"name"`
	Size string `json:"size"`
}

type GetSavedParams

type GetSavedParams struct {
	ID uint64 `form:"id" json:"id" binding:"numeric"`
}

type IPFSServer

type IPFSServer interface {
	IPFSAddFiles() error
}

type LinkDirForm

type LinkDirForm struct {
	DirID uint64 `form:"dir_id" json:"dir_id" binding:"numeric"`
}

type LinkDirParams

type LinkDirParams struct {
	ID uint64 `form:"id" json:"id" binding:"numeric"`
}

type ListDirQuery

type ListDirQuery struct {
	DirID uint64 `form:"dir_id" binding:"numeric"`
}

type Localhost

type Localhost struct {
	BaseURL string
}

func (*Localhost) Post

func (l *Localhost) Post(path string) (*resty.Response, error)

type LoginForm

type LoginForm struct {
	Username string `form:"username" json:"username" binding:"required,min=4,max=32"`
	Password string `form:"password" json:"password" binding:"required,min=6,max=32"`
}

LoginForm login form.

type MKDirForm

type MKDirForm struct {
	Name string `form:"name" json:"name" binding:"required,min=1,max=225"`
}

type MKDirQuery

type MKDirQuery struct {
	DirID uint64 `form:"dir_id" binding:"numeric"`
}

type MVDirParams

type MVDirParams struct {
	ID    uint64 `uri:"id" binding:"required,numeric"`
	NewID uint64 `uri:"new_id" binding:"required,numeric"`
}

type RMDirParams

type RMDirParams struct {
	ID uint64 `uri:"id" binding:"required,numeric"`
}

type RenameDirParams

type RenameDirParams struct {
	ID uint64 `uri:"id" binding:"required,numeric"`
}

type Saved

type Saved struct {
	ID         string    `json:"id"`
	CreateTime time.Time `json:"create_time"`
	UpdateTime time.Time `json:"update_time"`
	Name       string    `json:"name"`
	Caption    string    `json:"caption"`
	File       *File     `json:"file"`
}

func FMTSaved

func FMTSaved(saved *ent.Saves) *Saved

type SavedServer

type SavedServer interface {
	AddSaves() error

	GetSaves() error

	GetSaved() error

	EditSaved() error

	DelSaved() error

	LinkDir() error

	UnlinkDir() error
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(ctx *gin.Context, client *ent.Client) *Server

func (*Server) CreateSaves

func (s *Server) CreateSaves() error

func (*Server) CreateUser

func (s *Server) CreateUser() error

func (*Server) DelSaved

func (s *Server) DelSaved() error

func (*Server) DeleteDevice

func (s *Server) DeleteDevice() error

func (*Server) EditSaved

func (s *Server) EditSaved() error

func (*Server) GetDevices

func (s *Server) GetDevices() error

func (*Server) GetSaved

func (s *Server) GetSaved() error

func (*Server) GetSaves

func (s *Server) GetSaves() error

func (*Server) IPFSAddFiles

func (s *Server) IPFSAddFiles() error

func (*Server) LinkDir

func (s *Server) LinkDir() error

func (*Server) ListDir

func (s *Server) ListDir() error

func (*Server) ListDirs

func (s *Server) ListDirs() error

func (*Server) Login

func (s *Server) Login() error

func (*Server) MKDir

func (s *Server) MKDir() error

func (*Server) MVDir

func (s *Server) MVDir() error

func (*Server) RMDir

func (s *Server) RMDir() error

func (*Server) RenameDir

func (s *Server) RenameDir() error

func (*Server) UnlinkDir

func (s *Server) UnlinkDir() error

func (*Server) ValidateJWT

func (s *Server) ValidateJWT() error

type Subdir

type Subdir struct {
	ID         string    `json:"id"`
	CreateTime time.Time `json:"create_time"`
	UpdateTime time.Time `json:"update_time"`
	Name       string    `json:"name"`
}

type UnlinkDirParams

type UnlinkDirParams struct {
	ID uint64 `uri:"id" binding:"numeric,required"`
}

type UsersServer

type UsersServer interface {
	// Login is a function that handles user authentication.
	//
	// It does not take any parameters.
	// It returns an error if there is an issue with the authentication process.
	Login() error

	// CreateUser creates a user.
	//
	// It returns an error if there was a problem creating the user.
	CreateUser() error
}

type Web3Storage

type Web3Storage struct {
	BaseURL string
}

func (*Web3Storage) Post

func (w *Web3Storage) Post(path string) (*resty.Response, error)

Jump to

Keyboard shortcuts

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