|
4 | 4 | "encoding/json" |
5 | 5 | "fmt" |
6 | 6 | "net/http" |
| 7 | + "time" |
7 | 8 |
|
8 | 9 | "github.com/Bananenpro/cli" |
9 | 10 | "github.com/code-game-project/go-utils/config" |
@@ -36,6 +37,25 @@ var sessionImportCmd = &cobra.Command{ |
36 | 37 | resp, err := http.Get(fmt.Sprintf(baseURL+"/%s?type=session", id)) |
37 | 38 | abortf(fmt.Sprintf("Failed to contact %s: %s", conf.ShareURL, "%s"), err) |
38 | 39 |
|
| 40 | + for resp.StatusCode == http.StatusForbidden { |
| 41 | + password, err := cli.Input("Password:") |
| 42 | + abort(err) |
| 43 | + request, err := http.NewRequest("GET", fmt.Sprintf(baseURL+"/%s?type=session", id), nil) |
| 44 | + abort(err) |
| 45 | + request.Header.Set("Password", password) |
| 46 | + resp, err = http.DefaultClient.Do(request) |
| 47 | + abortf(fmt.Sprintf("Failed to contact %s: %s", conf.ShareURL, "%s"), err) |
| 48 | + if resp.StatusCode == http.StatusTooManyRequests { |
| 49 | + time.Sleep(1 * time.Second) |
| 50 | + resp, err = http.DefaultClient.Do(request) |
| 51 | + abortf(fmt.Sprintf("Failed to contact %s: %s", conf.ShareURL, "%s"), err) |
| 52 | + } |
| 53 | + if resp.StatusCode != http.StatusForbidden { |
| 54 | + break |
| 55 | + } |
| 56 | + cli.Error("Wrong password. Try again.") |
| 57 | + } |
| 58 | + |
39 | 59 | type resSession struct { |
40 | 60 | GameId string `json:"game_id"` |
41 | 61 | PlayerId string `json:"player_id"` |
|
0 commit comments