storage

package
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2023 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// AdminAccess represents full access.
	AdminAccess = "admin"
	// UserAccess represents priviledge access.
	UserAccess = "user"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessToken

type AccessToken struct {
	AccessType string `json:"access_type"`
	Token      string `json:"token"`
	ExpiresAt  int64  `json:"expires_at"`
}

AccessToken represents an access token.

type FileMetadata

type FileMetadata struct {
	FileName       string `json:"file_name"`
	MerkleRootHash string `json:"merkle_root_hash"`
	Hash           string `json:"hash"`
	FilePath       string `json:"file_path"`
	Size           int64  `json:"size"`
}

FileMetadata holds the metadata for a file.

type Interface

type Interface interface {
	StoragePath() string
	Enabled() bool
	SetEnabled(val bool)
	CreateSubfolders() (string, error)
	SaveToken(token AccessToken) error
	SaveFileMetadata(nodeHash, fileHash string, metadata FileMetadata) error
	GetFileMetadata(fileHash string) (FileMetadata, error)
	GetNodeHashFromFileHash(fileHash string) (string, bool)
	CanAccess(token string) (bool, AccessToken, error)
}

Interface defines the functionalities of the storage engine.

type Storage

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

Storage represents the storage engine and the metadata.

func New

func New(db database.Database, storagePath string, enabled bool, adminToken string, merkleTreeTotalSegments int) (*Storage, error)

New creates a new storage instance.

func (*Storage) Authenticate

func (s *Storage) Authenticate(w http.ResponseWriter, r *http.Request)

Authenticate authenticates storage access.

func (*Storage) CanAccess

func (s *Storage) CanAccess(token string) (bool, AccessToken, error)

CanAccess authorizes access.

func (*Storage) CreateSubfolders

func (s *Storage) CreateSubfolders() (string, error)

CreateSubfolders creates sub folders with current date inside the data directory.

func (*Storage) Enabled

func (s *Storage) Enabled() bool

Enabled return if storage functionality is enabled.

func (*Storage) GetFileMetadata

func (s *Storage) GetFileMetadata(fileHash string) (FileMetadata, error)

GetFileMetadata gets a file's metadata in the database.

func (*Storage) GetNodeHashFromFileHash

func (s *Storage) GetNodeHashFromFileHash(fileHash string) (string, bool)

GetNodeHashFromFileHash gets the node's Hash given a fileHash.

func (*Storage) SaveFileMetadata

func (s *Storage) SaveFileMetadata(nodeHash, fileHash string, metadata FileMetadata) error

SaveFileMetadata saves a file's metadata in the database.

func (*Storage) SaveToken

func (s *Storage) SaveToken(token AccessToken) error

SaveToken saves an access token into the database.

func (*Storage) ServeHTTP

func (s *Storage) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles file uploading.

func (*Storage) SetEnabled

func (s *Storage) SetEnabled(val bool)

SetEnabled return if storage functionality is enabled.

func (*Storage) StoragePath

func (s *Storage) StoragePath() string

StoragePath return the storage path.

Jump to

Keyboard shortcuts

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