move to goresources and add build scripts

This commit is contained in:
sentriz
2019-06-24 13:43:05 +01:00
parent 56b872a4b3
commit 895d27378f
34 changed files with 23289 additions and 229 deletions

File diff suppressed because it is too large Load Diff

9
server/assets_dev.go Normal file
View File

@@ -0,0 +1,9 @@
// +build !embed
package server
import "github.com/omeid/go-resources/live"
var (
assets = live.Dir("./assets_src")
)

9
server/assets_prod.go Normal file
View File

@@ -0,0 +1,9 @@
// +build embed
package server
import "github.com/sentriz/gonic/server/assets_compiled"
var (
assets = assets_compiled.Assets
)

View File

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

Before

Width:  |  Height:  |  Size: 236 KiB

After

Width:  |  Height:  |  Size: 236 KiB

View File

@@ -34,6 +34,24 @@ body {
display: flex;
flex-direction: column;
justify-content: space-between;
line-height: 1rem;
}
.left-cut {
display: flex;
flex-direction: row-reverse;
overflow-x: hidden;
}
table#recent-folders {
line-height: 0.45rem;
overflow: hidden;
white-space: nowrap;
}
table#recent-folders td, th {
border: none;
margin: 0;
}
a,

View File

@@ -5,7 +5,6 @@
<meta charset="utf-8">
<title>{{ template "title" }}</title>
<link rel="stylesheet" href="https://cdn.materialdesignicons.com/3.6.95/css/materialdesignicons.min.css">
<link rel="stylesheet" href="/admin/static/stylesheets/awsm.css">
<link rel="stylesheet" href="/admin/static/stylesheets/main.css">
<link rel="shortcut icon" href="/admin/static/images/favicon.ico" type="image/x-icon">
<link rel="icon" href="/admin/static/images/favicon.ico" type="image/x-icon">

View File

@@ -61,4 +61,19 @@
</div>
{{ end }}
</div>
<div class="padded box mono">
<div class="box-title">
<i class="mdi mdi-folder-multiple"></i> recent folders
</div>
<div class="left-cut">
<table id="recent-folders">
{{ range $folder := .RecentFolders }}
<tr>
<td><span>{{ $folder.RightPath }}</span></td>
<td><span class="light">{{ $folder.CreatedAt | humandate }}</span></td>
</tr>
{{ end }}
</table>
</div>
</div>
{{ end }}

View File

