feat(sync): paginate Android sync with change tokens
This commit is contained in:
1 parent
0ff94f9b10
commit
97c237be80
76 files changed
+3401
-851
No files matched your search
+14
-1
@@ -146,11 +146,24 @@ func requireAPIToken(db *DB) func(http.Handler) http.Handler {
|
||||
writeJSONError(w, http.StatusUnauthorized, "Invalid API token")
|
||||
return
|
||||
}
|
||||
next.ServeHTTP(w, r)
|
||||
ctx := context.WithValue(r.Context(), apiUserIDContextKey{}, userID)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
type apiUserIDContextKey struct{}
|
||||
|
||||
func requestUserID(r *http.Request) int64 {
|
||||
if userID, ok := r.Context().Value(apiUserIDContextKey{}).(int64); ok {
|
||||
return userID
|
||||
}
|
||||
if user := sharedauth.UserFromContext(r.Context()); user != nil {
|
||||
return user.ID
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func extractBearer(r *http.Request) string {
|
||||
header := r.Header.Get("Authorization")
|
||||
if !strings.HasPrefix(header, "Bearer ") {
|
||||
|
||||
Reference in new issue
Block a user