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.

75 lines
2.3 KiB

4 years ago
4 years ago
3 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. type AdminIPBan struct {
  44. Address string `json:"address"`
  45. BanTime time.Time `json:"ban_time"`
  46. ExpireTime time.Time `json:"expire_time"`
  47. Reason string `json:"reason"`
  48. }
  49. // AdminGetGlobals returns the global API settings
  50. func (p *PixelAPI) AdminGetGlobals() (resp []AdminGlobal, err error) {
  51. return resp, p.jsonRequest("GET", "admin/globals", &resp)
  52. }
  53. // AdminSetGlobals sets a global API setting
  54. func (p *PixelAPI) AdminSetGlobals(key, value string) (err error) {
  55. return p.form("POST", "admin/globals", url.Values{"key": {key}, "value": {value}}, nil)
  56. }
  57. // AdminBlockFiles blocks files from being downloaded
  58. func (p *PixelAPI) AdminBlockFiles(text, abuseType, reporter string) (bl AdminBlockFiles, err error) {
  59. return bl, p.form(
  60. "POST", "admin/block_files",
  61. url.Values{"text": {text}, "type": {abuseType}, "reporter": {reporter}},
  62. &bl,
  63. )
  64. }