add: profile connections, spotify connection
This commit is contained in:
parent
a5c2356940
commit
33ba576d4a
31 changed files with 931 additions and 19 deletions
|
@ -150,6 +150,21 @@ impl Default for TurnstileConfig {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize, Debug)]
|
||||
pub struct ConnectionsConfig {
|
||||
/// <https://developer.spotify.com/documentation/web-api>
|
||||
#[serde(default)]
|
||||
pub spotify_client_id: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for ConnectionsConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
spotify_client_id: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Configuration file
|
||||
#[derive(Clone, Serialize, Deserialize, Debug)]
|
||||
pub struct Config {
|
||||
|
@ -205,6 +220,8 @@ pub struct Config {
|
|||
/// This community **must** have open write access.
|
||||
#[serde(default)]
|
||||
pub town_square: usize,
|
||||
#[serde(default)]
|
||||
pub connections: ConnectionsConfig,
|
||||
}
|
||||
|
||||
fn default_name() -> String {
|
||||
|
@ -269,6 +286,10 @@ fn default_turnstile() -> TurnstileConfig {
|
|||
TurnstileConfig::default()
|
||||
}
|
||||
|
||||
fn default_connections() -> ConnectionsConfig {
|
||||
ConnectionsConfig::default()
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
|
@ -286,6 +307,7 @@ impl Default for Config {
|
|||
policies: default_policies(),
|
||||
turnstile: default_turnstile(),
|
||||
town_square: 0,
|
||||
connections: default_connections(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
1
crates/core/src/database/connections/mod.rs
Normal file
1
crates/core/src/database/connections/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod spotify;
|
21
crates/core/src/database/connections/spotify.rs
Normal file
21
crates/core/src/database/connections/spotify.rs
Normal 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,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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::*;
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use super::permissions::FinePermission;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use totp_rs::TOTP;
|
||||
|
@ -35,8 +37,14 @@ pub struct User {
|
|||
pub post_count: usize,
|
||||
#[serde(default)]
|
||||
pub request_count: usize,
|
||||
/// External service connection details.
|
||||
#[serde(default)]
|
||||
pub connections: UserConnections,
|
||||
}
|
||||
|
||||
pub type UserConnections =
|
||||
HashMap<ConnectionService, (ExternalConnectionInfo, ExternalConnectionData)>;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub enum ThemePreference {
|
||||
Auto,
|
||||
|
@ -220,6 +228,7 @@ impl User {
|
|||
recovery_codes: Vec::new(),
|
||||
post_count: 0,
|
||||
request_count: 0,
|
||||
connections: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -333,6 +342,42 @@ impl User {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub enum ConnectionService {
|
||||
/// A connection to a Spotify account.
|
||||
Spotify,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub enum ConnectionType {
|
||||
/// A connection through a token with an expiration time.
|
||||
Token,
|
||||
/// <https://www.rfc-editor.org/rfc/rfc7636>
|
||||
PKCE,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct ExternalConnectionInfo {
|
||||
pub con_type: ConnectionType,
|
||||
pub data: HashMap<String, String>,
|
||||
pub show_on_profile: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct ExternalConnectionData {
|
||||
pub external_urls: HashMap<String, String>,
|
||||
pub data: HashMap<String, String>,
|
||||
}
|
||||
|
||||
impl Default for ExternalConnectionData {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
external_urls: HashMap::new(),
|
||||
data: HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Notification {
|
||||
pub id: usize,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue