download a zip of any particular version
This commit is contained in:
parent
6dddd54e07
commit
c7271d2d33
3 changed files with 38 additions and 3 deletions
36
web/repo.go
36
web/repo.go
|
@ -1,7 +1,9 @@
|
||||||
package web
|
package web
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"archive/zip"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
|
@ -76,3 +78,37 @@ func (web *Web) mapPatch(c *gin.Context) {
|
||||||
|
|
||||||
c.String(http.StatusOK, "text/plain", patch.String())
|
c.String(http.StatusOK, "text/plain", patch.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (web *Web) mapZip(c *gin.Context) {
|
||||||
|
userId := c.Param("userId")
|
||||||
|
mapId := c.Param("mapId")
|
||||||
|
hash := c.Param("hash")
|
||||||
|
|
||||||
|
repoDir := path.Join(web.config.Repos, userId, mapId)
|
||||||
|
repo, _ := git.PlainOpen(repoDir)
|
||||||
|
|
||||||
|
hashObj := plumbing.NewHash(hash)
|
||||||
|
commit, _ := repo.CommitObject(hashObj)
|
||||||
|
tree, _ := commit.Tree()
|
||||||
|
|
||||||
|
files := tree.Files()
|
||||||
|
|
||||||
|
c.Writer.Header().Set("Content-type", "application/octet-stream")
|
||||||
|
c.Writer.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s.zip", mapId))
|
||||||
|
c.Stream(func(w io.Writer) bool {
|
||||||
|
ar := zip.NewWriter(w)
|
||||||
|
for {
|
||||||
|
file, err := files.Next()
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
reader, _ := file.Reader()
|
||||||
|
fdest, _ := ar.Create(file.Name)
|
||||||
|
io.Copy(fdest, reader)
|
||||||
|
}
|
||||||
|
ar.Close()
|
||||||
|
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td><span title="{{ .Date }}">{{ .HumanDate }}</span></td>
|
<td><span title="{{ .Date }}">{{ .HumanDate }}</span></td>
|
||||||
<td>
|
<td>
|
||||||
|
<a href="zip/{{ .Hash }}" target="_blank">zip</a>
|
||||||
{{ if .HasParent }}
|
{{ if .HasParent }}
|
||||||
<a href="patch/{{ .Hash }}" target="_blank">patch</a>
|
<a href="patch/{{ .Hash }}" target="_blank">patch</a>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
|
@ -68,14 +68,12 @@ func (web *Web) Run() {
|
||||||
})
|
})
|
||||||
|
|
||||||
r.GET("/logout", web.logout)
|
r.GET("/logout", web.logout)
|
||||||
|
|
||||||
r.GET("/login", web.login)
|
r.GET("/login", web.login)
|
||||||
|
|
||||||
r.GET("/login/callback", web.loginCallback)
|
r.GET("/login/callback", web.loginCallback)
|
||||||
|
|
||||||
r.GET("/map/:userId/:mapId/versions", web.mapVersions)
|
r.GET("/map/:userId/:mapId/versions", web.mapVersions)
|
||||||
|
|
||||||
r.GET("/map/:userId/:mapId/patch/:hash", web.mapPatch)
|
r.GET("/map/:userId/:mapId/patch/:hash", web.mapPatch)
|
||||||
|
r.GET("/map/:userId/:mapId/zip/:hash", web.mapZip)
|
||||||
|
|
||||||
r.GET("/", func(c *gin.Context) {
|
r.GET("/", func(c *gin.Context) {
|
||||||
beatmapSets := web.listRepos()
|
beatmapSets := web.listRepos()
|
||||||
|
|
Loading…
Add table
Reference in a new issue