@@ -53,6 +53,11 @@ func (c *Controller) ServeHome(w http.ResponseWriter, r *http.Request) {
c.DB.Table("albums").Count(&data.AlbumCount)
c.DB.Table("tracks").Count(&data.TrackCount)
c.DB.Find(&data.AllUsers)
c.DB.
Where("tag_artist_id IS NOT NULL").
Order("updated_at DESC").
Limit(8).
Find(&data.RecentFolders)
data.CurrentLastFMAPIKey = c.GetSetting("lastfm_api_key")
scheme := firstExisting(
"http", // fallback

View File

@@ -11,16 +11,17 @@ import (
)
type templateData struct {
Flashes []interface{}
User *model.User
SelectedUser *model.User
AlbumCount int
AllUsers []*model.User
ArtistCount int
AlbumCount int
TrackCount int
CurrentLastFMAPIKey string
CurrentLastFMAPISecret string
Flashes []interface{}
RecentFolders []*model.Album
RequestRoot string
SelectedUser *model.User
TrackCount int
User *model.User
}
func renderTemplate(w http.ResponseWriter, r *http.Request,

View File

@@ -5,20 +5,11 @@
"albumList": {
"album": [
{
"id": 7,
"coverArt": 7,
"artist": "A Certain Ratio",
"title": "(1994) The Graveyard and the Ballroom",
"parent": 6,
"isDir": true,
"created": "0001-01-01T00:00:00Z"
},
{
"id": 3,
"coverArt": 3,
"artist": "Jah Wobble, The Edge, Holger Czukay",
"title": "(1983) Snake Charmer",
"parent": 2,
"id": 11,
"coverArt": 11,
"artist": "13th Floor Lowervators",
"title": "(1966) The Psychedelic Sounds of the 13th Floor Elevators",
"parent": 9,
"isDir": true,
"created": "0001-01-01T00:00:00Z"
},
@@ -32,38 +23,11 @@
"created": "0001-01-01T00:00:00Z"
},
{
"id": 19,
"coverArt": 19,
"artist": "Swell Maps",
"title": "(1979) A Trip to Marineville",
"parent": 17,
"isDir": true,
"created": "0001-01-01T00:00:00Z"
},
{
"id": 18,
"coverArt": 18,
"artist": "Swell Maps",
"title": "(1980) Jane From Occupied Europe",
"parent": 17,
"isDir": true,
"created": "0001-01-01T00:00:00Z"
},
{
"id": 8,
"coverArt": 8,
"artist": "A Certain Ratio",
"title": "(1981) To Each.",
"parent": 6,
"isDir": true,
"created": "0001-01-01T00:00:00Z"
},
{
"id": 11,
"coverArt": 11,
"artist": "13th Floor Lowervators",
"title": "(1966) The Psychedelic Sounds of the 13th Floor Elevators",
"parent": 9,
"id": 3,
"coverArt": 3,
"artist": "Jah Wobble, The Edge, Holger Czukay",
"title": "(1983) Snake Charmer",
"parent": 2,
"isDir": true,
"created": "0001-01-01T00:00:00Z"
},
@@ -77,11 +41,20 @@
"created": "0001-01-01T00:00:00Z"
},
{
"id": 21,
"coverArt": 21,
"artist": "Ten Years After",
"title": "(1967) Ten Years After",
"parent": 20,
"id": 8,
"coverArt": 8,
"artist": "A Certain Ratio",
"title": "(1981) To Each.",
"parent": 6,
"isDir": true,
"created": "0001-01-01T00:00:00Z"
},
{
"id": 19,
"coverArt": 19,
"artist": "Swell Maps",
"title": "(1979) A Trip to Marineville",
"parent": 17,
"isDir": true,
"created": "0001-01-01T00:00:00Z"
},
@@ -93,6 +66,33 @@
"parent": 9,
"isDir": true,
"created": "0001-01-01T00:00:00Z"
},
{
"id": 18,
"coverArt": 18,
"artist": "Swell Maps",
"title": "(1980) Jane From Occupied Europe",
"parent": 17,
"isDir": true,
"created": "0001-01-01T00:00:00Z"
},
{
"id": 7,
"coverArt": 7,
"artist": "A Certain Ratio",
"title": "(1994) The Graveyard and the Ballroom",
"parent": 6,
"isDir": true,
"created": "0001-01-01T00:00:00Z"
},
{
"id": 21,
"coverArt": 21,
"artist": "Ten Years After",
"title": "(1967) Ten Years After",
"parent": 20,
"isDir": true,
"created": "0001-01-01T00:00:00Z"
}
]
}

View File

