mirror of
https://github.com/0PandaDEV/Qopy.git
synced 2025-04-21 13:14: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,16 +1,19 @@
|
||||||
use crate::utils::types::{ ContentType, HistoryItem };
|
use crate::utils::types::{ ContentType, HistoryItem };
|
||||||
use base64::{ engine::general_purpose::STANDARD, Engine };
|
use base64::{ engine::general_purpose::STANDARD, Engine };
|
||||||
use rand::distributions::Alphanumeric;
|
use rand::{ rng, Rng };
|
||||||
use rand::{ thread_rng, Rng };
|
use rand::distr::Alphanumeric;
|
||||||
use sqlx::{ Row, SqlitePool };
|
use sqlx::{ Row, SqlitePool };
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use tauri_plugin_aptabase::EventTracker;
|
use tauri_plugin_aptabase::EventTracker;
|
||||||
|
|
||||||
pub async fn initialize_history(pool: &SqlitePool) -> Result<(), Box<dyn std::error::Error>> {
|
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
|
sqlx::query(
|
||||||
::query(
|
|
||||||
"INSERT INTO history (id, source, content_type, content, timestamp) VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP)"
|
"INSERT INTO history (id, source, content_type, content, timestamp) VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP)"
|
||||||
)
|
)
|
||||||
.bind(id)
|
.bind(id)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue