database

package
v0.0.0-...-f768453 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2024 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyExist = fmt.Errorf("paste already exist")
View Source
var ErrDecodeBase64Hash = fmt.Errorf("invalid base64 hash")
View Source
var ErrInvalidShortURL = fmt.Errorf("invalid short url")
View Source
var ErrNoContent = fmt.Errorf("paste no content")
View Source
var ErrNoDatabase = fmt.Errorf("database not connect")
View Source
var ErrNotFound = fmt.Errorf("paste not found")
View Source
var ErrNotFoundOrPasswordWrong = fmt.Errorf("account not found or bad password")
View Source
var ErrPasteHold = fmt.Errorf("paste hold")
View Source
var ErrShortURLAlreadyExist = fmt.Errorf("short url already exist")
View Source
var HTMLTAGRegex = regexp.MustCompile(`(?i)<[^>]*>`)
View Source
var ReservedURL = regexp.MustCompile(`^(sw\.js(\.map)?|workbox.*?\.js(\.map)?|manifest\.json|favicon\.ico|robots\.txt|index\.(x|s)?htm(l)?|admin\.(x|s)?htm(l)?)$`)
View Source
var ResetAdminFlag = flag.Bool("resetadmin", false, "reset admin password")
View Source
var ShortURLRule = regexp.MustCompile(`^[a-zA-Z0-9_\.-]+$`)

Functions

func CheckShortURL

func CheckShortURL(p *Paste) error

func Close

func Close()

func GetConfigPath

func GetConfigPath() string

func GetDBPath

func GetDBPath() string

func GetPastesDir

func GetPastesDir() string

func HashExist

func HashExist(hash any) bool

func Init

func Init() (err error)

func InitWebAuthn

func InitWebAuthn() (err error)

func LoadConfig

func LoadConfig()

func PostInit

func PostInit()

func RenameOldDatabaseColumn

func RenameOldDatabaseColumn()

func ResetAdmin

func ResetAdmin()

func ResetHoldCount

func ResetHoldCount() error

func SaveConfig

func SaveConfig()

func ShortURLExist

func ShortURLExist(name string) bool

func UserDiscoverableHandle

func UserDiscoverableHandle(rawID, userHandle []byte) (webauthn.User, error)

func UserDiscoverableLoginRequest

func UserDiscoverableLoginRequest() (assertion *protocol.CredentialAssertion, session *webauthn.SessionData, err error)

Types

type Paste

type Paste struct {
	UUID                 string       `db:"uuid"`
	UID                  int64        `db:"uid"`
	Content              io.Reader    `db:"-"`
	Hash                 Paste_Hash   `db:"hash"`
	Password             string       `db:"password"`
	ExpireAfter          time.Time    `db:"expire_after"`
	AccessCount          int64        `db:"access_count"`
	MaxAccessCount       int64        `db:"max_access_count"`
	DeleteIfNotAvailable bool         `db:"delete_if_not_available"`
	HoldCount            int64        `db:"hold_count"`
	HoldBefore           time.Time    `db:"hold_before"`
	Extra                *Paste_Extra `db:"extra"`
	CreatedAt            time.Time    `db:"created_at"`
	Short_url            string       `db:"short_url"`
}

func QueryAllPaste

func QueryAllPaste(page int64, page_size int64) (pastes []*Paste, total int, err error)

func QueryAllPasteByUser

func QueryAllPasteByUser(uid int64, page int64, page_size int64) (pastes []*Paste, total int, err error)

func QueryPasteByHash

func QueryPasteByHash(hash Paste_Hash) (*Paste, error)

func QueryPasteByShortURLOrHash

func QueryPasteByShortURLOrHash(name string) (p *Paste, err error)

func QueryPasteByUUID

func QueryPasteByUUID(uuid string) (*Paste, error)

func (*Paste) Access

func (p *Paste) Access(hold_before time.Time) error

func (*Paste) Base64Hash

func (p *Paste) Base64Hash() string

func (*Paste) CreateShortURL

func (p *Paste) CreateShortURL() error

func (*Paste) Delete

func (p *Paste) Delete() error

func (*Paste) FlagDelete

func (p *Paste) FlagDelete() error

func (*Paste) ForceDelete

func (p *Paste) ForceDelete() error

func (*Paste) GenerateShortURL

func (p *Paste) GenerateShortURL() error

func (*Paste) HexHash

func (p *Paste) HexHash() string

func (*Paste) Hold

func (p *Paste) Hold() error

func (*Paste) Path

func (p *Paste) Path() string

func (*Paste) Save

func (p *Paste) Save() (*Paste, error)

func (*Paste) SetPassword

func (p *Paste) SetPassword(password string) (err error)

func (*Paste) Token

func (p *Paste) Token(ExpireAfter time.Time) string

func (*Paste) Unhold

func (p *Paste) Unhold() error

func (*Paste) Update

func (p *Paste) Update() (paste *Paste, err error)

func (*Paste) UpdateMetadata

func (p *Paste) UpdateMetadata() error

func (*Paste) UpdateShortURL

func (p *Paste) UpdateShortURL() error

func (*Paste) User

func (p *Paste) User() (*User, error)

func (*Paste) Valid

func (p *Paste) Valid() bool

func (*Paste) VerifyToken

func (p *Paste) VerifyToken(token string) bool

type Paste_Extra

type Paste_Extra struct {
	MimeType    string `json:"mime_type"`
	FileName    string `json:"filename"`
	Size        uint64 `json:"size"`
	HashPadding bool   `json:"hash_padding"`
}

func (*Paste_Extra) Scan

func (e *Paste_Extra) Scan(src any) error

func (*Paste_Extra) String

func (e *Paste_Extra) String() string

