feat: initialize app data and apply clippy lints
This commit is contained in:
parent
f8660f9216
commit
35aa155c0e
3 changed files with 59 additions and 5 deletions
53
src/data.rs
Normal file
53
src/data.rs
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* ForgeFlux StarChart - A federated software forge spider
|
||||
* Copyright © 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use reqwest::{Client, ClientBuilder};
|
||||
|
||||
use crate::settings::Settings;
|
||||
use crate::{DOMAIN, PKG_NAME, VERSION};
|
||||
|
||||
lazy_static! {
|
||||
pub static ref USER_AGENT: String = format!("{VERSION}---{PKG_NAME}---{DOMAIN}");
|
||||
}
|
||||
/// in seconds
|
||||
const CLIENT_TIMEOUT: u64 = 60;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Data {
|
||||
pub client: Client,
|
||||
pub settings: Settings,
|
||||
}
|
||||
|
||||
impl Data {
|
||||
pub async fn new(settings: Settings) -> Arc<Self> {
|
||||
let timeout = Duration::new(CLIENT_TIMEOUT, 0);
|
||||
let client = ClientBuilder::new()
|
||||
.user_agent(&*USER_AGENT)
|
||||
.use_rustls_tls()
|
||||
.timeout(timeout)
|
||||
.connect_timeout(timeout)
|
||||
.tcp_keepalive(timeout)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
Arc::new(Self { client, settings })
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
pub mod data;
|
||||
pub mod gitea;
|
||||
pub mod settings;
|
||||
pub mod utils;
|
||||
|
|
|
@ -121,12 +121,12 @@ impl DatabaseBuilder {
|
|||
let name = path.next().expect("no database name").to_string();
|
||||
|
||||
let database_type = DBType::from_url(url).unwrap();
|
||||
let port;
|
||||
if database_type == DBType::Sqlite {
|
||||
port = 0;
|
||||
let port = if database_type == DBType::Sqlite {
|
||||
0
|
||||
} else {
|
||||
port = url.port().expect("Enter database port").into();
|
||||
}
|
||||
url.port().expect("Enter database port").into()
|
||||
};
|
||||
|
||||
DatabaseBuilder {
|
||||
port,
|
||||
hostname: url.host().expect("Enter database host").to_string(),
|
||||
|
|
Loading…
Reference in a new issue