darkwing/server/services/browser_profile_services/config/
dolphin_specific.rs

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
use crate::server::{
  dtos::{
    browser_profile_dto::BrowserProfileFullData, start_dto::StartRequest,
  },
  error::Error,
};
use serde::{Deserialize, Serialize};

use super::{FromStartRequest, Navigator, Screen};

/// Configuration specific to Dolphin browser integration
///
/// Contains authentication tokens and API configuration needed
/// for our extensions to work.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct DolphinSpecific {
  /// Unique identifier for the browser profile
  pub(super) profile_id: u64,

  /// Authentication token for Anty API access
  pub(super) anty_token: String,

  /// Integration token for Dolphin-specific functionality
  pub(super) dolphin_integration_token: String,

  /// Base URL for the remote API
  pub(super) base_url: String,

  /// Version string for the API being used
  pub(super) api_version: String,

  /// Language setting for the user interface
  pub(super) user_language: String,
}

/// Implementation to create DolphinSpecific config from a start request
impl FromStartRequest<DolphinSpecific> for DolphinSpecific {
  /// Creates a new DolphinSpecific configuration from the provided start
  /// request and profile data
  ///
  /// # Arguments
  /// * `bp` - Browser profile data containing profile information
  /// * `request` - Start request containing configuration parameters
  /// * `_navigator` - Navigator configuration (unused)
  /// * `_screen` - Screen configuration (unused)
  /// * `token` - Authentication token
  ///
  /// # Returns
  /// * `Result<DolphinSpecific, Error>` - The created configuration or an error
  fn from_start_request(
    bp: &BrowserProfileFullData,
    request: &StartRequest,
    _navigator: &Navigator,
    _screen: &Screen,
    token: &str,
  ) -> Result<Self, Error> {
    let dolphin_integration_token = request
      .dolphin_integration_token
      .clone()
      .unwrap_or_default();

    Ok(Self {
      profile_id: bp.id,
      anty_token: format!("Bearer {}", token),
      dolphin_integration_token,
      base_url: request.remote_api_base_url.clone(),
      api_version: request.versions.local_api.clone(),
      user_language: "ru".to_string(),
    })
  }
}