Client for the pixeldrain API. Used by pixeldrain itself for tranferring data between the web UI and API server. And for rendering JSON responses
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.2 KiB

4 years ago
4 years ago
4 years ago
  1. package pixelapi
  2. import (
  3. "io"
  4. "net/url"
  5. "time"
  6. )
  7. // FileID is returned when a file has been sucessfully uploaded
  8. type FileID struct {
  9. Success bool `json:"success"`
  10. ID string `json:"id"`
  11. }
  12. // FileInfo is the public file information response
  13. type FileInfo struct {
  14. Success bool `json:"success"`
  15. ID string `json:"id"`
  16. Name string `json:"name"`
  17. Size int64 `json:"size"`
  18. Views int64 `json:"views"`
  19. BandwidthUsed int64 `json:"bandwidth_used"`
  20. Downloads int64 `json:"downloads"`
  21. DateUpload time.Time `json:"date_upload"`
  22. DateLastView time.Time `json:"date_last_view"`
  23. MimeType string `json:"mime_type"`
  24. ThumbnailHREF string `json:"thumbnail_href"`
  25. Availability string `json:"availability"`
  26. AvailabilityMessage string `json:"availability_message"`
  27. AvailabilityName string `json:"availability_name"`
  28. AbuseType string `json:"abuse_type"`
  29. AbuseReporterName string `json:"abuse_reporter_name"`
  30. CanEdit bool `json:"can_edit"`
  31. ShowAds bool `json:"show_ads"`
  32. }
  33. // FileStats contains realtime statistics for a file
  34. type FileStats struct {
  35. Views int64 `json:"views"`
  36. Bandwidth int64 `json:"bandwidth"`
  37. Downloads int64 `json:"downloads"`
  38. }
  39. // FileTimeSeries returns historic data for a file
  40. type FileTimeSeries struct {
  41. Views TimeSeries `json:"views"`
  42. Downloads TimeSeries `json:"downloads"`
  43. Bandwidth TimeSeries `json:"bandwidth"`
  44. }
  45. // TimeSeries contains data captures over a time span
  46. type TimeSeries struct {
  47. Timestamps []time.Time `json:"timestamps"`
  48. Amounts []int64 `json:"amounts"`
  49. }
  50. // GetFile makes a file download request and returns a readcloser. Don't forget
  51. // to close it!
  52. func (p *PixelAPI) GetFile(id string) (io.ReadCloser, error) {
  53. return p.getRaw("file/" + id)
  54. }
  55. // GetFileInfo gets the FileInfo from the pixeldrain API
  56. func (p *PixelAPI) GetFileInfo(id string) (resp FileInfo, err error) {
  57. return resp, p.jsonRequest("GET", "file/"+id+"/info", &resp)
  58. }
  59. // PostFileView adds a view to a file
  60. func (p *PixelAPI) PostFileView(id, viewtoken string) (err error) {
  61. return p.form("POST", "file/"+id+"/view", url.Values{"token": {viewtoken}}, nil)
  62. }