Documentation ¶
Index ¶
- Constants
- type AccessToken
- type FileMetadata
- type Interface
- type Storage
- func (s *Storage) Authenticate(w http.ResponseWriter, r *http.Request)
- func (s *Storage) CanAccess(token string) (bool, AccessToken, error)
- func (s *Storage) CreateSubfolders() (string, error)
- func (s *Storage) Enabled() bool
- func (s *Storage) GetFileMetadata(fileHash string) (FileMetadata, error)
- func (s *Storage) GetNodeHashFromFileHash(fileHash string) (string, bool)
- func (s *Storage) HandleIncomingFileUploads(stream network.Stream)
- func (s *Storage) SaveFileMetadata(nodeHash, fileHash string, metadata FileMetadata) error
- func (s *Storage) SaveToken(token AccessToken) error
- func (s *Storage) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Storage) SetEnabled(val bool)
- func (s *Storage) StoragePath() string
Constants ¶
const ( // AdminAccess represents full access. AdminAccess = "admin" // UserAccess represents privilege 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) HandleIncomingFileUploads(stream network.Stream) }
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 ¶
CreateSubfolders creates sub folders with current date inside the data directory.
func (*Storage) GetFileMetadata ¶
func (s *Storage) GetFileMetadata(fileHash string) (FileMetadata, error)
GetFileMetadata gets a file's metadata in the database.
func (*Storage) GetNodeHashFromFileHash ¶
GetNodeHashFromFileHash gets the node's Hash given a fileHash.
func (*Storage) HandleIncomingFileUploads ¶ added in v1.1.16
ServeHTTP handles file uploading.
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 ¶
SetEnabled return if storage functionality is enabled.
func (*Storage) StoragePath ¶
StoragePath return the storage path.