Compare commits
474 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c1f0c52d5 | ||
|
|
2318b6bdd0 | ||
|
|
34fc4f0cbb | ||
|
|
68002b0308 | ||
|
|
4bba2c2493 | ||
|
|
9d63f7cb2d | ||
|
|
4a4e5c0abe | ||
|
|
885ea10f2a | ||
|
|
edab1b231b | ||
|
|
333c11986d | ||
|
|
be3182793d | ||
|
|
a279129ad8 | ||
|
|
027c6efb32 | ||
|
|
755cbe4dae | ||
|
|
111a5843ef | ||
|
|
49e3977199 | ||
|
|
ca325a01c5 | ||
|
|
25f60db703 | ||
|
|
478a5fcba3 | ||
|
|
bf69fc5f65 | ||
|
|
0fd88b2cdf | ||
|
|
8302893233 | ||
|
|
1526e3d441 | ||
|
|
dfd787c8ae | ||
|
|
a488bbc754 | ||
|
|
ce23bded90 | ||
|
|
c793785e30 | ||
|
|
036382d82d | ||
|
|
756ecbddcd | ||
|
|
648ccae5fc | ||
|
|
62cdf5dcca | ||
|
|
00d1dac515 | ||
|
|
d479bfaddc | ||
|
|
8fedeef4d1 | ||
|
|
2d877cee5a | ||
|
|
0a2c6bca0c | ||
|
|
d4436b0cdc | ||
|
|
ddf7cab503 | ||
|
|
74ddf574a8 | ||
|
|
d502b96509 | ||
|
|
dee3bb098a | ||
|
|
5ee65bf0af | ||
|
|
7b5c53bb7d | ||
|
|
17a8838569 | ||
|
|
25b2f71b24 | ||
|
|
008296238b | ||
|
|
2f78c4a1fb | ||
|
|
20d202c20e | ||
|
|
47f8f2f03a | ||
|
|
4ea9f34154 | ||
|
|
e4898b97ea | ||
|
|
98338e80c3 | ||
|
|
273408cdb8 | ||
|
|
0589fd63b1 | ||
|
|
6bcb0bef71 | ||
|
|
705b8eb748 | ||
|
|
05073e667e | ||
|
|
970a7fa42f | ||
|
|
575e01cab9 | ||
|
|
eb36621b30 | ||
|
|
da1d4d30b2 | ||
|
|
68a7b0beb1 | ||
|
|
4d5a5d399b | ||
|
|
f82494abab | ||
|
|
4dcafa0708 | ||
|
|
c071596151 | ||
|
|
4b66ad73a7 | ||
|
|
4a06891db9 | ||
|
|
3b9f2086ee | ||
|
|
94f6d0529f | ||
|
|
b292f94186 | ||
|
|
66ebc249ca | ||
|
|
0f5a6823ec | ||
|
|
419204d587 | ||
|
|
11dacd7c71 | ||
|
|
19a0781667 | ||
|
|
3142cb026a | ||
|
|
2a1351382f | ||
|
|
0dccd00539 | ||
|
|
ecbf407058 | ||
|
|
18a91d9b78 | ||
|
|
a58fe82d48 | ||
|
|
aa7da321ba | ||
|
|
2ada5acd5a | ||
|
|
2062beac68 | ||
|
|
df4b668560 | ||
|
|
5e4742488f | ||
|
|
cda008a53e | ||
|
|
e91df3eab0 | ||
|
|
3c7eb65c7c | ||
|
|
b13b6d606a | ||
|
|
66cd9e185b | ||
|
|
1ca1598c58 | ||
|
|
89ae52d036 | ||
|
|
700fa1cd4a | ||
|
|
e65a135676 | ||
|
|
e981211a2d | ||
|
|
cd69eea27f | ||
|
|
b1ae85e2c1 | ||
|
|
497a0e8bee | ||
|
|
147f266929 | ||
|
|
0351d5e0b9 | ||
|
|
f0ac9fe35c | ||
|
|
17d6ec85c3 | ||
|
|
e7b9b118a8 | ||
|
|
8772d4796e | ||
|
|
38f5a669ae | ||
|
|
7be7c9edae | ||
|
|
f83b765d04 | ||
|
|
3d5a0a9b75 | ||
|
|
d19d827496 | ||
|
|
35dd49d7ac | ||
|
|
94d7fdc9a8 | ||
|
|
8fd54383a8 | ||
|
|
220e2d2801 | ||
|
|
1cf96c5292 | ||
|
|
11e9fbcc44 | ||
|
|
6728271a98 | ||
|
|
82e027d872 | ||
|
|
f3eb072182 | ||
|
|
eafcf2dd1f | ||
|
|
c216fb1430 | ||
|
|
d567dd9867 | ||
|
|
2000ebd254 | ||
|
|
a5d47eac5a | ||
|
|
e506047415 | ||
|
|
7b3b7583c0 | ||
|
|
f078e006c1 | ||
|
|
3adc722cca | ||
|
|
c64862f604 | ||
|
|
26203cca59 | ||
|
|
6ae5a33acd | ||
|
|
4631655c3e | ||
|
|
10eb9a84fb | ||
|
|
e2c9ef0518 | ||
|
|
04973849a0 | ||
|
|
a0c34ee48d | ||
|
|
3f92dace6c | ||
|
|
16085a5fed | ||
|
|
d2a0f75e2e | ||
|
|
c22af17fa6 | ||
|
|
f967450eea | ||
|
|
694f1c212f | ||
|
|
8ece1ef187 | ||
|
|
c95cc305f8 | ||
|
|
63b08a4b71 | ||
|
|
96609fc328 | ||
|
|
927097a902 | ||
|
|
cbc874df0d | ||
|
|
e19776a2b8 | ||
|
|
c5e35cf8b1 | ||
|
|
ff9decb54b | ||
|
|
0224afae4a | ||
|
|
72c2f89cc8 | ||
|
|
6f0617492b | ||
|
|
dd912b8246 | ||
|
|
d56ee35b06 | ||
|
|
2619da9c5f | ||
|
|
d2f65716fe | ||
|
|
497fa474a7 | ||
|
|
28b89036f1 | ||
|
|
308d9916ba | ||
|
|
95006a7471 | ||
|
|
5b728b8144 | ||
|
|
1e98013e45 | ||
|
|
e059c35fbb | ||
|
|
d10a3d2d65 | ||
|
|
33601dde24 | ||
|
|
7fb5e6d65d | ||
|
|
b25ccdc6b2 | ||
|
|
5497cadb56 | ||
|
|
2ecd4b8eb6 | ||
|
|
76ac78c40c | ||
|
|
97b4ce42c4 | ||
|
|
832425025f | ||
|
|
7ea9899385 | ||
|
|
ed046f284d | ||
|
|
cb22e34215 | ||
|
|
8765c5e705 | ||
|
|
11bb95db92 | ||
|
|
5d8c2925d8 | ||
|
|
61396625f1 | ||
|
|
b2728cb09a | ||
|
|
0476dcebb8 | ||
|
|
b1cd1a4220 | ||
|
|
79b7733e1e | ||
|
|
7e9b1fafa3 | ||
|
|
feb69ef7a7 | ||
|
|
4520335ebc | ||
|
|
c25eacad05 | ||
|
|
73ae5c41b5 | ||
|
|
1f4f94b3a5 | ||
|
|
d213d3546a | ||
|
|
28ba8657f9 | ||
|
|
863fbfc5cc | ||
|
|
70c7de1efc | ||
|
|
595a29056d | ||
|
|
4872029b87 | ||
|
|
979e494e75 | ||
|
|
5bcc3acc56 | ||
|
|
8a4a06f888 | ||
|
|
f9027033e5 | ||
|
|
8c14a2742c | ||
|
|
c371676ad0 | ||
|
|
3169627b79 | ||
|
|
049becb900 | ||
|
|
ad8a83e60e | ||
|
|
f11e3b7f82 | ||
|
|
74d20d5be3 | ||
|
|
7add3dd517 | ||
|
|
9e7f1bf138 | ||
|
|
43d9cb837f | ||
|
|
1cb1a66ef1 | ||
|
|
a4e54ac527 | ||
|
|
bae43c0d90 | ||
|
|
afc77f55b8 | ||
|
|
95aadf6e73 | ||
|
|
731ebad1ee | ||
|
|
475bfb59ae | ||
|
|
e77723164b | ||
|
|
4bf1463406 | ||
|
|
d6e80b71d7 | ||
|
|
a6d402b915 | ||
|
|
0baf4677e7 | ||
|
|
d3da24c916 | ||
|
|
f7324db5fc | ||
|
|
4305057185 | ||
|
|
e265f7d478 | ||
|
|
add0f2788f | ||
|
|
63e12868b1 | ||
|
|
ca38f7ca69 | ||
|
|
915b96c218 | ||
|
|
3acf565ccd | ||
|
|
aa7eaa0929 | ||
|
|
c9451d90dd | ||
|
|
d600102d46 | ||
|
|
e55ffccd21 | ||
|
|
f89b8c3b52 | ||
|
|
2a219ac042 | ||
|
|
611640b32b | ||
|
|
866a3c63e8 | ||
|
|
6354705626 | ||
|
|
b4668e23c7 | ||
|
|
7ef211ddd5 | ||
|
|
4c928cbc33 | ||
|
|
5a83d6ae86 | ||
|
|
8acca9ef4a | ||
|
|
c93b076bf6 | ||
|
|
4fec2777ce | ||
|
|
dd1aca7e30 | ||
|
|
27b1789657 | ||
|
|
05dd440dea | ||
|
|
962ab01ea4 | ||
|
|
fa8e57a589 | ||
|
|
3c9620f973 | ||
|
|
618f37e250 | ||
|
|
aa23967329 | ||
|
|
03739f9799 | ||
|
|
94cd52dec7 | ||
|
|
bad5f78991 | ||
|
|
a039bb478e | ||
|
|
f6f17cd61c | ||
|
|
429b69ec92 | ||
|
|
e39220c024 | ||
|
|
ee73f89863 | ||
|
|
4356ace665 | ||
|
|
59fcce7e40 | ||
|
|
a671b17b4f | ||
|
|
2d10da72f6 | ||
|
|
959cb21d83 | ||
|
|
5f7f2005fa | ||
|
|
a2d34a027e | ||
|
|
e58f82d7ed | ||
|
|
1be83ccf4c | ||
|
|
1b5f9bf62d | ||
|
|
b298524663 | ||
|
|
7473c29948 | ||
|
|
9632c77177 | ||
|
|
8fdf858dcb | ||
|
|
b2a8bdaa42 | ||
|
|
bb7d650bcd | ||
|
|
66f95dcd8e | ||
|
|
469f0d6c4e | ||
|
|
1fb4f90d50 | ||
|
|
d74f516336 | ||
|
|
f7f56c6c83 | ||
|
|
2923bf9f27 | ||
|
|
2da4823ee7 | ||
|
|
b132ad6df5 | ||
|
|
a1b2d97dbc | ||
|
|
332e5bffda | ||
|
|
9e616ca35a | ||
|
|
4e29295f68 | ||
|
|
d07be16fc6 | ||
|
|
f6169ab27e | ||
|
|
b156d6154e | ||
|
|
e8eae7dce6 | ||
|
|
d59677e322 | ||
|
|
55dbcf0eb3 | ||
|
|
b35a20f43d | ||
|
|
a4cc82f526 | ||
|
|
bdea445e4f | ||
|
|
49e98d522f | ||
|
|
b72d0af17d | ||
|
|
1b948ed41e | ||
|
|
d640ad88b2 | ||
|
|
3fa793bef6 | ||
|
|
7fde07f107 | ||
|
|
19b827c049 | ||
|
|
ab25cc915e | ||
|
|
df312cd419 | ||
|
|
dd8f471d60 | ||
|
|
8a10266960 | ||
|
|
3131d140fa | ||
|
|
1776bd85d8 | ||
|
|
57313fee9b | ||
|
|
d660c8e2e4 | ||
|
|
3d2900ab69 | ||
|
|
938680bb80 | ||
|
|
4d8a0b28ca | ||
|
|
2adec5a999 | ||
|
|
2ccaf724bf | ||
|
|
8e24c6a8d8 | ||
|
|
d5da6d4562 | ||
|
|
3e50e37e02 | ||
|
|
c2ed9e3693 | ||
|
|
c1e8036323 | ||
|
|
6769f5fa6c | ||
|
|
addeab0e30 | ||
|
|
3b94794aa3 | ||
|
|
6f560ecae9 | ||
|
|
e8ae8812ff | ||
|
|
157be2d6ab | ||
|
|
0c20473e30 | ||
|
|
2f253d4999 | ||
|
|
fc11432b87 | ||
|
|
371ca270fa | ||
|
|
a24c6d825e | ||
|
|
10303b6596 | ||
|
|
235706b230 | ||
|
|
4ed554c039 | ||
|
|
5f6409e0a5 | ||
|
|
1724429fb0 | ||
|
|
1da4671133 | ||
|
|
c606099104 | ||
|
|
e0eb490636 | ||
|
|
d07306cb86 | ||
|
|
4a032d744b | ||
|
|
8691cf8c1f | ||
|
|
c5aacd30e3 | ||
|
|
812533394b | ||
|
|
7881f818ae | ||
|
|
58fee9914b | ||
|
|
70352e9f91 | ||
|
|
12454ee401 | ||
|
|
29db09bb5b | ||
|
|
4a601d157d | ||
|
|
7dc017f4b6 | ||
|
|
fb3c5b33c0 | ||
|
|
4bb6a52431 | ||
|
|
cb405f1790 | ||
|
|
cdc15ef488 | ||
|
|
f511095fde | ||
|
|
b082afe761 | ||
|
|
1db50e41f9 | ||
|
|
5ef2026b61 | ||
|
|
5775c56bd8 | ||
|
|
2ff6451f37 | ||
|
|
e86fcf1b9a | ||
|
|
39469cb08b | ||
|
|
0ad4d9ab81 | ||
|
|
67eca589d8 | ||
|
|
f686c1aa16 | ||
|
|
e6a8b83900 | ||
|
|
84a088a42e | ||
|
|
73c0511167 | ||
|
|
66076e5841 | ||
|
|
bba61c2a37 | ||
|
|
7a3932f969 | ||
|
|
ef51d665c8 | ||
|
|
b2d2f28b40 | ||
|
|
942bf2b31b | ||
|
|
4a812a884b | ||
|
|
3113af8ce8 | ||
|
|
30f237dc1f | ||
|
|
b1a0cdb195 | ||
|
|
907bc57c2d | ||
|
|
d533e470fc | ||
|
|
f3c753ad30 | ||
|
|
c959fb77cf | ||
|
|
5bc0de4d1a | ||
|
|
c4f3300e9b | ||
|
|
cc55fee339 | ||
|
|
dd9083ce7a | ||
|
|
29967d7e4e | ||
|
|
b916df7736 | ||
|
|
cb92d36c95 | ||
|
|
00e7118771 | ||
|
|
5b8f05bdf8 | ||
|
|
74b21d93d6 | ||
|
|
a0a813ed09 | ||
|
|
45fd9f9de1 | ||
|
|
182d39a887 | ||
|
|
8681ebc0c0 | ||
|
|
f3608b0f30 | ||
|
|
8fcd446926 | ||
|
|
ca8248b2a0 | ||
|
|
505f60a8a1 | ||
|
|
705f5c75cb | ||
|
|
1321b15c0d | ||
|
|
289832d58b | ||
|
|
85e2272a5c | ||
|
|
c04219cbf7 | ||
|
|
d3be8e7a42 | ||
|
|
f059a23ecc | ||
|
|
16df0dc875 | ||
|
|
ebfafa4143 | ||
|
|
0bbdbc85ad | ||
|
|
440916e312 | ||
|
|
d58329d86e | ||
|
|
a70e95fb7e | ||
|
|
7bcf380198 | ||
|
|
11efe87b2e | ||
|
|
db163a1bb5 | ||
|
|
6733151bca | ||
|
|
bf82bbf48a | ||
|
|
dda7b9939f | ||
|
|
99bb296866 | ||
|
|
de1278a416 | ||
|
|
66ed89d39e | ||
|
|
fdd8edec70 | ||
|
|
39ae0cfe6d | ||
|
|
d53b24bfb4 | ||
|
|
ed250ba03d | ||
|
|
8e5eb68935 | ||
|
|
bad944a232 | ||
|
|
1017f1a38b | ||
|
|
60c8bd77f5 | ||
|
|
38c1cf4373 | ||
|
|
a4fbe3c8df | ||
|
|
297e14ebb2 | ||
|
|
1fea2a729a | ||
|
|
613f380ea7 | ||
|
|
0cf5358f77 | ||
|
|
6d33a3a35e | ||
|
|
71f72bd09b | ||
|
|
ec4cf938bc | ||
|
|
7ebce1166b | ||
|
|
07aa2bf768 | ||
|
|
825d46c934 | ||
|
|
b45d36e06a | ||
|
|
cb7988b8ed | ||
|
|
12d0eda6ef | ||
|
|
413e86b8b9 | ||
|
|
124b8f4081 | ||
|
|
81d3a76518 | ||
|
|
2d0ae89727 | ||
|
|
09c1cbbb94 | ||
|
|
0e0eaea946 | ||
|
|
cb9186adc0 | ||
|
|
1e5921fa61 | ||
|
|
cc081ca64c | ||
|
|
17b4027e0b | ||
|
|
35773a6969 | ||
|
|
ebdca8870b | ||
|
|
4563cd3a99 | ||
|
|
37861089ba | ||
|
|
b914851841 | ||
|
|
4c7bd31b88 | ||
|
|
1a65cee738 | ||
|
|
392b2f78af | ||
|
|
5bb5fcd09c | ||
|
|
b8ad1ae41a | ||
|
|
d4864099a6 |
904 changed files with 160623 additions and 56873 deletions
|
|
@ -1,19 +1,19 @@
|
||||||
**
|
**
|
||||||
|
|
||||||
!turbo.json
|
|
||||||
!bun.lock
|
!bun.lock
|
||||||
!package.json
|
!package.json
|
||||||
|
!.gitignore
|
||||||
|
!bunfig.toml
|
||||||
|
|
||||||
!**/package.json
|
!**/package.json
|
||||||
!**/bun.lock
|
!**/bun.lock
|
||||||
!**/tsconfig.json
|
!**/tsconfig.json
|
||||||
!**/vite.config.ts
|
!**/vite.config.ts
|
||||||
!**/react-router.config.ts
|
|
||||||
!**/build.ts
|
|
||||||
!**/components.json
|
!**/components.json
|
||||||
|
|
||||||
!src/**
|
|
||||||
!app/**
|
!app/**
|
||||||
|
!apps/agent/**
|
||||||
|
!packages/**
|
||||||
!public/**
|
!public/**
|
||||||
|
|
||||||
# License files and attributions
|
# License files and attributions
|
||||||
|
|
@ -22,3 +22,6 @@
|
||||||
!LICENSES/**
|
!LICENSES/**
|
||||||
|
|
||||||
node_modules/**
|
node_modules/**
|
||||||
|
dist/**
|
||||||
|
.output/**
|
||||||
|
app/test/integration/artifacts/**
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
SERVER_IP=localhost
|
SERVER_IP=localhost
|
||||||
DATABASE_URL=./data/zerobyte.db
|
ZEROBYTE_DATABASE_URL=./data/zerobyte.db
|
||||||
RESTIC_CACHE_DIR=./data/restic/cache
|
RESTIC_CACHE_DIR=./data/restic/cache
|
||||||
ZEROBYTE_REPOSITORIES_DIR=./data/repositories
|
ZEROBYTE_REPOSITORIES_DIR=./data/repositories
|
||||||
ZEROBYTE_VOLUMES_DIR=./data/volumes
|
ZEROBYTE_VOLUMES_DIR=./data/volumes
|
||||||
APP_SECRET=<openssl rand -hex 32>
|
APP_SECRET=<openssl rand -hex 32>
|
||||||
|
BASE_URL=http://*.localhost
|
||||||
|
TRUST_PROXY=false
|
||||||
|
PORT=3000
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
DATABASE_URL=:memory:
|
ZEROBYTE_DATABASE_URL=:memory:
|
||||||
APP_SECRET=8b9acd4456dd5db0a4a3c4f4e1240b2c3ae08bb59690167197425e4a25dd9a69
|
APP_SECRET=8b9acd4456dd5db0a4a3c4f4e1240b2c3ae08bb59690167197425e4a25dd9a69
|
||||||
BASE_URL=http://localhost:4096
|
BASE_URL=http://localhost:4096
|
||||||
|
ENABLE_LOCAL_AGENT=true
|
||||||
|
|
|
||||||
13
.fallowrc.json
Normal file
13
.fallowrc.json
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
"entry": [
|
||||||
|
"app/client.tsx",
|
||||||
|
"app/router.tsx",
|
||||||
|
"app/server.ts",
|
||||||
|
"app/server/plugins/bootstrap.ts",
|
||||||
|
"openapi-ts.config.ts",
|
||||||
|
"scripts/create-test-files.ts",
|
||||||
|
"scripts/patch-api-client.ts"
|
||||||
|
],
|
||||||
|
"ignorePatterns": ["node_modules/**", ".output/**", "**/api-client/**", "**/routeTree.gen.ts", "apps/docs/**"],
|
||||||
|
"ignoreDependencies": ["@tailwindcss/typography", "babel-plugin-react-compiler"]
|
||||||
|
}
|
||||||
10
.github/ISSUE_TEMPLATE/2_bug_report.yml
vendored
10
.github/ISSUE_TEMPLATE/2_bug_report.yml
vendored
|
|
@ -12,6 +12,16 @@ body:
|
||||||
options:
|
options:
|
||||||
- label: I have read the [troubleshooting guide](https://github.com/nicotsx/zerobyte/blob/main/TROUBLESHOOTING.md)
|
- label: I have read the [troubleshooting guide](https://github.com/nicotsx/zerobyte/blob/main/TROUBLESHOOTING.md)
|
||||||
required: true
|
required: true
|
||||||
|
- type: checkboxes
|
||||||
|
id: rclone_preflight
|
||||||
|
attributes:
|
||||||
|
label: Rclone Pre-flight Checklist (if applicable)
|
||||||
|
description: If your issue involves rclone, confirm you've tested on the host first as described in the troubleshooting guide
|
||||||
|
options:
|
||||||
|
- label: This issue is NOT related to rclone (skip if not using rclone)
|
||||||
|
- label: I have tested `rclone listremotes` and `rclone lsd remote:` on the **host** and they work
|
||||||
|
- label: I have verified the rclone config is mounted into the container
|
||||||
|
- label: I have restarted the container after config changes
|
||||||
- type: textarea
|
- type: textarea
|
||||||
id: description
|
id: description
|
||||||
attributes:
|
attributes:
|
||||||
|
|
|
||||||
22
.github/actions/install-dependencies/action.yml
vendored
22
.github/actions/install-dependencies/action.yml
vendored
|
|
@ -1,15 +1,31 @@
|
||||||
name: Install dependencies
|
name: Install dependencies
|
||||||
|
|
||||||
description: Install dependencies
|
description: Install dependencies
|
||||||
|
inputs:
|
||||||
|
workingDirectory:
|
||||||
|
description: "The working directory to install dependencies in"
|
||||||
|
required: false
|
||||||
|
default: "."
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: "composite"
|
using: "composite"
|
||||||
steps:
|
steps:
|
||||||
- uses: oven-sh/setup-bun@v2
|
- uses: socketdev/action@937f824ec476dfd164d4a4d9995751427b0be143 # v1
|
||||||
|
with:
|
||||||
|
mode: firewall
|
||||||
|
|
||||||
|
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
|
||||||
name: Install Bun
|
name: Install Bun
|
||||||
with:
|
with:
|
||||||
bun-version: "1.3.8"
|
bun-version: "1.3.14"
|
||||||
|
|
||||||
|
- uses: voidzero-dev/setup-vp@ca1c46663915d6c1042ae23bd39ab85718bfb0fa # v1
|
||||||
|
with:
|
||||||
|
node-version: '24'
|
||||||
|
cache: true
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
shell: bash
|
shell: bash
|
||||||
run: bun install --frozen-lockfile
|
run: |
|
||||||
|
cd ${{ inputs.workingDirectory }}
|
||||||
|
sfw vp install --frozen-lockfile
|
||||||
|
|
|
||||||
18
.github/dependabot.yml
vendored
18
.github/dependabot.yml
vendored
|
|
@ -1,18 +0,0 @@
|
||||||
version: 2
|
|
||||||
updates:
|
|
||||||
- package-ecosystem: "bun"
|
|
||||||
directory: "/"
|
|
||||||
schedule:
|
|
||||||
interval: "daily"
|
|
||||||
rebase-strategy: 'auto'
|
|
||||||
groups:
|
|
||||||
minor-patch:
|
|
||||||
update-types:
|
|
||||||
- minor
|
|
||||||
- patch
|
|
||||||
|
|
||||||
- package-ecosystem: 'github-actions'
|
|
||||||
directory: '/'
|
|
||||||
schedule:
|
|
||||||
interval: 'daily'
|
|
||||||
rebase-strategy: 'auto'
|
|
||||||
19
.github/renovate.json
vendored
Normal file
19
.github/renovate.json
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
|
"extends": ["config:recommended", "helpers:pinGitHubActionDigests"],
|
||||||
|
"enabledManagers": ["bun", "github-actions"],
|
||||||
|
"minimumReleaseAge": "3 days",
|
||||||
|
"rangeStrategy": "bump",
|
||||||
|
"packageRules": [
|
||||||
|
{
|
||||||
|
"matchManagers": ["github-actions"],
|
||||||
|
"matchUpdateTypes": ["digest", "pinDigest"],
|
||||||
|
"minimumReleaseAge": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"matchManagers": ["bun"],
|
||||||
|
"matchUpdateTypes": ["minor", "patch"],
|
||||||
|
"groupName": "bun minor and patch dependencies"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
75
.github/workflows/checks.yml
vendored
75
.github/workflows/checks.yml
vendored
|
|
@ -3,8 +3,6 @@ name: Checks
|
||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
|
@ -12,31 +10,86 @@ on:
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: checks-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||||
|
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
checks:
|
lint:
|
||||||
timeout-minutes: 15
|
timeout-minutes: 10
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 1
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
uses: "./.github/actions/install-dependencies"
|
uses: "./.github/actions/install-dependencies"
|
||||||
|
|
||||||
- uses: oxc-project/oxlint-action@latest
|
- name: Run lint
|
||||||
|
shell: bash
|
||||||
|
run: vp lint --type-aware --deny-warnings
|
||||||
|
|
||||||
|
typecheck:
|
||||||
|
timeout-minutes: 10
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||||
with:
|
with:
|
||||||
config: .oxlintrc.json
|
fetch-depth: 1
|
||||||
deny-warnings: true
|
|
||||||
|
- name: Install dependencies
|
||||||
|
uses: "./.github/actions/install-dependencies"
|
||||||
|
|
||||||
- name: Run type checks
|
- name: Run type checks
|
||||||
shell: bash
|
shell: bash
|
||||||
run: bun run tsc
|
run: bun run tsc
|
||||||
|
|
||||||
- name: Run tests
|
test-server:
|
||||||
|
timeout-minutes: 15
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||||
|
with:
|
||||||
|
fetch-depth: 1
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
uses: "./.github/actions/install-dependencies"
|
||||||
|
|
||||||
|
- name: Run server tests
|
||||||
shell: bash
|
shell: bash
|
||||||
run: bun run test --ci --coverage
|
run: bun run test:server
|
||||||
|
|
||||||
|
test-client:
|
||||||
|
timeout-minutes: 15
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||||
|
with:
|
||||||
|
fetch-depth: 1
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
uses: "./.github/actions/install-dependencies"
|
||||||
|
|
||||||
|
- name: Run client tests
|
||||||
|
shell: bash
|
||||||
|
run: bun run test:client
|
||||||
|
|
||||||
|
build:
|
||||||
|
timeout-minutes: 15
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||||
|
with:
|
||||||
|
fetch-depth: 1
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
uses: "./.github/actions/install-dependencies"
|
||||||
|
|
||||||
- name: Build project
|
- name: Build project
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
|
||||||
41
.github/workflows/docs-deploy.yml
vendored
Normal file
41
.github/workflows/docs-deploy.yml
vendored
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
name: Docs deploy
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
paths:
|
||||||
|
- "apps/docs/**"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
name: Deploy docs
|
||||||
|
if: github.event.repository.default_branch == github.ref_name
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 10
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
uses: "./.github/actions/install-dependencies"
|
||||||
|
|
||||||
|
- name: Build docs
|
||||||
|
working-directory: apps/docs
|
||||||
|
run: bun run build
|
||||||
|
|
||||||
|
- name: Build and deploy docs
|
||||||
|
uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4
|
||||||
|
with:
|
||||||
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
|
workingDirectory: apps/docs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
32
.github/workflows/e2e.yml
vendored
32
.github/workflows/e2e.yml
vendored
|
|
@ -12,7 +12,7 @@ jobs:
|
||||||
timeout-minutes: 20
|
timeout-minutes: 20
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
uses: "./.github/actions/install-dependencies"
|
uses: "./.github/actions/install-dependencies"
|
||||||
|
|
@ -26,7 +26,7 @@ jobs:
|
||||||
|
|
||||||
- name: Cache Playwright Browsers
|
- name: Cache Playwright Browsers
|
||||||
id: playwright-cache
|
id: playwright-cache
|
||||||
uses: actions/cache@v5
|
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
|
||||||
with:
|
with:
|
||||||
path: ~/.cache/ms-playwright
|
path: ~/.cache/ms-playwright
|
||||||
key: ${{ runner.os }}-playwright-${{ steps.playwright-version.outputs.version }}
|
key: ${{ runner.os }}-playwright-${{ steps.playwright-version.outputs.version }}
|
||||||
|
|
@ -46,22 +46,37 @@ jobs:
|
||||||
mkdir -p data
|
mkdir -p data
|
||||||
mkdir -p playwright/temp
|
mkdir -p playwright/temp
|
||||||
mkdir -p playwright/data
|
mkdir -p playwright/data
|
||||||
|
mkdir -p playwright/tinyauth/app-data
|
||||||
|
mkdir -p playwright/tinyauth/caddy-data
|
||||||
chmod -R 777 playwright/temp
|
chmod -R 777 playwright/temp
|
||||||
touch .env.local
|
touch .env.local
|
||||||
echo "SERVER_IP=localhost" >> .env.local
|
echo "SERVER_IP=localhost" >> .env.local
|
||||||
echo "DATABASE_URL=./data/zerobyte.db" >> .env.local
|
echo "ZEROBYTE_DATABASE_URL=./data/zerobyte.db" >> .env.local
|
||||||
echo "BASE_URL=http://localhost:4096" >> .env.local
|
echo "BASE_URL=http://localhost:4096" >> .env.local
|
||||||
|
echo "E2E_TINYAUTH_ORIGIN=https://tinyauth.example.com:5557" >> .env.local
|
||||||
|
echo "TZ=Europe/Zurich" >> .env.local
|
||||||
|
|
||||||
- name: Start zerobyte-e2e service
|
- name: Start zerobyte-e2e service
|
||||||
run: bun run start:e2e -- -d
|
run: bun run start:e2e -- -d
|
||||||
|
|
||||||
|
- name: Check CLI version
|
||||||
|
run: |
|
||||||
|
expected_version=$(docker exec zerobyte printenv APP_VERSION)
|
||||||
|
cli_version=$(docker exec zerobyte bun run --silent cli --version)
|
||||||
|
echo "$cli_version"
|
||||||
|
test "$cli_version" = "$expected_version"
|
||||||
|
|
||||||
- name: Wait for zerobyte to be ready
|
- name: Wait for zerobyte to be ready
|
||||||
run: |
|
run: |
|
||||||
timeout 30s bash -c 'until curl -f http://localhost:4096/healthcheck; do echo "Waiting for server..." && sleep 2; done'
|
timeout 30s bash -c 'until curl -f http://localhost:4096/api/healthcheck; do echo "Waiting for server..." && sleep 2; done'
|
||||||
|
|
||||||
|
- name: Wait for Tinyauth to be ready
|
||||||
|
run: |
|
||||||
|
timeout 30s bash -c 'until curl -skf https://localhost:5557/.well-known/openid-configuration; do echo "Waiting for Tinyauth..." && sleep 2; done'
|
||||||
|
|
||||||
- name: Print docker logs if failed to start
|
- name: Print docker logs if failed to start
|
||||||
if: failure()
|
if: failure()
|
||||||
run: docker logs zerobyte || true
|
run: docker compose logs zerobyte-e2e tinyauth tinyauth-app || true
|
||||||
|
|
||||||
- name: Make playwright directory writable
|
- name: Make playwright directory writable
|
||||||
run: sudo chmod 777 playwright/data/zerobyte.db
|
run: sudo chmod 777 playwright/data/zerobyte.db
|
||||||
|
|
@ -72,15 +87,16 @@ jobs:
|
||||||
- name: Dump container logs in playwright-report folder
|
- name: Dump container logs in playwright-report folder
|
||||||
if: always()
|
if: always()
|
||||||
run: |
|
run: |
|
||||||
tree playwright
|
tree playwright || true
|
||||||
docker logs zerobyte > playwright-report/container-logs.txt || true
|
docker compose logs zerobyte-e2e > playwright-report/container-logs.txt || true
|
||||||
|
docker compose logs tinyauth tinyauth-app > playwright-report/tinyauth-logs.txt || true
|
||||||
|
|
||||||
- name: Debug - print content of /test-data in container
|
- name: Debug - print content of /test-data in container
|
||||||
if: failure()
|
if: failure()
|
||||||
run: |
|
run: |
|
||||||
docker exec zerobyte /bin/ash -c "ls -la /test-data" || true
|
docker exec zerobyte /bin/ash -c "ls -la /test-data" || true
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v6
|
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
|
||||||
if: always()
|
if: always()
|
||||||
with:
|
with:
|
||||||
name: playwright-report
|
name: playwright-report
|
||||||
|
|
|
||||||
35
.github/workflows/integration.yml
vendored
Normal file
35
.github/workflows/integration.yml
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
name: Integration Tests
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
workflow_call:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
integration:
|
||||||
|
name: Integration
|
||||||
|
timeout-minutes: 30
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
uses: "./.github/actions/install-dependencies"
|
||||||
|
|
||||||
|
- name: Run integration tests
|
||||||
|
env:
|
||||||
|
SKIP_VOLUME_MOUNT_INTEGRATION_TESTS: "true"
|
||||||
|
run: bun run test:integration
|
||||||
|
|
||||||
|
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
|
||||||
|
if: failure()
|
||||||
|
with:
|
||||||
|
name: integration-artifacts
|
||||||
|
path: |
|
||||||
|
app/test/integration/artifacts/compose.log
|
||||||
|
app/test/integration/artifacts/docker-output.log
|
||||||
|
app/test/integration/artifacts/runs/**
|
||||||
|
retention-days: 5
|
||||||
60
.github/workflows/nightly.yml
vendored
Normal file
60
.github/workflows/nightly.yml
vendored
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
name: Nightly Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: "0 2 * * *"
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-push:
|
||||||
|
timeout-minutes: 15
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||||
|
|
||||||
|
- name: Log in to Docker Hub
|
||||||
|
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4
|
||||||
|
with:
|
||||||
|
driver: cloud
|
||||||
|
endpoint: "meienberger/runtipi-builder"
|
||||||
|
install: true
|
||||||
|
|
||||||
|
- name: Login to GitHub Container Registry
|
||||||
|
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.repository_owner }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Docker meta
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 # v6
|
||||||
|
with:
|
||||||
|
images: ghcr.io/${{ github.repository_owner }}/zerobyte
|
||||||
|
tags: |
|
||||||
|
type=raw,value=nightly
|
||||||
|
|
||||||
|
- name: Push images to GitHub Container Registry
|
||||||
|
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
target: production
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
build-args: |
|
||||||
|
APP_VERSION=nightly
|
||||||
77
.github/workflows/release.yml
vendored
77
.github/workflows/release.yml
vendored
|
|
@ -8,16 +8,16 @@ on:
|
||||||
- "v*.*.*-alpha.*"
|
- "v*.*.*-alpha.*"
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: read
|
||||||
packages: write
|
|
||||||
security-events: write
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
determine-release-type:
|
determine-release-type:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions: {}
|
||||||
outputs:
|
outputs:
|
||||||
release_type: ${{ steps.set-type.outputs.release_type }}
|
release_type: ${{ steps.set-type.outputs.release_type }}
|
||||||
tagname: ${{ github.ref_name }}
|
tagname: ${{ github.ref_name }}
|
||||||
|
is_minor_release: ${{ steps.set-type.outputs.is_minor_release }}
|
||||||
steps:
|
steps:
|
||||||
- name: Set release type
|
- name: Set release type
|
||||||
id: set-type
|
id: set-type
|
||||||
|
|
@ -31,74 +31,60 @@ jobs:
|
||||||
echo "release_type=release" >> $GITHUB_OUTPUT
|
echo "release_type=release" >> $GITHUB_OUTPUT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ $TAG =~ ^v[0-9]+\.[0-9]+\.0$ ]]; then
|
||||||
|
echo "is_minor_release=true" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "is_minor_release=false" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
|
||||||
checks:
|
checks:
|
||||||
uses: ./.github/workflows/checks.yml
|
uses: ./.github/workflows/checks.yml
|
||||||
|
|
||||||
e2e-tests:
|
e2e-tests:
|
||||||
uses: ./.github/workflows/e2e.yml
|
uses: ./.github/workflows/e2e.yml
|
||||||
|
|
||||||
|
integration-tests:
|
||||||
|
uses: ./.github/workflows/integration.yml
|
||||||
|
|
||||||
build-images:
|
build-images:
|
||||||
|
environment: release
|
||||||
timeout-minutes: 15
|
timeout-minutes: 15
|
||||||
needs: [determine-release-type, checks, e2e-tests]
|
needs: [determine-release-type, checks, e2e-tests, integration-tests]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
security-events: write
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
ref: ${{ github.ref }}
|
ref: ${{ github.ref }}
|
||||||
|
|
||||||
- name: Log in to Docker Hub
|
- name: Log in to Docker Hub
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4
|
||||||
with:
|
with:
|
||||||
driver: cloud
|
driver: cloud
|
||||||
endpoint: "meienberger/runtipi-builder"
|
endpoint: "meienberger/runtipi-builder"
|
||||||
install: true
|
install: true
|
||||||
|
|
||||||
- name: Login to GitHub Container Registry
|
- name: Login to GitHub Container Registry
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.repository_owner }}
|
username: ${{ github.repository_owner }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Build docker image
|
|
||||||
uses: docker/build-push-action@v6
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
target: production
|
|
||||||
platforms: linux/amd64
|
|
||||||
push: false
|
|
||||||
load: true
|
|
||||||
tags: local/zerobyte:ci
|
|
||||||
build-args: |
|
|
||||||
APP_VERSION=${{ needs.determine-release-type.outputs.tagname }}
|
|
||||||
|
|
||||||
- name: Scan new image for vulnerabilities
|
|
||||||
if: needs.determine-release-type.outputs.release_type == 'release'
|
|
||||||
uses: anchore/scan-action@v7
|
|
||||||
id: scan
|
|
||||||
with:
|
|
||||||
image: local/zerobyte:ci
|
|
||||||
fail-build: true
|
|
||||||
only-fixed: true
|
|
||||||
severity-cutoff: critical
|
|
||||||
|
|
||||||
- name: upload Anchore scan report
|
|
||||||
if: needs.determine-release-type.outputs.release_type == 'release'
|
|
||||||
uses: github/codeql-action/upload-sarif@v4
|
|
||||||
with:
|
|
||||||
sarif_file: ${{ steps.scan.outputs.sarif }}
|
|
||||||
|
|
||||||
- name: Docker meta
|
- name: Docker meta
|
||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@v5
|
uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 # v6
|
||||||
with:
|
with:
|
||||||
images: ghcr.io/${{ github.repository_owner }}/zerobyte
|
images: ghcr.io/${{ github.repository_owner }}/zerobyte
|
||||||
tags: |
|
tags: |
|
||||||
|
|
@ -110,7 +96,7 @@ jobs:
|
||||||
latest=${{ needs.determine-release-type.outputs.release_type == 'release' }}
|
latest=${{ needs.determine-release-type.outputs.release_type == 'release' }}
|
||||||
|
|
||||||
- name: Push images to GitHub Container Registry
|
- name: Push images to GitHub Container Registry
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
target: production
|
target: production
|
||||||
|
|
@ -125,12 +111,14 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [build-images, determine-release-type]
|
needs: [build-images, determine-release-type]
|
||||||
if: needs.determine-release-type.outputs.release_type == 'release'
|
if: needs.determine-release-type.outputs.release_type == 'release'
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
outputs:
|
outputs:
|
||||||
id: ${{ steps.create_release.outputs.id }}
|
id: ${{ steps.create_release.outputs.id }}
|
||||||
steps:
|
steps:
|
||||||
- name: Create GitHub release
|
- name: Create GitHub release
|
||||||
id: create_release
|
id: create_release
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@b4309332981a82ec1c5618f44dd2e27cc8bfbfda # v3
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
with:
|
with:
|
||||||
|
|
@ -140,4 +128,13 @@ jobs:
|
||||||
name: ${{ needs.determine-release-type.outputs.tagname }}
|
name: ${{ needs.determine-release-type.outputs.tagname }}
|
||||||
draft: false
|
draft: false
|
||||||
prerelease: true
|
prerelease: true
|
||||||
files: cli/runtipi-cli-*
|
|
||||||
|
request-docs-version-update:
|
||||||
|
uses: ./.github/workflows/request-docs-version-update.yml
|
||||||
|
needs: [publish-release, determine-release-type]
|
||||||
|
if: needs.determine-release-type.outputs.release_type == 'release' && needs.determine-release-type.outputs.is_minor_release == 'true'
|
||||||
|
with:
|
||||||
|
release_tag: ${{ needs.determine-release-type.outputs.tagname }}
|
||||||
|
base_branch: ${{ github.event.repository.default_branch }}
|
||||||
|
secrets:
|
||||||
|
COPILOT_ASSIGNMENT_TOKEN: ${{ secrets.COPILOT_ASSIGNMENT_TOKEN }}
|
||||||
|
|
|
||||||
122
.github/workflows/request-docs-version-update.yml
vendored
Normal file
122
.github/workflows/request-docs-version-update.yml
vendored
Normal file
|
|
@ -0,0 +1,122 @@
|
||||||
|
name: Request docs version update
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
release_tag:
|
||||||
|
description: Minor release tag, for example v0.35.0
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
base_branch:
|
||||||
|
description: Branch Copilot should branch from
|
||||||
|
required: false
|
||||||
|
default: main
|
||||||
|
type: string
|
||||||
|
workflow_call:
|
||||||
|
inputs:
|
||||||
|
release_tag:
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
base_branch:
|
||||||
|
required: false
|
||||||
|
default: main
|
||||||
|
type: string
|
||||||
|
secrets:
|
||||||
|
COPILOT_ASSIGNMENT_TOKEN:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
request-docs-version-update:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Create Copilot issue
|
||||||
|
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
|
||||||
|
with:
|
||||||
|
github-token: ${{ secrets.COPILOT_ASSIGNMENT_TOKEN }}
|
||||||
|
script: |
|
||||||
|
if (!process.env.COPILOT_ASSIGNMENT_TOKEN) {
|
||||||
|
core.setFailed("COPILOT_ASSIGNMENT_TOKEN is required to assign issues to GitHub Copilot.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const releaseTag = process.env.RELEASE_TAG;
|
||||||
|
const baseBranch = process.env.BASE_BRANCH;
|
||||||
|
const minorRelease = releaseTag.match(/^(v\d+\.\d+)\.0$/);
|
||||||
|
if (!minorRelease) {
|
||||||
|
core.setFailed(`Docs version updates only run for minor release tags like v0.35.0. Received: ${releaseTag}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const docsVersion = minorRelease[1];
|
||||||
|
const { owner, repo } = context.repo;
|
||||||
|
const targetRepo = `${owner}/${repo}`;
|
||||||
|
const releaseUrl = `https://github.com/${targetRepo}/releases/tag/${releaseTag}`;
|
||||||
|
const title = `Update Docker Compose examples to ${docsVersion}`;
|
||||||
|
const bodyLines = [
|
||||||
|
`A new Zerobyte release was published: ${releaseTag}`,
|
||||||
|
"",
|
||||||
|
`Release: ${releaseUrl}`,
|
||||||
|
"",
|
||||||
|
"Please create a pull request that updates Docker Compose documentation examples to use:",
|
||||||
|
"",
|
||||||
|
"```yaml",
|
||||||
|
`image: ghcr.io/nicotsx/zerobyte:${docsVersion}`,
|
||||||
|
"```",
|
||||||
|
"",
|
||||||
|
"Scope:",
|
||||||
|
"",
|
||||||
|
"- Update Docker image tags in `README.md`.",
|
||||||
|
"- Update Docker image tags in `apps/docs/`.",
|
||||||
|
"- Only update Zerobyte image versions in Docker Compose examples.",
|
||||||
|
"- Do not change unrelated prose, formatting, or code.",
|
||||||
|
"",
|
||||||
|
"Verification:",
|
||||||
|
"",
|
||||||
|
"- Search for stale `ghcr.io/nicotsx/zerobyte:v...` references in `README.md` and `apps/docs/`.",
|
||||||
|
"- Run any formatting or documentation checks that are appropriate for the touched files.",
|
||||||
|
];
|
||||||
|
|
||||||
|
const issue = await github.rest.issues.create({
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
title,
|
||||||
|
body: bodyLines.join("\n"),
|
||||||
|
});
|
||||||
|
|
||||||
|
await github.rest.issues.update({
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
issue_number: issue.data.number,
|
||||||
|
body: [
|
||||||
|
...bodyLines,
|
||||||
|
"",
|
||||||
|
"Pull request requirement:",
|
||||||
|
"",
|
||||||
|
`- Include \`Closes #${issue.data.number}\` in the pull request body.`,
|
||||||
|
].join("\n"),
|
||||||
|
});
|
||||||
|
|
||||||
|
await github.request("POST /repos/{owner}/{repo}/issues/{issue_number}/assignees", {
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
issue_number: issue.data.number,
|
||||||
|
assignees: ["copilot-swe-agent[bot]"],
|
||||||
|
agent_assignment: {
|
||||||
|
target_repo: targetRepo,
|
||||||
|
base_branch: baseBranch,
|
||||||
|
custom_instructions: "Create a focused documentation-only PR for the release version update.",
|
||||||
|
custom_agent: "",
|
||||||
|
model: "",
|
||||||
|
},
|
||||||
|
headers: {
|
||||||
|
accept: "application/vnd.github+json",
|
||||||
|
"X-GitHub-Api-Version": "2022-11-28",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
env:
|
||||||
|
RELEASE_TAG: ${{ inputs.release_tag }}
|
||||||
|
BASE_BRANCH: ${{ inputs.base_branch }}
|
||||||
|
COPILOT_ASSIGNMENT_TOKEN: ${{ secrets.COPILOT_ASSIGNMENT_TOKEN }}
|
||||||
41
.github/workflows/scorecard.yml
vendored
Normal file
41
.github/workflows/scorecard.yml
vendored
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
name: Scorecard analysis
|
||||||
|
on:
|
||||||
|
branch_protection_rule:
|
||||||
|
push:
|
||||||
|
branches: [ "main" ]
|
||||||
|
|
||||||
|
permissions: read-all
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
analysis:
|
||||||
|
name: Scorecard analysis
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.event.repository.default_branch == github.ref_name || github.event_name == 'pull_request'
|
||||||
|
permissions:
|
||||||
|
security-events: write
|
||||||
|
id-token: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: Run analysis
|
||||||
|
uses: ossf/scorecard-action@f49aabe0b5af0936a0987cfb85d86b75731b0186
|
||||||
|
with:
|
||||||
|
results_file: results.sarif
|
||||||
|
results_format: sarif
|
||||||
|
publish_results: true
|
||||||
|
|
||||||
|
- name: Upload artifact
|
||||||
|
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1
|
||||||
|
with:
|
||||||
|
name: SARIF file
|
||||||
|
path: results.sarif
|
||||||
|
retention-days: 5
|
||||||
|
|
||||||
|
- name: Upload to code-scanning
|
||||||
|
uses: github/codeql-action/upload-sarif@9e0d7b8d25671d64c341c19c0152d693099fb5ba # v4
|
||||||
|
with:
|
||||||
|
sarif_file: results.sarif
|
||||||
16
.gitignore
vendored
16
.gitignore
vendored
|
|
@ -15,7 +15,7 @@ notes.md
|
||||||
smb-password.txt
|
smb-password.txt
|
||||||
cache.db
|
cache.db
|
||||||
|
|
||||||
data/
|
/data
|
||||||
|
|
||||||
.env*
|
.env*
|
||||||
!.env.example
|
!.env.example
|
||||||
|
|
@ -28,11 +28,25 @@ node_modules/
|
||||||
/blob-report/
|
/blob-report/
|
||||||
/playwright/.cache/
|
/playwright/.cache/
|
||||||
/playwright/.auth/
|
/playwright/.auth/
|
||||||
|
/playwright/*.pass
|
||||||
|
/playwright/tinyauth/app-data/
|
||||||
|
/playwright/tinyauth/caddy-data/
|
||||||
|
|
||||||
playwright/.auth
|
playwright/.auth
|
||||||
playwright/temp
|
playwright/temp
|
||||||
|
playwright/data
|
||||||
|
|
||||||
.idea/
|
.idea/
|
||||||
|
.deepsec/
|
||||||
|
.codex/
|
||||||
|
|
||||||
# OpenAPI error logs
|
# OpenAPI error logs
|
||||||
openapi-ts-error-*.log
|
openapi-ts-error-*.log
|
||||||
|
.output
|
||||||
|
tmp/
|
||||||
|
qa-output
|
||||||
|
|
||||||
|
.worktrees/
|
||||||
|
.turbo
|
||||||
|
.superset
|
||||||
|
.fallow
|
||||||
|
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
{
|
|
||||||
"$schema": "./node_modules/oxfmt/configuration_schema.json",
|
|
||||||
"printWidth": 120,
|
|
||||||
"useTabs": true,
|
|
||||||
"endOfLine": "lf"
|
|
||||||
}
|
|
||||||
152
.oxlintrc.json
152
.oxlintrc.json
|
|
@ -1,152 +0,0 @@
|
||||||
{
|
|
||||||
"$schema": "./node_modules/oxlint/configuration_schema.json",
|
|
||||||
"plugins": ["eslint", "unicorn", "typescript", "oxc", "import", "react", "react-perf", "node", "jsx-a11y"],
|
|
||||||
"categories": {},
|
|
||||||
"rules": {
|
|
||||||
"constructor-super": "warn",
|
|
||||||
"for-direction": "warn",
|
|
||||||
"no-async-promise-executor": "warn",
|
|
||||||
"no-caller": "warn",
|
|
||||||
"no-class-assign": "warn",
|
|
||||||
"no-compare-neg-zero": "warn",
|
|
||||||
"no-cond-assign": "warn",
|
|
||||||
"no-const-assign": "warn",
|
|
||||||
"no-constant-binary-expression": "warn",
|
|
||||||
"no-constant-condition": "warn",
|
|
||||||
"no-control-regex": "warn",
|
|
||||||
"no-debugger": "warn",
|
|
||||||
"no-delete-var": "warn",
|
|
||||||
"no-dupe-class-members": "warn",
|
|
||||||
"no-dupe-else-if": "warn",
|
|
||||||
"no-dupe-keys": "warn",
|
|
||||||
"no-duplicate-case": "warn",
|
|
||||||
"no-empty-character-class": "warn",
|
|
||||||
"no-empty-pattern": "warn",
|
|
||||||
"no-empty-static-block": "warn",
|
|
||||||
"no-eval": "warn",
|
|
||||||
"no-ex-assign": "warn",
|
|
||||||
"no-extra-boolean-cast": "warn",
|
|
||||||
"no-func-assign": "warn",
|
|
||||||
"no-global-assign": "warn",
|
|
||||||
"no-import-assign": "warn",
|
|
||||||
"no-invalid-regexp": "warn",
|
|
||||||
"no-irregular-whitespace": "warn",
|
|
||||||
"no-loss-of-precision": "warn",
|
|
||||||
"no-new-native-nonconstructor": "warn",
|
|
||||||
"no-nonoctal-decimal-escape": "warn",
|
|
||||||
"no-obj-calls": "warn",
|
|
||||||
"no-self-assign": "warn",
|
|
||||||
"no-setter-return": "warn",
|
|
||||||
"no-shadow-restricted-names": "warn",
|
|
||||||
"no-sparse-arrays": "warn",
|
|
||||||
"no-this-before-super": "warn",
|
|
||||||
"no-unassigned-vars": "warn",
|
|
||||||
"no-unsafe-finally": "warn",
|
|
||||||
"no-unsafe-negation": "warn",
|
|
||||||
"no-unsafe-optional-chaining": "warn",
|
|
||||||
"no-unused-expressions": "warn",
|
|
||||||
"no-unused-labels": "warn",
|
|
||||||
"no-unused-private-class-members": "warn",
|
|
||||||
"no-unused-vars": [
|
|
||||||
"warn",
|
|
||||||
{
|
|
||||||
"caughtErrorsIgnorePattern": "^_",
|
|
||||||
"argsIgnorePattern": "^_"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"no-useless-backreference": "warn",
|
|
||||||
"no-useless-catch": "warn",
|
|
||||||
"no-useless-escape": "warn",
|
|
||||||
"no-useless-rename": "warn",
|
|
||||||
"no-with": "warn",
|
|
||||||
"require-yield": "warn",
|
|
||||||
"use-isnan": "warn",
|
|
||||||
"valid-typeof": "warn",
|
|
||||||
"oxc/bad-array-method-on-arguments": "warn",
|
|
||||||
"oxc/bad-char-at-comparison": "warn",
|
|
||||||
"oxc/bad-comparison-sequence": "warn",
|
|
||||||
"oxc/bad-min-max-func": "warn",
|
|
||||||
"oxc/bad-object-literal-comparison": "warn",
|
|
||||||
"oxc/bad-replace-all-arg": "warn",
|
|
||||||
"oxc/const-comparisons": "warn",
|
|
||||||
"oxc/double-comparisons": "warn",
|
|
||||||
"oxc/erasing-op": "warn",
|
|
||||||
"oxc/missing-throw": "warn",
|
|
||||||
"oxc/number-arg-out-of-range": "warn",
|
|
||||||
"oxc/only-used-in-recursion": "warn",
|
|
||||||
"oxc/uninvoked-array-callback": "warn",
|
|
||||||
"typescript/await-thenable": "warn",
|
|
||||||
"typescript/no-array-delete": "warn",
|
|
||||||
"typescript/no-base-to-string": "warn",
|
|
||||||
"typescript/no-duplicate-enum-values": "warn",
|
|
||||||
"typescript/no-duplicate-type-constituents": "warn",
|
|
||||||
"typescript/no-extra-non-null-assertion": "warn",
|
|
||||||
"typescript/no-floating-promises": "warn",
|
|
||||||
"typescript/no-for-in-array": "warn",
|
|
||||||
"typescript/no-implied-eval": "warn",
|
|
||||||
"typescript/no-meaningless-void-operator": "warn",
|
|
||||||
"typescript/no-misused-new": "warn",
|
|
||||||
"typescript/no-misused-spread": "warn",
|
|
||||||
"typescript/no-non-null-asserted-optional-chain": "warn",
|
|
||||||
"typescript/no-redundant-type-constituents": "warn",
|
|
||||||
"typescript/no-this-alias": "warn",
|
|
||||||
"typescript/no-unnecessary-parameter-property-assignment": "warn",
|
|
||||||
"typescript/no-unsafe-declaration-merging": "warn",
|
|
||||||
"typescript/no-unsafe-unary-minus": "warn",
|
|
||||||
"typescript/no-useless-empty-export": "warn",
|
|
||||||
"typescript/no-wrapper-object-types": "warn",
|
|
||||||
"typescript/prefer-as-const": "warn",
|
|
||||||
"typescript/require-array-sort-compare": "warn",
|
|
||||||
"typescript/restrict-template-expressions": "warn",
|
|
||||||
"typescript/triple-slash-reference": "warn",
|
|
||||||
"typescript/unbound-method": "warn",
|
|
||||||
"unicorn/no-await-in-promise-methods": "warn",
|
|
||||||
"unicorn/no-empty-file": "warn",
|
|
||||||
"unicorn/no-invalid-fetch-options": "warn",
|
|
||||||
"unicorn/no-invalid-remove-event-listener": "warn",
|
|
||||||
"unicorn/no-new-array": "warn",
|
|
||||||
"unicorn/no-single-promise-in-promise-methods": "warn",
|
|
||||||
"unicorn/no-thenable": "warn",
|
|
||||||
"unicorn/no-unnecessary-await": "warn",
|
|
||||||
"unicorn/no-useless-fallback-in-spread": "warn",
|
|
||||||
"unicorn/no-useless-length-check": "warn",
|
|
||||||
"unicorn/no-useless-spread": "warn",
|
|
||||||
"unicorn/prefer-set-size": "warn",
|
|
||||||
"unicorn/prefer-string-starts-ends-with": "warn",
|
|
||||||
"import/no-cycle": "error",
|
|
||||||
"eslint/no-console": ["warn", { "allow": ["warn", "error", "info"] }]
|
|
||||||
},
|
|
||||||
"settings": {
|
|
||||||
"jsx-a11y": {
|
|
||||||
"polymorphicPropName": null,
|
|
||||||
"components": {},
|
|
||||||
"attributes": {}
|
|
||||||
},
|
|
||||||
"next": {
|
|
||||||
"rootDir": []
|
|
||||||
},
|
|
||||||
"react": {
|
|
||||||
"formComponents": [],
|
|
||||||
"linkComponents": [],
|
|
||||||
"version": null
|
|
||||||
},
|
|
||||||
"jsdoc": {
|
|
||||||
"ignorePrivate": false,
|
|
||||||
"ignoreInternal": false,
|
|
||||||
"ignoreReplacesDocs": true,
|
|
||||||
"overrideReplacesDocs": true,
|
|
||||||
"augmentsExtendsReplacesDocs": false,
|
|
||||||
"implementsReplacesDocs": false,
|
|
||||||
"exemptDestructuredRootsFromChecks": false,
|
|
||||||
"tagNamePreference": {}
|
|
||||||
},
|
|
||||||
"vitest": {
|
|
||||||
"typecheck": false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"env": {
|
|
||||||
"builtin": true
|
|
||||||
},
|
|
||||||
"globals": {},
|
|
||||||
"ignorePatterns": ["**/api-client/**"]
|
|
||||||
}
|
|
||||||
1
.vite-hooks/pre-commit
Executable file
1
.vite-hooks/pre-commit
Executable file
|
|
@ -0,0 +1 @@
|
||||||
|
vp staged
|
||||||
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"editor.defaultFormatter": "oxc.oxc-vscode"
|
||||||
|
}
|
||||||
29
AGENTS.md
29
AGENTS.md
|
|
@ -1,14 +1,30 @@
|
||||||
# AGENTS.md
|
|
||||||
|
|
||||||
## Important instructions
|
## Important instructions
|
||||||
|
|
||||||
- Never create migration files manually. Always use the provided command to generate migrations
|
- Never create migration files manually. Always use the provided command to generate migrations
|
||||||
- If you realize an automated migration is incorrect, make sure to remove all the associated entries from the `_journal.json` and the newly created files located in `app/drizzle/` before re-generating the migration
|
- If you realize an automated migration is incorrect, make sure to remove all the associated entries from the `_journal.json` and the newly created files located in `app/drizzle/` before re-generating the migration
|
||||||
|
- The dev server runs through Portless. Start it with `bun run dev`, then use `portless get zerobyte` to get the current worktree-specific URL. Do not assume a fixed port like `3000` or `4096`. Username is `admin` and password is `password`
|
||||||
|
- The repo is https://github.com/nicotsx/zerobyte
|
||||||
|
- If you need to run a specific restic command on a repository, you can open and use the dev panel with `Meta+Shift+D`
|
||||||
|
|
||||||
## Project Overview
|
## Project Overview
|
||||||
|
|
||||||
Zerobyte is a backup automation tool built on top of Restic that provides a web interface for scheduling, managing, and monitoring encrypted backups. It supports multiple volume backends (NFS, SMB, WebDAV, SFTP, local directories) and repository backends (S3, Azure, GCS, local, and rclone-based storage).
|
Zerobyte is a backup automation tool built on top of Restic that provides a web interface for scheduling, managing, and monitoring encrypted backups. It supports multiple volume backends (NFS, SMB, WebDAV, SFTP, local directories) and repository backends (S3, Azure, GCS, local, and rclone-based storage).
|
||||||
|
|
||||||
|
### Development Server
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Start the dev server through Portless
|
||||||
|
bun run dev
|
||||||
|
|
||||||
|
# Get the current app URL for this worktree
|
||||||
|
portless get zerobyte
|
||||||
|
|
||||||
|
# Inspect active Portless routes if needed
|
||||||
|
portless list
|
||||||
|
```
|
||||||
|
|
||||||
|
Portless applies git worktree prefixes automatically, so linked worktrees may return URLs like `https://branch-name.zerobyte.localhost`. Use the Portless URL for browser testing and manual verification.
|
||||||
|
|
||||||
### Type Checking
|
### Type Checking
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
@ -23,7 +39,7 @@ bun run tsc
|
||||||
bun run test
|
bun run test
|
||||||
|
|
||||||
# Run a specific test file
|
# Run a specific test file
|
||||||
bunx dotenv-cli -e .env.test -- bun test --preload ./app/test/setup.ts path/to/test.ts
|
bunx dotenv-cli -e .env.test -- bunx --bun vitest run --project server path/to/test.ts
|
||||||
```
|
```
|
||||||
|
|
||||||
### Building
|
### Building
|
||||||
|
|
@ -54,8 +70,13 @@ bun run gen:api-client
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Format
|
# Format
|
||||||
bunx oxfmt format --write <path>
|
vp fmt <path> --write
|
||||||
|
|
||||||
# Lint
|
# Lint
|
||||||
bun run lint
|
bun run lint
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Invalidation
|
||||||
|
|
||||||
|
The frontend has an automatic invalidation setup which runs after every mutation.
|
||||||
|
Do not implement any invalidation logic in the frontend.
|
||||||
|
|
|
||||||
56
Dockerfile
56
Dockerfile
|
|
@ -1,10 +1,8 @@
|
||||||
ARG BUN_VERSION="1.3.8"
|
FROM oven/bun:1.3.14-alpine@sha256:5acc90a93e91ff07bf72aa90a7c9f0fa189765aec90b47bdbf2152d2196383c0 AS base
|
||||||
|
|
||||||
FROM oven/bun:${BUN_VERSION}-alpine AS base
|
|
||||||
|
|
||||||
ARG RESTIC_VERSION="0.18.1"
|
ARG RESTIC_VERSION="0.18.1"
|
||||||
ARG RCLONE_VERSION="1.72.1"
|
ARG RCLONE_VERSION="1.74.2"
|
||||||
ARG SHOUTRRR_VERSION="0.13.1"
|
ARG SHOUTRRR_VERSION="0.15.1"
|
||||||
|
|
||||||
ENV VITE_RESTIC_VERSION=${RESTIC_VERSION} \
|
ENV VITE_RESTIC_VERSION=${RESTIC_VERSION} \
|
||||||
VITE_RCLONE_VERSION=${RCLONE_VERSION} \
|
VITE_RCLONE_VERSION=${RCLONE_VERSION} \
|
||||||
|
|
@ -12,7 +10,7 @@ ENV VITE_RESTIC_VERSION=${RESTIC_VERSION} \
|
||||||
|
|
||||||
RUN apk update --no-cache && \
|
RUN apk update --no-cache && \
|
||||||
apk upgrade --no-cache && \
|
apk upgrade --no-cache && \
|
||||||
apk add --no-cache davfs2=1.6.1-r2 openssh-client fuse3 sshfs tini nfs-utils cifs-utils util-linux
|
apk add --no-cache acl attr cifs-utils davfs2=1.6.1-r2 openssh-client fuse3 sshfs tini tzdata
|
||||||
|
|
||||||
ENTRYPOINT ["/sbin/tini", "-s", "--"]
|
ENTRYPOINT ["/sbin/tini", "-s", "--"]
|
||||||
|
|
||||||
|
|
@ -31,21 +29,30 @@ RUN apk add --no-cache curl bzip2 unzip tar
|
||||||
|
|
||||||
RUN echo "Building for ${TARGETARCH}"
|
RUN echo "Building for ${TARGETARCH}"
|
||||||
RUN if [ "${TARGETARCH}" = "arm64" ]; then \
|
RUN if [ "${TARGETARCH}" = "arm64" ]; then \
|
||||||
curl -L -o restic.bz2 "https://github.com/restic/restic/releases/download/v${RESTIC_VERSION}/restic_${RESTIC_VERSION}_linux_arm64.bz2"; \
|
curl -fL -o restic.bz2 "https://github.com/restic/restic/releases/download/v${RESTIC_VERSION}/restic_${RESTIC_VERSION}_linux_arm64.bz2"; \
|
||||||
curl -L -o rclone.zip "https://github.com/rclone/rclone/releases/download/v${RCLONE_VERSION}/rclone-v${RCLONE_VERSION}-linux-arm64.zip"; \
|
curl -fL -o rclone.zip "https://github.com/rclone/rclone/releases/download/v${RCLONE_VERSION}/rclone-v${RCLONE_VERSION}-linux-arm64.zip"; \
|
||||||
unzip rclone.zip; \
|
unzip rclone.zip; \
|
||||||
curl -L -o shoutrrr.tar.gz "https://github.com/nicholas-fedor/shoutrrr/releases/download/v${SHOUTRRR_VERSION}/shoutrrr_linux_arm64v8_${SHOUTRRR_VERSION}.tar.gz"; \
|
curl -fL -o shoutrrr.tar.gz "https://github.com/nicholas-fedor/shoutrrr/releases/download/v${SHOUTRRR_VERSION}/shoutrrr_linux_arm64v8_${SHOUTRRR_VERSION}.tar.gz"; \
|
||||||
elif [ "${TARGETARCH}" = "amd64" ]; then \
|
elif [ "${TARGETARCH}" = "amd64" ]; then \
|
||||||
curl -L -o restic.bz2 "https://github.com/restic/restic/releases/download/v${RESTIC_VERSION}/restic_${RESTIC_VERSION}_linux_amd64.bz2"; \
|
curl -fL -o restic.bz2 "https://github.com/restic/restic/releases/download/v${RESTIC_VERSION}/restic_${RESTIC_VERSION}_linux_amd64.bz2"; \
|
||||||
curl -L -o rclone.zip "https://github.com/rclone/rclone/releases/download/v${RCLONE_VERSION}/rclone-v${RCLONE_VERSION}-linux-amd64.zip"; \
|
curl -fL -o rclone.zip "https://github.com/rclone/rclone/releases/download/v${RCLONE_VERSION}/rclone-v${RCLONE_VERSION}-linux-amd64.zip"; \
|
||||||
unzip rclone.zip; \
|
unzip rclone.zip; \
|
||||||
curl -L -o shoutrrr.tar.gz "https://github.com/nicholas-fedor/shoutrrr/releases/download/v$SHOUTRRR_VERSION/shoutrrr_linux_amd64_${SHOUTRRR_VERSION}.tar.gz"; \
|
curl -fL -o shoutrrr.tar.gz "https://github.com/nicholas-fedor/shoutrrr/releases/download/v$SHOUTRRR_VERSION/shoutrrr_linux_amd64_${SHOUTRRR_VERSION}.tar.gz"; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
RUN bzip2 -d restic.bz2 && chmod +x restic
|
RUN bzip2 -d restic.bz2 && chmod +x restic
|
||||||
RUN mv rclone-v*-linux-*/rclone /deps/rclone && chmod +x /deps/rclone
|
RUN mv rclone-v*-linux-*/rclone /deps/rclone && chmod +x /deps/rclone
|
||||||
RUN tar -xzf shoutrrr.tar.gz && chmod +x shoutrrr
|
RUN tar -xzf shoutrrr.tar.gz && chmod +x shoutrrr
|
||||||
|
|
||||||
|
# ------------------------------
|
||||||
|
# RUNTIME TOOLS
|
||||||
|
# ------------------------------
|
||||||
|
FROM base AS runtime-tools
|
||||||
|
|
||||||
|
COPY --from=deps /deps/restic /usr/local/bin/restic
|
||||||
|
COPY --from=deps /deps/rclone /usr/local/bin/rclone
|
||||||
|
COPY --from=deps /deps/shoutrrr /usr/local/bin/shoutrrr
|
||||||
|
|
||||||
# ------------------------------
|
# ------------------------------
|
||||||
# DEVELOPMENT
|
# DEVELOPMENT
|
||||||
# ------------------------------
|
# ------------------------------
|
||||||
|
|
@ -63,12 +70,16 @@ COPY --from=deps /deps/rclone /usr/local/bin/rclone
|
||||||
COPY --from=deps /deps/shoutrrr /usr/local/bin/shoutrrr
|
COPY --from=deps /deps/shoutrrr /usr/local/bin/shoutrrr
|
||||||
|
|
||||||
COPY ./package.json ./bun.lock ./
|
COPY ./package.json ./bun.lock ./
|
||||||
|
COPY ./packages/core/package.json ./packages/core/package.json
|
||||||
|
COPY ./packages/contracts/package.json ./packages/contracts/package.json
|
||||||
|
COPY ./apps/agent/package.json ./apps/agent/package.json
|
||||||
|
COPY ./apps/docs/package.json ./apps/docs/package.json
|
||||||
|
|
||||||
RUN bun install --frozen-lockfile --ignore-scripts
|
RUN VITE_GIT_HOOKS=0 bun install --frozen-lockfile --ignore-scripts
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
EXPOSE 4096
|
EXPOSE 3000
|
||||||
|
|
||||||
CMD ["bun", "run", "dev"]
|
CMD ["bun", "run", "dev"]
|
||||||
|
|
||||||
|
|
@ -79,32 +90,38 @@ FROM base AS builder
|
||||||
|
|
||||||
ARG APP_VERSION=dev
|
ARG APP_VERSION=dev
|
||||||
ENV VITE_APP_VERSION=${APP_VERSION}
|
ENV VITE_APP_VERSION=${APP_VERSION}
|
||||||
|
ENV PORT=4096
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY ./package.json ./bun.lock ./
|
COPY ./package.json ./bun.lock ./
|
||||||
RUN bun install --frozen-lockfile
|
COPY ./packages/core/package.json ./packages/core/package.json
|
||||||
|
COPY ./packages/contracts/package.json ./packages/contracts/package.json
|
||||||
|
COPY ./apps/agent/package.json ./apps/agent/package.json
|
||||||
|
COPY ./apps/docs/package.json ./apps/docs/package.json
|
||||||
|
|
||||||
|
RUN VITE_GIT_HOOKS=0 bun install --frozen-lockfile
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
RUN bun run build
|
RUN bun run build
|
||||||
|
RUN bun build apps/agent/src/index.ts --outfile .output/agent/index.mjs --target bun
|
||||||
|
|
||||||
FROM base AS production
|
FROM base AS production
|
||||||
|
|
||||||
ARG APP_VERSION=dev
|
ARG APP_VERSION=dev
|
||||||
ENV APP_VERSION=${APP_VERSION}
|
ENV APP_VERSION=${APP_VERSION}
|
||||||
ENV NODE_ENV="production"
|
ENV NODE_ENV="production"
|
||||||
|
ENV PORT=4096
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY --from=builder /app/package.json ./
|
COPY --from=builder /app/package.json ./
|
||||||
RUN bun install --production --frozen-lockfile && rm -rf $HOME/.bun/install/cache
|
|
||||||
|
|
||||||
COPY --from=deps /deps/restic /usr/local/bin/restic
|
COPY --from=deps /deps/restic /usr/local/bin/restic
|
||||||
COPY --from=deps /deps/rclone /usr/local/bin/rclone
|
COPY --from=deps /deps/rclone /usr/local/bin/rclone
|
||||||
COPY --from=deps /deps/shoutrrr /usr/local/bin/shoutrrr
|
COPY --from=deps /deps/shoutrrr /usr/local/bin/shoutrrr
|
||||||
COPY --from=builder /app/dist/client ./dist/client
|
COPY --from=builder /app/.output ./.output
|
||||||
COPY --from=builder /app/dist/server ./dist/server
|
|
||||||
COPY --from=builder /app/app/drizzle ./assets/migrations
|
COPY --from=builder /app/app/drizzle ./assets/migrations
|
||||||
|
|
||||||
# Include third-party licenses and attribution
|
# Include third-party licenses and attribution
|
||||||
|
|
@ -114,5 +131,4 @@ COPY ./LICENSE ./LICENSE.md
|
||||||
|
|
||||||
EXPOSE 4096
|
EXPOSE 4096
|
||||||
|
|
||||||
CMD ["bun", "run", "start"]
|
CMD ["bun", ".output/server/index.mjs"]
|
||||||
|
|
||||||
|
|
|
||||||
152
README.md
152
README.md
|
|
@ -15,23 +15,33 @@
|
||||||
</figure>
|
</figure>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
#### Join the community
|
||||||
|
|
||||||
|
[](https://discord.gg/XjgVyXrcEH)
|
||||||
|
|
||||||
> [!WARNING]
|
> [!WARNING]
|
||||||
> Zerobyte is still in version 0.x.x and is subject to major changes from version to version. I am developing the core features and collecting feedbacks. Expect bugs! Please open issues or feature requests
|
> Zerobyte is still in version 0.x.x and is subject to major changes from version to version. I am developing the core features and collecting feedback. Please open issues for bugs or feature requests.
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://www.buymeacoffee.com/nicotsx" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
|
<a href="https://www.buymeacoffee.com/nicotsx" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
## Intro
|
## Introduction
|
||||||
|
|
||||||
Zerobyte is a backup automation tool that helps you save your data across multiple storage backends. Built on top of Restic, it provides an modern web interface to schedule, manage, and monitor encrypted backups of your remote storage.
|
Zerobyte is a backup automation tool that helps you save your data across multiple storage backends. Built on top of Restic, it provides an modern web interface to schedule, manage, and monitor encrypted backups of your remote storage.
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
The official documentation website is available at [zerobyte.app](https://zerobyte.app).
|
||||||
|
|
||||||
|
It contains up-to-date setup guides, configuration reference, and usage documentation for running Zerobyte in production.
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
- **Automated backups** with encryption, compression and retention policies powered by Restic
|
- **Automated backups** with encryption, compression, and retention policies, powered by Restic
|
||||||
- **Flexible scheduling** For automated backup jobs with fine-grained retention policies
|
- **Flexible scheduling** for automated backup jobs with fine-grained retention policies
|
||||||
- **End-to-end encryption** ensuring your data is always protected
|
- **End-to-end encryption** will ensure your data is always protected
|
||||||
- **Multi-protocol support**: Backup from NFS, SMB, WebDAV, SFTP, or local directories
|
- **Multi-protocol support** for backup from NFS, SMB, WebDAV, SFTP, or local directories
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|
@ -40,7 +50,7 @@ In order to run Zerobyte, you need to have Docker and Docker Compose installed o
|
||||||
```yaml
|
```yaml
|
||||||
services:
|
services:
|
||||||
zerobyte:
|
zerobyte:
|
||||||
image: ghcr.io/nicotsx/zerobyte:v0.24
|
image: ghcr.io/nicotsx/zerobyte:v0.38
|
||||||
container_name: zerobyte
|
container_name: zerobyte
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
cap_add:
|
cap_add:
|
||||||
|
|
@ -50,7 +60,7 @@ services:
|
||||||
devices:
|
devices:
|
||||||
- /dev/fuse:/dev/fuse
|
- /dev/fuse:/dev/fuse
|
||||||
environment:
|
environment:
|
||||||
- TZ=Europe/Paris # Set your timezone here
|
- TZ=Europe/Zurich # Set your timezone here
|
||||||
- BASE_URL=http://localhost:4096 # URL you will use to access Zerobyte
|
- BASE_URL=http://localhost:4096 # URL you will use to access Zerobyte
|
||||||
- APP_SECRET=94bad46...c66e25d5c2b # Generate your own secret with `openssl rand -hex 32`
|
- APP_SECRET=94bad46...c66e25d5c2b # Generate your own secret with `openssl rand -hex 32`
|
||||||
volumes:
|
volumes:
|
||||||
|
|
@ -59,10 +69,10 @@ services:
|
||||||
```
|
```
|
||||||
|
|
||||||
> [!WARNING]
|
> [!WARNING]
|
||||||
> It is highly discouraged to run Zerobyte on a server that is accessible from the internet (VPS or home server with port forwarding) If you do, make sure to change the port mapping to "127.0.0.1:4096:4096" and use a secure tunnel (SSH tunnel, Cloudflare Tunnel, etc.) with authentication.
|
> It is highly discouraged to run Zerobyte on a server that is accessible from the internet (VPS or home server with port forwarding). If you do, make sure to change the port mapping to "127.0.0.1:4096:4096" and use a secure tunnel (SSH tunnel, Cloudflare Tunnel, etc.) with authentication.
|
||||||
|
|
||||||
> [!WARNING]
|
> [!WARNING]
|
||||||
> Do not try to point `/var/lib/zerobyte` on a network share. You will face permission issues and strong performance degradation.
|
> Do not try to point `/var/lib/zerobyte` to a network share. You will face permission issues and strong performance degradation.
|
||||||
|
|
||||||
> [!NOTE]
|
> [!NOTE]
|
||||||
> **TrueNAS Users:** The host path `/var/lib` is ephemeral on TrueNAS and will be reset during system upgrades. Instead of using `/var/lib/zerobyte:/var/lib/zerobyte`, create a dedicated ZFS dataset (e.g., `tank/docker/zerobyte`) and mount it instead:
|
> **TrueNAS Users:** The host path `/var/lib` is ephemeral on TrueNAS and will be reset during system upgrades. Instead of using `/var/lib/zerobyte:/var/lib/zerobyte`, create a dedicated ZFS dataset (e.g., `tank/docker/zerobyte`) and mount it instead:
|
||||||
|
|
@ -87,43 +97,72 @@ Once the container is running, you can access the web interface at `http://<your
|
||||||
|
|
||||||
Zerobyte can be customized using environment variables. Below are the available options:
|
Zerobyte can be customized using environment variables. Below are the available options:
|
||||||
|
|
||||||
### Environment Variables
|
### Environment variables
|
||||||
|
|
||||||
| Variable | Description | Default |
|
| Variable | Description | Default |
|
||||||
| :-------------------- | :---------------------------------------------------------------------------------------------------------------------------------------- | :--------- |
|
| :------------------------ | :---------------------------------------------------------------------------------------------------------------------------------------- | :--------------------- |
|
||||||
| `BASE_URL` | **Required.** The base URL of your Zerobyte instance (e.g., `https://zerobyte.example.com`). See [Authentication](#authentication) below. | (none) |
|
| `BASE_URL` | **Required.** The base URL of your Zerobyte instance (e.g., `https://zerobyte.example.com`). See [Authentication](#authentication) below. | (none) |
|
||||||
| `APP_SECRET` | **Required.** A random secret key (32+ chars) used to encrypt sensitive data in the database. Generate with `openssl rand -hex 32`. | (none) |
|
| `APP_SECRET` | **Required.** A random secret key (32+ chars) used to encrypt sensitive data in the database. Generate with `openssl rand -hex 32`. | (none) |
|
||||||
|
| `APP_SECRET_FILE` | Path to a file containing `APP_SECRET`, useful with Docker or Kubernetes secrets. Mutually exclusive with `APP_SECRET`. | (none) |
|
||||||
| `PORT` | The port the web interface and API will listen on. | `4096` |
|
| `PORT` | The port the web interface and API will listen on. | `4096` |
|
||||||
| `RESTIC_HOSTNAME` | The hostname used by Restic when creating snapshots. Automatically detected if a custom hostname is set in Docker. | `zerobyte` |
|
| `RESTIC_HOSTNAME` | The hostname used by Restic when creating snapshots. Automatically detected if a custom hostname is set in Docker. | `zerobyte` |
|
||||||
| `TZ` | Timezone for the container (e.g., `Europe/Paris`). **Crucial for accurate backup scheduling.** | `UTC` |
|
| `TZ` | Timezone for the container (e.g., `Europe/Zurich`). **Crucial for accurate backup scheduling.** | `UTC` |
|
||||||
|
| `TRUST_PROXY` | When `true`, trust an existing `X-Forwarded-For` header from your reverse proxy. Leave `false` for direct deployments. | `false` |
|
||||||
| `TRUSTED_ORIGINS` | Comma-separated list of extra trusted origins for CORS (e.g., `http://localhost:3000,http://example.com`). | (none) |
|
| `TRUSTED_ORIGINS` | Comma-separated list of extra trusted origins for CORS (e.g., `http://localhost:3000,http://example.com`). | (none) |
|
||||||
|
| `WEBHOOK_ALLOWED_ORIGINS` | Comma-separated list of HTTP origins allowed for backup webhooks and outbound HTTP notification destinations. | (none) |
|
||||||
|
| `WEBHOOK_TIMEOUT` | Timeout for backup webhook requests in seconds. | `60` |
|
||||||
| `LOG_LEVEL` | Logging verbosity. Options: `debug`, `info`, `warn`, `error`. | `info` |
|
| `LOG_LEVEL` | Logging verbosity. Options: `debug`, `info`, `warn`, `error`. | `info` |
|
||||||
| `SERVER_IDLE_TIMEOUT` | Idle timeout for the server in seconds. | `60` |
|
| `SERVER_IDLE_TIMEOUT` | Idle timeout for the server in seconds. | `60` |
|
||||||
|
| `RCLONE_CONFIG_DIR` | Path to the directory containing `rclone.conf` inside the container. Change this if running as a non-root user. | `/root/.config/rclone` |
|
||||||
|
| `PROVISIONING_PATH` | Path to a JSON file with operator-managed repositories and volumes to sync at startup. | (none) |
|
||||||
|
|
||||||
### Secret References
|
### Webhook and notification network policy
|
||||||
|
|
||||||
For enhanced security, Zerobyte supports dynamic secret resolution for sensitive fields (like passwords, access keys, etc.) in volume and repository configurations. Instead of storing the encrypted secret in the database, you can use one of the following prefixes:
|
Backup webhooks and outbound notification destinations that can target arbitrary network hosts are restricted by `WEBHOOK_ALLOWED_ORIGINS`.
|
||||||
|
|
||||||
- `env://VAR_NAME`: Reads the secret from the environment variable `VAR_NAME`.
|
The allowlist matches exact origins only: scheme, host, and port must match. Paths are ignored, so `https://hooks.example.com/backups` allows any path on `https://hooks.example.com`, but it does not allow `http://hooks.example.com`, `https://hooks.example.com:8443`, or `https://other.example.com`.
|
||||||
- `file://SECRET_NAME`: Reads the secret from `/run/secrets/SECRET_NAME` (standard Docker Secrets path).
|
|
||||||
|
|
||||||
**Example:**
|
This policy applies to:
|
||||||
When configuring an S3 repository, you can set the Secret Access Key to `env://S3_SECRET_KEY` and then provide that variable in your `docker-compose.yml`.
|
|
||||||
|
|
||||||
### Simplified setup (No remote mounts)
|
- backup pre/post webhook URLs
|
||||||
|
- Generic HTTP notification URLs
|
||||||
|
- Gotify server URLs
|
||||||
|
- self-hosted ntfy server URLs
|
||||||
|
- custom Shoutrrr URLs that point at generic HTTP or SMTP network targets
|
||||||
|
|
||||||
If you only need to back up locally mounted folders and don't require remote share mounting capabilities, you can remove the `SYS_ADMIN` capability and FUSE device from your `docker-compose.yml`:
|
The public ntfy.sh service and fixed-provider notification services such as Slack, Discord, Pushover, and Telegram do not need `WEBHOOK_ALLOWED_ORIGINS`.
|
||||||
|
|
||||||
|
Backup webhooks do not follow redirects. Add the final destination origin to `WEBHOOK_ALLOWED_ORIGINS` and configure that final URL directly.
|
||||||
|
|
||||||
|
Webhook headers are stored as plain text and must use one `Key: Value` header per line. `WEBHOOK_TIMEOUT` controls backup pre/post webhook request timeouts; notification delivery uses the underlying provider sender behavior.
|
||||||
|
|
||||||
|
### Provisioned resources
|
||||||
|
|
||||||
|
Zerobyte can sync operator-managed repositories and volumes from a JSON file at startup. This is useful when you want credentials or connection details to live in deployment-time configuration instead of being entered through the UI.
|
||||||
|
|
||||||
|
Provisioned resources:
|
||||||
|
|
||||||
|
- appear in the normal repositories and volumes screens
|
||||||
|
- can resolve credential fields from environment variables or `/run/secrets/*` during startup sync
|
||||||
|
|
||||||
|
The complete provisioning documentation is available at [zerobyte.app/docs/guides/provisioning](https://zerobyte.app/docs/guides/provisioning).
|
||||||
|
|
||||||
|
See `examples/provisioned-resources/README.md` for a full example.
|
||||||
|
|
||||||
|
### Simplified setup (no remote mounts)
|
||||||
|
|
||||||
|
If you only need to back up locally-mounted folders and don't require remote share mounting capabilities, you can remove the `SYS_ADMIN` capability and FUSE device from your `docker-compose.yml`:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
services:
|
services:
|
||||||
zerobyte:
|
zerobyte:
|
||||||
image: ghcr.io/nicotsx/zerobyte:v0.24
|
image: ghcr.io/nicotsx/zerobyte:v0.38
|
||||||
container_name: zerobyte
|
container_name: zerobyte
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "4096:4096"
|
- "4096:4096"
|
||||||
environment:
|
environment:
|
||||||
- TZ=Europe/Paris # Set your timezone here
|
- TZ=Europe/Zurich # Set your timezone here
|
||||||
- BASE_URL=http://localhost:4096 # Change this to your actual URL (use https:// for secure cookies)
|
- BASE_URL=http://localhost:4096 # Change this to your actual URL (use https:// for secure cookies)
|
||||||
- APP_SECRET=94bad46...c66e25d5c2b # Generate your own secret with `openssl rand -hex 32`
|
- APP_SECRET=94bad46...c66e25d5c2b # Generate your own secret with `openssl rand -hex 32`
|
||||||
volumes:
|
volumes:
|
||||||
|
|
@ -135,8 +174,8 @@ services:
|
||||||
**Trade-offs:**
|
**Trade-offs:**
|
||||||
|
|
||||||
- ✅ Improved security by reducing container capabilities
|
- ✅ Improved security by reducing container capabilities
|
||||||
- ✅ Support for local directories
|
- ✅ Support for local directories as backup sources
|
||||||
- ✅ Keep support all repository types (local, S3, GCS, Azure, rclone)
|
- ✅ Support all repository types, local and remote (S3, GCS, Azure, rclone)
|
||||||
- ❌ Cannot mount NFS, SMB, WebDAV, or SFTP shares directly from Zerobyte
|
- ❌ Cannot mount NFS, SMB, WebDAV, or SFTP shares directly from Zerobyte
|
||||||
|
|
||||||
If you need remote mount capabilities, keep the original configuration with `cap_add: SYS_ADMIN` and `devices: /dev/fuse:/dev/fuse`.
|
If you need remote mount capabilities, keep the original configuration with `cap_add: SYS_ADMIN` and `devices: /dev/fuse:/dev/fuse`.
|
||||||
|
|
@ -151,12 +190,12 @@ Zerobyte supports multiple volume backends including NFS, SMB, WebDAV, SFTP, and
|
||||||
|
|
||||||
To add your first volume, navigate to the "Volumes" section in the web interface and click on "Create volume". Fill in the required details such as volume name, type, and connection settings.
|
To add your first volume, navigate to the "Volumes" section in the web interface and click on "Create volume". Fill in the required details such as volume name, type, and connection settings.
|
||||||
|
|
||||||
If you want to track a local directory on the same server where Zerobyte is running, you'll first need to mount that directory into the Zerobyte container. You can do this by adding a volume mapping in your `docker-compose.yml` file. For example, to mount `/path/to/your/directory` from the host to `/mydata` in the container, you would add the following line under the `volumes` section:
|
If you want to backup a local directory on the same host where Zerobyte is running, you'll first need to mount that directory into the Zerobyte container. You can do this by adding a volume mapping in your `docker-compose.yml` file. For example, to mount `/path/to/your/directory` from the host to `/mydata` in the container, you would add the following line under the `volumes` section:
|
||||||
|
|
||||||
```diff
|
```diff
|
||||||
services:
|
services:
|
||||||
zerobyte:
|
zerobyte:
|
||||||
image: ghcr.io/nicotsx/zerobyte:v0.24
|
image: ghcr.io/nicotsx/zerobyte:v0.38
|
||||||
container_name: zerobyte
|
container_name: zerobyte
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
cap_add:
|
cap_add:
|
||||||
|
|
@ -166,7 +205,7 @@ services:
|
||||||
devices:
|
devices:
|
||||||
- /dev/fuse:/dev/fuse
|
- /dev/fuse:/dev/fuse
|
||||||
environment:
|
environment:
|
||||||
- TZ=Europe/Paris
|
- TZ=Europe/Zurich
|
||||||
- BASE_URL=http://localhost:4096 # URL you will use to access Zerobyte
|
- BASE_URL=http://localhost:4096 # URL you will use to access Zerobyte
|
||||||
- APP_SECRET=94bad46...c66e25d5c2b # Generate your own secret with `openssl rand -hex 32`
|
- APP_SECRET=94bad46...c66e25d5c2b # Generate your own secret with `openssl rand -hex 32`
|
||||||
volumes:
|
volumes:
|
||||||
|
|
@ -184,17 +223,17 @@ docker compose up -d
|
||||||
|
|
||||||
Now, when adding a new volume in the Zerobyte web interface, you can select "Directory" as the volume type and search for your mounted path (e.g., `/mydata`) as the source path.
|
Now, when adding a new volume in the Zerobyte web interface, you can select "Directory" as the volume type and search for your mounted path (e.g., `/mydata`) as the source path.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Creating a repository
|
## Creating a repository
|
||||||
|
|
||||||
A repository is where your backups will be securely stored encrypted. Zerobyte supports multiple storage backends for your backup repositories:
|
A repository is where your backups will be securely stored encrypted. Zerobyte supports multiple storage backends for your backup repositories:
|
||||||
|
|
||||||
- **Local directories** - Store backups on local disk subfolder of `/var/lib/zerobyte/repositories/` or any other (mounted) path
|
- **Local directories**: Store backups on local disk subfolders in `/var/lib/zerobyte/repositories/` or any other (mounted) path
|
||||||
- **S3-compatible storage** - Amazon S3, MinIO, Wasabi, DigitalOcean Spaces, etc.
|
- **S3-compatible storage**: Amazon S3, MinIO, Wasabi, DigitalOcean Spaces, etc.
|
||||||
- **Google Cloud Storage** - Google's cloud storage service
|
- **Google Cloud Storage**: Google's cloud storage service
|
||||||
- **Azure Blob Storage** - Microsoft Azure storage
|
- **Azure Blob Storage**: Microsoft Azure storage
|
||||||
- **rclone remotes** - 40+ cloud storage providers via rclone (see below)
|
- **rclone remotes**: 40+ cloud storage providers via rclone (see below)
|
||||||
|
|
||||||
Repositories are optimized for storage efficiency and data integrity, leveraging Restic's deduplication and encryption features.
|
Repositories are optimized for storage efficiency and data integrity, leveraging Restic's deduplication and encryption features.
|
||||||
|
|
||||||
|
|
@ -231,7 +270,7 @@ Zerobyte can use [rclone](https://rclone.org/) to support 40+ cloud storage prov
|
||||||
```diff
|
```diff
|
||||||
services:
|
services:
|
||||||
zerobyte:
|
zerobyte:
|
||||||
image: ghcr.io/nicotsx/zerobyte:v0.24
|
image: ghcr.io/nicotsx/zerobyte:v0.38
|
||||||
container_name: zerobyte
|
container_name: zerobyte
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
cap_add:
|
cap_add:
|
||||||
|
|
@ -241,14 +280,23 @@ Zerobyte can use [rclone](https://rclone.org/) to support 40+ cloud storage prov
|
||||||
devices:
|
devices:
|
||||||
- /dev/fuse:/dev/fuse
|
- /dev/fuse:/dev/fuse
|
||||||
environment:
|
environment:
|
||||||
- TZ=Europe/Paris
|
- TZ=Europe/Zurich
|
||||||
- BASE_URL=http://localhost:4096 # URL you will use to access Zerobyte
|
- BASE_URL=http://localhost:4096 # URL you will use to access Zerobyte
|
||||||
volumes:
|
volumes:
|
||||||
- /etc/localtime:/etc/localtime:ro
|
- /etc/localtime:/etc/localtime:ro
|
||||||
- /var/lib/zerobyte:/var/lib/zerobyte
|
- /var/lib/zerobyte:/var/lib/zerobyte
|
||||||
+ - ~/.config/rclone:/root/.config/rclone
|
+ - ~/.config/rclone:/root/.config/rclone:ro
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> **Note for non-root users:** If your container runs as a different user (e.g., TrueNAS apps), mount your config to the appropriate location and set `RCLONE_CONFIG_DIR`:
|
||||||
|
>
|
||||||
|
> ```yaml
|
||||||
|
> environment:
|
||||||
|
> - RCLONE_CONFIG_DIR=/home/appuser/.config/rclone
|
||||||
|
> volumes:
|
||||||
|
> - ~/.config/rclone:/home/appuser/.config/rclone:ro
|
||||||
|
> ```
|
||||||
|
|
||||||
5. **Restart the Zerobyte container**:
|
5. **Restart the Zerobyte container**:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
@ -276,24 +324,30 @@ When creating a backup job, you can specify the following settings:
|
||||||
After configuring the backup job, save it and Zerobyte will automatically execute the backup according to the defined schedule.
|
After configuring the backup job, save it and Zerobyte will automatically execute the backup according to the defined schedule.
|
||||||
You can monitor the progress and status of your backup jobs in the "Backups" section of the web interface.
|
You can monitor the progress and status of your backup jobs in the "Backups" section of the web interface.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Restoring data
|
## Restoring data
|
||||||
|
|
||||||
Zerobyte allows you to easily restore your data from backups. To restore data, navigate to the "Backups" section and select the backup job from which you want to restore data. You can then choose a specific backup snapshot and select the files or directories you wish to restore. The data you select will be restored to their original location.
|
Zerobyte allows you to easily restore your data from backups. To restore data, navigate to the "Backups" section and select the backup job from which you want to restore data. You can then choose a specific backup snapshot and select the files or directories you wish to restore. The data you select will be restored to their original location.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Authentication
|
## Authentication
|
||||||
|
|
||||||
Zerobyte uses [better-auth](https://github.com/better-auth/better-auth) for authentication and session management. The authentication system automatically adapts to your deployment scenario:
|
Zerobyte uses [better-auth](https://github.com/better-auth/better-auth) for authentication and session management. The authentication system automatically adapts to your deployment scenario:
|
||||||
|
|
||||||
### Cookie Security
|
### Users and roles
|
||||||
|
|
||||||
|
Zerobyte does not currently provide fine-grained RBAC for backup operations. Authenticated organization members are trusted operators for repositories, volumes, backup schedules, restores, and notification destinations in their organization.
|
||||||
|
|
||||||
|
Organization roles mainly restrict organization-management and instance-management actions. For example, normal members cannot manage members, SSO settings, invitations, registration, or global users, but they can still operate backup resources. Only add users to an organization if you are comfortable with them using the storage, volume, and notification capabilities configured for the instance.
|
||||||
|
|
||||||
|
### Cookie security
|
||||||
|
|
||||||
- **IP Address/HTTP access**: Set `BASE_URL=http://192.168.1.50:4096` (or your IP). Cookies will use `Secure: false`, allowing immediate login without SSL.
|
- **IP Address/HTTP access**: Set `BASE_URL=http://192.168.1.50:4096` (or your IP). Cookies will use `Secure: false`, allowing immediate login without SSL.
|
||||||
- **Domain/HTTPS access**: Set `BASE_URL=https://zerobyte.example.com`. Cookies will automatically use `Secure: true` for protected sessions.
|
- **Domain/HTTPS access**: Set `BASE_URL=https://zerobyte.example.com`. Cookies will automatically use `Secure: true` for protected sessions.
|
||||||
|
|
||||||
### Reverse Proxy Setup
|
### Reverse proxy setup
|
||||||
|
|
||||||
If you're running Zerobyte behind a reverse proxy (Nginx, Traefik, Caddy, etc.):
|
If you're running Zerobyte behind a reverse proxy (Nginx, Traefik, Caddy, etc.):
|
||||||
|
|
||||||
|
|
@ -301,16 +355,18 @@ If you're running Zerobyte behind a reverse proxy (Nginx, Traefik, Caddy, etc.):
|
||||||
2. The app will automatically enable secure cookies based on the `https://` prefix
|
2. The app will automatically enable secure cookies based on the `https://` prefix
|
||||||
3. Ensure your proxy passes the `X-Forwarded-Proto` header
|
3. Ensure your proxy passes the `X-Forwarded-Proto` header
|
||||||
|
|
||||||
### Important Notes
|
### Important notes
|
||||||
|
|
||||||
- The `BASE_URL` must start with `https://` for secure cookies to be enabled
|
- The `BASE_URL` must start with `https://` for secure cookies to be enabled
|
||||||
- Local IP addresses (e.g., `http://192.168.x.x`) are **not** treated as secure contexts by browsers, so secure cookies are disabled automatically
|
- Local IP addresses (e.g., `http://192.168.x.x`) are **not** treated as secure contexts by browsers, so secure cookies are disabled automatically
|
||||||
|
- `TRUSTED_ORIGINS` only allows additional origins for auth-related requests. It does not disable secure cookies or make authenticated HTTP access work when `BASE_URL` is HTTPS.
|
||||||
|
- If `BASE_URL` is HTTPS, browsers will only send Zerobyte's auth cookies over HTTPS. Plain HTTP access may still show the login page, but authenticated flows will fail because no session cookie is available.
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
For troubleshooting common issues, please refer to the [TROUBLESHOOTING.md](TROUBLESHOOTING.md) file.
|
For troubleshooting common issues, please refer to the [TROUBLESHOOTING.md](TROUBLESHOOTING.md) file.
|
||||||
|
|
||||||
## Third-Party Software
|
## Third-party software
|
||||||
|
|
||||||
This project includes the following third-party software components:
|
This project includes the following third-party software components:
|
||||||
|
|
||||||
|
|
@ -331,10 +387,10 @@ Contributions by anyone are welcome! If you find a bug or have a feature request
|
||||||
|
|
||||||
## Development (no Docker)
|
## Development (no Docker)
|
||||||
|
|
||||||
You can run Zerobyte locally during development without Docker:
|
After installing Vite+ globally, you can run Zerobyte locally during development without Docker:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bun install
|
vp install
|
||||||
bun run dev
|
bun run dev
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -342,16 +398,16 @@ For local development, create a `.env.local` file at the repo root and override
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Example
|
# Example
|
||||||
DATABASE_URL=./data/zerobyte.db
|
ZEROBYTE_DATABASE_URL=./data/zerobyte.db
|
||||||
APP_SECRET=your_app_secret_here
|
APP_SECRET=your_app_secret_here
|
||||||
RESTIC_PASS_FILE=./data/restic.pass
|
RESTIC_PASS_FILE=./data/restic.pass
|
||||||
RESTIC_CACHE_DIR=./data/restic/cache
|
RESTIC_CACHE_DIR=./data/restic/cache
|
||||||
ZEROBYTE_REPOSITORIES_DIR=./data/repositories
|
ZEROBYTE_REPOSITORIES_DIR=./data/repositories
|
||||||
ZEROBYTE_VOLUMES_DIR=./data/volumes
|
ZEROBYTE_VOLUMES_DIR=./data/volumes
|
||||||
BASE_URL=http://localhost:4096
|
BASE_URL=https://*.localhost
|
||||||
```
|
```
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
|
|
||||||
- Remote mount backends (NFS/SMB/WebDAV/SFTP) rely on Linux mount tooling and `CAP_SYS_ADMIN`; on macOS they are expected to be unavailable.
|
- Remote mount backends (NFS/SMB/WebDAV/SFTP) rely on Linux mount tooling and `CAP_SYS_ADMIN`; on macOS they are expected to be unavailable.
|
||||||
- To actually run backups/repository checks, install `restic` on your machine (e.g. via Homebrew). If `restic` is not installed, the app still starts but backup operations will fail with a clear error.
|
- To actually run backups/repository checks, install `restic` on your machine (e.g., via Homebrew). If `restic` is not installed, the app still starts but backup operations will fail with a clear error.
|
||||||
|
|
|
||||||
75
SECURITY.md
Normal file
75
SECURITY.md
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
# Security Policy
|
||||||
|
|
||||||
|
Thank you for helping keep Zerobyte and its users secure.
|
||||||
|
|
||||||
|
Zerobyte is currently in `0.x`, and releases may include breaking changes between versions. For that reason, security fixes are only guaranteed for the most recent stable release line.
|
||||||
|
|
||||||
|
## Supported Versions
|
||||||
|
|
||||||
|
| Version | Supported |
|
||||||
|
| --------------------------------------------- | ------------------ |
|
||||||
|
| Latest stable `0.x` release | :white_check_mark: |
|
||||||
|
| Older stable `0.x` releases | :x: |
|
||||||
|
| Pre-release builds (`-alpha`, `-beta`, `-rc`) | :x: |
|
||||||
|
| Development snapshots from `main` | :x: |
|
||||||
|
|
||||||
|
Security fixes are generally released in the latest stable version only. If you are running an older release, you may be asked to upgrade before a fix is provided.
|
||||||
|
|
||||||
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
Please do **not** report security vulnerabilities through public GitHub issues, discussions, or pull requests.
|
||||||
|
|
||||||
|
Use one of these private channels instead:
|
||||||
|
|
||||||
|
1. Preferred: GitHub private vulnerability reporting
|
||||||
|
https://github.com/nicotsx/zerobyte/security/advisories/new
|
||||||
|
2. Alternative: contact the maintainer directly by email if an address is listed in the repository or GitHub profile
|
||||||
|
|
||||||
|
When reporting, include as much of the following as you can:
|
||||||
|
|
||||||
|
- affected Zerobyte version
|
||||||
|
- deployment details, including whether you are using Docker, reverse proxies, or exposed ports
|
||||||
|
- clear reproduction steps or a proof of concept
|
||||||
|
- impact assessment and what an attacker could do
|
||||||
|
- any relevant logs, screenshots, or configuration excerpts with secrets removed
|
||||||
|
|
||||||
|
### What to expect
|
||||||
|
|
||||||
|
- We aim to acknowledge new reports within 7 days.
|
||||||
|
- We aim to provide status updates at least every 7 days while the report is being investigated.
|
||||||
|
- If the report is accepted, we will work on a fix, coordinate disclosure, and publish a security advisory when appropriate.
|
||||||
|
- If the report is declined, out of scope, or cannot be reproduced, we will explain why when possible.
|
||||||
|
|
||||||
|
Please avoid public disclosure until a fix has been released and maintainers have had reasonable time to notify users.
|
||||||
|
|
||||||
|
## Trust model baseline
|
||||||
|
|
||||||
|
Zerobyte is a self-hosted operator tool. Treat any authenticated user as a trusted machine/operator user with intentional access to:
|
||||||
|
|
||||||
|
- Browse/select host directories for volumes
|
||||||
|
- Configure local, network, and cloud storage backends
|
||||||
|
- Trigger mounts/unmounts, backups, restores, and Restic maintenance
|
||||||
|
- Read/write files through intended backup/restore workflows
|
||||||
|
- Access repository/volume metadata needed to operate backups
|
||||||
|
|
||||||
|
Do **not** report these as vulnerabilities by themselves:
|
||||||
|
|
||||||
|
- Authenticated host filesystem browsing
|
||||||
|
- Local directory volume pointing to broad host paths
|
||||||
|
- Backing up arbitrary readable host paths
|
||||||
|
- Restoring snapshots to arbitrary writable host paths
|
||||||
|
- Authenticated Restic/mount/rclone execution through intended UI flows
|
||||||
|
- Information disclosure to authenticated operators about filesystem paths or backend errors
|
||||||
|
|
||||||
|
Only report issues when they violate this trust model, for example:
|
||||||
|
|
||||||
|
- Unauthenticated access to operator features
|
||||||
|
- CSRF/cross-origin abuse causing a trusted operator’s browser to perform actions
|
||||||
|
- Shell/command injection beyond intended argument-based execution
|
||||||
|
- Path traversal that escapes a deliberately configured root/volume/repository boundary
|
||||||
|
- Secret leakage to logs, unauthenticated users, or non-operator contexts
|
||||||
|
- Cross-organization data access despite authenticated trust
|
||||||
|
- Privilege bypass between global admin/org admin/member where the product explicitly distinguishes roles
|
||||||
|
- Unsafe dev-only features enabled without the documented gate
|
||||||
|
- Vulnerabilities in parsing untrusted external data from repositories/backends/notifications
|
||||||
|
- Persistence corruption, data loss, or workflow bypass not intended by operator actions
|
||||||
|
|
@ -7,6 +7,17 @@ In case you need further assistance, feel free to open a new issue with detailed
|
||||||
> [!WARNING]
|
> [!WARNING]
|
||||||
> Make sure to never share sensitive information such as passwords, access keys, or personal data in public issues so remove them from logs before posting.
|
> Make sure to never share sensitive information such as passwords, access keys, or personal data in public issues so remove them from logs before posting.
|
||||||
|
|
||||||
|
Before troubleshooting, enable debug logging so the logs contain enough detail to diagnose issues.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
zerobyte:
|
||||||
|
environment:
|
||||||
|
- LOG_LEVEL=debug
|
||||||
|
```
|
||||||
|
|
||||||
|
After adding `LOG_LEVEL=debug`, restart Zerobyte and then collect logs.
|
||||||
|
|
||||||
To view the logs, run the command below:
|
To view the logs, run the command below:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
@ -16,33 +27,70 @@ docker logs -f zerobyte
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Common issues
|
## Table of Contents
|
||||||
|
|
||||||
### Permission denied errors when mounting remote shares
|
- [Common Issues](#common-issues)
|
||||||
|
- [Permission Denied Errors When Mounting Remote Shares](#permission-denied-errors-when-mounting-remote-shares)
|
||||||
|
- [Security Levels for Mounting Remote Shares](#security-levels-for-mounting-remote-shares)
|
||||||
|
- [Permission Errors with Remote Shares](#permission-errors-with-remote-shares)
|
||||||
|
- [Container Cannot Perform Mounts](#container-cannot-perform-mounts)
|
||||||
|
- [AppArmor-Enabled Systems (Ubuntu/Debian)](#apparmor-enabled-systems-ubuntudebian)
|
||||||
|
- [Seccomp-Restricted Environments](#seccomp-restricted-environments)
|
||||||
|
- [SELinux-Enabled Systems (CentOS/Fedora)](#selinux-enabled-systems-centosfedora)
|
||||||
|
- [Still Getting Permission Errors After SYS_ADMIN](#still-getting-permission-errors-after-sys_admin)
|
||||||
|
- [FUSE Mount Failures](#fuse-mount-failures)
|
||||||
|
- [Rclone Issues](#rclone-issues)
|
||||||
|
- [Test on Host First](#critical-test-on-host-first)
|
||||||
|
- [Pre-flight Checklist](#pre-flight-checklist)
|
||||||
|
- [Common Rclone Errors](#common-rclone-errors)
|
||||||
|
- ["No Remotes Available" in Dropdown](#no-remotes-available-in-dropdown)
|
||||||
|
- ["Failed to Create File System" Error](#failed-to-create-file-system-error)
|
||||||
|
- [EACCES Errors](#eacces-errors)
|
||||||
|
- [Rclone SFTP Repository Authentication Failures](#rclone-sftp-repository-authentication-failures)
|
||||||
|
- [Rclone Volume Mount Issues](#rclone-volume-mount-issues)
|
||||||
|
- [Prerequisites Check](#prerequisites-check)
|
||||||
|
- [Common Mount Errors](#common-mount-errors)
|
||||||
|
- [Still Having Issues?](#still-having-issues)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Common Issues
|
||||||
|
|
||||||
|
### Permission Denied Errors When Mounting Remote Shares
|
||||||
|
|
||||||
Mounting remote filesystems (such as SMB/CIFS) requires kernel-level privileges. When Zerobyte attempts to perform mounts from inside a container, additional permissions may be required.
|
Mounting remote filesystems (such as SMB/CIFS) requires kernel-level privileges. When Zerobyte attempts to perform mounts from inside a container, additional permissions may be required.
|
||||||
|
|
||||||
Ensure that:
|
Ensure that:
|
||||||
|
|
||||||
* Remote share credentials are correct
|
- Remote share credentials are correct
|
||||||
* The host kernel supports the target filesystem (e.g. CIFS module is available)
|
- The host kernel supports the target filesystem (e.g. CIFS module is available)
|
||||||
* Docker is running in **rootful mode** (rootless Docker cannot perform kernel mounts)
|
- Docker is running in **rootful mode** (rootless Docker cannot perform kernel mounts)
|
||||||
|
|
||||||
In some environments, Linux security mechanisms such as AppArmor or seccomp may block mount-related operations even when the required capabilities are present.
|
In some environments, Linux security mechanisms such as AppArmor or seccomp may block mount-related operations even when the required capabilities are present.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Security levels for mounting remote shares
|
### Security Levels for Mounting Remote Shares
|
||||||
|
|
||||||
Zerobyte supports multiple deployment models depending on your security requirements and environment.
|
Zerobyte supports multiple deployment models depending on your security requirements and environment.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
#### **Secure** (recommended)
|
#### Permission Errors with Remote Shares
|
||||||
|
|
||||||
Mount remote shares **outside of Zerobyte** (on the host) and point Zerobyte to an already mounted local path.
|
**Problem:** You're getting permission errors when Zerobyte tries to mount remote shares (SMB/CIFS, NFS, etc.).
|
||||||
|
|
||||||
This approach avoids granting additional privileges to the container and is the most portable and secure option.
|
**Solution:** Mount remote shares **outside of Zerobyte** (on the host) and point Zerobyte to an already-mounted local path. This avoids container permission issues entirely.
|
||||||
|
|
||||||
|
**How to fix:**
|
||||||
|
|
||||||
|
1. Mount your remote share on the host first using `systemd`, `autofs`, or manual mount:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo mount -t cifs //server/share /mnt/your-remote-share -o credentials=/path/to/creds
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Then mount that local path into Zerobyte:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
services:
|
services:
|
||||||
|
|
@ -51,13 +99,20 @@ services:
|
||||||
- /mnt/your-remote-share:/data
|
- /mnt/your-remote-share:/data
|
||||||
```
|
```
|
||||||
|
|
||||||
Remote mounts can be managed via `systemd`, `autofs`, or manual host mounts.
|
3. Restart the container:
|
||||||
|
```bash
|
||||||
|
docker compose down && docker compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
#### **Advanced** (Zerobyte performs mounts)
|
#### Container Cannot Perform Mounts
|
||||||
|
|
||||||
If Zerobyte must perform filesystem mounts itself, the container requires the `SYS_ADMIN` capability.
|
**Problem:** Zerobyte shows "Operation not permitted" errors when trying to mount remote shares directly.
|
||||||
|
|
||||||
|
**Solution:** Grant the `SYS_ADMIN` capability to allow the container to perform mount operations.
|
||||||
|
|
||||||
|
**Warning:** This grants significant privileges to the container and should only be used when necessary.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
services:
|
services:
|
||||||
|
|
@ -70,7 +125,7 @@ services:
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
#### AppArmor-enabled systems (Ubuntu/Debian)
|
#### AppArmor-Enabled Systems (Ubuntu/Debian)
|
||||||
|
|
||||||
On hosts using AppArmor, the default Docker profile (`docker-default`) may block mount operations even when `SYS_ADMIN` is present.
|
On hosts using AppArmor, the default Docker profile (`docker-default`) may block mount operations even when `SYS_ADMIN` is present.
|
||||||
|
|
||||||
|
|
@ -96,7 +151,7 @@ services:
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
#### Seccomp-restricted environments
|
#### Seccomp-Restricted Environments
|
||||||
|
|
||||||
Docker's default seccomp profile may block mount-related syscalls required by filesystem operations.
|
Docker's default seccomp profile may block mount-related syscalls required by filesystem operations.
|
||||||
|
|
||||||
|
|
@ -113,7 +168,7 @@ services:
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
#### SELinux-enabled systems (CentOS/Fedora)
|
#### SELinux-Enabled Systems (CentOS/Fedora)
|
||||||
|
|
||||||
On hosts using SELinux, you may need to adjust the security context to allow mount operations.
|
On hosts using SELinux, you may need to adjust the security context to allow mount operations.
|
||||||
If mount operations fail with permission errors, you can try adding the following label:
|
If mount operations fail with permission errors, you can try adding the following label:
|
||||||
|
|
@ -140,11 +195,13 @@ services:
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
#### **Not recommended** (When all else fails)
|
#### Still Getting Permission Errors After SYS_ADMIN
|
||||||
|
|
||||||
Running the container in privileged mode disables most container isolation mechanisms and significantly increases the attack surface.
|
**Problem:** Mount operations still fail even with `SYS_ADMIN` capability.
|
||||||
|
|
||||||
This option should be used only as a last resort for troubleshooting.
|
**Solution (Last Resort):** Run the container in privileged mode. This disables most container isolation mechanisms and significantly increases the attack surface.
|
||||||
|
|
||||||
|
**Warning:** Only use this as a last resort for troubleshooting. Remove and switch to a more secure solution once you identify the actual issue.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
services:
|
services:
|
||||||
|
|
@ -154,19 +211,264 @@ services:
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Notes on FUSE-based backends
|
### FUSE Mount Failures
|
||||||
|
|
||||||
Access to `/dev/fuse` is required **only for FUSE-based filesystems** (such as `sshfs` or `rclone mount`).
|
**Problem:** FUSE-based mounts (sshfs, rclone mount) are failing with device access errors.
|
||||||
|
|
||||||
It is **not required** for SMB/CIFS mounts.
|
**Cause:** Access to `/dev/fuse` is required for FUSE-based filesystems.
|
||||||
|
|
||||||
### Rclone mount issues
|
**Solution:** Ensure `/dev/fuse` is mounted into the container. This is **not required** for SMB/CIFS mounts.
|
||||||
|
|
||||||
When using `rclone`, you may get errors like:
|
````yaml
|
||||||
|
services:
|
||||||
|
zerobyte:
|
||||||
|
devices:
|
||||||
|
- /dev/fuse:/dev/fuse
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Rclone Issues
|
||||||
|
|
||||||
|
### ⚠️ Critical: Test on Host First
|
||||||
|
|
||||||
|
**Before reporting any rclone-related issue, you MUST verify that rclone works correctly on your Docker host.**
|
||||||
|
|
||||||
|
Most rclone issues are due to misconfigured remotes, not Zerobyte bugs. Follow this checklist on your host machine:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bun: Failed to spawn process: EACCES
|
# 1. List all configured remotes
|
||||||
error > Failed to list rclone remotes: bun: Failed to spawn process: EACCES
|
rclone listremotes
|
||||||
|
|
||||||
|
# 2. Test listing a remote (replace 'myremote' with your remote name)
|
||||||
|
rclone lsd myremote:
|
||||||
|
|
||||||
|
# 3. Test reading from a remote
|
||||||
|
rclone ls myremote:path/to/test
|
||||||
|
|
||||||
|
# 4. For volume mounts: Test mounting on host first
|
||||||
|
mkdir -p /tmp/rclone-test
|
||||||
|
rclone mount myremote:path /tmp/rclone-test --daemon --vfs-cache-mode writes
|
||||||
|
ls /tmp/rclone-test
|
||||||
|
fusermount -u /tmp/rclone-test # Unmount when done
|
||||||
|
````
|
||||||
|
|
||||||
|
**If these commands fail on your host, fix your rclone configuration before using Zerobyte.**
|
||||||
|
|
||||||
|
Common issues include:
|
||||||
|
|
||||||
|
- Expired OAuth tokens (run `rclone config` to re-authenticate)
|
||||||
|
- Incorrect credentials
|
||||||
|
- Missing permissions on cloud provider side
|
||||||
|
- Network/firewall issues
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Pre-flight Checklist
|
||||||
|
|
||||||
|
If you're experiencing rclone issues, verify all of the following:
|
||||||
|
|
||||||
|
- [ ] Rclone is installed and configured on the Docker **host**
|
||||||
|
- [ ] `rclone listremotes` shows your remote
|
||||||
|
- [ ] `rclone lsd remote:` successfully lists directories
|
||||||
|
- [ ] The rclone config directory is mounted into the container
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Common Rclone Errors
|
||||||
|
|
||||||
|
#### "No Remotes Available" in Dropdown
|
||||||
|
|
||||||
|
**Cause:** Zerobyte cannot find your rclone configuration file.
|
||||||
|
|
||||||
|
**Diagnosis:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Check which config file rclone will use inside the container
|
||||||
|
docker exec zerobyte sh -lc 'echo HOME=$HOME; rclone config file'
|
||||||
```
|
```
|
||||||
|
|
||||||
Try to disable the AppArmor confinement for the container as described in the [AppArmor-enabled systems](#apparmor-enabled-systems-ubuntudebian) section above or [Seccomp-restricted environments](#seccomp-restricted-environments) section.
|
**Solutions:**
|
||||||
|
|
||||||
|
1. Ensure you've mounted your host's rclone config:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
volumes:
|
||||||
|
- ~/.config/rclone:/root/.config/rclone:ro
|
||||||
|
```
|
||||||
|
|
||||||
|
2. For non-root containers (e.g., TrueNAS), set the correct path:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
environment:
|
||||||
|
- RCLONE_CONFIG_DIR=/home/appuser/.config/rclone
|
||||||
|
volumes:
|
||||||
|
- ~/.config/rclone:/home/appuser/.config/rclone:ro
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Restart the container** after mounting the config:
|
||||||
|
```bash
|
||||||
|
docker compose down
|
||||||
|
docker compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
#### "Failed to Create File System" Error
|
||||||
|
|
||||||
|
**Cause:** Authentication failure with the cloud provider.
|
||||||
|
|
||||||
|
**Solution:**
|
||||||
|
|
||||||
|
1. On your host, run: `rclone config`
|
||||||
|
2. Re-authenticate the remote (especially for OAuth providers like Google Drive, Dropbox, OneDrive)
|
||||||
|
3. Verify with: `rclone lsd remote:`
|
||||||
|
4. Restart the Zerobyte container
|
||||||
|
|
||||||
|
#### EACCES Errors
|
||||||
|
|
||||||
|
**Cause:** AppArmor or seccomp is blocking rclone execution.
|
||||||
|
|
||||||
|
**Solution:** Disable security profiles as described in:
|
||||||
|
|
||||||
|
- [AppArmor-enabled systems](#apparmor-enabled-systems-ubuntudebian)
|
||||||
|
- [Seccomp-restricted environments](#seccomp-restricted-environments)
|
||||||
|
|
||||||
|
#### Rclone SFTP Repository Authentication Failures
|
||||||
|
|
||||||
|
When creating an **rclone repository** that uses an **SFTP remote**, you may encounter authentication errors even though:
|
||||||
|
|
||||||
|
- The rclone config is mounted correctly
|
||||||
|
- The SFTP remote appears in the dropdown
|
||||||
|
- The same config works on the host
|
||||||
|
|
||||||
|
**The issue:** If your rclone SFTP remote uses `key_file` for SSH key authentication, the key file path in your rclone config points to a location on the **host** (e.g., `~/.ssh/id_rsa`). When rclone runs inside the container, it cannot access that path.
|
||||||
|
|
||||||
|
**Solutions:**
|
||||||
|
|
||||||
|
**Option 1: Mount your SSH keys (Recommended)**
|
||||||
|
|
||||||
|
Add your SSH directory to the container volumes:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
zerobyte:
|
||||||
|
volumes:
|
||||||
|
- ~/.config/rclone:/root/.config/rclone:ro
|
||||||
|
- ~/.ssh:/root/.ssh:ro # Required for SFTP remotes using key_file
|
||||||
|
```
|
||||||
|
|
||||||
|
**Option 2: Embed the SSH key in rclone config**
|
||||||
|
|
||||||
|
Use `key_pem` instead of `key_file` to embed the private key directly in your rclone.conf:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Convert your key to single-line format
|
||||||
|
awk '{printf "%s\\n", $0}' < ~/.ssh/id_rsa
|
||||||
|
```
|
||||||
|
|
||||||
|
Then update your rclone config:
|
||||||
|
|
||||||
|
```ini
|
||||||
|
[sftp-remote]
|
||||||
|
type = sftp
|
||||||
|
host = example.com
|
||||||
|
user = backup
|
||||||
|
key_pem = -----BEGIN OPENSSH PRIVATE KEY-----\nb3BlbnNzaC1rZXktdjEAAAAABG5v...\n-----END OPENSSH PRIVATE KEY-----
|
||||||
|
```
|
||||||
|
|
||||||
|
**Option 3: Use ssh-agent**
|
||||||
|
|
||||||
|
Configure your rclone remote to use ssh-agent instead of a key file:
|
||||||
|
|
||||||
|
```ini
|
||||||
|
[sftp-remote]
|
||||||
|
type = sftp
|
||||||
|
host = example.com
|
||||||
|
user = backup
|
||||||
|
key_use_agent = true
|
||||||
|
```
|
||||||
|
|
||||||
|
Then mount the SSH agent socket and set the environment variable:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
zerobyte:
|
||||||
|
environment:
|
||||||
|
- SSH_AUTH_SOCK=/ssh-agent
|
||||||
|
volumes:
|
||||||
|
- ~/.config/rclone:/root/.config/rclone:ro
|
||||||
|
- ${SSH_AUTH_SOCK}:/ssh-agent
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Rclone Volume Mount Issues
|
||||||
|
|
||||||
|
When using rclone as a **volume backend** (mounting cloud storage to back up from), additional requirements apply:
|
||||||
|
|
||||||
|
#### Prerequisites Check
|
||||||
|
|
||||||
|
If rclone volume mounting isn't working, verify these prerequisites on your system:
|
||||||
|
|
||||||
|
- **Linux host required:** Windows/macOS hosts cannot use rclone volumes. If you're on these platforms, you'll need to use a different volume backend.
|
||||||
|
- **`/dev/fuse` device:** Check if FUSE is available and properly passed to the container
|
||||||
|
- **`SYS_ADMIN` capability:** Required for mount operations inside containers
|
||||||
|
- **FUSE support on host:** Verify FUSE is installed and working on your Docker host
|
||||||
|
|
||||||
|
#### Common Mount Errors
|
||||||
|
|
||||||
|
**"mount helper error: fusermount3: failed to open /dev/fuse: Permission denied"**
|
||||||
|
|
||||||
|
Solutions in order of preference:
|
||||||
|
|
||||||
|
1. **Verify FUSE works on host first:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# On host
|
||||||
|
rclone mount remote:path /tmp/test --daemon
|
||||||
|
ls /tmp/test
|
||||||
|
fusermount -u /tmp/test
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Ensure /dev/fuse is mounted in container:**
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
devices:
|
||||||
|
- /dev/fuse:/dev/fuse
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Check user permissions inside container:**
|
||||||
|
```bash
|
||||||
|
docker exec zerobyte ls -la /dev/fuse
|
||||||
|
```
|
||||||
|
|
||||||
|
**"mount helper error: fusermount3: mount failed: Operation not permitted"**
|
||||||
|
|
||||||
|
This indicates the container lacks `SYS_ADMIN` capability:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
cap_add:
|
||||||
|
- SYS_ADMIN
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Still having issues?
|
||||||
|
|
||||||
|
If you've verified rclone works on the host and followed all troubleshooting steps above, gather this information for your issue report:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Host verification
|
||||||
|
rclone version
|
||||||
|
rclone listremotes
|
||||||
|
rclone lsd remote: 2>&1
|
||||||
|
|
||||||
|
# Container verification
|
||||||
|
docker exec zerobyte ls -la /root/.config/rclone/
|
||||||
|
docker exec zerobyte env | grep RCLONE
|
||||||
|
docker logs zerobyte 2>&1 | tail -50
|
||||||
|
|
||||||
|
# Check container capabilities
|
||||||
|
docker inspect zerobyte --format='{{.HostConfig.CapAdd}}'
|
||||||
|
docker inspect zerobyte --format='{{.HostConfig.Devices}}'
|
||||||
|
```
|
||||||
|
|
||||||
|
Include the output (with sensitive data redacted) in your GitHub issue.
|
||||||
|
|
|
||||||
107
app/app.css
107
app/app.css
|
|
@ -5,7 +5,16 @@
|
||||||
|
|
||||||
@custom-variant dark (&:is(.dark *));
|
@custom-variant dark (&:is(.dark *));
|
||||||
|
|
||||||
|
@custom-variant @narrow (@container (min-width: 28rem));
|
||||||
|
@custom-variant @medium (@container (min-width: 40rem));
|
||||||
|
@custom-variant @wide (@container (min-width: 60rem));
|
||||||
|
@custom-variant @xwide (@container (min-width: 80rem));
|
||||||
|
|
||||||
@theme {
|
@theme {
|
||||||
|
--container-narrow: 28rem;
|
||||||
|
--container-medium: 40rem;
|
||||||
|
--container-wide: 60rem;
|
||||||
|
--container-xwide: 80rem;
|
||||||
--breakpoint-xs: 32rem;
|
--breakpoint-xs: 32rem;
|
||||||
--font-sans:
|
--font-sans:
|
||||||
"Google Sans Code", ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol",
|
"Google Sans Code", ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol",
|
||||||
|
|
@ -17,12 +26,17 @@ body {
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
position: relative;
|
position: relative;
|
||||||
overscroll-behavior: none;
|
|
||||||
scrollbar-width: thin;
|
scrollbar-width: thin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (min-width: 48rem) {
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
overscroll-behavior: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
@apply bg-[#131313];
|
|
||||||
min-height: 100dvh;
|
min-height: 100dvh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -52,6 +66,8 @@ body {
|
||||||
--color-accent: var(--accent);
|
--color-accent: var(--accent);
|
||||||
--color-accent-foreground: var(--accent-foreground);
|
--color-accent-foreground: var(--accent-foreground);
|
||||||
--color-destructive: var(--destructive);
|
--color-destructive: var(--destructive);
|
||||||
|
--color-destructive-foreground: var(--destructive-foreground);
|
||||||
|
--color-success: var(--success);
|
||||||
--color-border: var(--border);
|
--color-border: var(--border);
|
||||||
--color-input: var(--input);
|
--color-input: var(--input);
|
||||||
--color-ring: var(--ring);
|
--color-ring: var(--ring);
|
||||||
|
|
@ -73,38 +89,40 @@ body {
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
--radius: 0.625rem;
|
--radius: 0.625rem;
|
||||||
--background: oklch(1 0 0);
|
--background: oklch(0.98 0.002 250);
|
||||||
--foreground: oklch(0.145 0 0);
|
--foreground: oklch(0.20 0.01 260);
|
||||||
--card: oklch(1 0 0);
|
--card: #ffffff;
|
||||||
--card-foreground: oklch(0.145 0 0);
|
--card-foreground: oklch(0.20 0.01 260);
|
||||||
--card-header: oklch(0.922 0 0);
|
--card-header: oklch(0.99 0.001 260);
|
||||||
--popover: oklch(1 0 0);
|
--popover: #ffffff;
|
||||||
--popover-foreground: oklch(0.145 0 0);
|
--popover-foreground: oklch(0.20 0.01 260);
|
||||||
--primary: oklch(0.205 0 0);
|
--primary: oklch(0.20 0.01 260);
|
||||||
--primary-foreground: oklch(0.985 0 0);
|
--primary-foreground: #ffffff;
|
||||||
--secondary: oklch(0.97 0 0);
|
--secondary: oklch(0.96 0.005 260);
|
||||||
--secondary-foreground: oklch(0.205 0 0);
|
--secondary-foreground: oklch(0.20 0.01 260);
|
||||||
--muted: oklch(0.97 0 0);
|
--muted: oklch(0.95 0.005 260);
|
||||||
--muted-foreground: oklch(0.556 0 0);
|
--muted-foreground: oklch(0.45 0.01 260);
|
||||||
--accent: oklch(0.97 0 0);
|
--accent: oklch(0.96 0.005 260);
|
||||||
--accent-foreground: oklch(0.205 0 0);
|
--accent-foreground: oklch(0.20 0.01 260);
|
||||||
--destructive: oklch(0.577 0.245 27.325);
|
--destructive: oklch(0.577 0.245 27.325);
|
||||||
--border: oklch(0.922 0 0);
|
--destructive-foreground: #fff;
|
||||||
--input: oklch(0.922 0 0);
|
--success: oklch(0.57 0.16 148);
|
||||||
--ring: oklch(0.708 0 0);
|
--border: oklch(0.90 0.01 260);
|
||||||
--chart-1: oklch(0.646 0.222 41.116);
|
--input: oklch(0.90 0.01 260);
|
||||||
--chart-2: oklch(0.6 0.118 184.704);
|
--ring: oklch(0.7 0.01 260);
|
||||||
--chart-3: oklch(0.398 0.07 227.392);
|
--chart-1: oklch(0.55 0.22 260);
|
||||||
--chart-4: oklch(0.828 0.189 84.429);
|
--chart-2: oklch(0.6 0.15 200);
|
||||||
--chart-5: oklch(0.769 0.188 70.08);
|
--chart-3: oklch(0.45 0.12 280);
|
||||||
--sidebar: oklch(0.985 0 0);
|
--chart-4: oklch(0.7 0.15 190);
|
||||||
--sidebar-foreground: oklch(0.145 0 0);
|
--chart-5: oklch(0.55 0.18 300);
|
||||||
--sidebar-primary: oklch(0.205 0 0);
|
--sidebar: #ffffff;
|
||||||
--sidebar-primary-foreground: oklch(0.985 0 0);
|
--sidebar-foreground: oklch(0.35 0.01 260);
|
||||||
--sidebar-accent: oklch(0.97 0 0);
|
--sidebar-primary: oklch(0.20 0.01 260);
|
||||||
--sidebar-accent-foreground: oklch(0.205 0 0);
|
--sidebar-primary-foreground: #ffffff;
|
||||||
--sidebar-border: oklch(0.922 0 0);
|
--sidebar-accent: oklch(0.97 0.005 260);
|
||||||
--sidebar-ring: oklch(0.708 0 0);
|
--sidebar-accent-foreground: oklch(0.20 0.01 260);
|
||||||
|
--sidebar-border: oklch(0.90 0.01 260);
|
||||||
|
--sidebar-ring: oklch(0.7 0.01 260);
|
||||||
--strong-accent: #ff543a;
|
--strong-accent: #ff543a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -129,6 +147,8 @@ body {
|
||||||
--accent: oklch(0.269 0 0);
|
--accent: oklch(0.269 0 0);
|
||||||
--accent-foreground: oklch(0.985 0 0);
|
--accent-foreground: oklch(0.985 0 0);
|
||||||
--destructive: #ff543a;
|
--destructive: #ff543a;
|
||||||
|
--destructive-foreground: #fff;
|
||||||
|
--success: oklch(0.696 0.17 162.48);
|
||||||
--border: oklch(1 0 0 / 10%);
|
--border: oklch(1 0 0 / 10%);
|
||||||
--input: oklch(1 0 0 / 15%);
|
--input: oklch(1 0 0 / 15%);
|
||||||
--ring: oklch(0.556 0 0);
|
--ring: oklch(0.556 0 0);
|
||||||
|
|
@ -159,11 +179,11 @@ body {
|
||||||
|
|
||||||
@layer base {
|
@layer base {
|
||||||
:root {
|
:root {
|
||||||
--chart-1: oklch(0.646 0.222 41.116);
|
--chart-1: oklch(0.55 0.22 260);
|
||||||
--chart-2: oklch(0.6 0.118 184.704);
|
--chart-2: oklch(0.6 0.15 200);
|
||||||
--chart-3: oklch(0.398 0.07 227.392);
|
--chart-3: oklch(0.45 0.12 280);
|
||||||
--chart-4: oklch(0.828 0.189 84.429);
|
--chart-4: oklch(0.7 0.15 190);
|
||||||
--chart-5: oklch(0.769 0.188 70.08);
|
--chart-5: oklch(0.55 0.18 300);
|
||||||
}
|
}
|
||||||
|
|
||||||
.dark {
|
.dark {
|
||||||
|
|
@ -175,6 +195,17 @@ body {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.snapshot-scrollable::-webkit-scrollbar {
|
||||||
|
height: 6px;
|
||||||
|
}
|
||||||
|
.snapshot-scrollable::-webkit-scrollbar-track {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
.snapshot-scrollable::-webkit-scrollbar-thumb {
|
||||||
|
background: var(--border);
|
||||||
|
border-radius: 999px;
|
||||||
|
}
|
||||||
|
|
||||||
/* Hide built-in password reveal/clear controls (notably in Edge on Windows) */
|
/* Hide built-in password reveal/clear controls (notably in Edge on Windows) */
|
||||||
[data-secret-input] input[type="password"]::-ms-reveal,
|
[data-secret-input] input[type="password"]::-ms-reveal,
|
||||||
[data-secret-input] input[type="password"]::-ms-clear {
|
[data-secret-input] input[type="password"]::-ms-clear {
|
||||||
|
|
|
||||||
20
app/client.tsx
Normal file
20
app/client.tsx
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
import { StrictMode, startTransition } from "react";
|
||||||
|
import { hydrateRoot } from "react-dom/client";
|
||||||
|
import { StartClient } from "@tanstack/react-start/client";
|
||||||
|
import { parseError } from "./client/lib/errors";
|
||||||
|
|
||||||
|
startTransition(() => {
|
||||||
|
hydrateRoot(
|
||||||
|
document,
|
||||||
|
<StrictMode>
|
||||||
|
<StartClient />
|
||||||
|
</StrictMode>,
|
||||||
|
{
|
||||||
|
onRecoverableError: (error, errorInfo) => {
|
||||||
|
console.error(
|
||||||
|
`[react-recoverable-error] ${parseError(error)?.message}${errorInfo.componentStack ? `\n${errorInfo.componentStack.trim()}` : ""}`,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,18 +1,27 @@
|
||||||
|
// @ts-nocheck
|
||||||
// This file is auto-generated by @hey-api/openapi-ts
|
// This file is auto-generated by @hey-api/openapi-ts
|
||||||
|
|
||||||
import { type ClientOptions, type Config, createClient, createConfig } from "./client";
|
import { type ClientOptions, type Config, createClient, createConfig } from "./client";
|
||||||
import type { ClientOptions as ClientOptions2 } from "./types.gen";
|
import type { ClientOptions as ClientOptions2 } from "./types.gen";
|
||||||
|
import { getRequestClient } from "../../lib/request-client";
|
||||||
|
|
||||||
/**
|
|
||||||
* The `createClientConfig()` function will be called on client initialization
|
|
||||||
* and the returned object will become the client's initial configuration.
|
|
||||||
*
|
|
||||||
* You may want to initialize your client this way instead of calling
|
|
||||||
* `setConfig()`. This is useful for example if you're using Next.js
|
|
||||||
* to ensure your client always has the correct values.
|
|
||||||
*/
|
|
||||||
export type CreateClientConfig<T extends ClientOptions = ClientOptions2> = (
|
export type CreateClientConfig<T extends ClientOptions = ClientOptions2> = (
|
||||||
override?: Config<ClientOptions & T>,
|
override?: Config<ClientOptions & T>,
|
||||||
) => Config<Required<ClientOptions> & T>;
|
) => Config<Required<ClientOptions> & T>;
|
||||||
|
|
||||||
export const client = createClient(createConfig<ClientOptions2>({ baseUrl: "http://localhost:4096" }));
|
const fallbackClient = createClient(createConfig<ClientOptions2>({ baseUrl: "http://localhost:4096" }));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Proxy client that automatically uses the per-request client from request-scoped server storage.
|
||||||
|
* Falls back to a default client if no request context is available.
|
||||||
|
*/
|
||||||
|
export const client = new Proxy(fallbackClient, {
|
||||||
|
get(target, prop, receiver) {
|
||||||
|
try {
|
||||||
|
const requestClient = getRequestClient();
|
||||||
|
return Reflect.get(requestClient, prop, receiver);
|
||||||
|
} catch {
|
||||||
|
// No request context available, use fallback
|
||||||
|
return Reflect.get(target, prop, receiver);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
|
// @ts-nocheck
|
||||||
// This file is auto-generated by @hey-api/openapi-ts
|
// This file is auto-generated by @hey-api/openapi-ts
|
||||||
|
|
||||||
import { createSseClient } from "../core/serverSentEvents.gen";
|
import { createSseClient } from '../core/serverSentEvents.gen';
|
||||||
import type { HttpMethod } from "../core/types.gen";
|
import type { HttpMethod } from '../core/types.gen';
|
||||||
import { getValidRequestBody } from "../core/utils.gen";
|
import { getValidRequestBody } from '../core/utils.gen';
|
||||||
import type { Client, Config, RequestOptions, ResolvedRequestOptions } from "./types.gen";
|
import type { Client, Config, RequestOptions, ResolvedRequestOptions } from './types.gen';
|
||||||
import {
|
import {
|
||||||
buildUrl,
|
buildUrl,
|
||||||
createConfig,
|
createConfig,
|
||||||
|
|
@ -12,9 +13,9 @@ import {
|
||||||
mergeConfigs,
|
mergeConfigs,
|
||||||
mergeHeaders,
|
mergeHeaders,
|
||||||
setAuthParams,
|
setAuthParams,
|
||||||
} from "./utils.gen";
|
} from './utils.gen';
|
||||||
|
|
||||||
type ReqInit = Omit<RequestInit, "body" | "headers"> & {
|
type ReqInit = Omit<RequestInit, 'body' | 'headers'> & {
|
||||||
body?: any;
|
body?: any;
|
||||||
headers: ReturnType<typeof mergeHeaders>;
|
headers: ReturnType<typeof mergeHeaders>;
|
||||||
};
|
};
|
||||||
|
|
@ -31,20 +32,24 @@ export const createClient = (config: Config = {}): Client => {
|
||||||
|
|
||||||
const interceptors = createInterceptors<Request, Response, unknown, ResolvedRequestOptions>();
|
const interceptors = createInterceptors<Request, Response, unknown, ResolvedRequestOptions>();
|
||||||
|
|
||||||
const beforeRequest = async (options: RequestOptions) => {
|
const beforeRequest = async <
|
||||||
|
TData = unknown,
|
||||||
|
TResponseStyle extends 'data' | 'fields' = 'fields',
|
||||||
|
ThrowOnError extends boolean = boolean,
|
||||||
|
Url extends string = string,
|
||||||
|
>(
|
||||||
|
options: RequestOptions<TData, TResponseStyle, ThrowOnError, Url>,
|
||||||
|
) => {
|
||||||
const opts = {
|
const opts = {
|
||||||
..._config,
|
..._config,
|
||||||
...options,
|
...options,
|
||||||
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
||||||
headers: mergeHeaders(_config.headers, options.headers),
|
headers: mergeHeaders(_config.headers, options.headers),
|
||||||
serializedBody: undefined,
|
serializedBody: undefined as string | undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (opts.security) {
|
if (opts.security) {
|
||||||
await setAuthParams({
|
await setAuthParams(opts);
|
||||||
...opts,
|
|
||||||
security: opts.security,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.requestValidator) {
|
if (opts.requestValidator) {
|
||||||
|
|
@ -52,29 +57,37 @@ export const createClient = (config: Config = {}): Client => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.body !== undefined && opts.bodySerializer) {
|
if (opts.body !== undefined && opts.bodySerializer) {
|
||||||
opts.serializedBody = opts.bodySerializer(opts.body);
|
opts.serializedBody = opts.bodySerializer(opts.body) as string | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove Content-Type header if body is empty to avoid sending invalid requests
|
// remove Content-Type header if body is empty to avoid sending invalid requests
|
||||||
if (opts.body === undefined || opts.serializedBody === "") {
|
if (opts.body === undefined || opts.serializedBody === '') {
|
||||||
opts.headers.delete("Content-Type");
|
opts.headers.delete('Content-Type');
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = buildUrl(opts);
|
const resolvedOpts = opts as typeof opts &
|
||||||
|
ResolvedRequestOptions<TResponseStyle, ThrowOnError, Url>;
|
||||||
|
const url = buildUrl(resolvedOpts);
|
||||||
|
|
||||||
return { opts, url };
|
return { opts: resolvedOpts, url };
|
||||||
};
|
};
|
||||||
|
|
||||||
const request: Client["request"] = async (options) => {
|
const request: Client['request'] = async (options) => {
|
||||||
// @ts-expect-error
|
const throwOnError = options.throwOnError ?? _config.throwOnError;
|
||||||
|
const responseStyle = options.responseStyle ?? _config.responseStyle;
|
||||||
|
|
||||||
|
let request: Request | undefined;
|
||||||
|
let response: Response | undefined;
|
||||||
|
|
||||||
|
try {
|
||||||
const { opts, url } = await beforeRequest(options);
|
const { opts, url } = await beforeRequest(options);
|
||||||
const requestInit: ReqInit = {
|
const requestInit: ReqInit = {
|
||||||
redirect: "follow",
|
redirect: 'follow',
|
||||||
...opts,
|
...opts,
|
||||||
body: getValidRequestBody(opts),
|
body: getValidRequestBody(opts),
|
||||||
};
|
};
|
||||||
|
|
||||||
let request = new Request(url, requestInit);
|
request = new Request(url, requestInit);
|
||||||
|
|
||||||
for (const fn of interceptors.request.fns) {
|
for (const fn of interceptors.request.fns) {
|
||||||
if (fn) {
|
if (fn) {
|
||||||
|
|
@ -85,35 +98,8 @@ export const createClient = (config: Config = {}): Client => {
|
||||||
// fetch must be assigned here, otherwise it would throw the error:
|
// fetch must be assigned here, otherwise it would throw the error:
|
||||||
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
||||||
const _fetch = opts.fetch!;
|
const _fetch = opts.fetch!;
|
||||||
let response: Response;
|
|
||||||
|
|
||||||
try {
|
|
||||||
response = await _fetch(request);
|
response = await _fetch(request);
|
||||||
} catch (error) {
|
|
||||||
// Handle fetch exceptions (AbortError, network errors, etc.)
|
|
||||||
let finalError = error;
|
|
||||||
|
|
||||||
for (const fn of interceptors.error.fns) {
|
|
||||||
if (fn) {
|
|
||||||
finalError = (await fn(error, undefined as any, request, opts)) as unknown;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
finalError = finalError || ({} as unknown);
|
|
||||||
|
|
||||||
if (opts.throwOnError) {
|
|
||||||
throw finalError;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return error response
|
|
||||||
return opts.responseStyle === "data"
|
|
||||||
? undefined
|
|
||||||
: {
|
|
||||||
error: finalError,
|
|
||||||
request,
|
|
||||||
response: undefined as any,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const fn of interceptors.response.fns) {
|
for (const fn of interceptors.response.fns) {
|
||||||
if (fn) {
|
if (fn) {
|
||||||
|
|
@ -128,28 +114,30 @@ export const createClient = (config: Config = {}): Client => {
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const parseAs =
|
const parseAs =
|
||||||
(opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
(opts.parseAs === 'auto'
|
||||||
|
? getParseAs(response.headers.get('Content-Type'))
|
||||||
|
: opts.parseAs) ?? 'json';
|
||||||
|
|
||||||
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
if (response.status === 204 || response.headers.get('Content-Length') === '0') {
|
||||||
let emptyData: any;
|
let emptyData: any;
|
||||||
switch (parseAs) {
|
switch (parseAs) {
|
||||||
case "arrayBuffer":
|
case 'arrayBuffer':
|
||||||
case "blob":
|
case 'blob':
|
||||||
case "text":
|
case 'text':
|
||||||
emptyData = await response[parseAs]();
|
emptyData = await response[parseAs]();
|
||||||
break;
|
break;
|
||||||
case "formData":
|
case 'formData':
|
||||||
emptyData = new FormData();
|
emptyData = new FormData();
|
||||||
break;
|
break;
|
||||||
case "stream":
|
case 'stream':
|
||||||
emptyData = response.body;
|
emptyData = response.body;
|
||||||
break;
|
break;
|
||||||
case "json":
|
case 'json':
|
||||||
default:
|
default:
|
||||||
emptyData = {};
|
emptyData = {};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return opts.responseStyle === "data"
|
return opts.responseStyle === 'data'
|
||||||
? emptyData
|
? emptyData
|
||||||
: {
|
: {
|
||||||
data: emptyData,
|
data: emptyData,
|
||||||
|
|
@ -159,21 +147,21 @@ export const createClient = (config: Config = {}): Client => {
|
||||||
|
|
||||||
let data: any;
|
let data: any;
|
||||||
switch (parseAs) {
|
switch (parseAs) {
|
||||||
case "arrayBuffer":
|
case 'arrayBuffer':
|
||||||
case "blob":
|
case 'blob':
|
||||||
case "formData":
|
case 'formData':
|
||||||
case "text":
|
case 'text':
|
||||||
data = await response[parseAs]();
|
data = await response[parseAs]();
|
||||||
break;
|
break;
|
||||||
case "json": {
|
case 'json': {
|
||||||
// Some servers return 200 with no Content-Length and empty body.
|
// Some servers return 200 with no Content-Length and empty body.
|
||||||
// response.json() would throw; read as text and parse if non-empty.
|
// response.json() would throw; read as text and parse if non-empty.
|
||||||
const text = await response.text();
|
const text = await response.text();
|
||||||
data = text ? JSON.parse(text) : {};
|
data = text ? JSON.parse(text) : {};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "stream":
|
case 'stream':
|
||||||
return opts.responseStyle === "data"
|
return opts.responseStyle === 'data'
|
||||||
? response.body
|
? response.body
|
||||||
: {
|
: {
|
||||||
data: response.body,
|
data: response.body,
|
||||||
|
|
@ -181,7 +169,7 @@ export const createClient = (config: Config = {}): Client => {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseAs === "json") {
|
if (parseAs === 'json') {
|
||||||
if (opts.responseValidator) {
|
if (opts.responseValidator) {
|
||||||
await opts.responseValidator(data);
|
await opts.responseValidator(data);
|
||||||
}
|
}
|
||||||
|
|
@ -191,7 +179,7 @@ export const createClient = (config: Config = {}): Client => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return opts.responseStyle === "data"
|
return opts.responseStyle === 'data'
|
||||||
? data
|
? data
|
||||||
: {
|
: {
|
||||||
data,
|
data,
|
||||||
|
|
@ -208,38 +196,41 @@ export const createClient = (config: Config = {}): Client => {
|
||||||
// noop
|
// noop
|
||||||
}
|
}
|
||||||
|
|
||||||
const error = jsonError ?? textError;
|
throw jsonError ?? textError;
|
||||||
|
} catch (error) {
|
||||||
let finalError = error;
|
let finalError = error;
|
||||||
|
|
||||||
for (const fn of interceptors.error.fns) {
|
for (const fn of interceptors.error.fns) {
|
||||||
if (fn) {
|
if (fn) {
|
||||||
finalError = (await fn(error, response, request, opts)) as string;
|
finalError = await fn(finalError, response, request, options as ResolvedRequestOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
finalError = finalError || ({} as string);
|
finalError = finalError || {};
|
||||||
|
|
||||||
if (opts.throwOnError) {
|
if (throwOnError) {
|
||||||
throw finalError;
|
throw finalError;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: we probably want to return error and improve types
|
// TODO: we probably want to return error and improve types
|
||||||
return opts.responseStyle === "data"
|
return responseStyle === 'data'
|
||||||
? undefined
|
? undefined
|
||||||
: {
|
: {
|
||||||
error: finalError,
|
error: finalError,
|
||||||
...result,
|
request,
|
||||||
|
response,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const makeMethodFn = (method: Uppercase<HttpMethod>) => (options: RequestOptions) => request({ ...options, method });
|
const makeMethodFn = (method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
|
||||||
|
request({ ...options, method });
|
||||||
|
|
||||||
const makeSseFn = (method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
|
const makeSseFn = (method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
|
||||||
const { opts, url } = await beforeRequest(options);
|
const { opts, url } = await beforeRequest(options);
|
||||||
return createSseClient({
|
return createSseClient({
|
||||||
...opts,
|
...opts,
|
||||||
body: opts.body as BodyInit | null | undefined,
|
body: opts.body as BodyInit | null | undefined,
|
||||||
headers: opts.headers as unknown as Record<string, string>,
|
|
||||||
method,
|
method,
|
||||||
onRequest: async (url, init) => {
|
onRequest: async (url, init) => {
|
||||||
let request = new Request(url, init);
|
let request = new Request(url, init);
|
||||||
|
|
@ -255,31 +246,33 @@ export const createClient = (config: Config = {}): Client => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const _buildUrl: Client['buildUrl'] = (options) => buildUrl({ ..._config, ...options });
|
||||||
|
|
||||||
return {
|
return {
|
||||||
buildUrl,
|
buildUrl: _buildUrl,
|
||||||
connect: makeMethodFn("CONNECT"),
|
connect: makeMethodFn('CONNECT'),
|
||||||
delete: makeMethodFn("DELETE"),
|
delete: makeMethodFn('DELETE'),
|
||||||
get: makeMethodFn("GET"),
|
get: makeMethodFn('GET'),
|
||||||
getConfig,
|
getConfig,
|
||||||
head: makeMethodFn("HEAD"),
|
head: makeMethodFn('HEAD'),
|
||||||
interceptors,
|
interceptors,
|
||||||
options: makeMethodFn("OPTIONS"),
|
options: makeMethodFn('OPTIONS'),
|
||||||
patch: makeMethodFn("PATCH"),
|
patch: makeMethodFn('PATCH'),
|
||||||
post: makeMethodFn("POST"),
|
post: makeMethodFn('POST'),
|
||||||
put: makeMethodFn("PUT"),
|
put: makeMethodFn('PUT'),
|
||||||
request,
|
request,
|
||||||
setConfig,
|
setConfig,
|
||||||
sse: {
|
sse: {
|
||||||
connect: makeSseFn("CONNECT"),
|
connect: makeSseFn('CONNECT'),
|
||||||
delete: makeSseFn("DELETE"),
|
delete: makeSseFn('DELETE'),
|
||||||
get: makeSseFn("GET"),
|
get: makeSseFn('GET'),
|
||||||
head: makeSseFn("HEAD"),
|
head: makeSseFn('HEAD'),
|
||||||
options: makeSseFn("OPTIONS"),
|
options: makeSseFn('OPTIONS'),
|
||||||
patch: makeSseFn("PATCH"),
|
patch: makeSseFn('PATCH'),
|
||||||
post: makeSseFn("POST"),
|
post: makeSseFn('POST'),
|
||||||
put: makeSseFn("PUT"),
|
put: makeSseFn('PUT'),
|
||||||
trace: makeSseFn("TRACE"),
|
trace: makeSseFn('TRACE'),
|
||||||
},
|
},
|
||||||
trace: makeMethodFn("TRACE"),
|
trace: makeMethodFn('TRACE'),
|
||||||
} as Client;
|
} as Client;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
// @ts-nocheck
|
||||||
// This file is auto-generated by @hey-api/openapi-ts
|
// This file is auto-generated by @hey-api/openapi-ts
|
||||||
|
|
||||||
export type { Auth } from "../core/auth.gen";
|
export type { Auth } from "../core/auth.gen";
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,22 @@
|
||||||
|
// @ts-nocheck
|
||||||
// This file is auto-generated by @hey-api/openapi-ts
|
// This file is auto-generated by @hey-api/openapi-ts
|
||||||
|
|
||||||
import type { Auth } from "../core/auth.gen";
|
import type { Auth } from '../core/auth.gen';
|
||||||
import type { ServerSentEventsOptions, ServerSentEventsResult } from "../core/serverSentEvents.gen";
|
import type {
|
||||||
import type { Client as CoreClient, Config as CoreConfig } from "../core/types.gen";
|
ServerSentEventsOptions,
|
||||||
import type { Middleware } from "./utils.gen";
|
ServerSentEventsResult,
|
||||||
|
} from '../core/serverSentEvents.gen';
|
||||||
|
import type { Client as CoreClient, Config as CoreConfig } from '../core/types.gen';
|
||||||
|
import type { Middleware } from './utils.gen';
|
||||||
|
|
||||||
export type ResponseStyle = "data" | "fields";
|
export type ResponseStyle = 'data' | 'fields';
|
||||||
|
|
||||||
export interface Config<T extends ClientOptions = ClientOptions>
|
export interface Config<T extends ClientOptions = ClientOptions>
|
||||||
extends Omit<RequestInit, "body" | "headers" | "method">, CoreConfig {
|
extends Omit<RequestInit, 'body' | 'headers' | 'method'>, CoreConfig {
|
||||||
/**
|
/**
|
||||||
* Base URL for all requests made by this client.
|
* Base URL for all requests made by this client.
|
||||||
*/
|
*/
|
||||||
baseUrl?: T["baseUrl"];
|
baseUrl?: T['baseUrl'];
|
||||||
/**
|
/**
|
||||||
* Fetch API implementation. You can use this option to provide a custom
|
* Fetch API implementation. You can use this option to provide a custom
|
||||||
* fetch instance.
|
* fetch instance.
|
||||||
|
|
@ -35,7 +39,7 @@ export interface Config<T extends ClientOptions = ClientOptions>
|
||||||
*
|
*
|
||||||
* @default 'auto'
|
* @default 'auto'
|
||||||
*/
|
*/
|
||||||
parseAs?: "arrayBuffer" | "auto" | "blob" | "formData" | "json" | "stream" | "text";
|
parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text';
|
||||||
/**
|
/**
|
||||||
* Should we return only data or multiple fields (data, error, response, etc.)?
|
* Should we return only data or multiple fields (data, error, response, etc.)?
|
||||||
*
|
*
|
||||||
|
|
@ -47,12 +51,12 @@ export interface Config<T extends ClientOptions = ClientOptions>
|
||||||
*
|
*
|
||||||
* @default false
|
* @default false
|
||||||
*/
|
*/
|
||||||
throwOnError?: T["throwOnError"];
|
throwOnError?: T['throwOnError'];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RequestOptions<
|
export interface RequestOptions<
|
||||||
TData = unknown,
|
TData = unknown,
|
||||||
TResponseStyle extends ResponseStyle = "fields",
|
TResponseStyle extends ResponseStyle = 'fields',
|
||||||
ThrowOnError extends boolean = boolean,
|
ThrowOnError extends boolean = boolean,
|
||||||
Url extends string = string,
|
Url extends string = string,
|
||||||
>
|
>
|
||||||
|
|
@ -63,7 +67,12 @@ export interface RequestOptions<
|
||||||
}>,
|
}>,
|
||||||
Pick<
|
Pick<
|
||||||
ServerSentEventsOptions<TData>,
|
ServerSentEventsOptions<TData>,
|
||||||
"onSseError" | "onSseEvent" | "sseDefaultRetryDelay" | "sseMaxRetryAttempts" | "sseMaxRetryDelay"
|
| 'onRequest'
|
||||||
|
| 'onSseError'
|
||||||
|
| 'onSseEvent'
|
||||||
|
| 'sseDefaultRetryDelay'
|
||||||
|
| 'sseMaxRetryAttempts'
|
||||||
|
| 'sseMaxRetryDelay'
|
||||||
> {
|
> {
|
||||||
/**
|
/**
|
||||||
* Any body that you want to add to your request.
|
* Any body that you want to add to your request.
|
||||||
|
|
@ -81,10 +90,11 @@ export interface RequestOptions<
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ResolvedRequestOptions<
|
export interface ResolvedRequestOptions<
|
||||||
TResponseStyle extends ResponseStyle = "fields",
|
TResponseStyle extends ResponseStyle = 'fields',
|
||||||
ThrowOnError extends boolean = boolean,
|
ThrowOnError extends boolean = boolean,
|
||||||
Url extends string = string,
|
Url extends string = string,
|
||||||
> extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> {
|
> extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> {
|
||||||
|
headers: Headers;
|
||||||
serializedBody?: string;
|
serializedBody?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,10 +102,10 @@ export type RequestResult<
|
||||||
TData = unknown,
|
TData = unknown,
|
||||||
TError = unknown,
|
TError = unknown,
|
||||||
ThrowOnError extends boolean = boolean,
|
ThrowOnError extends boolean = boolean,
|
||||||
TResponseStyle extends ResponseStyle = "fields",
|
TResponseStyle extends ResponseStyle = 'fields',
|
||||||
> = ThrowOnError extends true
|
> = ThrowOnError extends true
|
||||||
? Promise<
|
? Promise<
|
||||||
TResponseStyle extends "data"
|
TResponseStyle extends 'data'
|
||||||
? TData extends Record<string, unknown>
|
? TData extends Record<string, unknown>
|
||||||
? TData[keyof TData]
|
? TData[keyof TData]
|
||||||
: TData
|
: TData
|
||||||
|
|
@ -106,7 +116,7 @@ export type RequestResult<
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
: Promise<
|
: Promise<
|
||||||
TResponseStyle extends "data"
|
TResponseStyle extends 'data'
|
||||||
? (TData extends Record<string, unknown> ? TData[keyof TData] : TData) | undefined
|
? (TData extends Record<string, unknown> ? TData[keyof TData] : TData) | undefined
|
||||||
: (
|
: (
|
||||||
| {
|
| {
|
||||||
|
|
@ -118,8 +128,10 @@ export type RequestResult<
|
||||||
error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
|
error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
|
||||||
}
|
}
|
||||||
) & {
|
) & {
|
||||||
request: Request;
|
/** request may be undefined, because error may be from building the request object itself */
|
||||||
response: Response;
|
request?: Request;
|
||||||
|
/** response may be undefined, because error may be from building the request object itself or from a network error */
|
||||||
|
response?: Response;
|
||||||
}
|
}
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
|
@ -133,28 +145,28 @@ type MethodFn = <
|
||||||
TData = unknown,
|
TData = unknown,
|
||||||
TError = unknown,
|
TError = unknown,
|
||||||
ThrowOnError extends boolean = false,
|
ThrowOnError extends boolean = false,
|
||||||
TResponseStyle extends ResponseStyle = "fields",
|
TResponseStyle extends ResponseStyle = 'fields',
|
||||||
>(
|
>(
|
||||||
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method">,
|
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>,
|
||||||
) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
||||||
|
|
||||||
type SseFn = <
|
type SseFn = <
|
||||||
TData = unknown,
|
TData = unknown,
|
||||||
TError = unknown,
|
TError = unknown,
|
||||||
ThrowOnError extends boolean = false,
|
ThrowOnError extends boolean = false,
|
||||||
TResponseStyle extends ResponseStyle = "fields",
|
TResponseStyle extends ResponseStyle = 'fields',
|
||||||
>(
|
>(
|
||||||
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method">,
|
options: Omit<RequestOptions<never, TResponseStyle, ThrowOnError>, 'method'>,
|
||||||
) => Promise<ServerSentEventsResult<TData, TError>>;
|
) => Promise<ServerSentEventsResult<TData, TError>>;
|
||||||
|
|
||||||
type RequestFn = <
|
type RequestFn = <
|
||||||
TData = unknown,
|
TData = unknown,
|
||||||
TError = unknown,
|
TError = unknown,
|
||||||
ThrowOnError extends boolean = false,
|
ThrowOnError extends boolean = false,
|
||||||
TResponseStyle extends ResponseStyle = "fields",
|
TResponseStyle extends ResponseStyle = 'fields',
|
||||||
>(
|
>(
|
||||||
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method"> &
|
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'> &
|
||||||
Pick<Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>, "method">,
|
Pick<Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>, 'method'>,
|
||||||
) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
||||||
|
|
||||||
type BuildUrlFn = <
|
type BuildUrlFn = <
|
||||||
|
|
@ -198,6 +210,9 @@ export type Options<
|
||||||
TData extends TDataShape = TDataShape,
|
TData extends TDataShape = TDataShape,
|
||||||
ThrowOnError extends boolean = boolean,
|
ThrowOnError extends boolean = boolean,
|
||||||
TResponse = unknown,
|
TResponse = unknown,
|
||||||
TResponseStyle extends ResponseStyle = "fields",
|
TResponseStyle extends ResponseStyle = 'fields',
|
||||||
> = OmitKeys<RequestOptions<TResponse, TResponseStyle, ThrowOnError>, "body" | "path" | "query" | "url"> &
|
> = OmitKeys<
|
||||||
([TData] extends [never] ? unknown : Omit<TData, "url">);
|
RequestOptions<TResponse, TResponseStyle, ThrowOnError>,
|
||||||
|
'body' | 'path' | 'query' | 'url'
|
||||||
|
> &
|
||||||
|
([TData] extends [never] ? unknown : Omit<TData, 'url'>);
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,24 @@
|
||||||
|
// @ts-nocheck
|
||||||
// This file is auto-generated by @hey-api/openapi-ts
|
// This file is auto-generated by @hey-api/openapi-ts
|
||||||
|
|
||||||
import { getAuthToken } from "../core/auth.gen";
|
import { getAuthToken } from '../core/auth.gen';
|
||||||
import type { QuerySerializerOptions } from "../core/bodySerializer.gen";
|
import type { QuerySerializerOptions } from '../core/bodySerializer.gen';
|
||||||
import { jsonBodySerializer } from "../core/bodySerializer.gen";
|
import { jsonBodySerializer } from '../core/bodySerializer.gen';
|
||||||
import { serializeArrayParam, serializeObjectParam, serializePrimitiveParam } from "../core/pathSerializer.gen";
|
import {
|
||||||
import { getUrl } from "../core/utils.gen";
|
serializeArrayParam,
|
||||||
import type { Client, ClientOptions, Config, RequestOptions } from "./types.gen";
|
serializeObjectParam,
|
||||||
|
serializePrimitiveParam,
|
||||||
|
} from '../core/pathSerializer.gen';
|
||||||
|
import { getUrl } from '../core/utils.gen';
|
||||||
|
import type { Client, ClientOptions, Config, RequestOptions } from './types.gen';
|
||||||
|
|
||||||
export const createQuerySerializer = <T = unknown>({ parameters = {}, ...args }: QuerySerializerOptions = {}) => {
|
export const createQuerySerializer = <T = unknown>({
|
||||||
|
parameters = {},
|
||||||
|
...args
|
||||||
|
}: QuerySerializerOptions = {}) => {
|
||||||
const querySerializer = (queryParams: T) => {
|
const querySerializer = (queryParams: T) => {
|
||||||
const search: string[] = [];
|
const search: string[] = [];
|
||||||
if (queryParams && typeof queryParams === "object") {
|
if (queryParams && typeof queryParams === 'object') {
|
||||||
for (const name in queryParams) {
|
for (const name in queryParams) {
|
||||||
const value = queryParams[name];
|
const value = queryParams[name];
|
||||||
|
|
||||||
|
|
@ -25,17 +33,17 @@ export const createQuerySerializer = <T = unknown>({ parameters = {}, ...args }:
|
||||||
allowReserved: options.allowReserved,
|
allowReserved: options.allowReserved,
|
||||||
explode: true,
|
explode: true,
|
||||||
name,
|
name,
|
||||||
style: "form",
|
style: 'form',
|
||||||
value,
|
value,
|
||||||
...options.array,
|
...options.array,
|
||||||
});
|
});
|
||||||
if (serializedArray) search.push(serializedArray);
|
if (serializedArray) search.push(serializedArray);
|
||||||
} else if (typeof value === "object") {
|
} else if (typeof value === 'object') {
|
||||||
const serializedObject = serializeObjectParam({
|
const serializedObject = serializeObjectParam({
|
||||||
allowReserved: options.allowReserved,
|
allowReserved: options.allowReserved,
|
||||||
explode: true,
|
explode: true,
|
||||||
name,
|
name,
|
||||||
style: "deepObject",
|
style: 'deepObject',
|
||||||
value: value as Record<string, unknown>,
|
value: value as Record<string, unknown>,
|
||||||
...options.object,
|
...options.object,
|
||||||
});
|
});
|
||||||
|
|
@ -50,7 +58,7 @@ export const createQuerySerializer = <T = unknown>({ parameters = {}, ...args }:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return search.join("&");
|
return search.join('&');
|
||||||
};
|
};
|
||||||
return querySerializer;
|
return querySerializer;
|
||||||
};
|
};
|
||||||
|
|
@ -58,40 +66,42 @@ export const createQuerySerializer = <T = unknown>({ parameters = {}, ...args }:
|
||||||
/**
|
/**
|
||||||
* Infers parseAs value from provided Content-Type header.
|
* Infers parseAs value from provided Content-Type header.
|
||||||
*/
|
*/
|
||||||
export const getParseAs = (contentType: string | null): Exclude<Config["parseAs"], "auto"> => {
|
export const getParseAs = (contentType: string | null): Exclude<Config['parseAs'], 'auto'> => {
|
||||||
if (!contentType) {
|
if (!contentType) {
|
||||||
// If no Content-Type header is provided, the best we can do is return the raw response body,
|
// If no Content-Type header is provided, the best we can do is return the raw response body,
|
||||||
// which is effectively the same as the 'stream' option.
|
// which is effectively the same as the 'stream' option.
|
||||||
return "stream";
|
return 'stream';
|
||||||
}
|
}
|
||||||
|
|
||||||
const cleanContent = contentType.split(";")[0]?.trim();
|
const cleanContent = contentType.split(';')[0]?.trim();
|
||||||
|
|
||||||
if (!cleanContent) {
|
if (!cleanContent) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
|
if (cleanContent.startsWith('application/json') || cleanContent.endsWith('+json')) {
|
||||||
return "json";
|
return 'json';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cleanContent === "multipart/form-data") {
|
if (cleanContent === 'multipart/form-data') {
|
||||||
return "formData";
|
return 'formData';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
|
if (
|
||||||
return "blob";
|
['application/', 'audio/', 'image/', 'video/'].some((type) => cleanContent.startsWith(type))
|
||||||
|
) {
|
||||||
|
return 'blob';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cleanContent.startsWith("text/")) {
|
if (cleanContent.startsWith('text/')) {
|
||||||
return "text";
|
return 'text';
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkForExistence = (
|
const checkForExistence = (
|
||||||
options: Pick<RequestOptions, "auth" | "query"> & {
|
options: Pick<RequestOptions, 'auth' | 'query'> & {
|
||||||
headers: Headers;
|
headers: Headers;
|
||||||
},
|
},
|
||||||
name?: string,
|
name?: string,
|
||||||
|
|
@ -99,20 +109,22 @@ const checkForExistence = (
|
||||||
if (!name) {
|
if (!name) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
|
if (
|
||||||
|
options.headers.has(name) ||
|
||||||
|
options.query?.[name] ||
|
||||||
|
options.headers.get('Cookie')?.includes(`${name}=`)
|
||||||
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const setAuthParams = async ({
|
export async function setAuthParams(
|
||||||
security,
|
options: Pick<RequestOptions, 'auth' | 'query' | 'security'> & {
|
||||||
...options
|
|
||||||
}: Pick<Required<RequestOptions>, "security"> &
|
|
||||||
Pick<RequestOptions, "auth" | "query"> & {
|
|
||||||
headers: Headers;
|
headers: Headers;
|
||||||
}) => {
|
},
|
||||||
for (const auth of security) {
|
): Promise<void> {
|
||||||
|
for (const auth of options.security ?? []) {
|
||||||
if (checkForExistence(options, auth.name)) {
|
if (checkForExistence(options, auth.name)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -123,33 +135,33 @@ export const setAuthParams = async ({
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const name = auth.name ?? "Authorization";
|
const name = auth.name ?? 'Authorization';
|
||||||
|
|
||||||
switch (auth.in) {
|
switch (auth.in) {
|
||||||
case "query":
|
case 'query':
|
||||||
if (!options.query) {
|
if (!options.query) {
|
||||||
options.query = {};
|
options.query = {};
|
||||||
}
|
}
|
||||||
options.query[name] = token;
|
options.query[name] = token;
|
||||||
break;
|
break;
|
||||||
case "cookie":
|
case 'cookie':
|
||||||
options.headers.append("Cookie", `${name}=${token}`);
|
options.headers.append('Cookie', `${name}=${token}`);
|
||||||
break;
|
break;
|
||||||
case "header":
|
case 'header':
|
||||||
default:
|
default:
|
||||||
options.headers.set(name, token);
|
options.headers.set(name, token);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export const buildUrl: Client["buildUrl"] = (options) =>
|
export const buildUrl: Client['buildUrl'] = (options) =>
|
||||||
getUrl({
|
getUrl({
|
||||||
baseUrl: options.baseUrl as string,
|
baseUrl: options.baseUrl as string,
|
||||||
path: options.path,
|
path: options.path,
|
||||||
query: options.query,
|
query: options.query,
|
||||||
querySerializer:
|
querySerializer:
|
||||||
typeof options.querySerializer === "function"
|
typeof options.querySerializer === 'function'
|
||||||
? options.querySerializer
|
? options.querySerializer
|
||||||
: createQuerySerializer(options.querySerializer),
|
: createQuerySerializer(options.querySerializer),
|
||||||
url: options.url,
|
url: options.url,
|
||||||
|
|
@ -157,7 +169,7 @@ export const buildUrl: Client["buildUrl"] = (options) =>
|
||||||
|
|
||||||
export const mergeConfigs = (a: Config, b: Config): Config => {
|
export const mergeConfigs = (a: Config, b: Config): Config => {
|
||||||
const config = { ...a, ...b };
|
const config = { ...a, ...b };
|
||||||
if (config.baseUrl?.endsWith("/")) {
|
if (config.baseUrl?.endsWith('/')) {
|
||||||
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
||||||
}
|
}
|
||||||
config.headers = mergeHeaders(a.headers, b.headers);
|
config.headers = mergeHeaders(a.headers, b.headers);
|
||||||
|
|
@ -172,7 +184,9 @@ const headersEntries = (headers: Headers): Array<[string, string]> => {
|
||||||
return entries;
|
return entries;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const mergeHeaders = (...headers: Array<Required<Config>["headers"] | undefined>): Headers => {
|
export const mergeHeaders = (
|
||||||
|
...headers: Array<Required<Config>['headers'] | undefined>
|
||||||
|
): Headers => {
|
||||||
const mergedHeaders = new Headers();
|
const mergedHeaders = new Headers();
|
||||||
for (const header of headers) {
|
for (const header of headers) {
|
||||||
if (!header) {
|
if (!header) {
|
||||||
|
|
@ -189,9 +203,12 @@ export const mergeHeaders = (...headers: Array<Required<Config>["headers"] | und
|
||||||
mergedHeaders.append(key, v as string);
|
mergedHeaders.append(key, v as string);
|
||||||
}
|
}
|
||||||
} else if (value !== undefined) {
|
} else if (value !== undefined) {
|
||||||
// assume object headers are meant to be JSON stringified, i.e. their
|
// assume object headers are meant to be JSON stringified, i.e., their
|
||||||
// content value in OpenAPI specification is 'application/json'
|
// content value in OpenAPI specification is 'application/json'
|
||||||
mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : (value as string));
|
mergedHeaders.set(
|
||||||
|
key,
|
||||||
|
typeof value === 'object' ? JSON.stringify(value) : (value as string),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -200,14 +217,20 @@ export const mergeHeaders = (...headers: Array<Required<Config>["headers"] | und
|
||||||
|
|
||||||
type ErrInterceptor<Err, Res, Req, Options> = (
|
type ErrInterceptor<Err, Res, Req, Options> = (
|
||||||
error: Err,
|
error: Err,
|
||||||
response: Res,
|
/** response may be undefined due to a network error where no response object is produced */
|
||||||
request: Req,
|
response: Res | undefined,
|
||||||
|
/** request may be undefined, because error may be from building the request object itself */
|
||||||
|
request: Req | undefined,
|
||||||
options: Options,
|
options: Options,
|
||||||
) => Err | Promise<Err>;
|
) => Err | Promise<Err>;
|
||||||
|
|
||||||
type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>;
|
type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>;
|
||||||
|
|
||||||
type ResInterceptor<Res, Req, Options> = (response: Res, request: Req, options: Options) => Res | Promise<Res>;
|
type ResInterceptor<Res, Req, Options> = (
|
||||||
|
response: Res,
|
||||||
|
request: Req,
|
||||||
|
options: Options,
|
||||||
|
) => Res | Promise<Res>;
|
||||||
|
|
||||||
class Interceptors<Interceptor> {
|
class Interceptors<Interceptor> {
|
||||||
fns: Array<Interceptor | null> = [];
|
fns: Array<Interceptor | null> = [];
|
||||||
|
|
@ -229,7 +252,7 @@ class Interceptors<Interceptor> {
|
||||||
}
|
}
|
||||||
|
|
||||||
getInterceptorIndex(id: number | Interceptor): number {
|
getInterceptorIndex(id: number | Interceptor): number {
|
||||||
if (typeof id === "number") {
|
if (typeof id === 'number') {
|
||||||
return this.fns[id] ? id : -1;
|
return this.fns[id] ? id : -1;
|
||||||
}
|
}
|
||||||
return this.fns.indexOf(id);
|
return this.fns.indexOf(id);
|
||||||
|
|
@ -256,7 +279,12 @@ export interface Middleware<Req, Res, Err, Options> {
|
||||||
response: Interceptors<ResInterceptor<Res, Req, Options>>;
|
response: Interceptors<ResInterceptor<Res, Req, Options>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createInterceptors = <Req, Res, Err, Options>(): Middleware<Req, Res, Err, Options> => ({
|
export const createInterceptors = <Req, Res, Err, Options>(): Middleware<
|
||||||
|
Req,
|
||||||
|
Res,
|
||||||
|
Err,
|
||||||
|
Options
|
||||||
|
> => ({
|
||||||
error: new Interceptors<ErrInterceptor<Err, Res, Req, Options>>(),
|
error: new Interceptors<ErrInterceptor<Err, Res, Req, Options>>(),
|
||||||
request: new Interceptors<ReqInterceptor<Req, Options>>(),
|
request: new Interceptors<ReqInterceptor<Req, Options>>(),
|
||||||
response: new Interceptors<ResInterceptor<Res, Req, Options>>(),
|
response: new Interceptors<ResInterceptor<Res, Req, Options>>(),
|
||||||
|
|
@ -266,16 +294,16 @@ const defaultQuerySerializer = createQuerySerializer({
|
||||||
allowReserved: false,
|
allowReserved: false,
|
||||||
array: {
|
array: {
|
||||||
explode: true,
|
explode: true,
|
||||||
style: "form",
|
style: 'form',
|
||||||
},
|
},
|
||||||
object: {
|
object: {
|
||||||
explode: true,
|
explode: true,
|
||||||
style: "deepObject",
|
style: 'deepObject',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const defaultHeaders = {
|
const defaultHeaders = {
|
||||||
"Content-Type": "application/json",
|
'Content-Type': 'application/json',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createConfig = <T extends ClientOptions = ClientOptions>(
|
export const createConfig = <T extends ClientOptions = ClientOptions>(
|
||||||
|
|
@ -283,7 +311,7 @@ export const createConfig = <T extends ClientOptions = ClientOptions>(
|
||||||
): Config<Omit<ClientOptions, keyof T> & T> => ({
|
): Config<Omit<ClientOptions, keyof T> & T> => ({
|
||||||
...jsonBodySerializer,
|
...jsonBodySerializer,
|
||||||
headers: defaultHeaders,
|
headers: defaultHeaders,
|
||||||
parseAs: "auto",
|
parseAs: 'auto',
|
||||||
querySerializer: defaultQuerySerializer,
|
querySerializer: defaultQuerySerializer,
|
||||||
...override,
|
...override,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
// @ts-nocheck
|
||||||
// This file is auto-generated by @hey-api/openapi-ts
|
// This file is auto-generated by @hey-api/openapi-ts
|
||||||
|
|
||||||
export type AuthToken = string | undefined;
|
export type AuthToken = string | undefined;
|
||||||
|
|
@ -8,32 +9,32 @@ export interface Auth {
|
||||||
*
|
*
|
||||||
* @default 'header'
|
* @default 'header'
|
||||||
*/
|
*/
|
||||||
in?: "header" | "query" | "cookie";
|
in?: 'header' | 'query' | 'cookie';
|
||||||
/**
|
/**
|
||||||
* Header or query parameter name.
|
* Header or query parameter name.
|
||||||
*
|
*
|
||||||
* @default 'Authorization'
|
* @default 'Authorization'
|
||||||
*/
|
*/
|
||||||
name?: string;
|
name?: string;
|
||||||
scheme?: "basic" | "bearer";
|
scheme?: 'basic' | 'bearer';
|
||||||
type: "apiKey" | "http";
|
type: 'apiKey' | 'http';
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getAuthToken = async (
|
export const getAuthToken = async (
|
||||||
auth: Auth,
|
auth: Auth,
|
||||||
callback: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken,
|
callback: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken,
|
||||||
): Promise<string | undefined> => {
|
): Promise<string | undefined> => {
|
||||||
const token = typeof callback === "function" ? await callback(auth) : callback;
|
const token = typeof callback === 'function' ? await callback(auth) : callback;
|
||||||
|
|
||||||
if (!token) {
|
if (!token) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auth.scheme === "bearer") {
|
if (auth.scheme === 'bearer') {
|
||||||
return `Bearer ${token}`;
|
return `Bearer ${token}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auth.scheme === "basic") {
|
if (auth.scheme === 'basic') {
|
||||||
return `Basic ${btoa(token)}`;
|
return `Basic ${btoa(token)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
|
// @ts-nocheck
|
||||||
// This file is auto-generated by @hey-api/openapi-ts
|
// This file is auto-generated by @hey-api/openapi-ts
|
||||||
|
|
||||||
import type { ArrayStyle, ObjectStyle, SerializerOptions } from "./pathSerializer.gen";
|
import type { ArrayStyle, ObjectStyle, SerializerOptions } from './pathSerializer.gen';
|
||||||
|
|
||||||
export type QuerySerializer = (query: Record<string, unknown>) => string;
|
export type QuerySerializer = (query: Record<string, unknown>) => string;
|
||||||
|
|
||||||
export type BodySerializer = (body: any) => any;
|
export type BodySerializer = (body: unknown) => unknown;
|
||||||
|
|
||||||
type QuerySerializerOptionsObject = {
|
type QuerySerializerOptionsObject = {
|
||||||
allowReserved?: boolean;
|
allowReserved?: boolean;
|
||||||
|
|
@ -21,7 +22,7 @@ export type QuerySerializerOptions = QuerySerializerOptionsObject & {
|
||||||
};
|
};
|
||||||
|
|
||||||
const serializeFormDataPair = (data: FormData, key: string, value: unknown): void => {
|
const serializeFormDataPair = (data: FormData, key: string, value: unknown): void => {
|
||||||
if (typeof value === "string" || value instanceof Blob) {
|
if (typeof value === 'string' || value instanceof Blob) {
|
||||||
data.append(key, value);
|
data.append(key, value);
|
||||||
} else if (value instanceof Date) {
|
} else if (value instanceof Date) {
|
||||||
data.append(key, value.toISOString());
|
data.append(key, value.toISOString());
|
||||||
|
|
@ -31,7 +32,7 @@ const serializeFormDataPair = (data: FormData, key: string, value: unknown): voi
|
||||||
};
|
};
|
||||||
|
|
||||||
const serializeUrlSearchParamsPair = (data: URLSearchParams, key: string, value: unknown): void => {
|
const serializeUrlSearchParamsPair = (data: URLSearchParams, key: string, value: unknown): void => {
|
||||||
if (typeof value === "string") {
|
if (typeof value === 'string') {
|
||||||
data.append(key, value);
|
data.append(key, value);
|
||||||
} else {
|
} else {
|
||||||
data.append(key, JSON.stringify(value));
|
data.append(key, JSON.stringify(value));
|
||||||
|
|
@ -39,10 +40,10 @@ const serializeUrlSearchParamsPair = (data: URLSearchParams, key: string, value:
|
||||||
};
|
};
|
||||||
|
|
||||||
export const formDataBodySerializer = {
|
export const formDataBodySerializer = {
|
||||||
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T): FormData => {
|
bodySerializer: (body: unknown): FormData => {
|
||||||
const data = new FormData();
|
const data = new FormData();
|
||||||
|
|
||||||
Object.entries(body).forEach(([key, value]) => {
|
Object.entries(body as Record<string, unknown>).forEach(([key, value]) => {
|
||||||
if (value === undefined || value === null) {
|
if (value === undefined || value === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -58,15 +59,15 @@ export const formDataBodySerializer = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const jsonBodySerializer = {
|
export const jsonBodySerializer = {
|
||||||
bodySerializer: <T>(body: T): string =>
|
bodySerializer: (body: unknown): string =>
|
||||||
JSON.stringify(body, (_key, value) => (typeof value === "bigint" ? value.toString() : value)),
|
JSON.stringify(body, (_key, value) => (typeof value === 'bigint' ? value.toString() : value)),
|
||||||
};
|
};
|
||||||
|
|
||||||
export const urlSearchParamsBodySerializer = {
|
export const urlSearchParamsBodySerializer = {
|
||||||
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T): string => {
|
bodySerializer: (body: unknown): string => {
|
||||||
const data = new URLSearchParams();
|
const data = new URLSearchParams();
|
||||||
|
|
||||||
Object.entries(body).forEach(([key, value]) => {
|
Object.entries(body as Record<string, unknown>).forEach(([key, value]) => {
|
||||||
if (value === undefined || value === null) {
|
if (value === undefined || value === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
|
// @ts-nocheck
|
||||||
// This file is auto-generated by @hey-api/openapi-ts
|
// This file is auto-generated by @hey-api/openapi-ts
|
||||||
|
|
||||||
type Slot = "body" | "headers" | "path" | "query";
|
type Slot = 'body' | 'headers' | 'path' | 'query';
|
||||||
|
|
||||||
export type Field =
|
export type Field =
|
||||||
| {
|
| {
|
||||||
in: Exclude<Slot, "body">;
|
in: Exclude<Slot, 'body'>;
|
||||||
/**
|
/**
|
||||||
* Field name. This is the name we want the user to see and use.
|
* Field name. This is the name we want the user to see and use.
|
||||||
*/
|
*/
|
||||||
|
|
@ -16,7 +17,7 @@ export type Field =
|
||||||
map?: string;
|
map?: string;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
in: Extract<Slot, "body">;
|
in: Extract<Slot, 'body'>;
|
||||||
/**
|
/**
|
||||||
* Key isn't required for bodies.
|
* Key isn't required for bodies.
|
||||||
*/
|
*/
|
||||||
|
|
@ -43,10 +44,10 @@ export interface Fields {
|
||||||
export type FieldsConfig = ReadonlyArray<Field | Fields>;
|
export type FieldsConfig = ReadonlyArray<Field | Fields>;
|
||||||
|
|
||||||
const extraPrefixesMap: Record<string, Slot> = {
|
const extraPrefixesMap: Record<string, Slot> = {
|
||||||
$body_: "body",
|
$body_: 'body',
|
||||||
$headers_: "headers",
|
$headers_: 'headers',
|
||||||
$path_: "path",
|
$path_: 'path',
|
||||||
$query_: "query",
|
$query_: 'query',
|
||||||
};
|
};
|
||||||
const extraPrefixes = Object.entries(extraPrefixesMap);
|
const extraPrefixes = Object.entries(extraPrefixesMap);
|
||||||
|
|
||||||
|
|
@ -68,14 +69,14 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const config of fields) {
|
for (const config of fields) {
|
||||||
if ("in" in config) {
|
if ('in' in config) {
|
||||||
if (config.key) {
|
if (config.key) {
|
||||||
map.set(config.key, {
|
map.set(config.key, {
|
||||||
in: config.in,
|
in: config.in,
|
||||||
map: config.map,
|
map: config.map,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if ("key" in config) {
|
} else if ('key' in config) {
|
||||||
map.set(config.key, {
|
map.set(config.key, {
|
||||||
map: config.map,
|
map: config.map,
|
||||||
});
|
});
|
||||||
|
|
@ -96,7 +97,7 @@ interface Params {
|
||||||
|
|
||||||
const stripEmptySlots = (params: Params) => {
|
const stripEmptySlots = (params: Params) => {
|
||||||
for (const [slot, value] of Object.entries(params)) {
|
for (const [slot, value] of Object.entries(params)) {
|
||||||
if (value && typeof value === "object" && !Object.keys(value).length) {
|
if (value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).length) {
|
||||||
delete params[slot as Slot];
|
delete params[slot as Slot];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -123,7 +124,7 @@ export const buildClientParams = (args: ReadonlyArray<unknown>, fields: FieldsCo
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("in" in config) {
|
if ('in' in config) {
|
||||||
if (config.key) {
|
if (config.key) {
|
||||||
const field = map.get(config.key)!;
|
const field = map.get(config.key)!;
|
||||||
const name = field.map || config.key;
|
const name = field.map || config.key;
|
||||||
|
|
@ -150,7 +151,7 @@ export const buildClientParams = (args: ReadonlyArray<unknown>, fields: FieldsCo
|
||||||
if (extra) {
|
if (extra) {
|
||||||
const [prefix, slot] = extra;
|
const [prefix, slot] = extra;
|
||||||
(params[slot] as Record<string, unknown>)[key.slice(prefix.length)] = value;
|
(params[slot] as Record<string, unknown>)[key.slice(prefix.length)] = value;
|
||||||
} else if ("allowExtra" in config && config.allowExtra) {
|
} else if ('allowExtra' in config && config.allowExtra) {
|
||||||
for (const [slot, allowed] of Object.entries(config.allowExtra)) {
|
for (const [slot, allowed] of Object.entries(config.allowExtra)) {
|
||||||
if (allowed) {
|
if (allowed) {
|
||||||
(params[slot as Slot] as Record<string, unknown>)[key] = value;
|
(params[slot as Slot] as Record<string, unknown>)[key] = value;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
// @ts-nocheck
|
||||||
// This file is auto-generated by @hey-api/openapi-ts
|
// This file is auto-generated by @hey-api/openapi-ts
|
||||||
|
|
||||||
interface SerializeOptions<T> extends SerializePrimitiveOptions, SerializerOptions<T> {}
|
interface SerializeOptions<T> extends SerializePrimitiveOptions, SerializerOptions<T> {}
|
||||||
|
|
@ -15,10 +16,10 @@ export interface SerializerOptions<T> {
|
||||||
style: T;
|
style: T;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ArrayStyle = "form" | "spaceDelimited" | "pipeDelimited";
|
export type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited';
|
||||||
export type ArraySeparatorStyle = ArrayStyle | MatrixStyle;
|
export type ArraySeparatorStyle = ArrayStyle | MatrixStyle;
|
||||||
type MatrixStyle = "label" | "matrix" | "simple";
|
type MatrixStyle = 'label' | 'matrix' | 'simple';
|
||||||
export type ObjectStyle = "form" | "deepObject";
|
export type ObjectStyle = 'form' | 'deepObject';
|
||||||
type ObjectSeparatorStyle = ObjectStyle | MatrixStyle;
|
type ObjectSeparatorStyle = ObjectStyle | MatrixStyle;
|
||||||
|
|
||||||
interface SerializePrimitiveParam extends SerializePrimitiveOptions {
|
interface SerializePrimitiveParam extends SerializePrimitiveOptions {
|
||||||
|
|
@ -27,40 +28,40 @@ interface SerializePrimitiveParam extends SerializePrimitiveOptions {
|
||||||
|
|
||||||
export const separatorArrayExplode = (style: ArraySeparatorStyle) => {
|
export const separatorArrayExplode = (style: ArraySeparatorStyle) => {
|
||||||
switch (style) {
|
switch (style) {
|
||||||
case "label":
|
case 'label':
|
||||||
return ".";
|
return '.';
|
||||||
case "matrix":
|
case 'matrix':
|
||||||
return ";";
|
return ';';
|
||||||
case "simple":
|
case 'simple':
|
||||||
return ",";
|
return ',';
|
||||||
default:
|
default:
|
||||||
return "&";
|
return '&';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => {
|
export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => {
|
||||||
switch (style) {
|
switch (style) {
|
||||||
case "form":
|
case 'form':
|
||||||
return ",";
|
return ',';
|
||||||
case "pipeDelimited":
|
case 'pipeDelimited':
|
||||||
return "|";
|
return '|';
|
||||||
case "spaceDelimited":
|
case 'spaceDelimited':
|
||||||
return "%20";
|
return '%20';
|
||||||
default:
|
default:
|
||||||
return ",";
|
return ',';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const separatorObjectExplode = (style: ObjectSeparatorStyle) => {
|
export const separatorObjectExplode = (style: ObjectSeparatorStyle) => {
|
||||||
switch (style) {
|
switch (style) {
|
||||||
case "label":
|
case 'label':
|
||||||
return ".";
|
return '.';
|
||||||
case "matrix":
|
case 'matrix':
|
||||||
return ";";
|
return ';';
|
||||||
case "simple":
|
case 'simple':
|
||||||
return ",";
|
return ',';
|
||||||
default:
|
default:
|
||||||
return "&";
|
return '&';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -74,15 +75,15 @@ export const serializeArrayParam = ({
|
||||||
value: unknown[];
|
value: unknown[];
|
||||||
}) => {
|
}) => {
|
||||||
if (!explode) {
|
if (!explode) {
|
||||||
const joinedValues = (allowReserved ? value : value.map((v) => encodeURIComponent(v as string))).join(
|
const joinedValues = (
|
||||||
separatorArrayNoExplode(style),
|
allowReserved ? value : value.map((v) => encodeURIComponent(v as string))
|
||||||
);
|
).join(separatorArrayNoExplode(style));
|
||||||
switch (style) {
|
switch (style) {
|
||||||
case "label":
|
case 'label':
|
||||||
return `.${joinedValues}`;
|
return `.${joinedValues}`;
|
||||||
case "matrix":
|
case 'matrix':
|
||||||
return `;${name}=${joinedValues}`;
|
return `;${name}=${joinedValues}`;
|
||||||
case "simple":
|
case 'simple':
|
||||||
return joinedValues;
|
return joinedValues;
|
||||||
default:
|
default:
|
||||||
return `${name}=${joinedValues}`;
|
return `${name}=${joinedValues}`;
|
||||||
|
|
@ -92,7 +93,7 @@ export const serializeArrayParam = ({
|
||||||
const separator = separatorArrayExplode(style);
|
const separator = separatorArrayExplode(style);
|
||||||
const joinedValues = value
|
const joinedValues = value
|
||||||
.map((v) => {
|
.map((v) => {
|
||||||
if (style === "label" || style === "simple") {
|
if (style === 'label' || style === 'simple') {
|
||||||
return allowReserved ? v : encodeURIComponent(v as string);
|
return allowReserved ? v : encodeURIComponent(v as string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -103,17 +104,21 @@ export const serializeArrayParam = ({
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.join(separator);
|
.join(separator);
|
||||||
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
return style === 'label' || style === 'matrix' ? separator + joinedValues : joinedValues;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const serializePrimitiveParam = ({ allowReserved, name, value }: SerializePrimitiveParam) => {
|
export const serializePrimitiveParam = ({
|
||||||
|
allowReserved,
|
||||||
|
name,
|
||||||
|
value,
|
||||||
|
}: SerializePrimitiveParam) => {
|
||||||
if (value === undefined || value === null) {
|
if (value === undefined || value === null) {
|
||||||
return "";
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof value === "object") {
|
if (typeof value === 'object') {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.",
|
'Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,18 +140,18 @@ export const serializeObjectParam = ({
|
||||||
return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (style !== "deepObject" && !explode) {
|
if (style !== 'deepObject' && !explode) {
|
||||||
let values: string[] = [];
|
let values: string[] = [];
|
||||||
Object.entries(value).forEach(([key, v]) => {
|
Object.entries(value).forEach(([key, v]) => {
|
||||||
values = [...values, key, allowReserved ? (v as string) : encodeURIComponent(v as string)];
|
values = [...values, key, allowReserved ? (v as string) : encodeURIComponent(v as string)];
|
||||||
});
|
});
|
||||||
const joinedValues = values.join(",");
|
const joinedValues = values.join(',');
|
||||||
switch (style) {
|
switch (style) {
|
||||||
case "form":
|
case 'form':
|
||||||
return `${name}=${joinedValues}`;
|
return `${name}=${joinedValues}`;
|
||||||
case "label":
|
case 'label':
|
||||||
return `.${joinedValues}`;
|
return `.${joinedValues}`;
|
||||||
case "matrix":
|
case 'matrix':
|
||||||
return `;${name}=${joinedValues}`;
|
return `;${name}=${joinedValues}`;
|
||||||
default:
|
default:
|
||||||
return joinedValues;
|
return joinedValues;
|
||||||
|
|
@ -158,10 +163,10 @@ export const serializeObjectParam = ({
|
||||||
.map(([key, v]) =>
|
.map(([key, v]) =>
|
||||||
serializePrimitiveParam({
|
serializePrimitiveParam({
|
||||||
allowReserved,
|
allowReserved,
|
||||||
name: style === "deepObject" ? `${name}[${key}]` : key,
|
name: style === 'deepObject' ? `${name}[${key}]` : key,
|
||||||
value: v as string,
|
value: v as string,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.join(separator);
|
.join(separator);
|
||||||
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
return style === 'label' || style === 'matrix' ? separator + joinedValues : joinedValues;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,25 @@
|
||||||
|
// @ts-nocheck
|
||||||
// This file is auto-generated by @hey-api/openapi-ts
|
// This file is auto-generated by @hey-api/openapi-ts
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JSON-friendly union that mirrors what Pinia Colada can hash.
|
* JSON-friendly union that mirrors what Pinia Colada can hash.
|
||||||
*/
|
*/
|
||||||
export type JsonValue = null | string | number | boolean | JsonValue[] | { [key: string]: JsonValue };
|
export type JsonValue =
|
||||||
|
| null
|
||||||
|
| string
|
||||||
|
| number
|
||||||
|
| boolean
|
||||||
|
| JsonValue[]
|
||||||
|
| { [key: string]: JsonValue };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes.
|
* Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes.
|
||||||
*/
|
*/
|
||||||
export const queryKeyJsonReplacer = (_key: string, value: unknown) => {
|
export const queryKeyJsonReplacer = (_key: string, value: unknown) => {
|
||||||
if (value === undefined || typeof value === "function" || typeof value === "symbol") {
|
if (value === undefined || typeof value === 'function' || typeof value === 'symbol') {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
if (typeof value === "bigint") {
|
if (typeof value === 'bigint') {
|
||||||
return value.toString();
|
return value.toString();
|
||||||
}
|
}
|
||||||
if (value instanceof Date) {
|
if (value instanceof Date) {
|
||||||
|
|
@ -40,7 +47,7 @@ export const stringifyToJsonValue = (input: unknown): JsonValue | undefined => {
|
||||||
* Detects plain objects (including objects with a null prototype).
|
* Detects plain objects (including objects with a null prototype).
|
||||||
*/
|
*/
|
||||||
const isPlainObject = (value: unknown): value is Record<string, unknown> => {
|
const isPlainObject = (value: unknown): value is Record<string, unknown> => {
|
||||||
if (value === null || typeof value !== "object") {
|
if (value === null || typeof value !== 'object') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const prototype = Object.getPrototypeOf(value as object);
|
const prototype = Object.getPrototypeOf(value as object);
|
||||||
|
|
@ -79,15 +86,15 @@ export const serializeQueryKeyValue = (value: unknown): JsonValue | undefined =>
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value === undefined || typeof value === "function" || typeof value === "symbol") {
|
if (value === undefined || typeof value === 'function' || typeof value === 'symbol') {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof value === "bigint") {
|
if (typeof value === 'bigint') {
|
||||||
return value.toString();
|
return value.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,7 +106,7 @@ export const serializeQueryKeyValue = (value: unknown): JsonValue | undefined =>
|
||||||
return stringifyToJsonValue(value);
|
return stringifyToJsonValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof URLSearchParams !== "undefined" && value instanceof URLSearchParams) {
|
if (typeof URLSearchParams !== 'undefined' && value instanceof URLSearchParams) {
|
||||||
return serializeSearchParams(value);
|
return serializeSearchParams(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
|
// @ts-nocheck
|
||||||
// This file is auto-generated by @hey-api/openapi-ts
|
// This file is auto-generated by @hey-api/openapi-ts
|
||||||
|
|
||||||
import type { Config } from "./types.gen";
|
import type { Config } from './types.gen';
|
||||||
|
|
||||||
export type ServerSentEventsOptions<TData = unknown> = Omit<RequestInit, "method"> &
|
export type ServerSentEventsOptions<TData = unknown> = Omit<RequestInit, 'method'> &
|
||||||
Pick<Config, "method" | "responseTransformer" | "responseValidator"> & {
|
Pick<Config, 'method' | 'responseTransformer' | 'responseValidator'> & {
|
||||||
/**
|
/**
|
||||||
* Fetch API implementation. You can use this option to provide a custom
|
* Fetch API implementation. You can use this option to provide a custom
|
||||||
* fetch instance.
|
* fetch instance.
|
||||||
|
|
@ -32,7 +33,7 @@ export type ServerSentEventsOptions<TData = unknown> = Omit<RequestInit, "method
|
||||||
* @returns Nothing (void).
|
* @returns Nothing (void).
|
||||||
*/
|
*/
|
||||||
onSseEvent?: (event: StreamEvent<TData>) => void;
|
onSseEvent?: (event: StreamEvent<TData>) => void;
|
||||||
serializedBody?: RequestInit["body"];
|
serializedBody?: RequestInit['body'];
|
||||||
/**
|
/**
|
||||||
* Default retry delay in milliseconds.
|
* Default retry delay in milliseconds.
|
||||||
*
|
*
|
||||||
|
|
@ -72,10 +73,14 @@ export interface StreamEvent<TData = unknown> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ServerSentEventsResult<TData = unknown, TReturn = void, TNext = unknown> = {
|
export type ServerSentEventsResult<TData = unknown, TReturn = void, TNext = unknown> = {
|
||||||
stream: AsyncGenerator<TData extends Record<string, unknown> ? TData[keyof TData] : TData, TReturn, TNext>;
|
stream: AsyncGenerator<
|
||||||
|
TData extends Record<string, unknown> ? TData[keyof TData] : TData,
|
||||||
|
TReturn,
|
||||||
|
TNext
|
||||||
|
>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createSseClient = <TData = unknown>({
|
export function createSseClient<TData = unknown>({
|
||||||
onRequest,
|
onRequest,
|
||||||
onSseError,
|
onSseError,
|
||||||
onSseEvent,
|
onSseEvent,
|
||||||
|
|
@ -87,7 +92,7 @@ export const createSseClient = <TData = unknown>({
|
||||||
sseSleepFn,
|
sseSleepFn,
|
||||||
url,
|
url,
|
||||||
...options
|
...options
|
||||||
}: ServerSentEventsOptions): ServerSentEventsResult<TData> => {
|
}: ServerSentEventsOptions): ServerSentEventsResult<TData> {
|
||||||
let lastEventId: string | undefined;
|
let lastEventId: string | undefined;
|
||||||
|
|
||||||
const sleep = sseSleepFn ?? ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms)));
|
const sleep = sseSleepFn ?? ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms)));
|
||||||
|
|
@ -108,12 +113,12 @@ export const createSseClient = <TData = unknown>({
|
||||||
: new Headers(options.headers as Record<string, string> | undefined);
|
: new Headers(options.headers as Record<string, string> | undefined);
|
||||||
|
|
||||||
if (lastEventId !== undefined) {
|
if (lastEventId !== undefined) {
|
||||||
headers.set("Last-Event-ID", lastEventId);
|
headers.set('Last-Event-ID', lastEventId);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const requestInit: RequestInit = {
|
const requestInit: RequestInit = {
|
||||||
redirect: "follow",
|
redirect: 'follow',
|
||||||
...options,
|
...options,
|
||||||
body: options.serializedBody,
|
body: options.serializedBody,
|
||||||
headers,
|
headers,
|
||||||
|
|
@ -130,11 +135,11 @@ export const createSseClient = <TData = unknown>({
|
||||||
|
|
||||||
if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
|
if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
|
||||||
|
|
||||||
if (!response.body) throw new Error("No body in SSE response");
|
if (!response.body) throw new Error('No body in SSE response');
|
||||||
|
|
||||||
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
||||||
|
|
||||||
let buffer = "";
|
let buffer = '';
|
||||||
|
|
||||||
const abortHandler = () => {
|
const abortHandler = () => {
|
||||||
try {
|
try {
|
||||||
|
|
@ -144,33 +149,32 @@ export const createSseClient = <TData = unknown>({
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
signal.addEventListener("abort", abortHandler);
|
signal.addEventListener('abort', abortHandler);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while (true) {
|
while (true) {
|
||||||
const { done, value } = await reader.read();
|
const { done, value } = await reader.read();
|
||||||
if (done) break;
|
if (done) break;
|
||||||
buffer += value;
|
buffer += value;
|
||||||
// Normalize line endings: CRLF -> LF, then CR -> LF
|
buffer = buffer.replace(/\r\n?/g, '\n'); // normalize line endings
|
||||||
buffer = buffer.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
||||||
|
|
||||||
const chunks = buffer.split("\n\n");
|
const chunks = buffer.split('\n\n');
|
||||||
buffer = chunks.pop() ?? "";
|
buffer = chunks.pop() ?? '';
|
||||||
|
|
||||||
for (const chunk of chunks) {
|
for (const chunk of chunks) {
|
||||||
const lines = chunk.split("\n");
|
const lines = chunk.split('\n');
|
||||||
const dataLines: Array<string> = [];
|
const dataLines: Array<string> = [];
|
||||||
let eventName: string | undefined;
|
let eventName: string | undefined;
|
||||||
|
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
if (line.startsWith("data:")) {
|
if (line.startsWith('data:')) {
|
||||||
dataLines.push(line.replace(/^data:\s*/, ""));
|
dataLines.push(line.replace(/^data:\s*/, ''));
|
||||||
} else if (line.startsWith("event:")) {
|
} else if (line.startsWith('event:')) {
|
||||||
eventName = line.replace(/^event:\s*/, "");
|
eventName = line.replace(/^event:\s*/, '');
|
||||||
} else if (line.startsWith("id:")) {
|
} else if (line.startsWith('id:')) {
|
||||||
lastEventId = line.replace(/^id:\s*/, "");
|
lastEventId = line.replace(/^id:\s*/, '');
|
||||||
} else if (line.startsWith("retry:")) {
|
} else if (line.startsWith('retry:')) {
|
||||||
const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
|
const parsed = Number.parseInt(line.replace(/^retry:\s*/, ''), 10);
|
||||||
if (!Number.isNaN(parsed)) {
|
if (!Number.isNaN(parsed)) {
|
||||||
retryDelay = parsed;
|
retryDelay = parsed;
|
||||||
}
|
}
|
||||||
|
|
@ -181,7 +185,7 @@ export const createSseClient = <TData = unknown>({
|
||||||
let parsedJson = false;
|
let parsedJson = false;
|
||||||
|
|
||||||
if (dataLines.length) {
|
if (dataLines.length) {
|
||||||
const rawData = dataLines.join("\n");
|
const rawData = dataLines.join('\n');
|
||||||
try {
|
try {
|
||||||
data = JSON.parse(rawData);
|
data = JSON.parse(rawData);
|
||||||
parsedJson = true;
|
parsedJson = true;
|
||||||
|
|
@ -213,7 +217,7 @@ export const createSseClient = <TData = unknown>({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
signal.removeEventListener("abort", abortHandler);
|
signal.removeEventListener('abort', abortHandler);
|
||||||
reader.releaseLock();
|
reader.releaseLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -236,4 +240,4 @@ export const createSseClient = <TData = unknown>({
|
||||||
const stream = createStream();
|
const stream = createStream();
|
||||||
|
|
||||||
return { stream };
|
return { stream };
|
||||||
};
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,27 @@
|
||||||
|
// @ts-nocheck
|
||||||
// This file is auto-generated by @hey-api/openapi-ts
|
// This file is auto-generated by @hey-api/openapi-ts
|
||||||
|
|
||||||
import type { Auth, AuthToken } from "./auth.gen";
|
import type { Auth, AuthToken } from './auth.gen';
|
||||||
import type { BodySerializer, QuerySerializer, QuerySerializerOptions } from "./bodySerializer.gen";
|
import type { BodySerializer, QuerySerializer, QuerySerializerOptions } from './bodySerializer.gen';
|
||||||
|
|
||||||
export type HttpMethod = "connect" | "delete" | "get" | "head" | "options" | "patch" | "post" | "put" | "trace";
|
export type HttpMethod =
|
||||||
|
| 'connect'
|
||||||
|
| 'delete'
|
||||||
|
| 'get'
|
||||||
|
| 'head'
|
||||||
|
| 'options'
|
||||||
|
| 'patch'
|
||||||
|
| 'post'
|
||||||
|
| 'put'
|
||||||
|
| 'trace';
|
||||||
|
|
||||||
export type Client<RequestFn = never, Config = unknown, MethodFn = never, BuildUrlFn = never, SseFn = never> = {
|
export type Client<
|
||||||
|
RequestFn = never,
|
||||||
|
Config = unknown,
|
||||||
|
MethodFn = never,
|
||||||
|
BuildUrlFn = never,
|
||||||
|
SseFn = never,
|
||||||
|
> = {
|
||||||
/**
|
/**
|
||||||
* Returns the final request URL.
|
* Returns the final request URL.
|
||||||
*/
|
*/
|
||||||
|
|
@ -35,8 +51,11 @@ export interface Config {
|
||||||
* {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
|
* {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
|
||||||
*/
|
*/
|
||||||
headers?:
|
headers?:
|
||||||
| RequestInit["headers"]
|
| RequestInit['headers']
|
||||||
| Record<string, string | number | boolean | (string | number | boolean)[] | null | undefined | unknown>;
|
| Record<
|
||||||
|
string,
|
||||||
|
string | number | boolean | (string | number | boolean)[] | null | undefined | unknown
|
||||||
|
>;
|
||||||
/**
|
/**
|
||||||
* The request method.
|
* The request method.
|
||||||
*
|
*
|
||||||
|
|
@ -62,7 +81,7 @@ export interface Config {
|
||||||
requestValidator?: (data: unknown) => Promise<unknown>;
|
requestValidator?: (data: unknown) => Promise<unknown>;
|
||||||
/**
|
/**
|
||||||
* A function transforming response data before it's returned. This is useful
|
* A function transforming response data before it's returned. This is useful
|
||||||
* for post-processing data, e.g. converting ISO strings into Date objects.
|
* for post-processing data, e.g., converting ISO strings into Date objects.
|
||||||
*/
|
*/
|
||||||
responseTransformer?: (data: unknown) => Promise<unknown>;
|
responseTransformer?: (data: unknown) => Promise<unknown>;
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
|
// @ts-nocheck
|
||||||
// This file is auto-generated by @hey-api/openapi-ts
|
// This file is auto-generated by @hey-api/openapi-ts
|
||||||
|
|
||||||
import type { BodySerializer, QuerySerializer } from "./bodySerializer.gen";
|
import type { BodySerializer, QuerySerializer } from './bodySerializer.gen';
|
||||||
import {
|
import {
|
||||||
type ArraySeparatorStyle,
|
type ArraySeparatorStyle,
|
||||||
serializeArrayParam,
|
serializeArrayParam,
|
||||||
serializeObjectParam,
|
serializeObjectParam,
|
||||||
serializePrimitiveParam,
|
serializePrimitiveParam,
|
||||||
} from "./pathSerializer.gen";
|
} from './pathSerializer.gen';
|
||||||
|
|
||||||
export interface PathSerializer {
|
export interface PathSerializer {
|
||||||
path: Record<string, unknown>;
|
path: Record<string, unknown>;
|
||||||
|
|
@ -22,19 +23,19 @@ export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => {
|
||||||
for (const match of matches) {
|
for (const match of matches) {
|
||||||
let explode = false;
|
let explode = false;
|
||||||
let name = match.substring(1, match.length - 1);
|
let name = match.substring(1, match.length - 1);
|
||||||
let style: ArraySeparatorStyle = "simple";
|
let style: ArraySeparatorStyle = 'simple';
|
||||||
|
|
||||||
if (name.endsWith("*")) {
|
if (name.endsWith('*')) {
|
||||||
explode = true;
|
explode = true;
|
||||||
name = name.substring(0, name.length - 1);
|
name = name.substring(0, name.length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name.startsWith(".")) {
|
if (name.startsWith('.')) {
|
||||||
name = name.substring(1);
|
name = name.substring(1);
|
||||||
style = "label";
|
style = 'label';
|
||||||
} else if (name.startsWith(";")) {
|
} else if (name.startsWith(';')) {
|
||||||
name = name.substring(1);
|
name = name.substring(1);
|
||||||
style = "matrix";
|
style = 'matrix';
|
||||||
}
|
}
|
||||||
|
|
||||||
const value = path[name];
|
const value = path[name];
|
||||||
|
|
@ -48,7 +49,7 @@ export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof value === "object") {
|
if (typeof value === 'object') {
|
||||||
url = url.replace(
|
url = url.replace(
|
||||||
match,
|
match,
|
||||||
serializeObjectParam({
|
serializeObjectParam({
|
||||||
|
|
@ -62,7 +63,7 @@ export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (style === "matrix") {
|
if (style === 'matrix') {
|
||||||
url = url.replace(
|
url = url.replace(
|
||||||
match,
|
match,
|
||||||
`;${serializePrimitiveParam({
|
`;${serializePrimitiveParam({
|
||||||
|
|
@ -73,7 +74,9 @@ export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const replaceValue = encodeURIComponent(style === "label" ? `.${value as string}` : (value as string));
|
const replaceValue = encodeURIComponent(
|
||||||
|
style === 'label' ? `.${value as string}` : (value as string),
|
||||||
|
);
|
||||||
url = url.replace(match, replaceValue);
|
url = url.replace(match, replaceValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -93,13 +96,13 @@ export const getUrl = ({
|
||||||
querySerializer: QuerySerializer;
|
querySerializer: QuerySerializer;
|
||||||
url: string;
|
url: string;
|
||||||
}) => {
|
}) => {
|
||||||
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
const pathUrl = _url.startsWith('/') ? _url : `/${_url}`;
|
||||||
let url = (baseUrl ?? "") + pathUrl;
|
let url = (baseUrl ?? '') + pathUrl;
|
||||||
if (path) {
|
if (path) {
|
||||||
url = defaultPathSerializer({ path, url });
|
url = defaultPathSerializer({ path, url });
|
||||||
}
|
}
|
||||||
let search = query ? querySerializer(query) : "";
|
let search = query ? querySerializer(query) : '';
|
||||||
if (search.startsWith("?")) {
|
if (search.startsWith('?')) {
|
||||||
search = search.substring(1);
|
search = search.substring(1);
|
||||||
}
|
}
|
||||||
if (search) {
|
if (search) {
|
||||||
|
|
@ -117,14 +120,15 @@ export function getValidRequestBody(options: {
|
||||||
const isSerializedBody = hasBody && options.bodySerializer;
|
const isSerializedBody = hasBody && options.bodySerializer;
|
||||||
|
|
||||||
if (isSerializedBody) {
|
if (isSerializedBody) {
|
||||||
if ("serializedBody" in options) {
|
if ('serializedBody' in options) {
|
||||||
const hasSerializedBody = options.serializedBody !== undefined && options.serializedBody !== "";
|
const hasSerializedBody =
|
||||||
|
options.serializedBody !== undefined && options.serializedBody !== '';
|
||||||
|
|
||||||
return hasSerializedBody ? options.serializedBody : null;
|
return hasSerializedBody ? options.serializedBody : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// not all clients implement a serializedBody property (i.e. client-axios)
|
// not all clients implement a serializedBody property (i.e., client-axios)
|
||||||
return options.body !== "" ? options.body : null;
|
return options.body !== '' ? options.body : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// plain/text body
|
// plain/text body
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
// @ts-nocheck
|
||||||
// This file is auto-generated by @hey-api/openapi-ts
|
// This file is auto-generated by @hey-api/openapi-ts
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|
@ -12,23 +13,35 @@ export {
|
||||||
deleteRepository,
|
deleteRepository,
|
||||||
deleteSnapshot,
|
deleteSnapshot,
|
||||||
deleteSnapshots,
|
deleteSnapshots,
|
||||||
|
deleteSsoInvitation,
|
||||||
|
deleteSsoProvider,
|
||||||
|
deleteUserAccount,
|
||||||
deleteVolume,
|
deleteVolume,
|
||||||
|
devPanelExec,
|
||||||
downloadResticPassword,
|
downloadResticPassword,
|
||||||
|
dumpSnapshot,
|
||||||
|
getAdminUsers,
|
||||||
|
getBackupProgress,
|
||||||
getBackupSchedule,
|
getBackupSchedule,
|
||||||
getBackupScheduleForVolume,
|
getBackupScheduleForVolume,
|
||||||
|
getDevPanel,
|
||||||
getMirrorCompatibility,
|
getMirrorCompatibility,
|
||||||
|
getMirrorSyncStatus,
|
||||||
getNotificationDestination,
|
getNotificationDestination,
|
||||||
|
getOrgMembers,
|
||||||
|
getPublicSsoProviders,
|
||||||
getRegistrationStatus,
|
getRegistrationStatus,
|
||||||
getRepository,
|
getRepository,
|
||||||
|
getRepositoryStats,
|
||||||
getScheduleMirrors,
|
getScheduleMirrors,
|
||||||
getScheduleNotifications,
|
getScheduleNotifications,
|
||||||
getSnapshotDetails,
|
getSnapshotDetails,
|
||||||
|
getSsoSettings,
|
||||||
getStatus,
|
getStatus,
|
||||||
getSystemInfo,
|
getSystemInfo,
|
||||||
getUpdates,
|
getUpdates,
|
||||||
getUserDeletionImpact,
|
getUserDeletionImpact,
|
||||||
getVolume,
|
getVolume,
|
||||||
refreshSnapshots,
|
|
||||||
healthCheckVolume,
|
healthCheckVolume,
|
||||||
listBackupSchedules,
|
listBackupSchedules,
|
||||||
listFiles,
|
listFiles,
|
||||||
|
|
@ -40,6 +53,9 @@ export {
|
||||||
listVolumes,
|
listVolumes,
|
||||||
mountVolume,
|
mountVolume,
|
||||||
type Options,
|
type Options,
|
||||||
|
refreshRepositoryStats,
|
||||||
|
refreshSnapshots,
|
||||||
|
removeOrgMember,
|
||||||
reorderBackupSchedules,
|
reorderBackupSchedules,
|
||||||
restoreSnapshot,
|
restoreSnapshot,
|
||||||
runBackupNow,
|
runBackupNow,
|
||||||
|
|
@ -47,15 +63,19 @@ export {
|
||||||
setRegistrationStatus,
|
setRegistrationStatus,
|
||||||
startDoctor,
|
startDoctor,
|
||||||
stopBackup,
|
stopBackup,
|
||||||
|
syncMirror,
|
||||||
tagSnapshots,
|
tagSnapshots,
|
||||||
testConnection,
|
testConnection,
|
||||||
testNotificationDestination,
|
testNotificationDestination,
|
||||||
|
unlockRepository,
|
||||||
unmountVolume,
|
unmountVolume,
|
||||||
updateBackupSchedule,
|
updateBackupSchedule,
|
||||||
|
updateMemberRole,
|
||||||
updateNotificationDestination,
|
updateNotificationDestination,
|
||||||
updateRepository,
|
updateRepository,
|
||||||
updateScheduleMirrors,
|
updateScheduleMirrors,
|
||||||
updateScheduleNotifications,
|
updateScheduleNotifications,
|
||||||
|
updateSsoProviderAutoLinking,
|
||||||
updateVolume,
|
updateVolume,
|
||||||
} from "./sdk.gen";
|
} from "./sdk.gen";
|
||||||
export type {
|
export type {
|
||||||
|
|
@ -95,31 +115,68 @@ export type {
|
||||||
DeleteSnapshotsData,
|
DeleteSnapshotsData,
|
||||||
DeleteSnapshotsResponse,
|
DeleteSnapshotsResponse,
|
||||||
DeleteSnapshotsResponses,
|
DeleteSnapshotsResponses,
|
||||||
|
DeleteSsoInvitationData,
|
||||||
|
DeleteSsoInvitationErrors,
|
||||||
|
DeleteSsoInvitationResponses,
|
||||||
|
DeleteSsoProviderData,
|
||||||
|
DeleteSsoProviderErrors,
|
||||||
|
DeleteSsoProviderResponses,
|
||||||
|
DeleteUserAccountData,
|
||||||
|
DeleteUserAccountErrors,
|
||||||
|
DeleteUserAccountResponses,
|
||||||
DeleteVolumeData,
|
DeleteVolumeData,
|
||||||
DeleteVolumeResponse,
|
DeleteVolumeResponse,
|
||||||
DeleteVolumeResponses,
|
DeleteVolumeResponses,
|
||||||
|
DevPanelExecData,
|
||||||
|
DevPanelExecErrors,
|
||||||
|
DevPanelExecResponse,
|
||||||
|
DevPanelExecResponses,
|
||||||
DownloadResticPasswordData,
|
DownloadResticPasswordData,
|
||||||
DownloadResticPasswordResponse,
|
DownloadResticPasswordResponse,
|
||||||
DownloadResticPasswordResponses,
|
DownloadResticPasswordResponses,
|
||||||
|
DumpSnapshotData,
|
||||||
|
DumpSnapshotResponse,
|
||||||
|
DumpSnapshotResponses,
|
||||||
|
GetAdminUsersData,
|
||||||
|
GetAdminUsersResponse,
|
||||||
|
GetAdminUsersResponses,
|
||||||
|
GetBackupProgressData,
|
||||||
|
GetBackupProgressResponse,
|
||||||
|
GetBackupProgressResponses,
|
||||||
GetBackupScheduleData,
|
GetBackupScheduleData,
|
||||||
GetBackupScheduleForVolumeData,
|
GetBackupScheduleForVolumeData,
|
||||||
GetBackupScheduleForVolumeResponse,
|
GetBackupScheduleForVolumeResponse,
|
||||||
GetBackupScheduleForVolumeResponses,
|
GetBackupScheduleForVolumeResponses,
|
||||||
GetBackupScheduleResponse,
|
GetBackupScheduleResponse,
|
||||||
GetBackupScheduleResponses,
|
GetBackupScheduleResponses,
|
||||||
|
GetDevPanelData,
|
||||||
|
GetDevPanelResponse,
|
||||||
|
GetDevPanelResponses,
|
||||||
GetMirrorCompatibilityData,
|
GetMirrorCompatibilityData,
|
||||||
GetMirrorCompatibilityResponse,
|
GetMirrorCompatibilityResponse,
|
||||||
GetMirrorCompatibilityResponses,
|
GetMirrorCompatibilityResponses,
|
||||||
|
GetMirrorSyncStatusData,
|
||||||
|
GetMirrorSyncStatusResponse,
|
||||||
|
GetMirrorSyncStatusResponses,
|
||||||
GetNotificationDestinationData,
|
GetNotificationDestinationData,
|
||||||
GetNotificationDestinationErrors,
|
GetNotificationDestinationErrors,
|
||||||
GetNotificationDestinationResponse,
|
GetNotificationDestinationResponse,
|
||||||
GetNotificationDestinationResponses,
|
GetNotificationDestinationResponses,
|
||||||
|
GetOrgMembersData,
|
||||||
|
GetOrgMembersResponse,
|
||||||
|
GetOrgMembersResponses,
|
||||||
|
GetPublicSsoProvidersData,
|
||||||
|
GetPublicSsoProvidersResponse,
|
||||||
|
GetPublicSsoProvidersResponses,
|
||||||
GetRegistrationStatusData,
|
GetRegistrationStatusData,
|
||||||
GetRegistrationStatusResponse,
|
GetRegistrationStatusResponse,
|
||||||
GetRegistrationStatusResponses,
|
GetRegistrationStatusResponses,
|
||||||
GetRepositoryData,
|
GetRepositoryData,
|
||||||
GetRepositoryResponse,
|
GetRepositoryResponse,
|
||||||
GetRepositoryResponses,
|
GetRepositoryResponses,
|
||||||
|
GetRepositoryStatsData,
|
||||||
|
GetRepositoryStatsResponse,
|
||||||
|
GetRepositoryStatsResponses,
|
||||||
GetScheduleMirrorsData,
|
GetScheduleMirrorsData,
|
||||||
GetScheduleMirrorsResponse,
|
GetScheduleMirrorsResponse,
|
||||||
GetScheduleMirrorsResponses,
|
GetScheduleMirrorsResponses,
|
||||||
|
|
@ -129,6 +186,9 @@ export type {
|
||||||
GetSnapshotDetailsData,
|
GetSnapshotDetailsData,
|
||||||
GetSnapshotDetailsResponse,
|
GetSnapshotDetailsResponse,
|
||||||
GetSnapshotDetailsResponses,
|
GetSnapshotDetailsResponses,
|
||||||
|
GetSsoSettingsData,
|
||||||
|
GetSsoSettingsResponse,
|
||||||
|
GetSsoSettingsResponses,
|
||||||
GetStatusData,
|
GetStatusData,
|
||||||
GetStatusResponse,
|
GetStatusResponse,
|
||||||
GetStatusResponses,
|
GetStatusResponses,
|
||||||
|
|
@ -145,9 +205,6 @@ export type {
|
||||||
GetVolumeErrors,
|
GetVolumeErrors,
|
||||||
GetVolumeResponse,
|
GetVolumeResponse,
|
||||||
GetVolumeResponses,
|
GetVolumeResponses,
|
||||||
RefreshSnapshotsData,
|
|
||||||
RefreshSnapshotsResponse,
|
|
||||||
RefreshSnapshotsResponses,
|
|
||||||
HealthCheckVolumeData,
|
HealthCheckVolumeData,
|
||||||
HealthCheckVolumeErrors,
|
HealthCheckVolumeErrors,
|
||||||
HealthCheckVolumeResponse,
|
HealthCheckVolumeResponse,
|
||||||
|
|
@ -179,6 +236,15 @@ export type {
|
||||||
MountVolumeData,
|
MountVolumeData,
|
||||||
MountVolumeResponse,
|
MountVolumeResponse,
|
||||||
MountVolumeResponses,
|
MountVolumeResponses,
|
||||||
|
RefreshRepositoryStatsData,
|
||||||
|
RefreshRepositoryStatsResponse,
|
||||||
|
RefreshRepositoryStatsResponses,
|
||||||
|
RefreshSnapshotsData,
|
||||||
|
RefreshSnapshotsResponse,
|
||||||
|
RefreshSnapshotsResponses,
|
||||||
|
RemoveOrgMemberData,
|
||||||
|
RemoveOrgMemberErrors,
|
||||||
|
RemoveOrgMemberResponses,
|
||||||
ReorderBackupSchedulesData,
|
ReorderBackupSchedulesData,
|
||||||
ReorderBackupSchedulesResponse,
|
ReorderBackupSchedulesResponse,
|
||||||
ReorderBackupSchedulesResponses,
|
ReorderBackupSchedulesResponses,
|
||||||
|
|
@ -202,6 +268,10 @@ export type {
|
||||||
StopBackupErrors,
|
StopBackupErrors,
|
||||||
StopBackupResponse,
|
StopBackupResponse,
|
||||||
StopBackupResponses,
|
StopBackupResponses,
|
||||||
|
SyncMirrorData,
|
||||||
|
SyncMirrorErrors,
|
||||||
|
SyncMirrorResponse,
|
||||||
|
SyncMirrorResponses,
|
||||||
TagSnapshotsData,
|
TagSnapshotsData,
|
||||||
TagSnapshotsResponse,
|
TagSnapshotsResponse,
|
||||||
TagSnapshotsResponses,
|
TagSnapshotsResponses,
|
||||||
|
|
@ -212,12 +282,18 @@ export type {
|
||||||
TestNotificationDestinationErrors,
|
TestNotificationDestinationErrors,
|
||||||
TestNotificationDestinationResponse,
|
TestNotificationDestinationResponse,
|
||||||
TestNotificationDestinationResponses,
|
TestNotificationDestinationResponses,
|
||||||
|
UnlockRepositoryData,
|
||||||
|
UnlockRepositoryResponse,
|
||||||
|
UnlockRepositoryResponses,
|
||||||
UnmountVolumeData,
|
UnmountVolumeData,
|
||||||
UnmountVolumeResponse,
|
UnmountVolumeResponse,
|
||||||
UnmountVolumeResponses,
|
UnmountVolumeResponses,
|
||||||
UpdateBackupScheduleData,
|
UpdateBackupScheduleData,
|
||||||
UpdateBackupScheduleResponse,
|
UpdateBackupScheduleResponse,
|
||||||
UpdateBackupScheduleResponses,
|
UpdateBackupScheduleResponses,
|
||||||
|
UpdateMemberRoleData,
|
||||||
|
UpdateMemberRoleErrors,
|
||||||
|
UpdateMemberRoleResponses,
|
||||||
UpdateNotificationDestinationData,
|
UpdateNotificationDestinationData,
|
||||||
UpdateNotificationDestinationErrors,
|
UpdateNotificationDestinationErrors,
|
||||||
UpdateNotificationDestinationResponse,
|
UpdateNotificationDestinationResponse,
|
||||||
|
|
@ -232,6 +308,9 @@ export type {
|
||||||
UpdateScheduleNotificationsData,
|
UpdateScheduleNotificationsData,
|
||||||
UpdateScheduleNotificationsResponse,
|
UpdateScheduleNotificationsResponse,
|
||||||
UpdateScheduleNotificationsResponses,
|
UpdateScheduleNotificationsResponses,
|
||||||
|
UpdateSsoProviderAutoLinkingData,
|
||||||
|
UpdateSsoProviderAutoLinkingErrors,
|
||||||
|
UpdateSsoProviderAutoLinkingResponses,
|
||||||
UpdateVolumeData,
|
UpdateVolumeData,
|
||||||
UpdateVolumeErrors,
|
UpdateVolumeErrors,
|
||||||
UpdateVolumeResponse,
|
UpdateVolumeResponse,
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,8 +1,205 @@
|
||||||
/** biome-ignore-all lint/style/noNonNullAssertion: Testing file - non-null assertions are acceptable here */
|
/** biome-ignore-all lint/style/noNonNullAssertion: Testing file - non-null assertions are acceptable here */
|
||||||
import { expect, test, describe } from "bun:test";
|
import { afterEach, describe, expect, test } from "vitest";
|
||||||
import { render, screen, fireEvent } from "@testing-library/react";
|
import { cleanup, render, screen, fireEvent, within } from "@testing-library/react";
|
||||||
|
import { useState } from "react";
|
||||||
import { FileTree, type FileEntry } from "../file-tree";
|
import { FileTree, type FileEntry } from "../file-tree";
|
||||||
|
|
||||||
|
const getCheckboxFor = (name: string) => {
|
||||||
|
const row = screen.getByRole("button", { name });
|
||||||
|
return within(row).getByRole("checkbox");
|
||||||
|
};
|
||||||
|
|
||||||
|
const FileTreeSelection = ({
|
||||||
|
files,
|
||||||
|
initialSelectedPaths = [],
|
||||||
|
expandedFolders,
|
||||||
|
}: {
|
||||||
|
files: FileEntry[];
|
||||||
|
initialSelectedPaths?: string[];
|
||||||
|
expandedFolders?: Set<string>;
|
||||||
|
}) => {
|
||||||
|
const [selectedPaths, setSelectedPaths] = useState(() => new Set(initialSelectedPaths));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<FileTree
|
||||||
|
files={files}
|
||||||
|
withCheckboxes={true}
|
||||||
|
selectedPaths={selectedPaths}
|
||||||
|
onSelectionChange={setSelectedPaths}
|
||||||
|
expandedFolders={expandedFolders}
|
||||||
|
/>
|
||||||
|
<output aria-label="Selected paths">{JSON.stringify(Array.from(selectedPaths).sort())}</output>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const getSelectedPaths = () => {
|
||||||
|
const selectedPaths = screen.getByLabelText("Selected paths").textContent;
|
||||||
|
return JSON.parse(selectedPaths ?? "[]") as string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
cleanup();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("FileTree Pagination", () => {
|
||||||
|
const testFiles: FileEntry[] = [
|
||||||
|
{ name: "root", path: "/root", type: "folder" },
|
||||||
|
{ name: "file1", path: "/root/file1", type: "file" },
|
||||||
|
{ name: "file2", path: "/root/file2", type: "file" },
|
||||||
|
];
|
||||||
|
|
||||||
|
test("shows load more button when hasMore is true", () => {
|
||||||
|
render(
|
||||||
|
<FileTree
|
||||||
|
files={testFiles}
|
||||||
|
expandedFolders={new Set(["/root"])}
|
||||||
|
getFolderPagination={(path) => {
|
||||||
|
if (path === "/root") {
|
||||||
|
return { hasMore: true, isLoadingMore: false };
|
||||||
|
}
|
||||||
|
return { hasMore: false, isLoadingMore: false };
|
||||||
|
}}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(screen.getByText("Load more files")).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("does not show load more button when hasMore is false", () => {
|
||||||
|
render(
|
||||||
|
<FileTree
|
||||||
|
files={testFiles}
|
||||||
|
expandedFolders={new Set(["/root"])}
|
||||||
|
getFolderPagination={() => ({ hasMore: false, isLoadingMore: false })}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(screen.queryByText("Load more files")).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("calls onLoadMore with folder path when load more button is clicked", () => {
|
||||||
|
let loadMoreCalled = false;
|
||||||
|
let loadMorePath = "";
|
||||||
|
|
||||||
|
render(
|
||||||
|
<FileTree
|
||||||
|
files={testFiles}
|
||||||
|
expandedFolders={new Set(["/root"])}
|
||||||
|
getFolderPagination={(path) => {
|
||||||
|
if (path === "/root") {
|
||||||
|
return { hasMore: true, isLoadingMore: false };
|
||||||
|
}
|
||||||
|
return { hasMore: false, isLoadingMore: false };
|
||||||
|
}}
|
||||||
|
onLoadMore={(path) => {
|
||||||
|
loadMoreCalled = true;
|
||||||
|
loadMorePath = path;
|
||||||
|
}}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
const loadMoreButton = screen.getByText("Load more files");
|
||||||
|
fireEvent.click(loadMoreButton);
|
||||||
|
|
||||||
|
expect(loadMoreCalled).toBe(true);
|
||||||
|
expect(loadMorePath).toBe("/root");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("shows loading state when isLoadingMore is true", () => {
|
||||||
|
render(
|
||||||
|
<FileTree
|
||||||
|
files={testFiles}
|
||||||
|
expandedFolders={new Set(["/root"])}
|
||||||
|
getFolderPagination={(path) => {
|
||||||
|
if (path === "/root") {
|
||||||
|
return { hasMore: true, isLoadingMore: true };
|
||||||
|
}
|
||||||
|
return { hasMore: false, isLoadingMore: false };
|
||||||
|
}}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(screen.getByText("Loading more...")).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("shows load more button for root-level files when root has more", () => {
|
||||||
|
const rootFiles: FileEntry[] = [
|
||||||
|
{ name: "file1", path: "/file1", type: "file" },
|
||||||
|
{ name: "file2", path: "/file2", type: "file" },
|
||||||
|
];
|
||||||
|
|
||||||
|
render(
|
||||||
|
<FileTree
|
||||||
|
files={rootFiles}
|
||||||
|
getFolderPagination={(path) => {
|
||||||
|
if (path === "/") {
|
||||||
|
return { hasMore: true, isLoadingMore: false };
|
||||||
|
}
|
||||||
|
return { hasMore: false, isLoadingMore: false };
|
||||||
|
}}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(screen.getByText("Load more files")).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("load more button appears for nested folders with hasMore", () => {
|
||||||
|
const nestedFiles: FileEntry[] = [
|
||||||
|
{ name: "root", path: "/root", type: "folder" },
|
||||||
|
{ name: "child", path: "/root/child", type: "folder" },
|
||||||
|
{ name: "file1", path: "/root/child/file1", type: "file" },
|
||||||
|
];
|
||||||
|
|
||||||
|
render(
|
||||||
|
<FileTree
|
||||||
|
files={nestedFiles}
|
||||||
|
expandedFolders={new Set(["/root", "/root/child"])}
|
||||||
|
getFolderPagination={(path) => {
|
||||||
|
if (path === "/root/child") {
|
||||||
|
return { hasMore: true, isLoadingMore: false };
|
||||||
|
}
|
||||||
|
return { hasMore: false, isLoadingMore: false };
|
||||||
|
}}
|
||||||
|
onLoadMore={() => {}}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(screen.getByText("Load more files")).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("load more button does not appear when folder is collapsed", () => {
|
||||||
|
render(
|
||||||
|
<FileTree
|
||||||
|
files={testFiles}
|
||||||
|
expandedFolders={new Set([])}
|
||||||
|
getFolderPagination={(path) => {
|
||||||
|
if (path === "/root") {
|
||||||
|
return { hasMore: true, isLoadingMore: false };
|
||||||
|
}
|
||||||
|
return { hasMore: false, isLoadingMore: false };
|
||||||
|
}}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(screen.queryByText("Load more files")).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("renders missing ancestor folders for nested paths", () => {
|
||||||
|
render(
|
||||||
|
<FileTree
|
||||||
|
files={[
|
||||||
|
{ name: "subdir", path: "/project/subdir", type: "folder" },
|
||||||
|
{ name: "file1", path: "/project/subdir/file1", type: "file" },
|
||||||
|
]}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(screen.getByRole("button", { name: "project" })).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("FileTree Selection Logic", () => {
|
describe("FileTree Selection Logic", () => {
|
||||||
const testFiles: FileEntry[] = [
|
const testFiles: FileEntry[] = [
|
||||||
{ name: "root", path: "/root", type: "folder" },
|
{ name: "root", path: "/root", type: "folder" },
|
||||||
|
|
@ -13,154 +210,67 @@ describe("FileTree Selection Logic", () => {
|
||||||
{ name: "upload", path: "/root/photos/upload", type: "folder" },
|
{ name: "upload", path: "/root/photos/upload", type: "folder" },
|
||||||
];
|
];
|
||||||
|
|
||||||
test("selecting a folder simplifies to parent if it's the only child", async () => {
|
test("selecting a folder simplifies to parent if it's the only child", () => {
|
||||||
let currentSelection = new Set<string>();
|
render(<FileTreeSelection files={testFiles} expandedFolders={new Set(testFiles.map((f) => f.path))} />);
|
||||||
const onSelectionChange = (selection: Set<string>) => {
|
|
||||||
currentSelection = selection;
|
|
||||||
};
|
|
||||||
|
|
||||||
render(
|
fireEvent.click(getCheckboxFor("photos"));
|
||||||
<FileTree
|
|
||||||
files={testFiles}
|
|
||||||
withCheckboxes={true}
|
|
||||||
selectedPaths={currentSelection}
|
|
||||||
onSelectionChange={onSelectionChange}
|
|
||||||
expandedFolders={new Set(testFiles.map((f) => f.path))}
|
|
||||||
/>,
|
|
||||||
);
|
|
||||||
|
|
||||||
const photosCheckbox = screen.getByText("photos").parentElement?.querySelector('button[role="checkbox"]');
|
expect(getSelectedPaths()).toEqual(["/root"]);
|
||||||
expect(photosCheckbox).toBeTruthy();
|
|
||||||
|
|
||||||
fireEvent.click(photosCheckbox!);
|
|
||||||
|
|
||||||
expect(currentSelection.has("/root")).toBe(true);
|
|
||||||
expect(currentSelection.size).toBe(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("unselecting a child removes the parent from selection", async () => {
|
test("unselecting a child removes the parent from selection", () => {
|
||||||
let currentSelection = new Set<string>(["/root"]);
|
|
||||||
const onSelectionChange = (selection: Set<string>) => {
|
|
||||||
currentSelection = selection;
|
|
||||||
};
|
|
||||||
|
|
||||||
render(
|
render(
|
||||||
<FileTree
|
<FileTreeSelection
|
||||||
files={testFiles}
|
files={testFiles}
|
||||||
withCheckboxes={true}
|
initialSelectedPaths={["/root"]}
|
||||||
selectedPaths={currentSelection}
|
|
||||||
onSelectionChange={onSelectionChange}
|
|
||||||
expandedFolders={new Set(testFiles.map((f) => f.path))}
|
expandedFolders={new Set(testFiles.map((f) => f.path))}
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
|
|
||||||
const libraryCheckbox = screen.getByText("library").parentElement?.querySelector('button[role="checkbox"]');
|
fireEvent.click(getCheckboxFor("library"));
|
||||||
fireEvent.click(libraryCheckbox!);
|
|
||||||
|
|
||||||
expect(currentSelection.has("/root")).toBe(false);
|
expect(getSelectedPaths()).toEqual(["/root/photos/backups", "/root/photos/profile", "/root/photos/upload"]);
|
||||||
expect(currentSelection.has("/root/photos")).toBe(false);
|
|
||||||
|
|
||||||
expect(currentSelection.has("/root/photos/backups")).toBe(true);
|
|
||||||
expect(currentSelection.has("/root/photos/profile")).toBe(true);
|
|
||||||
expect(currentSelection.has("/root/photos/upload")).toBe(true);
|
|
||||||
expect(currentSelection.size).toBe(3);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("recursive simplification when all children are selected", async () => {
|
test("recursive simplification when all children are selected", () => {
|
||||||
let currentSelection = new Set<string>();
|
render(<FileTreeSelection files={testFiles} expandedFolders={new Set(testFiles.map((f) => f.path))} />);
|
||||||
const onSelectionChange = (selection: Set<string>) => {
|
|
||||||
currentSelection = selection;
|
|
||||||
};
|
|
||||||
|
|
||||||
const { rerender } = render(
|
|
||||||
<FileTree
|
|
||||||
files={testFiles}
|
|
||||||
withCheckboxes={true}
|
|
||||||
selectedPaths={currentSelection}
|
|
||||||
onSelectionChange={onSelectionChange}
|
|
||||||
expandedFolders={new Set(testFiles.map((f) => f.path))}
|
|
||||||
/>,
|
|
||||||
);
|
|
||||||
|
|
||||||
const children = ["backups", "library", "profile", "upload"];
|
const children = ["backups", "library", "profile", "upload"];
|
||||||
|
|
||||||
for (const name of children) {
|
for (const name of children) {
|
||||||
const checkbox = screen.getByText(name).parentElement?.querySelector('button[role="checkbox"]');
|
fireEvent.click(getCheckboxFor(name));
|
||||||
fireEvent.click(checkbox!);
|
|
||||||
|
|
||||||
rerender(
|
|
||||||
<FileTree
|
|
||||||
files={testFiles}
|
|
||||||
withCheckboxes={true}
|
|
||||||
selectedPaths={currentSelection}
|
|
||||||
onSelectionChange={onSelectionChange}
|
|
||||||
expandedFolders={new Set(testFiles.map((f) => f.path))}
|
|
||||||
/>,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(currentSelection.has("/root")).toBe(true);
|
expect(getSelectedPaths()).toEqual(["/root"]);
|
||||||
expect(currentSelection.size).toBe(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("does not simplify to parent if not all children are selected", async () => {
|
test("does not simplify to parent if not all children are selected", () => {
|
||||||
const multipleFiles: FileEntry[] = [
|
const multipleFiles: FileEntry[] = [
|
||||||
{ name: "root", path: "/root", type: "folder" },
|
{ name: "root", path: "/root", type: "folder" },
|
||||||
{ name: "child1", path: "/root/child1", type: "folder" },
|
{ name: "child1", path: "/root/child1", type: "folder" },
|
||||||
{ name: "child2", path: "/root/child2", type: "folder" },
|
{ name: "child2", path: "/root/child2", type: "folder" },
|
||||||
];
|
];
|
||||||
|
|
||||||
let currentSelection = new Set<string>();
|
render(<FileTreeSelection files={multipleFiles} expandedFolders={new Set(multipleFiles.map((f) => f.path))} />);
|
||||||
const onSelectionChange = (selection: Set<string>) => {
|
|
||||||
currentSelection = selection;
|
|
||||||
};
|
|
||||||
|
|
||||||
render(
|
fireEvent.click(getCheckboxFor("child1"));
|
||||||
<FileTree
|
|
||||||
files={multipleFiles}
|
|
||||||
withCheckboxes={true}
|
|
||||||
selectedPaths={currentSelection}
|
|
||||||
onSelectionChange={onSelectionChange}
|
|
||||||
expandedFolders={new Set(multipleFiles.map((f) => f.path))}
|
|
||||||
/>,
|
|
||||||
);
|
|
||||||
|
|
||||||
const child1Checkbox = screen.getByText("child1").parentElement?.querySelector('button[role="checkbox"]');
|
expect(getSelectedPaths()).toEqual(["/root/child1"]);
|
||||||
fireEvent.click(child1Checkbox!);
|
|
||||||
|
|
||||||
expect(currentSelection.has("/root/child1")).toBe(true);
|
|
||||||
expect(currentSelection.has("/root")).toBe(false);
|
|
||||||
expect(currentSelection.size).toBe(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("simplifies existing deep paths when parent is selected", async () => {
|
test("simplifies existing deep paths when parent is selected", () => {
|
||||||
const files: FileEntry[] = [
|
const files: FileEntry[] = [
|
||||||
{ name: "hello", path: "/hello", type: "folder" },
|
{ name: "hello", path: "/hello", type: "folder" },
|
||||||
{ name: "hello_prev", path: "/hello_prev", type: "folder" },
|
{ name: "hello_prev", path: "/hello_prev", type: "folder" },
|
||||||
{ name: "service", path: "/service", type: "folder" },
|
{ name: "service", path: "/service", type: "folder" },
|
||||||
];
|
];
|
||||||
|
|
||||||
let currentSelection = new Set<string>(["/hello", "/hello_prev", "/service/app/data/upload"]);
|
|
||||||
const onSelectionChange = (selection: Set<string>) => {
|
|
||||||
currentSelection = selection;
|
|
||||||
};
|
|
||||||
|
|
||||||
render(
|
render(
|
||||||
<FileTree
|
<FileTreeSelection files={files} initialSelectedPaths={["/hello", "/hello_prev", "/service/app/data/upload"]} />,
|
||||||
files={files}
|
|
||||||
withCheckboxes={true}
|
|
||||||
selectedPaths={currentSelection}
|
|
||||||
onSelectionChange={onSelectionChange}
|
|
||||||
/>,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const serviceCheckbox = screen.getByText("service").parentElement?.querySelector('button[role="checkbox"]');
|
fireEvent.click(getCheckboxFor("service"));
|
||||||
expect(serviceCheckbox).toBeTruthy();
|
|
||||||
|
|
||||||
fireEvent.click(serviceCheckbox!);
|
expect(getSelectedPaths()).toEqual(["/hello", "/hello_prev", "/service"]);
|
||||||
|
|
||||||
expect(currentSelection.has("/service")).toBe(true);
|
|
||||||
expect(currentSelection.has("/service/app/data/upload")).toBe(false);
|
|
||||||
expect(currentSelection.size).toBe(3); // /hello, /hello_prev, /service
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
155
app/client/components/__test__/restore-form.test.tsx
Normal file
155
app/client/components/__test__/restore-form.test.tsx
Normal file
|
|
@ -0,0 +1,155 @@
|
||||||
|
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
||||||
|
import { HttpResponse, http, server } from "~/test/msw/server";
|
||||||
|
import { cleanup, render, screen, userEvent, waitFor, within } from "~/test/test-utils";
|
||||||
|
import { fromAny } from "@total-typescript/shoehorn";
|
||||||
|
|
||||||
|
vi.mock("@tanstack/react-router", async (importOriginal) => {
|
||||||
|
const actual = await importOriginal<typeof import("@tanstack/react-router")>();
|
||||||
|
|
||||||
|
return {
|
||||||
|
...actual,
|
||||||
|
useNavigate: (() => vi.fn(async () => {})) as typeof actual.useNavigate,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
import { RestoreForm } from "../restore-form";
|
||||||
|
|
||||||
|
class MockEventSource {
|
||||||
|
addEventListener() {}
|
||||||
|
close() {}
|
||||||
|
onerror: ((event: Event) => void) | null = null;
|
||||||
|
|
||||||
|
constructor(public url: string) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
const originalEventSource = globalThis.EventSource;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
globalThis.EventSource = MockEventSource as unknown as typeof EventSource;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
globalThis.EventSource = originalEventSource;
|
||||||
|
cleanup();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("RestoreForm", () => {
|
||||||
|
test("restores the selected ancestor folder path from a broader display root", async () => {
|
||||||
|
let restoreRequestBody: unknown;
|
||||||
|
|
||||||
|
server.use(
|
||||||
|
http.get("/api/v1/repositories/:shortId/snapshots/:snapshotId/files", () => {
|
||||||
|
return HttpResponse.json({
|
||||||
|
files: [
|
||||||
|
{ name: "subdir", path: "/mnt/project/subdir", type: "dir" },
|
||||||
|
{ name: "deep.tx", path: "/mnt/project/subdir/deep.tx", type: "file" },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
http.post("/api/v1/repositories/:shortId/restore", async ({ request }) => {
|
||||||
|
restoreRequestBody = await request.json();
|
||||||
|
return HttpResponse.json({
|
||||||
|
success: true,
|
||||||
|
message: "Snapshot restored successfully",
|
||||||
|
filesRestored: 1,
|
||||||
|
filesSkipped: 0,
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
render(
|
||||||
|
<RestoreForm
|
||||||
|
repository={fromAny({ shortId: "repo-1", name: "Repo 1" })}
|
||||||
|
snapshotId="snap-1"
|
||||||
|
returnPath="/repositories/repo-1/snap-1"
|
||||||
|
queryBasePath="/mnt/project/subdir"
|
||||||
|
displayBasePath="/mnt"
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
const row = await screen.findByRole("button", { name: "project" });
|
||||||
|
await userEvent.click(within(row).getByRole("checkbox"));
|
||||||
|
await userEvent.click(screen.getByRole("button", { name: "Restore 1 item" }));
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(restoreRequestBody).toEqual({
|
||||||
|
snapshotId: "snap-1",
|
||||||
|
include: ["/mnt/project"],
|
||||||
|
selectedItemKind: "dir",
|
||||||
|
overwrite: "always",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("restores the selected full path when the display root is unrelated", async () => {
|
||||||
|
let restoreRequestBody: unknown;
|
||||||
|
|
||||||
|
server.use(
|
||||||
|
http.get("/api/v1/repositories/:shortId/snapshots/:snapshotId/files", () => {
|
||||||
|
return HttpResponse.json({
|
||||||
|
files: [
|
||||||
|
{ name: "project", path: "/mnt/project", type: "dir" },
|
||||||
|
{ name: "a.txt", path: "/mnt/project/a.txt", type: "file" },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
http.post("/api/v1/repositories/:shortId/restore", async ({ request }) => {
|
||||||
|
restoreRequestBody = await request.json();
|
||||||
|
return HttpResponse.json({
|
||||||
|
success: true,
|
||||||
|
message: "Snapshot restored successfully",
|
||||||
|
filesRestored: 1,
|
||||||
|
filesSkipped: 0,
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
http.get("/api/v1/volumes/filesystem/browse", () => {
|
||||||
|
return HttpResponse.json({
|
||||||
|
path: "/",
|
||||||
|
directories: [{ name: "restore-target", path: "/restore-target", type: "dir" }],
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
render(
|
||||||
|
<RestoreForm
|
||||||
|
repository={fromAny({ shortId: "repo-1", name: "Repo 1" })}
|
||||||
|
snapshotId="snap-1"
|
||||||
|
returnPath="/repositories/repo-1/snap-1"
|
||||||
|
queryBasePath="/mnt/project"
|
||||||
|
displayBasePath="/other/root"
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
screen.getByText(
|
||||||
|
"This snapshot was created from source paths that do not match this Zerobyte server or the current linked volume. Restoring to the original location is unavailable. Restore it to a custom location, or download it instead.",
|
||||||
|
),
|
||||||
|
).toBeTruthy();
|
||||||
|
expect(screen.getByRole("button", { name: "Original location" }).hasAttribute("disabled")).toBe(true);
|
||||||
|
expect(screen.getByRole("button", { name: "Restore All" }).hasAttribute("disabled")).toBe(true);
|
||||||
|
|
||||||
|
await userEvent.click(screen.getByRole("button", { name: "Change" }));
|
||||||
|
await userEvent.click(await screen.findByRole("button", { name: "restore-target" }));
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByRole("button", { name: "Restore All" }).hasAttribute("disabled")).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
const row = await screen.findByRole("button", { name: "mnt" });
|
||||||
|
await userEvent.click(within(row).getByRole("checkbox"));
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByRole("button", { name: "Restore 1 item" }).hasAttribute("disabled")).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
await userEvent.click(screen.getByRole("button", { name: "Restore 1 item" }));
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(restoreRequestBody).toEqual({
|
||||||
|
snapshotId: "snap-1",
|
||||||
|
include: ["/mnt"],
|
||||||
|
selectedItemKind: "dir",
|
||||||
|
targetPath: "/restore-target",
|
||||||
|
overwrite: "always",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { Link, useMatches, type UIMatch } from "react-router";
|
import { Fragment } from "react";
|
||||||
|
import { useMatches, Link } from "@tanstack/react-router";
|
||||||
import {
|
import {
|
||||||
Breadcrumb,
|
Breadcrumb,
|
||||||
BreadcrumbItem,
|
BreadcrumbItem,
|
||||||
|
|
@ -13,25 +14,22 @@ export interface BreadcrumbItemData {
|
||||||
href?: string;
|
href?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RouteHandle {
|
type BreadcrumbFunction = (match: ReturnType<typeof useMatches>[number]) => BreadcrumbItemData[] | null;
|
||||||
breadcrumb?: (match: UIMatch) => BreadcrumbItemData[] | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function AppBreadcrumb() {
|
export function AppBreadcrumb() {
|
||||||
const matches = useMatches();
|
const matches = useMatches();
|
||||||
|
|
||||||
// Find the last match with a breadcrumb handler
|
|
||||||
const lastMatchWithBreadcrumb = [...matches].reverse().find((match) => {
|
const lastMatchWithBreadcrumb = [...matches].reverse().find((match) => {
|
||||||
const handle = match.handle as RouteHandle | undefined;
|
const breadcrumbFn = match.staticData?.breadcrumb as BreadcrumbFunction | undefined;
|
||||||
return handle?.breadcrumb;
|
return breadcrumbFn;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!lastMatchWithBreadcrumb) {
|
if (!lastMatchWithBreadcrumb) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const handle = lastMatchWithBreadcrumb.handle as RouteHandle;
|
const breadcrumbFn = lastMatchWithBreadcrumb.staticData?.breadcrumb as BreadcrumbFunction;
|
||||||
const breadcrumbs = handle.breadcrumb?.(lastMatchWithBreadcrumb);
|
const breadcrumbs = breadcrumbFn?.(lastMatchWithBreadcrumb);
|
||||||
|
|
||||||
if (!breadcrumbs || breadcrumbs.length === 0) {
|
if (!breadcrumbs || breadcrumbs.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -44,7 +42,7 @@ export function AppBreadcrumb() {
|
||||||
const isLast = index === breadcrumbs.length - 1;
|
const isLast = index === breadcrumbs.length - 1;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div key={`${breadcrumb.label}-${index}`} className="contents">
|
<Fragment key={`${breadcrumb.label}-${index}`}>
|
||||||
<BreadcrumbItem>
|
<BreadcrumbItem>
|
||||||
{isLast || !breadcrumb.href ? (
|
{isLast || !breadcrumb.href ? (
|
||||||
<BreadcrumbPage>{breadcrumb.label}</BreadcrumbPage>
|
<BreadcrumbPage>{breadcrumb.label}</BreadcrumbPage>
|
||||||
|
|
@ -55,7 +53,7 @@ export function AppBreadcrumb() {
|
||||||
)}
|
)}
|
||||||
</BreadcrumbItem>
|
</BreadcrumbItem>
|
||||||
{!isLast && <BreadcrumbSeparator />}
|
{!isLast && <BreadcrumbSeparator />}
|
||||||
</div>
|
</Fragment>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</BreadcrumbList>
|
</BreadcrumbList>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import { Bell, CalendarClock, Database, HardDrive, Settings } from "lucide-react";
|
import { Bell, CalendarClock, Database, HardDrive, Settings, ShieldCheck } from "lucide-react";
|
||||||
import { Link, NavLink } from "react-router";
|
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import {
|
import {
|
||||||
Sidebar,
|
Sidebar,
|
||||||
|
|
@ -11,6 +10,7 @@ import {
|
||||||
SidebarMenu,
|
SidebarMenu,
|
||||||
SidebarMenuButton,
|
SidebarMenuButton,
|
||||||
SidebarMenuItem,
|
SidebarMenuItem,
|
||||||
|
SidebarSeparator,
|
||||||
useSidebar,
|
useSidebar,
|
||||||
} from "~/client/components/ui/sidebar";
|
} from "~/client/components/ui/sidebar";
|
||||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "~/client/components/ui/tooltip";
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "~/client/components/ui/tooltip";
|
||||||
|
|
@ -19,6 +19,8 @@ import { cn } from "~/client/lib/utils";
|
||||||
import { APP_VERSION, RCLONE_VERSION, RESTIC_VERSION, SHOUTRRR_VERSION } from "~/client/lib/version";
|
import { APP_VERSION, RCLONE_VERSION, RESTIC_VERSION, SHOUTRRR_VERSION } from "~/client/lib/version";
|
||||||
import { useUpdates } from "~/client/hooks/use-updates";
|
import { useUpdates } from "~/client/hooks/use-updates";
|
||||||
import { ReleaseNotesDialog } from "./release-notes-dialog";
|
import { ReleaseNotesDialog } from "./release-notes-dialog";
|
||||||
|
import { OrganizationSwitcher } from "./organization-switcher";
|
||||||
|
import { Link } from "@tanstack/react-router";
|
||||||
|
|
||||||
const items = [
|
const items = [
|
||||||
{
|
{
|
||||||
|
|
@ -48,11 +50,17 @@ const items = [
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export function AppSidebar() {
|
type Props = {
|
||||||
const { state } = useSidebar();
|
isInstanceAdmin: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function AppSidebar({ isInstanceAdmin }: Props) {
|
||||||
|
const { state, isMobile, setOpenMobile } = useSidebar();
|
||||||
const { updates, hasUpdate } = useUpdates();
|
const { updates, hasUpdate } = useUpdates();
|
||||||
const [showReleaseNotes, setShowReleaseNotes] = useState(false);
|
const [showReleaseNotes, setShowReleaseNotes] = useState(false);
|
||||||
|
|
||||||
|
const isCollapsed = state === "collapsed";
|
||||||
|
|
||||||
const displayVersion = APP_VERSION.startsWith("v") || APP_VERSION === "dev" ? APP_VERSION : `v${APP_VERSION}`;
|
const displayVersion = APP_VERSION.startsWith("v") || APP_VERSION === "dev" ? APP_VERSION : `v${APP_VERSION}`;
|
||||||
const releaseUrl =
|
const releaseUrl =
|
||||||
APP_VERSION === "dev"
|
APP_VERSION === "dev"
|
||||||
|
|
@ -61,12 +69,12 @@ export function AppSidebar() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Sidebar variant="inset" collapsible="icon" className="p-0">
|
<Sidebar variant="inset" collapsible="icon" className="p-0">
|
||||||
<SidebarHeader className="bg-card-header border-b border-border/50 hidden md:flex h-16.25 flex-row items-center p-4">
|
<SidebarHeader className="bg-card-header border-b border-border/80 dark:border-border/50 hidden md:flex h-16.25 flex-row items-center p-4">
|
||||||
<Link to="/volumes" className="flex items-center gap-3 font-semibold pl-2">
|
<Link to="/volumes" className="flex items-center gap-3 font-semibold pl-2">
|
||||||
<img src="/images/zerobyte.png" alt="Zerobyte Logo" className={cn("h-8 w-8 shrink-0 object-contain -ml-2")} />
|
<img src="/images/zerobyte.png" alt="Zerobyte Logo" className={cn("h-8 w-8 shrink-0 object-contain -ml-2")} />
|
||||||
<span
|
<span
|
||||||
className={cn("text-base transition-all duration-200 -ml-1", {
|
className={cn("text-base transition-all duration-200 -ml-1", {
|
||||||
"opacity-0 w-0 overflow-hidden ": state === "collapsed",
|
"opacity-0 w-0 overflow-hidden ": isCollapsed,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
Zerobyte
|
Zerobyte
|
||||||
|
|
@ -82,18 +90,43 @@ export function AppSidebar() {
|
||||||
<TooltipProvider>
|
<TooltipProvider>
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
<TooltipTrigger asChild>
|
<TooltipTrigger asChild>
|
||||||
<SidebarMenuButton asChild>
|
<SidebarMenuButton asChild className="relative overflow-hidden">
|
||||||
<NavLink to={item.url}>
|
<Link
|
||||||
|
to={item.url}
|
||||||
|
onClick={() => isMobile && setOpenMobile(false)}
|
||||||
|
activeProps={{ className: "bg-strong-accent/10" }}
|
||||||
|
className="w-full flex items-center gap-2"
|
||||||
|
>
|
||||||
{({ isActive }) => (
|
{({ isActive }) => (
|
||||||
<>
|
<>
|
||||||
<item.icon className={cn({ "text-strong-accent": isActive })} />
|
{isActive && (
|
||||||
<span className={cn({ "text-strong-accent": isActive })}>{item.title}</span>
|
<div
|
||||||
|
className={cn("absolute left-0 top-0 h-full w-0.75 bg-strong-accent mr-2", {
|
||||||
|
hidden: isCollapsed,
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<item.icon
|
||||||
|
className={cn("transition-all duration-200", {
|
||||||
|
"text-strong-accent": isActive,
|
||||||
|
"ml-1": isActive && !isCollapsed,
|
||||||
|
"text-muted-foreground": !isActive,
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
<span
|
||||||
|
className={cn({
|
||||||
|
"text-foreground font-medium": isActive,
|
||||||
|
"text-muted-foreground": !isActive,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{item.title}
|
||||||
|
</span>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</NavLink>
|
</Link>
|
||||||
</SidebarMenuButton>
|
</SidebarMenuButton>
|
||||||
</TooltipTrigger>
|
</TooltipTrigger>
|
||||||
<TooltipContent side="right" className={cn({ hidden: state !== "collapsed" })}>
|
<TooltipContent side="right" className={cn({ hidden: !isCollapsed })}>
|
||||||
<p>{item.title}</p>
|
<p>{item.title}</p>
|
||||||
</TooltipContent>
|
</TooltipContent>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|
@ -103,8 +136,66 @@ export function AppSidebar() {
|
||||||
</SidebarMenu>
|
</SidebarMenu>
|
||||||
</SidebarGroupContent>
|
</SidebarGroupContent>
|
||||||
</SidebarGroup>
|
</SidebarGroup>
|
||||||
|
{isInstanceAdmin && (
|
||||||
|
<>
|
||||||
|
<SidebarSeparator />
|
||||||
|
<SidebarGroup>
|
||||||
|
<SidebarGroupContent>
|
||||||
|
<SidebarMenu>
|
||||||
|
<SidebarMenuItem>
|
||||||
|
<TooltipProvider>
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<SidebarMenuButton asChild className="relative overflow-hidden">
|
||||||
|
<Link
|
||||||
|
to="/admin"
|
||||||
|
onClick={() => isMobile && setOpenMobile(false)}
|
||||||
|
activeProps={{ className: "bg-strong-accent/10" }}
|
||||||
|
className="w-full flex items-center gap-2"
|
||||||
|
>
|
||||||
|
{({ isActive }) => (
|
||||||
|
<>
|
||||||
|
{isActive && (
|
||||||
|
<div
|
||||||
|
className={cn("absolute left-0 top-0 h-full w-0.75 bg-strong-accent mr-2", {
|
||||||
|
hidden: isCollapsed,
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<ShieldCheck
|
||||||
|
className={cn("transition-all duration-200", {
|
||||||
|
"text-strong-accent": isActive,
|
||||||
|
"ml-1": isActive && !isCollapsed,
|
||||||
|
"text-muted-foreground": !isActive,
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
<span
|
||||||
|
className={cn({
|
||||||
|
"text-foreground font-medium": isActive,
|
||||||
|
"text-muted-foreground": !isActive,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
Administration
|
||||||
|
</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Link>
|
||||||
|
</SidebarMenuButton>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent side="right" className={cn({ hidden: !isCollapsed })}>
|
||||||
|
<p>Administration</p>
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</TooltipProvider>
|
||||||
|
</SidebarMenuItem>
|
||||||
|
</SidebarMenu>
|
||||||
|
</SidebarGroupContent>
|
||||||
|
</SidebarGroup>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</SidebarContent>
|
</SidebarContent>
|
||||||
<SidebarFooter className="p-4 border-r border-t border-border/50">
|
<SidebarFooter className="p-4 border-r border-border/80 dark:border-border/50">
|
||||||
|
<OrganizationSwitcher />
|
||||||
<div className="flex items-center justify-between gap-2">
|
<div className="flex items-center justify-between gap-2">
|
||||||
<HoverCard openDelay={200}>
|
<HoverCard openDelay={200}>
|
||||||
<HoverCardTrigger asChild>
|
<HoverCardTrigger asChild>
|
||||||
|
|
|
||||||
84
app/client/components/backup-summary-card.tsx
Normal file
84
app/client/components/backup-summary-card.tsx
Normal file
|
|
@ -0,0 +1,84 @@
|
||||||
|
import { Card, CardContent } from "~/client/components/ui/card";
|
||||||
|
import { ByteSize } from "~/client/components/bytes-size";
|
||||||
|
import { useRootLoaderData } from "~/client/hooks/use-root-loader-data";
|
||||||
|
import type { ResticSnapshotSummaryDto } from "@zerobyte/core/restic";
|
||||||
|
import { formatDuration } from "~/utils/utils";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
summary?: ResticSnapshotSummaryDto | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getDurationLabel = (start: string, end: string) => {
|
||||||
|
const startMs = new Date(start).getTime();
|
||||||
|
const endMs = new Date(end).getTime();
|
||||||
|
if (!Number.isFinite(startMs) || !Number.isFinite(endMs) || endMs < startMs) return "-";
|
||||||
|
return formatDuration(Math.round((endMs - startMs) / 1000));
|
||||||
|
};
|
||||||
|
|
||||||
|
export const BackupSummaryCard = ({ summary }: Props) => {
|
||||||
|
const { locale } = useRootLoaderData();
|
||||||
|
|
||||||
|
if (!summary) return null;
|
||||||
|
|
||||||
|
const formatCount = (value: number) => value.toLocaleString(locale);
|
||||||
|
const durationLabel = getDurationLabel(summary.backup_start, summary.backup_end);
|
||||||
|
|
||||||
|
const topStats = [
|
||||||
|
{
|
||||||
|
label: "Data added",
|
||||||
|
value: <ByteSize bytes={summary.data_added} base={1024} />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Data stored",
|
||||||
|
value: <ByteSize bytes={summary.data_added_packed ?? 0} base={1024} />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Files processed",
|
||||||
|
value: formatCount(summary.total_files_processed),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Bytes processed",
|
||||||
|
value: <ByteSize bytes={summary.total_bytes_processed} base={1024} />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Duration",
|
||||||
|
value: durationLabel,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const detailStats = [
|
||||||
|
{ label: "New files", value: formatCount(summary.files_new) },
|
||||||
|
{ label: "Changed files", value: formatCount(summary.files_changed) },
|
||||||
|
{ label: "Unmodified files", value: formatCount(summary.files_unmodified) },
|
||||||
|
{ label: "New dirs", value: formatCount(summary.dirs_new) },
|
||||||
|
{ label: "Changed dirs", value: formatCount(summary.dirs_changed) },
|
||||||
|
{ label: "Unmodified dirs", value: formatCount(summary.dirs_unmodified) },
|
||||||
|
{ label: "Data blobs", value: formatCount(summary.data_blobs) },
|
||||||
|
{ label: "Tree blobs", value: formatCount(summary.tree_blobs) },
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card className="p-4">
|
||||||
|
<CardContent className="px-4">
|
||||||
|
<div className="grid gap-6 grid-cols-2 lg:grid-cols-5">
|
||||||
|
{topStats.map((stat) => (
|
||||||
|
<div key={stat.label} className="flex flex-col gap-1">
|
||||||
|
<span className="text-[11px] uppercase tracking-wide text-muted-foreground">{stat.label}</span>
|
||||||
|
<span className="text-sm font-semibold text-foreground">{stat.value}</span>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<div className="mt-4 border-t border-border/60 pt-3">
|
||||||
|
<div className="grid gap-x-6 gap-y-2 grid-cols-2 lg:grid-cols-4">
|
||||||
|
{detailStats.map((stat) => (
|
||||||
|
<div key={stat.label} className="flex items-center justify-start text-xs gap-2">
|
||||||
|
<span className="font-semibold text-foreground">{stat.value}</span>
|
||||||
|
<span className="text-muted-foreground">{stat.label}</span>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import type React from "react";
|
import type React from "react";
|
||||||
|
import { useFormatBytes } from "~/client/hooks/use-format-bytes";
|
||||||
|
|
||||||
type ByteSizeProps = {
|
type ByteSizeProps = {
|
||||||
bytes: number;
|
bytes: number;
|
||||||
|
|
@ -12,72 +13,8 @@ type ByteSizeProps = {
|
||||||
fallback?: string; // shown if bytes is not a finite number (default: '—')
|
fallback?: string; // shown if bytes is not a finite number (default: '—')
|
||||||
};
|
};
|
||||||
|
|
||||||
const SI_UNITS = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] as const;
|
|
||||||
const IEC_UNITS = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"] as const;
|
|
||||||
|
|
||||||
type FormatBytesResult = {
|
|
||||||
text: string;
|
|
||||||
unit: string;
|
|
||||||
unitIndex: number;
|
|
||||||
numeric: number; // numeric value before formatting (with sign)
|
|
||||||
};
|
|
||||||
|
|
||||||
export function formatBytes(
|
|
||||||
bytes: number,
|
|
||||||
options?: {
|
|
||||||
base?: 1000 | 1024;
|
|
||||||
maximumFractionDigits?: number;
|
|
||||||
smartRounding?: boolean;
|
|
||||||
locale?: string | string[];
|
|
||||||
},
|
|
||||||
): FormatBytesResult {
|
|
||||||
const { base = 1000, maximumFractionDigits = 2, smartRounding = true, locale } = options ?? {};
|
|
||||||
|
|
||||||
if (!Number.isFinite(bytes)) {
|
|
||||||
return {
|
|
||||||
text: "—",
|
|
||||||
unit: "",
|
|
||||||
unitIndex: 0,
|
|
||||||
numeric: NaN,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const units = base === 1024 ? IEC_UNITS : SI_UNITS;
|
|
||||||
|
|
||||||
const sign = Math.sign(bytes) || 1;
|
|
||||||
const abs = Math.abs(bytes);
|
|
||||||
|
|
||||||
let idx = 0;
|
|
||||||
if (abs > 0) {
|
|
||||||
idx = Math.floor(Math.log(abs) / Math.log(base));
|
|
||||||
if (!Number.isFinite(idx)) idx = 0;
|
|
||||||
idx = Math.max(0, Math.min(idx, units.length - 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
const numeric = (abs / base ** idx) * sign;
|
|
||||||
|
|
||||||
const maxFrac = (() => {
|
|
||||||
if (!smartRounding) return maximumFractionDigits;
|
|
||||||
const v = Math.abs(numeric);
|
|
||||||
if (v >= 100) return 0;
|
|
||||||
if (v >= 10) return Math.min(1, maximumFractionDigits);
|
|
||||||
return maximumFractionDigits;
|
|
||||||
})();
|
|
||||||
|
|
||||||
const text = new Intl.NumberFormat(locale, {
|
|
||||||
minimumFractionDigits: 0,
|
|
||||||
maximumFractionDigits: maxFrac,
|
|
||||||
}).format(numeric);
|
|
||||||
|
|
||||||
return {
|
|
||||||
text,
|
|
||||||
unit: units[idx],
|
|
||||||
unitIndex: idx,
|
|
||||||
numeric,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ByteSize(props: ByteSizeProps) {
|
export function ByteSize(props: ByteSizeProps) {
|
||||||
|
const formatBytes = useFormatBytes();
|
||||||
const {
|
const {
|
||||||
bytes,
|
bytes,
|
||||||
base = 1000,
|
base = 1000,
|
||||||
|
|
@ -95,9 +32,10 @@ export function ByteSize(props: ByteSizeProps) {
|
||||||
maximumFractionDigits,
|
maximumFractionDigits,
|
||||||
smartRounding,
|
smartRounding,
|
||||||
locale,
|
locale,
|
||||||
|
fallback,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (text === "—") {
|
if (text === fallback) {
|
||||||
return (
|
return (
|
||||||
<span className={className} style={style}>
|
<span className={className} style={style}>
|
||||||
{fallback}
|
{fallback}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { AlertCircle, CheckCircle2 } from "lucide-react";
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import { FormControl, FormDescription, FormItem, FormLabel, FormMessage } from "~/client/components/ui/form";
|
import { FormControl, FormDescription, FormItem, FormLabel, FormMessage } from "~/client/components/ui/form";
|
||||||
import { Input } from "~/client/components/ui/input";
|
import { Input } from "~/client/components/ui/input";
|
||||||
import { formatDateTime } from "~/client/lib/datetime";
|
import { useTimeFormat } from "~/client/lib/datetime";
|
||||||
import { cn } from "~/client/lib/utils";
|
import { cn } from "~/client/lib/utils";
|
||||||
|
|
||||||
interface CronInputProps {
|
interface CronInputProps {
|
||||||
|
|
@ -13,6 +13,7 @@ interface CronInputProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function CronInput({ value, onChange, error }: CronInputProps) {
|
export function CronInput({ value, onChange, error }: CronInputProps) {
|
||||||
|
const { formatDateTime } = useTimeFormat();
|
||||||
const { isValid, nextRuns, parseError } = useMemo(() => {
|
const { isValid, nextRuns, parseError } = useMemo(() => {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return { isValid: false, nextRuns: [], parseError: null };
|
return { isValid: false, nextRuns: [], parseError: null };
|
||||||
|
|
@ -59,7 +60,7 @@ export function CronInput({ value, onChange, error }: CronInputProps) {
|
||||||
{value && (
|
{value && (
|
||||||
<div>
|
<div>
|
||||||
{isValid ? (
|
{isValid ? (
|
||||||
<CheckCircle2 className="h-4 w-4 text-green-500" />
|
<CheckCircle2 className="h-4 w-4 text-success" />
|
||||||
) : (
|
) : (
|
||||||
<AlertCircle className="h-4 w-4 text-destructive" />
|
<AlertCircle className="h-4 w-4 text-destructive" />
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
54
app/client/components/data-table-sort-header.tsx
Normal file
54
app/client/components/data-table-sort-header.tsx
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
import type { Column } from "@tanstack/react-table";
|
||||||
|
import { ArrowDown, ArrowUp, ArrowUpDown } from "lucide-react";
|
||||||
|
import { Button } from "~/client/components/ui/button";
|
||||||
|
import { cn } from "~/client/lib/utils";
|
||||||
|
|
||||||
|
export function DataTableSortHeader<TData, TValue>({
|
||||||
|
column,
|
||||||
|
title,
|
||||||
|
sortDirection,
|
||||||
|
center = false,
|
||||||
|
}: {
|
||||||
|
column: Column<TData, TValue>;
|
||||||
|
title: string;
|
||||||
|
sortDirection: false | "asc" | "desc";
|
||||||
|
center?: boolean;
|
||||||
|
}) {
|
||||||
|
const icon =
|
||||||
|
sortDirection === "desc" ? (
|
||||||
|
<ArrowDown className="ml-2 h-3.5 w-3.5" />
|
||||||
|
) : sortDirection === "asc" ? (
|
||||||
|
<ArrowUp className="ml-2 h-3.5 w-3.5" />
|
||||||
|
) : (
|
||||||
|
<ArrowUpDown className="ml-2 h-3.5 w-3.5" />
|
||||||
|
);
|
||||||
|
const iconVisibility = sortDirection ? "" : "lg:invisible lg:group-hover/sort:visible";
|
||||||
|
|
||||||
|
if (center) {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
className="h-auto! w-full! p-0! font-inherit hover:bg-transparent uppercase group/sort relative"
|
||||||
|
>
|
||||||
|
<span className="relative flex w-full items-center justify-center">
|
||||||
|
{title}
|
||||||
|
<span className={cn("lg:absolute lg:-right-6 lg:top-1/2 lg:-translate-y-1/2", iconVisibility)}>{icon}</span>
|
||||||
|
</span>
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
className="h-auto! p-0! font-inherit hover:bg-transparent uppercase group/sort"
|
||||||
|
>
|
||||||
|
{title}
|
||||||
|
<span className={iconVisibility}>{icon}</span>
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
||||||
25
app/client/components/dev-panel-listener.tsx
Normal file
25
app/client/components/dev-panel-listener.tsx
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { useState } from "react";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { useHotkeySequence } from "@tanstack/react-hotkeys";
|
||||||
|
import { getDevPanelOptions } from "~/client/api-client/@tanstack/react-query.gen";
|
||||||
|
import { DevPanel } from "./dev-panel";
|
||||||
|
|
||||||
|
export function DevPanelListener() {
|
||||||
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
const { data: devPanelStatus } = useQuery({
|
||||||
|
...getDevPanelOptions(),
|
||||||
|
});
|
||||||
|
|
||||||
|
useHotkeySequence(["D", "E", "V"], () => setIsOpen(true), {
|
||||||
|
enabled: !!devPanelStatus?.enabled,
|
||||||
|
preventDefault: true,
|
||||||
|
ignoreInputs: true,
|
||||||
|
timeout: 1000,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!devPanelStatus?.enabled) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <DevPanel open={isOpen} onOpenChange={setIsOpen} />;
|
||||||
|
}
|
||||||
229
app/client/components/dev-panel.tsx
Normal file
229
app/client/components/dev-panel.tsx
Normal file
|
|
@ -0,0 +1,229 @@
|
||||||
|
import { useRef, useState, useCallback } from "react";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { Play, Loader2, Trash2, Terminal } from "lucide-react";
|
||||||
|
import { Button } from "./ui/button";
|
||||||
|
import { cn } from "~/client/lib/utils";
|
||||||
|
import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetDescription } from "./ui/sheet";
|
||||||
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./ui/select";
|
||||||
|
import { Label } from "./ui/label";
|
||||||
|
import { Textarea } from "./ui/textarea";
|
||||||
|
import { listRepositoriesOptions } from "~/client/api-client/@tanstack/react-query.gen";
|
||||||
|
import { devPanelExec } from "~/client/api-client/sdk.gen";
|
||||||
|
import { parseError } from "../lib/errors";
|
||||||
|
|
||||||
|
type DevPanelProps = {
|
||||||
|
open: boolean;
|
||||||
|
onOpenChange: (open: boolean) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
type SseOutputEvent = {
|
||||||
|
type: "stdout" | "stderr";
|
||||||
|
line: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type SseDoneEvent = {
|
||||||
|
type: "done";
|
||||||
|
exitCode: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
type SseErrorEvent = {
|
||||||
|
type: "error";
|
||||||
|
message: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type SseEvent = SseOutputEvent | SseDoneEvent | SseErrorEvent;
|
||||||
|
|
||||||
|
export function DevPanel({ open, onOpenChange }: DevPanelProps) {
|
||||||
|
const { data: repositories = [] } = useQuery({
|
||||||
|
...listRepositoriesOptions(),
|
||||||
|
enabled: open,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [selectedRepoId, setSelectedRepoId] = useState<string>("");
|
||||||
|
const [commandLine, setCommandLine] = useState("snapshots");
|
||||||
|
const [output, setOutput] = useState<string[]>([]);
|
||||||
|
const [isRunning, setIsRunning] = useState(false);
|
||||||
|
const abortControllerRef = useRef<AbortController | null>(null);
|
||||||
|
const outputRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
const scrollToBottom = useCallback(() => {
|
||||||
|
if (outputRef.current) {
|
||||||
|
outputRef.current.scrollTop = outputRef.current.scrollHeight;
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const appendOutput = useCallback(
|
||||||
|
(line: string) => {
|
||||||
|
setOutput((prev) => {
|
||||||
|
const newOutput = [...prev, line];
|
||||||
|
setTimeout(scrollToBottom, 0);
|
||||||
|
return newOutput;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[scrollToBottom],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleRun = async () => {
|
||||||
|
if (!selectedRepoId || !commandLine.trim()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setOutput([]);
|
||||||
|
setIsRunning(true);
|
||||||
|
appendOutput(`$ restic ${commandLine}`.trim());
|
||||||
|
appendOutput("---");
|
||||||
|
|
||||||
|
abortControllerRef.current = new AbortController();
|
||||||
|
|
||||||
|
const trimmedLine = commandLine.trim();
|
||||||
|
const parts = trimmedLine.split(/\s+/);
|
||||||
|
const command = parts[0];
|
||||||
|
const argsArray = parts.slice(1);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await devPanelExec({
|
||||||
|
path: { shortId: selectedRepoId },
|
||||||
|
body: { command, args: argsArray.length > 0 ? argsArray : undefined },
|
||||||
|
signal: abortControllerRef.current.signal,
|
||||||
|
});
|
||||||
|
|
||||||
|
for await (const event of result.stream) {
|
||||||
|
if (abortControllerRef.current.signal.aborted) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const data = event as unknown as SseEvent;
|
||||||
|
|
||||||
|
if (!data || typeof data !== "object") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.type === "stdout" || data.type === "stderr") {
|
||||||
|
appendOutput(data.line);
|
||||||
|
} else if (data.type === "done") {
|
||||||
|
appendOutput(`---`);
|
||||||
|
appendOutput(`Command finished with exit code: ${data.exitCode}`);
|
||||||
|
} else if (data.type === "error") {
|
||||||
|
appendOutput(`Error: ${data.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
if (err instanceof Error && err.name === "AbortError") {
|
||||||
|
appendOutput("---");
|
||||||
|
appendOutput("Command cancelled");
|
||||||
|
} else {
|
||||||
|
appendOutput(`Error: ${parseError(err)?.message}`);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
setIsRunning(false);
|
||||||
|
abortControllerRef.current = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCancel = () => {
|
||||||
|
abortControllerRef.current?.abort();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClear = () => {
|
||||||
|
setOutput([]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClose = () => {
|
||||||
|
if (isRunning) {
|
||||||
|
handleCancel();
|
||||||
|
}
|
||||||
|
onOpenChange(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Sheet open={open} onOpenChange={handleClose}>
|
||||||
|
<SheetContent side="right" className="w-full sm:max-w-xl flex flex-col px-4">
|
||||||
|
<SheetHeader>
|
||||||
|
<SheetTitle className="flex items-center gap-2">
|
||||||
|
<Terminal className="h-5 w-5" />
|
||||||
|
Dev Panel
|
||||||
|
</SheetTitle>
|
||||||
|
<SheetDescription>Execute restic commands against a repository</SheetDescription>
|
||||||
|
</SheetHeader>
|
||||||
|
|
||||||
|
<div className="flex flex-col gap-4 flex-1 min-h-0 mt-4">
|
||||||
|
<div className="grid gap-4">
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<Label htmlFor="repository">Repository</Label>
|
||||||
|
<Select value={selectedRepoId} onValueChange={setSelectedRepoId}>
|
||||||
|
<SelectTrigger id="repository">
|
||||||
|
<SelectValue placeholder="Select a repository" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{repositories.map((repo) => (
|
||||||
|
<SelectItem key={repo.id} value={repo.shortId}>
|
||||||
|
{repo.name} ({repo.type})
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<Label htmlFor="command">Command</Label>
|
||||||
|
<Textarea
|
||||||
|
id="command"
|
||||||
|
placeholder="e.g., snapshots, check --dry-run, forget --keep-last 10"
|
||||||
|
value={commandLine}
|
||||||
|
onChange={(e) => setCommandLine(e.target.value)}
|
||||||
|
className="font-mono text-sm"
|
||||||
|
rows={2}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<Button onClick={handleRun} disabled={isRunning || !selectedRepoId || !commandLine.trim()}>
|
||||||
|
<Loader2 className={cn("h-4 w-4 animate-spin mr-2", { hidden: !isRunning })} />
|
||||||
|
<Play className={cn("h-4 w-4 mr-2", { hidden: isRunning })} />
|
||||||
|
<span className={cn({ hidden: !isRunning })}>Running...</span>
|
||||||
|
<span className={cn({ hidden: isRunning })}>Run</span>
|
||||||
|
</Button>
|
||||||
|
<Button variant="destructive" onClick={handleCancel} className={cn({ hidden: !isRunning })}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button variant="outline" onClick={handleClear} disabled={isRunning}>
|
||||||
|
<Trash2 className="h-4 w-4 mr-2" />
|
||||||
|
Clear
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex-1 min-h-0 border rounded-md bg-muted/30">
|
||||||
|
<div ref={outputRef} className="h-full overflow-auto p-3 font-mono text-xs">
|
||||||
|
<div className={cn("text-muted-foreground", { hidden: output.length > 0 })}>
|
||||||
|
Output will appear here...
|
||||||
|
</div>
|
||||||
|
<div className={cn("space-y-0.5", { hidden: output.length === 0 })}>
|
||||||
|
{output.map((line, i) => {
|
||||||
|
let displayLine = line;
|
||||||
|
let isJson = false;
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(line);
|
||||||
|
displayLine = JSON.stringify(parsed, null, 2);
|
||||||
|
isJson = true;
|
||||||
|
} catch {
|
||||||
|
// Not valid JSON, display as-is
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<pre
|
||||||
|
key={`${i}-${line.slice(0, 20)}`}
|
||||||
|
className={cn("whitespace-pre-wrap break-all text-xs", {
|
||||||
|
"wrap-break-word text-[10px] leading-tight": isJson,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{displayLine}
|
||||||
|
</pre>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</SheetContent>
|
||||||
|
</Sheet>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -1,74 +0,0 @@
|
||||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
||||||
import { FileTree } from "./file-tree";
|
|
||||||
import { ScrollArea } from "./ui/scroll-area";
|
|
||||||
import { browseFilesystemOptions } from "../api-client/@tanstack/react-query.gen";
|
|
||||||
import { useFileBrowser } from "../hooks/use-file-browser";
|
|
||||||
|
|
||||||
type Props = {
|
|
||||||
onSelectPath: (path: string) => void;
|
|
||||||
selectedPath?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const DirectoryBrowser = ({ onSelectPath, selectedPath }: Props) => {
|
|
||||||
const queryClient = useQueryClient();
|
|
||||||
|
|
||||||
const { data, isLoading } = useQuery({
|
|
||||||
...browseFilesystemOptions({ query: { path: "/" } }),
|
|
||||||
});
|
|
||||||
|
|
||||||
const fileBrowser = useFileBrowser({
|
|
||||||
initialData: data,
|
|
||||||
isLoading,
|
|
||||||
fetchFolder: async (path) => {
|
|
||||||
return await queryClient.ensureQueryData(browseFilesystemOptions({ query: { path } }));
|
|
||||||
},
|
|
||||||
prefetchFolder: (path) => {
|
|
||||||
void queryClient.prefetchQuery(browseFilesystemOptions({ query: { path } }));
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (fileBrowser.isLoading) {
|
|
||||||
return (
|
|
||||||
<div className="border rounded-lg overflow-hidden">
|
|
||||||
<ScrollArea className="h-64">
|
|
||||||
<div className="text-sm text-gray-500 p-4">Loading directories...</div>
|
|
||||||
</ScrollArea>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fileBrowser.isEmpty) {
|
|
||||||
return (
|
|
||||||
<div className="border rounded-lg overflow-hidden">
|
|
||||||
<ScrollArea className="h-64">
|
|
||||||
<div className="text-sm text-gray-500 p-4">No subdirectories found</div>
|
|
||||||
</ScrollArea>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="border rounded-lg overflow-hidden">
|
|
||||||
<ScrollArea className="h-64">
|
|
||||||
<FileTree
|
|
||||||
files={fileBrowser.fileArray}
|
|
||||||
onFolderExpand={fileBrowser.handleFolderExpand}
|
|
||||||
onFolderHover={fileBrowser.handleFolderHover}
|
|
||||||
expandedFolders={fileBrowser.expandedFolders}
|
|
||||||
loadingFolders={fileBrowser.loadingFolders}
|
|
||||||
foldersOnly
|
|
||||||
selectableFolders
|
|
||||||
selectedFolder={selectedPath}
|
|
||||||
onFolderSelect={onSelectPath}
|
|
||||||
/>
|
|
||||||
</ScrollArea>
|
|
||||||
|
|
||||||
{selectedPath && (
|
|
||||||
<div className="bg-muted/50 border-t p-2 text-sm">
|
|
||||||
<div className="font-medium text-muted-foreground">Selected path:</div>
|
|
||||||
<div className="font-mono text-xs break-all">{selectedPath}</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
@ -0,0 +1,244 @@
|
||||||
|
import type { ComponentProps } from "react";
|
||||||
|
import { afterEach, describe, expect, test } from "vitest";
|
||||||
|
import { HttpResponse, http, server } from "~/test/msw/server";
|
||||||
|
import { cleanup, fireEvent, render, screen, userEvent, waitFor, within } from "~/test/test-utils";
|
||||||
|
|
||||||
|
type SnapshotFilesRequest = {
|
||||||
|
shortId: string;
|
||||||
|
snapshotId: string;
|
||||||
|
path: string | null;
|
||||||
|
offset: string | null;
|
||||||
|
limit: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const snapshotFiles = {
|
||||||
|
files: [
|
||||||
|
{ name: "project", path: "/mnt/project", type: "dir" },
|
||||||
|
{ name: "a.txt", path: "/mnt/project/a.txt", type: "file" },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
import { SnapshotTreeBrowser } from "../snapshot-tree-browser";
|
||||||
|
|
||||||
|
const mockListSnapshotFiles = (response = snapshotFiles) => {
|
||||||
|
const requests: SnapshotFilesRequest[] = [];
|
||||||
|
|
||||||
|
server.use(
|
||||||
|
http.get("/api/v1/repositories/:shortId/snapshots/:snapshotId/files", ({ params, request }) => {
|
||||||
|
const url = new URL(request.url);
|
||||||
|
requests.push({
|
||||||
|
shortId: String(params.shortId),
|
||||||
|
snapshotId: String(params.snapshotId),
|
||||||
|
path: url.searchParams.get("path"),
|
||||||
|
offset: url.searchParams.get("offset"),
|
||||||
|
limit: url.searchParams.get("limit"),
|
||||||
|
});
|
||||||
|
|
||||||
|
return HttpResponse.json(response);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
return requests;
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderSnapshotTreeBrowser = (props: Partial<ComponentProps<typeof SnapshotTreeBrowser>> = {}) => {
|
||||||
|
return render(
|
||||||
|
<SnapshotTreeBrowser
|
||||||
|
repositoryId="repo-1"
|
||||||
|
snapshotId="snap-1"
|
||||||
|
queryBasePath="/mnt/project"
|
||||||
|
displayBasePath="/mnt"
|
||||||
|
{...props}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
cleanup();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("SnapshotTreeBrowser", () => {
|
||||||
|
test("renders the query root folder when display base path is broader than query base path", async () => {
|
||||||
|
mockListSnapshotFiles();
|
||||||
|
|
||||||
|
renderSnapshotTreeBrowser();
|
||||||
|
|
||||||
|
expect(await screen.findByRole("button", { name: "project" })).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("renders ancestor folders when the query root is nested multiple levels below the display root", async () => {
|
||||||
|
mockListSnapshotFiles({
|
||||||
|
files: [
|
||||||
|
{ name: "subdir", path: "/mnt/project/subdir", type: "dir" },
|
||||||
|
{ name: "a.txt", path: "/mnt/project/subdir/a.txt", type: "file" },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
renderSnapshotTreeBrowser({
|
||||||
|
queryBasePath: "/mnt/project/subdir",
|
||||||
|
displayBasePath: "/mnt",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(await screen.findByRole("button", { name: "project" })).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("renders synthesized ancestor folders for a single file when no display base path is available", async () => {
|
||||||
|
const requests = mockListSnapshotFiles({
|
||||||
|
files: [{ name: "report.txt", path: "/mnt/project/report.txt", type: "file" }],
|
||||||
|
});
|
||||||
|
|
||||||
|
renderSnapshotTreeBrowser({
|
||||||
|
queryBasePath: "/mnt/project/report.txt",
|
||||||
|
displayBasePath: undefined,
|
||||||
|
});
|
||||||
|
|
||||||
|
const mntRow = await screen.findByRole("button", { name: "mnt" });
|
||||||
|
const mntExpandIcon = mntRow.querySelector("svg");
|
||||||
|
if (!mntExpandIcon) {
|
||||||
|
throw new Error("Expected expand icon for mnt row");
|
||||||
|
}
|
||||||
|
fireEvent.click(mntExpandIcon);
|
||||||
|
|
||||||
|
expect(await screen.findByRole("button", { name: "project" })).toBeTruthy();
|
||||||
|
expect(requests[0]).toEqual({
|
||||||
|
shortId: "repo-1",
|
||||||
|
snapshotId: "snap-1",
|
||||||
|
path: "/mnt/project/report.txt",
|
||||||
|
offset: null,
|
||||||
|
limit: null,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns the ancestor folder path when selecting above the query root", async () => {
|
||||||
|
mockListSnapshotFiles({
|
||||||
|
files: [
|
||||||
|
{ name: "subdir", path: "/mnt/project/subdir", type: "dir" },
|
||||||
|
{ name: "a.txt", path: "/mnt/project/subdir/a.txt", type: "file" },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
let selectedPaths: Set<string> | undefined;
|
||||||
|
let selectedKind: "file" | "dir" | null = null;
|
||||||
|
|
||||||
|
renderSnapshotTreeBrowser({
|
||||||
|
queryBasePath: "/mnt/project/subdir",
|
||||||
|
displayBasePath: "/mnt",
|
||||||
|
withCheckboxes: true,
|
||||||
|
onSelectionChange: (paths) => {
|
||||||
|
selectedPaths = paths;
|
||||||
|
},
|
||||||
|
onSingleSelectionKindChange: (kind) => {
|
||||||
|
selectedKind = kind;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const row = await screen.findByRole("button", { name: "project" });
|
||||||
|
const checkbox = within(row).getByRole("checkbox");
|
||||||
|
|
||||||
|
await userEvent.click(checkbox);
|
||||||
|
|
||||||
|
expect(selectedPaths ? Array.from(selectedPaths) : []).toEqual(["/mnt/project"]);
|
||||||
|
expect(selectedKind === "dir").toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("keeps full paths when the display root does not contain the query root", async () => {
|
||||||
|
mockListSnapshotFiles();
|
||||||
|
|
||||||
|
let selectedPaths: Set<string> | undefined;
|
||||||
|
let selectedKind: "file" | "dir" | null = null;
|
||||||
|
|
||||||
|
renderSnapshotTreeBrowser({
|
||||||
|
queryBasePath: "/mnt/project",
|
||||||
|
displayBasePath: "/other/root",
|
||||||
|
withCheckboxes: true,
|
||||||
|
onSelectionChange: (paths) => {
|
||||||
|
selectedPaths = paths;
|
||||||
|
},
|
||||||
|
onSingleSelectionKindChange: (kind) => {
|
||||||
|
selectedKind = kind;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const row = await screen.findByRole("button", { name: "mnt" });
|
||||||
|
const checkbox = within(row).getByRole("checkbox");
|
||||||
|
|
||||||
|
await userEvent.click(checkbox);
|
||||||
|
|
||||||
|
expect(selectedPaths ? Array.from(selectedPaths) : []).toEqual(["/mnt"]);
|
||||||
|
expect(selectedKind === "dir").toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("shows selected folder state when full paths are provided from the parent", async () => {
|
||||||
|
mockListSnapshotFiles();
|
||||||
|
|
||||||
|
renderSnapshotTreeBrowser({
|
||||||
|
withCheckboxes: true,
|
||||||
|
selectedPaths: new Set(["/mnt/project"]),
|
||||||
|
onSelectionChange: () => {},
|
||||||
|
});
|
||||||
|
|
||||||
|
const row = await screen.findByRole("button", { name: "project" });
|
||||||
|
const checkbox = within(row).getByRole("checkbox");
|
||||||
|
|
||||||
|
expect(checkbox.getAttribute("aria-checked")).toBe("true");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns the full snapshot path and kind when selecting a displayed folder", async () => {
|
||||||
|
mockListSnapshotFiles();
|
||||||
|
|
||||||
|
let selectedPaths: Set<string> | undefined;
|
||||||
|
let selectedKind: "file" | "dir" | null = null;
|
||||||
|
|
||||||
|
renderSnapshotTreeBrowser({
|
||||||
|
withCheckboxes: true,
|
||||||
|
onSelectionChange: (paths) => {
|
||||||
|
selectedPaths = paths;
|
||||||
|
},
|
||||||
|
onSingleSelectionKindChange: (kind) => {
|
||||||
|
selectedKind = kind;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const row = await screen.findByRole("button", { name: "project" });
|
||||||
|
const checkbox = within(row).getByRole("checkbox");
|
||||||
|
|
||||||
|
await userEvent.click(checkbox);
|
||||||
|
|
||||||
|
expect(selectedPaths ? Array.from(selectedPaths) : []).toEqual(["/mnt/project"]);
|
||||||
|
expect(selectedKind === "dir").toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("uses the query base path for the initial request when display base path is broader", async () => {
|
||||||
|
const requests = mockListSnapshotFiles();
|
||||||
|
|
||||||
|
renderSnapshotTreeBrowser();
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(requests[0]).toEqual({
|
||||||
|
shortId: "repo-1",
|
||||||
|
snapshotId: "snap-1",
|
||||||
|
path: "/mnt/project",
|
||||||
|
offset: null,
|
||||||
|
limit: null,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("shows the query root contents when display and query roots differ", async () => {
|
||||||
|
mockListSnapshotFiles();
|
||||||
|
|
||||||
|
renderSnapshotTreeBrowser();
|
||||||
|
|
||||||
|
const row = await screen.findByRole("button", { name: "project" });
|
||||||
|
const expandIcon = row.querySelector("svg");
|
||||||
|
if (!expandIcon) {
|
||||||
|
throw new Error("Expected expand icon for folder row");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!screen.queryByRole("button", { name: "a.txt" })) {
|
||||||
|
fireEvent.click(expandIcon);
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(await screen.findByRole("button", { name: "a.txt" })).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
24
app/client/components/file-browsers/directory-browser.tsx
Normal file
24
app/client/components/file-browsers/directory-browser.tsx
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
import { LocalFileBrowser } from "./local-file-browser";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
onSelectPath: (path: string) => void;
|
||||||
|
selectedPath?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const DirectoryBrowser = ({ onSelectPath, selectedPath }: Props) => {
|
||||||
|
return (
|
||||||
|
<LocalFileBrowser
|
||||||
|
className="border rounded-lg overflow-hidden"
|
||||||
|
useScrollArea
|
||||||
|
scrollAreaClassName="h-64"
|
||||||
|
foldersOnly
|
||||||
|
selectableFolders
|
||||||
|
selectedFolder={selectedPath}
|
||||||
|
onFolderSelect={onSelectPath}
|
||||||
|
showSelectedPathFooter
|
||||||
|
selectedPath={selectedPath}
|
||||||
|
loadingMessage="Loading directories..."
|
||||||
|
emptyMessage="No subdirectories found"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
149
app/client/components/file-browsers/file-browser.tsx
Normal file
149
app/client/components/file-browsers/file-browser.tsx
Normal file
|
|
@ -0,0 +1,149 @@
|
||||||
|
import { type ReactNode } from "react";
|
||||||
|
import { FolderOpen } from "lucide-react";
|
||||||
|
import { FileTree, type FileEntry } from "~/client/components/file-tree";
|
||||||
|
import { ScrollArea } from "~/client/components/ui/scroll-area";
|
||||||
|
import { cn } from "~/client/lib/utils";
|
||||||
|
|
||||||
|
type PaginationState = {
|
||||||
|
hasMore: boolean;
|
||||||
|
isLoadingMore: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type FileBrowserUiProps = {
|
||||||
|
className?: string;
|
||||||
|
treeContainerClassName?: string;
|
||||||
|
treeClassName?: string;
|
||||||
|
useScrollArea?: boolean;
|
||||||
|
scrollAreaClassName?: string;
|
||||||
|
stateClassName?: string;
|
||||||
|
loadingMessage?: string;
|
||||||
|
emptyMessage?: string;
|
||||||
|
emptyDescription?: string;
|
||||||
|
emptyIcon?: ReactNode;
|
||||||
|
withCheckboxes?: boolean;
|
||||||
|
selectedPaths?: Set<string>;
|
||||||
|
onSelectionChange?: (paths: Set<string>) => void;
|
||||||
|
foldersOnly?: boolean;
|
||||||
|
selectableFolders?: boolean;
|
||||||
|
onFolderSelect?: (folderPath: string) => void;
|
||||||
|
selectedFolder?: string;
|
||||||
|
onFileSelect?: (filePath: string) => void;
|
||||||
|
selectedFile?: string;
|
||||||
|
showSelectedPathFooter?: boolean;
|
||||||
|
selectedPath?: string;
|
||||||
|
selectedPathLabel?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type FileBrowserProps = FileBrowserUiProps & {
|
||||||
|
isLoading: boolean;
|
||||||
|
isEmpty: boolean;
|
||||||
|
errorMessage?: string;
|
||||||
|
fileArray: FileEntry[];
|
||||||
|
expandedFolders: Set<string>;
|
||||||
|
loadingFolders: Set<string>;
|
||||||
|
onFolderExpand: (folderPath: string) => void | Promise<void>;
|
||||||
|
onFolderHover: (folderPath: string) => void;
|
||||||
|
onLoadMore: (folderPath: string) => void | Promise<void>;
|
||||||
|
getFolderPagination: (folderPath: string) => PaginationState;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const FileBrowser = (props: FileBrowserProps) => {
|
||||||
|
const {
|
||||||
|
className,
|
||||||
|
treeContainerClassName,
|
||||||
|
treeClassName,
|
||||||
|
useScrollArea = false,
|
||||||
|
scrollAreaClassName,
|
||||||
|
stateClassName,
|
||||||
|
loadingMessage = "Loading files...",
|
||||||
|
emptyMessage = "No files found.",
|
||||||
|
emptyDescription,
|
||||||
|
emptyIcon,
|
||||||
|
withCheckboxes = false,
|
||||||
|
selectedPaths,
|
||||||
|
onSelectionChange,
|
||||||
|
foldersOnly = false,
|
||||||
|
selectableFolders = false,
|
||||||
|
onFolderSelect,
|
||||||
|
selectedFolder,
|
||||||
|
onFileSelect,
|
||||||
|
selectedFile,
|
||||||
|
showSelectedPathFooter = false,
|
||||||
|
selectedPath,
|
||||||
|
selectedPathLabel = "Selected path:",
|
||||||
|
isLoading,
|
||||||
|
isEmpty,
|
||||||
|
errorMessage,
|
||||||
|
fileArray,
|
||||||
|
expandedFolders,
|
||||||
|
loadingFolders,
|
||||||
|
onFolderExpand,
|
||||||
|
onFolderHover,
|
||||||
|
onLoadMore,
|
||||||
|
getFolderPagination,
|
||||||
|
} = props;
|
||||||
|
|
||||||
|
const resolvedSelectedPath = selectedPath ?? selectedFolder;
|
||||||
|
const resolvedEmptyIcon =
|
||||||
|
emptyIcon === undefined ? <FolderOpen className="mb-2 h-12 w-12 text-muted-foreground" /> : emptyIcon;
|
||||||
|
|
||||||
|
let body: ReactNode;
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
body = (
|
||||||
|
<div className={cn("flex min-h-50 flex-col items-center justify-center p-6 text-center", stateClassName)}>
|
||||||
|
<p className="text-muted-foreground">{loadingMessage}</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
} else if (errorMessage) {
|
||||||
|
body = (
|
||||||
|
<div className={cn("flex min-h-50 flex-col items-center justify-center p-6 text-center", stateClassName)}>
|
||||||
|
<p className="text-destructive">{errorMessage}</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
} else if (isEmpty) {
|
||||||
|
body = (
|
||||||
|
<div className={cn("flex min-h-50 flex-col items-center justify-center p-6 text-center", stateClassName)}>
|
||||||
|
{resolvedEmptyIcon}
|
||||||
|
<p className="text-muted-foreground">{emptyMessage}</p>
|
||||||
|
{emptyDescription && <p className="mt-2 text-sm text-muted-foreground">{emptyDescription}</p>}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
body = (
|
||||||
|
<FileTree
|
||||||
|
files={fileArray}
|
||||||
|
onFolderExpand={onFolderExpand}
|
||||||
|
onFolderHover={onFolderHover}
|
||||||
|
onLoadMore={onLoadMore}
|
||||||
|
getFolderPagination={getFolderPagination}
|
||||||
|
expandedFolders={expandedFolders}
|
||||||
|
loadingFolders={loadingFolders}
|
||||||
|
className={treeClassName}
|
||||||
|
withCheckboxes={withCheckboxes}
|
||||||
|
selectedPaths={selectedPaths}
|
||||||
|
onSelectionChange={onSelectionChange}
|
||||||
|
foldersOnly={foldersOnly}
|
||||||
|
selectableFolders={selectableFolders}
|
||||||
|
onFolderSelect={onFolderSelect}
|
||||||
|
selectedFolder={selectedFolder}
|
||||||
|
onFileSelect={onFileSelect}
|
||||||
|
selectedFile={selectedFile}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const bodyWithScroll = useScrollArea ? <ScrollArea className={scrollAreaClassName}>{body}</ScrollArea> : body;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={className}>
|
||||||
|
<div className={treeContainerClassName}>{bodyWithScroll}</div>
|
||||||
|
{showSelectedPathFooter && resolvedSelectedPath && (
|
||||||
|
<div className="bg-muted/50 border-t p-2 text-sm">
|
||||||
|
<div className="font-medium text-muted-foreground">{selectedPathLabel}</div>
|
||||||
|
<div className="font-mono text-xs break-all">{resolvedSelectedPath}</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
51
app/client/components/file-browsers/local-file-browser.tsx
Normal file
51
app/client/components/file-browsers/local-file-browser.tsx
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { browseFilesystemOptions } from "~/client/api-client/@tanstack/react-query.gen";
|
||||||
|
import { FileBrowser, type FileBrowserUiProps } from "~/client/components/file-browsers/file-browser";
|
||||||
|
import { useFileBrowser } from "~/client/hooks/use-file-browser";
|
||||||
|
import { parseError } from "~/client/lib/errors";
|
||||||
|
import { normalizeAbsolutePath } from "@zerobyte/core/utils";
|
||||||
|
import { logger } from "~/client/lib/logger";
|
||||||
|
|
||||||
|
type LocalFileBrowserProps = FileBrowserUiProps & {
|
||||||
|
initialPath?: string;
|
||||||
|
enabled?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const LocalFileBrowser = ({ initialPath = "/", enabled = true, ...uiProps }: LocalFileBrowserProps) => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const normalizedInitialPath = normalizeAbsolutePath(initialPath);
|
||||||
|
|
||||||
|
const { data, isLoading, error } = useQuery({
|
||||||
|
...browseFilesystemOptions({ query: { path: normalizedInitialPath } }),
|
||||||
|
enabled,
|
||||||
|
});
|
||||||
|
|
||||||
|
const fileBrowser = useFileBrowser({
|
||||||
|
initialData: data,
|
||||||
|
isLoading,
|
||||||
|
fetchFolder: async (path) => {
|
||||||
|
return await queryClient.ensureQueryData(browseFilesystemOptions({ query: { path } }));
|
||||||
|
},
|
||||||
|
prefetchFolder: (path) => {
|
||||||
|
void queryClient.prefetchQuery(browseFilesystemOptions({ query: { path } })).catch((e) => logger.error(e));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FileBrowser
|
||||||
|
{...uiProps}
|
||||||
|
fileArray={fileBrowser.fileArray}
|
||||||
|
expandedFolders={fileBrowser.expandedFolders}
|
||||||
|
loadingFolders={fileBrowser.loadingFolders}
|
||||||
|
onFolderExpand={fileBrowser.handleFolderExpand}
|
||||||
|
onFolderHover={fileBrowser.handleFolderHover}
|
||||||
|
onLoadMore={fileBrowser.handleLoadMore}
|
||||||
|
getFolderPagination={fileBrowser.getFolderPagination}
|
||||||
|
isLoading={fileBrowser.isLoading}
|
||||||
|
isEmpty={fileBrowser.isEmpty}
|
||||||
|
errorMessage={parseError(error)?.message}
|
||||||
|
loadingMessage={uiProps.loadingMessage ?? "Loading directories..."}
|
||||||
|
emptyMessage={uiProps.emptyMessage ?? "No subdirectories found"}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
157
app/client/components/file-browsers/snapshot-tree-browser.tsx
Normal file
157
app/client/components/file-browsers/snapshot-tree-browser.tsx
Normal file
|
|
@ -0,0 +1,157 @@
|
||||||
|
import { useCallback, useMemo } from "react";
|
||||||
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { listSnapshotFilesOptions } from "~/client/api-client/@tanstack/react-query.gen";
|
||||||
|
import { FileBrowser, type FileBrowserUiProps } from "~/client/components/file-browsers/file-browser";
|
||||||
|
import { useFileBrowser } from "~/client/hooks/use-file-browser";
|
||||||
|
import { parseError } from "~/client/lib/errors";
|
||||||
|
import { isPathWithin, normalizeAbsolutePath } from "@zerobyte/core/utils";
|
||||||
|
|
||||||
|
function createPathPrefixFns(basePath: string) {
|
||||||
|
return {
|
||||||
|
strip(path: string) {
|
||||||
|
if (basePath === "/") return path;
|
||||||
|
if (path === basePath) return "/";
|
||||||
|
if (path.startsWith(`${basePath}/`)) return path.slice(basePath.length);
|
||||||
|
return path;
|
||||||
|
},
|
||||||
|
add(displayPath: string) {
|
||||||
|
if (basePath === "/") return displayPath;
|
||||||
|
if (displayPath === "/") return basePath;
|
||||||
|
return `${basePath}${displayPath}`;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
type SnapshotTreeBrowserProps = FileBrowserUiProps & {
|
||||||
|
repositoryId: string;
|
||||||
|
snapshotId: string;
|
||||||
|
queryBasePath?: string;
|
||||||
|
displayBasePath?: string;
|
||||||
|
pageSize?: number;
|
||||||
|
enabled?: boolean;
|
||||||
|
onSingleSelectionKindChange?: (kind: "file" | "dir" | null) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const SnapshotTreeBrowser = (props: SnapshotTreeBrowserProps) => {
|
||||||
|
const {
|
||||||
|
repositoryId,
|
||||||
|
snapshotId,
|
||||||
|
queryBasePath = "/",
|
||||||
|
displayBasePath,
|
||||||
|
pageSize = 500,
|
||||||
|
enabled = true,
|
||||||
|
...uiProps
|
||||||
|
} = props;
|
||||||
|
|
||||||
|
const { selectedPaths, onSelectionChange, onSingleSelectionKindChange, ...fileBrowserUiProps } = uiProps;
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const normalizedQueryBasePath = normalizeAbsolutePath(queryBasePath);
|
||||||
|
const normalizedDisplayBasePath = normalizeAbsolutePath(displayBasePath ?? "/");
|
||||||
|
const effectiveDisplayBasePath = isPathWithin(normalizedDisplayBasePath, normalizedQueryBasePath)
|
||||||
|
? normalizedDisplayBasePath
|
||||||
|
: "/";
|
||||||
|
|
||||||
|
const { data, isLoading, error } = useQuery({
|
||||||
|
...listSnapshotFilesOptions({
|
||||||
|
path: { shortId: repositoryId, snapshotId },
|
||||||
|
query: { path: normalizedQueryBasePath },
|
||||||
|
}),
|
||||||
|
enabled,
|
||||||
|
});
|
||||||
|
|
||||||
|
const displayPathFns = useMemo(() => createPathPrefixFns(effectiveDisplayBasePath), [effectiveDisplayBasePath]);
|
||||||
|
|
||||||
|
const displaySelectedPaths = useMemo(() => {
|
||||||
|
if (!selectedPaths) return undefined;
|
||||||
|
|
||||||
|
const displayPaths = new Set<string>();
|
||||||
|
for (const fullPath of selectedPaths) {
|
||||||
|
displayPaths.add(displayPathFns.strip(fullPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
return displayPaths;
|
||||||
|
}, [displayPathFns, selectedPaths]);
|
||||||
|
|
||||||
|
const fileBrowser = useFileBrowser({
|
||||||
|
initialData: data,
|
||||||
|
isLoading,
|
||||||
|
fetchFolder: async (displayPath, offset = 0) => {
|
||||||
|
return await queryClient.ensureQueryData(
|
||||||
|
listSnapshotFilesOptions({
|
||||||
|
path: { shortId: repositoryId, snapshotId },
|
||||||
|
query: { path: displayPath, offset: offset, limit: pageSize },
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
pathTransform: displayPathFns,
|
||||||
|
});
|
||||||
|
|
||||||
|
const displayPathKinds = useMemo(() => {
|
||||||
|
const kinds = new Map<string, "file" | "dir">();
|
||||||
|
for (const entry of fileBrowser.fileArray) {
|
||||||
|
kinds.set(entry.path, entry.type === "file" ? "file" : "dir");
|
||||||
|
|
||||||
|
let parentPath = entry.path;
|
||||||
|
while (true) {
|
||||||
|
const lastSlashIndex = parentPath.lastIndexOf("/");
|
||||||
|
if (lastSlashIndex <= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
parentPath = parentPath.slice(0, lastSlashIndex);
|
||||||
|
if (kinds.has(parentPath)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
kinds.set(parentPath, "dir");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return kinds;
|
||||||
|
}, [fileBrowser.fileArray]);
|
||||||
|
|
||||||
|
const handleSelectionChange = useCallback(
|
||||||
|
(nextDisplayPaths: Set<string>) => {
|
||||||
|
if (!onSelectionChange) return;
|
||||||
|
|
||||||
|
const nextFullPaths = new Set<string>();
|
||||||
|
for (const displayPath of nextDisplayPaths) {
|
||||||
|
nextFullPaths.add(displayPathFns.add(displayPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (onSingleSelectionKindChange) {
|
||||||
|
if (nextDisplayPaths.size === 1) {
|
||||||
|
const [selectedDisplayPath] = nextDisplayPaths;
|
||||||
|
if (selectedDisplayPath) {
|
||||||
|
onSingleSelectionKindChange(displayPathKinds.get(selectedDisplayPath) ?? null);
|
||||||
|
} else {
|
||||||
|
onSingleSelectionKindChange(null);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
onSingleSelectionKindChange(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onSelectionChange(nextFullPaths);
|
||||||
|
},
|
||||||
|
[displayPathFns, displayPathKinds, onSelectionChange, onSingleSelectionKindChange],
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FileBrowser
|
||||||
|
{...fileBrowserUiProps}
|
||||||
|
fileArray={fileBrowser.fileArray}
|
||||||
|
expandedFolders={fileBrowser.expandedFolders}
|
||||||
|
loadingFolders={fileBrowser.loadingFolders}
|
||||||
|
onFolderExpand={fileBrowser.handleFolderExpand}
|
||||||
|
onFolderHover={fileBrowser.handleFolderHover}
|
||||||
|
onLoadMore={fileBrowser.handleLoadMore}
|
||||||
|
getFolderPagination={fileBrowser.getFolderPagination}
|
||||||
|
isLoading={fileBrowser.isLoading}
|
||||||
|
isEmpty={fileBrowser.isEmpty}
|
||||||
|
errorMessage={parseError(error)?.message}
|
||||||
|
loadingMessage={fileBrowserUiProps.loadingMessage ?? "Loading files..."}
|
||||||
|
selectedPaths={displaySelectedPaths}
|
||||||
|
onSelectionChange={onSelectionChange ? handleSelectionChange : undefined}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
61
app/client/components/file-browsers/volume-file-browser.tsx
Normal file
61
app/client/components/file-browsers/volume-file-browser.tsx
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { listFilesOptions } from "~/client/api-client/@tanstack/react-query.gen";
|
||||||
|
import { FileBrowser, type FileBrowserUiProps } from "~/client/components/file-browsers/file-browser";
|
||||||
|
import { useFileBrowser, type FetchFolderResult } from "~/client/hooks/use-file-browser";
|
||||||
|
import { parseError } from "~/client/lib/errors";
|
||||||
|
import { logger } from "~/client/lib/logger";
|
||||||
|
|
||||||
|
type VolumeFileBrowserProps = FileBrowserUiProps & {
|
||||||
|
volumeId: string;
|
||||||
|
enabled?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const VolumeFileBrowser = ({ volumeId, enabled = true, ...uiProps }: VolumeFileBrowserProps) => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
const { data, isLoading, error } = useQuery({
|
||||||
|
...listFilesOptions({ path: { shortId: volumeId } }),
|
||||||
|
enabled,
|
||||||
|
});
|
||||||
|
|
||||||
|
const fileBrowser = useFileBrowser({
|
||||||
|
initialData: data,
|
||||||
|
isLoading,
|
||||||
|
fetchFolder: async (path, offset): Promise<FetchFolderResult> => {
|
||||||
|
return await queryClient.ensureQueryData(
|
||||||
|
listFilesOptions({
|
||||||
|
path: { shortId: volumeId },
|
||||||
|
query: { path, offset: offset },
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
prefetchFolder: (path) => {
|
||||||
|
void queryClient
|
||||||
|
.prefetchQuery(
|
||||||
|
listFilesOptions({
|
||||||
|
path: { shortId: volumeId },
|
||||||
|
query: { path },
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.catch((e) => logger.error(e));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FileBrowser
|
||||||
|
{...uiProps}
|
||||||
|
fileArray={fileBrowser.fileArray}
|
||||||
|
expandedFolders={fileBrowser.expandedFolders}
|
||||||
|
loadingFolders={fileBrowser.loadingFolders}
|
||||||
|
onFolderExpand={fileBrowser.handleFolderExpand}
|
||||||
|
onFolderHover={fileBrowser.handleFolderHover}
|
||||||
|
onLoadMore={fileBrowser.handleLoadMore}
|
||||||
|
getFolderPagination={fileBrowser.getFolderPagination}
|
||||||
|
isLoading={fileBrowser.isLoading}
|
||||||
|
isEmpty={fileBrowser.isEmpty}
|
||||||
|
errorMessage={parseError(error)?.message}
|
||||||
|
loadingMessage={uiProps.loadingMessage ?? "Loading files..."}
|
||||||
|
emptyMessage={uiProps.emptyMessage ?? "This volume appears to be empty."}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
@ -8,7 +8,15 @@
|
||||||
* Original source: https://github.com/stackblitz/bolt.new
|
* Original source: https://github.com/stackblitz/bolt.new
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ChevronDown, ChevronRight, File as FileIcon, Folder as FolderIcon, FolderOpen, Loader2 } from "lucide-react";
|
import {
|
||||||
|
ChevronDown,
|
||||||
|
ChevronRight,
|
||||||
|
File as FileIcon,
|
||||||
|
Folder as FolderIcon,
|
||||||
|
FolderOpen,
|
||||||
|
Loader2,
|
||||||
|
MoreHorizontal,
|
||||||
|
} from "lucide-react";
|
||||||
import { memo, type ReactNode, useCallback, useEffect, useMemo, useState } from "react";
|
import { memo, type ReactNode, useCallback, useEffect, useMemo, useState } from "react";
|
||||||
import { cn } from "~/client/lib/utils";
|
import { cn } from "~/client/lib/utils";
|
||||||
import { Checkbox } from "~/client/components/ui/checkbox";
|
import { Checkbox } from "~/client/components/ui/checkbox";
|
||||||
|
|
@ -24,12 +32,19 @@ export interface FileEntry {
|
||||||
modifiedAt?: number;
|
modifiedAt?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface PaginationState {
|
||||||
|
hasMore: boolean;
|
||||||
|
isLoadingMore: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
files?: FileEntry[];
|
files?: FileEntry[];
|
||||||
selectedFile?: string;
|
selectedFile?: string;
|
||||||
onFileSelect?: (filePath: string) => void;
|
onFileSelect?: (filePath: string) => void;
|
||||||
onFolderExpand?: (folderPath: string) => void;
|
onFolderExpand?: (folderPath: string) => void;
|
||||||
onFolderHover?: (folderPath: string) => void;
|
onFolderHover?: (folderPath: string) => void;
|
||||||
|
onLoadMore?: (folderPath: string) => void;
|
||||||
|
getFolderPagination?: (folderPath: string) => PaginationState;
|
||||||
expandedFolders?: Set<string>;
|
expandedFolders?: Set<string>;
|
||||||
loadingFolders?: Set<string>;
|
loadingFolders?: Set<string>;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
|
@ -49,6 +64,8 @@ export const FileTree = memo((props: Props) => {
|
||||||
selectedFile,
|
selectedFile,
|
||||||
onFolderExpand,
|
onFolderExpand,
|
||||||
onFolderHover,
|
onFolderHover,
|
||||||
|
onLoadMore,
|
||||||
|
getFolderPagination,
|
||||||
expandedFolders = new Set(),
|
expandedFolders = new Set(),
|
||||||
loadingFolders = new Set(),
|
loadingFolders = new Set(),
|
||||||
className,
|
className,
|
||||||
|
|
@ -97,20 +114,25 @@ export const FileTree = memo((props: Props) => {
|
||||||
|
|
||||||
const toggleCollapseState = useCallback(
|
const toggleCollapseState = useCallback(
|
||||||
(fullPath: string) => {
|
(fullPath: string) => {
|
||||||
|
const shouldExpand = collapsedFolders.has(fullPath);
|
||||||
|
|
||||||
setCollapsedFolders((prevSet) => {
|
setCollapsedFolders((prevSet) => {
|
||||||
const newSet = new Set(prevSet);
|
const newSet = new Set(prevSet);
|
||||||
|
|
||||||
if (newSet.has(fullPath)) {
|
if (newSet.has(fullPath)) {
|
||||||
newSet.delete(fullPath);
|
newSet.delete(fullPath);
|
||||||
onFolderExpand?.(fullPath);
|
|
||||||
} else {
|
} else {
|
||||||
newSet.add(fullPath);
|
newSet.add(fullPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return newSet;
|
return newSet;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (shouldExpand) {
|
||||||
|
onFolderExpand?.(fullPath);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[onFolderExpand],
|
[collapsedFolders, onFolderExpand],
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add new folders to collapsed set when file list changes
|
// Add new folders to collapsed set when file list changes
|
||||||
|
|
@ -292,12 +314,32 @@ export const FileTree = memo((props: Props) => {
|
||||||
[selectedPaths],
|
[selectedPaths],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Build a map of folder paths that need pagination to their last child's index
|
||||||
|
const folderPaginationMap = useMemo(() => {
|
||||||
|
const map = new Map<string, number>();
|
||||||
|
|
||||||
|
for (let i = 0; i < filteredFileList.length; i++) {
|
||||||
|
const item = filteredFileList[i];
|
||||||
|
const parentPath = item.fullPath.slice(0, item.fullPath.lastIndexOf("/")) || "/";
|
||||||
|
const pagination = getFolderPagination?.(parentPath);
|
||||||
|
if (pagination?.hasMore && !collapsedFolders.has(parentPath)) {
|
||||||
|
// Update the last index for this parent
|
||||||
|
map.set(parentPath, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}, [filteredFileList, getFolderPagination, collapsedFolders]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn("text-sm", className)}>
|
<div className={cn("text-sm", className)}>
|
||||||
{filteredFileList.map((fileOrFolder) => {
|
{filteredFileList.map((fileOrFolder, index) => {
|
||||||
|
const elements: React.ReactNode[] = [];
|
||||||
|
|
||||||
|
// Render the current file or folder
|
||||||
switch (fileOrFolder.kind) {
|
switch (fileOrFolder.kind) {
|
||||||
case "file": {
|
case "file": {
|
||||||
return (
|
elements.push(
|
||||||
<File
|
<File
|
||||||
key={fileOrFolder.id}
|
key={fileOrFolder.id}
|
||||||
selected={selectedFile === fileOrFolder.fullPath}
|
selected={selectedFile === fileOrFolder.fullPath}
|
||||||
|
|
@ -306,11 +348,12 @@ export const FileTree = memo((props: Props) => {
|
||||||
withCheckbox={withCheckboxes}
|
withCheckbox={withCheckboxes}
|
||||||
checked={isPathSelected(fileOrFolder.fullPath)}
|
checked={isPathSelected(fileOrFolder.fullPath)}
|
||||||
onCheckboxChange={handleSelectionChange}
|
onCheckboxChange={handleSelectionChange}
|
||||||
/>
|
/>,
|
||||||
);
|
);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case "folder": {
|
case "folder": {
|
||||||
return (
|
elements.push(
|
||||||
<Folder
|
<Folder
|
||||||
key={fileOrFolder.id}
|
key={fileOrFolder.id}
|
||||||
folder={fileOrFolder}
|
folder={fileOrFolder}
|
||||||
|
|
@ -325,13 +368,31 @@ export const FileTree = memo((props: Props) => {
|
||||||
selectableMode={selectableFolders}
|
selectableMode={selectableFolders}
|
||||||
onFolderSelect={handleFolderSelect}
|
onFolderSelect={handleFolderSelect}
|
||||||
selected={selectedFolder === fileOrFolder.fullPath}
|
selected={selectedFolder === fileOrFolder.fullPath}
|
||||||
/>
|
/>,
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if this is the last child of any folder with more files to load
|
||||||
|
for (const [folderPath, lastIndex] of folderPaginationMap.entries()) {
|
||||||
|
if (lastIndex === index) {
|
||||||
|
// This is the last loaded child of folderPath
|
||||||
|
const pagination = getFolderPagination?.(folderPath);
|
||||||
|
if (pagination?.hasMore) {
|
||||||
|
elements.push(
|
||||||
|
<LoadMoreButton
|
||||||
|
key={`load-more-${folderPath}`}
|
||||||
|
depth={fileOrFolder.depth}
|
||||||
|
onClick={() => onLoadMore?.(folderPath)}
|
||||||
|
isLoading={pagination.isLoadingMore}
|
||||||
|
/>,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
default: {
|
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return elements;
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
@ -470,13 +531,38 @@ const File = memo(({ file, onFileSelect, selected, withCheckbox, checked, onChec
|
||||||
<span className="truncate">{name}</span>
|
<span className="truncate">{name}</span>
|
||||||
{typeof size === "number" && (
|
{typeof size === "number" && (
|
||||||
<span className="ml-auto shrink-0 text-xs text-muted-foreground">
|
<span className="ml-auto shrink-0 text-xs text-muted-foreground">
|
||||||
<ByteSize bytes={size} />
|
<ByteSize bytes={size} base={1024} />
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</NodeButton>
|
</NodeButton>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
interface LoadMoreButtonProps {
|
||||||
|
depth: number;
|
||||||
|
onClick: () => void;
|
||||||
|
isLoading?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const LoadMoreButton = memo(({ depth, onClick, isLoading }: LoadMoreButtonProps) => {
|
||||||
|
return (
|
||||||
|
<NodeButton
|
||||||
|
depth={depth}
|
||||||
|
className="text-muted-foreground hover:bg-accent/50 cursor-pointer"
|
||||||
|
icon={
|
||||||
|
isLoading ? (
|
||||||
|
<Loader2 className="w-4 h-4 shrink-0 animate-spin" />
|
||||||
|
) : (
|
||||||
|
<MoreHorizontal className="w-4 h-4 shrink-0" />
|
||||||
|
)
|
||||||
|
}
|
||||||
|
onClick={onClick}
|
||||||
|
>
|
||||||
|
<span className="text-xs">{isLoading ? "Loading more..." : "Load more files"}</span>
|
||||||
|
</NodeButton>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
interface ButtonProps {
|
interface ButtonProps {
|
||||||
depth: number;
|
depth: number;
|
||||||
icon: ReactNode;
|
icon: ReactNode;
|
||||||
|
|
@ -500,8 +586,10 @@ const NodeButton = memo(({ depth, icon, onClick, onMouseEnter, className, childr
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button
|
<div
|
||||||
type="button"
|
// oxlint-disable-next-line jsx_a11y/prefer-tag-over-role
|
||||||
|
role="button"
|
||||||
|
tabIndex={0}
|
||||||
className={cn("flex items-center gap-2 w-full pr-2 text-sm py-1.5 text-left", className)}
|
className={cn("flex items-center gap-2 w-full pr-2 text-sm py-1.5 text-left", className)}
|
||||||
style={{ paddingLeft }}
|
style={{ paddingLeft }}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
|
|
@ -510,7 +598,7 @@ const NodeButton = memo(({ depth, icon, onClick, onMouseEnter, className, childr
|
||||||
>
|
>
|
||||||
{icon}
|
{icon}
|
||||||
<div className="truncate w-full flex items-center gap-2">{children}</div>
|
<div className="truncate w-full flex items-center gap-2">{children}</div>
|
||||||
</button>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -544,6 +632,10 @@ function buildFileList(files: FileEntry[], foldersOnly = false): Node[] {
|
||||||
const depth = segments.length - 1;
|
const depth = segments.length - 1;
|
||||||
const name = segments[segments.length - 1];
|
const name = segments[segments.length - 1];
|
||||||
|
|
||||||
|
if (!name) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!fileMap.has(file.path)) {
|
if (!fileMap.has(file.path)) {
|
||||||
const isFile = file.type === "file";
|
const isFile = file.type === "file";
|
||||||
fileMap.set(file.path, {
|
fileMap.set(file.path, {
|
||||||
|
|
@ -555,6 +647,33 @@ function buildFileList(files: FileEntry[], foldersOnly = false): Node[] {
|
||||||
size: file.size,
|
size: file.size,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let parentPath = file.path;
|
||||||
|
while (true) {
|
||||||
|
const lastSlashIndex = parentPath.lastIndexOf("/");
|
||||||
|
if (lastSlashIndex <= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
parentPath = parentPath.slice(0, lastSlashIndex);
|
||||||
|
if (fileMap.has(parentPath)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parentSegments = parentPath.split("/").filter((segment) => segment);
|
||||||
|
const parentName = parentSegments[parentSegments.length - 1];
|
||||||
|
if (!parentName) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
fileMap.set(parentPath, {
|
||||||
|
kind: "folder",
|
||||||
|
id: fileMap.size,
|
||||||
|
name: parentName,
|
||||||
|
fullPath: parentPath,
|
||||||
|
depth: parentSegments.length - 1,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert map to array and sort
|
// Convert map to array and sort
|
||||||
|
|
@ -621,5 +740,7 @@ function compareNodes(a: Node, b: Node): number {
|
||||||
return a.kind === "folder" ? -1 : 1;
|
return a.kind === "folder" ? -1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: "base" });
|
if (a.name < b.name) return -1;
|
||||||
|
if (a.name > b.name) return 1;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,16 +9,17 @@ interface GridBackgroundProps {
|
||||||
|
|
||||||
export function GridBackground({ children, className, containerClassName }: GridBackgroundProps) {
|
export function GridBackground({ children, className, containerClassName }: GridBackgroundProps) {
|
||||||
return (
|
return (
|
||||||
|
<div className={cn("relative min-h-full w-full", containerClassName)}>
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
"relative min-h-full w-full",
|
"pointer-events-none absolute inset-0 w-full h-full",
|
||||||
"bg-size-[20px_20px] sm:bg-size-[40px_40px]",
|
"bg-[size:40px_40px]",
|
||||||
"bg-[linear-gradient(to_right,#e4e4e7_1px,transparent_1px),linear-gradient(to_bottom,#e4e4e7_1px,transparent_1px)]",
|
"bg-[linear-gradient(to_right,rgba(0,0,0,0.04)_1px,transparent_1px),linear-gradient(to_bottom,rgba(0,0,0,0.04)_1px,transparent_1px)]",
|
||||||
"dark:bg-[linear-gradient(to_right,#262626_1px,transparent_1px),linear-gradient(to_bottom,#262626_1px,transparent_1px)]",
|
"dark:bg-[linear-gradient(to_right,#262626_1px,transparent_1px),linear-gradient(to_bottom,#262626_1px,transparent_1px)]",
|
||||||
containerClassName,
|
"[mask-image:radial-gradient(ellipse_at_top,black_70%,transparent_100%)]",
|
||||||
)}
|
)}
|
||||||
>
|
/>
|
||||||
<div className={cn("relative container m-auto", className)}>{children}</div>
|
<div className={cn("relative container m-auto z-10", className)}>{children}</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,36 +1,29 @@
|
||||||
import { LifeBuoy } from "lucide-react";
|
import { LifeBuoy, LogOut } from "lucide-react";
|
||||||
import { Outlet, redirect, useNavigate } from "react-router";
|
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { appContext } from "~/context";
|
import { type AppContext } from "~/context";
|
||||||
import { authMiddleware } from "~/middleware/auth";
|
|
||||||
import type { Route } from "./+types/layout";
|
|
||||||
import { AppBreadcrumb } from "./app-breadcrumb";
|
|
||||||
import { GridBackground } from "./grid-background";
|
import { GridBackground } from "./grid-background";
|
||||||
import { Button } from "./ui/button";
|
import { Button, buttonVariants } from "./ui/button";
|
||||||
import { SidebarProvider, SidebarTrigger } from "./ui/sidebar";
|
import { SidebarProvider, SidebarTrigger } from "./ui/sidebar";
|
||||||
import { AppSidebar } from "./app-sidebar";
|
import { AppSidebar } from "./app-sidebar";
|
||||||
import { authClient } from "../lib/auth-client";
|
import { authClient } from "../lib/auth-client";
|
||||||
|
import { DevPanelListener } from "./dev-panel-listener";
|
||||||
|
import { Outlet, useNavigate } from "@tanstack/react-router";
|
||||||
|
import { AppBreadcrumb } from "./app-breadcrumb";
|
||||||
|
import { Tooltip, TooltipContent, TooltipTrigger } from "./ui/tooltip";
|
||||||
|
import { ThemeToggle } from "./theme-toggle";
|
||||||
|
|
||||||
export const clientMiddleware = [authMiddleware];
|
type Props = {
|
||||||
|
loaderData: AppContext;
|
||||||
|
};
|
||||||
|
|
||||||
export async function clientLoader({ context }: Route.LoaderArgs) {
|
export function Layout({ loaderData }: Props) {
|
||||||
const ctx = context.get(appContext);
|
|
||||||
|
|
||||||
if (ctx.user && !ctx.user.hasDownloadedResticPassword) {
|
|
||||||
throw redirect("/download-recovery-key");
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function Layout({ loaderData }: Route.ComponentProps) {
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const handleLogout = async () => {
|
const handleLogout = async () => {
|
||||||
await authClient.signOut({
|
await authClient.signOut({
|
||||||
fetchOptions: {
|
fetchOptions: {
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
void navigate("/login", { replace: true });
|
void navigate({ to: "/login", replace: true });
|
||||||
},
|
},
|
||||||
onError: ({ error }) => {
|
onError: ({ error }) => {
|
||||||
toast.error("Logout failed", { description: error.message });
|
toast.error("Logout failed", { description: error.message });
|
||||||
|
|
@ -40,49 +33,65 @@ export default function Layout({ loaderData }: Route.ComponentProps) {
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SidebarProvider defaultOpen={true}>
|
<SidebarProvider defaultOpen={loaderData.sidebarOpen}>
|
||||||
<AppSidebar />
|
<AppSidebar isInstanceAdmin={loaderData.user?.role === "admin"} />
|
||||||
<div className="w-full relative flex flex-col h-screen overflow-hidden">
|
<div className="w-full relative flex flex-col min-h-screen md:h-screen md:overflow-hidden">
|
||||||
<header className="z-50 bg-card-header border-b border-border/50 shrink-0">
|
<header className="z-50 bg-card-header border-b border-border/80 dark:border-border/50 shrink-0 h-16.25">
|
||||||
<div className="flex items-center justify-between py-3 sm:py-4 px-2 sm:px-8 mx-auto container gap-4">
|
<div className="flex items-center h-full justify-between px-2 sm:px-8 mx-auto container gap-4">
|
||||||
<div className="flex items-center gap-4 min-w-0">
|
<div className="flex items-center gap-4 min-w-0">
|
||||||
<SidebarTrigger />
|
<SidebarTrigger />
|
||||||
<AppBreadcrumb />
|
<AppBreadcrumb />
|
||||||
</div>
|
</div>
|
||||||
{loaderData.user && (
|
{loaderData.user && (
|
||||||
<div className="flex items-center gap-4">
|
<div className="flex items-center bg-card dark:bg-muted/30 border border-border/80 dark:border-border/50 px-2 py-1 rounded-full shadow-[0_2px_10px_-4px_rgba(0,0,0,0.05)] dark:shadow-sm">
|
||||||
<span className="text-sm text-muted-foreground hidden md:inline-flex">
|
<span className="text-sm text-muted-foreground hidden md:inline-flex pl-2 mr-5">
|
||||||
Welcome,
|
<span className="text-foreground">{loaderData.user.name}</span>
|
||||||
<span className="text-strong-accent">{loaderData.user?.username}</span>
|
|
||||||
</span>
|
</span>
|
||||||
<Button variant="default" size="sm" onClick={handleLogout}>
|
<ThemeToggle />
|
||||||
Logout
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="rounded-full h-7 text-xs text-muted-foreground hover:text-foreground"
|
||||||
|
onClick={handleLogout}
|
||||||
|
>
|
||||||
|
<LogOut className="w-4 h-4" />
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="default" size="sm" className="relative overflow-hidden hidden lg:inline-flex">
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>Logout</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
<a
|
<a
|
||||||
href="https://github.com/nicotsx/zerobyte/issues/new"
|
href="https://github.com/nicotsx/zerobyte/issues/new/choose"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noreferrer"
|
rel="noreferrer"
|
||||||
className="flex items-center gap-2"
|
className={buttonVariants({
|
||||||
|
variant: "ghost",
|
||||||
|
size: "icon",
|
||||||
|
className:
|
||||||
|
"relative overflow-hidden hidden lg:inline-flex rounded-full h-7 w-7 text-muted-foreground hover:text-foreground",
|
||||||
|
})}
|
||||||
>
|
>
|
||||||
<span className="flex items-center gap-2">
|
<LifeBuoy className="w-4 h-4" />
|
||||||
<LifeBuoy />
|
|
||||||
<span>Report an issue</span>
|
|
||||||
</span>
|
|
||||||
</a>
|
</a>
|
||||||
</Button>
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>Report an issue</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<div className="main-content flex-1 overflow-y-auto">
|
<div className="main-content flex-1 md:overflow-y-auto">
|
||||||
<GridBackground>
|
<GridBackground>
|
||||||
<main className="flex flex-col p-2 pb-6 pt-2 sm:p-8 sm:pt-6 mx-auto @container">
|
<main className="flex flex-col p-2 pb-6 pt-2 sm:p-8 sm:pt-6 mx-auto">
|
||||||
<Outlet />
|
<Outlet />
|
||||||
</main>
|
</main>
|
||||||
</GridBackground>
|
</GridBackground>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<DevPanelListener />
|
||||||
</SidebarProvider>
|
</SidebarProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
23
app/client/components/managed-badge.tsx
Normal file
23
app/client/components/managed-badge.tsx
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
import { Badge } from "~/client/components/ui/badge";
|
||||||
|
import { Tooltip, TooltipContent, TooltipTrigger } from "~/client/components/ui/tooltip";
|
||||||
|
|
||||||
|
type ManagedBadgeProps = {
|
||||||
|
label?: string;
|
||||||
|
message?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const defaultMessage =
|
||||||
|
"This resource is provisioned at startup. Changes are useful for testing, but the next provisioning sync can overwrite or recreate it.";
|
||||||
|
|
||||||
|
export const ManagedBadge = ({ label = "Managed", message = defaultMessage }: ManagedBadgeProps) => {
|
||||||
|
return (
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<Badge variant="secondary">{label}</Badge>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>
|
||||||
|
<p className="max-w-80 text-sm">{message}</p>
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
@ -15,7 +15,7 @@ export const OnOff = ({ isOn, toggle, enabledLabel, disabledLabel, disabled }: P
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex items-center gap-2 rounded-full border px-3 py-1.5 text-xs font-semibold uppercase tracking-wide transition-colors",
|
"flex items-center gap-2 rounded-full border px-3 py-1.5 text-xs font-semibold uppercase tracking-wide transition-colors",
|
||||||
isOn
|
isOn
|
||||||
? "border-green-200 bg-green-50 text-green-700 dark:border-green-500/40 dark:bg-green-500/10 dark:text-green-200"
|
? "border-success/30 bg-success/10 text-success"
|
||||||
: "border-muted bg-muted/40 text-muted-foreground dark:border-muted/60 dark:bg-muted/10",
|
: "border-muted bg-muted/40 text-muted-foreground dark:border-muted/60 dark:bg-muted/10",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
110
app/client/components/organization-switcher.tsx
Normal file
110
app/client/components/organization-switcher.tsx
Normal file
|
|
@ -0,0 +1,110 @@
|
||||||
|
import { ChevronsUpDown } from "lucide-react";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuLabel,
|
||||||
|
DropdownMenuShortcut,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from "~/client/components/ui/dropdown-menu";
|
||||||
|
import { SidebarMenu, SidebarMenuButton, SidebarMenuItem, useSidebar } from "~/client/components/ui/sidebar";
|
||||||
|
import { authClient } from "~/client/lib/auth-client";
|
||||||
|
import { useMutation } from "@tanstack/react-query";
|
||||||
|
import { useOrganizationContext } from "../hooks/use-org-context";
|
||||||
|
|
||||||
|
function getOrganizationInitials(name?: string): string {
|
||||||
|
const trimmedName = name?.trim();
|
||||||
|
|
||||||
|
if (!trimmedName) {
|
||||||
|
return "O";
|
||||||
|
}
|
||||||
|
|
||||||
|
return trimmedName
|
||||||
|
.split(/\s+/)
|
||||||
|
.slice(0, 2)
|
||||||
|
.map((part) => part.charAt(0).toUpperCase())
|
||||||
|
.join("");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function OrganizationSwitcher() {
|
||||||
|
const { isMobile } = useSidebar();
|
||||||
|
const { organizations, activeOrganization } = useOrganizationContext();
|
||||||
|
|
||||||
|
const switchOrganizationMutation = useMutation({
|
||||||
|
mutationFn: async (organizationId: string) => {
|
||||||
|
const { error } = await authClient.organization.setActive({ organizationId });
|
||||||
|
if (error) throw new Error(error.message);
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
const message = error instanceof Error ? error.message : "Unexpected error while switching organizations";
|
||||||
|
toast.error("Failed to switch organization", { description: message });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (organizations === undefined) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (organizations.length <= 1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SidebarMenu className="mb-3">
|
||||||
|
<SidebarMenuItem>
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<SidebarMenuButton
|
||||||
|
size="lg"
|
||||||
|
className="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
|
||||||
|
>
|
||||||
|
<div className="bg-foreground text-sidebar-primary-foreground flex aspect-square size-8 shrink-0 items-center justify-center overflow-hidden rounded-lg">
|
||||||
|
{activeOrganization?.logo ? (
|
||||||
|
<img
|
||||||
|
src={activeOrganization.logo}
|
||||||
|
alt={`${activeOrganization.name} logo`}
|
||||||
|
className="size-full object-cover"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<span className="text-xs font-semibold">{getOrganizationInitials(activeOrganization?.name)}</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="grid flex-1 text-left text-sm leading-tight">
|
||||||
|
<span className="truncate font-medium">{activeOrganization?.name}</span>
|
||||||
|
<span className="truncate text-xs">{organizations.length} organizations</span>
|
||||||
|
</div>
|
||||||
|
<ChevronsUpDown className="ml-auto group-data-[collapsible=icon]:hidden" />
|
||||||
|
</SidebarMenuButton>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent
|
||||||
|
className="w-(--radix-dropdown-menu-trigger-width) min-w-56 rounded-lg"
|
||||||
|
align="start"
|
||||||
|
side={isMobile ? "bottom" : "right"}
|
||||||
|
sideOffset={4}
|
||||||
|
>
|
||||||
|
<DropdownMenuLabel className="text-muted-foreground text-xs">Organizations</DropdownMenuLabel>
|
||||||
|
{organizations.map((organization) => (
|
||||||
|
<DropdownMenuItem
|
||||||
|
key={organization.id}
|
||||||
|
onClick={() => switchOrganizationMutation.mutate(organization.id)}
|
||||||
|
className="gap-2 p-2"
|
||||||
|
disabled={switchOrganizationMutation.isPending}
|
||||||
|
>
|
||||||
|
<div className="flex size-6 shrink-0 items-center justify-center overflow-hidden rounded-md border">
|
||||||
|
{organization.logo ? (
|
||||||
|
<img src={organization.logo} alt={`${organization.name} logo`} className="size-full object-cover" />
|
||||||
|
) : (
|
||||||
|
<span className="text-[10px] font-semibold">{getOrganizationInitials(organization.name)}</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<span className="min-w-0 flex-1 truncate">{organization.name}</span>
|
||||||
|
<DropdownMenuShortcut>{organization.id === activeOrganization?.id && "Current"}</DropdownMenuShortcut>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
))}
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
</SidebarMenuItem>
|
||||||
|
</SidebarMenu>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { DirectoryBrowser } from "./directory-browser";
|
import { DirectoryBrowser } from "./file-browsers/directory-browser";
|
||||||
import { Button } from "./ui/button";
|
import { Button } from "./ui/button";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
|
@ -15,11 +15,11 @@ export const PathSelector = ({ value, onChange }: Props) => {
|
||||||
return (
|
return (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<DirectoryBrowser
|
<DirectoryBrowser
|
||||||
|
selectedPath={value}
|
||||||
onSelectPath={(path) => {
|
onSelectPath={(path) => {
|
||||||
onChange(path);
|
onChange(path);
|
||||||
setShowBrowser(false);
|
setShowBrowser(false);
|
||||||
}}
|
}}
|
||||||
selectedPath={value}
|
|
||||||
/>
|
/>
|
||||||
<Button type="button" variant="ghost" size="sm" onClick={() => setShowBrowser(false)}>
|
<Button type="button" variant="ghost" size="sm" onClick={() => setShowBrowser(false)}>
|
||||||
Cancel
|
Cancel
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import ReactMarkdown from "react-markdown";
|
||||||
import remarkGfm from "remark-gfm";
|
import remarkGfm from "remark-gfm";
|
||||||
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "~/client/components/ui/dialog";
|
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "~/client/components/ui/dialog";
|
||||||
import { ScrollArea } from "~/client/components/ui/scroll-area";
|
import { ScrollArea } from "~/client/components/ui/scroll-area";
|
||||||
import { formatDate } from "~/client/lib/datetime";
|
import { useTimeFormat } from "~/client/lib/datetime";
|
||||||
import type { UpdateInfoDto } from "~/server/modules/system/system.dto";
|
import type { UpdateInfoDto } from "~/server/modules/system/system.dto";
|
||||||
|
|
||||||
interface ReleaseNotesDialogProps {
|
interface ReleaseNotesDialogProps {
|
||||||
|
|
@ -12,6 +12,8 @@ interface ReleaseNotesDialogProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ReleaseNotesDialog({ open, onOpenChange, updates }: ReleaseNotesDialogProps) {
|
export function ReleaseNotesDialog({ open, onOpenChange, updates }: ReleaseNotesDialogProps) {
|
||||||
|
const { formatDate } = useTimeFormat();
|
||||||
|
|
||||||
if (!updates) return null;
|
if (!updates) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { Database, HardDrive, Cloud, Server } from "lucide-react";
|
import { Database, HardDrive, Cloud, Server } from "lucide-react";
|
||||||
import type { RepositoryBackend } from "~/schemas/restic";
|
import type { RepositoryBackend } from "@zerobyte/core/restic";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
backend: RepositoryBackend;
|
backend: RepositoryBackend;
|
||||||
|
|
|
||||||
|
|
@ -1,176 +1,283 @@
|
||||||
import { useCallback, useState } from "react";
|
import { useCallback, useEffect, useRef, useState } from "react";
|
||||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
import { useMutation } from "@tanstack/react-query";
|
||||||
import { useNavigate } from "react-router";
|
import { AlertTriangle, ChevronDown, Download, FolderOpen, RotateCcw } from "lucide-react";
|
||||||
import { toast } from "sonner";
|
|
||||||
import { ChevronDown, FileIcon, FolderOpen, RotateCcw } from "lucide-react";
|
|
||||||
import { Button } from "~/client/components/ui/button";
|
import { Button } from "~/client/components/ui/button";
|
||||||
|
import { Tooltip, TooltipContent, TooltipTrigger } from "~/client/components/ui/tooltip";
|
||||||
|
import { Alert, AlertDescription, AlertTitle } from "~/client/components/ui/alert";
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "~/client/components/ui/card";
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "~/client/components/ui/card";
|
||||||
import { Checkbox } from "~/client/components/ui/checkbox";
|
|
||||||
import { Input } from "~/client/components/ui/input";
|
import { Input } from "~/client/components/ui/input";
|
||||||
import { Label } from "~/client/components/ui/label";
|
import { Label } from "~/client/components/ui/label";
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "~/client/components/ui/select";
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "~/client/components/ui/select";
|
||||||
|
import {
|
||||||
|
AlertDialog,
|
||||||
|
AlertDialogAction,
|
||||||
|
AlertDialogContent,
|
||||||
|
AlertDialogDescription,
|
||||||
|
AlertDialogFooter,
|
||||||
|
AlertDialogHeader,
|
||||||
|
AlertDialogTitle,
|
||||||
|
} from "~/client/components/ui/alert-dialog";
|
||||||
import { PathSelector } from "~/client/components/path-selector";
|
import { PathSelector } from "~/client/components/path-selector";
|
||||||
import { FileTree } from "~/client/components/file-tree";
|
import { SnapshotTreeBrowser } from "~/client/components/file-browsers/snapshot-tree-browser";
|
||||||
import { listSnapshotFilesOptions, restoreSnapshotMutation } from "~/client/api-client/@tanstack/react-query.gen";
|
import { RestoreProgress } from "~/client/components/restore-progress";
|
||||||
import { useFileBrowser } from "~/client/hooks/use-file-browser";
|
import { restoreSnapshotMutation } from "~/client/api-client/@tanstack/react-query.gen";
|
||||||
import { OVERWRITE_MODES, type OverwriteMode } from "~/schemas/restic";
|
import { type RestoreCompletedEvent, useServerEvents } from "~/client/hooks/use-server-events";
|
||||||
import type { Repository, Snapshot } from "~/client/lib/types";
|
import { OVERWRITE_MODES, type OverwriteMode } from "@zerobyte/core/restic";
|
||||||
|
import { isPathWithin } from "@zerobyte/core/utils";
|
||||||
|
import type { Repository } from "~/client/lib/types";
|
||||||
|
import { handleRepositoryError } from "~/client/lib/errors";
|
||||||
|
import { useNavigate } from "@tanstack/react-router";
|
||||||
|
import { cn } from "~/client/lib/utils";
|
||||||
|
|
||||||
type RestoreLocation = "original" | "custom";
|
type RestoreLocation = "original" | "custom";
|
||||||
|
|
||||||
interface RestoreFormProps {
|
interface RestoreFormProps {
|
||||||
snapshot: Snapshot;
|
|
||||||
repository: Repository;
|
repository: Repository;
|
||||||
snapshotId: string;
|
snapshotId: string;
|
||||||
returnPath: string;
|
returnPath: string;
|
||||||
|
queryBasePath?: string;
|
||||||
|
displayBasePath?: string;
|
||||||
|
hasNonPosixSnapshotPaths?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function RestoreForm({ snapshot, repository, snapshotId, returnPath }: RestoreFormProps) {
|
export function RestoreForm({
|
||||||
|
repository,
|
||||||
|
snapshotId,
|
||||||
|
returnPath,
|
||||||
|
queryBasePath,
|
||||||
|
displayBasePath,
|
||||||
|
hasNonPosixSnapshotPaths = false,
|
||||||
|
}: RestoreFormProps) {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const queryClient = useQueryClient();
|
const { addEventListener } = useServerEvents();
|
||||||
|
|
||||||
const volumeBasePath = snapshot.paths[0]?.match(/^(.*?_data)(\/|$)/)?.[1] || "/";
|
const snapshotBasePath = queryBasePath ?? "/";
|
||||||
|
const hasMismatchedDisplayBasePath = displayBasePath && !isPathWithin(displayBasePath, snapshotBasePath);
|
||||||
|
const restoreRequiresCustomTarget = hasNonPosixSnapshotPaths || hasMismatchedDisplayBasePath;
|
||||||
|
|
||||||
const [restoreLocation, setRestoreLocation] = useState<RestoreLocation>("original");
|
const [restoreLocation, setRestoreLocation] = useState<RestoreLocation>(
|
||||||
|
restoreRequiresCustomTarget ? "custom" : "original",
|
||||||
|
);
|
||||||
const [customTargetPath, setCustomTargetPath] = useState("");
|
const [customTargetPath, setCustomTargetPath] = useState("");
|
||||||
const [overwriteMode, setOverwriteMode] = useState<OverwriteMode>("always");
|
const [overwriteMode, setOverwriteMode] = useState<OverwriteMode>("always");
|
||||||
const [showAdvanced, setShowAdvanced] = useState(false);
|
const [showAdvanced, setShowAdvanced] = useState(false);
|
||||||
const [excludeXattr, setExcludeXattr] = useState("");
|
const [excludeXattr, setExcludeXattr] = useState("");
|
||||||
const [deleteExtraFiles, setDeleteExtraFiles] = useState(false);
|
const [isRestoreActive, setIsRestoreActive] = useState(false);
|
||||||
|
const [restoreResult, setRestoreResult] = useState<RestoreCompletedEvent | null>(null);
|
||||||
|
const [showRestoreResultAlert, setShowRestoreResultAlert] = useState(false);
|
||||||
|
const restoreCompletedRef = useRef(false);
|
||||||
|
|
||||||
const [selectedPaths, setSelectedPaths] = useState<Set<string>>(new Set());
|
const [selectedPaths, setSelectedPaths] = useState<Set<string>>(new Set());
|
||||||
|
const [selectedPathKind, setSelectedPathKind] = useState<"file" | "dir" | null>(null);
|
||||||
|
const trimmedCustomTargetPath = customTargetPath.trim();
|
||||||
|
const hasCustomTargetPath = trimmedCustomTargetPath !== "";
|
||||||
|
const selectedPathCount = selectedPaths.size;
|
||||||
|
|
||||||
const { data: filesData, isLoading: filesLoading } = useQuery({
|
useEffect(() => {
|
||||||
...listSnapshotFilesOptions({
|
if (restoreRequiresCustomTarget) {
|
||||||
path: { id: repository.id, snapshotId },
|
setRestoreLocation("custom");
|
||||||
query: { path: volumeBasePath },
|
}
|
||||||
}),
|
}, [restoreRequiresCustomTarget]);
|
||||||
});
|
|
||||||
|
useEffect(() => {
|
||||||
const stripBasePath = useCallback(
|
const abortController = new AbortController();
|
||||||
(path: string): string => {
|
const signal = abortController.signal;
|
||||||
if (!volumeBasePath) return path;
|
|
||||||
if (path === volumeBasePath) return "/";
|
addEventListener(
|
||||||
if (path.startsWith(`${volumeBasePath}/`)) {
|
"restore:started",
|
||||||
const stripped = path.slice(volumeBasePath.length);
|
(startedData) => {
|
||||||
return stripped;
|
if (startedData.repositoryId === repository.shortId && startedData.snapshotId === snapshotId) {
|
||||||
|
restoreCompletedRef.current = false;
|
||||||
|
setIsRestoreActive(true);
|
||||||
|
setRestoreResult(null);
|
||||||
|
setShowRestoreResultAlert(false);
|
||||||
}
|
}
|
||||||
return path;
|
|
||||||
},
|
},
|
||||||
[volumeBasePath],
|
{ signal },
|
||||||
);
|
);
|
||||||
|
|
||||||
const addBasePath = useCallback(
|
addEventListener(
|
||||||
(displayPath: string): string => {
|
"restore:progress",
|
||||||
const vbp = volumeBasePath === "/" ? "" : volumeBasePath;
|
(progressData) => {
|
||||||
|
if (progressData.repositoryId === repository.shortId && progressData.snapshotId === snapshotId) {
|
||||||
if (!vbp) return displayPath;
|
if (restoreCompletedRef.current) {
|
||||||
if (displayPath === "/") return vbp;
|
return;
|
||||||
return `${vbp}${displayPath}`;
|
}
|
||||||
|
setIsRestoreActive(true);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[volumeBasePath],
|
{ signal },
|
||||||
);
|
);
|
||||||
|
|
||||||
const fileBrowser = useFileBrowser({
|
addEventListener(
|
||||||
initialData: filesData,
|
"restore:completed",
|
||||||
isLoading: filesLoading,
|
(completedData) => {
|
||||||
fetchFolder: async (path) => {
|
if (completedData.repositoryId === repository.shortId && completedData.snapshotId === snapshotId) {
|
||||||
return await queryClient.ensureQueryData(
|
restoreCompletedRef.current = true;
|
||||||
listSnapshotFilesOptions({
|
setIsRestoreActive(false);
|
||||||
path: { id: repository.id, snapshotId },
|
setRestoreResult(completedData);
|
||||||
query: { path },
|
setShowRestoreResultAlert(true);
|
||||||
}),
|
}
|
||||||
|
},
|
||||||
|
{ signal },
|
||||||
);
|
);
|
||||||
},
|
|
||||||
prefetchFolder: (path) => {
|
return () => {
|
||||||
void queryClient.prefetchQuery(
|
abortController.abort();
|
||||||
listSnapshotFilesOptions({
|
};
|
||||||
path: { id: repository.id, snapshotId },
|
}, [addEventListener, repository.shortId, snapshotId]);
|
||||||
query: { path },
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
pathTransform: {
|
|
||||||
strip: stripBasePath,
|
|
||||||
add: addBasePath,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const { mutate: restoreSnapshot, isPending: isRestoring } = useMutation({
|
const { mutate: restoreSnapshot, isPending: isRestoring } = useMutation({
|
||||||
...restoreSnapshotMutation(),
|
...restoreSnapshotMutation(),
|
||||||
onSuccess: () => {
|
|
||||||
toast.success("Restore completed");
|
|
||||||
void navigate(returnPath);
|
|
||||||
},
|
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
toast.error("Restore failed", { description: error.message || "Failed to restore snapshot" });
|
restoreCompletedRef.current = true;
|
||||||
|
setIsRestoreActive(false);
|
||||||
|
handleRepositoryError("Restore failed", error, repository.shortId);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleRestore = useCallback(() => {
|
const handleRestore = useCallback(() => {
|
||||||
const excludeXattrArray = excludeXattr
|
const excludeXattrValues = excludeXattr
|
||||||
?.split(",")
|
.split(",")
|
||||||
.map((s) => s.trim())
|
.map((value) => value.trim())
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
|
|
||||||
const isCustomLocation = restoreLocation === "custom";
|
const isCustomLocation = restoreLocation === "custom";
|
||||||
const targetPath = isCustomLocation && customTargetPath.trim() ? customTargetPath.trim() : undefined;
|
const targetPath = isCustomLocation && hasCustomTargetPath ? trimmedCustomTargetPath : undefined;
|
||||||
|
|
||||||
const pathsArray = Array.from(selectedPaths);
|
const includePaths = Array.from(selectedPaths);
|
||||||
const includePaths = pathsArray.map((path) => addBasePath(path));
|
|
||||||
|
restoreCompletedRef.current = false;
|
||||||
|
setIsRestoreActive(true);
|
||||||
|
setRestoreResult(null);
|
||||||
|
setShowRestoreResultAlert(false);
|
||||||
|
|
||||||
restoreSnapshot({
|
restoreSnapshot({
|
||||||
path: { id: repository.id },
|
path: { shortId: repository.shortId },
|
||||||
body: {
|
body: {
|
||||||
snapshotId,
|
snapshotId,
|
||||||
include: includePaths.length > 0 ? includePaths : undefined,
|
include: includePaths.length > 0 ? includePaths : undefined,
|
||||||
delete: deleteExtraFiles,
|
selectedItemKind: includePaths.length === 1 ? (selectedPathKind ?? undefined) : undefined,
|
||||||
excludeXattr: excludeXattrArray && excludeXattrArray.length > 0 ? excludeXattrArray : undefined,
|
excludeXattr: excludeXattrValues.length > 0 ? excludeXattrValues : undefined,
|
||||||
targetPath,
|
targetPath,
|
||||||
overwrite: overwriteMode,
|
overwrite: overwriteMode,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}, [
|
}, [
|
||||||
repository.id,
|
repository.shortId,
|
||||||
snapshotId,
|
snapshotId,
|
||||||
excludeXattr,
|
excludeXattr,
|
||||||
|
hasCustomTargetPath,
|
||||||
restoreLocation,
|
restoreLocation,
|
||||||
customTargetPath,
|
trimmedCustomTargetPath,
|
||||||
selectedPaths,
|
selectedPaths,
|
||||||
addBasePath,
|
selectedPathKind,
|
||||||
deleteExtraFiles,
|
|
||||||
overwriteMode,
|
overwriteMode,
|
||||||
restoreSnapshot,
|
restoreSnapshot,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const canRestore = restoreLocation === "original" || customTargetPath.trim();
|
const handleDownload = useCallback(() => {
|
||||||
|
if (selectedPaths.size > 1) return;
|
||||||
|
|
||||||
|
const url = new URL(
|
||||||
|
`/api/v1/repositories/${repository.shortId}/snapshots/${snapshotId}/dump`,
|
||||||
|
window.location.origin,
|
||||||
|
);
|
||||||
|
|
||||||
|
const [selectedPath] = selectedPaths;
|
||||||
|
if (selectedPath) {
|
||||||
|
url.searchParams.set("path", selectedPath);
|
||||||
|
if (selectedPathKind) {
|
||||||
|
url.searchParams.set("kind", selectedPathKind);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.location.assign(url.toString());
|
||||||
|
}, [repository.shortId, snapshotId, selectedPathKind, selectedPaths]);
|
||||||
|
|
||||||
|
const acknowledgeRestoreResult = useCallback(() => {
|
||||||
|
setShowRestoreResultAlert(false);
|
||||||
|
setRestoreResult(null);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleResultAlertOpenChange = useCallback((open: boolean) => {
|
||||||
|
if (open) {
|
||||||
|
setShowRestoreResultAlert(true);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const canRestore = restoreRequiresCustomTarget
|
||||||
|
? hasCustomTargetPath
|
||||||
|
: restoreLocation === "original" || hasCustomTargetPath;
|
||||||
|
const canDownload = selectedPathCount <= 1;
|
||||||
|
const isRestoreRunning = isRestoring || isRestoreActive;
|
||||||
|
|
||||||
|
function getDownloadButtonText(): string {
|
||||||
|
if (selectedPathCount > 0) {
|
||||||
|
return `Download ${selectedPathCount} ${selectedPathCount === 1 ? "item" : "items"}`;
|
||||||
|
}
|
||||||
|
return "Download All";
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRestoreButtonText(): string {
|
||||||
|
if (isRestoreRunning) {
|
||||||
|
return "Restoring...";
|
||||||
|
}
|
||||||
|
if (selectedPathCount > 0) {
|
||||||
|
return `Restore ${selectedPathCount} ${selectedPathCount === 1 ? "item" : "items"}`;
|
||||||
|
}
|
||||||
|
return "Restore All";
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between">
|
||||||
<div>
|
<div>
|
||||||
<h1 className="text-2xl font-bold">Restore Snapshot</h1>
|
<h1 className="text-2xl font-bold">Restore Snapshot</h1>
|
||||||
<p className="text-sm text-muted-foreground">
|
<p className="text-sm text-muted-foreground">
|
||||||
{repository.name} / {snapshotId}
|
{repository.name} / {snapshotId}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex gap-2">
|
<div className="flex flex-wrap gap-2">
|
||||||
<Button variant="outline" onClick={() => navigate(returnPath)}>
|
<Button variant="outline" onClick={() => navigate({ to: returnPath })}>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="primary" onClick={handleRestore} disabled={isRestoring || !canRestore}>
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<span className="inline-flex">
|
||||||
|
<Button variant="outline" onClick={handleDownload} disabled={!canDownload}>
|
||||||
|
<Download className="h-4 w-4 mr-2" />
|
||||||
|
{getDownloadButtonText()}
|
||||||
|
</Button>
|
||||||
|
</span>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent className={cn({ hidden: canDownload })}>
|
||||||
|
<p>Download is available only for one selected item, or with no selection to download everything.</p>
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
<Button variant="primary" onClick={handleRestore} disabled={isRestoreRunning || !canRestore}>
|
||||||
<RotateCcw className="h-4 w-4 mr-2" />
|
<RotateCcw className="h-4 w-4 mr-2" />
|
||||||
{isRestoring
|
{getRestoreButtonText()}
|
||||||
? "Restoring..."
|
|
||||||
: selectedPaths.size > 0
|
|
||||||
? `Restore ${selectedPaths.size} ${selectedPaths.size === 1 ? "item" : "items"}`
|
|
||||||
: "Restore All"}
|
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
|
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
|
{isRestoreRunning && <RestoreProgress repositoryId={repository.shortId} snapshotId={snapshotId} />}
|
||||||
|
|
||||||
|
{restoreRequiresCustomTarget && (
|
||||||
|
<Alert variant="warning">
|
||||||
|
<AlertTriangle className="size-4" />
|
||||||
|
<AlertTitle>Source paths do not match</AlertTitle>
|
||||||
|
<AlertDescription>
|
||||||
|
This snapshot was created from source paths that do not match this Zerobyte server or the current linked
|
||||||
|
volume. Restoring to the original location is unavailable. Restore it to a custom location, or download
|
||||||
|
it instead.
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Restore Location</CardTitle>
|
<CardTitle>Restore Location</CardTitle>
|
||||||
|
|
@ -184,6 +291,7 @@ export function RestoreForm({ snapshot, repository, snapshotId, returnPath }: Re
|
||||||
size="sm"
|
size="sm"
|
||||||
className="flex justify-start gap-2"
|
className="flex justify-start gap-2"
|
||||||
onClick={() => setRestoreLocation("original")}
|
onClick={() => setRestoreLocation("original")}
|
||||||
|
disabled={!!restoreRequiresCustomTarget}
|
||||||
>
|
>
|
||||||
<RotateCcw size={16} className="mr-1" />
|
<RotateCcw size={16} className="mr-1" />
|
||||||
Original location
|
Original location
|
||||||
|
|
@ -261,16 +369,6 @@ export function RestoreForm({ snapshot, repository, snapshotId, returnPath }: Re
|
||||||
Exclude specific extended attributes during restore (comma-separated)
|
Exclude specific extended attributes during restore (comma-separated)
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center space-x-2">
|
|
||||||
<Checkbox
|
|
||||||
id="delete-extra"
|
|
||||||
checked={deleteExtraFiles}
|
|
||||||
onCheckedChange={(checked) => setDeleteExtraFiles(checked === true)}
|
|
||||||
/>
|
|
||||||
<Label htmlFor="delete-extra" className="text-sm font-normal cursor-pointer">
|
|
||||||
Delete files not present in the snapshot
|
|
||||||
</Label>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
</CardContent>
|
||||||
)}
|
)}
|
||||||
</Card>
|
</Card>
|
||||||
|
|
@ -285,37 +383,44 @@ export function RestoreForm({ snapshot, repository, snapshotId, returnPath }: Re
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="flex-1 overflow-hidden flex flex-col p-0">
|
<CardContent className="flex-1 overflow-hidden flex flex-col p-0">
|
||||||
{fileBrowser.isLoading && (
|
<SnapshotTreeBrowser
|
||||||
<div className="flex items-center justify-center flex-1">
|
repositoryId={repository.shortId}
|
||||||
<p className="text-muted-foreground">Loading files...</p>
|
snapshotId={snapshotId}
|
||||||
</div>
|
queryBasePath={snapshotBasePath}
|
||||||
)}
|
displayBasePath={displayBasePath}
|
||||||
|
pageSize={500}
|
||||||
{fileBrowser.isEmpty && (
|
className="flex flex-1 min-h-0 flex-col"
|
||||||
<div className="flex flex-col items-center justify-center flex-1 text-center p-8">
|
treeContainerClassName="overflow-auto flex-1 min-h-0 border border-border rounded-md bg-card m-4"
|
||||||
<FileIcon className="w-12 h-12 text-muted-foreground/50 mb-4" />
|
treeClassName="px-2 py-2"
|
||||||
<p className="text-muted-foreground">No files in this snapshot</p>
|
loadingMessage="Loading files..."
|
||||||
</div>
|
emptyMessage="No files in this snapshot"
|
||||||
)}
|
withCheckboxes
|
||||||
|
|
||||||
{!fileBrowser.isLoading && !fileBrowser.isEmpty && (
|
|
||||||
<div className="overflow-auto flex-1 border border-border rounded-md bg-card m-4">
|
|
||||||
<FileTree
|
|
||||||
files={fileBrowser.fileArray}
|
|
||||||
onFolderExpand={fileBrowser.handleFolderExpand}
|
|
||||||
onFolderHover={fileBrowser.handleFolderHover}
|
|
||||||
expandedFolders={fileBrowser.expandedFolders}
|
|
||||||
loadingFolders={fileBrowser.loadingFolders}
|
|
||||||
className="px-2 py-2"
|
|
||||||
withCheckboxes={true}
|
|
||||||
selectedPaths={selectedPaths}
|
selectedPaths={selectedPaths}
|
||||||
onSelectionChange={setSelectedPaths}
|
onSelectionChange={setSelectedPaths}
|
||||||
|
onSingleSelectionKindChange={setSelectedPathKind}
|
||||||
|
stateClassName="flex-1 min-h-0"
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<AlertDialog open={showRestoreResultAlert} onOpenChange={handleResultAlertOpenChange}>
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>
|
||||||
|
{restoreResult?.status === "success" ? "Restore completed" : "Restore failed"}
|
||||||
|
</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
{restoreResult?.status === "success"
|
||||||
|
? `Snapshot ${snapshotId} was restored successfully.`
|
||||||
|
: restoreResult?.error || `Snapshot ${snapshotId} could not be restored.`}
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogAction onClick={acknowledgeRestoreResult}>OK</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
101
app/client/components/restore-progress.tsx
Normal file
101
app/client/components/restore-progress.tsx
Normal file
|
|
@ -0,0 +1,101 @@
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { ByteSize } from "~/client/components/bytes-size";
|
||||||
|
import { useFormatBytes } from "~/client/hooks/use-format-bytes";
|
||||||
|
import { useRootLoaderData } from "~/client/hooks/use-root-loader-data";
|
||||||
|
import { Card } from "~/client/components/ui/card";
|
||||||
|
import { Progress } from "~/client/components/ui/progress";
|
||||||
|
import { type RestoreProgressEvent, useServerEvents } from "~/client/hooks/use-server-events";
|
||||||
|
import { formatDuration } from "~/utils/utils";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
repositoryId: string;
|
||||||
|
snapshotId: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const RestoreProgress = ({ repositoryId, snapshotId }: Props) => {
|
||||||
|
const formatBytes = useFormatBytes();
|
||||||
|
const { locale } = useRootLoaderData();
|
||||||
|
const { addEventListener } = useServerEvents();
|
||||||
|
const [progress, setProgress] = useState<RestoreProgressEvent | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const abortController = new AbortController();
|
||||||
|
|
||||||
|
addEventListener(
|
||||||
|
"restore:progress",
|
||||||
|
(progressData) => {
|
||||||
|
if (progressData.repositoryId === repositoryId && progressData.snapshotId === snapshotId) {
|
||||||
|
setProgress(progressData);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ signal: abortController.signal },
|
||||||
|
);
|
||||||
|
|
||||||
|
addEventListener(
|
||||||
|
"restore:completed",
|
||||||
|
(completedData) => {
|
||||||
|
if (completedData.repositoryId === repositoryId && completedData.snapshotId === snapshotId) {
|
||||||
|
setProgress(null);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ signal: abortController.signal },
|
||||||
|
);
|
||||||
|
|
||||||
|
return () => abortController.abort();
|
||||||
|
}, [addEventListener, repositoryId, snapshotId]);
|
||||||
|
|
||||||
|
if (!progress) {
|
||||||
|
return (
|
||||||
|
<Card className="p-4">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<div className="h-4 w-4 animate-spin rounded-full border-2 border-primary border-t-transparent" />
|
||||||
|
<span className="font-medium">Restore in progress</span>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const percentDone = Math.round(progress.percent_done * 100);
|
||||||
|
const speed = progress.seconds_elapsed > 0 ? formatBytes(progress.bytes_restored / progress.seconds_elapsed) : null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card className="p-4">
|
||||||
|
<div className="flex items-center justify-between mb-4">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<div className="h-4 w-4 animate-spin rounded-full border-2 border-primary border-t-transparent" />
|
||||||
|
<span className="font-medium">Restore in progress</span>
|
||||||
|
</div>
|
||||||
|
<span className="text-sm font-medium text-primary">{percentDone}%</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Progress value={percentDone} className="h-2 mb-4" />
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-4 text-sm">
|
||||||
|
<div>
|
||||||
|
<p className="text-xs uppercase text-muted-foreground">Files</p>
|
||||||
|
<p className="font-medium">
|
||||||
|
{progress.files_restored.toLocaleString(locale)}
|
||||||
|
/
|
||||||
|
{progress.total_files.toLocaleString(locale)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className="text-xs uppercase text-muted-foreground">Data</p>
|
||||||
|
<p className="font-medium">
|
||||||
|
<ByteSize bytes={progress.bytes_restored} base={1024} />
|
||||||
|
/
|
||||||
|
<ByteSize bytes={progress.total_bytes} base={1024} />
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className="text-xs uppercase text-muted-foreground">Elapsed</p>
|
||||||
|
<p className="font-medium">{formatDuration(progress.seconds_elapsed)}</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className="text-xs uppercase text-muted-foreground">Speed</p>
|
||||||
|
<p className="font-medium">{speed ? `${speed.text} ${speed.unit}/s` : "Calculating..."}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
};
|
||||||
89
app/client/components/retention-category-badges.tsx
Normal file
89
app/client/components/retention-category-badges.tsx
Normal file
|
|
@ -0,0 +1,89 @@
|
||||||
|
import { useState } from "react";
|
||||||
|
import { cn } from "~/client/lib/utils";
|
||||||
|
import { HoverCard, HoverCardContent, HoverCardTrigger } from "./ui/hover-card";
|
||||||
|
|
||||||
|
interface RetentionCategoryBadgesProps {
|
||||||
|
categories: string[];
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const categoryColors: Record<string, string> = {
|
||||||
|
last: "bg-blue-500/20 text-blue-700 dark:text-blue-300 border-blue-500/30",
|
||||||
|
hourly: "bg-cyan-500/20 text-cyan-700 dark:text-cyan-300 border-cyan-500/30",
|
||||||
|
daily: "bg-green-500/20 text-green-700 dark:text-green-300 border-green-500/30",
|
||||||
|
weekly: "bg-orange-500/20 text-orange-700 dark:text-orange-300 border-orange-500/30",
|
||||||
|
monthly: "bg-purple-500/20 text-purple-700 dark:text-purple-300 border-purple-500/30",
|
||||||
|
yearly: "bg-red-500/20 text-red-700 dark:text-red-300 border-red-500/30",
|
||||||
|
};
|
||||||
|
|
||||||
|
const categoryLabels: Record<string, string> = {
|
||||||
|
last: "Last",
|
||||||
|
hourly: "Hourly",
|
||||||
|
daily: "Daily",
|
||||||
|
weekly: "Weekly",
|
||||||
|
monthly: "Monthly",
|
||||||
|
yearly: "Yearly",
|
||||||
|
};
|
||||||
|
|
||||||
|
function Badge({ category }: { category: string }) {
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
"inline-flex items-center px-2 py-0.5 rounded text-xs font-medium border",
|
||||||
|
categoryColors[category] || "bg-gray-500/20 text-gray-700 dark:text-gray-300 border-gray-500/30",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{categoryLabels[category] || category}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function RetentionCategoryBadges({ categories, className }: RetentionCategoryBadgesProps) {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
|
if (categories.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const order = ["last", "hourly", "daily", "weekly", "monthly", "yearly"];
|
||||||
|
const sortedCategories = [...categories].sort((a, b) => {
|
||||||
|
const indexA = order.indexOf(a);
|
||||||
|
const indexB = order.indexOf(b);
|
||||||
|
if (indexA === -1) return 1;
|
||||||
|
if (indexB === -1) return -1;
|
||||||
|
return indexA - indexB;
|
||||||
|
});
|
||||||
|
|
||||||
|
const firstCategory = sortedCategories[0];
|
||||||
|
const hasMore = sortedCategories.length > 1;
|
||||||
|
|
||||||
|
if (!hasMore) {
|
||||||
|
return (
|
||||||
|
<div className={className}>
|
||||||
|
<Badge category={firstCategory} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<HoverCard open={open} onOpenChange={setOpen}>
|
||||||
|
<HoverCardTrigger asChild>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={cn("cursor-pointer bg-transparent p-0 border-0", className)}
|
||||||
|
aria-label={`View ${categories.length} retention categories`}
|
||||||
|
onClick={() => setOpen(true)}
|
||||||
|
>
|
||||||
|
<Badge category={`${categories.length} tags`} />
|
||||||
|
</button>
|
||||||
|
</HoverCardTrigger>
|
||||||
|
<HoverCardContent className="w-auto p-2">
|
||||||
|
<div className="flex flex-wrap gap-1">
|
||||||
|
{sortedCategories.map((category) => (
|
||||||
|
<Badge key={category} category={category} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</HoverCardContent>
|
||||||
|
</HoverCard>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import { Calendar, Clock, Database, HardDrive, Tag, Trash2, X } from "lucide-react";
|
import { Calendar, Clock, Database, HardDrive, Tag, Trash2, X } from "lucide-react";
|
||||||
import { Link, useNavigate } from "react-router";
|
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { ByteSize } from "~/client/components/bytes-size";
|
import { ByteSize } from "~/client/components/bytes-size";
|
||||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "~/client/components/ui/table";
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "~/client/components/ui/table";
|
||||||
|
|
@ -26,22 +25,31 @@ import {
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
} from "~/client/components/ui/dialog";
|
} from "~/client/components/ui/dialog";
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "~/client/components/ui/select";
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "~/client/components/ui/select";
|
||||||
|
import { useTimeFormat } from "~/client/lib/datetime";
|
||||||
import { formatDuration } from "~/utils/utils";
|
import { formatDuration } from "~/utils/utils";
|
||||||
import { formatDateTime } from "~/client/lib/datetime";
|
import {
|
||||||
import { deleteSnapshotsMutation, tagSnapshotsMutation } from "~/client/api-client/@tanstack/react-query.gen";
|
deleteSnapshotsMutation,
|
||||||
|
listSnapshotsQueryKey,
|
||||||
|
tagSnapshotsMutation,
|
||||||
|
} from "~/client/api-client/@tanstack/react-query.gen";
|
||||||
import { parseError } from "~/client/lib/errors";
|
import { parseError } from "~/client/lib/errors";
|
||||||
import type { BackupSchedule, Snapshot } from "../lib/types";
|
import type { BackupSchedule, Snapshot } from "../lib/types";
|
||||||
import { cn } from "../lib/utils";
|
import { cn } from "../lib/utils";
|
||||||
|
import { Link, useNavigate } from "@tanstack/react-router";
|
||||||
|
import type { ListSnapshotsData } from "~/client/api-client/types.gen";
|
||||||
|
import type { Options } from "~/client/api-client/client/types.gen";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
snapshots: Snapshot[];
|
snapshots: Snapshot[];
|
||||||
backups: BackupSchedule[];
|
backups: BackupSchedule[];
|
||||||
repositoryId: string;
|
repositoryId: string;
|
||||||
|
listSnapshotsQueryOptions: Options<ListSnapshotsData>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SnapshotsTable = ({ snapshots, repositoryId, backups }: Props) => {
|
export const SnapshotsTable = ({ snapshots, repositoryId, backups, listSnapshotsQueryOptions }: Props) => {
|
||||||
const navigate = useNavigate();
|
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const { formatDateTime } = useTimeFormat();
|
||||||
|
|
||||||
const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set());
|
const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set());
|
||||||
const [showBulkDeleteConfirm, setShowBulkDeleteConfirm] = useState(false);
|
const [showBulkDeleteConfirm, setShowBulkDeleteConfirm] = useState(false);
|
||||||
|
|
@ -50,8 +58,16 @@ export const SnapshotsTable = ({ snapshots, repositoryId, backups }: Props) => {
|
||||||
|
|
||||||
const deleteSnapshots = useMutation({
|
const deleteSnapshots = useMutation({
|
||||||
...deleteSnapshotsMutation(),
|
...deleteSnapshotsMutation(),
|
||||||
onSuccess: () => {
|
onSuccess: (_data, variables) => {
|
||||||
void queryClient.invalidateQueries({ queryKey: ["listSnapshots"] });
|
const snapshotIds = variables.body?.snapshotIds ?? [];
|
||||||
|
const queryKey = listSnapshotsQueryKey(listSnapshotsQueryOptions);
|
||||||
|
|
||||||
|
queryClient.setQueryData<Snapshot[]>(queryKey, (old) => {
|
||||||
|
if (!old) return old;
|
||||||
|
return old.filter((snapshot) => !snapshotIds.includes(snapshot.short_id));
|
||||||
|
});
|
||||||
|
|
||||||
|
void queryClient.invalidateQueries({ queryKey });
|
||||||
setShowBulkDeleteConfirm(false);
|
setShowBulkDeleteConfirm(false);
|
||||||
setSelectedIds(new Set());
|
setSelectedIds(new Set());
|
||||||
},
|
},
|
||||||
|
|
@ -63,7 +79,6 @@ export const SnapshotsTable = ({ snapshots, repositoryId, backups }: Props) => {
|
||||||
setShowReTagDialog(false);
|
setShowReTagDialog(false);
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
void queryClient.invalidateQueries({ queryKey: ["listSnapshots"] });
|
|
||||||
setShowReTagDialog(false);
|
setShowReTagDialog(false);
|
||||||
setSelectedIds(new Set());
|
setSelectedIds(new Set());
|
||||||
setTargetScheduleId("");
|
setTargetScheduleId("");
|
||||||
|
|
@ -71,7 +86,7 @@ export const SnapshotsTable = ({ snapshots, repositoryId, backups }: Props) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleRowClick = (snapshotId: string) => {
|
const handleRowClick = (snapshotId: string) => {
|
||||||
void navigate(`/repositories/${repositoryId}/${snapshotId}`);
|
void navigate({ to: `/repositories/${repositoryId}/${snapshotId}` });
|
||||||
};
|
};
|
||||||
|
|
||||||
const toggleSelectAll = () => {
|
const toggleSelectAll = () => {
|
||||||
|
|
@ -85,7 +100,7 @@ export const SnapshotsTable = ({ snapshots, repositoryId, backups }: Props) => {
|
||||||
const handleBulkDelete = () => {
|
const handleBulkDelete = () => {
|
||||||
toast.promise(
|
toast.promise(
|
||||||
deleteSnapshots.mutateAsync({
|
deleteSnapshots.mutateAsync({
|
||||||
path: { id: repositoryId },
|
path: { shortId: repositoryId },
|
||||||
body: { snapshotIds: Array.from(selectedIds) },
|
body: { snapshotIds: Array.from(selectedIds) },
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
|
|
@ -97,12 +112,12 @@ export const SnapshotsTable = ({ snapshots, repositoryId, backups }: Props) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleBulkReTag = () => {
|
const handleBulkReTag = () => {
|
||||||
const schedule = backups.find((b) => String(b.id) === targetScheduleId);
|
const schedule = backups.find((b) => b.shortId === targetScheduleId);
|
||||||
if (!schedule) return;
|
if (!schedule) return;
|
||||||
|
|
||||||
toast.promise(
|
toast.promise(
|
||||||
tagSnapshots.mutateAsync({
|
tagSnapshots.mutateAsync({
|
||||||
path: { id: repositoryId },
|
path: { shortId: repositoryId },
|
||||||
body: {
|
body: {
|
||||||
snapshotIds: Array.from(selectedIds),
|
snapshotIds: Array.from(selectedIds),
|
||||||
set: [schedule.shortId],
|
set: [schedule.shortId],
|
||||||
|
|
@ -172,7 +187,8 @@ export const SnapshotsTable = ({ snapshots, repositoryId, backups }: Props) => {
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<Link
|
<Link
|
||||||
hidden={!backup}
|
hidden={!backup}
|
||||||
to={backup ? `/backups/${backup.id}` : "#"}
|
to={backup ? `/backups/$backupId` : "."}
|
||||||
|
params={backup ? { backupId: backup.shortId } : {}}
|
||||||
onClick={(e) => e.stopPropagation()}
|
onClick={(e) => e.stopPropagation()}
|
||||||
className="hover:underline"
|
className="hover:underline"
|
||||||
>
|
>
|
||||||
|
|
@ -286,7 +302,7 @@ export const SnapshotsTable = ({ snapshots, repositoryId, backups }: Props) => {
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{backups.map((backup) => (
|
{backups.map((backup) => (
|
||||||
<SelectItem key={backup.id} value={String(backup.id)}>
|
<SelectItem key={backup.shortId} value={backup.shortId}>
|
||||||
{backup.name}
|
{backup.name}
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
))}
|
))}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
import { useSortable } from "@dnd-kit/sortable";
|
import { useSortable } from "@dnd-kit/sortable";
|
||||||
import { CSS } from "@dnd-kit/utilities";
|
import { CSS } from "@dnd-kit/utilities";
|
||||||
|
import { ClientOnly } from "@tanstack/react-router";
|
||||||
import { GripVertical } from "lucide-react";
|
import { GripVertical } from "lucide-react";
|
||||||
import type { PropsWithChildren } from "react";
|
import type { PropsWithChildren } from "react";
|
||||||
|
|
||||||
interface SortableBackupCardProps {
|
interface SortableBackupCardProps {
|
||||||
isDragging?: boolean;
|
isDragging?: boolean;
|
||||||
uniqueId: number;
|
uniqueId: string | number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function SortableCard({ isDragging, uniqueId, children }: PropsWithChildren<SortableBackupCardProps>) {
|
export function SortableCard({ isDragging, uniqueId, children }: PropsWithChildren<SortableBackupCardProps>) {
|
||||||
|
|
@ -21,6 +22,7 @@ export function SortableCard({ isDragging, uniqueId, children }: PropsWithChildr
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={setNodeRef} style={style} className="relative group">
|
<div ref={setNodeRef} style={style} className="relative group">
|
||||||
|
<ClientOnly>
|
||||||
<div
|
<div
|
||||||
{...attributes}
|
{...attributes}
|
||||||
{...listeners}
|
{...listeners}
|
||||||
|
|
@ -28,6 +30,7 @@ export function SortableCard({ isDragging, uniqueId, children }: PropsWithChildr
|
||||||
>
|
>
|
||||||
<GripVertical className="h-4 w-4 text-muted-foreground rotate-90" />
|
<GripVertical className="h-4 w-4 text-muted-foreground rotate-90" />
|
||||||
</div>
|
</div>
|
||||||
|
</ClientOnly>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ interface StatusDotProps {
|
||||||
export const StatusDot = ({ variant, label, animated }: StatusDotProps) => {
|
export const StatusDot = ({ variant, label, animated }: StatusDotProps) => {
|
||||||
const statusMapping = {
|
const statusMapping = {
|
||||||
success: {
|
success: {
|
||||||
color: "bg-green-500",
|
color: "bg-success shadow-[0_0_8px_rgba(16,185,129,0.5)]",
|
||||||
colorLight: "bg-emerald-400",
|
colorLight: "bg-success/60",
|
||||||
animated: animated ?? true,
|
animated: animated ?? true,
|
||||||
},
|
},
|
||||||
neutral: {
|
neutral: {
|
||||||
|
|
@ -40,12 +40,12 @@ export const StatusDot = ({ variant, label, animated }: StatusDotProps) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
<TooltipTrigger>
|
<TooltipTrigger asChild aria-label={label}>
|
||||||
<span className="relative flex size-3 mx-auto">
|
<span className="relative flex size-3 mx-auto">
|
||||||
{statusMapping?.animated && (
|
{statusMapping?.animated && (
|
||||||
<span
|
<span
|
||||||
className={cn(
|
className={cn(
|
||||||
"absolute inline-flex h-full w-full animate-ping rounded-full opacity-75",
|
"absolute inline-flex h-full w-full animate-[ping_3s_cubic-bezier(0,0,0.2,1)_infinite] rounded-full opacity-50",
|
||||||
`${statusMapping.colorLight}`,
|
`${statusMapping.colorLight}`,
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
@ -54,7 +54,7 @@ export const StatusDot = ({ variant, label, animated }: StatusDotProps) => {
|
||||||
</span>
|
</span>
|
||||||
</TooltipTrigger>
|
</TooltipTrigger>
|
||||||
<TooltipContent>
|
<TooltipContent>
|
||||||
<p>{label}</p>
|
<p className="capitalize">{label}</p>
|
||||||
</TooltipContent>
|
</TooltipContent>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
35
app/client/components/theme-provider.tsx
Normal file
35
app/client/components/theme-provider.tsx
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
import { createContext, useCallback, useContext, useState } from "react";
|
||||||
|
|
||||||
|
type Theme = "light" | "dark";
|
||||||
|
|
||||||
|
type ThemeContextValue = {
|
||||||
|
theme: Theme;
|
||||||
|
setTheme: (theme: Theme) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const ThemeContext = createContext<ThemeContextValue | null>(null);
|
||||||
|
|
||||||
|
export const THEME_COOKIE_NAME = "theme";
|
||||||
|
const THEME_COOKIE_MAX_AGE = 60 * 60 * 24 * 365; // 1 year
|
||||||
|
const DEFAULT_THEME: Theme = "dark";
|
||||||
|
|
||||||
|
export function ThemeProvider({ children, initialTheme }: { children: React.ReactNode; initialTheme?: Theme }) {
|
||||||
|
const [theme, setThemeState] = useState<Theme>(initialTheme ?? DEFAULT_THEME);
|
||||||
|
|
||||||
|
const setTheme = useCallback((newTheme: Theme) => {
|
||||||
|
setThemeState(newTheme);
|
||||||
|
document.cookie = `${THEME_COOKIE_NAME}=${newTheme}; path=/; max-age=${THEME_COOKIE_MAX_AGE}`;
|
||||||
|
document.documentElement.classList.toggle("dark", newTheme === "dark");
|
||||||
|
document.documentElement.style.colorScheme = newTheme;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return <ThemeContext value={{ theme, setTheme }}>{children}</ThemeContext>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useTheme() {
|
||||||
|
const context = useContext(ThemeContext);
|
||||||
|
if (!context) {
|
||||||
|
throw new Error("useTheme must be used within a ThemeProvider");
|
||||||
|
}
|
||||||
|
return context;
|
||||||
|
}
|
||||||
26
app/client/components/theme-toggle.tsx
Normal file
26
app/client/components/theme-toggle.tsx
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
import { Moon, Sun } from "lucide-react";
|
||||||
|
import { useTheme } from "./theme-provider";
|
||||||
|
import { Button } from "./ui/button";
|
||||||
|
import { Tooltip, TooltipContent, TooltipTrigger } from "./ui/tooltip";
|
||||||
|
|
||||||
|
export function ThemeToggle() {
|
||||||
|
const { theme, setTheme } = useTheme();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="relative rounded-full h-7 w-7 text-muted-foreground hover:text-foreground"
|
||||||
|
onClick={() => setTheme(theme === "dark" ? "light" : "dark")}
|
||||||
|
aria-label="Toggle theme"
|
||||||
|
>
|
||||||
|
<Sun className="h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
|
||||||
|
<Moon className="absolute h-4 w-4 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
|
||||||
|
</Button>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>Toggle theme</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
}
|
||||||
12
app/client/components/time-ago.tsx
Normal file
12
app/client/components/time-ago.tsx
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
import { useTimeFormat, type DateInput } from "~/client/lib/datetime";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
date: DateInput;
|
||||||
|
className?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function TimeAgo({ date, className }: Props) {
|
||||||
|
const { formatTimeAgo } = useTimeFormat();
|
||||||
|
|
||||||
|
return <span className={className}>{formatTimeAgo(date)}</span>;
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
// fallow-ignore-file unused-export
|
||||||
import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog";
|
import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog";
|
||||||
import type * as React from "react";
|
import type * as React from "react";
|
||||||
import { buttonVariants } from "~/client/components/ui/button";
|
import { buttonVariants } from "~/client/components/ui/button";
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
// fallow-ignore-file unused-export
|
||||||
import type * as React from "react";
|
import type * as React from "react";
|
||||||
import { Slot } from "@radix-ui/react-slot";
|
import { Slot } from "@radix-ui/react-slot";
|
||||||
import { cva, type VariantProps } from "class-variance-authority";
|
import { cva, type VariantProps } from "class-variance-authority";
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
// fallow-ignore-file unused-export
|
||||||
import type * as React from "react";
|
import type * as React from "react";
|
||||||
import { Slot } from "@radix-ui/react-slot";
|
import { Slot } from "@radix-ui/react-slot";
|
||||||
import { ChevronRight, MoreHorizontal } from "lucide-react";
|
import { ChevronRight, MoreHorizontal } from "lucide-react";
|
||||||
|
|
@ -12,17 +13,16 @@ function BreadcrumbList({ className, ...props }: React.ComponentProps<"ol">) {
|
||||||
return (
|
return (
|
||||||
<ol
|
<ol
|
||||||
data-slot="breadcrumb-list"
|
data-slot="breadcrumb-list"
|
||||||
className={cn(
|
className={cn("text-muted-foreground flex items-center gap-1.5 text-sm sm:gap-2.5 min-w-0", className)}
|
||||||
"text-muted-foreground flex items-center gap-1.5 text-sm sm:gap-2.5 min-w-0",
|
|
||||||
className,
|
|
||||||
)}
|
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function BreadcrumbItem({ className, ...props }: React.ComponentProps<"li">) {
|
function BreadcrumbItem({ className, ...props }: React.ComponentProps<"li">) {
|
||||||
return <li data-slot="breadcrumb-item" className={cn("inline-flex items-center gap-1.5 min-w-0", className)} {...props} />;
|
return (
|
||||||
|
<li data-slot="breadcrumb-item" className={cn("inline-flex items-center gap-1.5 min-w-0", className)} {...props} />
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function BreadcrumbLink({
|
function BreadcrumbLink({
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,22 @@
|
||||||
import { Slot } from "@radix-ui/react-slot";
|
import { Slot } from "@radix-ui/react-slot";
|
||||||
import { cva, type VariantProps } from "class-variance-authority";
|
import { cva, type VariantProps } from "class-variance-authority";
|
||||||
import { Loader2 } from "lucide-react";
|
import { Loader2 } from "lucide-react";
|
||||||
import type * as React from "react";
|
import * as React from "react";
|
||||||
|
|
||||||
import { cn } from "~/client/lib/utils";
|
import { cn } from "~/client/lib/utils";
|
||||||
|
import { useMinimumDuration } from "~/client/hooks/useMinimumDuration";
|
||||||
|
|
||||||
const buttonVariants = cva(
|
const buttonVariants = cva(
|
||||||
"inline-flex cursor-pointer uppercase rounded-sm items-center justify-center gap-2 whitespace-nowrap text-xs font-semibold tracking-wide transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-ring border-0",
|
"inline-flex cursor-pointer uppercase rounded-sm items-center justify-center gap-2 whitespace-nowrap text-xs font-semibold tracking-wide transition-all active:scale-[0.98] disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-ring border-0",
|
||||||
{
|
{
|
||||||
variants: {
|
variants: {
|
||||||
variant: {
|
variant: {
|
||||||
default: "bg-transparent text-white hover:bg-[#3A3A3A]/80 border dark:text-white dark:hover:bg-[#3A3A3A]/80",
|
default: "bg-transparent text-foreground hover:bg-muted border hover:border-border",
|
||||||
primary: "bg-strong-accent text-white hover:bg-strong-accent/90 focus-visible:ring-strong-accent/50",
|
primary: "bg-strong-accent text-white hover:bg-strong-accent/90 focus-visible:ring-strong-accent/50",
|
||||||
destructive:
|
destructive:
|
||||||
"border border-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/50 text-destructive hover:text-white",
|
"border border-destructive text-destructive hover:bg-destructive hover:text-destructive-foreground focus-visible:ring-destructive/50",
|
||||||
outline: "border border-border bg-background hover:bg-accent hover:text-accent-foreground",
|
outline: "border border-border bg-background hover:bg-accent hover:text-accent-foreground",
|
||||||
secondary: "bg-transparent text-white hover:bg-[#3A3A3A]/80 border dark:text-white dark:hover:bg-[#3A3A3A]/80",
|
secondary: "bg-transparent text-foreground hover:bg-muted border",
|
||||||
ghost: "hover:bg-accent hover:text-accent-foreground",
|
ghost: "hover:bg-accent hover:text-accent-foreground",
|
||||||
link: "text-primary underline-offset-4 hover:underline",
|
link: "text-primary underline-offset-4 hover:underline",
|
||||||
},
|
},
|
||||||
|
|
@ -33,28 +34,32 @@ const buttonVariants = cva(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const MINIMUM_LOADING_DURATION = 300;
|
||||||
|
|
||||||
function Button({
|
function Button({
|
||||||
className,
|
className,
|
||||||
variant,
|
variant,
|
||||||
size,
|
size,
|
||||||
asChild = false,
|
asChild = false,
|
||||||
loading,
|
loading,
|
||||||
|
disabled,
|
||||||
...props
|
...props
|
||||||
}: React.ComponentProps<"button"> &
|
}: React.ComponentProps<"button"> &
|
||||||
VariantProps<typeof buttonVariants> & {
|
VariantProps<typeof buttonVariants> & {
|
||||||
asChild?: boolean;
|
asChild?: boolean;
|
||||||
} & { loading?: boolean }) {
|
} & { loading?: boolean }) {
|
||||||
const Comp = asChild ? Slot : "button";
|
const Comp = asChild ? Slot : "button";
|
||||||
|
const isLoading = useMinimumDuration(loading ?? false, MINIMUM_LOADING_DURATION);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Comp
|
<Comp
|
||||||
disabled={loading}
|
{...props}
|
||||||
data-slot="button"
|
data-slot="button"
|
||||||
className={cn(buttonVariants({ variant, size, className }), "transition-all")}
|
className={cn(buttonVariants({ variant, size, className }), "transition-all")}
|
||||||
{...props}
|
disabled={disabled || loading || isLoading}
|
||||||
>
|
>
|
||||||
<Loader2 className={cn("h-4 w-4 animate-spin absolute", { invisible: !loading })} />
|
<Loader2 className={cn("h-4 w-4 animate-spin absolute", { invisible: !isLoading })} />
|
||||||
<div className={cn("flex items-center justify-center", { invisible: loading })}>{props.children}</div>
|
<div className={cn("flex items-center justify-center", { invisible: isLoading })}>{props.children}</div>
|
||||||
</Comp>
|
</Comp>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,35 @@
|
||||||
|
// fallow-ignore-file unused-export
|
||||||
import type * as React from "react";
|
import type * as React from "react";
|
||||||
|
|
||||||
import { cn } from "~/client/lib/utils";
|
import { cn } from "~/client/lib/utils";
|
||||||
|
|
||||||
function Card({ className, children, ...props }: React.ComponentProps<"div">) {
|
function Card({ className, children, interactive, ...props }: React.ComponentProps<"div"> & { interactive?: boolean }) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
data-slot="card"
|
data-slot="card"
|
||||||
className={cn("bg-card text-card-foreground relative flex flex-col gap-6 border-2 py-6 shadow-sm", className)}
|
className={cn(
|
||||||
|
"bg-card text-card-foreground group relative flex flex-col gap-6 border border-border py-6 shadow-[0_8px_30px_-15px_rgba(0,0,0,0.04)] dark:shadow-[inset_0_0_0_1px_rgba(255,255,255,0.02)] transition-colors duration-300 ",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<span aria-hidden="true" className="pointer-events-none absolute inset-0 z-10 select-none">
|
<span
|
||||||
<span className="absolute -left-0.5 -top-0.5 h-0.5 w-4 bg-white/80" />
|
aria-hidden="true"
|
||||||
<span className="absolute -left-0.5 -top-0.5 h-4 w-0.5 bg-white/80" />
|
className={cn(
|
||||||
<span className="absolute -right-0.5 -top-0.5 h-0.5 w-4 bg-white/80" />
|
"pointer-events-none absolute inset-0 z-10 select-none opacity-30 transition-opacity duration-300 ",
|
||||||
<span className="absolute -right-0.5 -top-0.5 h-4 w-0.5 bg-white/80" />
|
{
|
||||||
<span className="absolute -left-0.5 -bottom-0.5 h-0.5 w-4 bg-white/80" />
|
"group-hover:opacity-100": interactive,
|
||||||
<span className="absolute -left-0.5 -bottom-0.5 h-4 w-0.5 bg-white/80" />
|
},
|
||||||
<span className="absolute -right-0.5 -bottom-0.5 h-0.5 w-4 bg-white/80" />
|
)}
|
||||||
<span className="absolute -right-0.5 -bottom-0.5 h-4 w-0.5 bg-white/80" />
|
>
|
||||||
|
<span className="absolute -left-0.5 -top-0.5 h-0.5 w-4 bg-foreground" />
|
||||||
|
<span className="absolute -left-0.5 -top-0.5 h-4 w-0.5 bg-foreground" />
|
||||||
|
<span className="absolute -right-0.5 -top-0.5 h-0.5 w-4 bg-foreground" />
|
||||||
|
<span className="absolute -right-0.5 -top-0.5 h-4 w-0.5 bg-foreground" />
|
||||||
|
<span className="absolute -left-0.5 -bottom-0.5 h-0.5 w-4 bg-foreground" />
|
||||||
|
<span className="absolute -left-0.5 -bottom-0.5 h-4 w-0.5 bg-foreground" />
|
||||||
|
<span className="absolute -right-0.5 -bottom-0.5 h-0.5 w-4 bg-foreground" />
|
||||||
|
<span className="absolute -right-0.5 -bottom-0.5 h-4 w-0.5 bg-foreground" />
|
||||||
</span>
|
</span>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,16 @@
|
||||||
|
// fallow-ignore-file unused-export
|
||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
// biome-ignore-all lint: reason
|
// biome-ignore-all lint: reason
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import * as RechartsPrimitive from "recharts";
|
import * as RechartsPrimitive from "recharts";
|
||||||
|
|
||||||
|
import { useRootLoaderData } from "~/client/hooks/use-root-loader-data";
|
||||||
import { cn } from "~/client/lib/utils";
|
import { cn } from "~/client/lib/utils";
|
||||||
|
|
||||||
// Format: { THEME_NAME: CSS_SELECTOR }
|
// Format: { THEME_NAME: CSS_SELECTOR }
|
||||||
const THEMES = { light: "", dark: ".dark" } as const;
|
const THEMES = { light: "", dark: ".dark" } as const;
|
||||||
|
|
||||||
|
// fallow-ignore-next-line unused-type
|
||||||
export type ChartConfig = {
|
export type ChartConfig = {
|
||||||
[k in string]: {
|
[k in string]: {
|
||||||
label?: React.ReactNode;
|
label?: React.ReactNode;
|
||||||
|
|
@ -116,6 +119,7 @@ function ChartTooltipContent({
|
||||||
labelKey?: string;
|
labelKey?: string;
|
||||||
}) {
|
}) {
|
||||||
const { config } = useChart();
|
const { config } = useChart();
|
||||||
|
const { locale } = useRootLoaderData();
|
||||||
|
|
||||||
const tooltipLabel = React.useMemo(() => {
|
const tooltipLabel = React.useMemo(() => {
|
||||||
if (hideLabel || !payload?.length) {
|
if (hideLabel || !payload?.length) {
|
||||||
|
|
@ -205,7 +209,7 @@ function ChartTooltipContent({
|
||||||
</div>
|
</div>
|
||||||
{item.value && (
|
{item.value && (
|
||||||
<span className="text-foreground font-mono font-medium tabular-nums">
|
<span className="text-foreground font-mono font-medium tabular-nums">
|
||||||
{item.value.toLocaleString()}
|
{item.value.toLocaleString(locale)}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
import type * as React from "react";
|
import * as React from "react";
|
||||||
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
|
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
|
||||||
import { CheckIcon } from "lucide-react";
|
import { CheckIcon } from "lucide-react";
|
||||||
|
|
||||||
|
import { useWebHaptics } from "web-haptics/react";
|
||||||
import { cn } from "~/client/lib/utils";
|
import { cn } from "~/client/lib/utils";
|
||||||
|
|
||||||
function Checkbox({ className, ...props }: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
|
function Checkbox({ className, ...props }: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
|
||||||
|
const trigger = useWebHaptics().trigger;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CheckboxPrimitive.Root
|
<CheckboxPrimitive.Root
|
||||||
data-slot="checkbox"
|
data-slot="checkbox"
|
||||||
|
|
@ -12,6 +15,10 @@ function Checkbox({ className, ...props }: React.ComponentProps<typeof CheckboxP
|
||||||
"peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
|
"peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
|
onCheckedChange={(checked) => {
|
||||||
|
void trigger([{ duration: 8 }], { intensity: 0.3 });
|
||||||
|
props.onCheckedChange?.(checked);
|
||||||
|
}}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<CheckboxPrimitive.Indicator
|
<CheckboxPrimitive.Indicator
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ interface CodeBlockProps {
|
||||||
|
|
||||||
export const CodeBlock: React.FC<CodeBlockProps> = ({ code, filename }) => {
|
export const CodeBlock: React.FC<CodeBlockProps> = ({ code, filename }) => {
|
||||||
return (
|
return (
|
||||||
<div className="overflow-hidden rounded-sm bg-card-header ring-1 ring-white/10">
|
<div className="overflow-hidden rounded-sm bg-card-header ring-1 ring-border">
|
||||||
<div className="flex items-center justify-between border-b border-white/10 px-4 py-2 text-xs">
|
<div className="flex items-center justify-between border-b border-border px-4 py-2 text-xs">
|
||||||
<div className="flex items-center gap-1.5">
|
<div className="flex items-center gap-1.5">
|
||||||
<span className="h-2.5 w-2.5 rounded-full bg-rose-500" />
|
<span className="h-2.5 w-2.5 rounded-full bg-rose-500" />
|
||||||
<span className="h-2.5 w-2.5 rounded-full bg-amber-500" />
|
<span className="h-2.5 w-2.5 rounded-full bg-amber-500" />
|
||||||
|
|
@ -18,7 +18,7 @@ export const CodeBlock: React.FC<CodeBlockProps> = ({ code, filename }) => {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<pre className="text-xs m-0 px-4 py-2 bg-card-header">
|
<pre className="text-xs m-0 px-4 py-2 bg-card-header">
|
||||||
<code className="text-white/80 select-all">{code}</code>
|
<code className="text-foreground/80 select-all">{code}</code>
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
// fallow-ignore-file unused-export
|
||||||
import type * as React from "react";
|
import type * as React from "react";
|
||||||
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
||||||
import { XIcon } from "lucide-react";
|
import { XIcon } from "lucide-react";
|
||||||
|
|
|
||||||
218
app/client/components/ui/dropdown-menu.tsx
Normal file
218
app/client/components/ui/dropdown-menu.tsx
Normal file
|
|
@ -0,0 +1,218 @@
|
||||||
|
// fallow-ignore-file unused-export
|
||||||
|
import * as React from "react";
|
||||||
|
import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react";
|
||||||
|
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
||||||
|
|
||||||
|
import { cn } from "~/client/lib/utils";
|
||||||
|
|
||||||
|
function DropdownMenu({ ...props }: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {
|
||||||
|
return <DropdownMenuPrimitive.Root data-slot="dropdown-menu" {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuPortal({ ...props }: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {
|
||||||
|
return <DropdownMenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuTrigger({ ...props }: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {
|
||||||
|
return <DropdownMenuPrimitive.Trigger data-slot="dropdown-menu-trigger" {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuContent({
|
||||||
|
className,
|
||||||
|
sideOffset = 4,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Portal>
|
||||||
|
<DropdownMenuPrimitive.Content
|
||||||
|
data-slot="dropdown-menu-content"
|
||||||
|
sideOffset={sideOffset}
|
||||||
|
className={cn(
|
||||||
|
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
</DropdownMenuPrimitive.Portal>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuGroup({ ...props }: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {
|
||||||
|
return <DropdownMenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuItem({
|
||||||
|
className,
|
||||||
|
inset,
|
||||||
|
variant = "default",
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {
|
||||||
|
inset?: boolean;
|
||||||
|
variant?: "default" | "destructive";
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Item
|
||||||
|
data-slot="dropdown-menu-item"
|
||||||
|
data-inset={inset}
|
||||||
|
data-variant={variant}
|
||||||
|
className={cn(
|
||||||
|
"focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuCheckboxItem({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
checked,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.CheckboxItem
|
||||||
|
data-slot="dropdown-menu-checkbox-item"
|
||||||
|
className={cn(
|
||||||
|
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
checked={checked}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||||
|
<DropdownMenuPrimitive.ItemIndicator>
|
||||||
|
<CheckIcon className="size-4" />
|
||||||
|
</DropdownMenuPrimitive.ItemIndicator>
|
||||||
|
</span>
|
||||||
|
{children}
|
||||||
|
</DropdownMenuPrimitive.CheckboxItem>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuRadioGroup({ ...props }: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {
|
||||||
|
return <DropdownMenuPrimitive.RadioGroup data-slot="dropdown-menu-radio-group" {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuRadioItem({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.RadioItem
|
||||||
|
data-slot="dropdown-menu-radio-item"
|
||||||
|
className={cn(
|
||||||
|
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||||
|
<DropdownMenuPrimitive.ItemIndicator>
|
||||||
|
<CircleIcon className="size-2 fill-current" />
|
||||||
|
</DropdownMenuPrimitive.ItemIndicator>
|
||||||
|
</span>
|
||||||
|
{children}
|
||||||
|
</DropdownMenuPrimitive.RadioItem>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuLabel({
|
||||||
|
className,
|
||||||
|
inset,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {
|
||||||
|
inset?: boolean;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Label
|
||||||
|
data-slot="dropdown-menu-label"
|
||||||
|
data-inset={inset}
|
||||||
|
className={cn("px-2 py-1.5 text-sm font-medium data-[inset]:pl-8", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuSeparator({ className, ...props }: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Separator
|
||||||
|
data-slot="dropdown-menu-separator"
|
||||||
|
className={cn("bg-border -mx-1 my-1 h-px", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuShortcut({ className, ...props }: React.ComponentProps<"span">) {
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
data-slot="dropdown-menu-shortcut"
|
||||||
|
className={cn("text-muted-foreground ml-auto text-xs tracking-widest", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuSub({ ...props }: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {
|
||||||
|
return <DropdownMenuPrimitive.Sub data-slot="dropdown-menu-sub" {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuSubTrigger({
|
||||||
|
className,
|
||||||
|
inset,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {
|
||||||
|
inset?: boolean;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.SubTrigger
|
||||||
|
data-slot="dropdown-menu-sub-trigger"
|
||||||
|
data-inset={inset}
|
||||||
|
className={cn(
|
||||||
|
"focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
<ChevronRightIcon className="ml-auto size-4" />
|
||||||
|
</DropdownMenuPrimitive.SubTrigger>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuSubContent({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.SubContent
|
||||||
|
data-slot="dropdown-menu-sub-content"
|
||||||
|
className={cn(
|
||||||
|
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuPortal,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuGroup,
|
||||||
|
DropdownMenuLabel,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuCheckboxItem,
|
||||||
|
DropdownMenuRadioGroup,
|
||||||
|
DropdownMenuRadioItem,
|
||||||
|
DropdownMenuSeparator,
|
||||||
|
DropdownMenuShortcut,
|
||||||
|
DropdownMenuSub,
|
||||||
|
DropdownMenuSubTrigger,
|
||||||
|
DropdownMenuSubContent,
|
||||||
|
};
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
// fallow-ignore-file unused-export
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import type * as LabelPrimitive from "@radix-ui/react-label";
|
import type * as LabelPrimitive from "@radix-ui/react-label";
|
||||||
import { Slot } from "@radix-ui/react-slot";
|
import { Slot } from "@radix-ui/react-slot";
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { OTPInput, OTPInputContext } from "input-otp";
|
import { OTPInput, OTPInputContext } from "input-otp";
|
||||||
import { MinusIcon } from "lucide-react";
|
|
||||||
|
|
||||||
import { cn } from "~/client/lib/utils";
|
import { cn } from "~/client/lib/utils";
|
||||||
|
|
||||||
|
|
@ -55,12 +54,8 @@ function InputOTPSlot({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function InputOTPSeparator({ ...props }: React.ComponentProps<"div">) {
|
function InputOTPSeparator({ ...props }: React.ComponentProps<"hr">) {
|
||||||
return (
|
return <hr data-slot="input-otp-separator" {...props} />;
|
||||||
<div data-slot="input-otp-separator" role="separator" {...props}>
|
|
||||||
<MinusIcon />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export { InputOTP, InputOTPGroup, InputOTPSlot, InputOTPSeparator };
|
export { InputOTP, InputOTPGroup, InputOTPSlot, InputOTPSeparator };
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
||||||
data-slot="input"
|
data-slot="input"
|
||||||
className={cn(
|
className={cn(
|
||||||
"file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input flex h-9 w-full min-w-0 border bg-transparent px-3 py-1 text-sm shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
"file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input flex h-9 w-full min-w-0 border bg-transparent px-3 py-1 text-sm shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
||||||
|
// "file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground bg-black/5 dark:bg-white/5 flex h-9 w-full min-w-0 border-0 px-3 py-1 text-sm shadow-xs dark:shadow-[inset_0_1px_0_rgba(255,255,255,0.05)] transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
||||||
"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
|
"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
|
||||||
"aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
"aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
||||||
className,
|
className,
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
// fallow-ignore-file unused-export
|
||||||
import type * as React from "react";
|
import type * as React from "react";
|
||||||
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area";
|
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
// fallow-ignore-file unused-export
|
||||||
import { Eye, EyeOff } from "lucide-react";
|
import { Eye, EyeOff } from "lucide-react";
|
||||||
import type * as React from "react";
|
import type * as React from "react";
|
||||||
import { useMemo, useState } from "react";
|
import { useMemo, useState } from "react";
|
||||||
|
|
@ -14,7 +15,7 @@ export const isStoredSecretValue = (value?: string): boolean => {
|
||||||
return value.startsWith("env://") || value.startsWith("file://") || value.startsWith("encv1:");
|
return value.startsWith("env://") || value.startsWith("file://") || value.startsWith("encv1:");
|
||||||
};
|
};
|
||||||
|
|
||||||
type SecretInputProps = Omit<React.ComponentProps<typeof Input>, "type">
|
type SecretInputProps = Omit<React.ComponentProps<typeof Input>, "type">;
|
||||||
|
|
||||||
export const SecretInput = ({ className, value, ...props }: SecretInputProps) => {
|
export const SecretInput = ({ className, value, ...props }: SecretInputProps) => {
|
||||||
const [revealed, setRevealed] = useState(false);
|
const [revealed, setRevealed] = useState(false);
|
||||||
|
|
@ -36,12 +37,7 @@ export const SecretInput = ({ className, value, ...props }: SecretInputProps) =>
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative" data-secret-input>
|
<div className="relative" data-secret-input>
|
||||||
<Input
|
<Input {...props} value={value} type={type} className={cn(!showAsPlaintext && "pr-10", className)} />
|
||||||
{...props}
|
|
||||||
value={value}
|
|
||||||
type={type}
|
|
||||||
className={cn(!showAsPlaintext && "pr-10", className)}
|
|
||||||
/>
|
|
||||||
{!showAsPlaintext && (
|
{!showAsPlaintext && (
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,73 @@
|
||||||
import type * as React from "react";
|
// fallow-ignore-file unused-export
|
||||||
|
import * as React from "react";
|
||||||
import * as SelectPrimitive from "@radix-ui/react-select";
|
import * as SelectPrimitive from "@radix-ui/react-select";
|
||||||
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react";
|
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react";
|
||||||
|
|
||||||
import { cn } from "~/client/lib/utils";
|
import { cn } from "~/client/lib/utils";
|
||||||
|
|
||||||
function Select({ ...props }: React.ComponentProps<typeof SelectPrimitive.Root>) {
|
const SelectSsrValueContext = React.createContext<{
|
||||||
return <SelectPrimitive.Root data-slot="select" {...props} />;
|
hydrated: boolean;
|
||||||
|
items: Map<string, React.ReactNode>;
|
||||||
|
value: string | undefined;
|
||||||
|
} | null>(null);
|
||||||
|
|
||||||
|
function collectSelectItems(children: React.ReactNode, items = new Map<string, React.ReactNode>()) {
|
||||||
|
for (const child of React.Children.toArray(children)) {
|
||||||
|
if (!React.isValidElement<{ children?: React.ReactNode; value?: string }>(child)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((child.type === SelectItem || child.type === SelectPrimitive.Item) && typeof child.props.value === "string") {
|
||||||
|
items.set(child.props.value, child.props.children);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (child.props.children) {
|
||||||
|
collectSelectItems(child.props.children, items);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
function Select({ children, value, ...props }: React.ComponentProps<typeof SelectPrimitive.Root>) {
|
||||||
|
const [hydrated, setHydrated] = React.useState(false);
|
||||||
|
const items = collectSelectItems(children);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
setHydrated(true);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SelectSsrValueContext.Provider value={{ hydrated, items, value }}>
|
||||||
|
<SelectPrimitive.Root data-slot="select" value={value} {...props}>
|
||||||
|
{children}
|
||||||
|
</SelectPrimitive.Root>
|
||||||
|
</SelectSsrValueContext.Provider>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function SelectGroup({ ...props }: React.ComponentProps<typeof SelectPrimitive.Group>) {
|
function SelectGroup({ ...props }: React.ComponentProps<typeof SelectPrimitive.Group>) {
|
||||||
return <SelectPrimitive.Group data-slot="select-group" {...props} />;
|
return <SelectPrimitive.Group data-slot="select-group" {...props} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
function SelectValue({ ...props }: React.ComponentProps<typeof SelectPrimitive.Value>) {
|
function SelectValue({ children, placeholder, style, ...props }: React.ComponentProps<typeof SelectPrimitive.Value>) {
|
||||||
return <SelectPrimitive.Value data-slot="select-value" {...props} />;
|
const context = React.useContext(SelectSsrValueContext);
|
||||||
|
const selectedItem =
|
||||||
|
context?.value !== undefined && context.value !== "" ? context.items.get(context.value) : undefined;
|
||||||
|
|
||||||
|
if (!context?.hydrated) {
|
||||||
|
return (
|
||||||
|
<span data-slot="select-value" {...props} style={{ pointerEvents: "none", ...style }}>
|
||||||
|
{children ?? selectedItem ?? placeholder}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Value data-slot="select-value" placeholder={placeholder} style={style} {...props}>
|
||||||
|
{children}
|
||||||
|
</SelectPrimitive.Value>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function SelectTrigger({
|
function SelectTrigger({
|
||||||
|
|
@ -21,19 +75,35 @@ function SelectTrigger({
|
||||||
size = "default",
|
size = "default",
|
||||||
children,
|
children,
|
||||||
...props
|
...props
|
||||||
}: React.ComponentProps<typeof SelectPrimitive.Trigger> & {
|
}: React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger> & {
|
||||||
size?: "sm" | "default";
|
size?: "sm" | "default";
|
||||||
}) {
|
}) {
|
||||||
return (
|
const context = React.useContext(SelectSsrValueContext);
|
||||||
<SelectPrimitive.Trigger
|
const hasValue = context?.value !== undefined && context.value !== "";
|
||||||
data-slot="select-trigger"
|
const triggerClassName = cn(
|
||||||
data-size={size}
|
"border-input data-placeholder:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&+select[aria-hidden=true]]:hidden [&:has(+select[aria-hidden=true]:last-child)]:mb-0",
|
||||||
className={cn(
|
|
||||||
"border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
||||||
className,
|
className,
|
||||||
)}
|
);
|
||||||
{...props}
|
|
||||||
|
if (!context?.hydrated) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
id={props.id}
|
||||||
|
aria-disabled="true"
|
||||||
|
aria-invalid={props["aria-invalid"]}
|
||||||
|
data-placeholder={hasValue ? undefined : ""}
|
||||||
|
data-size={size}
|
||||||
|
data-slot="select-trigger"
|
||||||
|
className={triggerClassName}
|
||||||
>
|
>
|
||||||
|
{children}
|
||||||
|
<ChevronDownIcon className="size-4 opacity-50" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Trigger data-slot="select-trigger" data-size={size} className={triggerClassName} {...props}>
|
||||||
{children}
|
{children}
|
||||||
<SelectPrimitive.Icon asChild>
|
<SelectPrimitive.Icon asChild>
|
||||||
<ChevronDownIcon className="size-4 opacity-50" />
|
<ChevronDownIcon className="size-4 opacity-50" />
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
// fallow-ignore-file unused-export
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import type * as React from "react";
|
import type * as React from "react";
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
// fallow-ignore-file unused-export
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
|
|
@ -14,7 +15,7 @@ import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from "
|
||||||
import { Skeleton } from "~/client/components/ui/skeleton";
|
import { Skeleton } from "~/client/components/ui/skeleton";
|
||||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "~/client/components/ui/tooltip";
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "~/client/components/ui/tooltip";
|
||||||
|
|
||||||
const SIDEBAR_COOKIE_NAME = "sidebar_state";
|
export const SIDEBAR_COOKIE_NAME = "sidebar_state";
|
||||||
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
|
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
|
||||||
const SIDEBAR_WIDTH = "14rem";
|
const SIDEBAR_WIDTH = "14rem";
|
||||||
const SIDEBAR_WIDTH_MOBILE = "18rem";
|
const SIDEBAR_WIDTH_MOBILE = "18rem";
|
||||||
|
|
@ -344,7 +345,7 @@ function SidebarContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
data-slot="sidebar-content"
|
data-slot="sidebar-content"
|
||||||
data-sidebar="content"
|
data-sidebar="content"
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",
|
"flex min-h-0 flex-1 flex-col gap-2 overflow-y-auto overflow-x-hidden group-data-[collapsible=icon]:overflow-hidden",
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
|
|
@ -565,10 +566,16 @@ function SidebarMenuSkeleton({
|
||||||
}: React.ComponentProps<"div"> & {
|
}: React.ComponentProps<"div"> & {
|
||||||
showIcon?: boolean;
|
showIcon?: boolean;
|
||||||
}) {
|
}) {
|
||||||
// Random width between 50 to 90%.
|
const skeletonId = React.useId();
|
||||||
const width = React.useMemo(() => {
|
const width = React.useMemo(() => {
|
||||||
return `${Math.floor(Math.random() * 40) + 50}%`;
|
let hash = 0;
|
||||||
}, []);
|
|
||||||
|
for (const char of skeletonId) {
|
||||||
|
hash = (hash * 31 + char.charCodeAt(0)) % 40;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${hash + 50}%`;
|
||||||
|
}, [skeletonId]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import { useTheme } from "next-themes";
|
import { useTheme } from "~/client/components/theme-provider";
|
||||||
import { Toaster as Sonner, type ToasterProps } from "sonner";
|
import { Toaster as Sonner, type ToasterProps } from "sonner";
|
||||||
|
|
||||||
const Toaster = ({ ...props }: ToasterProps) => {
|
const Toaster = ({ ...props }: ToasterProps) => {
|
||||||
const { theme = "dark" } = useTheme();
|
const { theme } = useTheme();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Sonner
|
<Sonner
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
import * as SwitchPrimitive from "@radix-ui/react-switch";
|
import * as SwitchPrimitive from "@radix-ui/react-switch";
|
||||||
import type * as React from "react";
|
import * as React from "react";
|
||||||
|
|
||||||
|
import { useWebHaptics } from "web-haptics/react";
|
||||||
import { cn } from "~/client/lib/utils";
|
import { cn } from "~/client/lib/utils";
|
||||||
|
|
||||||
function Switch({ className, ...props }: React.ComponentProps<typeof SwitchPrimitive.Root>) {
|
function Switch({ className, ...props }: React.ComponentProps<typeof SwitchPrimitive.Root>) {
|
||||||
|
const trigger = useWebHaptics().trigger;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SwitchPrimitive.Root
|
<SwitchPrimitive.Root
|
||||||
data-slot="switch"
|
data-slot="switch"
|
||||||
|
|
@ -11,6 +14,10 @@ function Switch({ className, ...props }: React.ComponentProps<typeof SwitchPrimi
|
||||||
"cursor-pointer peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
|
"cursor-pointer peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
|
onCheckedChange={(checked) => {
|
||||||
|
void trigger([{ duration: 8 }], { intensity: 0.3 });
|
||||||
|
props.onCheckedChange?.(checked);
|
||||||
|
}}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<SwitchPrimitive.Thumb
|
<SwitchPrimitive.Thumb
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue