فهرست منبع

Annex over HTTP routes

Cleaner implementation of the previous PR:
- /config: Returns annex config information
- /annex/objects: Starts a transfer of a given annex content key
- Head request performs the same as above, but doesn't transfer the
  data.
Achilleas Koutsou 5 سال پیش
والد
کامیت
78d9da7352
2فایلهای تغییر یافته به همراه26 افزوده شده و 0 حذف شده
  1. 7 0
      internal/cmd/web.go
  2. 19 0
      internal/route/repo/repo_gin.go

+ 7 - 0
internal/cmd/web.go

@@ -654,6 +654,13 @@ func runWeb(c *cli.Context) error {
 		m.Get("/watchers", repo.Watchers)
 	}, ignSignIn, context.RepoAssignment(), context.RepoRef())
 
+	m.Group("/:username/:reponame", func() {
+		// GIN mod: Annex over HTTP
+		m.Get("/config", repo.GitConfig)
+		m.Get("/annex/objects/:hashdira/:hashdirb/:key/:keyfile", repo.AnnexGetKey)
+		m.Head("/annex/objects/:hashdira/:hashdirb/:key/:keyfile", repo.AnnexGetKey)
+	}, ignSignInAndCsrf, context.RepoAssignment())
+
 	m.Group("/:username", func() {
 		m.Get("/:reponame", ignSignIn, context.RepoAssignment(), context.RepoRef(), repo.Home)
 

+ 19 - 0
internal/route/repo/repo_gin.go

@@ -159,3 +159,22 @@ func resolveAnnexedContent(c *context.Context, buf []byte, dataRc io.Reader) ([]
 	log.Trace("Annexed file size: %d B", info.Size())
 	return annexBuf, annexDataReader, nil
 }
+
+func GitConfig(c *context.Context) {
+	// TODO: Check if file exists and is readable, serve 500 otherwise
+	log.Trace("RepoPath: %+v", c.Repo.Repository.RepoPath())
+	configFilePath := path.Join(c.Repo.Repository.RepoPath(), "config")
+	log.Trace("Serving file %q", configFilePath)
+	c.ServeFileContent(configFilePath, "config")
+}
+
+func AnnexGetKey(c *context.Context) {
+	filename := c.Params(":keyfile")
+	key := c.Params(":key")
+	contentPath := filepath.Join("annex/objects", c.Params(":hashdira"), c.Params(":hashdirb"), key, filename)
+	log.Trace("Git annex requested key %q: %q", key, contentPath)
+	err := serveAnnexedKey(c, filename, contentPath)
+	if err != nil {
+		c.ServerError("AnnexGetKey", err)
+	}
+}