storage

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2019 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

imsto core objects

Index

Constants

View Source
const (
	ASCENDING  = 1
	DESCENDING = -1
)
View Source
const (
	DefaultMaxMemory = 12 << 20 // 8 MB
	APIKeyHeader     = "X-Access-Key"
)

consts

View Source
const (
	VC_TOKEN  valueCate = 1
	VC_TICKET valueCate = 2
)
View Source
const (
	// ViewName ...
	ViewName = "show"
)

Variables

View Source
var (
	ErrWriteFailed = errors.New("Err: Write file failed")
	ErrEmptyRoof   = errors.New("empty roof")
	ErrEmptyID     = errors.New("empty id")
	ErrZeroSize    = errors.New("zero size")
)

errors

View Source
var (
	ErrDbError = errors.New("database error")
)

Functions

func BytesToInt64

func BytesToInt64(buf []byte) int64

func CheckAPIKey

func CheckAPIKey(next http.Handler) http.Handler

CheckAPIKey ...

func Delete

func Delete(roof, id string) error

Delete ...

func Dump

func Dump(key, roof, file string) error

Dump ...

func GetURL

func GetURL(scheme, suffix string) string

GetURL ...

func InitMetaTables

func InitMetaTables()

func Int64ToBytes

func Int64ToBytes(i int64) []byte

func LoadPath

func LoadPath(u string) (oi *outItem, err error)

LoadPath ...

func ParseTags

func ParseTags(s string) (cdb.StringArray, error)

ParseTags ...

func PullBlob

func PullBlob(key string, roof string) (data []byte, err error)

PullBlob pull blob from engine with key path

func ReadyDir

func ReadyDir(filename string) error

ReadyDir ...

func SaveFile

func SaveFile(filename string, data []byte) error

SaveFile ...

Types

type App

type App struct {
	Id       AppID     `json:"id,omitempty"`
	Version  VerID     `json:"api_ver,omitempty"`
	ApiKey   string    `json:"api_key,omitempty"`
	ApiSalt  string    `json:"api_salt,omitempty"`
	Name     string    `json:"name,omitempty"`
	Created  time.Time `json:"created,omitempty"`
	Disabled bool      `json:"disabled,omitempty"`
}

func AppFromContext

func AppFromContext(ctx context.Context) (a *App, ok bool)

AppFromContext ...

func LoadApp

func LoadApp(api_key string) (app *App, err error)

func NewApp

func NewApp(name string) (app *App)

func (*App) RequestNewToken

func (a *App) RequestNewToken(uid int) string

func (*App) Save

func (a *App) Save() error

func (*App) TicketRequestLoad

func (a *App) TicketRequestLoad(token, roof string, author int) (ticket *Ticket, err error)

func (*App) TicketRequestNew

func (a *App) TicketRequestNew(roof, token string, uid int, prompt string) (t *apiToken, err error)

TicketRequestNew ... deprecated

func (*App) VerifyToken

func (a *App) VerifyToken(token string) (at *apiToken, err error)

VerifyToken ...

type AppID

type AppID uint16

type Author

type Author uint32

type Entry

type Entry struct {
	Id      imagid.IID  `json:"id"`
	Name    string      `json:"name"`
	Size    uint32      `json:"size"`
	Path    string      `json:"path"`
	Status  uint8       `json:"-"`
	Hashes  StringArray `json:"hashes,omitempty"`
	IDs     StringArray `json:"-"`
	Roofs   StringArray `json:"roofs,omitempty"`
	Tags    StringArray `json:"tags,omitempty"`
	Meta    *iimg.Attr  `json:"meta,omitempty"`
	AppId   AppID       `json:"appid,omitempty"`
	Author  Author      `json:"author,omitempty"`
	Created time.Time   `json:"created,omitempty"`

	Err string `json:"err,omitempty"`

	Done chan bool `json:"-"`
	// contains filtered or unexported fields
}

func Fetch

func Fetch(in FetchInput) (entry *Entry, err error)

Fetch ...

func NewEntryConvert

func NewEntryConvert(id, name, path string, size uint32, meta, sev types.JsonKV, hashes, ids []string,
	created time.Time) (entry *Entry, err error)

func NewEntryReader

func NewEntryReader(rs io.ReadSeeker, name string) (e *Entry, err error)

NewEntryReader ...

func PopReadyDone

func PopReadyDone() (entry *Entry, err error)

PopReadyDone ...

func PrepareFile

func PrepareFile(file, name string) (entry *Entry, err error)

PrepareFile ...

func PrepareReader

