Add config.yml & Set AIRA_VERSION in build.rs
This commit is contained in:
parent
275c2972df
commit
1b175b81e9
12
Cargo.lock
generated
12
Cargo.lock
generated
@ -389,13 +389,14 @@ dependencies = [
|
||||
"tungstenite",
|
||||
"uuid",
|
||||
"webbrowser",
|
||||
"yaml-rust",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-psec"
|
||||
version = "0.1.0"
|
||||
source = "git+https://forge.chapril.org/hardcoresushi/async-psec#272e7867e7a385b34d3d955aa3e5076e9833d3f1"
|
||||
source = "git+https://forge.chapril.org/hardcoresushi/async-psec#9d2713aea1e982d7c0f10a466268f623a87ec5d9"
|
||||
dependencies = [
|
||||
"aes-gcm",
|
||||
"async-trait",
|
||||
@ -2732,6 +2733,15 @@ dependencies = [
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yaml-rust"
|
||||
version = "0.4.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
|
||||
dependencies = [
|
||||
"linked-hash-map",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zeroize"
|
||||
version = "1.3.0"
|
||||
|
@ -35,6 +35,8 @@ if-addrs = "0.6"
|
||||
base64 = "0.13"
|
||||
scrypt = "0.7"
|
||||
zeroize = "1.2"
|
||||
yaml-rust = "0.4" #only in debug mode
|
||||
|
||||
[build-dependencies]
|
||||
html-minifier = "3.0"
|
||||
yaml-rust = "0.4"
|
33
build.rs
33
build.rs
@ -1,6 +1,7 @@
|
||||
#[cfg(not(debug_assertions))]
|
||||
use std::{env, fs::{File, read_to_string, create_dir}, path::Path, io::{Write, ErrorKind}};
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[cfg(not(debug_assertions))]
|
||||
fn minify_content(content: &str, language: &str) -> Option<String> {
|
||||
match language {
|
||||
"html" => Some(html_minifier::minify(content).unwrap()),
|
||||
@ -10,8 +11,10 @@ fn minify_content(content: &str, language: &str) -> Option<String> {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn minify_web_files() {
|
||||
#[cfg(not(debug_assertions))]
|
||||
fn generate_web_files() {
|
||||
use yaml_rust::YamlLoader;
|
||||
|
||||
let out_dir = env::var("OUT_DIR").unwrap();
|
||||
let out_dir = Path::new(&out_dir);
|
||||
let src_dir = Path::new("src/frontend");
|
||||
@ -22,23 +25,35 @@ fn minify_web_files() {
|
||||
}
|
||||
}
|
||||
|
||||
let config = &YamlLoader::load_from_str(&read_to_string("config.yml").unwrap()).unwrap()[0];
|
||||
let css_values = config["css"].as_hash().unwrap();
|
||||
|
||||
[
|
||||
"login.html",
|
||||
"index.html",
|
||||
"index.css",
|
||||
"index.js",
|
||||
"commons/style.css",
|
||||
"commons/script.js"
|
||||
"commons/script.js",
|
||||
].iter().for_each(|file_name| {
|
||||
let file_name = Path::new(file_name);
|
||||
let content = read_to_string(src_dir.join(file_name)).unwrap();
|
||||
let minified_content = minify_content(&content, file_name.extension().unwrap().to_str().unwrap()).unwrap();
|
||||
let mut dst = File::create(out_dir.join(file_name)).unwrap();
|
||||
let path = Path::new(file_name);
|
||||
let extension = path.extension().unwrap().to_str().unwrap();
|
||||
let mut content = read_to_string(src_dir.join(path)).unwrap();
|
||||
if extension == "css" {
|
||||
css_values.into_iter().for_each(|entry| {
|
||||
content = content.replace(entry.0.as_str().unwrap(), entry.1.as_str().unwrap());
|
||||
});
|
||||
}
|
||||
if file_name == &"index.html" {
|
||||
content = content.replace("AIRA_VERSION", env!("CARGO_PKG_VERSION"));
|
||||
}
|
||||
let minified_content = minify_content(&content, extension).unwrap();
|
||||
let mut dst = File::create(out_dir.join(path)).unwrap();
|
||||
dst.write(minified_content.as_bytes()).unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
fn main() {
|
||||
#[cfg(not(debug_assertions))]
|
||||
minify_web_files();
|
||||
generate_web_files();
|
||||
}
|
2
config.yml
Normal file
2
config.yml
Normal file
@ -0,0 +1,2 @@
|
||||
css:
|
||||
ACCENT_COLOR: "19a52c"
|
@ -4,7 +4,7 @@
|
||||
}
|
||||
|
||||
:root {
|
||||
--accent: #19a52c;
|
||||
--accent: #ACCENT_COLOR;
|
||||
--transparent: #00000000;
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ input[type="file"] {
|
||||
cursor: pointer;
|
||||
}
|
||||
.file_picker::after {
|
||||
content: url("/static/imgs/icons/attach/19a52c");
|
||||
content: url("/static/imgs/icons/attach/ACCENT_COLOR");
|
||||
width: 2em;
|
||||
}
|
||||
.popup {
|
||||
@ -126,7 +126,7 @@ input[type="file"] {
|
||||
font-size: 0.9em;
|
||||
}
|
||||
.popup h2.warning::before {
|
||||
content: url("/static/imgs/icons/warning/19a52c");
|
||||
content: url("/static/imgs/icons/warning/ACCENT_COLOR");
|
||||
width: 9%;
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
@ -272,7 +272,7 @@ label {
|
||||
background-color: #333940;
|
||||
}
|
||||
#left_panel ul li p::after {
|
||||
content: url("/static/imgs/icons/warning/19a52c");
|
||||
content: url("/static/imgs/icons/warning/ACCENT_COLOR");
|
||||
display: inline-block;
|
||||
width: 1em;
|
||||
margin-left: 5px;
|
||||
@ -282,7 +282,7 @@ label {
|
||||
content: unset;
|
||||
}
|
||||
#left_panel ul li.is_verified p::after {
|
||||
content: url("/static/imgs/icons/verified/19a52c");
|
||||
content: url("/static/imgs/icons/verified/ACCENT_COLOR");
|
||||
}
|
||||
#left_panel ul li .not_seen_marker {
|
||||
width: 12px;
|
||||
@ -316,7 +316,7 @@ label {
|
||||
}
|
||||
#show_local_ips:hover::after {
|
||||
background-color: unset;
|
||||
content: url("/static/imgs/icons/info/19a52c");
|
||||
content: url("/static/imgs/icons/info/ACCENT_COLOR");
|
||||
}
|
||||
.popup ul {
|
||||
list-style-type: unset;
|
||||
@ -341,7 +341,7 @@ label {
|
||||
margin: 0;
|
||||
}
|
||||
#chat_header p::after {
|
||||
content: url("/static/imgs/icons/warning/19a52c");
|
||||
content: url("/static/imgs/icons/warning/ACCENT_COLOR");
|
||||
display: inline-block;
|
||||
width: 1.2em;
|
||||
vertical-align: middle;
|
||||
@ -351,7 +351,7 @@ label {
|
||||
content: unset;
|
||||
}
|
||||
#chat_header.is_verified p::after {
|
||||
content: url("/static/imgs/icons/verified/19a52c");
|
||||
content: url("/static/imgs/icons/verified/ACCENT_COLOR");
|
||||
}
|
||||
#chat_header.is_contact #delete_conversation::after {
|
||||
content: url("/static/imgs/icons/delete_conversation");
|
||||
@ -403,7 +403,7 @@ label {
|
||||
#file_cancel::after {
|
||||
background-color: unset;
|
||||
width: 20px;
|
||||
content: url("/static/imgs/icons/cancel/19a52c");
|
||||
content: url("/static/imgs/icons/cancel/ACCENT_COLOR");
|
||||
}
|
||||
#file_progress {
|
||||
display: none;
|
||||
@ -477,7 +477,7 @@ label {
|
||||
color: var(--accent);
|
||||
}
|
||||
#msg_log .file a::after {
|
||||
content: url("/static/imgs/icons/download/19a52c");
|
||||
content: url("/static/imgs/icons/download/ACCENT_COLOR");
|
||||
display: block;
|
||||
width: 2em;
|
||||
margin-left: 15px;
|
||||
|
@ -1071,6 +1071,7 @@ function displayChatBottom(speed = undefined) {
|
||||
function displayHistory(scrollToBottom = true) {
|
||||
msg_log.style.display = "block";
|
||||
msg_log.innerHTML = "";
|
||||
let session = sessionsData.get(currentSessionId);
|
||||
let previousOutgoing = undefined;
|
||||
msgHistory.get(currentSessionId).forEach(entry => {
|
||||
let name = undefined;
|
||||
@ -1079,7 +1080,7 @@ function displayHistory(scrollToBottom = true) {
|
||||
if (entry[0]) { //outgoing msg
|
||||
name = identityName;
|
||||
} else {
|
||||
name = sessionsData.get(currentSessionId).name;
|
||||
name = session.name;
|
||||
}
|
||||
}
|
||||
if (entry[1]) { //is file
|
||||
@ -1091,7 +1092,9 @@ function displayHistory(scrollToBottom = true) {
|
||||
if (scrollToBottom) {
|
||||
msg_log.scrollTop = msg_log.scrollHeight;
|
||||
}
|
||||
if (msg_log.scrollHeight <= msg_log.clientHeight) {
|
||||
socket.send("load_msgs "+currentSessionId);
|
||||
if (typeof session !== "undefined") {
|
||||
if (msg_log.scrollHeight <= msg_log.clientHeight && session.isContact) {
|
||||
socket.send("load_msgs "+currentSessionId);
|
||||
}
|
||||
}
|
||||
}
|
20
src/main.rs
20
src/main.rs
@ -550,14 +550,14 @@ async fn handle_index(req: HttpRequest) -> HttpResponse {
|
||||
if is_authenticated(&req) {
|
||||
let global_vars_read = global_vars.read().unwrap();
|
||||
#[cfg(debug_assertions)]
|
||||
let html = fs::read_to_string("src/frontend/index.html").unwrap();
|
||||
let html = fs::read_to_string("src/frontend/index.html").unwrap()
|
||||
.replace("AIRA_VERSION", env!("CARGO_PKG_VERSION"));
|
||||
#[cfg(not(debug_assertions))]
|
||||
let html = include_str!(concat!(env!("OUT_DIR"), "/index.html"));
|
||||
let public_key = global_vars_read.session_manager.identity.read().unwrap().as_ref().unwrap().get_public_key();
|
||||
let use_padding = global_vars_read.session_manager.identity.read().unwrap().as_ref().unwrap().use_padding.to_string();
|
||||
HttpResponse::Ok().body(
|
||||
html
|
||||
.replace("AIRA_VERSION", env!("CARGO_PKG_VERSION"))
|
||||
.replace("IDENTITY_FINGERPRINT", &crypto::generate_fingerprint(&public_key))
|
||||
.replace("WEBSOCKET_PORT", &global_vars_read.websocket_port.to_string())
|
||||
.replace("IS_IDENTITY_PROTECTED", &Identity::is_protected().unwrap().to_string())
|
||||
@ -570,6 +570,18 @@ async fn handle_index(req: HttpRequest) -> HttpResponse {
|
||||
|
||||
const JS_CONTENT_TYPE: &str = "text/javascript";
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
fn replace_css(file_path: &str) -> String {
|
||||
use yaml_rust::YamlLoader;
|
||||
let mut content = fs::read_to_string(file_path).unwrap();
|
||||
let config = &YamlLoader::load_from_str(&fs::read_to_string("config.yml").unwrap()).unwrap()[0];
|
||||
let css_values = config["css"].as_hash().unwrap();
|
||||
css_values.into_iter().for_each(|entry| {
|
||||
content = content.replace(entry.0.as_str().unwrap(), entry.1.as_str().unwrap());
|
||||
});
|
||||
content
|
||||
}
|
||||
|
||||
fn handle_static(req: HttpRequest) -> HttpResponse {
|
||||
let splits: Vec<&str> = req.path()[1..].split("/").collect();
|
||||
if splits[0] == "static" {
|
||||
@ -584,7 +596,7 @@ fn handle_static(req: HttpRequest) -> HttpResponse {
|
||||
}
|
||||
"index.css" => {
|
||||
#[cfg(debug_assertions)]
|
||||
return response_builder.body(fs::read_to_string("src/frontend/index.css").unwrap());
|
||||
return response_builder.body(replace_css("src/frontend/index.css"));
|
||||
#[cfg(not(debug_assertions))]
|
||||
return response_builder.body(include_str!(concat!(env!("OUT_DIR"), "/index.css")));
|
||||
}
|
||||
@ -643,7 +655,7 @@ fn handle_static(req: HttpRequest) -> HttpResponse {
|
||||
}
|
||||
"style.css" => {
|
||||
#[cfg(debug_assertions)]
|
||||
return response_builder.body(fs::read_to_string("src/frontend/commons/style.css").unwrap());
|
||||
return response_builder.body(replace_css("src/frontend/commons/style.css"));
|
||||
#[cfg(not(debug_assertions))]
|
||||
return response_builder.body(include_str!(concat!(env!("OUT_DIR"), "/commons/style.css")));
|
||||
}
|
||||
|
@ -85,9 +85,9 @@ impl SessionManager {
|
||||
|
||||
pub fn store_msg(&self, session_id: &usize, outgoing: bool, buffer: Vec<u8>) {
|
||||
let mut msg_saved = false;
|
||||
if self.is_contact(session_id) {
|
||||
let mut offsets = self.last_loaded_msg_offsets.write().unwrap(); //locking mutex before modifying the DB to prevent race conditions
|
||||
match self.identity.read().unwrap().as_ref().unwrap().store_msg(&self.loaded_contacts.read().unwrap().get(session_id).unwrap().uuid, outgoing, &buffer) {
|
||||
if let Some(contact) = self.loaded_contacts.read().unwrap().get(session_id) {
|
||||
let mut offsets = self.last_loaded_msg_offsets.write().unwrap(); //locking mutex before modifying the DB to prevent race conditions with load_msgs()
|
||||
match self.identity.read().unwrap().as_ref().unwrap().store_msg(&contact.uuid, outgoing, &buffer) {
|
||||
Ok(_) => {
|
||||
*offsets.get_mut(session_id).unwrap() += 1;
|
||||
msg_saved = true;
|
||||
@ -607,10 +607,6 @@ impl SessionManager {
|
||||
result
|
||||
}
|
||||
|
||||
pub fn is_contact(&self, session_id: &usize) -> bool {
|
||||
self.loaded_contacts.read().unwrap().contains_key(session_id)
|
||||
}
|
||||
|
||||
pub fn store_file(&self, session_id: &usize, data: &[u8]) -> Result<Uuid, rusqlite::Error> {
|
||||
self.identity.read().unwrap().as_ref().unwrap().store_file(match self.loaded_contacts.read().unwrap().get(session_id) {
|
||||
Some(contact) => Some(contact.uuid),
|
||||
@ -621,12 +617,12 @@ impl SessionManager {
|
||||
pub fn load_msgs(&self, session_id: &usize, count: usize) -> Option<Vec<(bool, Vec<u8>)>> {
|
||||
let mut offsets = self.last_loaded_msg_offsets.write().unwrap();
|
||||
let msgs = self.identity.read().unwrap().as_ref().unwrap().load_msgs(
|
||||
&self.loaded_contacts.read().unwrap().get(session_id).unwrap().uuid,
|
||||
*offsets.get(session_id).unwrap(),
|
||||
&self.loaded_contacts.read().unwrap().get(session_id)?.uuid,
|
||||
*offsets.get(session_id)?,
|
||||
count
|
||||
);
|
||||
if let Some(msgs) = msgs.as_ref() {
|
||||
*offsets.get_mut(session_id).unwrap() += msgs.len();
|
||||
*offsets.get_mut(session_id)? += msgs.len();
|
||||
}
|
||||
msgs
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user