mirror of
https://github.com/YGGverse/rssto.git
synced 2026-04-01 01:25:29 +00:00
use config file instead of argument options
This commit is contained in:
parent
ec0cca64f3
commit
3e94399ccb
15 changed files with 162 additions and 123 deletions
|
|
@ -15,3 +15,5 @@ clap = { version = "4.5.54", features = ["derive"] }
|
|||
mysql = { package = "rssto-mysql", version = "0.1.0", path = "../mysql" }
|
||||
rocket = "0.5.1"
|
||||
rocket_dyn_templates = { version = "0.2.0", features = ["tera"] }
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
toml = "0.9.10"
|
||||
|
|
@ -7,8 +7,5 @@ Web server implementation based on the Rocket engine
|
|||
|
||||
```
|
||||
cd rssto/crates/rssto-http
|
||||
cargo run -- --mysql-username {USER} \
|
||||
--mysql-password {PASS} \
|
||||
--mysql-database {NAME}
|
||||
```
|
||||
* optionally, use `--provider-id {ID}` to filter content using post-processing results (e.g. generated by the `rssto-llm` crate)
|
||||
cargo run -- -c /path/to/config.toml
|
||||
```
|
||||
33
crates/http/config.toml
Normal file
33
crates/http/config.toml
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
title = "rssto"
|
||||
#description = ""
|
||||
|
||||
# Replace image sources with local
|
||||
# * if crawled with the `persist_images_selector` selector
|
||||
local_images = true
|
||||
|
||||
format_time = "%d/%m/%Y %H:%M"
|
||||
|
||||
# Provider ID (`provider` table)
|
||||
# * None for the original content
|
||||
# provider_id = 1
|
||||
|
||||
# Default listing limit
|
||||
list_limit = 20
|
||||
|
||||
# Bind server on given host
|
||||
host = "127.0.0.1"
|
||||
|
||||
# Bind server on given port
|
||||
port = 8000
|
||||
|
||||
#Configure instance in the debug mode
|
||||
debug = true
|
||||
|
||||
# Database connection setup
|
||||
# * see crates/mysql/database
|
||||
[mysql]
|
||||
host = "localhost"
|
||||
port = 3306
|
||||
username = ""
|
||||
password = ""
|
||||
database = "rssto"
|
||||
12
crates/http/src/argument.rs
Normal file
12
crates/http/src/argument.rs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
use clap::Parser;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
pub struct Argument {
|
||||
/// Path to config file
|
||||
///
|
||||
/// * see `config.toml`
|
||||
#[arg(short, long)]
|
||||
pub config: PathBuf,
|
||||
}
|
||||
|
|
@ -1,53 +1,24 @@
|
|||
use clap::Parser;
|
||||
use std::net::{IpAddr, Ipv4Addr};
|
||||
use serde::Deserialize;
|
||||
use std::net::IpAddr;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
pub struct Config {
|
||||
/// Server name
|
||||
#[arg(long, default_value_t = String::from("rssto"))]
|
||||
pub title: String,
|
||||
|
||||
/// Server description
|
||||
#[arg(long)]
|
||||
pub description: Option<String>,
|
||||
|
||||
/// Format timestamps (on the web view)
|
||||
///
|
||||
/// * tip: escape with `%%d/%%m/%%Y %%H:%%M` in the CLI/bash argument
|
||||
#[arg(long, default_value_t = String::from("%d/%m/%Y %H:%M"))]
|
||||
pub format_time: String,
|
||||
|
||||
/// Provider ID (`provider` table)
|
||||
/// * None for the original content
|
||||
#[arg(long, short)]
|
||||
pub provider_id: Option<u64>,
|
||||
|
||||
/// Default listing limit
|
||||
#[arg(long, default_value_t = 20)]
|
||||
pub list_limit: usize,
|
||||
|
||||
/// Bind server on given host
|
||||
#[arg(long, default_value_t = IpAddr::V4(Ipv4Addr::LOCALHOST))]
|
||||
pub host: IpAddr,
|
||||
|
||||
/// Bind server on given port
|
||||
#[arg(long, default_value_t = 8000)]
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Mysql {
|
||||
pub database: String,
|
||||
pub host: String,
|
||||
pub password: String,
|
||||
pub port: u16,
|
||||
|
||||
/// Configure instance in the debug mode
|
||||
#[arg(long, default_value_t = false)]
|
||||
pub debug: bool,
|
||||
|
||||
// Database
|
||||
#[arg(long, default_value_t = String::from("localhost"))]
|
||||
pub mysql_host: String,
|
||||
#[arg(long, default_value_t = 3306)]
|
||||
pub mysql_port: u16,
|
||||
#[arg(long)]
|
||||
pub mysql_username: String,
|
||||
#[arg(long)]
|
||||
pub mysql_password: String,
|
||||
#[arg(long)]
|
||||
pub mysql_database: String,
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Config {
|
||||
pub mysql: Mysql,
|
||||
pub title: String,
|
||||
pub description: Option<String>,
|
||||
pub format_time: String,
|
||||
pub provider_id: Option<u64>,
|
||||
pub list_limit: usize,
|
||||
pub host: IpAddr,
|
||||
pub port: u16,
|
||||
pub debug: bool,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
#[macro_use]
|
||||
extern crate rocket;
|
||||
|
||||
mod argument;
|
||||
mod config;
|
||||
mod feed;
|
||||
mod global;
|
||||
mod meta;
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use config::Config;
|
||||
use feed::Feed;
|
||||
use global::Global;
|
||||
use meta::Meta;
|
||||
|
|
@ -187,7 +187,9 @@ fn rss(
|
|||
#[launch]
|
||||
fn rocket() -> _ {
|
||||
use clap::Parser;
|
||||
let config = Config::parse();
|
||||
let argument = argument::Argument::parse();
|
||||
let config: config::Config =
|
||||
toml::from_str(&std::fs::read_to_string(argument.config).unwrap()).unwrap();
|
||||
rocket::build()
|
||||
.attach(Template::fairing())
|
||||
.configure(rocket::Config {
|
||||
|
|
@ -201,11 +203,11 @@ fn rocket() -> _ {
|
|||
})
|
||||
.manage(
|
||||
Database::pool(
|
||||
&config.mysql_host,
|
||||
config.mysql_port,
|
||||
&config.mysql_username,
|
||||
&config.mysql_password,
|
||||
&config.mysql_database,
|
||||
&config.mysql.host,
|
||||
config.mysql.port,
|
||||
&config.mysql.username,
|
||||
&config.mysql.password,
|
||||
&config.mysql.database,
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue