Init
This commit is contained in:
40
pixelapi/fileInfo.go
Normal file
40
pixelapi/fileInfo.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package pixelapi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"fornaxian.com/pixeldrain-web/conf"
|
||||
"fornaxian.com/pixeldrain-web/log"
|
||||
)
|
||||
|
||||
// FileInfo File information object from the pixeldrain API
|
||||
type FileInfo struct {
|
||||
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"`
|
||||
Thumbnail string `json:"thumbnail"`
|
||||
}
|
||||
|
||||
// GetFileInfo gets the FileInfo from the pixeldrain API
|
||||
func GetFileInfo(id string) *FileInfo {
|
||||
body, err := get(conf.ApiURL() + "/file/" + id + "/info")
|
||||
|
||||
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
|
||||
}
|
24
pixelapi/request.go
Normal file
24
pixelapi/request.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package pixelapi
|
||||
|
||||
import "net/http"
|
||||
import "io/ioutil"
|
||||
|
||||
func get(url string) (string, error) {
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
client := &http.Client{}
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
bodyBytes, err := ioutil.ReadAll(resp.Body)
|
||||
|
||||
return string(bodyBytes), err
|
||||
}
|
Reference in New Issue
Block a user