model

package
v1.6.5 Latest Latest
Warning

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

Go to latest
Published: May 17, 2022 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DirTypeSys = iota + 1
	DirTypeUser
	DirFileMaxNum = 65534
)
View Source
const (
	OptSite  = "core.site"
	OptEmail = "core.email"
)
View Source
const (
	StorageModeNetDisk = iota + 1
	StorageModeOutline
)
View Source
const (
	StorageStatusEnabled = iota + 1
	StorageStatusDisabled
)
View Source
const (
	RoleAdmin  = "admin"
	RoleMember = "member"
	RoleGuest  = "guest"
)
View Source
const (
	StatusInactivated = iota
	StatusActivated
	StatusDisabled
)
View Source
const (
	UserStorageDefaultSize = 50 << 20
	UserStorageActiveSize  = 1024 << 20
)

Variables

View Source
var (
	DefaultSiteOpts  = Opts{"name": "ZPan", "intro": "您的私有网盘专家", "locale": "zh-CN", "invite_required": true}
	DefaultEmailOpts = Opts{"address": "smtpdm.aliyun.com:25", "username": "no-reply@saltbo.fun", "password": "yourpassword", "sender": "ZPan"}
)
View Source
var DocTypes = []string{
	"text/csv",
	"application/msword",
	"application/vnd.ms-excel",
	"application/vnd.ms-powerpoint",
	"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
	"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
	"application/vnd.openxmlformats-officedocument.presentationml.presentation",
}
View Source
var SupportEnvs = []MatterEnv{
	{Name: "$UID", Intro: "用户ID", Example: "10001", /* contains filtered or unexported fields */},
	{Name: "$UUID", Intro: "UUID", Example: "6ba7b810-9dad-11d1-80b4-00c04fd430c8", /* contains filtered or unexported fields */},
	{Name: "$RAW_PATH", Intro: "初始上传路径", Example: "文稿/简历", /* contains filtered or unexported fields */},
	{Name: "$RAW_NAME", Intro: "初始文件名", Example: "张三-简历", /* contains filtered or unexported fields */},
	{Name: "$RAW_EXT", Intro: "初始文件后缀", Example: "pdf", /* contains filtered or unexported fields */},
	{Name: "$RAND_8KEY", Intro: "8位随机字符", Example: "mCUoR35r", /* contains filtered or unexported fields */},
	{Name: "$RAND_16KEY", Intro: "16位随机字符", Example: "e1CbDUNfyVP3sScJ", /* contains filtered or unexported fields */},
	{Name: "$NOW_DATE", Intro: "当前时间-日期", Example: "20210101", /* contains filtered or unexported fields */},
	{Name: "$NOW_YEAR", Intro: "当前时间-年", Example: "2021", /* contains filtered or unexported fields */},
	{Name: "$NOW_MONTH", Intro: "当前时间-月", Example: "01", /* contains filtered or unexported fields */},
	{Name: "$NOW_DAY", Intro: "当前时间-日", Example: "01", /* contains filtered or unexported fields */},
	{Name: "$NOW_HOUR", Intro: "当前时间-时", Example: "12", /* contains filtered or unexported fields */},
	{Name: "$NOW_MIN", Intro: "当前时间-分", Example: "30", /* contains filtered or unexported fields */},
	{Name: "$NOW_SEC", Intro: "当前时间-秒", Example: "10", /* contains filtered or unexported fields */},
	{Name: "$NOW_UNIX", Intro: "当前时间-时间戳", Example: "1612631185", /* contains filtered or unexported fields */},
}

Functions

func Tables

func Tables() []interface{}

Types

type Matter

type Matter struct {
	Id         int64          `json:"id"`
	Uid        int64          `json:"uid" gorm:"not null"`
	Sid        int64          `json:"sid" gorm:"not null"` // storage_id
	Alias      string         `json:"alias" gorm:"size:16;not null"`
	Name       string         `json:"name" gorm:"not null"`
	Type       string         `json:"type" gorm:"not null"`
	Size       int64          `json:"size" gorm:"not null"`
	DirType    int8           `json:"dirtype" gorm:"column:dirtype;not null"`
	Parent     string         `json:"parent" gorm:"not null"`
	Object     string         `json:"object" gorm:"not null"`
	URL        string         `json:"url" gorm:"-"`
	CreatedAt  time.Time      `json:"created" gorm:"not null"`
	UpdatedAt  time.Time      `json:"updated" gorm:"not null"`
	UploadedAt *time.Time     `json:"uploaded"`
	DeletedAt  gorm.DeletedAt `json:"-"`
	TrashedBy  string         `json:"-" gorm:"size:16;not null"`
}

func NewMatter

func NewMatter(uid, sid int64, name string) *Matter

func (*Matter) BuildObject

func (m *Matter) BuildObject(rootPath string, filePath string)

func (*Matter) Clone

func (m *Matter) Clone() *Matter

func (*Matter) FullPath

func (m *Matter) FullPath() string

func (*Matter) IsDir

func (m *Matter) IsDir() bool

