client

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package client handles HTTP requests to the API and storage backends.

API definitions are at https://gateway.filen.io/v3/docs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIResponse

type APIResponse struct {
	Status  bool            `json:"status"`  // whether the request was successful
	Message string          `json:"message"` // additional information
	Code    string          `json:"code"`    // a status code
	Data    json.RawMessage `json:"data"`    // response body, or nil
}

APIResponse represents a response from the API.

func (*APIResponse) String

func (res *APIResponse) String() string

type AuthInfo

type AuthInfo struct {
	AuthVersion int    `json:"authVersion"`
	Salt        string `json:"salt"`
}

type Client

type Client struct {
	APIKey string // the Filen API key
}

Client carries configuration.

func (*Client) CreateDirectory

func (client *Client) CreateDirectory(uuid string, name crypto.EncryptedString, nameHashed string, parentUUID string) (*CreateDirectoryResponse, error)

CreateDirectory calls /v3/dir/create

func (*Client) DownloadFileChunk

func (client *Client) DownloadFileChunk(uuid string, region string, bucket string, chunkIdx int) ([]byte, error)

DownloadFileChunk downloads a file chunk from the storage backend.

func (*Client) GetAuthInfo

func (client *Client) GetAuthInfo(email string) (*AuthInfo, error)

GetAuthInfo calls /v3/auth/info.

func (*Client) GetDirectoryContent

func (client *Client) GetDirectoryContent(uuid string) (*DirectoryContent, error)

GetDirectoryContent calls /v3/dir/content.

func (*Client) GetUserBaseFolder

func (client *Client) GetUserBaseFolder() (*UserBaseFolder, error)

GetUserBaseFolder calls /v3/user/baseFolder.

func (*Client) GetUserMasterKeys

func (client *Client) GetUserMasterKeys(encryptedMasterKey crypto.EncryptedString) (*UserMasterKeys, error)

GetUserMasterKeys calls /v3/user/masterKeys.

func (*Client) Login

func (client *Client) Login(email, password string) (*LoginResponse, error)

Login calls /v3/login.

func (*Client) Request

func (client *Client) Request(method string, path string, request any, data any) (*APIResponse, error)

Request makes an HTTP request with an optional body and optionally returning a response body.

The API sends responses in the format (written as TS type):

{status: number, message: string, code: string, data?: any}

The APIResponse is returned, and the unmarshalled `data` is written to the data parameter, if applicable.

func (*Client) TrashDirectory

func (client *Client) TrashDirectory(uuid string) error

TrashDirectory calls /v3/dir/trash

func (*Client) TrashFile

func (client *Client) TrashFile(uuid string) error

TrashFile calls /v3/file/trash

func (*Client) UploadDone

func (client *Client) UploadDone(request UploadDoneRequest) (*UploadDoneResponse, error)

UploadDone calls /v3/upload/done.

func (*Client) UploadFileChunk

func (client *Client) UploadFileChunk(uuid string, chunkIdx int, parentUUID string, uploadKey string, data []byte) (region string, bucket string, err error)

UploadFileChunk uploads a file chunk to the storage backend.

type CreateDirectoryResponse

type CreateDirectoryResponse struct {
	UUID string `json:"uuid"`
}

type DirectoryContent

type DirectoryContent struct {
	Uploads []struct {
		UUID      string                 `json:"uuid"`
		Metadata  crypto.EncryptedString `json:"metadata"`
		Rm        string                 `json:"rm"`
		Timestamp int                    `json:"timestamp"`
		Chunks    int                    `json:"chunks"`
		Size      int                    `json:"size"`
		Bucket    string                 `json:"bucket"`
		Region    string                 `json:"region"`
		Parent    string                 `json:"parent"`
		Version   int                    `json:"version"`
		Favorited int                    `json:"favorited"`
	} `json:"uploads"`
	Folders []struct {
		UUID      string                 `json:"uuid"`
		Name      crypto.EncryptedString `json:"name"`
		Parent    string                 `json:"parent"`
		Color     interface{}            `json:"color"`
		Timestamp int                    `json:"timestamp"`
		Favorited int                    `json:"favorited"`
		IsSync    int                    `json:"is_sync"`
		IsDefault int                    `json:"is_default"`
	} `json:"folders"`
}

type LoginResponse

type LoginResponse struct {
	APIKey     string                 `json:"apiKey"`
	MasterKeys crypto.EncryptedString `json:"masterKeys"`
	PublicKey  string                 `json:"publicKey"`
	PrivateKey string                 `json:"privateKey"`
}

type RequestError

type RequestError struct {
	Message         string // description of where the error occurred
	Method          string // HTTP method of the request
	Path            string // URL path of the request
	UnderlyingError error  // the underlying error
}

A RequestError carries information on a failed HTTP request.

func (*RequestError) Error

func (e *RequestError) Error() string

type UploadDoneRequest

type UploadDoneRequest struct {
	UUID       string                 `json:"uuid"`
	Name       crypto.EncryptedString `json:"name"`
	NameHashed string                 `json:"nameHashed"`
	Size       crypto.EncryptedString `json:"size"`
	Chunks     int                    `json:"chunks"`
	MimeType   crypto.EncryptedString `json:"mime"`
	Rm         string                 `json:"rm"`
	Metadata   crypto.EncryptedString `json:"metadata"`
	Version    int                    `json:"version"`
	UploadKey  string                 `json:"uploadKey"`
}

type UploadDoneResponse

type UploadDoneResponse struct {
	Chunks int `json:"chunks"`
	Size   int `json:"size"`
}

type UserBaseFolder

type UserBaseFolder struct {
	UUID string `json:"uuid"`
}

type UserMasterKeys

type UserMasterKeys struct {
	Keys crypto.EncryptedString `json:"keys"`
}

Jump to

Keyboard shortcuts

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