Jelajahi Sumber

[Doi] Lookup doi in base repo for doi user repos

cgars 7 tahun lalu
induk
melakukan
4a571dfb51
3 mengubah file dengan 18 tambahan dan 5 penghapusan
  1. 1 0
      conf/app.ini
  2. 4 4
      pkg/setting/setting.go
  3. 13 1
      routes/repo/view.go

+ 1 - 0
conf/app.ini

@@ -507,6 +507,7 @@ DO = false
 DOI_URL = https://doi.gin.g-node.org/
 ; AES key (eg. openssl enc -aes-128-cbc -k secret -P -md sha1)
 DOI_KEY = WONTWORK
+DOI_BASE = 123454/789.gty
 
 ; Extension mapping to highlight class
 ; e.g. .toml=ini

+ 4 - 4
pkg/setting/setting.go

@@ -106,7 +106,6 @@ var (
 	ReverseProxyAuthUser    string
 	EnableLoginStatusCookie bool
 	LoginStatusCookieName   string
-	DoiKey                  string
 
 	// Database settings
 	UseSQLite3    bool
@@ -325,9 +324,10 @@ var (
 	}
 
 	Doi struct {
-		Do     bool
-		DoiUrl string
-		DoiKey string
+		Do      bool
+		DoiUrl  string
+		DoiKey  string
+		DoiBase string
 	}
 )
 

+ 13 - 1
routes/repo/view.go

@@ -88,7 +88,8 @@ func renderDirectory(c *context.Context, treeLink string) {
 				log.Trace("Doi Blob could not be unmarshalled:%v", err)
 			}
 			c.Data["DoiInfo"] = doiInfo
-			doi := ginDoi.MakeDoi(ginDoi.RepoP2UUID(c.Repo.Repository.FullName()), "10.12751/g-node.")
+
+			doi := GDoiRepo(c, setting.Doi.DoiBase)
 			//ddata, err := ginDoi.GDoiMData(doi, "https://api.datacite.org/works/") //todo configure URL?
 
 			c.Data["DoiReg"] = ginDoi.IsRegsitredDoi(doi)
@@ -508,3 +509,14 @@ func Forks(c *context.Context) {
 
 	c.HTML(200, FORKS)
 }
+
+// Get the (theoretical ) doi for a repository. Make sure its tge doi for the Base repo
+// in cas eits a repo from the doi user
+func GDoiRepo(c *context.Context, doiBAse string) string {
+	repoN := c.Repo.Repository.FullName()
+	// check whether this repo belongs to doi and is a fork
+	if c.Repo.Repository.IsFork && c.Repo.Owner.Name == "doi" {
+		repoN = c.Repo.Repository.BaseRepo.FullName()
+	}
+	return ginDoi.MakeDoi(ginDoi.RepoP2UUID(repoN), doiBAse)
+}