File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package main
3
3
import (
4
4
"crypto/rand"
5
5
"fmt"
6
+ "log"
6
7
"math/big"
7
8
"net/http"
8
9
"os"
@@ -21,13 +22,13 @@ func main() {
21
22
22
23
err := godotenv .Load ()
23
24
if err != nil {
24
- fmt .Println ("Error loading .env file" )
25
+ log .Println ("Error loading .env file" )
25
26
}
26
27
r := chi .NewRouter ()
27
28
28
29
token := os .Getenv ("GITHUB_TOKEN" )
29
30
if token == "" {
30
- fmt .Println ("GITHUB_TOKEN is required" )
31
+ log .Println ("GITHUB_TOKEN is required" )
31
32
os .Exit (1 )
32
33
}
33
34
@@ -46,6 +47,16 @@ func main() {
46
47
}
47
48
48
49
func (server * Server ) MirrorImageHandler (w http.ResponseWriter , req * http.Request ) {
50
+ query := req .URL .Path
51
+ sourceIP := req .RemoteAddr
52
+ log .Printf ("Received request: query=%s, sourceIP=%s\n " , query , sourceIP )
53
+
54
+ userAgent := strings .ToLower (req .Header .Get ("User-Agent" ))
55
+ if ! strings .Contains (userAgent , "curl" ) && ! strings .Contains (userAgent , "wget" ) {
56
+ http .Redirect (w , req , "https://github.com/1mgr/image-mirrors" , http .StatusFound )
57
+ return
58
+ }
59
+
49
60
image := strings .TrimPrefix (req .URL .Path , "/" )
50
61
if image == "" {
51
62
httpError (w , 400 , "image not passed" )
You can’t perform that action at this time.
0 commit comments