Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add note id size option #90

Merged
merged 4 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ 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.0] - 2023-05-30

### Added

- New CLI 🎉
- Russian language
- New CLI 🎉.
- Russian language.
- Option for reducing note id size (`ID_LENGTH`).

### Changed

- Moved to monorepo

## [2.2.0] - 2023-01-14
- Moved to monorepo.

### Changed

Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -163,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.

Expand Down
2 changes: 1 addition & 1 deletion packages/backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cryptgeon"
version = "2.3.0-beta.6"
version = "2.3.0"
authors = ["cupcakearmy <[email protected]>"]
edition = "2021"

Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions packages/backend/src/note/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.3.0-beta.6",
"version": "2.3.0",
"name": "cryptgeon",
"repository": {
"type": "git",
Expand Down
Loading