Files
fnx_web/pixelapi/file.go

48 lines
1.3 KiB
Go
Raw Normal View History

2017-11-10 12:39:55 +01:00
package pixelapi
import (
"encoding/json"
2018-01-07 21:42:19 +01:00
"io"
2017-11-10 12:39:55 +01:00
"fornaxian.com/pixeldrain-web/conf"
"fornaxian.com/pixeldrain-web/log"
)
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 GetFile(id string) (io.ReadCloser, error) {
return getRaw(conf.ApiUrlInternal() + "/file/" + id)
}
2017-11-10 12:39:55 +01:00
// FileInfo File information object from the pixeldrain API
type FileInfo struct {
2017-12-17 23:34:49 +01:00
ID string `json:"id"`
FileName string `json:"file_name"`
DateUpload int64 `json:"date_upload"`
DateLastview int64 `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 GetFileInfo(id string) *FileInfo {
2018-01-07 21:42:19 +01:00
body, err := getString(conf.ApiUrlInternal() + "/file/" + id + "/info")
2017-11-10 12:39:55 +01:00
if err != nil {
log.Error("req failed: %v", err)
return nil
}
var fileInfo FileInfo
err = json.Unmarshal([]byte(body), &fileInfo)
if err != nil {
log.Error("unmarshal failed: %v. json: %s", err, body)
return nil
}
return &fileInfo
}