add: profile connections, spotify connection

This commit is contained in:
trisua 2025-04-26 16:27:18 -04:00
parent a5c2356940
commit 33ba576d4a
31 changed files with 931 additions and 19 deletions

View file

@ -1,5 +1,6 @@
use super::*;
use crate::cache::Cache;
use crate::model::auth::UserConnections;
use crate::model::moderation::AuditLogEntry;
use crate::model::{
Error, Result,
@ -42,6 +43,7 @@ impl DataManager {
recovery_codes: serde_json::from_str(&get!(x->14(String)).to_string()).unwrap(),
post_count: get!(x->15(i32)) as usize,
request_count: get!(x->16(i32)) as usize,
connections: serde_json::from_str(&get!(x->17(String)).to_string()).unwrap(),
}
}
@ -136,7 +138,7 @@ impl DataManager {
let res = execute!(
&conn,
"INSERT INTO users VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)",
"INSERT INTO users VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18)",
params![
&(data.id as i64),
&(data.created as i64),
@ -154,7 +156,8 @@ impl DataManager {
&String::new(),
&"[]",
&0_i32,
&0_i32
&0_i32,
&serde_json::to_string(&data.connections).unwrap(),
]
);
@ -630,6 +633,7 @@ impl DataManager {
auto_method!(update_user_tokens(Vec<Token>)@get_user_by_id -> "UPDATE users SET tokens = $1 WHERE id = $2" --serde --cache-key-tmpl=cache_clear_user);
auto_method!(update_user_settings(UserSettings)@get_user_by_id -> "UPDATE users SET settings = $1 WHERE id = $2" --serde --cache-key-tmpl=cache_clear_user);
auto_method!(update_user_connections(UserConnections)@get_user_by_id -> "UPDATE users SET connections = $1 WHERE id = $2" --serde --cache-key-tmpl=cache_clear_user);
auto_method!(incr_user_notifications()@get_user_by_id -> "UPDATE users SET notification_count = notification_count + 1 WHERE id = $1" --cache-key-tmpl=cache_clear_user --incr);
auto_method!(decr_user_notifications()@get_user_by_id -> "UPDATE users SET notification_count = notification_count - 1 WHERE id = $1" --cache-key-tmpl=cache_clear_user --decr);

View file

@ -0,0 +1 @@
pub mod spotify;

View file

@ -0,0 +1,21 @@
use std::collections::HashMap;
use crate::{
config::Config,
model::auth::{ConnectionType, ExternalConnectionInfo, UserConnections},
};
/// A connection to Spotify.
///
/// <https://developer.spotify.com/documentation/web-api>
pub struct SpotifyConnection(pub UserConnections, pub Config);
impl SpotifyConnection {
/// Create a new [`ExternalConnectionInfo`] for the connection.
pub fn connection() -> ExternalConnectionInfo {
ExternalConnectionInfo {
con_type: ConnectionType::PKCE,
data: HashMap::new(),
show_on_profile: true,
}
}
}

View file

@ -15,5 +15,6 @@ CREATE TABLE IF NOT EXISTS users (
totp TEXT NOT NULL,
recovery_codes TEXT NOT NULL,
post_count INT NOT NULL,
request_count INT NOT NULL
request_count INT NOT NULL,
connections TEXT NOT NULL
)

View file

@ -2,6 +2,7 @@ mod audit_log;
mod auth;
mod common;
mod communities;
pub mod connections;
mod drivers;
mod ipbans;
mod ipblocks;
@ -17,9 +18,9 @@ mod userblocks;
mod userfollows;
#[cfg(feature = "redis")]
pub mod channels;
mod channels;
#[cfg(feature = "redis")]
pub mod messages;
mod messages;
#[cfg(feature = "sqlite")]
pub use drivers::sqlite::*;