update rustpad

This commit is contained in:
Mateusz Gruszczyński
2026-07-27 16:25:49 +02:00
parent fafd240619
commit 4468011429
7 changed files with 114 additions and 164 deletions
+30 -3
View File
@@ -20,7 +20,7 @@ use lettre::{
use rand_core::{OsRng, RngCore};
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use sqlx::FromRow;
use sqlx::{any::AnyRow, FromRow, Row};
use tracing::{debug, info, warn};
use crate::{
@@ -32,7 +32,7 @@ const MIN_PASSWORD: usize = 8;
const MAX_PASSWORD: usize = 128;
const MAX_NICKNAME: usize = 40;
#[derive(Debug, Clone, FromRow)]
#[derive(Debug, Clone)]
pub struct User {
pub id: i64,
pub nickname: String,
@@ -103,7 +103,7 @@ pub struct ResourceActionRequest {
#[serde(default)]
password: Option<String>,
}
#[derive(Serialize, FromRow)]
#[derive(Serialize)]
pub struct ResourceItem {
slug: String,
title: String,
@@ -117,6 +117,33 @@ pub struct ResourceItem {
shared_by: String,
}
impl<'r> sqlx::FromRow<'r, AnyRow> for User {
fn from_row(row: &'r AnyRow) -> Result<Self, sqlx::Error> {
Ok(Self {
id: row.try_get("id")?,
nickname: crate::row_decode::text(row, "nickname")?,
email: crate::row_decode::text(row, "email")?,
password_hash: crate::row_decode::text(row, "password_hash")?,
confirmed_at: crate::row_decode::optional_text(row, "confirmed_at")?,
})
}
}
impl<'r> sqlx::FromRow<'r, AnyRow> for ResourceItem {
fn from_row(row: &'r AnyRow) -> Result<Self, sqlx::Error> {
Ok(Self {
slug: crate::row_decode::text(row, "slug")?,
title: crate::row_decode::text(row, "title")?,
protected: row.try_get("protected")?,
updated_at: crate::row_decode::text(row, "updated_at")?,
private_resource: row.try_get("private")?,
owned: row.try_get("owned")?,
permission: crate::row_decode::text(row, "permission")?,
shared_by: crate::row_decode::text(row, "shared_by")?,
})
}
}
#[derive(Deserialize)]
pub struct PrivacyRequest {
kind: String,