Impl /auth/token/delete

This commit is contained in:
2022-10-17 06:08:29 +00:00
committed by GitHub
parent d95885749a
commit 3c6c9f5812
7 changed files with 200 additions and 16 deletions

View File

@@ -220,6 +220,12 @@ impl PixivDownloaderSqlite {
Ok(())
}
#[cfg(feature = "server")]
fn _delete_token(tx: &Transaction, id: u64) -> Result<(), SqliteError> {
tx.execute("DELETE FROM token WHERE id = ?;", [id])?;
Ok(())
}
#[cfg(feature = "server")]
fn _delete_user(tx: &Transaction, id: u64) -> Result<bool, SqliteError> {
let af = tx.execute("DELETE FROM users WHERE id = ?;", [id])?;
@@ -594,6 +600,15 @@ impl PixivDownloaderDb for PixivDownloaderSqlite {
.expect("User not found:"))
}
#[cfg(feature = "server")]
async fn delete_token(&self, id: u64) -> Result<(), PixivDownloaderDbError> {
let mut db = self.db.lock().await;
let mut tx = db.transaction()?;
Self::_delete_token(&mut tx, id)?;
tx.commit()?;
Ok(())
}
#[cfg(feature = "server")]
async fn delete_user(&self, id: u64) -> Result<bool, PixivDownloaderDbError> {
let mut db = self.db.lock().await;

View File

@@ -55,6 +55,10 @@ pub trait PixivDownloaderDb {
is_admin: bool,
) -> Result<User, PixivDownloaderDbError>;
#[cfg(feature = "server")]
/// Delete a token
/// * `id` - The token ID
async fn delete_token(&self, id: u64) -> Result<(), PixivDownloaderDbError>;
#[cfg(feature = "server")]
/// Delete a user
/// * `id` - User ID
/// # Note