mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew.git
synced 2025-05-13 11:37:33 -05:00
Correct placement of config.json file
This commit is contained in:
parent
66ad791ff8
commit
e1e32a22b0
3 changed files with 15 additions and 7 deletions
13
src/main.rs
13
src/main.rs
|
@ -17,6 +17,7 @@ use actix_web::{
|
||||||
use crate::router::global;
|
use crate::router::global;
|
||||||
use json::JsonValue;
|
use json::JsonValue;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
fn unhandled(req: HttpRequest, body: String) -> Option<JsonValue> {
|
fn unhandled(req: HttpRequest, body: String) -> Option<JsonValue> {
|
||||||
if body != String::new() {
|
if body != String::new() {
|
||||||
|
@ -221,6 +222,16 @@ pub fn get_args() -> Args {
|
||||||
Args::parse()
|
Args::parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_data_path(file_name: &str) -> String {
|
||||||
|
let args = get_args();
|
||||||
|
let mut path = args.path;
|
||||||
|
while path.ends_with("/") {
|
||||||
|
path.pop();
|
||||||
|
}
|
||||||
|
fs::create_dir_all(&path).unwrap();
|
||||||
|
format!("{}/{}", path, file_name)
|
||||||
|
}
|
||||||
|
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
let args = get_args();
|
let args = get_args();
|
||||||
|
@ -239,7 +250,7 @@ async fn main() -> std::io::Result<()> {
|
||||||
|
|
||||||
println!("Server started: http://0.0.0.0:{}", port);
|
println!("Server started: http://0.0.0.0:{}", port);
|
||||||
println!("Data path is set to {}", args.path);
|
println!("Data path is set to {}", args.path);
|
||||||
println!("Sif1 transfer requests will attempt to contact NPPS4 at {}", host);
|
println!("Sif1 transfer requests will attempt to contact NPPS4 at {}", args.npps4);
|
||||||
|
|
||||||
if args.https {
|
if args.https {
|
||||||
println!("Note: gree is set to https mode. http requests will fail on jp clients.");
|
println!("Note: gree is set to https mode. http requests will fail on jp clients.");
|
||||||
|
|
|
@ -17,7 +17,7 @@ fn get_config() -> JsonValue {
|
||||||
import: true,
|
import: true,
|
||||||
export: true
|
export: true
|
||||||
};
|
};
|
||||||
let contents = fs::read_to_string("config.json").unwrap_or(String::from("aaaaaaaaaaaaaaaaa"));
|
let contents = fs::read_to_string(crate::get_data_path("config.json")).unwrap_or(String::from("aaaaaaaaaaaaaaaaa"));
|
||||||
let mut rv = json::parse(&contents).unwrap_or(def.clone());
|
let mut rv = json::parse(&contents).unwrap_or(def.clone());
|
||||||
for val in def.entries() {
|
for val in def.entries() {
|
||||||
if rv[val.0] == JsonValue::Null {
|
if rv[val.0] == JsonValue::Null {
|
||||||
|
@ -32,7 +32,7 @@ fn save_config(val: String) {
|
||||||
for vall in new.entries() {
|
for vall in new.entries() {
|
||||||
current[vall.0] = vall.1.clone();
|
current[vall.0] = vall.1.clone();
|
||||||
}
|
}
|
||||||
let mut f = File::create("config.json").unwrap();
|
let mut f = File::create(crate::get_data_path("config.json")).unwrap();
|
||||||
f.write_all(json::stringify(current).as_bytes()).unwrap();
|
f.write_all(json::stringify(current).as_bytes()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use rusqlite::{Connection, params, ToSql};
|
use rusqlite::{Connection, params, ToSql};
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use json::{JsonValue, array};
|
use json::{JsonValue, array};
|
||||||
use std::fs;
|
|
||||||
|
|
||||||
use crate::router::clear_rate::Live;
|
use crate::router::clear_rate::Live;
|
||||||
|
|
||||||
|
@ -12,9 +11,7 @@ pub struct SQLite {
|
||||||
|
|
||||||
impl SQLite {
|
impl SQLite {
|
||||||
pub fn new(path: &str, setup: fn(&SQLite)) -> SQLite {
|
pub fn new(path: &str, setup: fn(&SQLite)) -> SQLite {
|
||||||
let args = crate::get_args();
|
let conn = Connection::open(crate::get_data_path(path)).unwrap();
|
||||||
fs::create_dir_all(&args.path).unwrap();
|
|
||||||
let conn = Connection::open(format!("{}/{}", args.path, path)).unwrap();
|
|
||||||
conn.execute("PRAGMA foreign_keys = ON;", ()).unwrap();
|
conn.execute("PRAGMA foreign_keys = ON;", ()).unwrap();
|
||||||
let instance = SQLite {
|
let instance = SQLite {
|
||||||
engine: Mutex::new(conn),
|
engine: Mutex::new(conn),
|
||||||
|
|
Loading…
Add table
Reference in a new issue