func (*Paste_Extra) Value

func (e *Paste_Extra) Value() (driver.Value, error)

type Paste_Hash

type Paste_Hash int64

func DecodeBase64Hash

func DecodeBase64Hash(base64_hash string) (Paste_Hash, error)

type Pastebin_Config

type Pastebin_Config struct {
	SiteName            string   `yaml:"site_name"`
	SiteTitle           string   `yaml:"site_title"`
	SiteDomain          string   `yaml:"site_domain"`
	WebauthnOrigins     []string `yaml:"webauthn_origins"`
	SupportNoFilename   bool     `yaml:"support_no_filename"`
	Mode                string   `yaml:"mode"`
	AllowHTML           bool     `yaml:"allow_html"`
	AllowAnonymous      bool     `yaml:"allow_anonymous"`
	UserCookieMaxAge    int      `yaml:"user_cookie_max_age"`
	PasteAssessTokenAge int      `yaml:"paste_assess_token_age"`
	CustomTemplateDir   string   `yaml:"custom_template_dir"`
	SessionCookie       string   `yaml:"session_cookie"`
	DefaultColorScheme  string   `yaml:"default_color_scheme"`
	// contains filtered or unexported fields
}
var Config *Pastebin_Config = &Pastebin_Config{
	SiteName:            "Pastebin",
	SiteTitle:           "",
	SiteDomain:          "go-pastebin.app",
	WebauthnOrigins:     []string{"https://go-pastebin.app"},
	Mode:                "release",
	SupportNoFilename:   true,
	AllowHTML:           false,
	AllowAnonymous:      true,
	UserCookieMaxAge:    86400 * 30,
	PasteAssessTokenAge: 86400,
	DefaultColorScheme:  "light",
	SessionCookie:       "PASTEBIN_SESSION",
	CustomTemplateDir:   "",
	dataDir:             flag.String("data", "/var/lib/go-pastebin", "Data directory"),
	webauthnConfig:      &webauthn.Config{},
}

type Pastebin_DB

type Pastebin_DB struct {
	*sqlx.DB
}

type Session

type Session struct {
	UUID string
	// contains filtered or unexported fields
}

func GetSession

func GetSession(uuid string) (session *Session, err error)

func NewSession

func NewSession() (session *Session, err error)

func (*Session) Del

func (s *Session) Del(name string) error

func (*Session) Get

func (s *Session) Get(name string, value any) (err error)

func (*Session) Set

func (s *Session) Set(name string, value any, duration time.Duration) error

type User

type User struct {
	UID      int64       `json:"uid" db:"uid"`
	Username string      `json:"username" db:"username"`
	Email    string      `json:"email" db:"email"`
	Role     string      `json:"role" db:"role"`
	Password string      `json:"-" db:"password"`
	Extra    *User_Extra `json:"extra" db:"extra"`
}

func GetUser

func GetUser(uid int64) (*User, error)

func GetUserByAccount

func GetUserByAccount(account string) (*User, error)

func GetUserByToken

func GetUserByToken(token string) (*User, error)

func UserDiscoverableLogin

func UserDiscoverableLogin(c echo.Context, session webauthn.SessionData) (*User, error)

func UserLogin

func UserLogin(account string, password string) (*User, error)

func (*User) ChangePassword

func (user *User) ChangePassword(oldPassword string, newPassword string) error

func (*User) Create

func (user *User) Create(setuid bool) (err error)

func (*User) Delete

func (user *User) Delete() error

func (*User) IsAdmin

func (user *User) IsAdmin() bool

func (*User) IsAnonymous

func (user *User) IsAnonymous() bool

func (*User) LoginWebAuthn

func (user *User) LoginWebAuthn(c echo.Context, session webauthn.SessionData) error

func (*User) LoginWebAuthnRequest

func (user *User) LoginWebAuthnRequest() (assertion *protocol.CredentialAssertion, session *webauthn.SessionData, err error)

func (*User) RegisterWebAuthn

func (user *User) RegisterWebAuthn(c echo.Context, session webauthn.SessionData, credential_name string, passkey bool) error

func (*User) RegisterWebAuthnRequest

func (user *User) RegisterWebAuthnRequest(credential_name string, passkey bool) (creation *protocol.CredentialCreation, session *webauthn.SessionData, err error)

func (*User) RemoveWebAuthnCredential

func (user *User) RemoveWebAuthnCredential(credential_name string) error

func (*User) SetPassword

func (user *User) SetPassword(password string) error

func (*User) Token

func (u *User) Token() string

func (*User) Update

func (user *User) Update() error

func (*User) WebAuthnCredentials

func (user *User) WebAuthnCredentials() []webauthn.Credential

func (*User) WebAuthnDisplayName

func (user *User) WebAuthnDisplayName() string

func (*User) WebAuthnID

func (user *User) WebAuthnID() []byte

func (*User) WebAuthnName

func (user *User) WebAuthnName() string

type User_Extra

type User_Extra struct {
	WebAuthn *User_WebAuthn `json:"webauthn"`
}

func (*User_Extra) Scan

func (e *User_Extra) Scan(src any) error

func (*User_Extra) String

func (e *User_Extra) String() string

func (*User_Extra) Value

func (e *User_Extra) Value() (driver.Value, error)

type User_WebAuthn

type User_WebAuthn struct {
	Id          []byte                               `json:"id"`
	Credentials map[string]*User_WebAuthn_Credential `json:"credential"`
}

type User_WebAuthn_Credential

type User_WebAuthn_Credential struct {
	webauthn.Credential `json:"credential"`
	Passkey             bool `json:"passkey"`
	CreatedAt           time.Time
}

Jump to

Keyboard shortcuts

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