func (Matter) TableName

func (Matter) TableName() string

func (*Matter) UserAccessible

func (m *Matter) UserAccessible(uid int64) bool

type MatterEnv

type MatterEnv struct {
	Name    string `json:"name"`
	Intro   string `json:"intro"`
	Example string `json:"example"`
	// contains filtered or unexported fields
}

type Option

type Option struct {
	Id      int64          `json:"id"`
	Name    string         `json:"name" gorm:"size:16;not null"`
	Opts    Opts           `json:"opts" gorm:"not null"`
	Created time.Time      `json:"created" gorm:"autoCreateTime"`
	Updated time.Time      `json:"updated" gorm:"autoUpdateTime"`
	Deleted gorm.DeletedAt `json:"-"`
}

func (Option) TableName

func (Option) TableName() string

type Opts

type Opts map[string]interface{}

Opts defiend JSON data type, need to implements driver.Valuer, sql.Scanner interface

func (Opts) GetBool

func (m Opts) GetBool(name string) bool

func (Opts) GetInt

func (m Opts) GetInt(name string) int

func (Opts) GetString

func (m Opts) GetString(name string) string

func (Opts) GormDBDataType

func (Opts) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType gorm db data type

func (Opts) GormDataType

func (m Opts) GormDataType() string

GormDataType gorm common data type

func (Opts) MarshalJSON

func (m Opts) MarshalJSON() ([]byte, error)

MarshalJSON to output non base64 encoded []byte

func (*Opts) Scan

func (m *Opts) Scan(val interface{}) error

Scan scan value into Jsonb, implements sql.Scanner interface

func (*Opts) UnmarshalJSON

func (m *Opts) UnmarshalJSON(b []byte) error

UnmarshalJSON to deserialize []byte

func (Opts) Value

func (m Opts) Value() (driver.Value, error)

Value return json value, implement driver.Valuer interface

type Recycle

type Recycle struct {
	Id        int64      `json:"id"`
	Uid       int64      `json:"uid" gorm:"not null"`
	Sid       int64      `json:"sid" gorm:"not null"` // storage_id
	Alias     string     `json:"alias" gorm:"size:16;not null"`
	Name      string     `json:"name" gorm:"not null"`
	Type      string     `json:"type" gorm:"not null"`
	Size      int64      `json:"size" gorm:"not null"`
	DirType   int8       `json:"dirtype" gorm:"column:dirtype;not null"`
	Parent    string     `json:"parent" gorm:"not null"`
	Object    string     `json:"object" gorm:"not null"`
	CreatedAt time.Time  `json:"created" gorm:"not null"`
	DeletedAt *time.Time `json:"deleted"`
}

func (*Recycle) FullPath

func (m *Recycle) FullPath() string

func (*Recycle) IsDir

func (m *Recycle) IsDir() bool

func (Recycle) TableName

func (Recycle) TableName() string

func (*Recycle) UserAccessible

func (m *Recycle) UserAccessible(uid int64) bool

type Share

type Share struct {
	Id        int64      `json:"id"`
	Uid       int64      `json:"uid" gorm:"not null"`
	Alias     string     `json:"alias" gorm:"size:16;not null"`
	Matter    string     `json:"matter" gorm:"not null"`
	Name      string     `json:"name" gorm:"not null"`
	Type      string     `json:"type" gorm:"not null"`
	Secret    string     `json:"secret,omitempty" gorm:"size:16;not null"`
	Protected bool       `json:"protected" gorm:"-"`
	DownTimes int64      `json:"down_times" gorm:"not null"`
	ViewTimes int64      `json:"view_times" gorm:"not null"`
	ExpireAt  time.Time  `json:"expire_at" gorm:"not null"`
	CreateAt  time.Time  `json:"created" gorm:"autoCreateTime;not null"` // 这里的CreateAt应该是CreatedAt,但是先将错就错吧
	UpdateAt  time.Time  `json:"updated" gorm:"autoUpdateTime;not null"` // 这里的UpdateAt应该是UpdatedAt,但是先将错就错吧
	DeletedAt *time.Time `json:"-"`
}

func (*Share) AfterFind

func (s *Share) AfterFind(*gorm.DB) (err error)

func (Share) TableName

func (Share) TableName() string

type Storage

type Storage struct {
	Id         int64          `json:"id"`
	Mode       int8           `json:"mode" gorm:"size:16;not null"`
	Name       string         `json:"name" gorm:"size:16;not null"`
	Title      string         `json:"title" gorm:"size:16;not null"`
	IDirs      string         `json:"idirs" gorm:"size:255;not null"` // internal dirs
	Bucket     string         `json:"bucket" gorm:"size:32;not null"`
	Provider   string         `json:"provider" gorm:"size:8;not null"`
	Endpoint   string         `json:"endpoint" gorm:"size:128;not null"`
	Region     string         `json:"region" gorm:"size:128;default:auto;not null"`
	AccessKey  string         `json:"access_key" gorm:"size:64;not null"`
	SecretKey  string         `json:"secret_key" gorm:"size:64;not null"`
	CustomHost string         `json:"custom_host" gorm:"size:128;not null"`
	RootPath   string         `json:"root_path" gorm:"size:64;not null"`
	FilePath   string         `json:"file_path" gorm:"size:1024;not null"`
	Status     int8           `json:"status" gorm:"size:1;default:1;not null"`
	Created    time.Time      `json:"created" gorm:"autoCreateTime;not null"`
	Updated    time.Time      `json:"updated" gorm:"autoUpdateTime;not null"`
	Deleted    gorm.DeletedAt `json:"-"`
}

