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.

68 lines
2.1 KiB

4 years ago
4 years ago
4 years ago
4 years ago
  1. package pixelapi
  2. import (
  3. "net/url"
  4. "time"
  5. "github.com/gocql/gocql"
  6. )
  7. // AdminGlobal is a global setting in pixeldrain's back-end
  8. type AdminGlobal struct {
  9. Key string `json:"key"`
  10. Value string `json:"value"`
  11. }
  12. // AdminBlockFiles is an array of files which were blocked
  13. type AdminBlockFiles struct {
  14. FilesBlocked []string `json:"files_blocked"`
  15. }
  16. // AdminAbuseReporter is an e-mail address which is allowed to send abuse
  17. // reports to abuse@pixeldrain.com
  18. type AdminAbuseReporter struct {
  19. Email string `json:"email"`
  20. Name string `json:"name"`
  21. Type string `json:"type"`
  22. Created time.Time `json:"created"`
  23. FilesBlocked int `json:"files_blocked"`
  24. LastUsed time.Time `json:"last_used"`
  25. }
  26. type AdminAbuseReportContainer struct {
  27. ID gocql.UUID `json:"id"`
  28. Reports []AdminAbuseReport `json:"reports"`
  29. File FileInfo `json:"file"`
  30. Type string `json:"type"`
  31. Status string `json:"status"`
  32. FirstReportTime time.Time `json:"first_report_time"`
  33. }
  34. // AdminAbuseReport is a report someone submitted for a file
  35. type AdminAbuseReport struct {
  36. FileInstanceID gocql.UUID `json:"file_id"`
  37. IPAddress string `json:"ip_address"`
  38. Time time.Time `json:"time"`
  39. Status string `json:"status"` // pending, rejected, granted
  40. Type string `json:"type"`
  41. EMail string `json:"email"`
  42. }
  43. // AdminGetGlobals returns the global API settings
  44. func (p *PixelAPI) AdminGetGlobals() (resp []AdminGlobal, err error) {
  45. return resp, p.jsonRequest("GET", "admin/globals", &resp)
  46. }
  47. // AdminSetGlobals sets a global API setting
  48. func (p *PixelAPI) AdminSetGlobals(key, value string) (err error) {
  49. return p.form("POST", "admin/globals", url.Values{"key": {key}, "value": {value}}, nil)
  50. }
  51. // AdminBlockFiles blocks files from being downloaded
  52. func (p *PixelAPI) AdminBlockFiles(text, abuseType, reporter string) (bl AdminBlockFiles, err error) {
  53. return bl, p.form(
  54. "POST", "admin/block_files",
  55. url.Values{"text": {text}, "type": {abuseType}, "reporter": {reporter}},
  56. &bl,
  57. )
  58. }