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.

60 lines
1.8 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. // Bucket holds a filesystem
  7. type Bucket struct {
  8. Name string `json:"name"`
  9. ID string `json:"id"`
  10. DateCreated time.Time `json:"date_created"`
  11. DateModified time.Time `json:"date_modified"`
  12. ReadPassword string `json:"read_password"`
  13. WritePassword string `json:"write_password"`
  14. Properties map[string]string `json:"properties"`
  15. Permissions Permissions `json:"permissions"`
  16. }
  17. // FilesystemPath contains a filesystem with a bucket and all its children
  18. // leading up to the requested node
  19. type FilesystemPath struct {
  20. Bucket Bucket `json:"bucket"`
  21. Parents []FilesystemNode `json:"parents"`
  22. Base FilesystemNode `json:"base"`
  23. }
  24. // FilesystemNode is the return value of the GET /filesystem/ API
  25. type FilesystemNode struct {
  26. Type string `json:"type"`
  27. Path string `json:"path"`
  28. Name string `json:"name"`
  29. DateCreated time.Time `json:"date_created"`
  30. DateModified time.Time `json:"date_modified"`
  31. // File params
  32. FileSize int64 `json:"file_size"`
  33. FileType string `json:"file_type"`
  34. Children []FilesystemNode `json:"children"`
  35. }
  36. // Permissions contains the actions a user can perform on an object
  37. type Permissions struct {
  38. Create bool `json:"create"`
  39. Read bool `json:"read"`
  40. Update bool `json:"update"`
  41. Delete bool `json:"delete"`
  42. }
  43. // GetFilesystemBuckets returns a list of buckets for the user. You need to be
  44. // authenticated
  45. func (p *PixelAPI) GetFilesystemBuckets() (resp []Bucket, err error) {
  46. return resp, p.jsonRequest("GET", "filesystem", &resp)
  47. }
  48. // GetFilesystemPath opens a filesystem path
  49. func (p *PixelAPI) GetFilesystemPath(path string) (resp FilesystemPath, err error) {
  50. return resp, p.jsonRequest("GET", "filesystem/"+url.PathEscape(path)+"?stat", &resp)
  51. }