Skip to content
This repository was archived by the owner on Apr 23, 2024. It is now read-only.

Commit c511e28

Browse files
committed
feat: display update time on index file
1 parent 85823c8 commit c511e28

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

git/repo.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ func (g *GitHandler) DownloadRepository() error {
3232
return nil
3333
}
3434

35+
func (g *GitHandler) GetUpdatedTime() int64 {
36+
cacheFile, _ := ioutil.ReadFile(g.getCacheFilePath())
37+
cacheTime, _ := strconv.Atoi(string(cacheFile))
38+
return int64(cacheTime)
39+
}
40+
3541
func (g *GitHandler) IsUpToDate() bool {
3642
// File does not exist
3743
_, err := os.Stat(g.getDownloadPath())
@@ -44,9 +50,7 @@ func (g *GitHandler) IsUpToDate() bool {
4450
}
4551

4652
// Check if cache is up to date (within cacheTime interval)
47-
cacheFile, _ := ioutil.ReadFile(g.getCacheFilePath())
48-
cacheTime, _ := strconv.Atoi(string(cacheFile))
49-
return time.Now().Unix() <= int64(cacheTime+g.Cfg.Git.Update.Cache.Time)
53+
return time.Now().Unix() <= (g.GetUpdatedTime() + int64(g.Cfg.Git.Update.Cache.Time))
5054
}
5155

5256
func (g *GitHandler) GetBranches() []string {

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i
4141
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
4242
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd h1:Coekwdh0v2wtGp9Gmz1Ze3eVRAWJMLokvN3QjdzCHLY=
4343
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
44-
github.com/koron/go-github-webhook v0.0.0-20150705120715-fd8c61b5db99 h1:VXfv5FnSQV1UYzBHzX0PsqdO4g+0DyydTszhx0DzB/E=
45-
github.com/koron/go-github-webhook v0.0.0-20150705120715-fd8c61b5db99/go.mod h1:QsucCvHs4fa2IawkhLpASmQB9h9Wo8oIBt7UsACCIRg=
4644
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
4745
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
4846
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=

main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/markbates/pkger"
88
"github.com/saitho/static-git-file-server/rendering"
99
"net/http"
10+
"time"
1011

1112
"github.com/saitho/static-git-file-server/config"
1213
"github.com/saitho/static-git-file-server/git"
@@ -74,6 +75,7 @@ func main() {
7475
ShowTags bool
7576
Branches []string
7677
Tags []git.GitTag
78+
LastUpdate time.Time
7779
}
7880

7981
content, err := rendering.RenderTemplate("/tmpl/index.html", IndexTmplParams{
@@ -82,6 +84,7 @@ func main() {
8284
ShowTags: cfg.Display.Index.ShowTags,
8385
Branches: gitHandler.GetBranches(),
8486
Tags: gitHandler.GetTags(),
87+
LastUpdate: time.Unix(gitHandler.GetUpdatedTime(), 0),
8588
})
8689
if err != nil {
8790
resp.Text(http.StatusInternalServerError, err.Error())

tmpl/index.html

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
<h1>Git Repo</h1>
2-
<h2>Git Remote: {{ .Cfg.Git.Url }}</h2>
1+
<header>
2+
<h1>Git Repo</h1>
3+
<h2>Git Remote: {{ .Cfg.Git.Url }}</h2>
4+
<h3>Last Update: {{ .LastUpdate }}</h3>
5+
</header>
36

7+
<main>
48
{{ if .ShowBranches }}
59
<h2>Branches</h2>
610
{{ range $value := .Branches }}<a href="/branch/{{ . }}">{{ . }}<br></a>{{ end }}
@@ -12,3 +16,9 @@ <h2>Tags</h2>
1216
<a href="/tag/{{ .Tag }}">{{ .Tag }} {{ if $.Cfg.Display.Tags.ShowDate }}({{ .Date }}){{ end }}<br/></a>
1317
{{ end }}
1418
{{ end }}
19+
</main>
20+
21+
<footer>
22+
<hr />
23+
Powered by <a href="https://github.com/saitho/git-file-webserver" target="_blank">Git File Webserver</a>
24+
</footer>

0 commit comments

Comments
 (0)