Massive graphical overhaul

This commit is contained in:
2018-01-07 21:42:19 +01:00
parent 9a4eddcbd1
commit 636643c9e0
44 changed files with 600 additions and 548 deletions

View File

@@ -2,11 +2,18 @@ package pixelapi
import (
"encoding/json"
"io"
"fornaxian.com/pixeldrain-web/conf"
"fornaxian.com/pixeldrain-web/log"
)
// 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)
}
// FileInfo File information object from the pixeldrain API
type FileInfo struct {
ID string `json:"id"`
@@ -24,7 +31,7 @@ type FileInfo struct {
// GetFileInfo gets the FileInfo from the pixeldrain API
func GetFileInfo(id string) *FileInfo {
body, err := get(conf.ApiUrlInternal() + "/file/" + id + "/info")
body, err := getString(conf.ApiUrlInternal() + "/file/" + id + "/info")
if err != nil {
log.Error("req failed: %v", err)

View File

@@ -28,7 +28,7 @@ type ListFile struct {
// GetList get a List from the pixeldrain API
func GetList(id string) *List {
body, err := get(conf.ApiUrlInternal() + "/list/" + id)
body, err := getString(conf.ApiUrlInternal() + "/list/" + id)
if err != nil {
log.Error("req failed: %v", err)

View File

@@ -2,8 +2,9 @@ package pixelapi
import "net/http"
import "io/ioutil"
import "io"
func get(url string) (string, error) {
func getString(url string) (string, error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return "", err
@@ -22,3 +23,19 @@ func get(url string) (string, error) {
return string(bodyBytes), err
}
func getRaw(url string) (io.ReadCloser, error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
return resp.Body, err
}