• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

0xmichalis / nftbk / 18525274937

15 Oct 2025 10:05AM UTC coverage: 35.433% (+0.007%) from 35.426%
18525274937

push

github

0xmichalis
refactor: give more accurate names to ipfs pinning-related vars

14 of 34 new or added lines in 10 files covered. (41.18%)

1406 of 3968 relevant lines covered (35.43%)

6.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

27.03
/src/server/mod.rs
1
use std::collections::HashMap;
2
use std::str::FromStr;
3
use std::sync::atomic::AtomicBool;
4
use std::sync::Arc;
5
use tokio::sync::mpsc;
6
use tokio::sync::Mutex;
7
use tracing::{error, info};
8

9
use crate::backup::ChainConfig;
10
use crate::ipfs::{IpfsPinningConfig, IpfsPinningProvider};
11
use crate::server::api::{BackupRequest, Tokens};
12
use crate::server::database::Db;
13

14
pub mod api;
15
pub mod archive;
16
pub mod database;
17
pub mod handlers;
18
pub mod hashing;
19
pub mod pin_monitor;
20
pub mod privy;
21
pub mod pruner;
22
pub mod recovery;
23
pub mod router;
24
pub mod workers;
25
pub use handlers::handle_backup::handle_backup;
26
pub use handlers::handle_backup_delete_archive::handle_backup_delete_archive;
27
pub use handlers::handle_backup_delete_pins::handle_backup_delete_pins;
28
pub use handlers::handle_backup_retry::handle_backup_retry;
29
pub use handlers::handle_backups::handle_backups;
30
pub use handlers::handle_download::handle_download;
31
pub use handlers::handle_download::handle_download_token;
32
pub use handlers::handle_status::handle_status;
33
pub use recovery::{recover_incomplete_tasks, RecoveryDb};
34
pub use workers::deletion::{complete_deletion_for_scope, start_deletion_for_scope};
35
pub use workers::spawn_backup_workers;
36

37
#[derive(Debug, Clone)]
38
pub enum BackupTaskOrShutdown {
39
    Task(TaskType),
40
    Shutdown,
41
}
42

43
#[derive(Debug, Clone)]
44
pub enum TaskType {
45
    Creation(BackupTask),
46
    Deletion(DeletionTask),
47
}
48

49
#[derive(Debug, Clone)]
50
pub struct BackupTask {
51
    pub task_id: String,
52
    pub request: BackupRequest,
53
    pub force: bool,
54
    pub scope: StorageMode,
55
    pub archive_format: Option<String>,
56
    pub requestor: Option<String>,
57
}
58

59
#[derive(Debug, Clone)]
60
pub struct DeletionTask {
61
    pub task_id: String,
62
    pub requestor: Option<String>,
63
    /// Determines which parts of the backup to delete (e.g., only the archive, only the IPFS pins, or both).
64
    pub scope: StorageMode,
65
}
66

67
#[derive(Debug, Clone, PartialEq, Eq)]
68
pub enum StorageMode {
69
    Archive,
70
    Ipfs,
71
    Full,
72
}
73

74
impl StorageMode {
75
    pub fn as_str(&self) -> &'static str {
7✔
76
        match self {
7✔
77
            StorageMode::Archive => "archive",
6✔
78
            StorageMode::Ipfs => "ipfs",
1✔
79
            StorageMode::Full => "full",
×
80
        }
81
    }
82
}
83

84
impl FromStr for StorageMode {
85
    type Err = String;
86

87
    fn from_str(s: &str) -> Result<Self, Self::Err> {
5✔
88
        match s {
5✔
89
            "archive" => Ok(StorageMode::Archive),
8✔
90
            "ipfs" => Ok(StorageMode::Ipfs),
2✔
91
            "full" => Ok(StorageMode::Full),
3✔
92
            _ => Err(format!("Unknown storage mode: {}", s)),
1✔
93
        }
94
    }
95
}
96

97
#[derive(Clone)]
98
pub struct AppState {
99
    pub chain_config: Arc<ChainConfig>,
100
    pub base_dir: Arc<String>,
101
    pub unsafe_skip_checksum_check: bool,
102
    pub auth_token: Option<String>,
103
    pub pruner_enabled: bool,
104
    pub pruner_retention_days: u64,
105
    pub download_tokens: Arc<Mutex<HashMap<String, (String, u64)>>>,
106
    pub backup_task_sender: mpsc::Sender<BackupTaskOrShutdown>,
107
    pub db: Arc<Db>,
108
    pub shutdown_flag: Arc<AtomicBool>,
109
    pub ipfs_pinning_configs: Vec<IpfsPinningConfig>,
110
    pub ipfs_pinning_instances: Arc<Vec<Arc<dyn IpfsPinningProvider>>>,
111
}
112

113
impl Default for AppState {
114
    fn default() -> Self {
×
115
        panic!("AppState::default() should not be used; use AppState::new() instead");
×
116
    }
117
}
118

119
impl AppState {
120
    #[allow(clippy::too_many_arguments)]
121
    pub async fn new(
×
122
        chain_config_path: &str,
123
        base_dir: &str,
124
        unsafe_skip_checksum_check: bool,
125
        auth_token: Option<String>,
126
        pruner_enabled: bool,
127
        pruner_retention_days: u64,
128
        backup_task_sender: mpsc::Sender<BackupTaskOrShutdown>,
129
        db_url: &str,
130
        max_connections: u32,
131
        shutdown_flag: Arc<AtomicBool>,
132
        ipfs_pinning_configs: Vec<IpfsPinningConfig>,
133
    ) -> Self {
134
        let config_content = tokio::fs::read_to_string(chain_config_path)
×
135
            .await
×
136
            .expect("Failed to read chain config");
137
        let chains: std::collections::HashMap<String, String> =
×
138
            toml::from_str(&config_content).expect("Failed to parse chain config");
×
139
        let mut chain_config = ChainConfig(chains);
×
140
        chain_config
×
141
            .resolve_env_vars()
142
            .expect("Failed to resolve environment variables in chain config");
143
        let db = Arc::new(Db::new(db_url, max_connections).await);
×
144

145
        // Create IPFS provider instances at startup
NEW
146
        let mut ipfs_pinning_instances = Vec::new();
×
NEW
147
        for config in &ipfs_pinning_configs {
×
148
            match config.create_provider() {
×
149
                Ok(provider) => {
×
150
                    info!(
×
151
                        "Successfully created IPFS provider {} ({})",
×
152
                        provider.provider_type(),
×
153
                        provider.provider_url()
×
154
                    );
NEW
155
                    ipfs_pinning_instances.push(Arc::from(provider));
×
156
                }
157
                Err(e) => {
×
158
                    error!(
×
159
                        "Failed to create IPFS provider from config {:?}: {}",
×
160
                        config, e
161
                    );
162
                }
163
            }
164
        }
165

166
        AppState {
167
            chain_config: Arc::new(chain_config),
×
168
            base_dir: Arc::new(base_dir.to_string()),
×
169
            unsafe_skip_checksum_check,
170
            auth_token,
171
            pruner_enabled,
172
            pruner_retention_days,
173
            download_tokens: Arc::new(tokio::sync::Mutex::new(HashMap::new())),
×
174
            backup_task_sender,
175
            db,
176
            shutdown_flag,
177
            ipfs_pinning_configs,
NEW
178
            ipfs_pinning_instances: Arc::new(ipfs_pinning_instances),
×
179
        }
180
    }
181
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc