pd

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Name             = "PixelDrain.com"
	BaseURL          = "https://pixeldrain.com/"
	APIURL           = BaseURL + "api"
	DefaultUserAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36"
	// errors
	ErrMissingPathToFile = "file path or file reader is required"
	ErrMissingFileID     = "file id is required"
	ErrMissingFilename   = "if you use ReadCloser you need to specify the filename"
)

Variables

This section is empty.

Functions

func MockFileUploadServer

func MockFileUploadServer() *httptest.Server

Types

type Auth

type Auth struct {
	APIKey string // if you have an account you can enter here your API Key for uploading in your account
}

Auth hold the auth information

func (*Auth) IsAuthAvailable

func (a *Auth) IsAuthAvailable() bool

IsAuthAvailable checks if an API Key available

type Client

type Client struct {
	Header  req.Header
	Request *req.Req
}

type ClientOptions

type ClientOptions struct {
	Debug             bool
	ProxyURL          string
	EnableCookies     bool
	EnableInsecureTLS bool
	Timeout           time.Duration
}

type FileGetList

type FileGetList struct {
	DetailHref    string    `json:"detail_href"`
	Description   string    `json:"description"`
	Success       bool      `json:"success"`
	ID            string    `json:"id"`
	Name          string    `json:"name"`
	Size          int64     `json:"size"`
	DateCreated   time.Time `json:"date_created"`
	DateLastView  time.Time `json:"date_last_view"`
	MimeType      string    `json:"mime_type"`
	Views         int64     `json:"views"`
	BandwidthUsed int64     `json:"bandwidth_used"`
	ThumbnailHref string    `json:"thumbnail_href"`
}

type FileGetUser

type FileGetUser struct {
	ID                  string    `json:"id"`
	Name                string    `json:"name"`
	Size                int64     `json:"size"`
	Views               int64     `json:"views"`
	BandwidthUsed       int64     `json:"bandwidth_used"`
	BandwidthUsedPaid   int64     `json:"bandwidth_used_paid"`
	Downloads           int64     `json:"downloads"`
	DateUpload          time.Time `json:"date_upload"`
	DateLastView        time.Time `json:"date_last_view"`
	MimeType            string    `json:"mime_type"`
	ThumbnailHref       string    `json:"thumbnail_href"`
	HashSha256          string    `json:"hash_sha256"`
	Availability        string    `json:"availability"`
	AvailabilityMessage string    `json:"availability_message"`
	AbuseType           string    `json:"abuse_type"`
	AbuseReporterName   string    `json:"abuse_reporter_name"`
	CanEdit             bool      `json:"can_edit"`
	ShowAds             bool      `json:"show_ads"`
	AllowVideoPlayer    bool      `json:"allow_video_player"`
	DownloadSpeedLimit  int64     `json:"download_speed_limit"`
}

type GetUserSubscription added in v1.3.0

type GetUserSubscription struct {
	ID                  string `json:"id"`
	Name                string `json:"name"`
	Type                string `json:"type"`
	FileSizeLimit       int64  `json:"file_size_limit"`
	FileExpiryDays      int64  `json:"file_expiry_days"`
	StorageSpace        int64  `json:"storage_space"`
	PricePerTbStorage   int64  `json:"price_per_tb_storage"`
	PricePerTbBandwidth int64  `json:"price_per_tb_bandwidth"`
	MonthlyTransferCap  int64  `json:"monthly_transfer_cap"`
	FileViewerBranding  bool   `json:"file_viewer_branding"`
}

type ListFile

type ListFile struct {
	ID          string `json:"id"`
	Description string `json:"description"`
}

ListFile a file inside a CreateList request

type ListsGetUser

type ListsGetUser struct {
	ID          string      `json:"id"`
	Title       string      `json:"title"`
	DateCreated time.Time   `json:"date_created"`
	FileCount   int64       `json:"file_count"`
	Files       interface{} `json:"files"`
	CanEdit     bool        `json:"can_edit"`
}

type PixelDrainClient

type PixelDrainClient struct {
	Client *Client
	Debug  bool
}

func New

func New(opt *ClientOptions, c *Client) *PixelDrainClient

New - create a new PixelDrainClient

func (*PixelDrainClient) CreateList

CreateList POST /api/list

func (*PixelDrainClient) Delete

Delete DELETE /api/file/{id}

func (*PixelDrainClient) Download

Download GET /api/file/{id}

func (*PixelDrainClient) DownloadThumbnail

func (pd *PixelDrainClient) DownloadThumbnail(r *RequestThumbnail) (*ResponseThumbnail, error)

DownloadThumbnail GET /api/file/{id}/thumbnail?width=x&height=x

func (*PixelDrainClient) GetFileInfo

func (pd *PixelDrainClient) GetFileInfo(r *RequestFileInfo) (*ResponseFileInfo, error)

GetFileInfo GET /api/file/{id}/info

func (*PixelDrainClient) GetList

GetList GET /api/list/{id}

func (*PixelDrainClient) GetUser added in v1.3.0

GetUser GET /api/user

func (*PixelDrainClient) GetUserFiles

GetUserFiles GET /api/user/files

func (*PixelDrainClient) GetUserLists

GetUserLists GET /api/user/lists

func (*PixelDrainClient) UploadPOST

func (pd *PixelDrainClient) UploadPOST(r *RequestUpload) (*ResponseUpload, error)

UploadPOST POST /api/file curl -X POST -i -H "Authorization: Basic <TOKEN>" -F "file=@cat.jpg" https://pixeldrain.com/api/file

func (*PixelDrainClient) UploadPUT

func (pd *PixelDrainClient) UploadPUT(r *RequestUpload) (*ResponseUpload, error)

