From 3f00a6efbec422ed7221c761107be6689fb5dd34 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Wed, 23 Jun 2021 17:28:02 +0200 Subject: [PATCH] allow token::save() to handle existing tokens --- src/token.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/token.rs b/src/token.rs index f58dd1594..a0e60d9de 100644 --- a/src/token.rs +++ b/src/token.rs @@ -31,8 +31,12 @@ impl Default for Namespace { /// Creates a new token and saves it into the database. /// /// Returns created token. -pub async fn save(context: &Context, namespace: Namespace, foreign_id: Option) -> String { - let token = dc_create_id(); +pub async fn save( + context: &Context, + namespace: Namespace, + foreign_id: Option, + token: String, +) -> String { match foreign_id { Some(foreign_id) => context .sql @@ -93,7 +97,8 @@ pub async fn lookup_or_new( return token; } - save(context, namespace, foreign_id).await + let token = dc_create_id(); + save(context, namespace, foreign_id, token).await } pub async fn exists(context: &Context, namespace: Namespace, token: &str) -> bool {