File size: 1,618 Bytes
bbb1195 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | use serde::{Deserialize, Serialize};
use super::{token::TokenData, quota::QuotaData};
/// Account data structure
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Account {
pub id: String,
pub email: String,
pub name: Option<String>,
pub token: TokenData,
pub quota: Option<QuotaData>,
pub created_at: i64,
pub last_used: i64,
}
impl Account {
pub fn new(id: String, email: String, token: TokenData) -> Self {
let now = chrono::Utc::now().timestamp();
Self {
id,
email,
name: None,
token,
quota: None,
created_at: now,
last_used: now,
}
}
pub fn update_last_used(&mut self) {
self.last_used = chrono::Utc::now().timestamp();
}
pub fn update_quota(&mut self, quota: QuotaData) {
self.quota = Some(quota);
}
}
/// Account index (accounts.json)
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AccountIndex {
pub version: String,
pub accounts: Vec<AccountSummary>,
pub current_account_id: Option<String>,
}
/// Account summary
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AccountSummary {
pub id: String,
pub email: String,
pub name: Option<String>,
pub created_at: i64,
pub last_used: i64,
}
impl AccountIndex {
pub fn new() -> Self {
Self {
version: "2.0".to_string(),
accounts: Vec::new(),
current_account_id: None,
}
}
}
impl Default for AccountIndex {
fn default() -> Self {
Self::new()
}
}
|