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.

77 lines
2.2 KiB

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