@@ -5,12 +5,12 @@
"albumList2": {
"album": [
{
"id": 3,
"coverArt": 3,
"artistId": 1,
"artist": "Jah Wobble, The Edge & Holger Czukay",
"name": "Snake Charmer",
"created": "2019-06-10T17:06:25.998358476+01:00"
"id": 5,
"coverArt": 5,
"artistId": 2,
"artist": "Dead Moon",
"name": "Unknown Passage",
"created": "2019-06-10T17:06:26.000595013+01:00"
},
{
"id": 10,
@@ -20,21 +20,6 @@
"name": "Easter Everywhere",
"created": "2019-06-10T17:06:26.01139089+01:00"
},
{
"id": 7,
"coverArt": 7,
"artistId": 3,
"artist": "A Certain Ratio",
"name": "The Graveyard and the Ballroom",
"created": "2019-06-10T17:06:26.003805335+01:00"
},
{
"id": 8,
"artistId": 3,
"artist": "A Certain Ratio",
"name": "To Each...",
"created": "2019-06-10T17:06:26.00810814+01:00"
},
{
"id": 11,
"coverArt": 11,
@@ -44,28 +29,12 @@
"created": "2019-06-10T17:06:26.015039416+01:00"
},
{
"id": 5,
"coverArt": 5,
"artistId": 2,
"artist": "Dead Moon",
"name": "Unknown Passage",
"created": "2019-06-10T17:06:26.000595013+01:00"
},
{
"id": 15,
"coverArt": 15,
"artistId": 5,
"artist": "Anikas",
"name": "Anika",
"created": "2019-06-10T17:06:26.028934348+01:00"
},
{
"id": 21,
"coverArt": 21,
"artistId": 7,
"artist": "Ten Years After",
"name": "Ten Years After",
"created": "2019-06-10T17:06:26.041345532+01:00"
"id": 3,
"coverArt": 3,
"artistId": 1,
"artist": "Jah Wobble, The Edge & Holger Czukay",
"name": "Snake Charmer",
"created": "2019-06-10T17:06:25.998358476+01:00"
},
{
"id": 19,
@@ -75,6 +44,22 @@
"name": "A Trip to Marineville",
"created": "2019-06-10T17:06:26.036222364+01:00"
},
{
"id": 7,
"coverArt": 7,
"artistId": 3,
"artist": "A Certain Ratio",
"name": "The Graveyard and the Ballroom",
"created": "2019-06-10T17:06:26.003805335+01:00"
},
{
"id": 15,
"coverArt": 15,
"artistId": 5,
"artist": "Anikas",
"name": "Anika",
"created": "2019-06-10T17:06:26.028934348+01:00"
},
{
"id": 18,
"coverArt": 18,
@@ -82,6 +67,21 @@
"artist": "Swell Maps",
"name": "Jane From Occupied Europe",
"created": "2019-06-10T17:06:26.031594709+01:00"
},
{
"id": 21,
"coverArt": 21,
"artistId": 7,
"artist": "Ten Years After",
"name": "Ten Years After",
"created": "2019-06-10T17:06:26.041345532+01:00"
},
{
"id": 8,
"artistId": 3,
"artist": "A Certain Ratio",
"name": "To Each...",
"created": "2019-06-10T17:06:26.00810814+01:00"
}
]
}

View File

@@ -19,7 +19,6 @@
"contentType": "audio/x-flac",
"coverArt": 3,
"created": "2019-06-10T17:06:25.998787704+01:00",
"duration": 372,
"id": 1,
"parent": 3,
"path": "Jah Wobble, The Edge, Holger Czukay/(1983) Snake Charmer/01.05 Snake Charmer.flac",
@@ -39,7 +38,6 @@
"contentType": "audio/x-flac",
"coverArt": 3,
"created": "2019-06-10T17:06:25.999138309+01:00",
"duration": 331,
"id": 2,
"parent": 3,
"path": "Jah Wobble, The Edge, Holger Czukay/(1983) Snake Charmer/03.05 It Was a Camel.flac",
@@ -59,7 +57,6 @@
"contentType": "audio/x-flac",
"coverArt": 3,
"created": "2019-06-10T17:06:25.999449918+01:00",
"duration": 523,
"id": 3,
"parent": 3,
"path": "Jah Wobble, The Edge, Holger Czukay/(1983) Snake Charmer/02.05 Hold On to Your Dreams.flac",
@@ -79,7 +76,6 @@
"contentType": "audio/x-flac",
"coverArt": 3,
"created": "2019-06-10T17:06:25.999768289+01:00",
"duration": 418,
"id": 4,
"parent": 3,
"path": "Jah Wobble, The Edge, Holger Czukay/(1983) Snake Charmer/05.05 Snake Charmer (reprise).flac",
@@ -99,7 +95,6 @@
"contentType": "audio/x-flac",
"coverArt": 3,
"created": "2019-06-10T17:06:26.000111656+01:00",
"duration": 227,
"id": 5,
"parent": 3,
"path": "Jah Wobble, The Edge, Holger Czukay/(1983) Snake Charmer/04.05 Sleazy.flac",

View File

