8
8
"encoding/gob"
9
9
"fmt"
10
10
"net/http"
11
- "net/url"
12
11
"os"
13
12
"path"
14
13
"strings"
@@ -22,7 +21,6 @@ import (
22
21
"code.gitea.io/gitea/modules/setting"
23
22
"code.gitea.io/gitea/modules/storage"
24
23
"code.gitea.io/gitea/modules/templates"
25
- "code.gitea.io/gitea/modules/util"
26
24
"code.gitea.io/gitea/modules/validation"
27
25
"code.gitea.io/gitea/modules/web"
28
26
"code.gitea.io/gitea/routers"
@@ -51,7 +49,6 @@ import (
51
49
"github.com/go-chi/cors"
52
50
"github.com/prometheus/client_golang/prometheus"
53
51
"github.com/tstranex/u2f"
54
- "github.com/unknwon/com"
55
52
)
56
53
57
54
const (
@@ -173,7 +170,7 @@ func WebRoutes() *web.Route {
173
170
174
171
// this png is very likely to always be below the limit for gzip so it doesn't need to pass through gzip
175
172
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 )
177
174
})
178
175
179
176
gob .Register (& u2f.Challenge {})
@@ -228,6 +225,7 @@ func WebRoutes() *web.Route {
228
225
// TODO: These really seem like things that could be folded into Contexter or as helper functions
229
226
common = append (common , user .GetNotificationCount )
230
227
common = append (common , repo .GetActiveStopwatch )
228
+ common = append (common , goGet )
231
229
232
230
others := web .NewRoute ()
233
231
for _ , middle := range common {
@@ -239,67 +237,6 @@ func WebRoutes() *web.Route {
239
237
return routes
240
238
}
241
239
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
-
303
240
// RegisterRoutes register routes
304
241
func RegisterRoutes (m * web.Route ) {
305
242
reqSignIn := context .Toggle (& context.ToggleOptions {SignInRequired : true })
@@ -1104,7 +1041,7 @@ func RegisterRoutes(m *web.Route) {
1104
1041
m .Group ("/{username}" , func () {
1105
1042
m .Group ("/{reponame}" , func () {
1106
1043
m .Get ("" , repo .SetEditorconfigIfExists , repo .Home )
1107
- }, goGet , ignSignIn , context .RepoAssignment , context .RepoRef (), context .UnitTypes ())
1044
+ }, ignSignIn , context .RepoAssignment , context .RepoRef (), context .UnitTypes ())
1108
1045
1109
1046
m .Group ("/{reponame}" , func () {
1110
1047
m .Group ("/info/lfs" , func () {
0 commit comments