Skip to content

Commit b85a04d

Browse files
committed
Moved UI to Bulma and assorted work.
1 parent 2d6561a commit b85a04d

File tree

11 files changed

+126
-66
lines changed

11 files changed

+126
-66
lines changed

bindata/bindata.go

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config.example.json

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"Listen": ":8196",
3+
"Application": {
4+
"SiteName": "Package Savant"
5+
},
36
"SSL": {
47
"Enabled": false,
58
"KeyFile": "key.pem",

repository/maven/serve.go

+15-14
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,20 @@ import (
1414

1515
"github.com/minecrafter/sage/repository"
1616
"github.com/minecrafter/sage/util"
17+
"github.com/pkg/errors"
1718
)
1819

1920
type MavenRetrieveHandler struct {
2021
root string
21-
metadataStore repository.MetadataStore
22-
storageStore repository.StorageStore
22+
MetadataStore repository.MetadataStore
23+
StorageStore repository.StorageStore
2324
}
2425

2526
func NewMavenRetrieveHandler(path string, metadataStore repository.MetadataStore, storageStore repository.StorageStore) MavenRetrieveHandler {
2627
return MavenRetrieveHandler{
2728
root: path,
28-
metadataStore: metadataStore,
29-
storageStore: storageStore,
29+
MetadataStore: metadataStore,
30+
StorageStore: storageStore,
3031
}
3132
}
3233

@@ -60,7 +61,7 @@ func (h *MavenRetrieveHandler) GetMavenFile(w http.ResponseWriter, r *http.Reque
6061
}
6162

6263
func (h *MavenRetrieveHandler) servePackageListing(w http.ResponseWriter, r *http.Request) {
63-
ids, err := h.metadataStore.GetAllIDs()
64+
ids, err := h.MetadataStore.GetAllIDs()
6465
if err != nil {
6566
log.Printf("Unable to get package ID list: %s", err.Error())
6667
util.DoSpecificError(w, err)
@@ -78,14 +79,14 @@ func (h *MavenRetrieveHandler) servePackageListing(w http.ResponseWriter, r *htt
7879

7980
func (h *MavenRetrieveHandler) serveVersionListing(w http.ResponseWriter, r *http.Request, subtype string) {
8081
stripped := strings.TrimPrefix(strings.TrimSuffix(subtype, ".json"), "/api/packages/")
81-
pkg, err := h.metadataStore.FindByID(stripped)
82+
pkg, err := h.MetadataStore.FindByID(stripped)
8283
if err != nil {
8384
if err == repository.ErrPackageNotFound {
8485
// package not found
8586
util.Do404(w)
8687
} else {
8788
log.Printf("Unable to lookup package %s: %s", stripped, err.Error())
88-
util.DoSpecificError(w, err)
89+
util.DoSpecificError(w, errors.WithStack(err))
8990
}
9091
return
9192
}
@@ -149,7 +150,7 @@ func (h *MavenRetrieveHandler) serveMavenMetadata(w http.ResponseWriter, path st
149150
id := getPackageID(path, false)
150151

151152
// get package metadata
152-
metadata, err := h.metadataStore.FindByID(id)
153+
metadata, err := h.MetadataStore.FindByID(id)
153154
if err != nil {
154155
if err == repository.ErrPackageNotFound {
155156
// package not found
@@ -173,7 +174,7 @@ func (h *MavenRetrieveHandler) serveMavenHash(w http.ResponseWriter, path string
173174
version := getPackageVersion(path)
174175

175176
// get package metadata
176-
metadata, err := h.metadataStore.FindByID(id)
177+
metadata, err := h.MetadataStore.FindByID(id)
177178
if err != nil {
178179
if err == repository.ErrPackageNotFound {
179180
// package not found
@@ -215,7 +216,7 @@ func (h *MavenRetrieveHandler) serveMavenFile(w http.ResponseWriter, r *http.Req
215216
version := getPackageVersion(path)
216217

217218
// get package metadata
218-
metadata, err := h.metadataStore.FindByID(id)
219+
metadata, err := h.MetadataStore.FindByID(id)
219220
if err != nil {
220221
if err == repository.ErrPackageNotFound {
221222
// package not found
@@ -237,7 +238,7 @@ func (h *MavenRetrieveHandler) serveMavenFile(w http.ResponseWriter, r *http.Req
237238
if !exists {
238239
break
239240
}
240-
reader, err := h.storageStore.ReadByID(data.ID)
241+
reader, err := h.StorageStore.ReadByID(data.ID)
241242
if err != nil {
242243
util.DoSpecificError(w, err)
243244
} else {
@@ -271,7 +272,7 @@ func (h *MavenRetrieveHandler) PutMavenFile(w http.ResponseWriter, r *http.Reque
271272
version := getPackageVersion(path)
272273

273274
// Copy body to new storage file. Use io.TeeReader to allow us to calculate hashes at the same time.
274-
writer, sid, err := h.storageStore.Write()
275+
writer, sid, err := h.StorageStore.Write()
275276
if err != nil {
276277
log.Printf("Unable to create content: %s", err.Error())
277278
util.DoSpecificError(w, err)
@@ -295,7 +296,7 @@ func (h *MavenRetrieveHandler) PutMavenFile(w http.ResponseWriter, r *http.Reque
295296
fileName := path[strings.LastIndex(path, "/"):]
296297

297298
// create version and package if needed
298-
metadata, err := h.metadataStore.FindByID(id)
299+
metadata, err := h.MetadataStore.FindByID(id)
299300
if err != nil {
300301
if err == repository.ErrPackageNotFound {
301302
// package not found, create
@@ -339,7 +340,7 @@ func (h *MavenRetrieveHandler) PutMavenFile(w http.ResponseWriter, r *http.Reque
339340
}
340341
}
341342

342-
if err = h.metadataStore.Store(*metadata); err != nil {
343+
if err = h.MetadataStore.Store(*metadata); err != nil {
343344
log.Printf("Unable to create version: %s", err.Error())
344345
util.DoSpecificError(w, err)
345346
} else {

repository/store/local_metadata.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"sync"
77

88
"github.com/minecrafter/sage/repository"
9+
"github.com/pkg/errors"
910
)
1011

1112
// Represents a local metadata store.
@@ -41,7 +42,7 @@ func (ms *LocalMetadataStore) FindByID(id string) (*repository.PackageMetadata,
4142
if exists {
4243
return &data, nil
4344
}
44-
return nil, repository.ErrPackageNotFound
45+
return nil, errors.WithStack(repository.ErrPackageNotFound)
4546
}
4647

4748
// Stores new metadata for a package.
@@ -52,7 +53,7 @@ func (ms *LocalMetadataStore) Store(metadata repository.PackageMetadata) error {
5253

5354
file, err := os.OpenFile(ms.path, os.O_WRONLY, 666)
5455
if err != nil {
55-
return err
56+
return errors.WithStack(err)
5657
}
5758
defer file.Close()
5859

repository/store/local_package.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package store
33
import (
44
"crypto/rand"
55
"encoding/hex"
6-
"errors"
76
"io"
87
"os"
98
"path/filepath"
109
"strings"
10+
11+
"github.com/pkg/errors"
1112
)
1213

1314
var (
@@ -31,7 +32,11 @@ func NewLocalPackageStore(path string) *LocalPackageStorage {
3132
func (s *LocalPackageStorage) ReadByID(id string) (io.ReadSeeker, error) {
3233
realPath := filepath.Join(s.basePath, id)
3334
if strings.HasPrefix(realPath, s.basePath) {
34-
return os.Open(realPath)
35+
file, err := os.Open(realPath)
36+
if err != nil {
37+
return nil, errors.WithStack(err)
38+
}
39+
return file, nil
3540
}
3641
return nil, errPathInvalid
3742
}
@@ -47,7 +52,7 @@ func (s *LocalPackageStorage) Write() (io.WriteCloser, string, error) {
4752
realPath := filepath.Join(s.basePath, id)
4853
file, err := os.Create(realPath)
4954
if err != nil {
50-
return nil, "", err
55+
return nil, "", errors.WithStack(err)
5156
}
5257
return file, id, nil
5358
}

server/http.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package server
22

33
import (
4-
"errors"
54
"net/http"
65
"strings"
76

87
"github.com/minecrafter/sage/repository/maven"
98
"github.com/minecrafter/sage/util"
9+
"github.com/pkg/errors"
1010
)
1111

1212
type RepoHTTPHandler struct {
@@ -26,7 +26,21 @@ func (h RepoHTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
2626
}
2727

2828
if path == "/" {
29-
util.DoMain(w)
29+
// get repository names and total package count
30+
packageCount := 0
31+
repositoryNames := make([]string, len(h.Repositories))
32+
i := 0
33+
for key, server := range h.Repositories {
34+
packages, err := server.MetadataStore.GetAllIDs()
35+
if err != nil {
36+
// Skip this
37+
continue
38+
}
39+
repositoryNames[i] = key
40+
i++
41+
packageCount += len(*packages)
42+
}
43+
util.DoMain(w, repositoryNames, packageCount)
3044
return
3145
}
3246

templates/404.html

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
{{define "four_oh_four"}}
22
{{template "header" "Not found"}}
3-
<div class="mw9 center ph3-ns">
4-
<div class="cf ph2-ns">
5-
<div class="fl w-100 pa2">
6-
<div class="bg-white tc pv4">
7-
<h1 class="f2 lh-title">Not found</h1>
8-
<p>We were not able to find what you wanted. Try searching on <a href="/" class="link dark-blue hover-blue">the main page</a>.
9-
</div>
3+
<section class="hero is-primary">
4+
<div class="hero-body">
5+
<div class="container">
6+
<h1 class="title">
7+
Not found
8+
</h1>
9+
<h2 class="subtitle">
10+
Try searching on <a href="/">the main page</a>.
11+
</h2>
1012
</div>
1113
</div>
12-
</div>
14+
</section>
1315
{{template "footer"}}
1416
{{end}}

0 commit comments

Comments
 (0)