pixeldrain

package module
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 8 Imported by: 0

README

A Pixeldrain client

MIT License Go application Go Reference codecov Release

Usage

Upload files
pd upload <path[:name]>...

upload command uploads files specified by the given paths to Pixeldrain and shows a URL to download them. Each path can have an optional name. If a name is given, uploaded file will be renamed with it.

For example, this command reads img.png and uploads it as another.png:

pd upload img.png:another.png

If path is -, the uploading file is read from stdin. In this case, it's recommended to give a file name. For example, this command reads data from stdin and uploads it as output.log:

pd upload -:output.log

If multiple files are given, an album consists of them will be created. By default, the album has a random name. --album flag can specify the name. For example, this command uploads two files and creates an album named screenshots:

pd upload --album screenshots img1.png img2.png
Upload a directory

Since this application supports uploading a file from STDIN, you can upload a directory with tar command. For example, this command uploads ~/Documents directory:

tar zcf - ~/Documents | pd upload -:documents.tar.gz
Upload to your account

If you want to upload files to your account, give your API key with --api-key flag or via PIXELDRAIN_API_KEY environment variable.

An API key can be obtained from https://pixeldrain.com/user/api_keys.

Download files
pd download <URL>...

download command downloads files from Pixeldrain and stores it in the current directory by default.

If --dir or -o option is given with a directory path, the downloaded file is stored in the directory.

If the given URL refers an album which consists of multiple files, this command asks which file you want to download. If you want to download all files without any interaction, use --all flag.

End-to-end encryption

If recipients are specified with --recipient and/or --recipient-file flags to upload command, files will be encrypted before being uploaded by age. Encrypted files will have extension .age.

A recipient specified with --recipient flag can be an age public key generated by age-keygen ("age1...") or an SSH public key ("ssh-ed25519 AAAA...", "ssh-rsa AAAA..."). A recipient file specified with --recipient-file flag contains one or more recipients, one per line. Empty line sand lines starting with "#" are ignored as comments.

If a downloading file has extension .age and an identity file is specified with --identity flag to download command, the file will be decrypted.

An identity contains one or more secret keys ("AGE-SECRET-KEY-1..."), one per line, or an SSH key. Empty lines and lines starting with "#" are ignored as comments.

See age for the details of age and age-keygen.

Installation

If you're a Homebrew or Linuxbrew user, you can install this app by the following commands:

$ brew tap jkawamoto/pixeldrain
$ brew install pixeldrain

To build the newest version, use go get command:

$ go get github.com/jkawamoto/go-pixeldrain

Otherwise, compiled binaries are also available in GitHub.

License

This software is released under the MIT License, see LICENSE.

Documentation

Overview

Package pixeldrain provides a Pixeldrain client.

Example (Download)
ctx := context.Background()
id := "FILE_ID"
apiKey := "YOUR API KEY IF NECESSARY"

//  Get the file information.
info, err := pixeldrain.Default.File.GetFileInfo(
	file.NewGetFileInfoParamsWithContext(ctx).WithID(id),
	client.BasicAuth("", apiKey),
)
if err != nil {
	log.Fatal(err)
}

// Open a file to store the downloaded contents.
f, err := os.OpenFile(filepath.Join("~/Downloads", info.Payload.Name), os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
	log.Fatal(err)
}
defer func() {
	if err := f.Close(); err != nil {
		log.Fatal(err)
	}
}()

// If a directory path is given, the downloaded file will be stored in the directory.
_, err = pixeldrain.Default.File.DownloadFile(
	file.NewDownloadFileParamsWithContext(ctx).WithID(id),
	client.BasicAuth("", apiKey),
	f,
)
if err != nil {
	log.Fatal(err)
}
Output:

Example (Upload)
// Open the target file.
f, err := os.Open("example_test.go")
if err != nil {
	log.Fatal(err)
}
defer func() {
	if err := f.Close(); err != nil {
		log.Fatal(err)
	}
}()

// Upload the file with the default client. API key can be empty.
res, err := pixeldrain.Default.File.UploadFile(
	file.NewUploadFileParamsWithContext(context.Background()).WithFile(f),
	client.BasicAuth("", "YOUR API KEY IF NECESSARY"),
)
if err != nil {
	log.Fatal(err)
}

// File ID is used to download the file by this client.
fmt.Println("File ID:", swag.StringValue(res.Payload.ID))

// Download URL is for browsers, wget, curl, etc.
fmt.Println("Download URL:", pixeldrain.DownloadURL(swag.StringValue(res.Payload.ID)))
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var Default = New(nil, nil)

Default is a default client.

Functions

func ContentTypeFixer added in v0.6.0

func ContentTypeFixer(upstream runtime.ClientTransport) runtime.ClientTransport

ContentTypeFixer returns a new ClientTransport that wraps the given ClientTransport to fix the content type issue.

func DownloadURL added in v0.6.0

func DownloadURL(id string) string

DownloadURL returns the URL associated with the given file ID.

func IsDownloadURL added in v0.6.0

func IsDownloadURL(u string) (bool, error)

IsDownloadURL returns true if the given url points a file.

func IsListURL added in v0.6.0

func IsListURL(u string) (bool, error)

IsListURL returns true if the given url points a list.

func ListURL added in v0.6.0

func ListURL(id string) string

ListURL returns the URL associated with the given list ID.

func New added in v0.5.0

New creates a new PixelDrain client with the given configurations. formats and cfg can be nil.

Types

type Error added in v0.5.0

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

Error wraps an error to return a more readable error message.

func NewError added in v0.5.0

func NewError(err error) *Error

NewError returns *Error that wraps the given error.

func (Error) Error added in v0.5.0

func (e Error) Error() string

Error returns a string that represents this error.

func (Error) Unwrap added in v0.5.0

func (e Error) Unwrap() error

Unwrap returns the original error.

Directories

Path Synopsis
Package client contains auto generated an open API client for Pixeldrain.
Package client contains auto generated an open API client for Pixeldrain.
file
Package file contains auto generated operations for Pixeldrain file API.
Package file contains auto generated operations for Pixeldrain file API.
list
Package list contains auto generated operations for Pixeldrain list API.
Package list contains auto generated operations for Pixeldrain list API.
cmd
pd
pd is a Pixeldrain client application.
pd is a Pixeldrain client application.
pd/auth
Package auth provides functions to attach and extract auth information to and from a context.
Package auth provides functions to attach and extract auth information to and from a context.
pd/command
Package command implements subcommands.
Package command implements subcommands.
pd/command/mock
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
pd/status
Package status defines status codes pd command returns.
Package status defines status codes pd command returns.
Package models contains auto generated structures used in the open API client for Pixeldrain.
Package models contains auto generated structures used in the open API client for Pixeldrain.

Jump to

Keyboard shortcuts

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