feat: add note id size option

This commit is contained in:
Niccolo Borgioli 2023-05-29 16:34:59 +02:00
parent 2bff6a37db
commit a323d48c41
No known key found for this signature in database
GPG Key ID: D93C615F75EE4F0B
4 changed files with 25 additions and 9 deletions

View File

@ -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

View File

@ -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 |

View File

@ -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

View File

@ -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;
}