@@ -14,7 +14,6 @@
"contentType": "audio/x-flac",
"coverArt": 3,
"created": "0001-01-01T00:00:00Z",
"duration": 372,
"id": 1,
"parent": 3,
"path": "Jah Wobble, The Edge, Holger Czukay/(1983) Snake Charmer/01.05 Snake Charmer.flac",
@@ -32,7 +31,6 @@
"contentType": "audio/x-flac",
"coverArt": 3,
"created": "0001-01-01T00:00:00Z",
"duration": 523,
"id": 3,
"parent": 3,
"path": "Jah Wobble, The Edge, Holger Czukay/(1983) Snake Charmer/02.05 Hold On to Your Dreams.flac",
@@ -50,7 +48,6 @@
"contentType": "audio/x-flac",
"coverArt": 3,
"created": "0001-01-01T00:00:00Z",
"duration": 331,
"id": 2,
"parent": 3,
"path": "Jah Wobble, The Edge, Holger Czukay/(1983) Snake Charmer/03.05 It Was a Camel.flac",
@@ -68,7 +65,6 @@
"contentType": "audio/x-flac",
"coverArt": 3,
"created": "0001-01-01T00:00:00Z",
"duration": 227,
"id": 5,
"parent": 3,
"path": "Jah Wobble, The Edge, Holger Czukay/(1983) Snake Charmer/04.05 Sleazy.flac",
@@ -86,7 +82,6 @@
"contentType": "audio/x-flac",
"coverArt": 3,
"created": "0001-01-01T00:00:00Z",
"duration": 418,
"id": 4,
"parent": 3,
"path": "Jah Wobble, The Edge, Holger Czukay/(1983) Snake Charmer/05.05 Snake Charmer (reprise).flac",

View File

@@ -28,7 +28,6 @@
"contentType": "audio/x-flac",
"coverArt": 7,
"created": "0001-01-01T00:00:00Z",
"duration": 332,
"id": 15,
"parent": 7,
"path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/13.14 Flight.flac",
@@ -46,7 +45,6 @@
"contentType": "audio/mpeg",
"coverArt": 11,
"created": "0001-01-01T00:00:00Z",
"duration": 154,
"id": 49,
"parent": 11,
"path": "13th Floor Lowervators/(1966) The Psychedelic Sounds of the 13th Floor Elevators/13.21 Before You Accuse Me.mp3",
@@ -64,7 +62,6 @@
"contentType": "audio/x-flac",
"coverArt": 18,
"created": "0001-01-01T00:00:00Z",
"duration": 220,
"id": 85,
"parent": 18,
"path": "Swell Maps/(1980) Jane From Occupied Europe/13.16 Blenheim Shots.flac",
@@ -82,7 +79,6 @@
"contentType": "audio/mpeg",
"coverArt": 19,
"created": "0001-01-01T00:00:00Z",
"duration": 463,
"id": 102,
"parent": 19,
"path": "Swell Maps/(1979) A Trip to Marineville/d01 13.14 Adventuring Into Basketry.mp3",
@@ -100,7 +96,6 @@
"contentType": "audio/ogg",
"coverArt": 21,
"created": "0001-01-01T00:00:00Z",
"duration": 433,
"id": 115,
"parent": 21,
"path": "Ten Years After/(1967) Ten Years After/13.15 Spider in My Web.ogg",

View File

