Files
fnx_web/pixelapi/file.go

46 lines
1.4 KiB
Go
Raw Normal View History

2017-11-10 12:39:55 +01:00
package pixelapi
import (
2018-01-07 21:42:19 +01:00
"io"
2020-02-21 13:14:21 +01:00
"net/url"
"time"
2017-11-10 12:39:55 +01:00
)
2018-01-07 21:42:19 +01:00
// GetFile makes a file download request and returns a readcloser. Don't forget
// to close it!
func (p *PixelAPI) GetFile(id string) (io.ReadCloser, error) {
2018-06-23 21:17:53 +02:00
return p.getRaw(p.apiEndpoint + "/file/" + id)
2018-01-07 21:42:19 +01:00
}
2017-11-10 12:39:55 +01:00
// FileInfo File information object from the pixeldrain API
type FileInfo struct {
2018-07-08 14:40:20 +02:00
Success bool `json:"success"`
ID string `json:"id"`
2018-10-04 23:36:34 +02:00
Name string `json:"name"`
Size uint64 `json:"size"`
2019-02-11 22:41:22 +01:00
Views int64 `json:"views"`
2019-03-26 20:53:19 +01:00
BandwidthUsed uint64 `json:"bandwidth_used"`
DateUpload time.Time `json:"date_upload"`
2018-10-04 23:36:34 +02:00
DateLastView time.Time `json:"date_last_view"`
MimeType string `json:"mime_type"`
MimeImage string `json:"mime_image"`
ThumbnailHREF string `json:"thumbnail_href"`
2020-02-18 14:57:27 +01:00
Availability string `json:"availability"`
AvailabilityMessage string `json:"availability_message"`
AvailabilityName string `json:"availability_name"`
CanEdit bool `json:"can_edit"`
2017-11-10 12:39:55 +01:00
}
// GetFileInfo gets the FileInfo from the pixeldrain API
2020-01-21 15:43:09 +01:00
func (p *PixelAPI) GetFileInfo(id string) (resp FileInfo, err error) {
return resp, p.jsonRequest("GET", p.apiEndpoint+"/file/"+id+"/info", &resp)
2017-11-10 12:39:55 +01:00
}
2020-02-21 13:14:21 +01:00
func (p *PixelAPI) PostFileView(id, viewtoken string) (err error) {
vals := url.Values{}
vals.Set("token", viewtoken)
return p.form("POST", p.apiEndpoint+"/file/"+id+"/view", vals, nil, true)
}