opti
This commit is contained in:
@@ -215,20 +215,9 @@ func (s HTTPServer) upload(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
func (s HTTPServer) allHist(w http.ResponseWriter, r *http.Request) {
|
func (s HTTPServer) allHist(w http.ResponseWriter, r *http.Request) {
|
||||||
gameID := chi.URLParam(r, "id")
|
gameID := chi.URLParam(r, "id")
|
||||||
path := filepath.Join(s.documentRoot, "data", gameID, "hist")
|
|
||||||
datastore := make([]string, 0)
|
datastore := make([]string, 0)
|
||||||
|
|
||||||
if _, err := os.Stat(path); err != nil {
|
ds, err := s.Service.AllBackups(gameID)
|
||||||
if errors.Is(err, os.ErrNotExist) {
|
|
||||||
ok(datastore, w, r)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Fprintln(os.Stderr, "failed to open datastore (", s.documentRoot, "):", err)
|
|
||||||
internalServerError(w, r)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ds, err := os.ReadDir(path)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, "failed to open datastore (", s.documentRoot, "):", err)
|
fmt.Fprintln(os.Stderr, "failed to open datastore (", s.documentRoot, "):", err)
|
||||||
internalServerError(w, r)
|
internalServerError(w, r)
|
||||||
@@ -236,7 +225,7 @@ func (s HTTPServer) allHist(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, d := range ds {
|
for _, d := range ds {
|
||||||
datastore = append(datastore, d.Name())
|
datastore = append(datastore, d.UUID)
|
||||||
}
|
}
|
||||||
|
|
||||||
ok(datastore, w, r)
|
ok(datastore, w, r)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"runtime"
|
"runtime"
|
||||||
"slices"
|
"slices"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/go-chi/chi/v5/middleware"
|
"github.com/go-chi/chi/v5/middleware"
|
||||||
@@ -160,38 +161,59 @@ func (s *HTTPServer) detailled(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
save, err := cli.Metadata(id)
|
var wg sync.WaitGroup
|
||||||
if err != nil {
|
var err1, err2, err3 error
|
||||||
if errors.Is(err, client.ErrUnauthorized) {
|
var save repository.Metadata
|
||||||
|
var h string
|
||||||
|
var ids []string
|
||||||
|
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
save, err1 = cli.Metadata(id)
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
h, err2 = cli.Hash(id)
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
ids, err3 = cli.ListArchives(id)
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
if err1 != nil || err2 != nil || err3 != nil {
|
||||||
|
if errors.Is(err1, client.ErrUnauthorized) {
|
||||||
unauthorized("Unable to access resources", w, r)
|
unauthorized("Unable to access resources", w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
slog.Error("unable to connect to the remote", "err", err)
|
slog.Error("unable to connect to the remote", "err", err1)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
h, err := cli.Hash(id)
|
wg = sync.WaitGroup{}
|
||||||
if err != nil {
|
|
||||||
slog.Error("unable to connect to the remote", "err", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ids, err := cli.ListArchives(id)
|
|
||||||
if err != nil {
|
|
||||||
slog.Error("unable to connect to the remote", "err", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var bm []repository.Backup
|
var bm []repository.Backup
|
||||||
for _, i := range ids {
|
for _, i := range ids {
|
||||||
b, err := cli.ArchiveInfo(id, i)
|
wg.Add(1)
|
||||||
if err != nil {
|
go func() {
|
||||||
slog.Error("unable to connect to the remote", "err", err)
|
defer wg.Done()
|
||||||
return
|
b, err := cli.ArchiveInfo(id, i)
|
||||||
}
|
if err != nil {
|
||||||
bm = append(bm, b)
|
slog.Error("unable to connect to the remote", "err", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
bm = append(bm, b)
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
payload := DetaillePayload{
|
payload := DetaillePayload{
|
||||||
Save: save,
|
Save: save,
|
||||||
Hash: h,
|
Hash: h,
|
||||||
|
|||||||
Reference in New Issue
Block a user