mirror of
https://github.com/0PandaDEV/Qopy.git
synced 2025-04-22 05:34:04 +02:00
refactor: simplify random ID generation in history initialization
This commit is contained in:
parent
6016fbb494
commit
66df55017f
1 changed files with 15 additions and 12 deletions
|
@ -1,23 +1,26 @@
|
|||
use crate::utils::types::{ ContentType, HistoryItem };
|
||||
use base64::{ engine::general_purpose::STANDARD, Engine };
|
||||
use rand::distributions::Alphanumeric;
|
||||
use rand::{ thread_rng, Rng };
|
||||
use rand::{ rng, Rng };
|
||||
use rand::distr::Alphanumeric;
|
||||
use sqlx::{ Row, SqlitePool };
|
||||
use std::fs;
|
||||
use tauri_plugin_aptabase::EventTracker;
|
||||
|
||||
pub async fn initialize_history(pool: &SqlitePool) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let id: String = thread_rng().sample_iter(&Alphanumeric).take(16).map(char::from).collect();
|
||||
let id: String = rng()
|
||||
.sample_iter(&Alphanumeric)
|
||||
.take(16)
|
||||
.map(char::from)
|
||||
.collect();
|
||||
|
||||
sqlx
|
||||
::query(
|
||||
"INSERT INTO history (id, source, content_type, content, timestamp) VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP)"
|
||||
)
|
||||
.bind(id)
|
||||
.bind("System")
|
||||
.bind("text")
|
||||
.bind("Welcome to your clipboard history!")
|
||||
.execute(pool).await?;
|
||||
sqlx::query(
|
||||
"INSERT INTO history (id, source, content_type, content, timestamp) VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP)"
|
||||
)
|
||||
.bind(id)
|
||||
.bind("System")
|
||||
.bind("text")
|
||||
.bind("Welcome to your clipboard history!")
|
||||
.execute(pool).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue