Files
fnx_web/pixelapi/file.go

37 lines
1.0 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"
"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"`
Views int `json:"views"`
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"`
2017-11-10 12:39:55 +01:00
}
// GetFileInfo gets the FileInfo from the pixeldrain API
2018-07-09 21:41:17 +02:00
func (p *PixelAPI) GetFileInfo(id string) (resp *FileInfo, err error) {
resp = &FileInfo{}
2018-06-23 21:17:53 +02:00
err = p.jsonRequest("GET", p.apiEndpoint+"/file/"+id+"/info", resp)
2017-11-10 12:39:55 +01:00
if err != nil {
return nil, err
2017-11-10 12:39:55 +01:00
}
return resp, nil
2017-11-10 12:39:55 +01:00
}