UploadPUT PUT /api/file/{name} curl -X PUT -i -H "Authorization: Basic <TOKEN>" --upload-file cat.jpg https://pixeldrain.com/api/file/test_cat.jpg

type RequestCreateList

type RequestCreateList struct {
	Title     string     `json:"title"`
	Anonymous bool       `json:"anonymous"`
	Files     []ListFile `json:"files"`
	Auth      Auth
	URL       string
}

RequestCreateList parameters for creating new list

type RequestDelete

type RequestDelete struct {
	ID   string
	Auth Auth
	URL  string
}

RequestDelete delete the file if you are the owner with the given ID

type RequestDownload

type RequestDownload struct {
	ID         string
	PathToSave string
	Auth       Auth
	URL        string // specific the API endpoint, is set by default with the correct values
}

RequestDownload container for the file download

type RequestFileInfo

type RequestFileInfo struct {
	ID   string
	Auth Auth
	URL  string
}

RequestFileInfo the FileInfo request needs only an ID

type RequestGetList

type RequestGetList struct {
	ID   string `json:"id"`
	Auth Auth
	URL  string
}

RequestGetList request to a retrieve a list

type RequestGetUser added in v1.3.0

type RequestGetUser struct {
	Auth Auth
	URL  string
}

RequestGetUser ...

type RequestGetUserFiles

type RequestGetUserFiles struct {
	Auth Auth
	URL  string
}

RequestGetUserFiles ...

type RequestGetUserLists

type RequestGetUserLists struct {
	Auth Auth
	URL  string
}

RequestGetUserLists ...

type RequestThumbnail

type RequestThumbnail struct {
	ID         string
	Width      string
	Height     string
	PathToSave string
	Auth       Auth
	URL        string
}

RequestThumbnail the Thumbnail request needs the ID and width and height

type RequestUpload

type RequestUpload struct {
	File       io.ReadCloser
	PathToFile string // path to the file "/home/user/cat.jpg"
	FileName   string // just the filename "test.jpg"
	Anonymous  bool   // if the upload is anonymous or with auth
	Auth       Auth
	URL        string // specific the upload endpoint, is set by default with the correct values
}

RequestUpload container for the upload information

func (*RequestUpload) GetFileName

func (r *RequestUpload) GetFileName() string

GetFileName return the filename from the path if no specific filename in the params

type ResponseCreateList

type ResponseCreateList struct {
	ID string `json:"id"`
	ResponseDefault
}

type ResponseDefault

type ResponseDefault struct {
	StatusCode int    `json:"status_code"`
	Success    bool   `json:"success"`
	Value      string `json:"value,omitempty"`
	Message    string `json:"message,omitempty"`
}

type ResponseDelete

type ResponseDelete struct {
	ResponseDefault
}

type ResponseDownload

type ResponseDownload struct {
	FilePath string `json:"file_path"`
	FileName string `json:"file_name"`
	FileSize int64  `json:"file_size"`
	ResponseDefault
}

type ResponseFileInfo

type ResponseFileInfo struct {
	ID                string    `json:"id"`
	Name              string    `json:"name"`
	Size              int64     `json:"size"`
	Views             int64     `json:"views"`
	BandwidthUsed     int64     `json:"bandwidth_used"`
	BandwidthUsedPaid int64     `json:"bandwidth_used_paid"`
	Downloads         int64     `json:"downloads"`
	DateUpload        time.Time `json:"date_upload"`
	DateLastView      time.Time `json:"date_last_view"`
	MimeType          string    `json:"mime_type"`
	ThumbnailHref     string    `json:"thumbnail_href"`
	HashSha256        string    `json:"hash_sha256"`
	CanEdit           bool      `json:"can_edit"`
	ResponseDefault
}

type ResponseGetList

type ResponseGetList struct {
	ID          string        `json:"id"`
	Title       string        `json:"title"`
	DateCreated time.Time     `json:"date_created"`
	Files       []FileGetList `json:"files"`
	ResponseDefault
}

type ResponseGetUser added in v1.3.0

type ResponseGetUser struct {
	Username            string              `json:"username"`
	Email               string              `json:"email"`
	Subscription        GetUserSubscription `json:"subscription"`
	StorageSpaceUsed    int64               `json:"storage_space_used"`
	IsAdmin             bool                `json:"is_admin"`
	BalanceMicroEur     int64               `json:"balance_micro_eur"`
	HotlinkingEnabled   bool                `json:"hotlinking_enabled"`
	MonthlyTransferCap  int64               `json:"monthly_transfer_cap"`
	MonthlyTransferUsed int64               `json:"monthly_transfer_used"`
	FileViewerBranding  interface{}         `json:"file_viewer_branding"`
	FileEmbedDomains    string              `json:"file_embed_domains"`
	SkipFileViewer      bool                `json:"skip_file_viewer"`
	ResponseDefault
}

type ResponseGetUserFiles

type ResponseGetUserFiles struct {
	Files []FileGetUser `json:"files"`
	ResponseDefault
}

type ResponseGetUserLists

type ResponseGetUserLists struct {
	Lists []ListsGetUser `json:"lists"`
	ResponseDefault
}

type ResponseThumbnail

type ResponseThumbnail struct {
	FilePath string `json:"file_path"`
	FileName string `json:"file_name"`
	FileSize int64  `json:"file_size"`
	ResponseDefault
}

type ResponseUpload

type ResponseUpload struct {
	ID string `json:"id,omitempty"`
	ResponseDefault
}

func (*ResponseUpload) GetFileURL

func (rsp *ResponseUpload) GetFileURL() string

GetFileURL return the full URl to the uploaded file

Jump to

Keyboard shortcuts

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