diff --git a/Cargo.toml b/Cargo.toml index bb3a387..1f67d3b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" [dependencies] dotenv = "0.15.0" rocket = { version = "0.5.0-rc.2", features = ["json", "secrets"] } -rocket_cors = "0.5.2" +rocket_cors = "0.6.0" rpassword = "7.2.0" serde = "1.0.152" serde_json = "1.0.93" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ce28916 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 unurled + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.MD b/README.MD deleted file mode 100644 index 6a885ac..0000000 --- a/README.MD +++ /dev/null @@ -1,21 +0,0 @@ -# Text-display :) - -havn't throught of any better name sooo... - -making it working : - - download nodejs - - download or setup on cloud a mongodb database - - add to mongodb an entry: (will be making a proper way to do it in the future maybe not so sure) - ``` - { - "_id": { - "$oid": "id generated uhm google it" - }, - "name": "Username", - "pass": "Password", - "text": "text" -} -``` - - `cp .env.example .env` and change the values like you need. - - `npm i` - - `npm start` diff --git a/README.md b/README.md new file mode 100644 index 0000000..f831007 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# Text-display :) + +making it working : + +- download [rust](https://www.rust-lang.org/) +- modify `Rocket.toml` release section if you need +- `cargo build --release` +- launch target/release/text-display diff --git a/src/http_server.rs b/src/http_server.rs index fe91f24..02bb75a 100644 --- a/src/http_server.rs +++ b/src/http_server.rs @@ -1,16 +1,16 @@ +use rocket; +use rocket::fs::{relative, FileServer, NamedFile}; +use rocket::http::{Cookie, CookieJar, Status}; +use rocket::request::{FromRequest, Outcome}; +use rocket::serde::json::Json; +use rocket::{routes, uri, Request}; +use rocket_cors::{AllowedHeaders, AllowedOrigins, Cors}; use std::fs; use std::path::Path; -use rocket; -use rocket::fs::{FileServer, NamedFile, relative}; -use rocket::http::{CookieJar, Cookie, Status}; -use rocket::request::{FromRequest, Outcome}; -use rocket::{Request, routes, uri}; -use rocket_cors::{AllowedHeaders, AllowedOrigins, Cors}; -use rocket::serde::json::Json; -use crate::{data, file}; use crate::data::deserialize; use crate::file::PATH; +use crate::{data, file}; struct Token(String); @@ -36,7 +36,7 @@ impl<'r> FromRequest<'r> for Token { // check validity Outcome::Success(Token(token.to_string())) } - None => Outcome::Failure((Status::Unauthorized, ApiTokenError::Missing)), + None => Outcome::Error((Status::Unauthorized, ApiTokenError::Missing)), } } } @@ -124,4 +124,4 @@ pub async fn main() -> Result<(), rocket::Error> { .launch() .await?; Ok(()) -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index 8bd3f99..b44670a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,22 +1,14 @@ -use dotenv::dotenv; -use std::env; - +mod data; mod file; pub mod hash; mod http_server; -mod data; use file::get_file; fn main() { - dotenv().ok(); - if env::var("URL").is_err() || env::var("PORT").is_err() { - println!("Please set .env file, you can see an example in the file .env.example"); - return; - } let _file = get_file(); let res = http_server::main(); if res.is_err() { println!("Error in server: {}", res.unwrap_err()) } -} \ No newline at end of file +}