A music player that connects to your cloud/distributed storage.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Also refresh user dropbox token when saving

+50 -12
+49 -12
src/Applications/Brain/User/State.elm
··· 143 143 SaveAllHypaethralData -> 144 144 saveAllHypaethralData 145 145 146 - SaveHypaethralDataSlowly a -> 147 - saveHypaethralDataSlowly a 146 + SaveHypaethralDataBit a -> 147 + saveHypaethralData a 148 148 149 149 SaveHypaethralDataBits a -> 150 150 saveHypaethralDataBits a 151 + 152 + SaveHypaethralDataSlowly a -> 153 + saveHypaethralDataSlowly a 151 154 152 155 SaveNextHypaethralBit -> 153 156 saveNextHypaethralBit ··· 560 563 in 561 564 case model.authMethod of 562 565 -- 🚀 563 - Just (Dropbox { accessToken, refreshToken }) -> 564 - -- TODO: Refresh token 565 - [ ( "data", json ) 566 - , ( "file", file ) 567 - , ( "token", Json.string accessToken ) 568 - ] 569 - |> Json.object 570 - |> Alien.broadcast Alien.AuthDropbox 571 - |> Ports.toDropbox 572 - |> return model 566 + Just (Dropbox { accessToken, expiresAt, refreshToken }) -> 567 + let 568 + currentTime = 569 + Time.posixToMillis model.currentTime // 1000 570 + 571 + currentTimeWithOffset = 572 + -- We add 60 seconds here because we only get the current time every minute, 573 + -- so there's always the chance the "current time" is 1-60 seconds behind. 574 + currentTime + 60 575 + in 576 + -- If the access token is expired 577 + if currentTimeWithOffset >= expiresAt then 578 + refreshToken 579 + |> Dropbox.refreshAccessToken 580 + |> Task.attempt 581 + (\result -> 582 + case result of 583 + Ok tokens -> 584 + bit 585 + |> SaveHypaethralDataBit 586 + |> RefreshedDropboxTokens 587 + { currentTime = currentTime 588 + , refreshToken = refreshToken 589 + } 590 + tokens 591 + |> UserMsg 592 + 593 + Err err -> 594 + err 595 + |> Alien.report Alien.ReportError 596 + |> Ports.toUI 597 + |> Cmd 598 + ) 599 + |> return model 600 + 601 + else 602 + [ ( "data", json ) 603 + , ( "file", file ) 604 + , ( "token", Json.string accessToken ) 605 + ] 606 + |> Json.object 607 + |> Alien.broadcast Alien.AuthDropbox 608 + |> Ports.toDropbox 609 + |> return model 573 610 574 611 Just (Fission params) -> 575 612 json
+1
src/Applications/Brain/User/Types.elm
··· 53 53 ----------------------------------------- 54 54 | GotWebnativeResponse Webnative.Response 55 55 | SaveAllHypaethralData 56 + | SaveHypaethralDataBit HypaethralBit 56 57 | SaveHypaethralDataBits (List HypaethralBit) 57 58 | SaveHypaethralDataSlowly (Debouncer.Msg HypaethralBit) 58 59 | SaveNextHypaethralBit