Categorygithub.com/ManuelReschke/go-pd
modulepackage
1.5.0
Repository: https://github.com/manuelreschke/go-pd.git
Documentation: pkg.go.dev

# README

Version GitHub GitHub code size in bytes GitHub go.mod Go version GitHub top language

Go-PD - A pixeldrain.com client pkg and CLI tool

Go-PD

A free pixeldrain.com client written in go. We use the super power from imroc/req (v0.3.2) to build a robust and fast pixeldrain client and cobra for our CLI tool.

Go-PD

Content:

Using the CLI tool

CLI Tool: Install

Follow the link to download the correct binary for your system. View Releases. It's available for Linux, ARM and Windows. Download the correct archive, extract it and use the binary.

CLI Tool: Upload a file

Go to the folder where you download the binary file and run the following command in a CLI.

Simple upload:

 ./go-pd upload my-cat.jpg
 
 Output:
 https://pixeldrain.com/u/aaaaaaaa

Upload to your account (-verbose):

 ./go-pd upload -k <your-api-key> -v my-cat.jpg my-cat2.jpg
 
 Output:
 Successful! Anonymous upload: false | ID: xBxxxxxx | URL: https://pixeldrain.com/u/xBxxxxxx
 Successful! Anonymous upload: false | ID: xAxxxxxx | URL: https://pixeldrain.com/u/xAxxxxxx

CLI Tool: Download a file

Go to the folder where you download the binary file and run the following command in a CLI.

Simple download:

 ./go-pd download https://pixeldrain.com/u/YqiUjXXX
 
 Output:
 /the/path/to/your/file

Download multiple files to a specific path (-verbose):

 ./go-pd download -k <your-api-key> -p /home/pixeldrain/pictures/ YqiUjXXX YqiUjX02 YqiUjX03
 
 Output:
 Successful! Download complete: filename01.jpg | ID: xBxxxxxx | Stored to: /home/pixeldrain/pictures/filename01.jpg
 Successful! Download complete: filename02.jpg | ID: xBxxxxxx | Stored to: /home/pixeldrain/pictures/filename02.jpg
 Successful! Download complete: filename03.jpg | ID: xBxxxxxx | Stored to: /home/pixeldrain/pictures/filename03.jpg

Using the client pkg

Why the package?

Because we want a simple, fast, robust and tested go package to upload to pixeldrain.com.

Import the pkg

 go get github.com/ManuelReschke/go-pd/pkg/pd

Example 1 - the easiest way to upload an anonymous file

package main

import (
	"fmt"
	"time"

	"github.com/ManuelReschke/go-pd/pkg/pd"
)

func main() {
	req := &pd.RequestUpload{
		PathToFile: "testdata/cat.jpg",
		Anonymous:  true,
	}

	c := pd.New(nil, nil)
	rsp, err := c.UploadPOST(req)
	if err != nil {
		fmt.Println(err)
	}

	// print the full URL
	fmt.Println(rsp.GetFileURL())

        // example ID = xFNz76Vp
        // example URL = https://pixeldrain.com/u/xFNz76Vp
}

Example 2 - advanced way to upload a file to user account

package main

import (
	"fmt"
	"time"

	"github.com/ManuelReschke/go-pd/pkg/pd"
)

func main() {
	req := &pd.RequestUpload{
		PathToFile: "testdata/cat.jpg",
		FileName:   "test_post_cat.jpg",
		Anonymous:  false,
		Auth: pd.Auth{
			APIKey: "you-api-key-from-pixeldrain-account",
		},
	}

	// set specific request options
	opt := &pd.ClientOptions{
		Debug:             false,
		ProxyURL:          "example.socks5.proxy",
		EnableCookies:     true,
		EnableInsecureTLS: true,
		Timeout:           1 * time.Hour,
	}

	c := pd.New(opt, nil)
	rsp, err := c.UploadPOST(req)
	if err != nil {
		fmt.Println(err)
	}

	// print the full URL
	fmt.Println(rsp.GetFileURL())

        // example ID = xFNz76Vp
        // example URL = https://pixeldrain.com/u/xFNz76Vp
}

ToDo's:

  • implement simple upload method over POST /file
  • implement simple upload over PUT /file/{filename}
  • write unit tests
  • write integration tests
  • add API-KEY auth to requests
  • implement all other API methods
    • implement GET - /file/{id}
    • implement GET - /file/{id}/info
    • implement GET - /file/{id}/thumbnail?width=x&height=x
    • implement DELETE - /file/{id}
    • implement POST - /list
    • implement GET - /list/{id}
    • implement GET - /user
    • implement GET - /user/files
    • implement GET - /user/lists
  • create CLI tool for uploading to pixeldrain.com
  • refactor the hole shit and use nice to have patterns (like Option Pattern)
  • update imroc/req to the latest version (check if memory leak exist)

PixelDrain methods covered by this package

File Methods

PixelDrain CallPackage Func
[x] POST - /fileUploadPOST(r *RequestUpload) (*ResponseUpload, error)
[x] PUT - /file/{name}UploadPUT(r *RequestUpload) (*ResponseUpload, error)
[x] GET - /file/{id}Download(r *RequestDownload) (*ResponseDownload, error)
[x] GET - /file/{id}/infoGetFileInfo(r *RequestFileInfo) (*ResponseFileInfo, error)
[x] GET - /file/{id}/thumbnail?width=x&height=xDownloadThumbnail(r *RequestThumbnail) (*ResponseThumbnail, error)
[x] DELETE - /file/{id}Delete(r *RequestDelete) (*ResponseDelete, error)

List Methods

PixelDrain CallPackage Func
[x] POST - /listCreateList(r *RequestCreateList) (*ResponseCreateList, error)
[x] GET - /list/{id}GetList(r *RequestGetList) (*ResponseGetList, error)

User Methods

PixelDrain CallPackage Func
[x] GET - /userGetUser(r *RequestGetUser) (*ResponseGetUser, error)
[x] POST - /user/filesGetUserFiles(r *RequestGetUserFiles) (*ResponseGetUserFiles, error)
[x] GET - /user/listsGetUserLists(r *RequestGetUserLists) (*ResponseGetUserLists, error)

Package CLI commands

Unit Tests - Run pkg unit tests

Run unit tests against a local emulated server.

make test

Integration Tests - Run pkg integration tests

Run real integration tests against the real pixeldrain.com website.

make test-integration

Test Coverage - create test coverage report

Create a coverage report c.out and a coverage.html to view the results in web browser

make coverage

Thanks to

Special thanks to Visual Studio Code and to Jetbrains for this amazing IDE and supporting the open source community.

License

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

# Packages

No description provided by the author
No description provided by the author