Skip to content

Commit

Permalink
Reformat, relicense, and more
Browse files Browse the repository at this point in the history
  • Loading branch information
strawmelonjuice committed Apr 8, 2024
1 parent d9041fd commit 5645326
Show file tree
Hide file tree
Showing 11 changed files with 847 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ documentation = "https://cynthia-docs.strawmelonjuice.com/"
authors = ["MLC Bloeiman <[email protected]>"]
version = "2.1.4-alpha.0.1"
edition = "2021"
license = "GPL-3.0 OR MIT"
license = "AGPL-3"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
661 changes: 661 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright (c) 2024, MLC 'Strawmelonjuice' Bloeiman
*
* Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3, see the LICENSE file for more information.
*/

use crate::logger;
use serde::{Deserialize, Serialize};
use std::path::Path;
Expand Down Expand Up @@ -190,13 +196,13 @@ fn c_l_filep() -> String {
String::from("./cynthia.log")
}

fn d_logging () -> Logging {
fn d_logging() -> Logging {
Logging {
file: d_file_logging(),
console: d_console_logging(),
}
}
fn d_file_logging () -> FileLogging {
fn d_file_logging() -> FileLogging {
FileLogging {
filepath: "./cynthia.log".to_string(),
enabled: true,
Expand All @@ -210,7 +216,7 @@ fn d_file_logging () -> FileLogging {
jsr_errors: true,
}
}
fn d_console_logging () -> ConsoleLogging {
fn d_console_logging() -> ConsoleLogging {
ConsoleLogging {
enabled: true,
cache: false,
Expand All @@ -222,4 +228,4 @@ fn d_console_logging () -> ConsoleLogging {
plugin_asset_requests: false,
jsr_errors: true,
}
}
}
6 changes: 6 additions & 0 deletions src/contentservers.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright (c) 2024, MLC 'Strawmelonjuice' Bloeiman
*
* Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3, see the LICENSE file for more information.
*/

use std::fs;

use actix_web::HttpResponse;
Expand Down
17 changes: 11 additions & 6 deletions src/dashfunctions.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright (c) 2024, MLC 'Strawmelonjuice' Bloeiman
*
* Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3, see the LICENSE file for more information.
*/

use crate::{logger, LoadedData};
use actix_web::web::Data;
use actix_web::{post, web, HttpResponse};
Expand All @@ -19,10 +25,8 @@ struct DashAPIData {
}

#[derive(Deserialize)]
struct PluginDashInstallParams {
plugin_name: String,
plugin_version: String,
}
struct PluginDashInstallParams(String, Option<String>);

#[derive(Deserialize)]
struct PluginDashRemoveParams {
plugin_name: String,
Expand Down Expand Up @@ -63,12 +67,13 @@ pub(crate) async fn dashserver(
Ok(s) => {
let plugindata: PluginDashInstallParams = s;
crate::subcommand::plugin_install(
plugindata.plugin_name,
plugindata.plugin_version,
plugindata.0,
plugindata.1.unwrap_or("latest".parse().unwrap()),
);
}

Err(_e) => {
println!("{}", data.params);
return HttpResponse::BadRequest().body(String::from("Invalid plugin."));
}
},
Expand Down
6 changes: 6 additions & 0 deletions src/files.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright (c) 2024, MLC 'Strawmelonjuice' Bloeiman
*
* Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3, see the LICENSE file for more information.
*/

use crate::jsr::{jsruntime, BUNJSR, BUN_NPM_EX, NODEJSR, NODEJSR_EX};
use crate::structs::CynthiaCacheIndexObject;
use crate::{config, logger};
Expand Down
6 changes: 6 additions & 0 deletions src/jsr.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright (c) 2024, MLC 'Strawmelonjuice' Bloeiman
*
* Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3, see the LICENSE file for more information.
*/

use crate::logger;

// Bun on windows is enabled by default. This is because choosing to have Bun on windows, means choosing for an experimental feature.
Expand Down
132 changes: 121 additions & 11 deletions src/logger.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright (c) 2024, MLC 'Strawmelonjuice' Bloeiman
*
* Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3, see the LICENSE file for more information.
*/

#![allow(dead_code)]

use crate::config;
Expand Down Expand Up @@ -84,11 +90,25 @@ pub(crate) fn log_by_act_num(act: i32, msg: String) {
if !clog.enabled {
return;
};
let mut file = OpenOptions::new().append(true).create(true).open(log.clone().file.filepath).unwrap();
let mut file = OpenOptions::new()
.append(true)
.create(true)
.open(log.clone().file.filepath)
.unwrap();
file.seek(SeekFrom::End(0)).unwrap();
match act {
200 | 2 => {
if log.file.clone().enabled && log.file.clone().requests { file.write_all(format!("[{}]\t200/SUCCESS\t\t{}\n", times, strip_ansi_escapes::strip_str(msg.clone().as_str())).as_bytes()).unwrap(); };
if log.file.clone().enabled && log.file.clone().requests {
file.write_all(
format!(
"[{}]\t200/SUCCESS\t\t{}\n",
times,
strip_ansi_escapes::strip_str(msg.clone().as_str())
)
.as_bytes(),
)
.unwrap();
};
if !clog.requests {
return;
};
Expand All @@ -103,7 +123,17 @@ pub(crate) fn log_by_act_num(act: i32, msg: String) {
println!("{0}👍{DIVVER}{1}", preq, msg);
}
3 | 404 => {
if log.file.clone().enabled && log.file.clone().requests { file.write_all(format!("[{}]\t404/NOTFOUND\t\t{}\n", times, strip_ansi_escapes::strip_str(msg.clone().as_str())).as_bytes()).unwrap(); };
if log.file.clone().enabled && log.file.clone().requests {
file.write_all(
format!(
"[{}]\t404/NOTFOUND\t\t{}\n",
times,
strip_ansi_escapes::strip_str(msg.clone().as_str())
)
.as_bytes(),
)
.unwrap();
};
if !clog.requests {
return;
};
Expand All @@ -118,7 +148,17 @@ pub(crate) fn log_by_act_num(act: i32, msg: String) {
println!("{0}👎{DIVVER}{1}", preq, msg);
}
5 => {
if log.file.clone().enabled && log.file.clone().error { file.write_all(format!("[{}]\tERROR\t\t\t{}\n", times, strip_ansi_escapes::strip_str(msg.clone().as_str())).as_bytes()).unwrap(); };
if log.file.clone().enabled && log.file.clone().error {
file.write_all(
format!(
"[{}]\tERROR\t\t\t{}\n",
times,
strip_ansi_escapes::strip_str(msg.clone().as_str())
)
.as_bytes(),
)
.unwrap();
};
// Check if these log items are enabled
if !clog.error {
return;
Expand All @@ -134,7 +174,17 @@ pub(crate) fn log_by_act_num(act: i32, msg: String) {
eprintln!("{0}{1}", preq, msg.bright_red());
}
15 => {
if log.file.clone().enabled && log.file.clone().warn { file.write_all(format!("[{}]\tWARNING\t\t{}\n", times, strip_ansi_escapes::strip_str(msg.clone().as_str())).as_bytes()).unwrap(); };
if log.file.clone().enabled && log.file.clone().warn {
file.write_all(
format!(
"[{}]\tWARNING\t\t{}\n",
times,
strip_ansi_escapes::strip_str(msg.clone().as_str())
)
.as_bytes(),
)
.unwrap();
};
// Check if these log items are enabled
if !clog.warn {
return;
Expand All @@ -150,7 +200,17 @@ pub(crate) fn log_by_act_num(act: i32, msg: String) {
eprintln!("{0}⚠{DIVVER}{1}", preq, msg.on_bright_magenta().black());
}
12 => {
if log.file.clone().enabled && log.file.clone().jsr_errors { file.write_all(format!("[{}]\tERROR-JS\t\t\t{}\n", times, strip_ansi_escapes::strip_str(msg.clone().as_str())).as_bytes()).unwrap(); };
if log.file.clone().enabled && log.file.clone().jsr_errors {
file.write_all(
format!(
"[{}]\tERROR-JS\t\t\t{}\n",
times,
strip_ansi_escapes::strip_str(msg.clone().as_str())
)
.as_bytes(),
)
.unwrap();
};
// Check if these log items are enabled
if !clog.jsr_errors {
return;
Expand All @@ -166,7 +226,17 @@ pub(crate) fn log_by_act_num(act: i32, msg: String) {
eprintln!("{0}{1}", preq, msg.bright_red().on_bright_yellow());
}
49038 => {
if log.file.clone().enabled && log.file.clone().proxy_requests { file.write_all(format!("[{}]\tPROXY\t\t\t{}\n", times, strip_ansi_escapes::strip_str(msg.clone().as_str())).as_bytes()).unwrap(); };
if log.file.clone().enabled && log.file.clone().proxy_requests {
file.write_all(
format!(
"[{}]\tPROXY\t\t\t{}\n",
times,
strip_ansi_escapes::strip_str(msg.clone().as_str())
)
.as_bytes(),
)
.unwrap();
};
// Check if these log items are enabled
if !clog.proxy_requests {
return;
Expand All @@ -182,7 +252,17 @@ pub(crate) fn log_by_act_num(act: i32, msg: String) {
println!("{0}❕{DIVVER}{1}", preq, msg.bright_green());
}
293838 => {
if log.file.clone().enabled && log.file.clone().plugin_asset_requests { file.write_all(format!("[{}]\t200/PLUGIN\t\t{}\n", times, strip_ansi_escapes::strip_str(msg.clone().as_str())).as_bytes()).unwrap(); };
if log.file.clone().enabled && log.file.clone().plugin_asset_requests {
file.write_all(
format!(
"[{}]\t200/PLUGIN\t\t{}\n",
times,
strip_ansi_escapes::strip_str(msg.clone().as_str())
)
.as_bytes(),
)
.unwrap();
};

// Check if these log items are enabled
if !clog.plugin_asset_requests {
Expand All @@ -199,7 +279,17 @@ pub(crate) fn log_by_act_num(act: i32, msg: String) {
println!("{0}❕{DIVVER}{1}", preq, msg.bright_green());
}
10 => {
if log.file.clone().enabled && log.file.clone().info { file.write_all(format!("[{}]\tNOTE\t\t\t{}\n", times, strip_ansi_escapes::strip_str(msg.clone().as_str())).as_bytes()).unwrap(); };
if log.file.clone().enabled && log.file.clone().info {
file.write_all(
format!(
"[{}]\tNOTE\t\t\t{}\n",
times,
strip_ansi_escapes::strip_str(msg.clone().as_str())
)
.as_bytes(),
)
.unwrap();
};
// Check if these log items are enabled
if !clog.info {
return;
Expand All @@ -215,7 +305,17 @@ pub(crate) fn log_by_act_num(act: i32, msg: String) {
println!("{0}❕{DIVVER}{1}", preq, msg.bright_green());
}
31 => {
if log.file.clone().enabled && log.file.clone().cache { file.write_all(format!("[{}]\tCACHING\t\t{}\n", times, strip_ansi_escapes::strip_str(msg.clone().as_str())).as_bytes()).unwrap(); };
if log.file.clone().enabled && log.file.clone().cache {
file.write_all(
format!(
"[{}]\tCACHING\t\t{}\n",
times,
strip_ansi_escapes::strip_str(msg.clone().as_str())
)
.as_bytes(),
)
.unwrap();
};
if !clog.cache {
return;
};
Expand All @@ -230,7 +330,17 @@ pub(crate) fn log_by_act_num(act: i32, msg: String) {
println!("{0}♻️{DIVVER}{1}", preq, msg.bright_white().italic());
}
_ => {
if log.file.clone().enabled { file.write_all(format!("[{}]\tLOG\t\t\t\t{}\n", times, strip_ansi_escapes::strip_str(msg.clone().as_str())).as_bytes()).unwrap(); };
if log.file.clone().enabled {
file.write_all(
format!(
"[{}]\tLOG\t\t\t\t{}\n",
times,
strip_ansi_escapes::strip_str(msg.clone().as_str())
)
.as_bytes(),
)
.unwrap();
};
let name = format!("[{} - [LOG]", times).blue();
let spaceleft = if name.chars().count() < SPACES {
SPACES - name.chars().count()
Expand Down
14 changes: 13 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright (c) 2024, MLC 'Strawmelonjuice' Bloeiman
*
* Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3, see the LICENSE file for more information.
*/

use actix_files::NamedFile;
use std::io::{Error, ErrorKind};
use std::{fs, path::Path, process, sync::Mutex};
Expand Down Expand Up @@ -591,7 +597,13 @@ As of now, Cynthia has only 4 commands:
.italic()
));
if cynthiadashactive {
logger::general_warn( String::from("Cynthia dashboard plugin found! The Cynthia Dashboard has additional permissions, so uninstall it if left unused, also check the source of this plugin."));
logger::general_warn(String::from("Cynthia dashboard plugin found!"));
logger::general_warn(String::from(
"The Cynthia Dashboard has additional permissions,",
));
logger::general_warn(String::from(
" so uninstall it if left unused. Also check the source of this plugin, is it genuine?",
));

HttpServer::new(move || {
App::new()
Expand Down
6 changes: 6 additions & 0 deletions src/structs.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright (c) 2024, MLC 'Strawmelonjuice' Bloeiman
*
* Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3, see the LICENSE file for more information.
*/

use crate::config::CynthiaConf;
use serde::{Deserialize, Serialize};

Expand Down
6 changes: 6 additions & 0 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright (c) 2024, MLC 'Strawmelonjuice' Bloeiman
*
* Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3, see the LICENSE file for more information.
*/

use crate::structs::CynthiaPluginManifestItem;
use crate::{
jsr::{BUN_NPM, BUN_NPM_EX, NODE_NPM},
Expand Down

0 comments on commit 5645326

Please sign in to comment.