Skip to content

Commit

Permalink
BUGFIX download all cmd is fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
prnvbn committed Oct 25, 2022
1 parent f6eebe7 commit 97d2513
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 5 additions & 4 deletions cmd/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ var allCmd = &cobra.Command{
Short: "download all files from scientia",
Long: `TODO`,
RunE: func(cmd *cobra.Command, args []string) (err error) {
courses, err = client.GetCourses()
if err != nil {
return err
}

for _, course := range courses {
if course.HasMaterials {
courses, err = client.GetCourses()
if err != nil {
return err
}
err := downloadCourse(course, unmodifiedOnly)
if err != nil {
fmt.Println(err)
Expand Down
9 changes: 7 additions & 2 deletions scientia/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,24 @@ func (c *APIClient) Do(req *http.Request) (*http.Response, error) {
resp, err := c.Client.Do(req)

// token has not expired
if err != nil || (resp.StatusCode == http.StatusOK && resp.StatusCode != http.StatusUnauthorized) {
if err != nil || (resp.StatusCode == http.StatusOK || resp.StatusCode != http.StatusUnprocessableEntity) {
return resp, err
}

refreshReq, _ := http.NewRequest("POST", c.baseURL+"auth/refresh", nil)

req.Header.Set("Cookie", "refresh_token_cookie="+c.refreshToken)
refreshReq.Header.Set("Cookie", "access_token_cookie="+c.accessToken)
refreshReq.Header.Set("Cookie", "refresh_token_cookie="+c.refreshToken)
refreshResp, err := c.Client.Do(refreshReq)
if err != nil {
return nil, errors.Wrap(err, "Couldn't refresh access token, please login again")
}

fmt.Printf("refreshResp.StatusCode: %v\n", refreshResp.StatusCode)

old := c.accessToken
c.setAuthTokens(refreshResp)
fmt.Println(c.accessToken == old)
req.Header.Set("Cookie", "access_token_cookie="+c.accessToken)
return c.Client.Do(req)
}
Expand Down

0 comments on commit 97d2513

Please sign in to comment.