This commit is contained in:
2017-11-10 12:39:55 +01:00
commit 5a752618c3
579 changed files with 81271 additions and 0 deletions

40
pixelapi/fileInfo.go Normal file
View 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
View 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
}