vfssrv

package
v1.4.6 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package vfssrv provides a client for interacting with a Virtual File System (VFS) service. It supports authentication, file uploads, and file downloads with proper error handling.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound     = errors.New("not found")
	ErrUnauthorized = errors.New("invalid token")
	ErrInternal     = errors.New("internal error")
)

Functions

func HashURL

func HashURL(hash string) string

HashURL converts a 32-character hash into a hierarchical file path structure. It returns the original hash unchanged if the input is not exactly 32 characters. The resulting path format is: first_char/next_two_chars/full_hash

Types

type Client

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

func NewClient

func NewClient(opts Opts) *Client

func (*Client) AuthToken

func (c *Client) AuthToken(ctx context.Context) (string, error)

AuthToken returns vfs auth token for further requests.

func (*Client) DownloadFile

func (c *Client) DownloadFile(ctx context.Context, namespace, hash, ext, size string) ([]byte, error)

DownloadFile downloads vfs file and returns bytes. Size and extension could be empty.

func (*Client) DownloadImage

func (c *Client) DownloadImage(ctx context.Context, namespace, hash, size string) ([]byte, error)

DownloadImage DownloadFile downloads vfs image with default extension and returns bytes.

func (*Client) FilePath

func (c *Client) FilePath(namespace, hash, size, ext string) (string, error)

FilePath constructs a URL for accessing a media image in the VFS. It returns an empty string and no error if the hash is not 32 characters. The URL format is: base_url/namespace/size/hash_path.jpg

func (*Client) UploadFile

func (c *Client) UploadFile(ctx context.Context, token, namespace, filename string, file io.Reader) (*HashUploadResponse, error)

UploadFile uploads File to VFS. Filename with extension. Use empty namespace for default.

type HashUploadResponse

type HashUploadResponse struct {
	Error     string `json:"error,omitempty"`   // error message
	Hash      string `json:"hash,omitempty"`    // for hash
	Extension string `json:"ext,omitempty"`     // vfs file ext
	WebPath   string `json:"webPath,omitempty"` // for hash
	FileID    int    `json:"id,omitempty"`      // vfs file id
	Name      string `json:"name,omitempty"`    // vfs file name
}

type Opts

type Opts struct {
	ApiURL         string        // Base URL for API endpoints
	PublicURL      string        // Base URL for Public Files
	Timeout        time.Duration // HTTP request timeout, default is 5s
	UploadFormName string        // Form field name for file uploads, default is Filedata
	AuthHeader     string        // Header name for authentication, default is AuthorizationJWT
	Client         *http.Client  // Custom HTTP client (optional)
}

type RequestError

type RequestError struct {
	Code int
	URL  string
	Err  error
}

RequestError records an error, URL and code.

func (*RequestError) Error

func (e *RequestError) Error() string

func (*RequestError) Unwrap

func (e *RequestError) Unwrap() error

Jump to

Keyboard shortcuts

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