You've already forked AstralRinth
forked from didirus/AstralRinth
Add launcher analytics (#661)
* Add more analytics * finish hydra move * Finish websocket flow * add minecraft account flow * Finish playtime vals + payout automation
This commit is contained in:
111
src/models/analytics.rs
Normal file
111
src/models/analytics.rs
Normal file
@@ -0,0 +1,111 @@
|
||||
use clickhouse::Row;
|
||||
use serde::Serialize;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::net::Ipv6Addr;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Row, Serialize, Clone)]
|
||||
pub struct Download {
|
||||
#[serde(with = "uuid::serde::compact")]
|
||||
pub id: Uuid,
|
||||
pub recorded: i64,
|
||||
pub domain: String,
|
||||
pub site_path: String,
|
||||
|
||||
// Modrinth User ID for logged in users, default 0
|
||||
pub user_id: u64,
|
||||
// default is 0 if unknown
|
||||
pub project_id: u64,
|
||||
// default is 0 if unknown
|
||||
pub version_id: u64,
|
||||
|
||||
// The below information is used exclusively for data aggregation and fraud detection
|
||||
// (ex: download botting).
|
||||
pub ip: Ipv6Addr,
|
||||
pub country: String,
|
||||
pub user_agent: String,
|
||||
pub headers: Vec<(String, String)>,
|
||||
}
|
||||
|
||||
impl PartialEq<Self> for Download {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.id == other.id
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for Download {}
|
||||
|
||||
impl Hash for Download {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.id.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Row, Serialize, Clone)]
|
||||
pub struct PageView {
|
||||
#[serde(with = "uuid::serde::compact")]
|
||||
pub id: Uuid,
|
||||
pub recorded: i64,
|
||||
pub domain: String,
|
||||
pub site_path: String,
|
||||
|
||||
// Modrinth User ID for logged in users
|
||||
pub user_id: u64,
|
||||
// Modrinth Project ID (used for payouts)
|
||||
pub project_id: u64,
|
||||
|
||||
// The below information is used exclusively for data aggregation and fraud detection
|
||||
// (ex: page view botting).
|
||||
pub ip: Ipv6Addr,
|
||||
pub country: String,
|
||||
pub user_agent: String,
|
||||
pub headers: Vec<(String, String)>,
|
||||
}
|
||||
|
||||
impl PartialEq<Self> for PageView {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.id == other.id
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for PageView {}
|
||||
|
||||
impl Hash for PageView {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.id.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Row, Serialize, Clone)]
|
||||
pub struct Playtime {
|
||||
#[serde(with = "uuid::serde::compact")]
|
||||
pub id: Uuid,
|
||||
pub recorded: i64,
|
||||
pub seconds: u16,
|
||||
|
||||
// Modrinth User ID for logged in users (unused atm)
|
||||
pub user_id: u64,
|
||||
// Modrinth Project ID
|
||||
pub project_id: u64,
|
||||
// Modrinth Version ID
|
||||
pub version_id: u64,
|
||||
|
||||
pub loader: String,
|
||||
pub game_version: String,
|
||||
/// Parent modpack this playtime was recorded in
|
||||
pub parent: u64,
|
||||
}
|
||||
|
||||
impl PartialEq<Self> for Playtime {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.id == other.id
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for Playtime {}
|
||||
|
||||
impl Hash for Playtime {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.id.hash(state);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,6 @@ pub use super::users::UserId;
|
||||
///
|
||||
/// This method panics if `n` is 0 or greater than 11, since a `u64`
|
||||
/// can only represent up to 11 character base62 strings
|
||||
#[allow(dead_code)]
|
||||
#[inline]
|
||||
pub fn random_base62(n: usize) -> u64 {
|
||||
random_base62_rng(&mut rand::thread_rng(), n)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod analytics;
|
||||
pub mod error;
|
||||
pub mod ids;
|
||||
pub mod notifications;
|
||||
|
||||
@@ -82,7 +82,10 @@ bitflags::bitflags! {
|
||||
// delete a session
|
||||
const SESSION_DELETE = 1 << 29;
|
||||
|
||||
const ALL = 0b111111111111111111111111111111;
|
||||
// perform analytics action
|
||||
const PERFORM_ANALYTICS = 1 << 30;
|
||||
|
||||
const ALL = 0b1111111111111111111111111111111;
|
||||
const NOT_RESTRICTED = 0b00000011111111111111100111;
|
||||
const NONE = 0b0;
|
||||
}
|
||||
@@ -99,7 +102,8 @@ impl Scopes {
|
||||
| Scopes::SESSION_READ
|
||||
| Scopes::SESSION_DELETE
|
||||
| Scopes::USER_AUTH_WRITE
|
||||
| Scopes::USER_DELETE,
|
||||
| Scopes::USER_DELETE
|
||||
| Scopes::PERFORM_ANALYTICS,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user