chore: testing n94 streams

This commit is contained in:
2024-11-19 17:12:03 +00:00
parent e111e50199
commit 877db958fc
9 changed files with 223 additions and 141 deletions

View File

@ -8,7 +8,8 @@ create table user
tos_accepted timestamp,
stream_key text not null default uuid(),
is_admin bool not null default false,
is_blocked bool not null default false
is_blocked bool not null default false,
recording bool not null default false
);
create unique index ix_user_pubkey on user (pubkey);
create table user_stream

View File

@ -1,4 +1,4 @@
use crate::UserStream;
use crate::{User, UserStream};
use anyhow::Result;
use sqlx::{MySqlPool, Row};
use uuid::Uuid;
@ -33,6 +33,15 @@ impl ZapStreamDb {
.map(|r| r.try_get(0).unwrap()))
}
/// Get user by id
pub async fn get_user(&self, uid: u64) -> Result<User> {
Ok(sqlx::query_as("select * from user where id = ?")
.bind(uid)
.fetch_one(&self.db)
.await
.map_err(anyhow::Error::new)?)
}
pub async fn upsert_user(&self, pubkey: &[u8; 32]) -> Result<u64> {
let res = sqlx::query("insert ignore into user(pubkey) values(?) returning id")
.bind(pubkey.as_slice())

View File

@ -5,14 +5,24 @@ use uuid::Uuid;
#[derive(Debug, Clone, FromRow)]
pub struct User {
/// Database ID for this uer
pub id: u64,
pub pubkey: [u8; 32],
/// Nostr pubkey of this user
pub pubkey: Vec<u8>,
/// Timestamp when this user first used the service
pub created: DateTime<Utc>,
/// Current balance in milli-sats
pub balance: i64,
pub tos_accepted: DateTime<Utc>,
/// When the TOS was accepted
pub tos_accepted: Option<DateTime<Utc>>,
/// Primary stream key
pub stream_key: String,
/// If the user is an admin
pub is_admin: bool,
/// If the user is blocked from streaming
pub is_blocked: bool,
/// Streams are recorded
pub recording: bool,
}
#[derive(Default, Debug, Clone, Type)]