Browse Source

Add types

master
Wim Brand 4 years ago
parent
commit
d3418ced63
  1. 29
      pixelapi/admin.go
  2. 56
      pixelapi/file.go
  3. 50
      pixelapi/filesystem.go
  4. 23
      pixelapi/list.go
  5. 9
      pixelapi/misc.go
  6. 22
      pixelapi/patreon.go
  7. 30
      pixelapi/subscription.go
  8. 42
      pixelapi/user.go

29
pixelapi/admin.go

@ -2,12 +2,33 @@ package pixelapi
import (
"net/url"
"fornaxian.tech/pixeldrain_server/api/restapi/apitype"
"time"
)
// AdminGlobal is a global setting in pixeldrain's back-end
type AdminGlobal struct {
Key string `json:"key"`
Value string `json:"value"`
}
// AdminBlockFiles is an array of files which were blocked
type AdminBlockFiles struct {
FilesBlocked []string `json:"files_blocked"`
}
// AdminAbuseReporter is an e-mail address which is allowed to send abuse
// reports to abuse@pixeldrain.com
type AdminAbuseReporter struct {
Email string `json:"email"`
Name string `json:"name"`
Type string `json:"type"`
Created time.Time `json:"created"`
FilesBlocked int `json:"files_blocked"`
LastUsed time.Time `json:"last_used"`
}
// AdminGetGlobals returns the global API settings
func (p *PixelAPI) AdminGetGlobals() (resp []apitype.AdminGlobal, err error) {
func (p *PixelAPI) AdminGetGlobals() (resp []AdminGlobal, err error) {
return resp, p.jsonRequest("GET", "admin/globals", &resp)
}
@ -17,7 +38,7 @@ func (p *PixelAPI) AdminSetGlobals(key, value string) (err error) {
}
// AdminBlockFiles blocks files from being downloaded
func (p *PixelAPI) AdminBlockFiles(text, abuseType, reporter string) (bl apitype.AdminBlockFiles, err error) {
func (p *PixelAPI) AdminBlockFiles(text, abuseType, reporter string) (bl AdminBlockFiles, err error) {
return bl, p.form(
"POST", "admin/block_files",
url.Values{"text": {text}, "type": {abuseType}, "reporter": {reporter}},

56
pixelapi/file.go

@ -3,10 +3,60 @@ package pixelapi
import (
"io"
"net/url"
"fornaxian.tech/pixeldrain_server/api/restapi/apitype"
"time"
)
// FileID is returned when a file has been sucessfully uploaded
type FileID struct {
Success bool `json:"success"`
ID string `json:"id"`
}
// FileInfo is the public file information response
type FileInfo struct {
Success bool `json:"success"`
ID string `json:"id"`
Name string `json:"name"`
Size int64 `json:"size"`
Views int64 `json:"views"`
BandwidthUsed int64 `json:"bandwidth_used"`
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"`
Availability string `json:"availability"`
AvailabilityMessage string `json:"availability_message"`
AvailabilityName string `json:"availability_name"`
AbuseType string `json:"abuse_type"`
AbuseReporterName string `json:"abuse_reporter_name"`
CanEdit bool `json:"can_edit"`
ShowAds bool `json:"show_ads"`
}
// FileStats contains realtime statistics for a file
type FileStats struct {
Views int64 `json:"views"`
Bandwidth int64 `json:"bandwidth"`
Downloads int64 `json:"downloads"`
}
// FileTimeSeries returns historic data for a file
type FileTimeSeries struct {
Views TimeSeries `json:"views"`
Downloads TimeSeries `json:"downloads"`
Bandwidth TimeSeries `json:"bandwidth"`
}
// TimeSeries contains data captures over a time span
type TimeSeries struct {
Timestamps []time.Time `json:"timestamps"`
Amounts []int64 `json:"amounts"`
}
// GetFile makes a file download request and returns a readcloser. Don't forget
// to close it!
func (p *PixelAPI) GetFile(id string) (io.ReadCloser, error) {
@ -14,7 +64,7 @@ func (p *PixelAPI) GetFile(id string) (io.ReadCloser, error) {
}
// GetFileInfo gets the FileInfo from the pixeldrain API
func (p *PixelAPI) GetFileInfo(id string) (resp apitype.FileInfo, err error) {
func (p *PixelAPI) GetFileInfo(id string) (resp FileInfo, err error) {
return resp, p.jsonRequest("GET", "file/"+id+"/info", &resp)
}

50
pixelapi/filesystem.go

@ -2,17 +2,59 @@ package pixelapi
import (
"net/url"
"fornaxian.tech/pixeldrain_server/api/restapi/apitype"
"time"
)
// Bucket holds a filesystem
type Bucket struct {
Name string `json:"name"`
ID string `json:"id"`
DateCreated time.Time `json:"date_created"`
DateModified time.Time `json:"date_modified"`
ReadPassword string `json:"read_password"`
WritePassword string `json:"write_password"`
Properties map[string]string `json:"properties"`
Permissions Permissions `json:"permissions"`
}
// FilesystemPath contains a filesystem with a bucket and all its children
// leading up to the requested node
type FilesystemPath struct {
Bucket Bucket `json:"bucket"`
Parents []FilesystemNode `json:"parents"`
Base FilesystemNode `json:"base"`
}
// FilesystemNode is the return value of the GET /filesystem/ API
type FilesystemNode struct {
Type string `json:"type"`
Path string `json:"path"`
Name string `json:"name"`
DateCreated time.Time `json:"date_created"`
DateModified time.Time `json:"date_modified"`
// File params
FileSize int64 `json:"file_size"`
FileType string `json:"file_type"`
Children []FilesystemNode `json:"children"`
}
// Permissions contains the actions a user can perform on an object
type Permissions struct {
Create bool `json:"create"`
Read bool `json:"read"`
Update bool `json:"update"`
Delete bool `json:"delete"`
}
// GetFilesystemBuckets returns a list of buckets for the user. You need to be
// authenticated
func (p *PixelAPI) GetFilesystemBuckets() (resp []apitype.Bucket, err error) {
func (p *PixelAPI) GetFilesystemBuckets() (resp []Bucket, err error) {
return resp, p.jsonRequest("GET", "filesystem", &resp)
}
// GetFilesystemPath opens a filesystem path
func (p *PixelAPI) GetFilesystemPath(path string) (resp apitype.FilesystemPath, err error) {
func (p *PixelAPI) GetFilesystemPath(path string) (resp FilesystemPath, err error) {
return resp, p.jsonRequest("GET", "filesystem/"+url.PathEscape(path)+"?stat", &resp)
}

23
pixelapi/list.go

@ -1,8 +1,27 @@
package pixelapi
import "fornaxian.tech/pixeldrain_server/api/restapi/apitype"
import (
"time"
)
// ListInfo information object from the pixeldrain API
type ListInfo struct {
Success bool `json:"success"`
ID string `json:"id"`
Title string `json:"title"`
DateCreated time.Time `json:"date_created"`
FileCount int `json:"file_count"`
Files []ListFile `json:"files"`
}
// ListFile information object from the pixeldrain API
type ListFile struct {
DetailHREF string `json:"detail_href"`
Description string `json:"description"`
FileInfo `json:""`
}
// GetListID get a List from the pixeldrain API
func (p *PixelAPI) GetListID(id string) (resp apitype.ListInfo, err error) {
func (p *PixelAPI) GetListID(id string) (resp ListInfo, err error) {
return resp, p.jsonRequest("GET", "list/"+id, &resp)
}

9
pixelapi/misc.go

@ -1,7 +1,5 @@
package pixelapi
import "fornaxian.tech/pixeldrain_server/api/restapi/apitype"
// Recaptcha stores the reCaptcha site key
type Recaptcha struct {
SiteKey string `json:"site_key"`
@ -20,8 +18,13 @@ func (p *PixelAPI) GetMiscViewToken() (resp string, err error) {
return resp, p.jsonRequest("GET", "misc/viewtoken", &resp)
}
// SiaPrice is the price of one siacoin
type SiaPrice struct {
Price float64 `json:"price"`
}
// GetSiaPrice gets the price of one siacoin
func (p *PixelAPI) GetSiaPrice() (resp float64, err error) {
var sp apitype.SiaPrice
var sp SiaPrice
return sp.Price, p.jsonRequest("GET", "misc/sia_price", &sp)
}

22
pixelapi/patreon.go

@ -1,11 +1,25 @@
package pixelapi
import (
"fornaxian.tech/pixeldrain_server/api/restapi/apitype"
)
import "time"
// Patron is a backer on pixeldrain's patreon campaign
type Patron struct {
PatreonUserID string `json:"patreon_user_id"`
ClaimID string `json:"claim_id"`
CampaignID string `json:"campaign_id"`
FullName string `json:"full_name"`
LastChargeDate time.Time `json:"last_charge_date"`
LastChargeStatus string `json:"last_charge_status"`
LifetimeSupportCents int `json:"lifetime_support_cents"`
PatronStatus string `json:"patron_status"`
PledgeAmountCents int `json:"pledge_amount_cents"`
PledgeRelationshipStart time.Time `json:"pledge_relationship_start"`
UserEmail string `json:"user_email"`
Subscription SubscriptionType `json:"subscription"`
}
// GetPatreonByID returns information about a patron by the ID
func (p *PixelAPI) GetPatreonByID(id string) (resp apitype.Patron, err error) {
func (p *PixelAPI) GetPatreonByID(id string) (resp Patron, err error) {
return resp, p.jsonRequest("GET", "patreon/"+id, &resp)
}

30
pixelapi/subscription.go

@ -2,12 +2,38 @@ package pixelapi
import (
"net/url"
"time"
"fornaxian.tech/pixeldrain_server/api/restapi/apitype"
"github.com/gocql/gocql"
)
// Subscription contains information about a user's subscription. When it
// started, when it ends, and what type of subscription it is
type Subscription struct {
ID gocql.UUID `json:"id"`
Used bool `json:"used"`
DurationDays int `json:"duration_days"`
StartTime time.Time `json:"start_date"`
WarningDate time.Time `json:"warning_date"`
EndDate time.Time `json:"end_date"`
SubscriptionType SubscriptionType `json:"subscription_type"`
}
// SubscriptionType contains information about a subscription type. It's not the
// active subscription itself, only the properties of the subscription. Like the
// perks and cost
type SubscriptionType struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
DisableAdDisplay bool `json:"disable_ad_display"`
DisableAdsOnFiles bool `json:"disable_ads_on_files"`
FileSizeLimit int64 `json:"file_size_limit"`
FileExpiryDays int `json:"file_expiry_days"`
}
// GetSubscriptionID returns the subscription object identified by the given ID
func (p *PixelAPI) GetSubscriptionID(id string) (resp apitype.Subscription, err error) {
func (p *PixelAPI) GetSubscriptionID(id string) (resp Subscription, err error) {
return resp, p.jsonRequest("GET", p.apiEndpoint+"/subscription/"+url.PathEscape(id), &resp)
}

42
pixelapi/user.go

@ -3,10 +3,28 @@ package pixelapi
import (
"net/url"
"strconv"
"time"
"fornaxian.tech/pixeldrain_server/api/restapi/apitype"
"github.com/gocql/gocql"
)
// UserInfo contains information about the logged in user
type UserInfo struct {
Username string `json:"username"`
Email string `json:"email"`
Subscription SubscriptionType `json:"subscription"`
IsAdmin bool `json:"is_admin"`
}
// UserSession is one user session
type UserSession struct {
AuthKey gocql.UUID `json:"auth_key"`
CreationIP string `json:"creation_ip_address"`
UserAgent string `json:"user_agent"`
CreationTime time.Time `json:"creation_time"`
LastUsedTime time.Time `json:"last_used_time"`
}
// UserRegister registers a new user on the Pixeldrain server. username and
// password are always required. email is optional, but without it you will not
// be able to reset your password in case you forget it. captcha depends on
@ -33,7 +51,7 @@ func (p *PixelAPI) UserRegister(username, email, password, captcha string) (err
// contain the returned API key. If saveKey is true the API key will also be
// saved in the client and following requests with this client will be
// autenticated
func (p *PixelAPI) PostUserLogin(username, password string) (resp apitype.UserSession, err error) {
func (p *PixelAPI) PostUserLogin(username, password string) (resp UserSession, err error) {
return resp, p.form(
"POST", "user/login",
url.Values{"username": {username}, "password": {password}},
@ -42,17 +60,17 @@ func (p *PixelAPI) PostUserLogin(username, password string) (resp apitype.UserSe
}
// GetUser returns information about the logged in user. Requires an API key
func (p *PixelAPI) GetUser() (resp apitype.UserInfo, err error) {
func (p *PixelAPI) GetUser() (resp UserInfo, err error) {
return resp, p.jsonRequest("GET", "user", &resp)
}
// PostUserSession creates a new user sessions
func (p *PixelAPI) PostUserSession() (resp apitype.UserSession, err error) {
func (p *PixelAPI) PostUserSession() (resp UserSession, err error) {
return resp, p.jsonRequest("POST", "user/session", &resp)
}
// GetUserSession lists all active user sessions
func (p *PixelAPI) GetUserSession() (resp []apitype.UserSession, err error) {
func (p *PixelAPI) GetUserSession() (resp []UserSession, err error) {
return resp, p.jsonRequest("GET", "user/session", &resp)
}
@ -62,13 +80,23 @@ func (p *PixelAPI) DeleteUserSession(key string) (err error) {
return p.jsonRequest("DELETE", "user/session", nil)
}
// FileInfoSlice a collection of files which belong to a user
type FileInfoSlice struct {
Files []FileInfo `json:"files"`
}
// GetUserFiles gets files uploaded by a user
func (p *PixelAPI) GetUserFiles() (resp apitype.FileInfoSlice, err error) {
func (p *PixelAPI) GetUserFiles() (resp FileInfoSlice, err error) {
return resp, p.jsonRequest("GET", "user/files", &resp)
}
// ListInfoSlice is a collection of lists which belong to a user
type ListInfoSlice struct {
Lists []ListInfo `json:"lists"`
}
// GetUserLists gets lists created by a user
func (p *PixelAPI) GetUserLists() (resp apitype.ListInfoSlice, err error) {
func (p *PixelAPI) GetUserLists() (resp ListInfoSlice, err error) {
return resp, p.jsonRequest("GET", "user/lists", &resp)
}

Loading…
Cancel
Save