Skip to content

Commit

Permalink
add build version to footer
Browse files Browse the repository at this point in the history
  • Loading branch information
stv0g committed Apr 3, 2022
1 parent bd97abf commit c7012c9
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func run(cfg *config.Config) {
router.Use(APIMiddleware(svrs, short, cfg))
router.Use(StaticMiddleware(cfg))

router.GET(apiBase+"/config", handlers.HandleConfig)
router.GET(apiBase+"/config", handlers.HandleConfigWith(version, commit, date))
router.POST(apiBase+"/initiate", handlers.HandleInitiate)
router.POST(apiBase+"/part", handlers.HandlePart)
router.POST(apiBase+"/complete", handlers.HandleComplete)
Expand Down
2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ <h2 class="accordion-header" id="heading-settings">
</main>
<footer class="footer mt-auto py-3 bg-light">
<div class="container text-center">
<span class="text-muted"><a href="https://github.com/stv0g/gose">GoSƐ</a> is open-source software written by <a href="https://www.steffenvogel.de">Steffen Vogel</a>.</span>
<span class="text-muted"><a href="https://github.com/stv0g/gose">GoSƐ</a><span id="version"></span> is open-source software written by <a href="https://www.steffenvogel.de">Steffen Vogel</a>.</span>
</div>
</footer>
</body>
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ class Features {
notify_browser: boolean = false;
}

class Build {
version: string
commit: string
state: string
}

export class Config {
servers: Array<Server> = []
features: Features
build: Build
}
5 changes: 5 additions & 0 deletions frontend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ function onConfig(config: Config) {
});
updateExpiration(config.servers[0]);

// Update settings pane
if (config.features.short_url) {
let divShorten = document.getElementById("config-shorten");
divShorten.classList.remove("d-none");
Expand All @@ -317,6 +318,10 @@ function onConfig(config: Config) {
let divNotifyBrowser = document.getElementById("config-notify-browser");
divNotifyBrowser.classList.remove("d-none");
}

// Update footer
let spanVersion = document.getElementById("version");
spanVersion.innerHTML = `<a class="mx-1" href="https://github.com/stv0g/gose/commit/${config.build.commit}">v${config.build.version}</a>`;
}

async function setupNotification(ev: Event) {
Expand Down
44 changes: 29 additions & 15 deletions pkg/handlers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,41 @@ type featureResponse struct {
NotifyBrowser bool `json:"notify_browser"`
}

type respBuild struct {
Version string `json:"version"`
Date string `json:"date"`
Commit string `json:"commit"`
}

type configResponse struct {
Build respBuild `json:"build"`
Servers []config.S3ServerConfig `json:"servers"`
Features featureResponse `json:"features"`
}

// HandleConfig returns runtime configuration to the frontend
func HandleConfig(c *gin.Context) {
cfg := c.MustGet("config").(*config.Config)
svrs := c.MustGet("servers").(server.List)
func HandleConfigWith(version, commit, date string) func(*gin.Context) {
return func(c *gin.Context) {
cfg := c.MustGet("config").(*config.Config)
svrs := c.MustGet("servers").(server.List)

svrsResp := []config.S3ServerConfig{}
for _, svr := range svrs {
svrsResp = append(svrsResp, svr.Config.S3ServerConfig)
}
svrsResp := []config.S3ServerConfig{}
for _, svr := range svrs {
svrsResp = append(svrsResp, svr.Config.S3ServerConfig)
}

c.JSON(200, &configResponse{
Servers: svrsResp,
Features: featureResponse{
ShortURL: cfg.Shortener != nil,
NotifyMail: cfg.Notification.Mail != nil,
NotifyBrowser: true,
},
})
c.JSON(200, &configResponse{
Servers: svrsResp,
Build: respBuild{
Commit: commit,
Version: version,
Date: date,
},
Features: featureResponse{
ShortURL: cfg.Shortener != nil,
NotifyMail: cfg.Notification.Mail != nil,
NotifyBrowser: true,
},
})
}
}

0 comments on commit c7012c9

Please sign in to comment.