@@ -6,24 +6,30 @@ import (
"net/http"
"time"
"github.com/gobuffalo/packr/v2"
"github.com/dustin/go-humanize"
"github.com/gorilla/securecookie"
"github.com/wader/gormstore"
)
func extendFromBox(tmpl *template.Template, box *packr.Box, key string) *template.Template {
strT, err := box.FindString(key)
if err != nil {
log.Fatalf("error when reading template from box: %v", err)
var (
tmplFuncMap = template.FuncMap{
"humandate": humanize.Time,
}
)
func extendFrom(tmpl *template.Template, key string) *template.Template {
strT, ok := assets.String(key)
if !ok {
log.Fatalf("error when reading %q from assets", key)
}
if tmpl == nil {
tmpl = template.New("layout")
tmpl = template.New("layout").Funcs(tmplFuncMap)
} else {
tmpl = template.Must(tmpl.Clone())
}
newT, err := tmpl.Parse(strT)
if err != nil {
log.Fatalf("error when parsing template template: %v", err)
log.Fatalf("error when parsing template: %v", err)
}
return newT
}
@@ -34,22 +40,21 @@ func (s *Server) SetupAdmin() {
sessionKey = securecookie.GenerateRandomKey(32)
s.SetSetting("session_key", string(sessionKey))
}
// create gormstore (and cleanup) for backend sessions
s.SessDB = gormstore.New(s.DB, sessionKey)
go s.SessDB.PeriodicCleanup(1*time.Hour, nil)
// using packr to bundle templates and static files
box := packr.New("templates", "./templates")
layoutT := extendFromBox(nil, box, "layout.tmpl")
userT := extendFromBox(layoutT, box, "user.tmpl")
go s.SessDB.PeriodicCleanup(time.Hour, nil)
//
layoutT := extendFrom(nil, "/templates/layout.tmpl")
userT := extendFrom(layoutT, "/templates/user.tmpl")
s.Templates = map[string]*template.Template{
"login": extendFromBox(layoutT, box, "pages/login.tmpl"),
"home": extendFromBox(userT, box, "pages/home.tmpl"),
"change_own_password": extendFromBox(userT, box, "pages/change_own_password.tmpl"),
"change_password": extendFromBox(userT, box, "pages/change_password.tmpl"),
"delete_user": extendFromBox(userT, box, "pages/delete_user.tmpl"),
"create_user": extendFromBox(userT, box, "pages/create_user.tmpl"),
"update_lastfm_api_key": extendFromBox(userT, box, "pages/update_lastfm_api_key.tmpl"),
"login": extendFrom(layoutT, "/templates/pages/login.tmpl"),
"home": extendFrom(userT, "/templates/pages/home.tmpl"),
"change_own_password": extendFrom(userT, "/templates/pages/change_own_password.tmpl"),
"change_password": extendFrom(userT, "/templates/pages/change_password.tmpl"),
"delete_user": extendFrom(userT, "/templates/pages/delete_user.tmpl"),
"create_user": extendFrom(userT, "/templates/pages/create_user.tmpl"),
"update_lastfm_api_key": extendFrom(userT, "/templates/pages/update_lastfm_api_key.tmpl"),
}
//
withPublicWare := newChain(
s.WithLogging,
s.WithSession,
@@ -62,16 +67,21 @@ func (s *Server) SetupAdmin() {
withUserWare,
s.WithAdminSession,
)
server := http.FileServer(packr.New("static", "./static"))
s.mux.Handle("/admin/static/", http.StripPrefix("/admin/static/", server))
// begin static server
s.mux.Handle("/admin/static/", http.StripPrefix("/admin",
http.FileServer(assets),
))
// begin public routes (creates new session)
s.mux.HandleFunc("/admin/login", withPublicWare(s.ServeLogin))
s.mux.HandleFunc("/admin/login_do", withPublicWare(s.ServeLoginDo))
// begin user routes (if session is valid)
s.mux.HandleFunc("/admin/logout", withUserWare(s.ServeLogout))
s.mux.HandleFunc("/admin/home", withUserWare(s.ServeHome))
s.mux.HandleFunc("/admin/change_own_password", withUserWare(s.ServeChangeOwnPassword))
s.mux.HandleFunc("/admin/change_own_password_do", withUserWare(s.ServeChangeOwnPasswordDo))
s.mux.HandleFunc("/admin/link_lastfm_do", withUserWare(s.ServeLinkLastFMDo))
s.mux.HandleFunc("/admin/unlink_lastfm_do", withUserWare(s.ServeUnlinkLastFMDo))
// begin admin routes (if session is valid, and is admin)
s.mux.HandleFunc("/admin/change_password", withAdminWare(s.ServeChangePassword))
s.mux.HandleFunc("/admin/change_password_do", withAdminWare(s.ServeChangePasswordDo))
s.mux.HandleFunc("/admin/delete_user", withAdminWare(s.ServeDeleteUser))