pkg

package
v0.0.0-...-1ae2f7c Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckApiAlive

func CheckApiAlive() bool

CheckApiAlive checks if the API is alive by sending a GET request to the /ping endpoint

func DownloadFile

func DownloadFile(token string, fileId string, writer io.Writer, cryptoInfo *CryptoInfo) (fileName string, numBytes int64, err error)

DownloadFile downloads a file from the cloud. If the file is encrypted, it will be decrypted using the provided. If the file is encrypted and no crypto info provided, it will return an error. You need to provide at least your crypto password in CryptoInfo to decrypt the file. If no keys are provided, it will try to get the crypto info from the server and decrypt your key with the password.

func GetKeyRings

func GetKeyRings(publicKey string, privateKey string, passwd []byte) (public *crypto.KeyRing, private *crypto.KeyRing, err error)

GetKeyRings gets the public and private key rings from the armored keys

func GetUserDisk

func GetUserDisk(token string, disk string) (*Disk, *CryptoInfo, error)

GetUserDisk returns the user's default disk or the disk with the desired id. It also returns the crypto info for the disk

func GetUserID

func GetUserID(token string) (string, error)

GetUserID checks if the token is valid by calling auth.getMe method and returns the user id

func KtCustomClient

func KtCustomClient() *http.Client

KtCustomClient returns a custom http client for ktCloud API It has a timeout of 5 seconds and transport with a timeout of 3 seconds

func MapToStruct

func MapToStruct[Object any](m map[string]interface{}) (*Object, error)

MapToStruct converts a map to a struct. It is useful when we need to convert a json response to a struct

func ScanOrDefault

func ScanOrDefault(prompt, defaultValue string) (input string)

ScanOrDefault scans user input and returns it. If the input is empty, it returns the default value. Input is not scanned in non-interactive mode and the default value is returned

func SetInteractiveMode

func SetInteractiveMode(interactive bool)

SetInteractiveMode sets the interactive mode. If it is set to true, the library will ask for user input. By default, the library is not interactive. Interactive mode is used for CLI applications when you need to ask for user input.

func SetLogger

func SetLogger(logger Logger)

SetLogger sets the logger for the library. By default, the library doesn't log anything. You can set your own logger using this function, but it's not required

func UploadFile

func UploadFile(token string, name string, rewriteMime string, disk string, folder string, cryptoInfo *CryptoInfo, reader io.Reader) (fileId string, err error)

UploadFile uploads a file to the cloud. If encryption is enabled, it will encrypt the file before uploading. The file will be encrypted using the public key provided in the CryptoInfo struct. You need public key to encrypt the file. If you don't have the public key, you can get it from the server using the GetCryptoInfo function.

Types

type ApiResponse

type ApiResponse struct {
	ID    uint `mapstructure:"id"`
	Error struct {
		Code    uint   `mapstructure:"code"`
		Message string `mapstructure:"message"`
	} `mapstructure:"error,omitempty"`
	Result map[string]interface{} `mapstructure:"result,omitempty"`
}

ApiResponse is the basic mapstructure-RPC response structure

func ApiRequest

func ApiRequest(token string, method string, params map[string]interface{}) (*ApiResponse, error)

ApiRequest sends a JSON-RPC request to the API. Token can be rewritten in the params map

type CryptoInfo

type CryptoInfo struct {
	// EncryptedCryptoKey is the encrypted crypto key received from the server. You should decrypt it with a password
	EncryptedCryptoKey string
	// RawCryptoKey is the decrypted crypto key.
	//You can use it for encryption/decryption.
	//It usually is not provided by the server, you should decrypt EncryptedCryptoKey with a password
	RawCryptoKey string
	// PublicKey is the public key of the user. It is used for encryption and signature verification
	PublicKey string
	// Password is used to decrypt the EncryptedCryptoKey, also it is used as passphrase for the private key
	Password string
}

CryptoInfo is a struct that holds all the necessary information for encryption/decryption

func GetCryptoInfo

func GetCryptoInfo(token string, disk string, password string) (*CryptoInfo, error)

GetCryptoInfo gets the CryptoInfo from the server. It decrypts the crypto key if it is encrypted and a password is provided

func (*CryptoInfo) IsCryptoReady

func (c *CryptoInfo) IsCryptoReady() bool

IsCryptoReady checks if the CryptoInfo is ready for encryption/decryption. It should have the crypto key to be decrypted

func (*CryptoInfo) TryGetReady

func (c *CryptoInfo) TryGetReady(token string, disk string) error

TryGetReady tries to get the CryptoInfo ready for encryption/decryption. It tries to decrypt the key with the password.

type Disk

type Disk struct {
	CryptoKey string `mapstructure:"crypto_key"`
	ID        string `mapstructure:"id"`
	PublicKey string `mapstructure:"public_key"`
	Title     string `mapstructure:"title"`
}

type DisksInfo

type DisksInfo struct {
	Count int     `mapstructure:"count"`
	List  []*Disk `mapstructure:"list"`
}

type DownloadResponse

type DownloadResponse struct {
	Crypto bool   `mapstructure:"crypto"`
	Name   string `mapstructure:"name"`
	URL    string `mapstructure:"url"`
}

type File

type File struct {
	Date       int    `mapstructure:"date"`
	Disk       string `mapstructure:"disk"`
	Encrypted  bool   `mapstructure:"encrypted"`
	Folder     string `mapstructure:"folder"`
	ID         string `mapstructure:"id"`
	Mime       string `mapstructure:"mime"`
	Name       string `mapstructure:"name"`
	NameCrypto string `mapstructure:"name_crypto"`
	Rating     int    `mapstructure:"rating"`
	Size       int    `mapstructure:"size"`
	Text       string `mapstructure:"text"`
	Type       string `mapstructure:"type"`
	TypeDesc   string `mapstructure:"type_desc"`
	URLSecret  string `mapstructure:"url_secret"`
	URLShared  bool   `mapstructure:"url_shared"`
}

type FileGetByIdResponse

type FileGetByIdResponse struct {
	Count int     `mapstructure:"count"`
	List  []*File `mapstructure:"list"`
}

type FilesGetResponse

type FilesGetResponse struct {
	Folders    []*Folder `mapstructure:"folders"`
	HasFiles   bool      `mapstructure:"has_files"`
	HasFolders bool      `mapstructure:"has_folders"`
	List       []*File   `mapstructure:"list"`
	Offset     int       `mapstructure:"offset"`
}

type Folder

type Folder struct {
	Disk   string `mapstructure:"disk"`
	ID     string `mapstructure:"id"`
	Name   string `mapstructure:"name"`
	Parent string `mapstructure:"parent"`
}

type Logger

type Logger func(content string, params ...interface{})

Logger is a function type used to log messages This library doesn't log anything by default. You can set your own logger using SetLogger function

type UploadResult

type UploadResult struct {
	FileID string `mapstructure:"file_id"`
	Ok     bool   `mapstructure:"ok"`
}

type UserInfo

type UserInfo struct {
	AvailableSpace int64  `mapstructure:"available_space"`
	Avatar         string `mapstructure:"avatar"`
	Email          string `mapstructure:"email"`
	ID             string `mapstructure:"id"`
	PrepaidSpace   int64  `mapstructure:"prepaid_space"`
}

Jump to

Keyboard shortcuts

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