Merge pull request #119 from compasspathways/main

Misc improvements including `ALLOW_FILES` and `NEW_NOTE_NOTICE`
This commit is contained in:
Nicco 2024-03-19 16:04:04 +01:00 committed by GitHub
commit 9b48d39c82
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 110 additions and 81 deletions

View File

@ -13,13 +13,13 @@ RUN pnpm run build
# BACKEND
FROM rust:1.76-alpine as backend
WORKDIR /tmp
RUN apk add libc-dev openssl-dev alpine-sdk
RUN apk add --no-cache libc-dev openssl-dev alpine-sdk
COPY ./packages/backend ./
RUN cargo build --release
# RUNNER
FROM alpine
FROM alpine:3.19
WORKDIR /app
RUN apk add --no-cache curl
COPY --from=backend /tmp/target/release/cryptgeon .

View File

@ -62,19 +62,21 @@ of the notes even if it tried to.
## Environment Variables
| Variable | Default | Description |
| ------------------ | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `REDIS` | `redis://redis/` | Redis URL to connect to. [According to format](https://docs.rs/redis/latest/redis/#connection-parameters) |
| `SIZE_LIMIT` | `1 KiB` | Max size for body. Accepted values according to [byte-unit](https://docs.rs/byte-unit/). <br> `512 MiB` is the maximum allowed. <br> The frontend will show that number including the ~35% encoding overhead. |
| `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 |
| `THEME_PAGE_TITLE` | `""` | Custom text the page title |
| `THEME_FAVICON` | `""` | Custom url for the favicon. Must be publicly reachable |
| Variable | Default | Description |
| ----------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `REDIS` | `redis://redis/` | Redis URL to connect to. [According to format](https://docs.rs/redis/latest/redis/#connection-parameters) |
| `SIZE_LIMIT` | `1 KiB` | Max size for body. Accepted values according to [byte-unit](https://docs.rs/byte-unit/). <br> `512 MiB` is the maximum allowed. <br> The frontend will show that number including the ~35% encoding overhead. |
| `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. |
| `ALLOW_FILES` | `true` | Allow uploading files. If set to `false`, users will only be allowed to create text notes. |
| `THEME_NEW_NOTE_NOTICE` | `true` | Show the message about how notes are stored in the memory and may be evicted after creating a new note. Defaults to `true`. |
| `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 |
| `THEME_PAGE_TITLE` | `""` | Custom text the page title |
| `THEME_FAVICON` | `""` | Custom url for the favicon. Must be publicly reachable |
## Deployment

View File

@ -13,7 +13,7 @@
},
"devDependencies": {
"@playwright/test": "^1.42.1",
"@types/node": "^20.11.24",
"@types/node": "^20.11.28",
"npm-run-all": "^4.1.5",
"shelljs": "^0.8.5"
},

View File

@ -14,26 +14,34 @@ lazy_static! {
// CONFIG
lazy_static! {
pub static ref LIMIT: usize =
Byte::from_str(std::env::var("SIZE_LIMIT").unwrap_or("1 KiB".to_string()))
.unwrap()
.get_bytes() as usize;
pub static ref MAX_VIEWS: u32 = std::env::var("MAX_VIEWS")
.unwrap_or("100".to_string())
.parse()
.unwrap();
pub static ref MAX_EXPIRATION: u32 = std::env::var("MAX_EXPIRATION")
.unwrap_or("360".to_string()) // 6 hours in minutes
.parse()
.unwrap();
pub static ref ALLOW_ADVANCED: bool = std::env::var("ALLOW_ADVANCED")
.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();
pub static ref LIMIT: usize =
Byte::from_str(std::env::var("SIZE_LIMIT").unwrap_or("1 KiB".to_string()))
.unwrap()
.get_bytes() as usize;
pub static ref MAX_VIEWS: u32 = std::env::var("MAX_VIEWS")
.unwrap_or("100".to_string())
.parse()
.unwrap();
pub static ref MAX_EXPIRATION: u32 = std::env::var("MAX_EXPIRATION")
.unwrap_or("360".to_string()) // 6 hours in minutes
.parse()
.unwrap();
pub static ref ALLOW_ADVANCED: bool = std::env::var("ALLOW_ADVANCED")
.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();
pub static ref ALLOW_FILES: bool = std::env::var("ALLOW_FILES")
.unwrap_or("true".to_string())
.parse()
.unwrap();
pub static ref THEME_NEW_NOTE_NOTICE: bool = std::env::var("THEME_NEW_NOTE_NOTICE")
.unwrap_or("true".to_string())
.parse()
.unwrap();
}
// THEME

View File

@ -9,6 +9,8 @@ pub struct Status {
pub max_views: u32,
pub max_expiration: u32,
pub allow_advanced: bool,
pub allow_files: bool,
pub theme_new_note_notice: bool,
// Theme
pub theme_image: String,
pub theme_text: String,

View File

@ -11,10 +11,12 @@ async fn get_status() -> impl Responder {
max_views: *config::MAX_VIEWS,
max_expiration: *config::MAX_EXPIRATION,
allow_advanced: *config::ALLOW_ADVANCED,
allow_files: *config::ALLOW_FILES,
theme_new_note_notice: *config::THEME_NEW_NOTE_NOTICE,
theme_image: config::THEME_IMAGE.to_string(),
theme_text: config::THEME_TEXT.to_string(),
theme_page_title: config::THEME_PAGE_TITLE.to_string(),
theme_favicon: config::THEME_FAVICON.to_string()
theme_favicon: config::THEME_FAVICON.to_string(),
});
}

View File

@ -7,7 +7,7 @@
<script lang="ts">
import { t } from 'svelte-intl-precompile'
import { status } from '$lib/stores/status'
import Button from '$lib/ui/Button.svelte'
import TextInput from '$lib/ui/TextInput.svelte'
import Canvas from './Canvas.svelte'
@ -35,9 +35,11 @@
<Canvas value={url} />
</div>
<p>
{@html $t('home.new_note_notice')}
</p>
{#if $status?.theme_new_note_notice}
<p>
{@html $t('home.theme_new_note_notice')}
</p>
{/if}
<br />
<Button on:click={reset}>{$t('home.new_note')}</Button>

View File

@ -3,7 +3,8 @@
</script>
<script lang="ts">
import { saveAs } from 'file-saver'
import pkg from 'file-saver'
const { saveAs } = pkg
import prettyBytes from 'pretty-bytes'
import { t } from 'svelte-intl-precompile'

View File

@ -118,12 +118,14 @@
{/if}
<div class="bottom">
<Switch
data-testid="switch-file"
class="file"
label={$t('common.file')}
bind:value={isFile}
/>
{#if $status?.allow_files}
<Switch
data-testid="switch-file"
class="file"
label={$t('common.file')}
bind:value={isFile}
/>
{/if}
{#if $status?.allow_advanced}
<Switch
data-testid="switch-advanced"

View File

@ -1,9 +1,13 @@
<script lang="ts">
import { status } from '$lib/stores/status'
function reset() {
window.location.reload()
}
</script>
<header>
<a href="/">
<a on:click={reset} href="/">
{#if $status?.theme_image}
<img alt="logo" src={$status.theme_image} />
{:else}

View File

@ -40,8 +40,8 @@
<br />
you are welcomed to check & audit the
<a href="https://github.com/cupcakearmy/cryptgeon" target="_blank" rel="noopener noreferrer">
source code
</a>.
source code</a
>.
</span>
</AboutParagraph>

66
pnpm-lock.yaml generated
View File

@ -12,8 +12,8 @@ importers:
specifier: ^1.42.1
version: 1.42.1
'@types/node':
specifier: ^20.11.24
version: 20.11.24
specifier: ^20.11.28
version: 20.11.28
npm-run-all:
specifier: ^4.1.5
version: 4.1.5
@ -127,7 +127,7 @@ importers:
version: 5.3.3
vite:
specifier: ^5.1.4
version: 5.1.4(@types/node@20.11.24)
version: 5.1.4(@types/node@20.11.28)
packages/proxy:
dependencies:
@ -1016,7 +1016,7 @@ packages:
sirv: 2.0.4
svelte: 4.2.12
tiny-glob: 0.2.9
vite: 5.1.4(@types/node@20.11.24)
vite: 5.1.4(@types/node@20.11.28)
dev: true
/@sveltejs/vite-plugin-svelte-inspector@2.0.0(@sveltejs/vite-plugin-svelte@3.0.2)(svelte@4.2.12)(vite@5.1.4):
@ -1030,7 +1030,7 @@ packages:
'@sveltejs/vite-plugin-svelte': 3.0.2(svelte@4.2.12)(vite@5.1.4)
debug: 4.3.4
svelte: 4.2.12
vite: 5.1.4(@types/node@20.11.24)
vite: 5.1.4(@types/node@20.11.28)
transitivePeerDependencies:
- supports-color
dev: true
@ -1049,7 +1049,7 @@ packages:
magic-string: 0.30.7
svelte: 4.2.12
svelte-hmr: 0.15.3(svelte@4.2.12)
vite: 5.1.4(@types/node@20.11.24)
vite: 5.1.4(@types/node@20.11.28)
vitefu: 0.2.5(vite@5.1.4)
transitivePeerDependencies:
- supports-color
@ -1084,6 +1084,12 @@ packages:
undici-types: 5.26.5
dev: true
/@types/node@20.11.28:
resolution: {integrity: sha512-M/GPWVS2wLkSkNHVeLkrF2fD5Lx5UC4PxA0uZcKc6QqbIQUJyW1jVjueJYi1z8n0I5PxYrtpnPnWglE+y9A0KA==}
dependencies:
undici-types: 5.26.5
dev: true
/@types/pug@2.0.10:
resolution: {integrity: sha512-Sk/uYFOBAB7mb74XcpizmH0KOR2Pv3D2Hmrh1Dmy5BmK3MpdSa5kqZcg6EKBdklU0bFXX9gCfzvpnyUehrPIuA==}
dev: true
@ -1242,8 +1248,8 @@ packages:
engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7}
hasBin: true
dependencies:
caniuse-lite: 1.0.30001591
electron-to-chromium: 1.4.690
caniuse-lite: 1.0.30001597
electron-to-chromium: 1.4.707
node-releases: 2.0.14
update-browserslist-db: 1.0.13(browserslist@4.23.0)
dev: true
@ -1275,8 +1281,8 @@ packages:
engines: {node: '>=6'}
dev: true
/caniuse-lite@1.0.30001591:
resolution: {integrity: sha512-PCzRMei/vXjJyL5mJtzNiUCKP59dm8Apqc3PH8gJkMnMXZGox93RbE76jHsmLwmIo6/3nsYIpJtx0O7u5PqFuQ==}
/caniuse-lite@1.0.30001597:
resolution: {integrity: sha512-7LjJvmQU6Sj7bL0j5b5WY/3n7utXUJvAe1lxhsHDbLmwX9mdL86Yjtr+5SRCyf8qME4M7pU2hswj0FpyBVCv9w==}
dev: true
/chalk@2.4.2:
@ -1476,8 +1482,8 @@ packages:
engines: {node: '>=12'}
dev: true
/electron-to-chromium@1.4.690:
resolution: {integrity: sha512-+2OAGjUx68xElQhydpcbqH50hE8Vs2K6TkAeLhICYfndb67CVH0UsZaijmRUE3rHlIxU1u0jxwhgVe6fK3YANA==}
/electron-to-chromium@1.4.707:
resolution: {integrity: sha512-qRq74Mo7ChePOU6GHdfAJ0NREXU8vQTlVlfWz3wNygFay6xrd/fY2J7oGHwrhFeU30OVctGLdTh/FcnokTWpng==}
dev: true
/emoji-regex@8.0.0:
@ -1510,7 +1516,7 @@ packages:
has-property-descriptors: 1.0.2
has-proto: 1.0.3
has-symbols: 1.0.3
hasown: 2.0.1
hasown: 2.0.2
internal-slot: 1.0.7
is-array-buffer: 3.0.4
is-callable: 1.2.7
@ -1524,7 +1530,7 @@ packages:
object-keys: 1.1.1
object.assign: 4.1.5
regexp.prototype.flags: 1.5.2
safe-array-concat: 1.1.0
safe-array-concat: 1.1.2
safe-regex-test: 1.0.3
string.prototype.trim: 1.2.8
string.prototype.trimend: 1.0.7
@ -1534,7 +1540,7 @@ packages:
typed-array-byte-offset: 1.0.2
typed-array-length: 1.0.5
unbox-primitive: 1.0.2
which-typed-array: 1.1.14
which-typed-array: 1.1.15
dev: true
/es-define-property@1.0.0:
@ -1555,7 +1561,7 @@ packages:
dependencies:
get-intrinsic: 1.2.4
has-tostringtag: 1.0.2
hasown: 2.0.1
hasown: 2.0.2
dev: true
/es-to-primitive@1.2.1:
@ -1884,15 +1890,15 @@ packages:
function-bind: 1.1.1
dev: true
/hasown@2.0.0:
resolution: {integrity: sha512-vUptKVTpIJhcczKBbgnS+RtcuYMB8+oNzPK2/Hp3hanz8JmpATdmmgLgSaadVREkDm+e2giHwY3ZRkyjSIDDFA==}
/hasown@2.0.1:
resolution: {integrity: sha512-1/th4MHjnwncwXsIW6QMzlvYL9kG5e/CpVvLRZe4XPa8TOUNbCELqmvhDmnkNsAjwaG4+I8gJJL0JBvTTLO9qA==}
engines: {node: '>= 0.4'}
dependencies:
function-bind: 1.1.2
dev: true
/hasown@2.0.1:
resolution: {integrity: sha512-1/th4MHjnwncwXsIW6QMzlvYL9kG5e/CpVvLRZe4XPa8TOUNbCELqmvhDmnkNsAjwaG4+I8gJJL0JBvTTLO9qA==}
/hasown@2.0.2:
resolution: {integrity: sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==}
engines: {node: '>= 0.4'}
dependencies:
function-bind: 1.1.2
@ -1973,7 +1979,7 @@ packages:
engines: {node: '>= 0.4'}
dependencies:
es-errors: 1.3.0
hasown: 2.0.1
hasown: 2.0.2
side-channel: 1.0.6
dev: true
@ -2023,7 +2029,7 @@ packages:
/is-core-module@2.13.1:
resolution: {integrity: sha512-hHrIjvZsftOsvKSn2TRYl63zvxsgE0K+0mYMoH6gD4omR5IWB2KynivBQczo3+wF1cCkjzvptnI9Q0sPU66ilw==}
dependencies:
hasown: 2.0.0
hasown: 2.0.2
dev: true
/is-date-object@1.0.5:
@ -2111,7 +2117,7 @@ packages:
resolution: {integrity: sha512-uZ25/bUAlUY5fR4OKT4rZQEBrzQWYV9ZJYGGsUmEJ6thodVJ1HX64ePQ6Z0qPWP+m+Uq6e9UugrE38jeYsDSMw==}
engines: {node: '>= 0.4'}
dependencies:
which-typed-array: 1.1.14
which-typed-array: 1.1.15
dev: true
/is-unicode-supported@0.1.0:
@ -2624,8 +2630,8 @@ packages:
mri: 1.2.0
dev: true
/safe-array-concat@1.1.0:
resolution: {integrity: sha512-ZdQ0Jeb9Ofti4hbt5lX3T2JcAamT9hfzYU1MNB+z/jaEbB6wfFfPIR/zEORmZqobkCCJhSjodobH6WHNmJ97dg==}
/safe-array-concat@1.1.2:
resolution: {integrity: sha512-vj6RsCsWBCf19jIeHEfkRMw8DPiBb+DMXklQ/1SGDHOMlHdPUkZXFQ2YdplS23zESTijAcurb1aSgJA3AgMu1Q==}
engines: {node: '>=0.4'}
dependencies:
call-bind: 1.0.7
@ -3121,7 +3127,7 @@ packages:
spdx-expression-parse: 3.0.1
dev: true
/vite@5.1.4(@types/node@20.11.24):
/vite@5.1.4(@types/node@20.11.28):
resolution: {integrity: sha512-n+MPqzq+d9nMVTKyewqw6kSt+R3CkvF9QAKY8obiQn8g1fwTscKxyfaYnC632HtBXAQGc1Yjomphwn1dtwGAHg==}
engines: {node: ^18.0.0 || >=20.0.0}
hasBin: true
@ -3149,7 +3155,7 @@ packages:
terser:
optional: true
dependencies:
'@types/node': 20.11.24
'@types/node': 20.11.28
esbuild: 0.19.12
postcss: 8.4.35
rollup: 4.12.0
@ -3165,7 +3171,7 @@ packages:
vite:
optional: true
dependencies:
vite: 5.1.4(@types/node@20.11.24)
vite: 5.1.4(@types/node@20.11.28)
dev: true
/wcwidth@1.0.1:
@ -3184,8 +3190,8 @@ packages:
is-symbol: 1.0.4
dev: true
/which-typed-array@1.1.14:
resolution: {integrity: sha512-VnXFiIW8yNn9kIHN88xvZ4yOWchftKDsRJ8fEPacX/wl1lOvBrhsJ/OeJCXq7B0AaijRuqgzSKalJoPk+D8MPg==}
/which-typed-array@1.1.15:
resolution: {integrity: sha512-oV0jmFtUky6CXfkqehVvBP/LSWJ2sy4vWMioiENyJLePrBO/yKyV9OyJySfAKosh+RYkIl5zJCNZ8/4JncrpdA==}
engines: {node: '>= 0.4'}
dependencies:
available-typed-arrays: 1.0.7