88 "encoding/gob"
99 "fmt"
1010 "net/http"
11- "net/url"
1211 "os"
1312 "path"
1413 "strings"
@@ -22,7 +21,6 @@ import (
2221 "code.gitea.io/gitea/modules/setting"
2322 "code.gitea.io/gitea/modules/storage"
2423 "code.gitea.io/gitea/modules/templates"
25- "code.gitea.io/gitea/modules/util"
2624 "code.gitea.io/gitea/modules/validation"
2725 "code.gitea.io/gitea/modules/web"
2826 "code.gitea.io/gitea/routers"
@@ -51,7 +49,6 @@ import (
5149 "github.com/go-chi/cors"
5250 "github.com/prometheus/client_golang/prometheus"
5351 "github.com/tstranex/u2f"
54- "github.com/unknwon/com"
5552)
5653
5754const (
@@ -173,7 +170,7 @@ func WebRoutes() *web.Route {
173170
174171 // this png is very likely to always be below the limit for gzip so it doesn't need to pass through gzip
175172 routes .Get ("/apple-touch-icon.png" , func (w http.ResponseWriter , req * http.Request ) {
176- http .Redirect (w , req , path .Join (setting .StaticURLPrefix , "img/apple-touch-icon.png" ), 301 )
173+ http .Redirect (w , req , path .Join (setting .StaticURLPrefix , "/assets/ img/apple-touch-icon.png" ), 301 )
177174 })
178175
179176 gob .Register (& u2f.Challenge {})
@@ -228,6 +225,7 @@ func WebRoutes() *web.Route {
228225 // TODO: These really seem like things that could be folded into Contexter or as helper functions
229226 common = append (common , user .GetNotificationCount )
230227 common = append (common , repo .GetActiveStopwatch )
228+ common = append (common , goGet )
231229
232230 others := web .NewRoute ()
233231 for _ , middle := range common {
@@ -239,67 +237,6 @@ func WebRoutes() *web.Route {
239237 return routes
240238}
241239
242- func goGet (ctx * context.Context ) {
243- if ctx .Query ("go-get" ) != "1" {
244- return
245- }
246-
247- // Quick responses appropriate go-get meta with status 200
248- // regardless of if user have access to the repository,
249- // or the repository does not exist at all.
250- // This is particular a workaround for "go get" command which does not respect
251- // .netrc file.
252-
253- ownerName := ctx .Params (":username" )
254- repoName := ctx .Params (":reponame" )
255- trimmedRepoName := strings .TrimSuffix (repoName , ".git" )
256-
257- if ownerName == "" || trimmedRepoName == "" {
258- _ , _ = ctx .Write ([]byte (`<!doctype html>
259- <html>
260- <body>
261- invalid import path
262- </body>
263- </html>
264- ` ))
265- ctx .Status (400 )
266- return
267- }
268- branchName := setting .Repository .DefaultBranch
269-
270- repo , err := models .GetRepositoryByOwnerAndName (ownerName , repoName )
271- if err == nil && len (repo .DefaultBranch ) > 0 {
272- branchName = repo .DefaultBranch
273- }
274- prefix := setting .AppURL + path .Join (url .PathEscape (ownerName ), url .PathEscape (repoName ), "src" , "branch" , util .PathEscapeSegments (branchName ))
275-
276- appURL , _ := url .Parse (setting .AppURL )
277-
278- insecure := ""
279- if appURL .Scheme == string (setting .HTTP ) {
280- insecure = "--insecure "
281- }
282- ctx .Header ().Set ("Content-Type" , "text/html" )
283- ctx .Status (http .StatusOK )
284- _ , _ = ctx .Write ([]byte (com .Expand (`<!doctype html>
285- <html>
286- <head>
287- <meta name="go-import" content="{GoGetImport} git {CloneLink}">
288- <meta name="go-source" content="{GoGetImport} _ {GoDocDirectory} {GoDocFile}">
289- </head>
290- <body>
291- go get {Insecure}{GoGetImport}
292- </body>
293- </html>
294- ` , map [string ]string {
295- "GoGetImport" : context .ComposeGoGetImport (ownerName , trimmedRepoName ),
296- "CloneLink" : models .ComposeHTTPSCloneURL (ownerName , repoName ),
297- "GoDocDirectory" : prefix + "{/dir}" ,
298- "GoDocFile" : prefix + "{/dir}/{file}#L{line}" ,
299- "Insecure" : insecure ,
300- })))
301- }
302-
303240// RegisterRoutes register routes
304241func RegisterRoutes (m * web.Route ) {
305242 reqSignIn := context .Toggle (& context.ToggleOptions {SignInRequired : true })
@@ -1104,7 +1041,7 @@ func RegisterRoutes(m *web.Route) {
11041041 m .Group ("/{username}" , func () {
11051042 m .Group ("/{reponame}" , func () {
11061043 m .Get ("" , repo .SetEditorconfigIfExists , repo .Home )
1107- }, goGet , ignSignIn , context .RepoAssignment , context .RepoRef (), context .UnitTypes ())
1044+ }, ignSignIn , context .RepoAssignment , context .RepoRef (), context .UnitTypes ())
11081045
11091046 m .Group ("/{reponame}" , func () {
11101047 m .Group ("/info/lfs" , func () {
0 commit comments