Files
fnx_web/pixelapi/file.go

38 lines
1.1 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 {
ID string `json:"id"`
FileName string `json:"file_name"`
DateUpload time.Time `json:"date_upload"`
DateLastview time.Time `json:"date_last_view"`
DaysValid uint16 `json:"days_valid"`
FileSize uint64 `json:"file_size"`
Views uint `json:"views"`
MimeType string `json:"mime_type"`
Description string `json:"description"`
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
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
}