func (*Storage) PublicRead

func (s *Storage) PublicRead() bool

func (*Storage) SKAsterisk added in v1.5.6

func (s *Storage) SKAsterisk() (sk string)

func (Storage) TableName

func (Storage) TableName() string

type User

type User struct {
	Id        int64          `json:"id"`
	Email     string         `json:"email" gorm:"size:32;unique_index;not null"`
	Username  string         `json:"username" gorm:"size:20;unique_index;not null"`
	Password  string         `json:"-" gorm:"size:32;not null"`
	Status    uint8          `json:"-" gorm:"size:1;not null"`
	StatusTxt string         `json:"status" gorm:"-"`
	Roles     string         `json:"-" gorm:"size:64;not null"`
	RoleTxt   string         `json:"role" gorm:"-"`
	Ticket    string         `json:"ticket" gorm:"size:6;unique_index;not null"`
	Profile   UserProfile    `json:"profile,omitempty" gorm:"foreignKey:Uid"`
	Storage   UserStorage    `json:"storage,omitempty" gorm:"foreignKey:Uid"`
	Created   time.Time      `json:"created" gorm:"autoCreateTime;not null"`
	Updated   time.Time      `json:"updated" gorm:"autoUpdateTime;not null"`
	Deleted   gorm.DeletedAt `json:"-"`

	Token string `json:"-" gorm:"-"`
}

func (*User) Activated

func (u *User) Activated() bool

func (*User) Format

func (u *User) Format() *User

func (*User) IDString

func (u *User) IDString() string

func (*User) RolesSplit

func (u *User) RolesSplit() []string

func (User) TableName

func (User) TableName() string

type UserCreateOption

type UserCreateOption struct {
	Roles      string
	Ticket     string
	Origin     string
	Activated  bool
	StorageMax uint64
}

func NewUserCreateOption

func NewUserCreateOption() UserCreateOption

type UserKey added in v1.6.0

type UserKey struct {
	Id        int64          `json:"id"`
	Uid       int64          `json:"uid" gorm:"not null"`
	Name      string         `json:"name" gorm:"not null"`
	AccessKey string         `json:"access_key" gorm:"size:32;not null"`
	SecretKey string         `json:"secret_key" gorm:"size:64;not null"`
	Created   time.Time      `json:"created" gorm:"autoCreateTime;not null"`
	Updated   time.Time      `json:"updated" gorm:"autoUpdateTime;not null"`
	Deleted   gorm.DeletedAt `json:"-"`
}

func NewUserKey added in v1.6.0

func NewUserKey(uid int64, name string) *UserKey

func (*UserKey) ResetSecret added in v1.6.0

func (uk *UserKey) ResetSecret()

func (UserKey) TableName added in v1.6.0

func (UserKey) TableName() string

type UserProfile

type UserProfile struct {
	Id       int64          `json:"id"`
	Uid      int64          `json:"uid" gorm:"unique_index;not null"`
	Nickname string         `json:"nickname" gorm:"size:32;not null"`
	Avatar   string         `json:"avatar" gorm:"size:255;not null"`
	Bio      string         `json:"bio" gorm:"size:255;not null"`
	URL      string         `json:"url" gorm:"size:255;not null"`
	Company  string         `json:"company" gorm:"size:32;not null"`
	Location string         `json:"location" gorm:"size:32;not null"`
	Locale   string         `json:"locale" gorm:"not null"`
	Created  time.Time      `json:"created" gorm:"autoCreateTime;not null"`
	Updated  time.Time      `json:"updated" gorm:"autoUpdateTime;not null"`
	Deleted  gorm.DeletedAt `json:"-"`
}

func (UserProfile) TableName

func (UserProfile) TableName() string

type UserStorage

type UserStorage struct {
	Id      int64          `json:"id"`
	Uid     int64          `json:"uid" gorm:"not null"`
	Max     uint64         `json:"max" gorm:"not null"`
	Used    uint64         `json:"used" gorm:"not null"`
	Created time.Time      `json:"created" gorm:"autoCreateTime;not null"`
	Updated time.Time      `json:"updated" gorm:"autoUpdateTime;not null"`
	Deleted gorm.DeletedAt `json:"-"`
}

func (*UserStorage) Overflowed

func (sq *UserStorage) Overflowed(addonSize int64) bool

func (UserStorage) TableName

func (UserStorage) TableName() string

Jump to

Keyboard shortcuts

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