1use serde::{Deserialize, Serialize};
2
3use crate::Timestamp;
4
5#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
9#[cfg_attr(feature = "typescript", derive(ts_rs::TS))]
10#[cfg_attr(feature = "typescript", ts(export_to = "controller-api.ts"))]
11pub struct ApiKey {
12 pub id: i64,
13 pub name: String,
14 pub ending: String,
16 pub created_at: Timestamp,
17 pub last_used_at: Option<Timestamp>,
19}
20
21impl ApiKey {
22 pub const PREFIX: &str = "dvm_";
25
26 pub fn masked(&self) -> String {
29 format!("{}…{}", Self::PREFIX, self.ending)
30 }
31}
32
33#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
35#[cfg_attr(feature = "typescript", derive(ts_rs::TS))]
36#[cfg_attr(feature = "typescript", ts(export_to = "controller-api.ts"))]
37pub struct NewApiKey {
38 pub name: String,
39}
40
41#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
43#[cfg_attr(feature = "typescript", derive(ts_rs::TS))]
44#[cfg_attr(feature = "typescript", ts(export_to = "controller-api.ts"))]
45pub struct CreatedApiKey {
46 pub key: ApiKey,
47 pub secret: String,
48}