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.

47 lines
1.4 KiB

4 years ago
4 years ago
4 years ago
4 years ago
  1. package pixelapi
  2. import (
  3. "net/url"
  4. "time"
  5. )
  6. // AdminGlobal is a global setting in pixeldrain's back-end
  7. type AdminGlobal struct {
  8. Key string `json:"key"`
  9. Value string `json:"value"`
  10. }
  11. // AdminBlockFiles is an array of files which were blocked
  12. type AdminBlockFiles struct {
  13. FilesBlocked []string `json:"files_blocked"`
  14. }
  15. // AdminAbuseReporter is an e-mail address which is allowed to send abuse
  16. // reports to abuse@pixeldrain.com
  17. type AdminAbuseReporter struct {
  18. Email string `json:"email"`
  19. Name string `json:"name"`
  20. Type string `json:"type"`
  21. Created time.Time `json:"created"`
  22. FilesBlocked int `json:"files_blocked"`
  23. LastUsed time.Time `json:"last_used"`
  24. }
  25. // AdminGetGlobals returns the global API settings
  26. func (p *PixelAPI) AdminGetGlobals() (resp []AdminGlobal, err error) {
  27. return resp, p.jsonRequest("GET", "admin/globals", &resp)
  28. }
  29. // AdminSetGlobals sets a global API setting
  30. func (p *PixelAPI) AdminSetGlobals(key, value string) (err error) {
  31. return p.form("POST", "admin/globals", url.Values{"key": {key}, "value": {value}}, nil)
  32. }
  33. // AdminBlockFiles blocks files from being downloaded
  34. func (p *PixelAPI) AdminBlockFiles(text, abuseType, reporter string) (bl AdminBlockFiles, err error) {
  35. return bl, p.form(
  36. "POST", "admin/block_files",
  37. url.Values{"text": {text}, "type": {abuseType}, "reporter": {reporter}},
  38. &bl,
  39. )
  40. }