From a323d48c41877d04a21751b03500b1bc235837af Mon Sep 17 00:00:00 2001 From: Niccolo Borgioli Date: Mon, 29 May 2023 16:34:59 +0200 Subject: [PATCH 1/4] feat: add note id size option --- CHANGELOG.md | 16 ++++++++++------ README.md | 1 + packages/backend/src/config.rs | 4 ++++ packages/backend/src/note/model.rs | 13 ++++++++++--- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65ded82..3126540 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,18 +5,22 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [2.3.0] - 2023-05-XX +## [2.3.1] - 2023-05-XX ### Added -- New CLI 🎉 -- Russian language +- Option for reducing note id size (`ID_LENGTH`). + +## [2.3.0] - 2023-05-29 + +### Added + +- New CLI 🎉. +- Russian language. ### Changed -- Moved to monorepo - -## [2.2.0] - 2023-01-14 +- Moved to monorepo. ### Changed diff --git a/README.md b/README.md index e3d8dfa..437c561 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ of the notes even if it tried to. | `MAX_VIEWS` | `100` | Maximal number of views. | | `MAX_EXPIRATION` | `360` | Maximal expiration in minutes. | | `ALLOW_ADVANCED` | `true` | Allow custom configuration. If set to `false` all notes will be one view only. | +| `ID_LENGTH` | `32` | Set the size of the note `id` in bytes. By default this is `32` bytes. This is useful for reducing link size. _This setting does not affect encryption strength_. | | `VERBOSITY` | `warn` | Verbosity level for the backend. [Possible values](https://docs.rs/env_logger/latest/env_logger/#enabling-logging) are: `error`, `warn`, `info`, `debug`, `trace` | | `THEME_IMAGE` | `""` | Custom image for replacing the logo. Must be publicly reachable | | `THEME_TEXT` | `""` | Custom text for replacing the description below the logo | diff --git a/packages/backend/src/config.rs b/packages/backend/src/config.rs index ecab69e..ae65940 100644 --- a/packages/backend/src/config.rs +++ b/packages/backend/src/config.rs @@ -30,6 +30,10 @@ lazy_static! { .unwrap_or("true".to_string()) .parse() .unwrap(); + pub static ref ID_LENGTH: u32 = std::env::var("ID_LENGTH") + .unwrap_or("32".to_string()) + .parse() + .unwrap(); } // THEME diff --git a/packages/backend/src/note/model.rs b/packages/backend/src/note/model.rs index 36a2618..61271bd 100644 --- a/packages/backend/src/note/model.rs +++ b/packages/backend/src/note/model.rs @@ -2,6 +2,8 @@ use bs62; use ring::rand::SecureRandom; use serde::{Deserialize, Serialize}; +use crate::config; + #[derive(Serialize, Deserialize, Clone)] pub struct Note { pub meta: String, @@ -22,8 +24,13 @@ pub struct NotePublic { } pub fn generate_id() -> String { - let mut id: [u8; 32] = [0; 32]; + let mut result = "".to_owned(); + let mut id: [u8; 1] = [0; 1]; let sr = ring::rand::SystemRandom::new(); - let _ = sr.fill(&mut id); - return bs62::encode_data(&id); + + for _ in 0..*config::ID_LENGTH { + let _ = sr.fill(&mut id); + result.push_str(&bs62::encode_data(&id)); + } + return result; } From 7c85c1e621734bb8f55766f6730560b269e0a131 Mon Sep 17 00:00:00 2001 From: Niccolo Borgioli Date: Tue, 30 May 2023 09:43:26 +0200 Subject: [PATCH 2/4] version bump --- packages/backend/Cargo.lock | 2 +- packages/backend/Cargo.toml | 2 +- packages/cli/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/backend/Cargo.lock b/packages/backend/Cargo.lock index 5044eb0..de87ceb 100644 --- a/packages/backend/Cargo.lock +++ b/packages/backend/Cargo.lock @@ -439,7 +439,7 @@ dependencies = [ [[package]] name = "cryptgeon" -version = "2.3.0-beta.6" +version = "2.3.0" dependencies = [ "actix-files", "actix-web", diff --git a/packages/backend/Cargo.toml b/packages/backend/Cargo.toml index 3b721b2..9923916 100644 --- a/packages/backend/Cargo.toml +++ b/packages/backend/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cryptgeon" -version = "2.3.0-beta.6" +version = "2.3.0" authors = ["cupcakearmy "] edition = "2021" diff --git a/packages/cli/package.json b/packages/cli/package.json index cbf3b77..1f75faa 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,5 +1,5 @@ { - "version": "2.3.0-beta.6", + "version": "2.3.0", "name": "cryptgeon", "repository": { "type": "git", From 815ac4e8ba08f642c758c277614b96e4c473ad91 Mon Sep 17 00:00:00 2001 From: Niccolo Borgioli Date: Tue, 30 May 2023 09:43:31 +0200 Subject: [PATCH 3/4] changelog --- CHANGELOG.md | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3126540..9ff0314 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,18 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [2.3.1] - 2023-05-XX - -### Added - -- Option for reducing note id size (`ID_LENGTH`). - -## [2.3.0] - 2023-05-29 +## [2.3.0] - 2023-05-30 ### Added - New CLI 🎉. - Russian language. +- Option for reducing note id size (`ID_LENGTH`). ### Changed From 2a75acae3f76d6c87a4717586acb9726eeec50dd Mon Sep 17 00:00:00 2001 From: Niccolo Borgioli Date: Tue, 30 May 2023 09:43:41 +0200 Subject: [PATCH 4/4] docs --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 437c561..067e84f 100644 --- a/README.md +++ b/README.md @@ -164,7 +164,9 @@ Running `pnpm run dev` in the root folder will start the following things: You can see the app under [localhost:1234](http://localhost:1234). -## Tests +> There is a Postman collection with some example requests [available in the repo](./Cryptgeon.postman_collection.json) + +### Tests Tests are end to end tests written with Playwright.