func PrepareReader(r io.ReadSeeker, name string) (entry *Entry, err error)

PrepareReader ...

func (*Entry) IsDone

func (e *Entry) IsDone() bool

func (*Entry) PushTo

func (e *Entry) PushTo(roof string) (sev cdb.JsonKV, err error)

PushTo ...

func (*Entry) Store

func (e *Entry) Store(roof string) (ch chan error)

Store ...

func (*Entry) Trek

func (e *Entry) Trek(roof string) (err error)

Trek 处理图片信息并填充

type FLock

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

FLock is a file-based lock

func NewFLock

func NewFLock(path string) (FLock, error)

NewFLock creates new Flock-based lock (unlocked first)

func (FLock) Lock

func (lock FLock) Lock() error

Lock acquires the lock, blocking

func (FLock) TryLock

func (lock FLock) TryLock() (bool, error)

TryLock acquires the lock, non-blocking

func (FLock) Unlock

func (lock FLock) Unlock() error

Unlock releases the lock

type FetchInput

type FetchInput struct {
	URI     string
	Roof    string
	Referer string
	AppID   int
	UserID  int
}

FetchInput ...

type HttpError

type HttpError struct {
	Code int
	Text string
	Path string
}

HttpError ...

func NewHttpError

func NewHttpError(code int, text string) *HttpError

NewHttpError ...

func (*HttpError) Error

func (ie *HttpError) Error() string

Error ...

type IID

type IID = imagid.IID

type MetaFilter

type MetaFilter struct {
	Tags   string
	App    AppID
	Author Author
}

MetaFilter ...

type MetaWrap

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

MetaWrap ...

func (*MetaWrap) BatchSave

func (mw *MetaWrap) BatchSave(entries []*Entry) error

func (*MetaWrap) Browse

func (mw *MetaWrap) Browse(limit, offset int, sort map[string]int, filter MetaFilter) (a []*Entry, err error)

func (*MetaWrap) Count

func (mw *MetaWrap) Count(filter MetaFilter) (t int, err error)

func (*MetaWrap) Delete

func (mw *MetaWrap) Delete(id string) error

func (*MetaWrap) GetHash

func (mw *MetaWrap) GetHash(hash string) (*ehash, error)

func (*MetaWrap) GetMapping

func (mw *MetaWrap) GetMapping(id string) (*mapItem, error)

func (*MetaWrap) GetMeta

func (mw *MetaWrap) GetMeta(id string) (entry *Entry, err error)

func (*MetaWrap) MapTags

func (mw *MetaWrap) MapTags(id string, tags string) error

func (*MetaWrap) Ready

func (mw *MetaWrap) Ready(entry *Entry) error

func (*MetaWrap) Save

func (mw *MetaWrap) Save(entry *Entry, isUpdate bool) error

Save ...

func (*MetaWrap) SetDone

func (mw *MetaWrap) SetDone(id string, sev cdb.JsonKV) error

func (*MetaWrap) TableSuffix

func (mw *MetaWrap) TableSuffix() string

func (*MetaWrap) UnmapTags

func (mw *MetaWrap) UnmapTags(id string, tags string) error

type MetaWrapper

type MetaWrapper interface {
	Browse(limit, offset int, sort map[string]int, filter MetaFilter) ([]*Entry, error)
	Count(filter MetaFilter) (int, error)
	Ready(entry *Entry) error
	SetDone(id string, sev cdb.JsonKV) error
	Save(entry *Entry, isUpdate bool) error
	BatchSave(entries []*Entry) error
	GetMeta(id string) (*Entry, error)
	GetHash(hash string) (*ehash, error)
	GetMapping(id string) (*mapItem, error)
	Delete(id string) error
	MapTags(id string, tags string) error
	UnmapTags(id string, tags string) error
}

MetaWrapper ...

func NewMetaWrapper

func NewMetaWrapper(roof string) (mw MetaWrapper)

type StringArray

type StringArray = cdb.StringArray

type StringSlice

type StringSlice = cdb.StringSlice

type Ticket

type Ticket struct {
	AppID  AppID  `json:"appid,omitempty"`
	Author Author `json:"author,omitempty"`
	Prompt string `json:"prompt,omitempty"`

	ImgId   string `json:"img_id,omitempty"`
	ImgPath string `json:"img_path,omitempty"`
	Done    bool   `json:"done,omitempty"`
	// contains filtered or unexported fields
}

func (*Ticket) GetId

func (t *Ticket) GetId() int

type VerID

type VerID uint8

Directories

Path Synopsis
s3

Jump to

Keyboard shortcuts

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