conflict
This commit is contained in:
@@ -9,14 +9,16 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
Metadata struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
Version int `json:"version"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
Version int `json:"version"`
|
||||
Date time.Time `json:"date"`
|
||||
}
|
||||
)
|
||||
|
||||
@@ -186,3 +188,32 @@ func SetVersion(gameID string, version int) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func SetDate(gameID string, dt time.Time) error {
|
||||
path := filepath.Join(datastorepath, gameID, "metadata.json")
|
||||
|
||||
f, err := os.OpenFile(path, os.O_RDWR, 0740)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
var metadata Metadata
|
||||
d := json.NewDecoder(f)
|
||||
err = d.Decode(&metadata)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
f.Seek(0, io.SeekStart)
|
||||
|
||||
metadata.Date = dt
|
||||
|
||||
e := json.NewEncoder(f)
|
||||
err = e.Encode(metadata)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -67,6 +68,24 @@ func (c *Client) Version(gameID string) (int, error) {
|
||||
return 0, errors.New("invalid payload sent by the server")
|
||||
}
|
||||
|
||||
func (c *Client) Date(gameID string) (time.Time, error) {
|
||||
u, err := url.JoinPath(c.baseURL, "api", "v1", "games", gameID, "version")
|
||||
if err != nil {
|
||||
return time.Time{}, err
|
||||
}
|
||||
|
||||
o, err := c.get(u)
|
||||
if err != nil {
|
||||
return time.Time{}, err
|
||||
}
|
||||
|
||||
if h, ok := (o.Data).(time.Time); ok {
|
||||
return h, nil
|
||||
}
|
||||
|
||||
return time.Time{}, errors.New("invalid payload sent by the server")
|
||||
}
|
||||
|
||||
func (c *Client) Push(gameID, archivePath string, m game.Metadata) error {
|
||||
u, err := url.JoinPath(c.baseURL, "api", "v1", "games", gameID, "data")
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user