Compare commits
121 commits
copilot/up
...
main
| 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 |
340 changed files with 40759 additions and 6089 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
!bun.lock
|
!bun.lock
|
||||||
!package.json
|
!package.json
|
||||||
!.gitignore
|
!.gitignore
|
||||||
|
!bunfig.toml
|
||||||
|
|
||||||
!**/package.json
|
!**/package.json
|
||||||
!**/bun.lock
|
!**/bun.lock
|
||||||
|
|
@ -23,3 +24,4 @@
|
||||||
node_modules/**
|
node_modules/**
|
||||||
dist/**
|
dist/**
|
||||||
.output/**
|
.output/**
|
||||||
|
app/test/integration/artifacts/**
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,6 @@ 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:300
|
BASE_URL=http://*.localhost
|
||||||
TRUST_PROXY=false
|
TRUST_PROXY=false
|
||||||
PORT=3000
|
PORT=3000
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,9 @@ runs:
|
||||||
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
|
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
|
||||||
name: Install Bun
|
name: Install Bun
|
||||||
with:
|
with:
|
||||||
bun-version: "1.3.13"
|
bun-version: "1.3.14"
|
||||||
|
|
||||||
- uses: voidzero-dev/setup-vp@8ecb39174989ce55af90f45cf55b02738599831d # v1
|
- uses: voidzero-dev/setup-vp@ca1c46663915d6c1042ae23bd39ab85718bfb0fa # v1
|
||||||
with:
|
with:
|
||||||
node-version: '24'
|
node-version: '24'
|
||||||
cache: true
|
cache: true
|
||||||
|
|
|
||||||
8
.github/renovate.json
vendored
8
.github/renovate.json
vendored
|
|
@ -2,8 +2,14 @@
|
||||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
"extends": ["config:recommended", "helpers:pinGitHubActionDigests"],
|
"extends": ["config:recommended", "helpers:pinGitHubActionDigests"],
|
||||||
"enabledManagers": ["bun", "github-actions"],
|
"enabledManagers": ["bun", "github-actions"],
|
||||||
"minimumReleaseAge": "1 day",
|
"minimumReleaseAge": "3 days",
|
||||||
|
"rangeStrategy": "bump",
|
||||||
"packageRules": [
|
"packageRules": [
|
||||||
|
{
|
||||||
|
"matchManagers": ["github-actions"],
|
||||||
|
"matchUpdateTypes": ["digest", "pinDigest"],
|
||||||
|
"minimumReleaseAge": null
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"matchManagers": ["bun"],
|
"matchManagers": ["bun"],
|
||||||
"matchUpdateTypes": ["minor", "patch"],
|
"matchUpdateTypes": ["minor", "patch"],
|
||||||
|
|
|
||||||
3
.github/workflows/docs-deploy.yml
vendored
3
.github/workflows/docs-deploy.yml
vendored
|
|
@ -13,6 +13,7 @@ on:
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
deploy:
|
||||||
name: Deploy docs
|
name: Deploy docs
|
||||||
|
if: github.event.repository.default_branch == github.ref_name
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 10
|
timeout-minutes: 10
|
||||||
|
|
||||||
|
|
@ -27,7 +28,7 @@ jobs:
|
||||||
run: bun run build
|
run: bun run build
|
||||||
|
|
||||||
- name: Build and deploy docs
|
- name: Build and deploy docs
|
||||||
uses: cloudflare/wrangler-action@9acf94ace14e7dc412b076f2c5c20b8ce93c79cd # v3
|
uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4
|
||||||
with:
|
with:
|
||||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
|
|
|
||||||
4
.github/workflows/e2e.yml
vendored
4
.github/workflows/e2e.yml
vendored
|
|
@ -26,7 +26,7 @@ jobs:
|
||||||
|
|
||||||
- name: Cache Playwright Browsers
|
- name: Cache Playwright Browsers
|
||||||
id: playwright-cache
|
id: playwright-cache
|
||||||
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # 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 }}
|
||||||
|
|
@ -96,7 +96,7 @@ jobs:
|
||||||
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@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7
|
- 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
|
||||||
10
.github/workflows/nightly.yml
vendored
10
.github/workflows/nightly.yml
vendored
|
|
@ -20,20 +20,20 @@ jobs:
|
||||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||||
|
|
||||||
- name: Log in to Docker Hub
|
- name: Log in to Docker Hub
|
||||||
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4
|
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@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4
|
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@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4
|
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.repository_owner }}
|
username: ${{ github.repository_owner }}
|
||||||
|
|
@ -41,14 +41,14 @@ jobs:
|
||||||
|
|
||||||
- name: Docker meta
|
- name: Docker meta
|
||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6
|
uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 # v6
|
||||||
with:
|
with:
|
||||||
images: ghcr.io/${{ github.repository_owner }}/zerobyte
|
images: ghcr.io/${{ github.repository_owner }}/zerobyte
|
||||||
tags: |
|
tags: |
|
||||||
type=raw,value=nightly
|
type=raw,value=nightly
|
||||||
|
|
||||||
- name: Push images to GitHub Container Registry
|
- name: Push images to GitHub Container Registry
|
||||||
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7
|
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
target: production
|
target: production
|
||||||
|
|
|
||||||
53
.github/workflows/release.yml
vendored
53
.github/workflows/release.yml
vendored
|
|
@ -17,6 +17,7 @@ jobs:
|
||||||
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
|
||||||
|
|
@ -30,16 +31,25 @@ 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
|
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:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
|
@ -53,56 +63,28 @@ jobs:
|
||||||
ref: ${{ github.ref }}
|
ref: ${{ github.ref }}
|
||||||
|
|
||||||
- name: Log in to Docker Hub
|
- name: Log in to Docker Hub
|
||||||
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4
|
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@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4
|
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@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4
|
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@d08e5c354a6adb9ed34480a06d141179aa583294 # v7
|
|
||||||
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@e1165082ffb1fe366ebaf02d8526e7c4989ea9d2 # v7
|
|
||||||
id: scan
|
|
||||||
with:
|
|
||||||
image: local/zerobyte:ci
|
|
||||||
fail-build: false
|
|
||||||
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@c10b8064de6f491fea524254123dbe5e09572f13 # v4
|
|
||||||
with:
|
|
||||||
sarif_file: ${{ steps.scan.outputs.sarif }}
|
|
||||||
|
|
||||||
- name: Docker meta
|
- name: Docker meta
|
||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6
|
uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 # v6
|
||||||
with:
|
with:
|
||||||
images: ghcr.io/${{ github.repository_owner }}/zerobyte
|
images: ghcr.io/${{ github.repository_owner }}/zerobyte
|
||||||
tags: |
|
tags: |
|
||||||
|
|
@ -114,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@d08e5c354a6adb9ed34480a06d141179aa583294 # v7
|
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
target: production
|
target: production
|
||||||
|
|
@ -146,12 +128,11 @@ 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:
|
request-docs-version-update:
|
||||||
uses: ./.github/workflows/request-docs-version-update.yml
|
uses: ./.github/workflows/request-docs-version-update.yml
|
||||||
needs: [publish-release, determine-release-type]
|
needs: [publish-release, determine-release-type]
|
||||||
if: needs.determine-release-type.outputs.release_type == 'release'
|
if: needs.determine-release-type.outputs.release_type == 'release' && needs.determine-release-type.outputs.is_minor_release == 'true'
|
||||||
with:
|
with:
|
||||||
release_tag: ${{ needs.determine-release-type.outputs.tagname }}
|
release_tag: ${{ needs.determine-release-type.outputs.tagname }}
|
||||||
base_branch: ${{ github.event.repository.default_branch }}
|
base_branch: ${{ github.event.repository.default_branch }}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
release_tag:
|
release_tag:
|
||||||
description: Release tag to update documentation examples to
|
description: Minor release tag, for example v0.35.0
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
base_branch:
|
base_branch:
|
||||||
|
|
@ -44,11 +44,18 @@ jobs:
|
||||||
|
|
||||||
const releaseTag = process.env.RELEASE_TAG;
|
const releaseTag = process.env.RELEASE_TAG;
|
||||||
const baseBranch = process.env.BASE_BRANCH;
|
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 { owner, repo } = context.repo;
|
||||||
const targetRepo = `${owner}/${repo}`;
|
const targetRepo = `${owner}/${repo}`;
|
||||||
const releaseUrl = `https://github.com/${targetRepo}/releases/tag/${releaseTag}`;
|
const releaseUrl = `https://github.com/${targetRepo}/releases/tag/${releaseTag}`;
|
||||||
const title = `Update Docker Compose examples to ${releaseTag}`;
|
const title = `Update Docker Compose examples to ${docsVersion}`;
|
||||||
const body = [
|
const bodyLines = [
|
||||||
`A new Zerobyte release was published: ${releaseTag}`,
|
`A new Zerobyte release was published: ${releaseTag}`,
|
||||||
"",
|
"",
|
||||||
`Release: ${releaseUrl}`,
|
`Release: ${releaseUrl}`,
|
||||||
|
|
@ -56,7 +63,7 @@ jobs:
|
||||||
"Please create a pull request that updates Docker Compose documentation examples to use:",
|
"Please create a pull request that updates Docker Compose documentation examples to use:",
|
||||||
"",
|
"",
|
||||||
"```yaml",
|
"```yaml",
|
||||||
`image: ghcr.io/nicotsx/zerobyte:${releaseTag}`,
|
`image: ghcr.io/nicotsx/zerobyte:${docsVersion}`,
|
||||||
"```",
|
"```",
|
||||||
"",
|
"",
|
||||||
"Scope:",
|
"Scope:",
|
||||||
|
|
@ -70,13 +77,32 @@ jobs:
|
||||||
"",
|
"",
|
||||||
"- Search for stale `ghcr.io/nicotsx/zerobyte:v...` references in `README.md` and `apps/docs/`.",
|
"- 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.",
|
"- Run any formatting or documentation checks that are appropriate for the touched files.",
|
||||||
].join("\n");
|
];
|
||||||
|
|
||||||
await github.request("POST /repos/{owner}/{repo}/issues", {
|
const issue = await github.rest.issues.create({
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
title,
|
title,
|
||||||
body,
|
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]"],
|
assignees: ["copilot-swe-agent[bot]"],
|
||||||
agent_assignment: {
|
agent_assignment: {
|
||||||
target_repo: targetRepo,
|
target_repo: targetRepo,
|
||||||
|
|
|
||||||
2
.github/workflows/scorecard.yml
vendored
2
.github/workflows/scorecard.yml
vendored
|
|
@ -36,6 +36,6 @@ jobs:
|
||||||
retention-days: 5
|
retention-days: 5
|
||||||
|
|
||||||
- name: Upload to code-scanning
|
- name: Upload to code-scanning
|
||||||
uses: github/codeql-action/upload-sarif@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 # v4
|
uses: github/codeql-action/upload-sarif@9e0d7b8d25671d64c341c19c0152d693099fb5ba # v4
|
||||||
with:
|
with:
|
||||||
sarif_file: results.sarif
|
sarif_file: results.sarif
|
||||||
|
|
|
||||||
5
.gitignore
vendored
5
.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
|
||||||
|
|
@ -34,8 +34,11 @@ node_modules/
|
||||||
|
|
||||||
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
|
||||||
|
|
|
||||||
17
AGENTS.md
17
AGENTS.md
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
- 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 is running at http://localhost:3000. Username is `admin` and password is `password`
|
- 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
|
- 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`
|
- If you need to run a specific restic command on a repository, you can open and use the dev panel with `Meta+Shift+D`
|
||||||
|
|
||||||
|
|
@ -10,6 +10,21 @@
|
||||||
|
|
||||||
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
|
||||||
|
|
|
||||||
17
Dockerfile
17
Dockerfile
|
|
@ -1,8 +1,8 @@
|
||||||
FROM oven/bun:1.3.13-alpine@sha256:4de475389889577f346c636f956b42a5c31501b654664e9ae5726f94d7bb5349 AS base
|
FROM oven/bun:1.3.14-alpine@sha256:5acc90a93e91ff07bf72aa90a7c9f0fa189765aec90b47bdbf2152d2196383c0 AS base
|
||||||
|
|
||||||
ARG RESTIC_VERSION="0.18.1"
|
ARG RESTIC_VERSION="0.18.1"
|
||||||
ARG RCLONE_VERSION="1.73.5"
|
ARG RCLONE_VERSION="1.74.2"
|
||||||
ARG SHOUTRRR_VERSION="0.14.3"
|
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} \
|
||||||
|
|
@ -10,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 tzdata
|
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", "--"]
|
||||||
|
|
||||||
|
|
@ -44,6 +44,15 @@ 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
|
||||||
# ------------------------------
|
# ------------------------------
|
||||||
|
|
|
||||||
126
README.md
126
README.md
|
|
@ -20,13 +20,13 @@
|
||||||
[](https://discord.gg/XjgVyXrcEH)
|
[](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. Please open issues for bugs 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.
|
||||||
|
|
||||||
|
|
@ -38,10 +38,10 @@ It contains up-to-date setup guides, configuration reference, and usage document
|
||||||
|
|
||||||
### 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
|
||||||
|
|
||||||
|
|
@ -50,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.35
|
image: ghcr.io/nicotsx/zerobyte:v0.38
|
||||||
container_name: zerobyte
|
container_name: zerobyte
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
cap_add:
|
cap_add:
|
||||||
|
|
@ -69,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:
|
||||||
|
|
@ -97,24 +97,46 @@ 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) |
|
| `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/Zurich`). **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` |
|
| `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) |
|
||||||
| `LOG_LEVEL` | Logging verbosity. Options: `debug`, `info`, `warn`, `error`. | `info` |
|
| `WEBHOOK_ALLOWED_ORIGINS` | Comma-separated list of HTTP origins allowed for backup webhooks and outbound HTTP notification destinations. | (none) |
|
||||||
| `SERVER_IDLE_TIMEOUT` | Idle timeout for the server in seconds. | `60` |
|
| `WEBHOOK_TIMEOUT` | Timeout for backup webhook requests 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` |
|
| `LOG_LEVEL` | Logging verbosity. Options: `debug`, `info`, `warn`, `error`. | `info` |
|
||||||
| `PROVISIONING_PATH` | Path to a JSON file with operator-managed repositories and volumes to sync at startup. | (none) |
|
| `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) |
|
||||||
|
|
||||||
### Provisioned Resources
|
### Webhook and notification network policy
|
||||||
|
|
||||||
|
Backup webhooks and outbound notification destinations that can target arbitrary network hosts are restricted by `WEBHOOK_ALLOWED_ORIGINS`.
|
||||||
|
|
||||||
|
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`.
|
||||||
|
|
||||||
|
This policy applies to:
|
||||||
|
|
||||||
|
- 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
|
||||||
|
|
||||||
|
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.
|
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.
|
||||||
|
|
||||||
|
|
@ -127,14 +149,14 @@ The complete provisioning documentation is available at [zerobyte.app/docs/guide
|
||||||
|
|
||||||
See `examples/provisioned-resources/README.md` for a full example.
|
See `examples/provisioned-resources/README.md` for a full example.
|
||||||
|
|
||||||
### Simplified setup (No remote mounts)
|
### 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`:
|
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.35
|
image: ghcr.io/nicotsx/zerobyte:v0.38
|
||||||
container_name: zerobyte
|
container_name: zerobyte
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
|
|
@ -152,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`.
|
||||||
|
|
@ -168,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.35
|
image: ghcr.io/nicotsx/zerobyte:v0.38
|
||||||
container_name: zerobyte
|
container_name: zerobyte
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
cap_add:
|
cap_add:
|
||||||
|
|
@ -201,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.
|
||||||
|
|
||||||
|
|
@ -248,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.35
|
image: ghcr.io/nicotsx/zerobyte:v0.38
|
||||||
container_name: zerobyte
|
container_name: zerobyte
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
cap_add:
|
cap_add:
|
||||||
|
|
@ -302,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
|
||||||
|
|
||||||
- **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.
|
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.
|
||||||
- **Domain / HTTPS access**: Set `BASE_URL=https://zerobyte.example.com`. Cookies will automatically use `Secure: true` for protected sessions.
|
|
||||||
|
|
||||||
### Reverse Proxy Setup
|
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.
|
||||||
|
- **Domain/HTTPS access**: Set `BASE_URL=https://zerobyte.example.com`. Cookies will automatically use `Secure: true` for protected sessions.
|
||||||
|
|
||||||
|
### 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.):
|
||||||
|
|
||||||
|
|
@ -327,7 +355,7 @@ 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
|
||||||
|
|
@ -338,7 +366,7 @@ If you're running Zerobyte behind a reverse proxy (Nginx, Traefik, Caddy, etc.):
|
||||||
|
|
||||||
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:
|
||||||
|
|
||||||
|
|
@ -376,10 +404,10 @@ 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.
|
||||||
|
|
|
||||||
|
|
@ -49,10 +49,7 @@ export const createClient = (config: Config = {}): Client => {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (opts.security) {
|
if (opts.security) {
|
||||||
await setAuthParams({
|
await setAuthParams(opts);
|
||||||
...opts,
|
|
||||||
security: opts.security,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.requestValidator) {
|
if (opts.requestValidator) {
|
||||||
|
|
@ -76,171 +73,154 @@ export const createClient = (config: Config = {}): Client => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const request: Client['request'] = async (options) => {
|
const request: Client['request'] = async (options) => {
|
||||||
const { opts, url } = await beforeRequest(options);
|
const throwOnError = options.throwOnError ?? _config.throwOnError;
|
||||||
const requestInit: ReqInit = {
|
const responseStyle = options.responseStyle ?? _config.responseStyle;
|
||||||
redirect: 'follow',
|
|
||||||
...opts,
|
|
||||||
body: getValidRequestBody(opts),
|
|
||||||
};
|
|
||||||
|
|
||||||
let request = new Request(url, requestInit);
|
let request: Request | undefined;
|
||||||
|
let response: Response | undefined;
|
||||||
for (const fn of interceptors.request.fns) {
|
|
||||||
if (fn) {
|
|
||||||
request = await fn(request, opts);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// fetch must be assigned here, otherwise it would throw the error:
|
|
||||||
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
|
||||||
const _fetch = opts.fetch!;
|
|
||||||
let response: Response;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
response = await _fetch(request);
|
const { opts, url } = await beforeRequest(options);
|
||||||
} catch (error) {
|
const requestInit: ReqInit = {
|
||||||
// Handle fetch exceptions (AbortError, network errors, etc.)
|
redirect: 'follow',
|
||||||
let finalError = error;
|
...opts,
|
||||||
|
body: getValidRequestBody(opts),
|
||||||
|
};
|
||||||
|
|
||||||
for (const fn of interceptors.error.fns) {
|
request = new Request(url, requestInit);
|
||||||
|
|
||||||
|
for (const fn of interceptors.request.fns) {
|
||||||
if (fn) {
|
if (fn) {
|
||||||
finalError = (await fn(error, undefined as any, request, opts)) as unknown;
|
request = await fn(request, opts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
finalError = finalError || ({} as unknown);
|
// fetch must be assigned here, otherwise it would throw the error:
|
||||||
|
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
||||||
|
const _fetch = opts.fetch!;
|
||||||
|
|
||||||
if (opts.throwOnError) {
|
response = await _fetch(request);
|
||||||
throw finalError;
|
|
||||||
|
for (const fn of interceptors.response.fns) {
|
||||||
|
if (fn) {
|
||||||
|
response = await fn(response, request, opts);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return error response
|
const result = {
|
||||||
return opts.responseStyle === 'data'
|
request,
|
||||||
? undefined
|
response,
|
||||||
: {
|
};
|
||||||
error: finalError,
|
|
||||||
request,
|
|
||||||
response: undefined as any,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const fn of interceptors.response.fns) {
|
if (response.ok) {
|
||||||
if (fn) {
|
const parseAs =
|
||||||
response = await fn(response, request, opts);
|
(opts.parseAs === 'auto'
|
||||||
}
|
? getParseAs(response.headers.get('Content-Type'))
|
||||||
}
|
: opts.parseAs) ?? 'json';
|
||||||
|
|
||||||
const result = {
|
if (response.status === 204 || response.headers.get('Content-Length') === '0') {
|
||||||
request,
|
let emptyData: any;
|
||||||
response,
|
switch (parseAs) {
|
||||||
};
|
case 'arrayBuffer':
|
||||||
|
case 'blob':
|
||||||
|
case 'text':
|
||||||
|
emptyData = await response[parseAs]();
|
||||||
|
break;
|
||||||
|
case 'formData':
|
||||||
|
emptyData = new FormData();
|
||||||
|
break;
|
||||||
|
case 'stream':
|
||||||
|
emptyData = response.body;
|
||||||
|
break;
|
||||||
|
case 'json':
|
||||||
|
default:
|
||||||
|
emptyData = {};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return opts.responseStyle === 'data'
|
||||||
|
? emptyData
|
||||||
|
: {
|
||||||
|
data: emptyData,
|
||||||
|
...result,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (response.ok) {
|
let data: any;
|
||||||
const parseAs =
|
|
||||||
(opts.parseAs === 'auto'
|
|
||||||
? getParseAs(response.headers.get('Content-Type'))
|
|
||||||
: opts.parseAs) ?? 'json';
|
|
||||||
|
|
||||||
if (response.status === 204 || response.headers.get('Content-Length') === '0') {
|
|
||||||
let emptyData: any;
|
|
||||||
switch (parseAs) {
|
switch (parseAs) {
|
||||||
case 'arrayBuffer':
|
case 'arrayBuffer':
|
||||||
case 'blob':
|
case 'blob':
|
||||||
case 'text':
|
|
||||||
emptyData = await response[parseAs]();
|
|
||||||
break;
|
|
||||||
case 'formData':
|
case 'formData':
|
||||||
emptyData = new FormData();
|
case 'text':
|
||||||
|
data = await response[parseAs]();
|
||||||
break;
|
break;
|
||||||
|
case 'json': {
|
||||||
|
// Some servers return 200 with no Content-Length and empty body.
|
||||||
|
// response.json() would throw; read as text and parse if non-empty.
|
||||||
|
const text = await response.text();
|
||||||
|
data = text ? JSON.parse(text) : {};
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 'stream':
|
case 'stream':
|
||||||
emptyData = response.body;
|
return opts.responseStyle === 'data'
|
||||||
break;
|
? response.body
|
||||||
case 'json':
|
: {
|
||||||
default:
|
data: response.body,
|
||||||
emptyData = {};
|
...result,
|
||||||
break;
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (parseAs === 'json') {
|
||||||
|
if (opts.responseValidator) {
|
||||||
|
await opts.responseValidator(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opts.responseTransformer) {
|
||||||
|
data = await opts.responseTransformer(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return opts.responseStyle === 'data'
|
return opts.responseStyle === 'data'
|
||||||
? emptyData
|
? data
|
||||||
: {
|
: {
|
||||||
data: emptyData,
|
data,
|
||||||
...result,
|
...result,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let data: any;
|
const textError = await response.text();
|
||||||
switch (parseAs) {
|
let jsonError: unknown;
|
||||||
case 'arrayBuffer':
|
|
||||||
case 'blob':
|
try {
|
||||||
case 'formData':
|
jsonError = JSON.parse(textError);
|
||||||
case 'text':
|
} catch {
|
||||||
data = await response[parseAs]();
|
// noop
|
||||||
break;
|
|
||||||
case 'json': {
|
|
||||||
// Some servers return 200 with no Content-Length and empty body.
|
|
||||||
// response.json() would throw; read as text and parse if non-empty.
|
|
||||||
const text = await response.text();
|
|
||||||
data = text ? JSON.parse(text) : {};
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'stream':
|
|
||||||
return opts.responseStyle === 'data'
|
|
||||||
? response.body
|
|
||||||
: {
|
|
||||||
data: response.body,
|
|
||||||
...result,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseAs === 'json') {
|
throw jsonError ?? textError;
|
||||||
if (opts.responseValidator) {
|
} catch (error) {
|
||||||
await opts.responseValidator(data);
|
let finalError = error;
|
||||||
}
|
|
||||||
|
|
||||||
if (opts.responseTransformer) {
|
for (const fn of interceptors.error.fns) {
|
||||||
data = await opts.responseTransformer(data);
|
if (fn) {
|
||||||
|
finalError = await fn(finalError, response, request, options as ResolvedRequestOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return opts.responseStyle === 'data'
|
finalError = finalError || {};
|
||||||
? data
|
|
||||||
|
if (throwOnError) {
|
||||||
|
throw finalError;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: we probably want to return error and improve types
|
||||||
|
return responseStyle === 'data'
|
||||||
|
? undefined
|
||||||
: {
|
: {
|
||||||
data,
|
error: finalError,
|
||||||
...result,
|
request,
|
||||||
|
response,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const textError = await response.text();
|
|
||||||
let jsonError: unknown;
|
|
||||||
|
|
||||||
try {
|
|
||||||
jsonError = JSON.parse(textError);
|
|
||||||
} catch {
|
|
||||||
// noop
|
|
||||||
}
|
|
||||||
|
|
||||||
const error = jsonError ?? textError;
|
|
||||||
let finalError = error;
|
|
||||||
|
|
||||||
for (const fn of interceptors.error.fns) {
|
|
||||||
if (fn) {
|
|
||||||
finalError = (await fn(error, response, request, opts)) as string;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
finalError = finalError || ({} as string);
|
|
||||||
|
|
||||||
if (opts.throwOnError) {
|
|
||||||
throw finalError;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: we probably want to return error and improve types
|
|
||||||
return opts.responseStyle === 'data'
|
|
||||||
? undefined
|
|
||||||
: {
|
|
||||||
error: finalError,
|
|
||||||
...result,
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const makeMethodFn = (method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
|
const makeMethodFn = (method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
|
||||||
|
|
@ -251,7 +231,6 @@ export const createClient = (config: Config = {}): Client => {
|
||||||
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);
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,7 @@ export interface ResolvedRequestOptions<
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,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;
|
||||||
}
|
}
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -119,14 +119,12 @@ const checkForExistence = (
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
@ -155,7 +153,7 @@ export const setAuthParams = async ({
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export const buildUrl: Client['buildUrl'] = (options) =>
|
export const buildUrl: Client['buildUrl'] = (options) =>
|
||||||
getUrl({
|
getUrl({
|
||||||
|
|
@ -219,8 +217,10 @@ export const mergeHeaders = (
|
||||||
|
|
||||||
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>;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -337,14 +337,7 @@ export type ListVolumesResponses = {
|
||||||
200: Array<{
|
200: Array<{
|
||||||
id: number;
|
id: number;
|
||||||
shortId: string;
|
shortId: string;
|
||||||
provisioningId: string | null;
|
|
||||||
name: string;
|
name: string;
|
||||||
type: 'nfs' | 'smb' | 'directory' | 'webdav' | 'rclone' | 'sftp';
|
|
||||||
status: 'mounted' | 'unmounted' | 'error';
|
|
||||||
lastError: string | null;
|
|
||||||
createdAt: number;
|
|
||||||
updatedAt: number;
|
|
||||||
lastHealthCheck: number;
|
|
||||||
config: {
|
config: {
|
||||||
backend: 'nfs';
|
backend: 'nfs';
|
||||||
server: string;
|
server: string;
|
||||||
|
|
@ -359,6 +352,7 @@ export type ListVolumesResponses = {
|
||||||
username?: string;
|
username?: string;
|
||||||
password?: string;
|
password?: string;
|
||||||
guest?: boolean;
|
guest?: boolean;
|
||||||
|
mapToContainerUidGid?: boolean;
|
||||||
vers?: '1.0' | '2.0' | '2.1' | '3.0' | 'auto';
|
vers?: '1.0' | '2.0' | '2.1' | '3.0' | 'auto';
|
||||||
domain?: string;
|
domain?: string;
|
||||||
port?: string | number;
|
port?: string | number;
|
||||||
|
|
@ -392,7 +386,15 @@ export type ListVolumesResponses = {
|
||||||
readOnly?: boolean;
|
readOnly?: boolean;
|
||||||
skipHostKeyCheck?: boolean;
|
skipHostKeyCheck?: boolean;
|
||||||
knownHosts?: string;
|
knownHosts?: string;
|
||||||
|
allowLegacySshRsa?: boolean;
|
||||||
};
|
};
|
||||||
|
createdAt: number;
|
||||||
|
updatedAt: number;
|
||||||
|
lastHealthCheck: number;
|
||||||
|
type: 'nfs' | 'smb' | 'directory' | 'webdav' | 'rclone' | 'sftp';
|
||||||
|
status: 'mounted' | 'unmounted' | 'error';
|
||||||
|
lastError: string | null;
|
||||||
|
provisioningId?: string | null;
|
||||||
autoRemount: boolean;
|
autoRemount: boolean;
|
||||||
}>;
|
}>;
|
||||||
};
|
};
|
||||||
|
|
@ -416,6 +418,7 @@ export type CreateVolumeData = {
|
||||||
username?: string;
|
username?: string;
|
||||||
password?: string;
|
password?: string;
|
||||||
guest?: boolean;
|
guest?: boolean;
|
||||||
|
mapToContainerUidGid?: boolean;
|
||||||
vers?: '1.0' | '2.0' | '2.1' | '3.0' | 'auto';
|
vers?: '1.0' | '2.0' | '2.1' | '3.0' | 'auto';
|
||||||
domain?: string;
|
domain?: string;
|
||||||
port?: string | number;
|
port?: string | number;
|
||||||
|
|
@ -449,6 +452,7 @@ export type CreateVolumeData = {
|
||||||
readOnly?: boolean;
|
readOnly?: boolean;
|
||||||
skipHostKeyCheck?: boolean;
|
skipHostKeyCheck?: boolean;
|
||||||
knownHosts?: string;
|
knownHosts?: string;
|
||||||
|
allowLegacySshRsa?: boolean;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
path?: never;
|
path?: never;
|
||||||
|
|
@ -463,14 +467,7 @@ export type CreateVolumeResponses = {
|
||||||
201: {
|
201: {
|
||||||
id: number;
|
id: number;
|
||||||
shortId: string;
|
shortId: string;
|
||||||
provisioningId: string | null;
|
|
||||||
name: string;
|
name: string;
|
||||||
type: 'nfs' | 'smb' | 'directory' | 'webdav' | 'rclone' | 'sftp';
|
|
||||||
status: 'mounted' | 'unmounted' | 'error';
|
|
||||||
lastError: string | null;
|
|
||||||
createdAt: number;
|
|
||||||
updatedAt: number;
|
|
||||||
lastHealthCheck: number;
|
|
||||||
config: {
|
config: {
|
||||||
backend: 'nfs';
|
backend: 'nfs';
|
||||||
server: string;
|
server: string;
|
||||||
|
|
@ -485,6 +482,7 @@ export type CreateVolumeResponses = {
|
||||||
username?: string;
|
username?: string;
|
||||||
password?: string;
|
password?: string;
|
||||||
guest?: boolean;
|
guest?: boolean;
|
||||||
|
mapToContainerUidGid?: boolean;
|
||||||
vers?: '1.0' | '2.0' | '2.1' | '3.0' | 'auto';
|
vers?: '1.0' | '2.0' | '2.1' | '3.0' | 'auto';
|
||||||
domain?: string;
|
domain?: string;
|
||||||
port?: string | number;
|
port?: string | number;
|
||||||
|
|
@ -518,7 +516,15 @@ export type CreateVolumeResponses = {
|
||||||
readOnly?: boolean;
|
readOnly?: boolean;
|
||||||
skipHostKeyCheck?: boolean;
|
skipHostKeyCheck?: boolean;
|
||||||
knownHosts?: string;
|
knownHosts?: string;
|
||||||
|
allowLegacySshRsa?: boolean;
|
||||||
};
|
};
|
||||||
|
createdAt: number;
|
||||||
|
updatedAt: number;
|
||||||
|
lastHealthCheck: number;
|
||||||
|
type: 'nfs' | 'smb' | 'directory' | 'webdav' | 'rclone' | 'sftp';
|
||||||
|
status: 'mounted' | 'unmounted' | 'error';
|
||||||
|
lastError: string | null;
|
||||||
|
provisioningId?: string | null;
|
||||||
autoRemount: boolean;
|
autoRemount: boolean;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -541,6 +547,7 @@ export type TestConnectionData = {
|
||||||
username?: string;
|
username?: string;
|
||||||
password?: string;
|
password?: string;
|
||||||
guest?: boolean;
|
guest?: boolean;
|
||||||
|
mapToContainerUidGid?: boolean;
|
||||||
vers?: '1.0' | '2.0' | '2.1' | '3.0' | 'auto';
|
vers?: '1.0' | '2.0' | '2.1' | '3.0' | 'auto';
|
||||||
domain?: string;
|
domain?: string;
|
||||||
port?: string | number;
|
port?: string | number;
|
||||||
|
|
@ -574,6 +581,7 @@ export type TestConnectionData = {
|
||||||
readOnly?: boolean;
|
readOnly?: boolean;
|
||||||
skipHostKeyCheck?: boolean;
|
skipHostKeyCheck?: boolean;
|
||||||
knownHosts?: string;
|
knownHosts?: string;
|
||||||
|
allowLegacySshRsa?: boolean;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
path?: never;
|
path?: never;
|
||||||
|
|
@ -637,14 +645,7 @@ export type GetVolumeResponses = {
|
||||||
volume: {
|
volume: {
|
||||||
id: number;
|
id: number;
|
||||||
shortId: string;
|
shortId: string;
|
||||||
provisioningId: string | null;
|
|
||||||
name: string;
|
name: string;
|
||||||
type: 'nfs' | 'smb' | 'directory' | 'webdav' | 'rclone' | 'sftp';
|
|
||||||
status: 'mounted' | 'unmounted' | 'error';
|
|
||||||
lastError: string | null;
|
|
||||||
createdAt: number;
|
|
||||||
updatedAt: number;
|
|
||||||
lastHealthCheck: number;
|
|
||||||
config: {
|
config: {
|
||||||
backend: 'nfs';
|
backend: 'nfs';
|
||||||
server: string;
|
server: string;
|
||||||
|
|
@ -659,6 +660,7 @@ export type GetVolumeResponses = {
|
||||||
username?: string;
|
username?: string;
|
||||||
password?: string;
|
password?: string;
|
||||||
guest?: boolean;
|
guest?: boolean;
|
||||||
|
mapToContainerUidGid?: boolean;
|
||||||
vers?: '1.0' | '2.0' | '2.1' | '3.0' | 'auto';
|
vers?: '1.0' | '2.0' | '2.1' | '3.0' | 'auto';
|
||||||
domain?: string;
|
domain?: string;
|
||||||
port?: string | number;
|
port?: string | number;
|
||||||
|
|
@ -692,13 +694,21 @@ export type GetVolumeResponses = {
|
||||||
readOnly?: boolean;
|
readOnly?: boolean;
|
||||||
skipHostKeyCheck?: boolean;
|
skipHostKeyCheck?: boolean;
|
||||||
knownHosts?: string;
|
knownHosts?: string;
|
||||||
|
allowLegacySshRsa?: boolean;
|
||||||
};
|
};
|
||||||
|
createdAt: number;
|
||||||
|
updatedAt: number;
|
||||||
|
lastHealthCheck: number;
|
||||||
|
type: 'nfs' | 'smb' | 'directory' | 'webdav' | 'rclone' | 'sftp';
|
||||||
|
status: 'mounted' | 'unmounted' | 'error';
|
||||||
|
lastError: string | null;
|
||||||
|
provisioningId?: string | null;
|
||||||
autoRemount: boolean;
|
autoRemount: boolean;
|
||||||
};
|
};
|
||||||
statfs: {
|
statfs: {
|
||||||
total: number;
|
total?: number;
|
||||||
used: number;
|
used?: number;
|
||||||
free: number;
|
free?: number;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -723,6 +733,7 @@ export type UpdateVolumeData = {
|
||||||
username?: string;
|
username?: string;
|
||||||
password?: string;
|
password?: string;
|
||||||
guest?: boolean;
|
guest?: boolean;
|
||||||
|
mapToContainerUidGid?: boolean;
|
||||||
vers?: '1.0' | '2.0' | '2.1' | '3.0' | 'auto';
|
vers?: '1.0' | '2.0' | '2.1' | '3.0' | 'auto';
|
||||||
domain?: string;
|
domain?: string;
|
||||||
port?: string | number;
|
port?: string | number;
|
||||||
|
|
@ -756,6 +767,7 @@ export type UpdateVolumeData = {
|
||||||
readOnly?: boolean;
|
readOnly?: boolean;
|
||||||
skipHostKeyCheck?: boolean;
|
skipHostKeyCheck?: boolean;
|
||||||
knownHosts?: string;
|
knownHosts?: string;
|
||||||
|
allowLegacySshRsa?: boolean;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
path: {
|
path: {
|
||||||
|
|
@ -779,14 +791,7 @@ export type UpdateVolumeResponses = {
|
||||||
200: {
|
200: {
|
||||||
id: number;
|
id: number;
|
||||||
shortId: string;
|
shortId: string;
|
||||||
provisioningId: string | null;
|
|
||||||
name: string;
|
name: string;
|
||||||
type: 'nfs' | 'smb' | 'directory' | 'webdav' | 'rclone' | 'sftp';
|
|
||||||
status: 'mounted' | 'unmounted' | 'error';
|
|
||||||
lastError: string | null;
|
|
||||||
createdAt: number;
|
|
||||||
updatedAt: number;
|
|
||||||
lastHealthCheck: number;
|
|
||||||
config: {
|
config: {
|
||||||
backend: 'nfs';
|
backend: 'nfs';
|
||||||
server: string;
|
server: string;
|
||||||
|
|
@ -801,6 +806,7 @@ export type UpdateVolumeResponses = {
|
||||||
username?: string;
|
username?: string;
|
||||||
password?: string;
|
password?: string;
|
||||||
guest?: boolean;
|
guest?: boolean;
|
||||||
|
mapToContainerUidGid?: boolean;
|
||||||
vers?: '1.0' | '2.0' | '2.1' | '3.0' | 'auto';
|
vers?: '1.0' | '2.0' | '2.1' | '3.0' | 'auto';
|
||||||
domain?: string;
|
domain?: string;
|
||||||
port?: string | number;
|
port?: string | number;
|
||||||
|
|
@ -834,7 +840,15 @@ export type UpdateVolumeResponses = {
|
||||||
readOnly?: boolean;
|
readOnly?: boolean;
|
||||||
skipHostKeyCheck?: boolean;
|
skipHostKeyCheck?: boolean;
|
||||||
knownHosts?: string;
|
knownHosts?: string;
|
||||||
|
allowLegacySshRsa?: boolean;
|
||||||
};
|
};
|
||||||
|
createdAt: number;
|
||||||
|
updatedAt: number;
|
||||||
|
lastHealthCheck: number;
|
||||||
|
type: 'nfs' | 'smb' | 'directory' | 'webdav' | 'rclone' | 'sftp';
|
||||||
|
status: 'mounted' | 'unmounted' | 'error';
|
||||||
|
lastError: string | null;
|
||||||
|
provisioningId?: string | null;
|
||||||
autoRemount: boolean;
|
autoRemount: boolean;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -855,8 +869,8 @@ export type MountVolumeResponses = {
|
||||||
* Volume mounted successfully
|
* Volume mounted successfully
|
||||||
*/
|
*/
|
||||||
200: {
|
200: {
|
||||||
error?: string;
|
|
||||||
status: 'mounted' | 'unmounted' | 'error';
|
status: 'mounted' | 'unmounted' | 'error';
|
||||||
|
error?: string;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -876,8 +890,8 @@ export type UnmountVolumeResponses = {
|
||||||
* Volume unmounted successfully
|
* Volume unmounted successfully
|
||||||
*/
|
*/
|
||||||
200: {
|
200: {
|
||||||
error?: string;
|
|
||||||
status: 'mounted' | 'unmounted' | 'error';
|
status: 'mounted' | 'unmounted' | 'error';
|
||||||
|
error?: string;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -904,8 +918,8 @@ export type HealthCheckVolumeResponses = {
|
||||||
* Volume health check result
|
* Volume health check result
|
||||||
*/
|
*/
|
||||||
200: {
|
200: {
|
||||||
error?: string;
|
|
||||||
status: 'mounted' | 'unmounted' | 'error';
|
status: 'mounted' | 'unmounted' | 'error';
|
||||||
|
error?: string;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -932,7 +946,7 @@ export type ListFilesResponses = {
|
||||||
files: Array<{
|
files: Array<{
|
||||||
name: string;
|
name: string;
|
||||||
path: string;
|
path: string;
|
||||||
type: 'file' | 'directory';
|
type: 'directory' | 'file';
|
||||||
size?: number;
|
size?: number;
|
||||||
modifiedAt?: number;
|
modifiedAt?: number;
|
||||||
}>;
|
}>;
|
||||||
|
|
@ -966,8 +980,8 @@ export type BrowseFilesystemResponses = {
|
||||||
directories: Array<{
|
directories: Array<{
|
||||||
name: string;
|
name: string;
|
||||||
path: string;
|
path: string;
|
||||||
type: 'file' | 'directory';
|
type: 'directory';
|
||||||
size?: number;
|
size?: unknown;
|
||||||
modifiedAt?: number;
|
modifiedAt?: number;
|
||||||
}>;
|
}>;
|
||||||
path: string;
|
path: string;
|
||||||
|
|
@ -1136,6 +1150,7 @@ export type ListRepositoriesResponses = {
|
||||||
privateKey: string;
|
privateKey: string;
|
||||||
skipHostKeyCheck?: boolean;
|
skipHostKeyCheck?: boolean;
|
||||||
knownHosts?: string;
|
knownHosts?: string;
|
||||||
|
allowLegacySshRsa?: boolean;
|
||||||
isExistingRepository?: boolean;
|
isExistingRepository?: boolean;
|
||||||
customPassword?: string;
|
customPassword?: string;
|
||||||
cacert?: string;
|
cacert?: string;
|
||||||
|
|
@ -1319,6 +1334,7 @@ export type CreateRepositoryData = {
|
||||||
privateKey: string;
|
privateKey: string;
|
||||||
skipHostKeyCheck?: boolean;
|
skipHostKeyCheck?: boolean;
|
||||||
knownHosts?: string;
|
knownHosts?: string;
|
||||||
|
allowLegacySshRsa?: boolean;
|
||||||
isExistingRepository?: boolean;
|
isExistingRepository?: boolean;
|
||||||
customPassword?: string;
|
customPassword?: string;
|
||||||
cacert?: string;
|
cacert?: string;
|
||||||
|
|
@ -1557,6 +1573,7 @@ export type GetRepositoryResponses = {
|
||||||
privateKey: string;
|
privateKey: string;
|
||||||
skipHostKeyCheck?: boolean;
|
skipHostKeyCheck?: boolean;
|
||||||
knownHosts?: string;
|
knownHosts?: string;
|
||||||
|
allowLegacySshRsa?: boolean;
|
||||||
isExistingRepository?: boolean;
|
isExistingRepository?: boolean;
|
||||||
customPassword?: string;
|
customPassword?: string;
|
||||||
cacert?: string;
|
cacert?: string;
|
||||||
|
|
@ -1740,6 +1757,7 @@ export type UpdateRepositoryData = {
|
||||||
privateKey: string;
|
privateKey: string;
|
||||||
skipHostKeyCheck?: boolean;
|
skipHostKeyCheck?: boolean;
|
||||||
knownHosts?: string;
|
knownHosts?: string;
|
||||||
|
allowLegacySshRsa?: boolean;
|
||||||
isExistingRepository?: boolean;
|
isExistingRepository?: boolean;
|
||||||
customPassword?: string;
|
customPassword?: string;
|
||||||
cacert?: string;
|
cacert?: string;
|
||||||
|
|
@ -1931,6 +1949,7 @@ export type UpdateRepositoryResponses = {
|
||||||
privateKey: string;
|
privateKey: string;
|
||||||
skipHostKeyCheck?: boolean;
|
skipHostKeyCheck?: boolean;
|
||||||
knownHosts?: string;
|
knownHosts?: string;
|
||||||
|
allowLegacySshRsa?: boolean;
|
||||||
isExistingRepository?: boolean;
|
isExistingRepository?: boolean;
|
||||||
customPassword?: string;
|
customPassword?: string;
|
||||||
cacert?: string;
|
cacert?: string;
|
||||||
|
|
@ -2248,6 +2267,7 @@ export type RestoreSnapshotData = {
|
||||||
excludeXattr?: Array<string>;
|
excludeXattr?: Array<string>;
|
||||||
delete?: boolean;
|
delete?: boolean;
|
||||||
targetPath?: string;
|
targetPath?: string;
|
||||||
|
targetAgentId?: string;
|
||||||
overwrite?: 'always' | 'if-changed' | 'if-newer' | 'never';
|
overwrite?: 'always' | 'if-changed' | 'if-newer' | 'never';
|
||||||
};
|
};
|
||||||
path: {
|
path: {
|
||||||
|
|
@ -2259,13 +2279,11 @@ export type RestoreSnapshotData = {
|
||||||
|
|
||||||
export type RestoreSnapshotResponses = {
|
export type RestoreSnapshotResponses = {
|
||||||
/**
|
/**
|
||||||
* Snapshot restored successfully
|
* Snapshot restore started
|
||||||
*/
|
*/
|
||||||
200: {
|
202: {
|
||||||
success: boolean;
|
restoreId: string;
|
||||||
message: string;
|
status: 'started';
|
||||||
filesRestored: number;
|
|
||||||
filesSkipped: number;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -2434,6 +2452,18 @@ export type ListBackupSchedulesResponses = {
|
||||||
includePatterns: Array<string> | null;
|
includePatterns: Array<string> | null;
|
||||||
oneFileSystem: boolean;
|
oneFileSystem: boolean;
|
||||||
customResticParams: Array<string> | null;
|
customResticParams: Array<string> | null;
|
||||||
|
backupWebhooks: {
|
||||||
|
pre: {
|
||||||
|
url: string;
|
||||||
|
headers?: Array<string>;
|
||||||
|
body?: string;
|
||||||
|
} | null;
|
||||||
|
post: {
|
||||||
|
url: string;
|
||||||
|
headers?: Array<string>;
|
||||||
|
body?: string;
|
||||||
|
} | null;
|
||||||
|
} | null;
|
||||||
maxRetries: number;
|
maxRetries: number;
|
||||||
retryDelay: number;
|
retryDelay: number;
|
||||||
lastBackupAt: number | null;
|
lastBackupAt: number | null;
|
||||||
|
|
@ -2445,14 +2475,7 @@ export type ListBackupSchedulesResponses = {
|
||||||
volume: {
|
volume: {
|
||||||
id: number;
|
id: number;
|
||||||
shortId: string;
|
shortId: string;
|
||||||
provisioningId: string | null;
|
|
||||||
name: string;
|
name: string;
|
||||||
type: 'nfs' | 'smb' | 'directory' | 'webdav' | 'rclone' | 'sftp';
|
|
||||||
status: 'mounted' | 'unmounted' | 'error';
|
|
||||||
lastError: string | null;
|
|
||||||
createdAt: number;
|
|
||||||
updatedAt: number;
|
|
||||||
lastHealthCheck: number;
|
|
||||||
config: {
|
config: {
|
||||||
backend: 'nfs';
|
backend: 'nfs';
|
||||||
server: string;
|
server: string;
|
||||||
|
|
@ -2467,6 +2490,7 @@ export type ListBackupSchedulesResponses = {
|
||||||
username?: string;
|
username?: string;
|
||||||
password?: string;
|
password?: string;
|
||||||
guest?: boolean;
|
guest?: boolean;
|
||||||
|
mapToContainerUidGid?: boolean;
|
||||||
vers?: '1.0' | '2.0' | '2.1' | '3.0' | 'auto';
|
vers?: '1.0' | '2.0' | '2.1' | '3.0' | 'auto';
|
||||||
domain?: string;
|
domain?: string;
|
||||||
port?: string | number;
|
port?: string | number;
|
||||||
|
|
@ -2500,7 +2524,15 @@ export type ListBackupSchedulesResponses = {
|
||||||
readOnly?: boolean;
|
readOnly?: boolean;
|
||||||
skipHostKeyCheck?: boolean;
|
skipHostKeyCheck?: boolean;
|
||||||
knownHosts?: string;
|
knownHosts?: string;
|
||||||
|
allowLegacySshRsa?: boolean;
|
||||||
};
|
};
|
||||||
|
createdAt: number;
|
||||||
|
updatedAt: number;
|
||||||
|
lastHealthCheck: number;
|
||||||
|
type: 'nfs' | 'smb' | 'directory' | 'webdav' | 'rclone' | 'sftp';
|
||||||
|
status: 'mounted' | 'unmounted' | 'error';
|
||||||
|
lastError: string | null;
|
||||||
|
provisioningId?: string | null;
|
||||||
autoRemount: boolean;
|
autoRemount: boolean;
|
||||||
};
|
};
|
||||||
repository: {
|
repository: {
|
||||||
|
|
@ -2652,6 +2684,7 @@ export type ListBackupSchedulesResponses = {
|
||||||
privateKey: string;
|
privateKey: string;
|
||||||
skipHostKeyCheck?: boolean;
|
skipHostKeyCheck?: boolean;
|
||||||
knownHosts?: string;
|
knownHosts?: string;
|
||||||
|
allowLegacySshRsa?: boolean;
|
||||||
isExistingRepository?: boolean;
|
isExistingRepository?: boolean;
|
||||||
customPassword?: string;
|
customPassword?: string;
|
||||||
cacert?: string;
|
cacert?: string;
|
||||||
|
|
@ -2712,6 +2745,18 @@ export type CreateBackupScheduleData = {
|
||||||
oneFileSystem?: boolean;
|
oneFileSystem?: boolean;
|
||||||
tags?: Array<string>;
|
tags?: Array<string>;
|
||||||
customResticParams?: Array<string>;
|
customResticParams?: Array<string>;
|
||||||
|
backupWebhooks?: {
|
||||||
|
pre: {
|
||||||
|
url: string;
|
||||||
|
headers?: Array<string>;
|
||||||
|
body?: string;
|
||||||
|
} | null;
|
||||||
|
post: {
|
||||||
|
url: string;
|
||||||
|
headers?: Array<string>;
|
||||||
|
body?: string;
|
||||||
|
} | null;
|
||||||
|
} | null;
|
||||||
maxRetries?: number;
|
maxRetries?: number;
|
||||||
retryDelay?: number;
|
retryDelay?: number;
|
||||||
};
|
};
|
||||||
|
|
@ -2747,6 +2792,18 @@ export type CreateBackupScheduleResponses = {
|
||||||
includePatterns: Array<string> | null;
|
includePatterns: Array<string> | null;
|
||||||
oneFileSystem: boolean;
|
oneFileSystem: boolean;
|
||||||
customResticParams: Array<string> | null;
|
customResticParams: Array<string> | null;
|
||||||
|
backupWebhooks: {
|
||||||
|
pre: {
|
||||||
|
url: string;
|
||||||
|
headers?: Array<string>;
|
||||||
|
body?: string;
|
||||||
|
} | null;
|
||||||
|
post: {
|
||||||
|
url: string;
|
||||||
|
headers?: Array<string>;
|
||||||
|
body?: string;
|
||||||
|
} | null;
|
||||||
|
} | null;
|
||||||
maxRetries: number;
|
maxRetries: number;
|
||||||
retryDelay: number;
|
retryDelay: number;
|
||||||
lastBackupAt: number | null;
|
lastBackupAt: number | null;
|
||||||
|
|
@ -2816,6 +2873,18 @@ export type GetBackupScheduleResponses = {
|
||||||
includePatterns: Array<string> | null;
|
includePatterns: Array<string> | null;
|
||||||
oneFileSystem: boolean;
|
oneFileSystem: boolean;
|
||||||
customResticParams: Array<string> | null;
|
customResticParams: Array<string> | null;
|
||||||
|
backupWebhooks: {
|
||||||
|
pre: {
|
||||||
|
url: string;
|
||||||
|
headers?: Array<string>;
|
||||||
|
body?: string;
|
||||||
|
} | null;
|
||||||
|
post: {
|
||||||
|
url: string;
|
||||||
|
headers?: Array<string>;
|
||||||
|
body?: string;
|
||||||
|
} | null;
|
||||||
|
} | null;
|
||||||
maxRetries: number;
|
maxRetries: number;
|
||||||
retryDelay: number;
|
retryDelay: number;
|
||||||
lastBackupAt: number | null;
|
lastBackupAt: number | null;
|
||||||
|
|
@ -2827,14 +2896,7 @@ export type GetBackupScheduleResponses = {
|
||||||
volume: {
|
volume: {
|
||||||
id: number;
|
id: number;
|
||||||
shortId: string;
|
shortId: string;
|
||||||
provisioningId: string | null;
|
|
||||||
name: string;
|
name: string;
|
||||||
type: 'nfs' | 'smb' | 'directory' | 'webdav' | 'rclone' | 'sftp';
|
|
||||||
status: 'mounted' | 'unmounted' | 'error';
|
|
||||||
lastError: string | null;
|
|
||||||
createdAt: number;
|
|
||||||
updatedAt: number;
|
|
||||||
lastHealthCheck: number;
|
|
||||||
config: {
|
config: {
|
||||||
backend: 'nfs';
|
backend: 'nfs';
|
||||||
server: string;
|
server: string;
|
||||||
|
|
@ -2849,6 +2911,7 @@ export type GetBackupScheduleResponses = {
|
||||||
username?: string;
|
username?: string;
|
||||||
password?: string;
|
password?: string;
|
||||||
guest?: boolean;
|
guest?: boolean;
|
||||||
|
mapToContainerUidGid?: boolean;
|
||||||
vers?: '1.0' | '2.0' | '2.1' | '3.0' | 'auto';
|
vers?: '1.0' | '2.0' | '2.1' | '3.0' | 'auto';
|
||||||
domain?: string;
|
domain?: string;
|
||||||
port?: string | number;
|
port?: string | number;
|
||||||
|
|
@ -2882,7 +2945,15 @@ export type GetBackupScheduleResponses = {
|
||||||
readOnly?: boolean;
|
readOnly?: boolean;
|
||||||
skipHostKeyCheck?: boolean;
|
skipHostKeyCheck?: boolean;
|
||||||
knownHosts?: string;
|
knownHosts?: string;
|
||||||
|
allowLegacySshRsa?: boolean;
|
||||||
};
|
};
|
||||||
|
createdAt: number;
|
||||||
|
updatedAt: number;
|
||||||
|
lastHealthCheck: number;
|
||||||
|
type: 'nfs' | 'smb' | 'directory' | 'webdav' | 'rclone' | 'sftp';
|
||||||
|
status: 'mounted' | 'unmounted' | 'error';
|
||||||
|
lastError: string | null;
|
||||||
|
provisioningId?: string | null;
|
||||||
autoRemount: boolean;
|
autoRemount: boolean;
|
||||||
};
|
};
|
||||||
repository: {
|
repository: {
|
||||||
|
|
@ -3034,6 +3105,7 @@ export type GetBackupScheduleResponses = {
|
||||||
privateKey: string;
|
privateKey: string;
|
||||||
skipHostKeyCheck?: boolean;
|
skipHostKeyCheck?: boolean;
|
||||||
knownHosts?: string;
|
knownHosts?: string;
|
||||||
|
allowLegacySshRsa?: boolean;
|
||||||
isExistingRepository?: boolean;
|
isExistingRepository?: boolean;
|
||||||
customPassword?: string;
|
customPassword?: string;
|
||||||
cacert?: string;
|
cacert?: string;
|
||||||
|
|
@ -3093,6 +3165,18 @@ export type UpdateBackupScheduleData = {
|
||||||
oneFileSystem?: boolean;
|
oneFileSystem?: boolean;
|
||||||
tags?: Array<string>;
|
tags?: Array<string>;
|
||||||
customResticParams?: Array<string>;
|
customResticParams?: Array<string>;
|
||||||
|
backupWebhooks?: {
|
||||||
|
pre: {
|
||||||
|
url: string;
|
||||||
|
headers?: Array<string>;
|
||||||
|
body?: string;
|
||||||
|
} | null;
|
||||||
|
post: {
|
||||||
|
url: string;
|
||||||
|
headers?: Array<string>;
|
||||||
|
body?: string;
|
||||||
|
} | null;
|
||||||
|
} | null;
|
||||||
maxRetries?: number;
|
maxRetries?: number;
|
||||||
retryDelay?: number;
|
retryDelay?: number;
|
||||||
};
|
};
|
||||||
|
|
@ -3130,6 +3214,18 @@ export type UpdateBackupScheduleResponses = {
|
||||||
includePatterns: Array<string> | null;
|
includePatterns: Array<string> | null;
|
||||||
oneFileSystem: boolean;
|
oneFileSystem: boolean;
|
||||||
customResticParams: Array<string> | null;
|
customResticParams: Array<string> | null;
|
||||||
|
backupWebhooks: {
|
||||||
|
pre: {
|
||||||
|
url: string;
|
||||||
|
headers?: Array<string>;
|
||||||
|
body?: string;
|
||||||
|
} | null;
|
||||||
|
post: {
|
||||||
|
url: string;
|
||||||
|
headers?: Array<string>;
|
||||||
|
body?: string;
|
||||||
|
} | null;
|
||||||
|
} | null;
|
||||||
maxRetries: number;
|
maxRetries: number;
|
||||||
retryDelay: number;
|
retryDelay: number;
|
||||||
lastBackupAt: number | null;
|
lastBackupAt: number | null;
|
||||||
|
|
@ -3179,6 +3275,18 @@ export type GetBackupScheduleForVolumeResponses = {
|
||||||
includePatterns: Array<string> | null;
|
includePatterns: Array<string> | null;
|
||||||
oneFileSystem: boolean;
|
oneFileSystem: boolean;
|
||||||
customResticParams: Array<string> | null;
|
customResticParams: Array<string> | null;
|
||||||
|
backupWebhooks: {
|
||||||
|
pre: {
|
||||||
|
url: string;
|
||||||
|
headers?: Array<string>;
|
||||||
|
body?: string;
|
||||||
|
} | null;
|
||||||
|
post: {
|
||||||
|
url: string;
|
||||||
|
headers?: Array<string>;
|
||||||
|
body?: string;
|
||||||
|
} | null;
|
||||||
|
} | null;
|
||||||
maxRetries: number;
|
maxRetries: number;
|
||||||
retryDelay: number;
|
retryDelay: number;
|
||||||
lastBackupAt: number | null;
|
lastBackupAt: number | null;
|
||||||
|
|
@ -3190,14 +3298,7 @@ export type GetBackupScheduleForVolumeResponses = {
|
||||||
volume: {
|
volume: {
|
||||||
id: number;
|
id: number;
|
||||||
shortId: string;
|
shortId: string;
|
||||||
provisioningId: string | null;
|
|
||||||
name: string;
|
name: string;
|
||||||
type: 'nfs' | 'smb' | 'directory' | 'webdav' | 'rclone' | 'sftp';
|
|
||||||
status: 'mounted' | 'unmounted' | 'error';
|
|
||||||
lastError: string | null;
|
|
||||||
createdAt: number;
|
|
||||||
updatedAt: number;
|
|
||||||
lastHealthCheck: number;
|
|
||||||
config: {
|
config: {
|
||||||
backend: 'nfs';
|
backend: 'nfs';
|
||||||
server: string;
|
server: string;
|
||||||
|
|
@ -3212,6 +3313,7 @@ export type GetBackupScheduleForVolumeResponses = {
|
||||||
username?: string;
|
username?: string;
|
||||||
password?: string;
|
password?: string;
|
||||||
guest?: boolean;
|
guest?: boolean;
|
||||||
|
mapToContainerUidGid?: boolean;
|
||||||
vers?: '1.0' | '2.0' | '2.1' | '3.0' | 'auto';
|
vers?: '1.0' | '2.0' | '2.1' | '3.0' | 'auto';
|
||||||
domain?: string;
|
domain?: string;
|
||||||
port?: string | number;
|
port?: string | number;
|
||||||
|
|
@ -3245,7 +3347,15 @@ export type GetBackupScheduleForVolumeResponses = {
|
||||||
readOnly?: boolean;
|
readOnly?: boolean;
|
||||||
skipHostKeyCheck?: boolean;
|
skipHostKeyCheck?: boolean;
|
||||||
knownHosts?: string;
|
knownHosts?: string;
|
||||||
|
allowLegacySshRsa?: boolean;
|
||||||
};
|
};
|
||||||
|
createdAt: number;
|
||||||
|
updatedAt: number;
|
||||||
|
lastHealthCheck: number;
|
||||||
|
type: 'nfs' | 'smb' | 'directory' | 'webdav' | 'rclone' | 'sftp';
|
||||||
|
status: 'mounted' | 'unmounted' | 'error';
|
||||||
|
lastError: string | null;
|
||||||
|
provisioningId?: string | null;
|
||||||
autoRemount: boolean;
|
autoRemount: boolean;
|
||||||
};
|
};
|
||||||
repository: {
|
repository: {
|
||||||
|
|
@ -3397,6 +3507,7 @@ export type GetBackupScheduleForVolumeResponses = {
|
||||||
privateKey: string;
|
privateKey: string;
|
||||||
skipHostKeyCheck?: boolean;
|
skipHostKeyCheck?: boolean;
|
||||||
knownHosts?: string;
|
knownHosts?: string;
|
||||||
|
allowLegacySshRsa?: boolean;
|
||||||
isExistingRepository?: boolean;
|
isExistingRepository?: boolean;
|
||||||
customPassword?: string;
|
customPassword?: string;
|
||||||
cacert?: string;
|
cacert?: string;
|
||||||
|
|
@ -3526,6 +3637,9 @@ export type GetScheduleNotificationsResponses = {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
|
status: 'healthy' | 'error' | 'unknown';
|
||||||
|
lastChecked: number | null;
|
||||||
|
lastError: string | null;
|
||||||
type: 'email' | 'slack' | 'discord' | 'gotify' | 'ntfy' | 'pushover' | 'telegram' | 'generic' | 'custom';
|
type: 'email' | 'slack' | 'discord' | 'gotify' | 'ntfy' | 'pushover' | 'telegram' | 'generic' | 'custom';
|
||||||
config: {
|
config: {
|
||||||
type: 'email';
|
type: 'email';
|
||||||
|
|
@ -3627,6 +3741,9 @@ export type UpdateScheduleNotificationsResponses = {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
|
status: 'healthy' | 'error' | 'unknown';
|
||||||
|
lastChecked: number | null;
|
||||||
|
lastError: string | null;
|
||||||
type: 'email' | 'slack' | 'discord' | 'gotify' | 'ntfy' | 'pushover' | 'telegram' | 'generic' | 'custom';
|
type: 'email' | 'slack' | 'discord' | 'gotify' | 'ntfy' | 'pushover' | 'telegram' | 'generic' | 'custom';
|
||||||
config: {
|
config: {
|
||||||
type: 'email';
|
type: 'email';
|
||||||
|
|
@ -3865,6 +3982,7 @@ export type GetScheduleMirrorsResponses = {
|
||||||
privateKey: string;
|
privateKey: string;
|
||||||
skipHostKeyCheck?: boolean;
|
skipHostKeyCheck?: boolean;
|
||||||
knownHosts?: string;
|
knownHosts?: string;
|
||||||
|
allowLegacySshRsa?: boolean;
|
||||||
isExistingRepository?: boolean;
|
isExistingRepository?: boolean;
|
||||||
customPassword?: string;
|
customPassword?: string;
|
||||||
cacert?: string;
|
cacert?: string;
|
||||||
|
|
@ -4077,6 +4195,7 @@ export type UpdateScheduleMirrorsResponses = {
|
||||||
privateKey: string;
|
privateKey: string;
|
||||||
skipHostKeyCheck?: boolean;
|
skipHostKeyCheck?: boolean;
|
||||||
knownHosts?: string;
|
knownHosts?: string;
|
||||||
|
allowLegacySshRsa?: boolean;
|
||||||
isExistingRepository?: boolean;
|
isExistingRepository?: boolean;
|
||||||
customPassword?: string;
|
customPassword?: string;
|
||||||
cacert?: string;
|
cacert?: string;
|
||||||
|
|
@ -4258,6 +4377,9 @@ export type ListNotificationDestinationsResponses = {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
|
status: 'healthy' | 'error' | 'unknown';
|
||||||
|
lastChecked: number | null;
|
||||||
|
lastError: string | null;
|
||||||
type: 'email' | 'slack' | 'discord' | 'gotify' | 'ntfy' | 'pushover' | 'telegram' | 'generic' | 'custom';
|
type: 'email' | 'slack' | 'discord' | 'gotify' | 'ntfy' | 'pushover' | 'telegram' | 'generic' | 'custom';
|
||||||
config: {
|
config: {
|
||||||
type: 'email';
|
type: 'email';
|
||||||
|
|
@ -4401,6 +4523,9 @@ export type CreateNotificationDestinationResponses = {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
|
status: 'healthy' | 'error' | 'unknown';
|
||||||
|
lastChecked: number | null;
|
||||||
|
lastError: string | null;
|
||||||
type: 'email' | 'slack' | 'discord' | 'gotify' | 'ntfy' | 'pushover' | 'telegram' | 'generic' | 'custom';
|
type: 'email' | 'slack' | 'discord' | 'gotify' | 'ntfy' | 'pushover' | 'telegram' | 'generic' | 'custom';
|
||||||
config: {
|
config: {
|
||||||
type: 'email';
|
type: 'email';
|
||||||
|
|
@ -4519,6 +4644,9 @@ export type GetNotificationDestinationResponses = {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
|
status: 'healthy' | 'error' | 'unknown';
|
||||||
|
lastChecked: number | null;
|
||||||
|
lastError: string | null;
|
||||||
type: 'email' | 'slack' | 'discord' | 'gotify' | 'ntfy' | 'pushover' | 'telegram' | 'generic' | 'custom';
|
type: 'email' | 'slack' | 'discord' | 'gotify' | 'ntfy' | 'pushover' | 'telegram' | 'generic' | 'custom';
|
||||||
config: {
|
config: {
|
||||||
type: 'email';
|
type: 'email';
|
||||||
|
|
@ -4672,6 +4800,9 @@ export type UpdateNotificationDestinationResponses = {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
|
status: 'healthy' | 'error' | 'unknown';
|
||||||
|
lastChecked: number | null;
|
||||||
|
lastError: string | null;
|
||||||
type: 'email' | 'slack' | 'discord' | 'gotify' | 'ntfy' | 'pushover' | 'telegram' | 'generic' | 'custom';
|
type: 'email' | 'slack' | 'discord' | 'gotify' | 'ntfy' | 'pushover' | 'telegram' | 'generic' | 'custom';
|
||||||
config: {
|
config: {
|
||||||
type: 'email';
|
type: 'email';
|
||||||
|
|
|
||||||
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>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { useHotkey } from "@tanstack/react-hotkeys";
|
import { useHotkeySequence } from "@tanstack/react-hotkeys";
|
||||||
import { getDevPanelOptions } from "~/client/api-client/@tanstack/react-query.gen";
|
import { getDevPanelOptions } from "~/client/api-client/@tanstack/react-query.gen";
|
||||||
import { DevPanel } from "./dev-panel";
|
import { DevPanel } from "./dev-panel";
|
||||||
|
|
||||||
|
|
@ -10,7 +10,12 @@ export function DevPanelListener() {
|
||||||
...getDevPanelOptions(),
|
...getDevPanelOptions(),
|
||||||
});
|
});
|
||||||
|
|
||||||
useHotkey("Mod+Shift+D", () => setIsOpen(true), { enabled: !!devPanelStatus?.enabled, preventDefault: true });
|
useHotkeySequence(["D", "E", "V"], () => setIsOpen(true), {
|
||||||
|
enabled: !!devPanelStatus?.enabled,
|
||||||
|
preventDefault: true,
|
||||||
|
ignoreInputs: true,
|
||||||
|
timeout: 1000,
|
||||||
|
});
|
||||||
|
|
||||||
if (!devPanelStatus?.enabled) {
|
if (!devPanelStatus?.enabled) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -224,29 +224,6 @@ describe("SnapshotTreeBrowser", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("prefetches using the query path when display and query roots differ", async () => {
|
|
||||||
const requests = mockListSnapshotFiles();
|
|
||||||
|
|
||||||
renderSnapshotTreeBrowser();
|
|
||||||
|
|
||||||
const row = await screen.findByRole("button", { name: "project" });
|
|
||||||
const initialRequestCount = requests.length;
|
|
||||||
|
|
||||||
await userEvent.hover(row);
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(requests.length).toBe(initialRequestCount + 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(requests.at(-1)).toEqual({
|
|
||||||
shortId: "repo-1",
|
|
||||||
snapshotId: "snap-1",
|
|
||||||
path: "/mnt/project",
|
|
||||||
offset: "0",
|
|
||||||
limit: "500",
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test("shows the query root contents when display and query roots differ", async () => {
|
test("shows the query root contents when display and query roots differ", async () => {
|
||||||
mockListSnapshotFiles();
|
mockListSnapshotFiles();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import { FileBrowser, type FileBrowserUiProps } from "~/client/components/file-b
|
||||||
import { useFileBrowser } from "~/client/hooks/use-file-browser";
|
import { useFileBrowser } from "~/client/hooks/use-file-browser";
|
||||||
import { parseError } from "~/client/lib/errors";
|
import { parseError } from "~/client/lib/errors";
|
||||||
import { isPathWithin, normalizeAbsolutePath } from "@zerobyte/core/utils";
|
import { isPathWithin, normalizeAbsolutePath } from "@zerobyte/core/utils";
|
||||||
import { logger } from "~/client/lib/logger";
|
|
||||||
|
|
||||||
function createPathPrefixFns(basePath: string) {
|
function createPathPrefixFns(basePath: string) {
|
||||||
return {
|
return {
|
||||||
|
|
@ -84,16 +83,6 @@ export const SnapshotTreeBrowser = (props: SnapshotTreeBrowserProps) => {
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
prefetchFolder: (displayPath) => {
|
|
||||||
void queryClient
|
|
||||||
.prefetchQuery(
|
|
||||||
listSnapshotFilesOptions({
|
|
||||||
path: { shortId: repositoryId, snapshotId },
|
|
||||||
query: { path: displayPath, offset: 0, limit: pageSize },
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.catch((e) => logger.error(e));
|
|
||||||
},
|
|
||||||
pathTransform: displayPathFns,
|
pathTransform: displayPathFns,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ export function Layout({ loaderData }: Props) {
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
<TooltipTrigger asChild>
|
<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={buttonVariants({
|
className={buttonVariants({
|
||||||
|
|
|
||||||
|
|
@ -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>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -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 };
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ 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,5 +1,5 @@
|
||||||
import { Cloud, Folder, Server } from "lucide-react";
|
import { Cloud, Folder, Server } from "lucide-react";
|
||||||
import type { BackendType } from "~/schemas/volumes";
|
import type { BackendType } from "@zerobyte/contracts/volumes";
|
||||||
|
|
||||||
type VolumeIconProps = {
|
type VolumeIconProps = {
|
||||||
backend: BackendType;
|
backend: BackendType;
|
||||||
|
|
|
||||||
25
app/client/components/webhook-request-preview.tsx
Normal file
25
app/client/components/webhook-request-preview.tsx
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { CodeBlock } from "~/client/components/ui/code-block";
|
||||||
|
import { Label } from "~/client/components/ui/label";
|
||||||
|
|
||||||
|
type WebhookRequestPreviewProps = {
|
||||||
|
method: string;
|
||||||
|
url?: string;
|
||||||
|
contentType?: string;
|
||||||
|
headers?: string[];
|
||||||
|
body: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const WebhookRequestPreview = ({ method, url, contentType, headers, body }: WebhookRequestPreviewProps) => {
|
||||||
|
const headerLines = [contentType ? `Content-Type: ${contentType}` : undefined, ...(headers ?? [])].filter(Boolean);
|
||||||
|
const previewCode = `${method} ${url || "https://api.example.com/webhook"}${headerLines.length > 0 ? `\n${headerLines.join("\n")}` : ""}
|
||||||
|
|
||||||
|
${body}`;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-2 pt-4 border-t">
|
||||||
|
<Label>Request Preview</Label>
|
||||||
|
<CodeBlock code={previewCode} filename="HTTP Request" />
|
||||||
|
<p className="text-[0.8rem] text-muted-foreground">This is a preview of the HTTP request that will be sent.</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
36
app/client/functions/__tests__/is-secure-context.test.ts
Normal file
36
app/client/functions/__tests__/is-secure-context.test.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
import { describe, expect, test } from "vitest";
|
||||||
|
import { getIsSecureContextForRequest, isSecureContextOrigin } from "../is-secure-context";
|
||||||
|
|
||||||
|
describe("isSecureContextOrigin", () => {
|
||||||
|
test("treats HTTPS and loopback HTTP origins as secure contexts", () => {
|
||||||
|
expect(isSecureContextOrigin("https://example.com")).toBe(true);
|
||||||
|
expect(isSecureContextOrigin("http://localhost:3000")).toBe(true);
|
||||||
|
expect(isSecureContextOrigin("http://app.localhost")).toBe(true);
|
||||||
|
expect(isSecureContextOrigin("http://127.0.0.1:3000")).toBe(true);
|
||||||
|
expect(isSecureContextOrigin("http://[::1]:3000")).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("treats non-local HTTP origins as insecure contexts", () => {
|
||||||
|
expect(isSecureContextOrigin("http://example.com")).toBe(false);
|
||||||
|
expect(isSecureContextOrigin("http://127.example.com")).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("getIsSecureContextForRequest", () => {
|
||||||
|
test("uses forwarded protocol and host when present", () => {
|
||||||
|
const request = new Request("http://internal.local/settings", {
|
||||||
|
headers: {
|
||||||
|
host: "internal.local",
|
||||||
|
"x-forwarded-host": "zerobyte.example.com",
|
||||||
|
"x-forwarded-proto": "https",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(getIsSecureContextForRequest(request)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("uses the request URL when forwarded headers are absent", () => {
|
||||||
|
expect(getIsSecureContextForRequest(new Request("http://zerobyte.example.com/settings"))).toBe(false);
|
||||||
|
expect(getIsSecureContextForRequest(new Request("https://zerobyte.example.com/settings"))).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
51
app/client/functions/is-secure-context.ts
Normal file
51
app/client/functions/is-secure-context.ts
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
import { createIsomorphicFn } from "@tanstack/react-start";
|
||||||
|
import { getRequest } from "@tanstack/react-start/server";
|
||||||
|
import ipaddr from "ipaddr.js";
|
||||||
|
|
||||||
|
const getFirstHeaderValue = (value: string | null) => value?.split(",")[0]?.trim();
|
||||||
|
|
||||||
|
const isLoopbackIp = (hostname: string) => {
|
||||||
|
try {
|
||||||
|
return ipaddr.parse(hostname).range() === "loopback";
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getRequestOrigin = (request: Request) => {
|
||||||
|
const requestUrl = new URL(request.url);
|
||||||
|
const forwardedProto = getFirstHeaderValue(request.headers.get("x-forwarded-proto"));
|
||||||
|
const forwardedHost = getFirstHeaderValue(request.headers.get("x-forwarded-host"));
|
||||||
|
const host = forwardedHost || getFirstHeaderValue(request.headers.get("host"));
|
||||||
|
|
||||||
|
if (!host) {
|
||||||
|
return requestUrl.origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
const protocol = (forwardedProto || requestUrl.protocol).replace(/:$/, "");
|
||||||
|
return `${protocol}://${host}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const isSecureContextOrigin = (origin: string) => {
|
||||||
|
const url = new URL(origin);
|
||||||
|
|
||||||
|
if (url.protocol === "https:") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const hostname = url.hostname.replace(/^\[(.*)\]$/, "$1").toLowerCase();
|
||||||
|
|
||||||
|
return hostname === "localhost" || hostname.endsWith(".localhost") || isLoopbackIp(hostname);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getIsSecureContextForRequest = (request: Request) => isSecureContextOrigin(getRequestOrigin(request));
|
||||||
|
|
||||||
|
export const getIsSecureContext = createIsomorphicFn()
|
||||||
|
.server(() => {
|
||||||
|
try {
|
||||||
|
return getIsSecureContextForRequest(getRequest());
|
||||||
|
} catch {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.client(() => window.isSecureContext ?? true);
|
||||||
|
|
@ -28,6 +28,7 @@ const invalidatingEvents = new Set<ServerEventType>([
|
||||||
"backup:completed",
|
"backup:completed",
|
||||||
"volume:updated",
|
"volume:updated",
|
||||||
"volume:status_changed",
|
"volume:status_changed",
|
||||||
|
"notification:updated",
|
||||||
"mirror:completed",
|
"mirror:completed",
|
||||||
"doctor:started",
|
"doctor:started",
|
||||||
"doctor:completed",
|
"doctor:completed",
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import {
|
||||||
inferAdditionalFields,
|
inferAdditionalFields,
|
||||||
} from "better-auth/client/plugins";
|
} from "better-auth/client/plugins";
|
||||||
import { ssoClient } from "@better-auth/sso/client";
|
import { ssoClient } from "@better-auth/sso/client";
|
||||||
|
import { passkeyClient } from "@better-auth/passkey/client";
|
||||||
import type { auth } from "~/server/lib/auth";
|
import type { auth } from "~/server/lib/auth";
|
||||||
|
|
||||||
export const authClient = createAuthClient({
|
export const authClient = createAuthClient({
|
||||||
|
|
@ -17,5 +18,6 @@ export const authClient = createAuthClient({
|
||||||
organizationClient(),
|
organizationClient(),
|
||||||
ssoClient(),
|
ssoClient(),
|
||||||
twoFactorClient(),
|
twoFactorClient(),
|
||||||
|
passkeyClient(),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
import { useSuspenseQuery } from "@tanstack/react-query";
|
||||||
|
import { useServerFn } from "@tanstack/react-start";
|
||||||
|
import { getPublicSsoProvidersOptions } from "~/client/api-client/@tanstack/react-query.gen";
|
||||||
|
import { SsoLoginButtons } from "~/client/modules/sso/components/sso-login-buttons";
|
||||||
|
import { getLoginOptions } from "~/server/lib/functions/login-options";
|
||||||
|
import { PasskeySignInButton } from "./passkey-sign-in-button";
|
||||||
|
|
||||||
|
type AlternativeSignInSectionProps = {
|
||||||
|
onPasskeySignIn: () => Promise<void>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function AlternativeSignInSection({ onPasskeySignIn }: AlternativeSignInSectionProps) {
|
||||||
|
const getOptions = useServerFn(getLoginOptions);
|
||||||
|
const { data: ssoProviders } = useSuspenseQuery({
|
||||||
|
...getPublicSsoProvidersOptions(),
|
||||||
|
});
|
||||||
|
const { data: loginOptions } = useSuspenseQuery({
|
||||||
|
queryKey: ["login-options"],
|
||||||
|
queryFn: getOptions,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (ssoProviders.providers.length === 0 && !loginOptions.hasPasskeySignIn) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="pt-4 border-t border-border/60 space-y-3">
|
||||||
|
<p className="text-sm font-medium">Alternative Sign-in</p>
|
||||||
|
<div className="flex flex-col gap-2">
|
||||||
|
{loginOptions.hasPasskeySignIn && <PasskeySignInButton onSignIn={onPasskeySignIn} />}
|
||||||
|
<SsoLoginButtons providers={ssoProviders.providers} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,64 @@
|
||||||
|
import { useMutation } from "@tanstack/react-query";
|
||||||
|
import { useNavigate } from "@tanstack/react-router";
|
||||||
|
import { Fingerprint } from "lucide-react";
|
||||||
|
import { Button } from "~/client/components/ui/button";
|
||||||
|
import { authClient } from "~/client/lib/auth-client";
|
||||||
|
import { logger } from "~/client/lib/logger";
|
||||||
|
import { LOGIN_ERROR_CODES, PASSKEY_LOGIN_FAILED_ERROR, type LoginErrorCode } from "~/lib/sso-errors";
|
||||||
|
|
||||||
|
type PasskeySignInButtonProps = {
|
||||||
|
onSignIn: () => Promise<void>;
|
||||||
|
};
|
||||||
|
|
||||||
|
type PasskeySignInError = {
|
||||||
|
code?: string;
|
||||||
|
message?: string;
|
||||||
|
status?: number;
|
||||||
|
statusText?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const LOGIN_ERROR_CODE_SET = new Set<string>(LOGIN_ERROR_CODES);
|
||||||
|
|
||||||
|
function getPasskeyLoginErrorCode(code: string | undefined): LoginErrorCode {
|
||||||
|
if (code && LOGIN_ERROR_CODE_SET.has(code)) {
|
||||||
|
return code as LoginErrorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
return PASSKEY_LOGIN_FAILED_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PasskeySignInButton({ onSignIn }: PasskeySignInButtonProps) {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const passkeyLoginMutation = useMutation<void, PasskeySignInError>({
|
||||||
|
mutationFn: async () => {
|
||||||
|
const { error } = await authClient.signIn.passkey();
|
||||||
|
if (error) throw error;
|
||||||
|
|
||||||
|
await onSignIn();
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
logger.error(error);
|
||||||
|
|
||||||
|
void navigate({
|
||||||
|
to: "/login",
|
||||||
|
search: {
|
||||||
|
error: getPasskeyLoginErrorCode(error.code),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
className="w-full"
|
||||||
|
loading={passkeyLoginMutation.isPending}
|
||||||
|
disabled={passkeyLoginMutation.isPending}
|
||||||
|
onClick={() => passkeyLoginMutation.mutate()}
|
||||||
|
>
|
||||||
|
<Fingerprint className="h-4 w-4 mr-2" />
|
||||||
|
Sign in with passkey
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -1,16 +1,49 @@
|
||||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||||
import { HttpResponse, http, server } from "~/test/msw/server";
|
import { HttpResponse, http, server } from "~/test/msw/server";
|
||||||
import { cleanup, render, screen } from "~/test/test-utils";
|
import { cleanup, render, screen, userEvent, waitFor } from "~/test/test-utils";
|
||||||
|
import { getLoginErrorDescription, PASSKEY_LOGIN_FAILED_ERROR } from "~/lib/sso-errors";
|
||||||
|
|
||||||
|
const { mockGetLoginOptions, mockNavigate, mockPasskeySignIn } = vi.hoisted(() => ({
|
||||||
|
mockGetLoginOptions: vi.fn(async () => ({ hasPasskeySignIn: false })),
|
||||||
|
mockNavigate: vi.fn(async () => {}),
|
||||||
|
mockPasskeySignIn: vi.fn(
|
||||||
|
async (): Promise<{
|
||||||
|
data: unknown;
|
||||||
|
error: { code: string; message: string } | null;
|
||||||
|
}> => ({ data: null, error: null }),
|
||||||
|
),
|
||||||
|
}));
|
||||||
|
|
||||||
vi.mock("@tanstack/react-router", async (importOriginal) => {
|
vi.mock("@tanstack/react-router", async (importOriginal) => {
|
||||||
const actual = await importOriginal<typeof import("@tanstack/react-router")>();
|
const actual = await importOriginal<typeof import("@tanstack/react-router")>();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...actual,
|
...actual,
|
||||||
useNavigate: (() => vi.fn(async () => {})) as typeof actual.useNavigate,
|
useNavigate: (() => mockNavigate) as typeof actual.useNavigate,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
vi.mock("@tanstack/react-start", async (importOriginal) => {
|
||||||
|
const actual = await importOriginal<typeof import("@tanstack/react-start")>();
|
||||||
|
|
||||||
|
return {
|
||||||
|
...actual,
|
||||||
|
useServerFn: (fn: unknown) => fn,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
vi.mock("~/server/lib/functions/login-options", () => ({
|
||||||
|
getLoginOptions: mockGetLoginOptions,
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock("~/client/lib/auth-client", () => ({
|
||||||
|
authClient: {
|
||||||
|
signIn: {
|
||||||
|
passkey: mockPasskeySignIn,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
import { LoginPage } from "../login";
|
import { LoginPage } from "../login";
|
||||||
const inviteOnlyMessage =
|
const inviteOnlyMessage =
|
||||||
"Access is invite-only. Ask an organization admin to send you an invitation before signing in with SSO.";
|
"Access is invite-only. Ask an organization admin to send you an invitation before signing in with SSO.";
|
||||||
|
|
@ -29,6 +62,12 @@ const mockSsoProvidersRequest = (
|
||||||
};
|
};
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
mockGetLoginOptions.mockClear();
|
||||||
|
mockGetLoginOptions.mockResolvedValue({ hasPasskeySignIn: false });
|
||||||
|
mockNavigate.mockClear();
|
||||||
|
mockPasskeySignIn.mockClear();
|
||||||
|
mockPasskeySignIn.mockResolvedValue({ data: null, error: null });
|
||||||
|
vi.unstubAllGlobals();
|
||||||
cleanup();
|
cleanup();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -81,6 +120,14 @@ describe("LoginPage", () => {
|
||||||
expect(await screen.findByText("SSO authentication failed. Please try again.")).toBeTruthy();
|
expect(await screen.findByText("SSO authentication failed. Please try again.")).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("shows passkey login failure message when passkey returns the login error code", async () => {
|
||||||
|
mockSsoProvidersRequest();
|
||||||
|
|
||||||
|
render(<LoginPage error={"PASSKEY_LOGIN_FAILED"} />, { withSuspense: true });
|
||||||
|
|
||||||
|
expect(await screen.findByText(getLoginErrorDescription(PASSKEY_LOGIN_FAILED_ERROR))).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
test("does not show error message for invalid error codes", async () => {
|
test("does not show error message for invalid error codes", async () => {
|
||||||
mockSsoProvidersRequest();
|
mockSsoProvidersRequest();
|
||||||
|
|
||||||
|
|
@ -90,11 +137,141 @@ describe("LoginPage", () => {
|
||||||
expect(screen.queryByText(inviteOnlyMessage)).toBeNull();
|
expect(screen.queryByText(inviteOnlyMessage)).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("renders available SSO providers from the real SSO section", async () => {
|
test("renders available SSO providers from the alternative sign-in section", async () => {
|
||||||
mockSsoProvidersRequest([{ providerId: "acme", organizationSlug: "acme-org" }]);
|
mockSsoProvidersRequest([{ providerId: "acme", organizationSlug: "acme-org" }]);
|
||||||
|
|
||||||
render(<LoginPage />, { withSuspense: true });
|
render(<LoginPage />, { withSuspense: true });
|
||||||
|
|
||||||
expect(await screen.findByRole("button", { name: "Log in with acme" })).toBeTruthy();
|
expect(await screen.findByRole("button", { name: "Log in with acme" })).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("renders passkey sign-in when an active user has a passkey", async () => {
|
||||||
|
mockSsoProvidersRequest();
|
||||||
|
mockGetLoginOptions.mockResolvedValue({ hasPasskeySignIn: true });
|
||||||
|
|
||||||
|
render(<LoginPage />, { withSuspense: true });
|
||||||
|
|
||||||
|
expect(await screen.findByRole("button", { name: "Sign in with passkey" })).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("redirects passkey verification failures to the login error box", async () => {
|
||||||
|
mockSsoProvidersRequest();
|
||||||
|
mockGetLoginOptions.mockResolvedValue({ hasPasskeySignIn: true });
|
||||||
|
mockPasskeySignIn.mockResolvedValue({
|
||||||
|
data: null,
|
||||||
|
error: { code: "AUTHENTICATION_FAILED", message: "Authentication failed" },
|
||||||
|
});
|
||||||
|
|
||||||
|
render(<LoginPage />, { withSuspense: true });
|
||||||
|
|
||||||
|
await userEvent.click(await screen.findByRole("button", { name: "Sign in with passkey" }));
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(mockNavigate).toHaveBeenCalledWith({
|
||||||
|
to: "/login",
|
||||||
|
search: {
|
||||||
|
error: PASSKEY_LOGIN_FAILED_ERROR,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("redirects unauthorized passkey failures to the login error box", async () => {
|
||||||
|
mockSsoProvidersRequest();
|
||||||
|
mockGetLoginOptions.mockResolvedValue({ hasPasskeySignIn: true });
|
||||||
|
mockPasskeySignIn.mockResolvedValue({
|
||||||
|
data: null,
|
||||||
|
error: { code: "UNAUTHORIZED", message: "Unauthorized" },
|
||||||
|
});
|
||||||
|
|
||||||
|
render(<LoginPage />, { withSuspense: true });
|
||||||
|
|
||||||
|
await userEvent.click(await screen.findByRole("button", { name: "Sign in with passkey" }));
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(mockNavigate).toHaveBeenCalledWith({
|
||||||
|
to: "/login",
|
||||||
|
search: {
|
||||||
|
error: PASSKEY_LOGIN_FAILED_ERROR,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("preserves specific passkey login error codes", async () => {
|
||||||
|
mockSsoProvidersRequest();
|
||||||
|
mockGetLoginOptions.mockResolvedValue({ hasPasskeySignIn: true });
|
||||||
|
mockPasskeySignIn.mockResolvedValue({
|
||||||
|
data: null,
|
||||||
|
error: { code: "ERROR_INVALID_RP_ID", message: "Auth cancelled" },
|
||||||
|
});
|
||||||
|
|
||||||
|
render(<LoginPage />, { withSuspense: true });
|
||||||
|
|
||||||
|
await userEvent.click(await screen.findByRole("button", { name: "Sign in with passkey" }));
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(mockNavigate).toHaveBeenCalledWith({
|
||||||
|
to: "/login",
|
||||||
|
search: {
|
||||||
|
error: "ERROR_INVALID_RP_ID",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("redirects conditional passkey autofill failures to the login error box", async () => {
|
||||||
|
mockSsoProvidersRequest();
|
||||||
|
mockPasskeySignIn.mockResolvedValue({
|
||||||
|
data: null,
|
||||||
|
error: { code: "AUTHENTICATION_FAILED", message: "Authentication failed" },
|
||||||
|
});
|
||||||
|
vi.stubGlobal("PublicKeyCredential", {
|
||||||
|
isConditionalMediationAvailable: vi.fn(async () => true),
|
||||||
|
});
|
||||||
|
|
||||||
|
render(<LoginPage />, { withSuspense: true });
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(mockPasskeySignIn).toHaveBeenCalledWith({
|
||||||
|
autoFill: true,
|
||||||
|
});
|
||||||
|
expect(mockNavigate).toHaveBeenCalledWith({
|
||||||
|
to: "/login",
|
||||||
|
search: {
|
||||||
|
error: "PASSKEY_LOGIN_FAILED",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("ignores conditional passkey autofill cancellation", async () => {
|
||||||
|
mockSsoProvidersRequest();
|
||||||
|
mockPasskeySignIn.mockResolvedValue({
|
||||||
|
data: null,
|
||||||
|
error: { code: "AUTH_CANCELLED", message: "Authentication cancelled" },
|
||||||
|
});
|
||||||
|
vi.stubGlobal("PublicKeyCredential", {
|
||||||
|
isConditionalMediationAvailable: vi.fn(async () => true),
|
||||||
|
});
|
||||||
|
|
||||||
|
render(<LoginPage />, { withSuspense: true });
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(mockPasskeySignIn).toHaveBeenCalledWith({
|
||||||
|
autoFill: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
expect(mockNavigate).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("hides alternative sign-in when no SSO providers or passkeys are available", async () => {
|
||||||
|
mockSsoProvidersRequest();
|
||||||
|
|
||||||
|
render(<LoginPage />, { withSuspense: true });
|
||||||
|
|
||||||
|
await screen.findByText("Login to your account");
|
||||||
|
expect(screen.queryByText("Alternative Sign-in")).toBeNull();
|
||||||
|
expect(screen.queryByRole("button", { name: "Sign in with passkey" })).toBeNull();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,25 @@ import { Button } from "~/client/components/ui/button";
|
||||||
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 { downloadResticPasswordMutation } from "~/client/api-client/@tanstack/react-query.gen";
|
import { downloadResticPasswordMutation } from "~/client/api-client/@tanstack/react-query.gen";
|
||||||
|
import { parseError } from "~/client/lib/errors";
|
||||||
|
import {
|
||||||
|
RECOVERY_KEY_DOWNLOAD_SKIPPED_COOKIE_MAX_AGE,
|
||||||
|
RECOVERY_KEY_DOWNLOAD_SKIPPED_COOKIE_NAME,
|
||||||
|
} from "~/lib/recovery-key-skip";
|
||||||
import { useNavigate } from "@tanstack/react-router";
|
import { useNavigate } from "@tanstack/react-router";
|
||||||
|
|
||||||
export function DownloadRecoveryKeyPage() {
|
const RECOVERY_KEY_CREDENTIAL_REQUIRED_MESSAGE =
|
||||||
|
"Downloading the recovery key requires a local credential password. Ask an operator to run `docker exec -it zerobyte bun run cli reset-password` for your user, then sign in with that password and try again.";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
hasCredentialPassword: boolean;
|
||||||
|
userId: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function DownloadRecoveryKeyPage({ hasCredentialPassword, userId }: Props) {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [password, setPassword] = useState("");
|
const [password, setPassword] = useState("");
|
||||||
|
const [blockedMessage, setBlockedMessage] = useState<string | null>(null);
|
||||||
|
|
||||||
const downloadResticPassword = useMutation({
|
const downloadResticPassword = useMutation({
|
||||||
...downloadResticPasswordMutation(),
|
...downloadResticPasswordMutation(),
|
||||||
|
|
@ -25,13 +39,16 @@ export function DownloadRecoveryKeyPage() {
|
||||||
document.body.appendChild(a);
|
document.body.appendChild(a);
|
||||||
a.click();
|
a.click();
|
||||||
document.body.removeChild(a);
|
document.body.removeChild(a);
|
||||||
window.URL.revokeObjectURL(url);
|
window.setTimeout(() => window.URL.revokeObjectURL(url), 60_000);
|
||||||
|
|
||||||
toast.success("Recovery key downloaded successfully!");
|
toast.success("Recovery key downloaded successfully!");
|
||||||
|
setBlockedMessage(null);
|
||||||
void navigate({ to: "/volumes", replace: true });
|
void navigate({ to: "/volumes", replace: true });
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
toast.error("Failed to download recovery key", { description: error.message });
|
const message = parseError(error)?.message;
|
||||||
|
setBlockedMessage(message?.includes("credential password") ? message : null);
|
||||||
|
toast.error("Failed to download recovery key", { description: message });
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -43,11 +60,15 @@ export function DownloadRecoveryKeyPage() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadResticPassword.mutate({
|
setBlockedMessage(null);
|
||||||
body: {
|
downloadResticPassword.mutate({ body: { password } });
|
||||||
password,
|
};
|
||||||
},
|
|
||||||
});
|
const handleSkip = () => {
|
||||||
|
if (!userId) return;
|
||||||
|
|
||||||
|
document.cookie = `${RECOVERY_KEY_DOWNLOAD_SKIPPED_COOKIE_NAME}=${userId}; path=/; max-age=${RECOVERY_KEY_DOWNLOAD_SKIPPED_COOKIE_MAX_AGE}`;
|
||||||
|
void navigate({ to: "/volumes", replace: true });
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -59,30 +80,56 @@ export function DownloadRecoveryKeyPage() {
|
||||||
<AlertTriangle className="size-5" />
|
<AlertTriangle className="size-5" />
|
||||||
<AlertTitle>Important: Save This File Securely</AlertTitle>
|
<AlertTitle>Important: Save This File Securely</AlertTitle>
|
||||||
<AlertDescription>
|
<AlertDescription>
|
||||||
Your Restic password is essential for recovering your backup data. If you lose access to this server without
|
Your Restic password is essential for recovering your backup data. If you previously downloaded this
|
||||||
this file, your backups will be unrecoverable. Store it in a password manager or encrypted storage.
|
file, replace that saved copy with the new download. If you lose access to this server without this
|
||||||
|
file, your backups will be unrecoverable. Store it in a password manager or encrypted storage.
|
||||||
</AlertDescription>
|
</AlertDescription>
|
||||||
</Alert>
|
</Alert>
|
||||||
|
|
||||||
<form onSubmit={handleSubmit} className="space-y-4">
|
<form onSubmit={handleSubmit} className="space-y-4">
|
||||||
<div className="space-y-2">
|
{(!hasCredentialPassword || blockedMessage) && (
|
||||||
<Label htmlFor="password">Confirm Your Password</Label>
|
<Alert variant="warning">
|
||||||
<Input
|
<AlertTriangle className="size-5" />
|
||||||
id="password"
|
<AlertTitle>Local password required</AlertTitle>
|
||||||
type="password"
|
<AlertDescription>
|
||||||
value={password}
|
{blockedMessage ?? RECOVERY_KEY_CREDENTIAL_REQUIRED_MESSAGE}
|
||||||
onChange={(e) => setPassword(e.target.value)}
|
</AlertDescription>
|
||||||
placeholder="Enter your password"
|
</Alert>
|
||||||
required
|
)}
|
||||||
disabled={downloadResticPassword.isPending}
|
|
||||||
/>
|
{hasCredentialPassword && (
|
||||||
<p className="text-xs text-muted-foreground">Enter your account password to download the recovery key</p>
|
<div className="space-y-2">
|
||||||
</div>
|
<Label htmlFor="password">Confirm Your Password</Label>
|
||||||
|
<Input
|
||||||
|
id="password"
|
||||||
|
type="password"
|
||||||
|
value={password}
|
||||||
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
|
placeholder="Enter your password"
|
||||||
|
required
|
||||||
|
disabled={downloadResticPassword.isPending}
|
||||||
|
/>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
Enter your account password to download the recovery key
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<div className="flex flex-col gap-2">
|
<div className="flex flex-col gap-2">
|
||||||
<Button type="submit" loading={downloadResticPassword.isPending} className="w-full">
|
{hasCredentialPassword && (
|
||||||
<Download size={16} className="mr-2" />
|
<Button type="submit" loading={downloadResticPassword.isPending} className="w-full">
|
||||||
Download Recovery Key
|
<Download size={16} className="mr-2" />
|
||||||
|
Download Recovery Key
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="ghost"
|
||||||
|
onClick={handleSkip}
|
||||||
|
disabled={downloadResticPassword.isPending}
|
||||||
|
className="w-full"
|
||||||
|
>
|
||||||
|
Skip
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { useState } from "react";
|
import { useCallback, useEffect, useState } from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { AuthLayout } from "~/client/components/auth-layout";
|
import { AuthLayout } from "~/client/components/auth-layout";
|
||||||
|
|
@ -10,12 +10,14 @@ import { InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot } from "~/clie
|
||||||
import { Label } from "~/client/components/ui/label";
|
import { Label } from "~/client/components/ui/label";
|
||||||
import { authClient } from "~/client/lib/auth-client";
|
import { authClient } from "~/client/lib/auth-client";
|
||||||
import { logger } from "~/client/lib/logger";
|
import { logger } from "~/client/lib/logger";
|
||||||
|
import { RECOVERY_KEY_DOWNLOAD_SKIPPED_COOKIE_NAME } from "~/lib/recovery-key-skip";
|
||||||
import { decodeLoginError, getLoginErrorDescription } from "~/client/lib/sso-errors";
|
import { decodeLoginError, getLoginErrorDescription } from "~/client/lib/sso-errors";
|
||||||
|
import { PASSKEY_LOGIN_FAILED_ERROR } from "~/lib/sso-errors";
|
||||||
import { ResetPasswordDialog } from "../components/reset-password-dialog";
|
import { ResetPasswordDialog } from "../components/reset-password-dialog";
|
||||||
import { useNavigate } from "@tanstack/react-router";
|
import { useNavigate } from "@tanstack/react-router";
|
||||||
import { normalizeUsername } from "~/lib/username";
|
import { normalizeUsername } from "~/lib/username";
|
||||||
import { cn } from "~/client/lib/utils";
|
import { cn } from "~/client/lib/utils";
|
||||||
import { SsoLoginSection } from "~/client/modules/sso/components/sso-login-section";
|
import { AlternativeSignInSection } from "../components/alternative-sign-in-section";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
const loginSchema = z.object({
|
const loginSchema = z.object({
|
||||||
|
|
@ -32,6 +34,23 @@ type LoginPageProps = {
|
||||||
error?: string;
|
error?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type PasskeySignInError = {
|
||||||
|
code?: string;
|
||||||
|
message?: string;
|
||||||
|
status?: number;
|
||||||
|
statusText?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
function isPasskeyVerificationFailure(error: PasskeySignInError | null) {
|
||||||
|
return error?.code === "AUTHENTICATION_FAILED" || error?.code === "UNAUTHORIZED";
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasSkippedRecoveryKeyDownload(userId: string) {
|
||||||
|
return document.cookie
|
||||||
|
.split(";")
|
||||||
|
.some((cookie) => cookie.trim() === `${RECOVERY_KEY_DOWNLOAD_SKIPPED_COOKIE_NAME}=${userId}`);
|
||||||
|
}
|
||||||
|
|
||||||
export function LoginPage({ error }: LoginPageProps = {}) {
|
export function LoginPage({ error }: LoginPageProps = {}) {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [showResetDialog, setShowResetDialog] = useState(false);
|
const [showResetDialog, setShowResetDialog] = useState(false);
|
||||||
|
|
@ -43,6 +62,52 @@ export function LoginPage({ error }: LoginPageProps = {}) {
|
||||||
const errorCode = decodeLoginError(error);
|
const errorCode = decodeLoginError(error);
|
||||||
const errorDescription = errorCode ? getLoginErrorDescription(errorCode) : null;
|
const errorDescription = errorCode ? getLoginErrorDescription(errorCode) : null;
|
||||||
|
|
||||||
|
const navigateAfterLogin = useCallback(async () => {
|
||||||
|
const session = await authClient.getSession();
|
||||||
|
|
||||||
|
if (
|
||||||
|
session.data?.user &&
|
||||||
|
!session.data.user.hasDownloadedResticPassword &&
|
||||||
|
!hasSkippedRecoveryKeyDownload(session.data.user.id)
|
||||||
|
) {
|
||||||
|
void navigate({ to: "/download-recovery-key" });
|
||||||
|
} else {
|
||||||
|
void navigate({ to: "/volumes" });
|
||||||
|
}
|
||||||
|
}, [navigate]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const autoSignIn = async () => {
|
||||||
|
if (
|
||||||
|
typeof PublicKeyCredential === "undefined" ||
|
||||||
|
!PublicKeyCredential.isConditionalMediationAvailable ||
|
||||||
|
!(await PublicKeyCredential.isConditionalMediationAvailable())
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data, error } = await authClient.signIn.passkey({
|
||||||
|
autoFill: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (isPasskeyVerificationFailure(error)) {
|
||||||
|
void navigate({
|
||||||
|
to: "/login",
|
||||||
|
search: {
|
||||||
|
error: PASSKEY_LOGIN_FAILED_ERROR,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data) {
|
||||||
|
await navigateAfterLogin();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void autoSignIn();
|
||||||
|
}, [navigate, navigateAfterLogin]);
|
||||||
|
|
||||||
const form = useForm<LoginFormValues>({
|
const form = useForm<LoginFormValues>({
|
||||||
resolver: zodResolver(loginSchema),
|
resolver: zodResolver(loginSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
|
|
@ -76,12 +141,7 @@ export function LoginPage({ error }: LoginPageProps = {}) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const d = await authClient.getSession();
|
await navigateAfterLogin();
|
||||||
if (data.user && !d.data?.user.hasDownloadedResticPassword) {
|
|
||||||
void navigate({ to: "/download-recovery-key" });
|
|
||||||
} else {
|
|
||||||
void navigate({ to: "/volumes" });
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleVerify2FA = async () => {
|
const handleVerify2FA = async () => {
|
||||||
|
|
@ -113,7 +173,11 @@ export function LoginPage({ error }: LoginPageProps = {}) {
|
||||||
if (data) {
|
if (data) {
|
||||||
toast.success("Login successful");
|
toast.success("Login successful");
|
||||||
const session = await authClient.getSession();
|
const session = await authClient.getSession();
|
||||||
if (session.data?.user && !session.data.user.hasDownloadedResticPassword) {
|
if (
|
||||||
|
session.data?.user &&
|
||||||
|
!session.data.user.hasDownloadedResticPassword &&
|
||||||
|
!hasSkippedRecoveryKeyDownload(session.data.user.id)
|
||||||
|
) {
|
||||||
void navigate({ to: "/download-recovery-key" });
|
void navigate({ to: "/download-recovery-key" });
|
||||||
} else {
|
} else {
|
||||||
void navigate({ to: "/volumes" });
|
void navigate({ to: "/volumes" });
|
||||||
|
|
@ -130,7 +194,10 @@ export function LoginPage({ error }: LoginPageProps = {}) {
|
||||||
|
|
||||||
if (requires2FA) {
|
if (requires2FA) {
|
||||||
return (
|
return (
|
||||||
<AuthLayout title="Two-Factor Authentication" description="Enter the 6-digit code from your authenticator app">
|
<AuthLayout
|
||||||
|
title="Two-Factor Authentication"
|
||||||
|
description="Enter the 6-digit code from your authenticator app"
|
||||||
|
>
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
<div className="space-y-4 flex flex-col items-center">
|
<div className="space-y-4 flex flex-col items-center">
|
||||||
<Label htmlFor="totp-code">Authentication code</Label>
|
<Label htmlFor="totp-code">Authentication code</Label>
|
||||||
|
|
@ -161,6 +228,7 @@ export function LoginPage({ error }: LoginPageProps = {}) {
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
id="trust-device"
|
id="trust-device"
|
||||||
|
aria-label="Trust this device for 30 days"
|
||||||
checked={trustDevice}
|
checked={trustDevice}
|
||||||
onChange={(e) => setTrustDevice(e.target.checked)}
|
onChange={(e) => setTrustDevice(e.target.checked)}
|
||||||
className="h-4 w-4"
|
className="h-4 w-4"
|
||||||
|
|
@ -199,7 +267,11 @@ export function LoginPage({ error }: LoginPageProps = {}) {
|
||||||
<AuthLayout title="Login to your account" description="Enter your credentials below to login to your account">
|
<AuthLayout title="Login to your account" description="Enter your credentials below to login to your account">
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
|
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
|
||||||
<div className={cn("rounded-md border border-destructive/50 p-3 text-sm", { hidden: !errorDescription })}>
|
<div
|
||||||
|
className={cn("rounded-md border border-destructive/50 p-3 text-sm", {
|
||||||
|
hidden: !errorDescription,
|
||||||
|
})}
|
||||||
|
>
|
||||||
{errorDescription}
|
{errorDescription}
|
||||||
</div>
|
</div>
|
||||||
<FormField
|
<FormField
|
||||||
|
|
@ -209,7 +281,13 @@ export function LoginPage({ error }: LoginPageProps = {}) {
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Username</FormLabel>
|
<FormLabel>Username</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input {...field} type="text" placeholder="admin" disabled={isLoggingIn} />
|
<Input
|
||||||
|
{...field}
|
||||||
|
type="text"
|
||||||
|
placeholder="admin"
|
||||||
|
disabled={isLoggingIn}
|
||||||
|
autoComplete="username webauthn"
|
||||||
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|
@ -231,7 +309,12 @@ export function LoginPage({ error }: LoginPageProps = {}) {
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input {...field} type="password" disabled={isLoggingIn} />
|
<Input
|
||||||
|
{...field}
|
||||||
|
type="password"
|
||||||
|
disabled={isLoggingIn}
|
||||||
|
autoComplete="current-password webauthn"
|
||||||
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|
@ -243,7 +326,7 @@ export function LoginPage({ error }: LoginPageProps = {}) {
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
|
|
||||||
<SsoLoginSection />
|
<AlternativeSignInSection onPasskeySignIn={navigateAfterLogin} />
|
||||||
|
|
||||||
<ResetPasswordDialog open={showResetDialog} onOpenChange={setShowResetDialog} />
|
<ResetPasswordDialog open={showResetDialog} onOpenChange={setShowResetDialog} />
|
||||||
</AuthLayout>
|
</AuthLayout>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from "~/client/components/ui/form";
|
import { FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from "~/client/components/ui/form";
|
||||||
import { Textarea } from "~/client/components/ui/textarea";
|
import { Textarea } from "~/client/components/ui/textarea";
|
||||||
import type { UseFormReturn } from "react-hook-form";
|
import { type UseFormReturn } from "react-hook-form";
|
||||||
import type { InternalFormValues } from "./types";
|
import type { InternalFormValues } from "./types";
|
||||||
import { Input } from "~/client/components/ui/input";
|
import { Input } from "~/client/components/ui/input";
|
||||||
|
|
||||||
|
|
@ -8,6 +8,74 @@ type AdvancedSectionProps = {
|
||||||
form: UseFormReturn<InternalFormValues>;
|
form: UseFormReturn<InternalFormValues>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type WebhookFieldsProps = {
|
||||||
|
form: UseFormReturn<InternalFormValues>;
|
||||||
|
phase: "pre" | "post";
|
||||||
|
urlPlaceholder: string;
|
||||||
|
bodyPlaceholder: string;
|
||||||
|
description: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const WebhookFields = ({ form, phase, urlPlaceholder, bodyPlaceholder, description }: WebhookFieldsProps) => {
|
||||||
|
const labelPrefix = phase === "pre" ? "Pre-backup" : "Post-backup";
|
||||||
|
const fieldPrefix = phase === "pre" ? "preBackupWebhook" : "postBackupWebhook";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name={`${fieldPrefix}Url`}
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>{labelPrefix} webhook</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input {...field} type="url" placeholder={urlPlaceholder} />
|
||||||
|
</FormControl>
|
||||||
|
<FormDescription>
|
||||||
|
{description} The URL origin must be listed in WEBHOOK_ALLOWED_ORIGINS; redirects are not followed.
|
||||||
|
</FormDescription>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name={`${fieldPrefix}HeadersText`}
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>{labelPrefix} webhook headers</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Textarea
|
||||||
|
{...field}
|
||||||
|
placeholder="Authorization: Bearer token X-Custom-Header: value"
|
||||||
|
className="font-mono text-sm min-h-24"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormDescription>
|
||||||
|
One header per line in Key: Value format. Values are stored as plain text.
|
||||||
|
</FormDescription>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name={`${fieldPrefix}Body`}
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>{labelPrefix} webhook body</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Textarea {...field} placeholder={bodyPlaceholder} className="font-mono text-sm min-h-24" />
|
||||||
|
</FormControl>
|
||||||
|
<FormDescription>Optional raw POST body. Leave empty to send the backup context JSON.</FormDescription>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export const AdvancedSection = ({ form }: AdvancedSectionProps) => {
|
export const AdvancedSection = ({ form }: AdvancedSectionProps) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
@ -56,6 +124,20 @@ export const AdvancedSection = ({ form }: AdvancedSectionProps) => {
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
<WebhookFields
|
||||||
|
form={form}
|
||||||
|
phase="pre"
|
||||||
|
urlPlaceholder="http://host.docker.internal:8080/stop"
|
||||||
|
bodyPlaceholder='{"action":"stop"}'
|
||||||
|
description="Called with POST before restic starts. A non-2xx response stops the backup."
|
||||||
|
/>
|
||||||
|
<WebhookFields
|
||||||
|
form={form}
|
||||||
|
phase="post"
|
||||||
|
urlPlaceholder="http://host.docker.internal:8080/start"
|
||||||
|
bodyPlaceholder='{"action":"start"}'
|
||||||
|
description="Called with POST after restic finishes, including failed or cancelled runs."
|
||||||
|
/>
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="customResticParamsText"
|
name="customResticParamsText"
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import { PathsSection } from "./paths-section";
|
||||||
import { RetentionSection } from "./retention-section";
|
import { RetentionSection } from "./retention-section";
|
||||||
import { SummarySection } from "./summary-section";
|
import { SummarySection } from "./summary-section";
|
||||||
import { internalFormSchema, type BackupScheduleFormValues, type InternalFormValues } from "./types";
|
import { internalFormSchema, type BackupScheduleFormValues, type InternalFormValues } from "./types";
|
||||||
import { backupScheduleToFormValues, parseMultilineEntries } from "./utils";
|
import { backupScheduleToFormValues, parseMultilineEntries, toWebhookConfig } from "./utils";
|
||||||
|
|
||||||
export type { BackupScheduleFormValues };
|
export type { BackupScheduleFormValues };
|
||||||
|
|
||||||
|
|
@ -46,12 +46,24 @@ export const CreateScheduleForm = ({ initialValues, formId, onSubmit, volume }:
|
||||||
cronExpression,
|
cronExpression,
|
||||||
maxRetries,
|
maxRetries,
|
||||||
retryDelay,
|
retryDelay,
|
||||||
|
preBackupWebhookUrl,
|
||||||
|
preBackupWebhookHeadersText,
|
||||||
|
preBackupWebhookBody,
|
||||||
|
postBackupWebhookUrl,
|
||||||
|
postBackupWebhookHeadersText,
|
||||||
|
postBackupWebhookBody,
|
||||||
...rest
|
...rest
|
||||||
} = data;
|
} = data;
|
||||||
const excludePatterns = parseMultilineEntries(excludePatternsText);
|
const excludePatterns = parseMultilineEntries(excludePatternsText);
|
||||||
const excludeIfPresent = parseMultilineEntries(excludeIfPresentText);
|
const excludeIfPresent = parseMultilineEntries(excludeIfPresentText);
|
||||||
const parsedIncludePatterns = parseMultilineEntries(includePatterns);
|
const parsedIncludePatterns = parseMultilineEntries(includePatterns);
|
||||||
const customResticParams = parseMultilineEntries(customResticParamsText);
|
const customResticParams = parseMultilineEntries(customResticParamsText);
|
||||||
|
const preBackupWebhook = toWebhookConfig(preBackupWebhookUrl, preBackupWebhookHeadersText, preBackupWebhookBody);
|
||||||
|
const postBackupWebhook = toWebhookConfig(
|
||||||
|
postBackupWebhookUrl,
|
||||||
|
postBackupWebhookHeadersText,
|
||||||
|
postBackupWebhookBody,
|
||||||
|
);
|
||||||
|
|
||||||
onSubmit({
|
onSubmit({
|
||||||
...rest,
|
...rest,
|
||||||
|
|
@ -61,6 +73,8 @@ export const CreateScheduleForm = ({ initialValues, formId, onSubmit, volume }:
|
||||||
excludePatterns,
|
excludePatterns,
|
||||||
excludeIfPresent,
|
excludeIfPresent,
|
||||||
customResticParams,
|
customResticParams,
|
||||||
|
backupWebhooks:
|
||||||
|
preBackupWebhook || postBackupWebhook ? { pre: preBackupWebhook, post: postBackupWebhook } : null,
|
||||||
maxRetries,
|
maxRetries,
|
||||||
retryDelay,
|
retryDelay,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,19 @@
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
import type { BackupWebhooks } from "@zerobyte/core/backup-hooks";
|
||||||
|
|
||||||
|
const webhookHeadersSchema = z.string().refine(
|
||||||
|
(value) =>
|
||||||
|
value
|
||||||
|
.split("\n")
|
||||||
|
.map((header) => header.trim())
|
||||||
|
.filter(Boolean)
|
||||||
|
.every((header) => {
|
||||||
|
const [key, value] = header.split(":", 2);
|
||||||
|
|
||||||
|
return /^[A-Za-z0-9-]+$/.test(key.trim()) && (value?.trim().length ?? 0) > 0;
|
||||||
|
}),
|
||||||
|
{ message: "Headers must use non-empty Key: Value format with valid header names" },
|
||||||
|
);
|
||||||
|
|
||||||
export const internalFormSchema = z.object({
|
export const internalFormSchema = z.object({
|
||||||
name: z.string().min(1).max(128),
|
name: z.string().min(1).max(128),
|
||||||
|
|
@ -20,6 +35,12 @@ export const internalFormSchema = z.object({
|
||||||
keepYearly: z.number().optional(),
|
keepYearly: z.number().optional(),
|
||||||
oneFileSystem: z.boolean().optional(),
|
oneFileSystem: z.boolean().optional(),
|
||||||
customResticParamsText: z.string().optional(),
|
customResticParamsText: z.string().optional(),
|
||||||
|
preBackupWebhookUrl: z.union([z.url(), z.literal("")]).optional(),
|
||||||
|
preBackupWebhookHeadersText: webhookHeadersSchema.optional(),
|
||||||
|
preBackupWebhookBody: z.string().optional(),
|
||||||
|
postBackupWebhookUrl: z.union([z.url(), z.literal("")]).optional(),
|
||||||
|
postBackupWebhookHeadersText: webhookHeadersSchema.optional(),
|
||||||
|
postBackupWebhookBody: z.string().optional(),
|
||||||
maxRetries: z.number().min(0).max(32).optional(),
|
maxRetries: z.number().min(0).max(32).optional(),
|
||||||
retryDelay: z.number().min(1).max(1440).optional(),
|
retryDelay: z.number().min(1).max(1440).optional(),
|
||||||
});
|
});
|
||||||
|
|
@ -38,10 +59,20 @@ export type InternalFormValues = z.infer<typeof internalFormSchema>;
|
||||||
|
|
||||||
export type BackupScheduleFormValues = Omit<
|
export type BackupScheduleFormValues = Omit<
|
||||||
InternalFormValues,
|
InternalFormValues,
|
||||||
"excludePatternsText" | "excludeIfPresentText" | "includePatterns" | "customResticParamsText"
|
| "excludePatternsText"
|
||||||
|
| "excludeIfPresentText"
|
||||||
|
| "includePatterns"
|
||||||
|
| "customResticParamsText"
|
||||||
|
| "preBackupWebhookUrl"
|
||||||
|
| "preBackupWebhookHeadersText"
|
||||||
|
| "preBackupWebhookBody"
|
||||||
|
| "postBackupWebhookUrl"
|
||||||
|
| "postBackupWebhookHeadersText"
|
||||||
|
| "postBackupWebhookBody"
|
||||||
> & {
|
> & {
|
||||||
excludePatterns?: string[];
|
excludePatterns?: string[];
|
||||||
excludeIfPresent?: string[];
|
excludeIfPresent?: string[];
|
||||||
includePatterns?: string[];
|
includePatterns?: string[];
|
||||||
customResticParams?: string[];
|
customResticParams?: string[];
|
||||||
|
backupWebhooks?: BackupWebhooks | null;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,29 @@ import type { BackupSchedule } from "~/client/lib/types";
|
||||||
import { cronToFormValues } from "../../lib/cron-utils";
|
import { cronToFormValues } from "../../lib/cron-utils";
|
||||||
import type { InternalFormValues } from "./types";
|
import type { InternalFormValues } from "./types";
|
||||||
|
|
||||||
export const parseMultilineEntries = (value?: string) =>
|
export const parseMultilineEntries = (value?: string) => {
|
||||||
value
|
if (!value) {
|
||||||
? value
|
return [];
|
||||||
.split("\n")
|
}
|
||||||
.map((entry) => entry.trim())
|
|
||||||
.filter(Boolean)
|
return value
|
||||||
: [];
|
.split("\n")
|
||||||
|
.map((entry) => entry.trim())
|
||||||
|
.filter(Boolean);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const toWebhookConfig = (url?: string, headers?: string, body?: string) => {
|
||||||
|
const trimmedUrl = url?.trim();
|
||||||
|
const parsedHeaders = parseMultilineEntries(headers);
|
||||||
|
|
||||||
|
return trimmedUrl
|
||||||
|
? {
|
||||||
|
url: trimmedUrl,
|
||||||
|
headers: parsedHeaders.length > 0 ? parsedHeaders : undefined,
|
||||||
|
body: body === "" ? undefined : body,
|
||||||
|
}
|
||||||
|
: null;
|
||||||
|
};
|
||||||
|
|
||||||
export const backupScheduleToFormValues = (schedule?: BackupSchedule): InternalFormValues | undefined => {
|
export const backupScheduleToFormValues = (schedule?: BackupSchedule): InternalFormValues | undefined => {
|
||||||
if (!schedule) {
|
if (!schedule) {
|
||||||
|
|
@ -26,6 +42,12 @@ export const backupScheduleToFormValues = (schedule?: BackupSchedule): InternalF
|
||||||
excludeIfPresentText: schedule.excludeIfPresent?.join("\n") || undefined,
|
excludeIfPresentText: schedule.excludeIfPresent?.join("\n") || undefined,
|
||||||
oneFileSystem: schedule.oneFileSystem ?? false,
|
oneFileSystem: schedule.oneFileSystem ?? false,
|
||||||
customResticParamsText: schedule.customResticParams?.join("\n") ?? "",
|
customResticParamsText: schedule.customResticParams?.join("\n") ?? "",
|
||||||
|
preBackupWebhookUrl: schedule.backupWebhooks?.pre?.url ?? "",
|
||||||
|
preBackupWebhookHeadersText: schedule.backupWebhooks?.pre?.headers?.join("\n") ?? "",
|
||||||
|
preBackupWebhookBody: schedule.backupWebhooks?.pre?.body ?? "",
|
||||||
|
postBackupWebhookUrl: schedule.backupWebhooks?.post?.url ?? "",
|
||||||
|
postBackupWebhookHeadersText: schedule.backupWebhooks?.post?.headers?.join("\n") ?? "",
|
||||||
|
postBackupWebhookBody: schedule.backupWebhooks?.post?.body ?? "",
|
||||||
maxRetries: schedule.maxRetries,
|
maxRetries: schedule.maxRetries,
|
||||||
retryDelay: schedule.retryDelay,
|
retryDelay: schedule.retryDelay,
|
||||||
...cronValues,
|
...cronValues,
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,7 @@ const schedule = {
|
||||||
excludeIfPresent: [],
|
excludeIfPresent: [],
|
||||||
oneFileSystem: false,
|
oneFileSystem: false,
|
||||||
customResticParams: [],
|
customResticParams: [],
|
||||||
|
backupWebhooks: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const snapshot = {
|
const snapshot = {
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ const renderEditBackupPage = ({ enabled, cronExpression }: { enabled: boolean; c
|
||||||
excludeIfPresent: [],
|
excludeIfPresent: [],
|
||||||
oneFileSystem: false,
|
oneFileSystem: false,
|
||||||
customResticParams: [],
|
customResticParams: [],
|
||||||
|
backupWebhooks: null,
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
http.get("/api/v1/repositories", () => {
|
http.get("/api/v1/repositories", () => {
|
||||||
|
|
@ -124,3 +125,28 @@ test("preserves a disabled schedule when saving a non-manual frequency", async (
|
||||||
cronExpression: "00 02 * * *",
|
cronExpression: "00 02 * * *",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("submits webhook headers and body as plain config values", async () => {
|
||||||
|
const { submittedBody } = renderEditBackupPage({ enabled: true, cronExpression: "0 2 * * *" });
|
||||||
|
|
||||||
|
await userEvent.click(await screen.findByText("Advanced"));
|
||||||
|
await userEvent.type(screen.getByLabelText("Pre-backup webhook"), "http://localhost:8080/stop");
|
||||||
|
fireEvent.change(screen.getByLabelText("Pre-backup webhook headers"), {
|
||||||
|
target: { value: "Authorization: Bearer stop-token" },
|
||||||
|
});
|
||||||
|
fireEvent.change(screen.getByLabelText("Pre-backup webhook body"), {
|
||||||
|
target: { value: '{"action":"stop"}' },
|
||||||
|
});
|
||||||
|
await userEvent.click(screen.getByRole("button", { name: "Update schedule" }));
|
||||||
|
|
||||||
|
await expect(submittedBody).resolves.toMatchObject({
|
||||||
|
backupWebhooks: {
|
||||||
|
pre: {
|
||||||
|
url: "http://localhost:8080/stop",
|
||||||
|
headers: ["Authorization: Bearer stop-token"],
|
||||||
|
body: '{"action":"stop"}',
|
||||||
|
},
|
||||||
|
post: null,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -63,9 +63,7 @@ export function ScheduleDetailsPage(props: Props) {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const searchParams = useSearch({ from: "/(dashboard)/backups/$backupId/" });
|
const searchParams = useSearch({ from: "/(dashboard)/backups/$backupId/" });
|
||||||
const [selectedSnapshotId, setSelectedSnapshotId] = useState<string | undefined>(
|
const [selectedSnapshotId, setSelectedSnapshotId] = useState<string | undefined>(initialSnapshotId);
|
||||||
initialSnapshotId ?? loaderData.snapshots?.at(-1)?.short_id,
|
|
||||||
);
|
|
||||||
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
|
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
|
||||||
const [snapshotToDelete, setSnapshotToDelete] = useState<string | null>(null);
|
const [snapshotToDelete, setSnapshotToDelete] = useState<string | null>(null);
|
||||||
|
|
||||||
|
|
@ -79,7 +77,10 @@ export function ScheduleDetailsPage(props: Props) {
|
||||||
isLoading,
|
isLoading,
|
||||||
failureReason,
|
failureReason,
|
||||||
} = useQuery({
|
} = useQuery({
|
||||||
...listSnapshotsOptions({ path: { shortId: schedule.repository.shortId }, query: { backupId: schedule.shortId } }),
|
...listSnapshotsOptions({
|
||||||
|
path: { shortId: schedule.repository.shortId },
|
||||||
|
query: { backupId: schedule.shortId },
|
||||||
|
}),
|
||||||
initialData: loaderData.snapshots,
|
initialData: loaderData.snapshots,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -167,6 +168,9 @@ export function ScheduleDetailsPage(props: Props) {
|
||||||
excludeIfPresent: schedule.excludeIfPresent || [],
|
excludeIfPresent: schedule.excludeIfPresent || [],
|
||||||
oneFileSystem: schedule.oneFileSystem,
|
oneFileSystem: schedule.oneFileSystem,
|
||||||
customResticParams: schedule.customResticParams || [],
|
customResticParams: schedule.customResticParams || [],
|
||||||
|
backupWebhooks: schedule.backupWebhooks,
|
||||||
|
maxRetries: schedule.maxRetries,
|
||||||
|
retryDelay: schedule.retryDelay,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
@ -252,8 +256,8 @@ export function ScheduleDetailsPage(props: Props) {
|
||||||
<AlertDialogHeader>
|
<AlertDialogHeader>
|
||||||
<AlertDialogTitle>Delete snapshot?</AlertDialogTitle>
|
<AlertDialogTitle>Delete snapshot?</AlertDialogTitle>
|
||||||
<AlertDialogDescription>
|
<AlertDialogDescription>
|
||||||
This action cannot be undone. This will permanently delete the snapshot and all its data from the
|
This action cannot be undone. This will permanently delete the snapshot and all its data
|
||||||
repository.
|
from the repository.
|
||||||
</AlertDialogDescription>
|
</AlertDialogDescription>
|
||||||
</AlertDialogHeader>
|
</AlertDialogHeader>
|
||||||
<AlertDialogFooter>
|
<AlertDialogFooter>
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,7 @@ export function CreateBackupPage() {
|
||||||
excludeIfPresent: formValues.excludeIfPresent,
|
excludeIfPresent: formValues.excludeIfPresent,
|
||||||
oneFileSystem: formValues.oneFileSystem,
|
oneFileSystem: formValues.oneFileSystem,
|
||||||
customResticParams: formValues.customResticParams,
|
customResticParams: formValues.customResticParams,
|
||||||
|
backupWebhooks: formValues.backupWebhooks,
|
||||||
maxRetries: formValues.maxRetries,
|
maxRetries: formValues.maxRetries,
|
||||||
retryDelay: formValues.retryDelay,
|
retryDelay: formValues.retryDelay,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,8 @@ export const CustomForm = ({ form }: Props) => {
|
||||||
>
|
>
|
||||||
Shoutrrr documentation
|
Shoutrrr documentation
|
||||||
</a>
|
</a>
|
||||||
for supported services and URL formats.
|
for supported services and URL formats. Custom HTTP, generic, and SMTP network targets must be listed
|
||||||
|
in WEBHOOK_ALLOWED_ORIGINS.
|
||||||
</FormDescription>
|
</FormDescription>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,7 @@ import { Input } from "~/client/components/ui/input";
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "~/client/components/ui/select";
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "~/client/components/ui/select";
|
||||||
import { Checkbox } from "~/client/components/ui/checkbox";
|
import { Checkbox } from "~/client/components/ui/checkbox";
|
||||||
import { Textarea } from "~/client/components/ui/textarea";
|
import { Textarea } from "~/client/components/ui/textarea";
|
||||||
import { CodeBlock } from "~/client/components/ui/code-block";
|
import { WebhookRequestPreview } from "~/client/components/webhook-request-preview";
|
||||||
import { Label } from "~/client/components/ui/label";
|
|
||||||
import type { NotificationFormValues } from "../create-notification-form";
|
import type { NotificationFormValues } from "../create-notification-form";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
|
@ -16,7 +15,7 @@ const WebhookPreview = ({ values }: { values: Partial<NotificationFormValues> })
|
||||||
if (values.type !== "generic") return null;
|
if (values.type !== "generic") return null;
|
||||||
|
|
||||||
const contentType = values.contentType || "application/json";
|
const contentType = values.contentType || "application/json";
|
||||||
const headers = values.headers || [];
|
const headers = values.headers?.filter(Boolean) || [];
|
||||||
const useJson = values.useJson;
|
const useJson = values.useJson;
|
||||||
const titleKey = values.titleKey || "title";
|
const titleKey = values.titleKey || "title";
|
||||||
const messageKey = values.messageKey || "message";
|
const messageKey = values.messageKey || "message";
|
||||||
|
|
@ -35,16 +34,14 @@ const WebhookPreview = ({ values }: { values: Partial<NotificationFormValues> })
|
||||||
body = "Notification message";
|
body = "Notification message";
|
||||||
}
|
}
|
||||||
|
|
||||||
const previewCode = `${values.method} ${values.url}\nContent-Type: ${contentType}${headers.length > 0 ? `\n${headers.join("\n")}` : ""}
|
|
||||||
|
|
||||||
${body}`;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-2 pt-4 border-t">
|
<WebhookRequestPreview
|
||||||
<Label>Request Preview</Label>
|
method={values.method || "POST"}
|
||||||
<CodeBlock code={previewCode} filename="HTTP Request" />
|
url={values.url}
|
||||||
<p className="text-[0.8rem] text-muted-foreground">This is a preview of the HTTP request that will be sent.</p>
|
contentType={contentType}
|
||||||
</div>
|
headers={headers}
|
||||||
|
body={body}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -63,7 +60,7 @@ export const GenericForm = ({ form }: Props) => {
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input {...field} placeholder="https://api.example.com/webhook" />
|
<Input {...field} placeholder="https://api.example.com/webhook" />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription>The target URL for the webhook.</FormDescription>
|
<FormDescription>The target origin must be listed in WEBHOOK_ALLOWED_ORIGINS.</FormDescription>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
|
|
@ -113,10 +110,19 @@ export const GenericForm = ({ form }: Props) => {
|
||||||
{...field}
|
{...field}
|
||||||
placeholder="Authorization: Bearer token X-Custom-Header: value"
|
placeholder="Authorization: Bearer token X-Custom-Header: value"
|
||||||
value={Array.isArray(field.value) ? field.value.join("\n") : ""}
|
value={Array.isArray(field.value) ? field.value.join("\n") : ""}
|
||||||
onChange={(e) => field.onChange(e.target.value.split("\n"))}
|
onChange={(e) =>
|
||||||
|
field.onChange(
|
||||||
|
e.target.value
|
||||||
|
.split("\n")
|
||||||
|
.map((header) => header.trim())
|
||||||
|
.filter(Boolean),
|
||||||
|
)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription>One header per line in Key: Value format.</FormDescription>
|
<FormDescription>
|
||||||
|
One header per line in Key: Value format. Values are stored as plain text.
|
||||||
|
</FormDescription>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,9 @@ export const GotifyForm = ({ form }: Props) => {
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input {...field} placeholder="https://gotify.example.com" />
|
<Input {...field} placeholder="https://gotify.example.com" />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription>Your self-hosted Gotify server URL.</FormDescription>
|
<FormDescription>
|
||||||
|
Your self-hosted Gotify server URL. Its origin must be listed in WEBHOOK_ALLOWED_ORIGINS.
|
||||||
|
</FormDescription>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,10 @@ export const NtfyForm = ({ form }: Props) => {
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input {...field} placeholder="https://ntfy.example.com" />
|
<Input {...field} placeholder="https://ntfy.example.com" />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription>Leave empty to use ntfy.sh public service.</FormDescription>
|
<FormDescription>
|
||||||
|
Leave empty to use ntfy.sh public service. Self-hosted ntfy origins must be listed in
|
||||||
|
WEBHOOK_ALLOWED_ORIGINS.
|
||||||
|
</FormDescription>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,8 @@ import {
|
||||||
Lock,
|
Lock,
|
||||||
Mail,
|
Mail,
|
||||||
AtSign,
|
AtSign,
|
||||||
|
AlertCircle,
|
||||||
|
Clock,
|
||||||
MessageSquare,
|
MessageSquare,
|
||||||
Pencil,
|
Pencil,
|
||||||
Server,
|
Server,
|
||||||
|
|
@ -55,6 +57,7 @@ import type { GetNotificationDestinationResponse } from "~/client/api-client/typ
|
||||||
import { useTimeFormat } from "~/client/lib/datetime";
|
import { useTimeFormat } from "~/client/lib/datetime";
|
||||||
|
|
||||||
type NotificationConfig = GetNotificationDestinationResponse["config"];
|
type NotificationConfig = GetNotificationDestinationResponse["config"];
|
||||||
|
type NotificationStatus = GetNotificationDestinationResponse["status"];
|
||||||
type Props = {
|
type Props = {
|
||||||
icon: React.ReactNode;
|
icon: React.ReactNode;
|
||||||
label: string;
|
label: string;
|
||||||
|
|
@ -72,6 +75,17 @@ function ConfigRow({ icon, label, value, mono }: Props) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getStatusLabel(enabled: boolean, status: NotificationStatus) {
|
||||||
|
return enabled ? status : "disabled";
|
||||||
|
}
|
||||||
|
|
||||||
|
function getStatusClass(enabled: boolean, status: NotificationStatus) {
|
||||||
|
if (!enabled) return "bg-gray-500";
|
||||||
|
if (status === "healthy") return "bg-success";
|
||||||
|
if (status === "error") return "bg-red-500";
|
||||||
|
return "bg-yellow-500";
|
||||||
|
}
|
||||||
|
|
||||||
function NotificationConfigRows({ config }: { config: NotificationConfig }) {
|
function NotificationConfigRows({ config }: { config: NotificationConfig }) {
|
||||||
switch (config.type) {
|
switch (config.type) {
|
||||||
case "slack":
|
case "slack":
|
||||||
|
|
@ -228,13 +242,8 @@ export function NotificationDetailsPage({ notificationId }: { notificationId: st
|
||||||
<h2 className="text-lg font-semibold tracking-tight">{data.name}</h2>
|
<h2 className="text-lg font-semibold tracking-tight">{data.name}</h2>
|
||||||
<Separator orientation="vertical" className="h-4 mx-1" />
|
<Separator orientation="vertical" className="h-4 mx-1" />
|
||||||
<Badge variant="outline" className="capitalize gap-1.5">
|
<Badge variant="outline" className="capitalize gap-1.5">
|
||||||
<span
|
<span className={cn("w-2 h-2 rounded-full shrink-0", getStatusClass(data.enabled, data.status))} />
|
||||||
className={cn("w-2 h-2 rounded-full shrink-0", {
|
{getStatusLabel(data.enabled, data.status)}
|
||||||
"bg-success": data.enabled,
|
|
||||||
"bg-red-500": !data.enabled,
|
|
||||||
})}
|
|
||||||
/>
|
|
||||||
{data.enabled ? "Enabled" : "Disabled"}
|
|
||||||
</Badge>
|
</Badge>
|
||||||
<Badge variant="secondary" className="capitalize">
|
<Badge variant="secondary" className="capitalize">
|
||||||
{data.type}
|
{data.type}
|
||||||
|
|
@ -289,6 +298,34 @@ export function NotificationDetailsPage({ notificationId }: { notificationId: st
|
||||||
<NotificationConfigRows config={data.config} />
|
<NotificationConfigRows config={data.config} />
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
<Card className="px-6 py-6">
|
||||||
|
<CardTitle className="flex items-center gap-2 mb-5">
|
||||||
|
<Clock className="h-4 w-4 text-muted-foreground" />
|
||||||
|
Delivery Health
|
||||||
|
</CardTitle>
|
||||||
|
<div className="space-y-0 divide-y divide-border/50">
|
||||||
|
<ConfigRow
|
||||||
|
icon={<Bell className="h-4 w-4" />}
|
||||||
|
label="Status"
|
||||||
|
value={getStatusLabel(data.enabled, data.status)}
|
||||||
|
/>
|
||||||
|
<ConfigRow icon={<Settings className="h-4 w-4" />} label="Enabled" value={data.enabled ? "Yes" : "No"} />
|
||||||
|
<ConfigRow
|
||||||
|
icon={<Clock className="h-4 w-4" />}
|
||||||
|
label="Last Checked"
|
||||||
|
value={data.lastChecked ? formatDateTime(data.lastChecked) : "Never"}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<Card className={cn("px-6 py-6", { hidden: !data.lastError })}>
|
||||||
|
<CardTitle className="flex items-center gap-2 mb-3 text-red-600">
|
||||||
|
<AlertCircle className="h-4 w-4" />
|
||||||
|
Last Delivery Error
|
||||||
|
</CardTitle>
|
||||||
|
<p className="text-sm text-muted-foreground wrap-break-word">{data.lastError}</p>
|
||||||
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<AlertDialog open={showDeleteConfirm} onOpenChange={setShowDeleteConfirm}>
|
<AlertDialog open={showDeleteConfirm} onOpenChange={setShowDeleteConfirm}>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,18 @@
|
||||||
import { useSuspenseQuery } from "@tanstack/react-query";
|
import { useSuspenseQuery } from "@tanstack/react-query";
|
||||||
|
import {
|
||||||
|
flexRender,
|
||||||
|
getCoreRowModel,
|
||||||
|
getFilteredRowModel,
|
||||||
|
getSortedRowModel,
|
||||||
|
type ColumnDef,
|
||||||
|
type ColumnFiltersState,
|
||||||
|
type SortingState,
|
||||||
|
useReactTable,
|
||||||
|
} from "@tanstack/react-table";
|
||||||
import { Bell, Plus, RotateCcw } from "lucide-react";
|
import { Bell, Plus, RotateCcw } from "lucide-react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
import { listNotificationDestinationsOptions } from "~/client/api-client/@tanstack/react-query.gen";
|
||||||
|
import { DataTableSortHeader } from "~/client/components/data-table-sort-header";
|
||||||
import { EmptyState } from "~/client/components/empty-state";
|
import { EmptyState } from "~/client/components/empty-state";
|
||||||
import { StatusDot } from "~/client/components/status-dot";
|
import { StatusDot } from "~/client/components/status-dot";
|
||||||
import { Button } from "~/client/components/ui/button";
|
import { Button } from "~/client/components/ui/button";
|
||||||
|
|
@ -8,20 +20,53 @@ import { Card } from "~/client/components/ui/card";
|
||||||
import { Input } from "~/client/components/ui/input";
|
import { Input } from "~/client/components/ui/input";
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "~/client/components/ui/select";
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "~/client/components/ui/select";
|
||||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "~/client/components/ui/table";
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "~/client/components/ui/table";
|
||||||
import { listNotificationDestinationsOptions } from "~/client/api-client/@tanstack/react-query.gen";
|
|
||||||
import { useNavigate } from "@tanstack/react-router";
|
import { useNavigate } from "@tanstack/react-router";
|
||||||
import { cn } from "~/client/lib/utils";
|
import { cn } from "~/client/lib/utils";
|
||||||
|
|
||||||
export function NotificationsPage() {
|
type NotificationRow = {
|
||||||
const [searchQuery, setSearchQuery] = useState("");
|
id: number;
|
||||||
const [typeFilter, setTypeFilter] = useState("");
|
name: string;
|
||||||
const [statusFilter, setStatusFilter] = useState("");
|
type: "email" | "slack" | "discord" | "gotify" | "ntfy" | "pushover" | "telegram" | "custom" | "generic";
|
||||||
|
enabled: boolean;
|
||||||
|
status: "healthy" | "error" | "unknown";
|
||||||
|
};
|
||||||
|
|
||||||
const clearFilters = () => {
|
const getNotificationStatus = (row: NotificationRow) => (row.enabled ? row.status : "disabled");
|
||||||
setSearchQuery("");
|
const getNotificationStatusVariant = (row: NotificationRow) => {
|
||||||
setTypeFilter("");
|
if (!row.enabled) return "neutral";
|
||||||
setStatusFilter("");
|
if (row.status === "healthy") return "success";
|
||||||
};
|
if (row.status === "error") return "error";
|
||||||
|
return "warning";
|
||||||
|
};
|
||||||
|
|
||||||
|
const notificationColumns: ColumnDef<NotificationRow>[] = [
|
||||||
|
{
|
||||||
|
accessorKey: "name",
|
||||||
|
header: ({ column }) => <DataTableSortHeader column={column} title="Name" sortDirection={column.getIsSorted()} />,
|
||||||
|
cell: ({ row }) => row.original.name,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "type",
|
||||||
|
header: ({ column }) => <DataTableSortHeader column={column} title="Type" sortDirection={column.getIsSorted()} />,
|
||||||
|
cell: ({ row }) => row.original.type,
|
||||||
|
filterFn: (row, id, value) => row.getValue(id) === value,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorFn: getNotificationStatus,
|
||||||
|
id: "status",
|
||||||
|
header: ({ column }) => (
|
||||||
|
<DataTableSortHeader column={column} title="Status" sortDirection={column.getIsSorted()} center />
|
||||||
|
),
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<StatusDot variant={getNotificationStatusVariant(row.original)} label={getNotificationStatus(row.original)} />
|
||||||
|
),
|
||||||
|
filterFn: (row, id, value) => row.getValue(id) === value,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export function NotificationsPage() {
|
||||||
|
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);
|
||||||
|
const [sorting, setSorting] = useState<SortingState>([]);
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
|
@ -29,15 +74,24 @@ export function NotificationsPage() {
|
||||||
...listNotificationDestinationsOptions(),
|
...listNotificationDestinationsOptions(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const filteredNotifications = data.filter((notification) => {
|
const table = useReactTable({
|
||||||
const matchesSearch = notification.name.toLowerCase().includes(searchQuery.toLowerCase());
|
data,
|
||||||
const matchesType = !typeFilter || notification.type === typeFilter;
|
columns: notificationColumns,
|
||||||
const matchesStatus = !statusFilter || (statusFilter === "enabled" ? notification.enabled : !notification.enabled);
|
state: { columnFilters, sorting },
|
||||||
return matchesSearch && matchesType && matchesStatus;
|
onColumnFiltersChange: setColumnFilters,
|
||||||
|
onSortingChange: setSorting,
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
getFilteredRowModel: getFilteredRowModel(),
|
||||||
|
getSortedRowModel: getSortedRowModel(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const rows = table.getRowModel().rows;
|
||||||
|
const hasFilters = columnFilters.length > 0;
|
||||||
|
|
||||||
|
const clearFilters = () => table.resetColumnFilters();
|
||||||
|
|
||||||
const hasNoNotifications = data.length === 0;
|
const hasNoNotifications = data.length === 0;
|
||||||
const hasNoFilteredNotifications = filteredNotifications.length === 0 && !hasNoNotifications;
|
const hasNoFilteredNotifications = rows.length === 0 && !hasNoNotifications;
|
||||||
|
|
||||||
if (hasNoNotifications) {
|
if (hasNoNotifications) {
|
||||||
return (
|
return (
|
||||||
|
|
@ -55,6 +109,10 @@ export function NotificationsPage() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const search = (table.getColumn("name")?.getFilterValue() as string) ?? "";
|
||||||
|
const type = (table.getColumn("type")?.getFilterValue() as string) ?? "";
|
||||||
|
const status = (table.getColumn("status")?.getFilterValue() as string) ?? "";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="p-0 gap-0">
|
<Card className="p-0 gap-0">
|
||||||
<div className="flex flex-col lg:flex-row items-stretch lg:items-center gap-2 md:justify-between p-4 bg-card-header py-4">
|
<div className="flex flex-col lg:flex-row items-stretch lg:items-center gap-2 md:justify-between p-4 bg-card-header py-4">
|
||||||
|
|
@ -62,10 +120,10 @@ export function NotificationsPage() {
|
||||||
<Input
|
<Input
|
||||||
className="w-full lg:w-45 min-w-45"
|
className="w-full lg:w-45 min-w-45"
|
||||||
placeholder="Search…"
|
placeholder="Search…"
|
||||||
value={searchQuery}
|
value={search}
|
||||||
onChange={(e) => setSearchQuery(e.target.value)}
|
onChange={(e) => table.getColumn("name")?.setFilterValue(e.target.value)}
|
||||||
/>
|
/>
|
||||||
<Select value={typeFilter} onValueChange={setTypeFilter}>
|
<Select value={type} onValueChange={(value) => table.getColumn("type")?.setFilterValue(value)}>
|
||||||
<SelectTrigger className="w-full lg:w-45 min-w-45">
|
<SelectTrigger className="w-full lg:w-45 min-w-45">
|
||||||
<SelectValue placeholder="All types" />
|
<SelectValue placeholder="All types" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
|
|
@ -77,19 +135,22 @@ export function NotificationsPage() {
|
||||||
<SelectItem value="ntfy">Ntfy</SelectItem>
|
<SelectItem value="ntfy">Ntfy</SelectItem>
|
||||||
<SelectItem value="pushover">Pushover</SelectItem>
|
<SelectItem value="pushover">Pushover</SelectItem>
|
||||||
<SelectItem value="telegram">Telegram</SelectItem>
|
<SelectItem value="telegram">Telegram</SelectItem>
|
||||||
|
<SelectItem value="generic">Generic</SelectItem>
|
||||||
<SelectItem value="custom">Custom</SelectItem>
|
<SelectItem value="custom">Custom</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
<Select value={statusFilter} onValueChange={setStatusFilter}>
|
<Select value={status} onValueChange={(value) => table.getColumn("status")?.setFilterValue(value)}>
|
||||||
<SelectTrigger className="w-full lg:w-45 min-w-45">
|
<SelectTrigger className="w-full lg:w-45 min-w-45">
|
||||||
<SelectValue placeholder="All status" />
|
<SelectValue placeholder="All status" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectItem value="enabled">Enabled</SelectItem>
|
<SelectItem value="healthy">Healthy</SelectItem>
|
||||||
|
<SelectItem value="error">Error</SelectItem>
|
||||||
|
<SelectItem value="unknown">Unknown</SelectItem>
|
||||||
<SelectItem value="disabled">Disabled</SelectItem>
|
<SelectItem value="disabled">Disabled</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
{(searchQuery || typeFilter || statusFilter) && (
|
{hasFilters && (
|
||||||
<Button onClick={clearFilters} className="w-full lg:w-auto mt-2 lg:mt-0 lg:ml-2">
|
<Button onClick={clearFilters} className="w-full lg:w-auto mt-2 lg:mt-0 lg:ml-2">
|
||||||
<RotateCcw className="h-4 w-4 mr-2" />
|
<RotateCcw className="h-4 w-4 mr-2" />
|
||||||
Clear filters
|
Clear filters
|
||||||
|
|
@ -104,11 +165,22 @@ export function NotificationsPage() {
|
||||||
<div className="overflow-x-auto">
|
<div className="overflow-x-auto">
|
||||||
<Table className="border-t">
|
<Table className="border-t">
|
||||||
<TableHeader className="bg-card-header">
|
<TableHeader className="bg-card-header">
|
||||||
<TableRow>
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
<TableHead className="w-25 uppercase">Name</TableHead>
|
<TableRow key={headerGroup.id}>
|
||||||
<TableHead className="uppercase text-left">Type</TableHead>
|
{headerGroup.headers.map((header) => (
|
||||||
<TableHead className="uppercase text-center">Status</TableHead>
|
<TableHead
|
||||||
</TableRow>
|
key={header.id}
|
||||||
|
className={cn("uppercase", {
|
||||||
|
"w-25": header.column.id === "name",
|
||||||
|
"text-left": header.column.id === "type",
|
||||||
|
"text-center": header.column.id === "status",
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
|
||||||
|
</TableHead>
|
||||||
|
))}
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
<TableRow className={cn({ hidden: !hasNoFilteredNotifications })}>
|
<TableRow className={cn({ hidden: !hasNoFilteredNotifications })}>
|
||||||
|
|
@ -122,30 +194,38 @@ export function NotificationsPage() {
|
||||||
</div>
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
{filteredNotifications.map((notification) => (
|
{rows.map((row) => (
|
||||||
<TableRow
|
<TableRow
|
||||||
key={notification.id}
|
key={row.original.id}
|
||||||
className="hover:bg-accent/50 hover:cursor-pointer h-12"
|
className="hover:bg-accent/50 hover:cursor-pointer h-12"
|
||||||
onClick={() => navigate({ to: `/notifications/${notification.id}` })}
|
onClick={() => navigate({ to: `/notifications/${row.original.id}` })}
|
||||||
>
|
>
|
||||||
<TableCell className="font-medium text-strong-accent">{notification.name}</TableCell>
|
{row.getVisibleCells().map((cell) => (
|
||||||
<TableCell className="capitalize text-muted-foreground">{notification.type}</TableCell>
|
<TableCell
|
||||||
<TableCell className="text-center">
|
key={cell.id}
|
||||||
<StatusDot
|
className={cn({
|
||||||
variant={notification.enabled ? "success" : "neutral"}
|
"font-medium text-strong-accent": cell.column.id === "name",
|
||||||
label={notification.enabled ? "Enabled" : "Disabled"}
|
"capitalize text-muted-foreground": cell.column.id === "type",
|
||||||
/>
|
"text-center": cell.column.id === "status",
|
||||||
</TableCell>
|
})}
|
||||||
|
>
|
||||||
|
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
||||||
|
</TableCell>
|
||||||
|
))}
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</div>
|
</div>
|
||||||
<div className="px-4 py-2 text-sm text-muted-foreground bg-card-header flex justify-end border-t">
|
<div className="px-4 py-2 text-sm text-muted-foreground bg-card-header flex justify-end border-t">
|
||||||
<span>
|
{hasNoFilteredNotifications ? (
|
||||||
<span className="text-strong-accent">{filteredNotifications.length}</span> destination
|
"No destinations match filters."
|
||||||
{filteredNotifications.length !== 1 ? "s" : ""}
|
) : (
|
||||||
</span>
|
<span>
|
||||||
|
<span className="text-strong-accent">{rows.length}</span> destination
|
||||||
|
{rows.length !== 1 ? "s" : ""}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,13 @@ const defaultValuesForType = (repoBase: string) => ({
|
||||||
azure: { backend: "azure" as const, compressionMode: "auto" as const },
|
azure: { backend: "azure" as const, compressionMode: "auto" as const },
|
||||||
rclone: { backend: "rclone" as const, compressionMode: "auto" as const },
|
rclone: { backend: "rclone" as const, compressionMode: "auto" as const },
|
||||||
rest: { backend: "rest" as const, compressionMode: "auto" as const },
|
rest: { backend: "rest" as const, compressionMode: "auto" as const },
|
||||||
sftp: { backend: "sftp" as const, compressionMode: "auto" as const, port: 22, skipHostKeyCheck: false },
|
sftp: {
|
||||||
|
backend: "sftp" as const,
|
||||||
|
compressionMode: "auto" as const,
|
||||||
|
port: 22,
|
||||||
|
skipHostKeyCheck: false,
|
||||||
|
allowLegacySshRsa: false,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const CreateRepositoryForm = ({
|
export const CreateRepositoryForm = ({
|
||||||
|
|
@ -251,7 +257,9 @@ export const CreateRepositoryForm = ({
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<FormLabel>Import existing repository</FormLabel>
|
<FormLabel>Import existing repository</FormLabel>
|
||||||
<FormDescription>Check this if the repository already exists at the specified location</FormDescription>
|
<FormDescription>
|
||||||
|
Check this if the repository already exists at the specified location
|
||||||
|
</FormDescription>
|
||||||
</div>
|
</div>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
|
|
@ -281,8 +289,8 @@ export const CreateRepositoryForm = ({
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
<FormDescription>
|
<FormDescription>
|
||||||
Choose whether to use Zerobyte's recovery key (which you downloaded when creating your account) or enter
|
Choose whether to use Zerobyte's recovery key (which you downloaded when creating your
|
||||||
a custom password for the existing repository.
|
account) or enter a custom password for the existing repository.
|
||||||
</FormDescription>
|
</FormDescription>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ export const AdvancedForm = ({ form }: Props) => {
|
||||||
const cacert = useWatch({ control: form.control, name: "cacert" });
|
const cacert = useWatch({ control: form.control, name: "cacert" });
|
||||||
const uploadLimitEnabled = useWatch({ control: form.control, name: "uploadLimit.enabled" });
|
const uploadLimitEnabled = useWatch({ control: form.control, name: "uploadLimit.enabled" });
|
||||||
const downloadLimitEnabled = useWatch({ control: form.control, name: "downloadLimit.enabled" });
|
const downloadLimitEnabled = useWatch({ control: form.control, name: "downloadLimit.enabled" });
|
||||||
|
const backend = useWatch({ control: form.control, name: "backend" });
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Collapsible>
|
<Collapsible>
|
||||||
|
|
@ -44,7 +45,9 @@ export const AdvancedForm = ({ form }: Props) => {
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<FormLabel>Enable upload speed limit</FormLabel>
|
<FormLabel>Enable upload speed limit</FormLabel>
|
||||||
<FormDescription className="text-xs">Limit upload speed to the repository</FormDescription>
|
<FormDescription className="text-xs">
|
||||||
|
Limit upload speed to the repository
|
||||||
|
</FormDescription>
|
||||||
</div>
|
</div>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
|
|
@ -66,7 +69,9 @@ export const AdvancedForm = ({ form }: Props) => {
|
||||||
placeholder="10"
|
placeholder="10"
|
||||||
className="pr-12"
|
className="pr-12"
|
||||||
{...field}
|
{...field}
|
||||||
onChange={(e) => field.onChange(parseFloat(e.target.value) || 1)}
|
onChange={(e) =>
|
||||||
|
field.onChange(parseFloat(e.target.value) || 1)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<div className="absolute inset-y-0 right-0 flex items-center pr-3">
|
<div className="absolute inset-y-0 right-0 flex items-center pr-3">
|
||||||
<div className="h-4 w-px bg-border" />
|
<div className="h-4 w-px bg-border" />
|
||||||
|
|
@ -120,7 +125,9 @@ export const AdvancedForm = ({ form }: Props) => {
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<FormLabel>Enable download speed limit</FormLabel>
|
<FormLabel>Enable download speed limit</FormLabel>
|
||||||
<FormDescription className="text-xs">Limit download speed from the repository</FormDescription>
|
<FormDescription className="text-xs">
|
||||||
|
Limit download speed from the repository
|
||||||
|
</FormDescription>
|
||||||
</div>
|
</div>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
|
|
@ -144,7 +151,9 @@ export const AdvancedForm = ({ form }: Props) => {
|
||||||
disabled={!downloadLimitEnabled}
|
disabled={!downloadLimitEnabled}
|
||||||
className="pr-12"
|
className="pr-12"
|
||||||
{...field}
|
{...field}
|
||||||
onChange={(e) => field.onChange(parseFloat(e.target.value) || 1)}
|
onChange={(e) =>
|
||||||
|
field.onChange(parseFloat(e.target.value) || 1)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<div className="absolute inset-y-0 right-0 flex items-center pr-3">
|
<div className="absolute inset-y-0 right-0 flex items-center pr-3">
|
||||||
<div className="h-4 w-px bg-border" />
|
<div className="h-4 w-px bg-border" />
|
||||||
|
|
@ -208,8 +217,8 @@ export const AdvancedForm = ({ form }: Props) => {
|
||||||
</TooltipTrigger>
|
</TooltipTrigger>
|
||||||
<TooltipContent className={cn({ hidden: !cacert })}>
|
<TooltipContent className={cn({ hidden: !cacert })}>
|
||||||
<p className="max-w-xs">
|
<p className="max-w-xs">
|
||||||
This option is disabled because a CA certificate is provided. Remove the CA certificate to skip
|
This option is disabled because a CA certificate is provided. Remove the CA
|
||||||
TLS validation instead.
|
certificate to skip TLS validation instead.
|
||||||
</p>
|
</p>
|
||||||
</TooltipContent>
|
</TooltipContent>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|
@ -217,8 +226,8 @@ export const AdvancedForm = ({ form }: Props) => {
|
||||||
<div className="space-y-1 leading-none">
|
<div className="space-y-1 leading-none">
|
||||||
<FormLabel>Skip TLS certificate verification</FormLabel>
|
<FormLabel>Skip TLS certificate verification</FormLabel>
|
||||||
<FormDescription>
|
<FormDescription>
|
||||||
Disable TLS certificate verification for HTTPS connections with self-signed certificates. This is
|
Disable TLS certificate verification for HTTPS connections with self-signed
|
||||||
insecure and should only be used for testing.
|
certificates. This is insecure and should only be used for testing.
|
||||||
</FormDescription>
|
</FormDescription>
|
||||||
</div>
|
</div>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|
@ -235,7 +244,9 @@ export const AdvancedForm = ({ form }: Props) => {
|
||||||
<TooltipTrigger asChild>
|
<TooltipTrigger asChild>
|
||||||
<div>
|
<div>
|
||||||
<Textarea
|
<Textarea
|
||||||
placeholder={"-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----"}
|
placeholder={
|
||||||
|
"-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----"
|
||||||
|
}
|
||||||
rows={6}
|
rows={6}
|
||||||
disabled={insecureTls}
|
disabled={insecureTls}
|
||||||
{...field}
|
{...field}
|
||||||
|
|
@ -244,8 +255,8 @@ export const AdvancedForm = ({ form }: Props) => {
|
||||||
</TooltipTrigger>
|
</TooltipTrigger>
|
||||||
<TooltipContent className={cn({ hidden: !insecureTls })}>
|
<TooltipContent className={cn({ hidden: !insecureTls })}>
|
||||||
<p className="max-w-xs">
|
<p className="max-w-xs">
|
||||||
CA certificate is disabled because TLS validation is being skipped. Uncheck "Skip TLS Certificate
|
CA certificate is disabled because TLS validation is being skipped. Uncheck
|
||||||
Verification" to provide a custom CA certificate.
|
"Skip TLS Certificate Verification" to provide a custom CA certificate.
|
||||||
</p>
|
</p>
|
||||||
</TooltipContent>
|
</TooltipContent>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|
@ -266,6 +277,26 @@ export const AdvancedForm = ({ form }: Props) => {
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
{backend === "sftp" && (
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="allowLegacySshRsa"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem className="flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm">
|
||||||
|
<div className="space-y-0.5">
|
||||||
|
<FormLabel>Allow legacy SSH RSA/SHA1 algorithms</FormLabel>
|
||||||
|
<FormDescription>
|
||||||
|
Only enable this for legacy SFTP servers that offer <code>ssh-rsa</code> only.
|
||||||
|
It permits RSA/SHA1 signatures, which are weaker than modern SSH algorithms.
|
||||||
|
</FormDescription>
|
||||||
|
</div>
|
||||||
|
<FormControl>
|
||||||
|
<Checkbox checked={field.value ?? false} onCheckedChange={field.onChange} />
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</CollapsibleContent>
|
</CollapsibleContent>
|
||||||
</Collapsible>
|
</Collapsible>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,18 @@
|
||||||
import { useSuspenseQuery } from "@tanstack/react-query";
|
import { useSuspenseQuery } from "@tanstack/react-query";
|
||||||
|
import {
|
||||||
|
flexRender,
|
||||||
|
getCoreRowModel,
|
||||||
|
getFilteredRowModel,
|
||||||
|
getSortedRowModel,
|
||||||
|
type ColumnDef,
|
||||||
|
type ColumnFiltersState,
|
||||||
|
type SortingState,
|
||||||
|
useReactTable,
|
||||||
|
} from "@tanstack/react-table";
|
||||||
import { Database, Plus, RotateCcw } from "lucide-react";
|
import { Database, Plus, RotateCcw } from "lucide-react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { listRepositoriesOptions } from "~/client/api-client/@tanstack/react-query.gen";
|
import { listRepositoriesOptions } from "~/client/api-client/@tanstack/react-query.gen";
|
||||||
|
import { DataTableSortHeader } from "~/client/components/data-table-sort-header";
|
||||||
import { RepositoryIcon } from "~/client/components/repository-icon";
|
import { RepositoryIcon } from "~/client/components/repository-icon";
|
||||||
import { Button } from "~/client/components/ui/button";
|
import { Button } from "~/client/components/ui/button";
|
||||||
import { Card } from "~/client/components/ui/card";
|
import { Card } from "~/client/components/ui/card";
|
||||||
|
|
@ -12,17 +23,73 @@ import { cn } from "~/client/lib/utils";
|
||||||
import { StatusDot } from "~/client/components/status-dot";
|
import { StatusDot } from "~/client/components/status-dot";
|
||||||
import { EmptyState } from "~/client/components/empty-state";
|
import { EmptyState } from "~/client/components/empty-state";
|
||||||
import { useNavigate } from "@tanstack/react-router";
|
import { useNavigate } from "@tanstack/react-router";
|
||||||
|
import type { RepositoryBackend } from "@zerobyte/core/restic";
|
||||||
|
|
||||||
|
type RepositoryRow = {
|
||||||
|
id: string;
|
||||||
|
shortId: string;
|
||||||
|
name: string;
|
||||||
|
type: RepositoryBackend;
|
||||||
|
status: string | null;
|
||||||
|
compressionMode?: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const repositoryColumns: ColumnDef<RepositoryRow>[] = [
|
||||||
|
{
|
||||||
|
accessorKey: "name",
|
||||||
|
header: ({ column }) => <DataTableSortHeader column={column} title="Name" sortDirection={column.getIsSorted()} />,
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span>{row.original.name}</span>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "type",
|
||||||
|
header: ({ column }) => (
|
||||||
|
<DataTableSortHeader column={column} title="Backend" sortDirection={column.getIsSorted()} />
|
||||||
|
),
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<span className="flex items-center gap-2 text-muted-foreground">
|
||||||
|
<RepositoryIcon backend={row.original.type} />
|
||||||
|
{row.original.type}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
filterFn: (row, id, value) => row.getValue(id) === value,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorFn: (row) => row.compressionMode || "off",
|
||||||
|
id: "compressionMode",
|
||||||
|
header: ({ column }) => (
|
||||||
|
<DataTableSortHeader column={column} title="Compression" sortDirection={column.getIsSorted()} />
|
||||||
|
),
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<span className="text-muted-foreground text-xs bg-primary/10 rounded-md px-2 py-1">
|
||||||
|
{row.original.compressionMode || "off"}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
sortingFn: "alphanumeric",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorFn: (row) => row.status || "unknown",
|
||||||
|
id: "status",
|
||||||
|
header: ({ column }) => (
|
||||||
|
<DataTableSortHeader column={column} title="Status" sortDirection={column.getIsSorted()} center />
|
||||||
|
),
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<StatusDot
|
||||||
|
variant={row.original.status === "healthy" ? "success" : row.original.status === "error" ? "error" : "warning"}
|
||||||
|
label={row.original.status || "unknown"}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
sortingFn: "alphanumeric",
|
||||||
|
filterFn: (row, id, value) => row.getValue(id) === value,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
export function RepositoriesPage() {
|
export function RepositoriesPage() {
|
||||||
const [searchQuery, setSearchQuery] = useState("");
|
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);
|
||||||
const [statusFilter, setStatusFilter] = useState("");
|
const [sorting, setSorting] = useState<SortingState>([{ id: "name", desc: false }]);
|
||||||
const [backendFilter, setBackendFilter] = useState("");
|
|
||||||
|
|
||||||
const clearFilters = () => {
|
|
||||||
setSearchQuery("");
|
|
||||||
setStatusFilter("");
|
|
||||||
setBackendFilter("");
|
|
||||||
};
|
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
|
@ -30,15 +97,23 @@ export function RepositoriesPage() {
|
||||||
...listRepositoriesOptions(),
|
...listRepositoriesOptions(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const filteredRepositories = data.filter((repository) => {
|
const table = useReactTable({
|
||||||
const matchesSearch = repository.name.toLowerCase().includes(searchQuery.toLowerCase());
|
data,
|
||||||
const matchesStatus = !statusFilter || repository.status === statusFilter;
|
columns: repositoryColumns,
|
||||||
const matchesBackend = !backendFilter || repository.type === backendFilter;
|
state: { columnFilters, sorting },
|
||||||
return matchesSearch && matchesStatus && matchesBackend;
|
onColumnFiltersChange: setColumnFilters,
|
||||||
|
onSortingChange: setSorting,
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
getFilteredRowModel: getFilteredRowModel(),
|
||||||
|
getSortedRowModel: getSortedRowModel(),
|
||||||
});
|
});
|
||||||
|
const rows = table.getRowModel().rows;
|
||||||
|
const hasFilters = columnFilters.length > 0;
|
||||||
|
|
||||||
|
const clearFilters = () => table.resetColumnFilters();
|
||||||
|
|
||||||
const hasNoRepositories = data.length === 0;
|
const hasNoRepositories = data.length === 0;
|
||||||
const hasNoFilteredRepositories = filteredRepositories.length === 0 && !hasNoRepositories;
|
const hasNoFilteredRepositories = rows.length === 0 && !hasNoRepositories;
|
||||||
|
|
||||||
if (hasNoRepositories) {
|
if (hasNoRepositories) {
|
||||||
return (
|
return (
|
||||||
|
|
@ -56,6 +131,10 @@ export function RepositoriesPage() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const search = (table.getColumn("name")?.getFilterValue() as string) ?? "";
|
||||||
|
const type = (table.getColumn("type")?.getFilterValue() as string) ?? "";
|
||||||
|
const status = (table.getColumn("status")?.getFilterValue() as string) ?? "";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="p-0 gap-0">
|
<Card className="p-0 gap-0">
|
||||||
<div className="flex flex-col lg:flex-row items-stretch lg:items-center gap-2 md:justify-between p-4 bg-card-header py-4">
|
<div className="flex flex-col lg:flex-row items-stretch lg:items-center gap-2 md:justify-between p-4 bg-card-header py-4">
|
||||||
|
|
@ -63,10 +142,10 @@ export function RepositoriesPage() {
|
||||||
<Input
|
<Input
|
||||||
className="w-full lg:w-45 min-w-45"
|
className="w-full lg:w-45 min-w-45"
|
||||||
placeholder="Search…"
|
placeholder="Search…"
|
||||||
value={searchQuery}
|
value={search}
|
||||||
onChange={(e) => setSearchQuery(e.target.value)}
|
onChange={(e) => table.getColumn("name")?.setFilterValue(e.target.value)}
|
||||||
/>
|
/>
|
||||||
<Select value={statusFilter} onValueChange={setStatusFilter}>
|
<Select value={status} onValueChange={(value) => table.getColumn("status")?.setFilterValue(value)}>
|
||||||
<SelectTrigger className="w-full lg:w-45 min-w-45">
|
<SelectTrigger className="w-full lg:w-45 min-w-45">
|
||||||
<SelectValue placeholder="All status" />
|
<SelectValue placeholder="All status" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
|
|
@ -76,7 +155,7 @@ export function RepositoriesPage() {
|
||||||
<SelectItem value="unknown">Unknown</SelectItem>
|
<SelectItem value="unknown">Unknown</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
<Select value={backendFilter} onValueChange={setBackendFilter}>
|
<Select value={type} onValueChange={(value) => table.getColumn("type")?.setFilterValue(value)}>
|
||||||
<SelectTrigger className="w-full lg:w-45 min-w-45">
|
<SelectTrigger className="w-full lg:w-45 min-w-45">
|
||||||
<SelectValue placeholder="All backends" />
|
<SelectValue placeholder="All backends" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
|
|
@ -87,7 +166,7 @@ export function RepositoriesPage() {
|
||||||
<SelectItem value="gcs">Google Cloud Storage</SelectItem>
|
<SelectItem value="gcs">Google Cloud Storage</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
{(searchQuery || statusFilter || backendFilter) && (
|
{hasFilters && (
|
||||||
<Button onClick={clearFilters} className="w-full lg:w-auto mt-2 lg:mt-0 lg:ml-2">
|
<Button onClick={clearFilters} className="w-full lg:w-auto mt-2 lg:mt-0 lg:ml-2">
|
||||||
<RotateCcw className="h-4 w-4 mr-2" />
|
<RotateCcw className="h-4 w-4 mr-2" />
|
||||||
Clear filters
|
Clear filters
|
||||||
|
|
@ -102,12 +181,23 @@ export function RepositoriesPage() {
|
||||||
<div className="overflow-x-auto">
|
<div className="overflow-x-auto">
|
||||||
<Table className="border-t">
|
<Table className="border-t">
|
||||||
<TableHeader className="bg-card-header">
|
<TableHeader className="bg-card-header">
|
||||||
<TableRow>
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
<TableHead className="w-25 uppercase">Name</TableHead>
|
<TableRow key={headerGroup.id}>
|
||||||
<TableHead className="uppercase text-left">Backend</TableHead>
|
{headerGroup.headers.map((header) => (
|
||||||
<TableHead className="uppercase hidden sm:table-cell">Compression</TableHead>
|
<TableHead
|
||||||
<TableHead className="uppercase text-center">Status</TableHead>
|
key={header.id}
|
||||||
</TableRow>
|
className={cn("uppercase", {
|
||||||
|
"w-25": header.column.id === "name",
|
||||||
|
"text-left": header.column.id === "type",
|
||||||
|
"hidden sm:table-cell": header.column.id === "compressionMode",
|
||||||
|
"text-center": header.column.id === "status",
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
|
||||||
|
</TableHead>
|
||||||
|
))}
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
<TableRow className={cn({ hidden: !hasNoFilteredRepositories })}>
|
<TableRow className={cn({ hidden: !hasNoFilteredRepositories })}>
|
||||||
|
|
@ -121,38 +211,24 @@ export function RepositoriesPage() {
|
||||||
</div>
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
{filteredRepositories.map((repository) => (
|
{rows.map((row) => (
|
||||||
<TableRow
|
<TableRow
|
||||||
key={repository.id}
|
key={row.original.id}
|
||||||
className="hover:bg-accent/50 hover:cursor-pointer h-12"
|
className="hover:bg-accent/50 hover:cursor-pointer h-12"
|
||||||
onClick={() => navigate({ to: `/repositories/${repository.shortId}` })}
|
onClick={() => navigate({ to: `/repositories/${row.original.shortId}` })}
|
||||||
>
|
>
|
||||||
<TableCell className="font-medium text-strong-accent">
|
{row.getVisibleCells().map((cell) => (
|
||||||
<div className="flex items-center gap-2">
|
<TableCell
|
||||||
<span>{repository.name}</span>
|
key={cell.id}
|
||||||
</div>
|
className={cn({
|
||||||
</TableCell>
|
"font-medium text-strong-accent": cell.column.id === "name",
|
||||||
<TableCell>
|
"hidden sm:table-cell": cell.column.id === "compressionMode",
|
||||||
<span className="flex items-center gap-2 text-muted-foreground">
|
"text-center": cell.column.id === "status",
|
||||||
<RepositoryIcon backend={repository.type} />
|
})}
|
||||||
{repository.type}
|
>
|
||||||
</span>
|
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="hidden sm:table-cell">
|
))}
|
||||||
<span className="text-muted-foreground text-xs bg-primary/10 rounded-md px-2 py-1">
|
|
||||||
{repository.compressionMode || "off"}
|
|
||||||
</span>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell className="text-center">
|
|
||||||
<StatusDot
|
|
||||||
variant={
|
|
||||||
repository.status === "healthy" ? "success" : repository.status === "error" ? "error" : "warning"
|
|
||||||
}
|
|
||||||
label={
|
|
||||||
repository.status ? repository.status[0].toUpperCase() + repository.status.slice(1) : "Unknown"
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
|
|
@ -163,8 +239,8 @@ export function RepositoriesPage() {
|
||||||
"No repositories match filters."
|
"No repositories match filters."
|
||||||
) : (
|
) : (
|
||||||
<span>
|
<span>
|
||||||
<span className="text-strong-accent">{filteredRepositories.length}</span> repositor
|
<span className="text-strong-accent">{rows.length}</span> repositor
|
||||||
{filteredRepositories.length === 1 ? "y" : "ies"}
|
{rows.length === 1 ? "y" : "ies"}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
322
app/client/modules/settings/components/passkeys-section.tsx
Normal file
322
app/client/modules/settings/components/passkeys-section.tsx
Normal file
|
|
@ -0,0 +1,322 @@
|
||||||
|
import { useState } from "react";
|
||||||
|
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||||
|
import { Fingerprint, Plus, Trash2, Pencil } from "lucide-react";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
import { Button } from "~/client/components/ui/button";
|
||||||
|
import { CardContent, CardDescription, CardTitle } from "~/client/components/ui/card";
|
||||||
|
import {
|
||||||
|
AlertDialog,
|
||||||
|
AlertDialogAction,
|
||||||
|
AlertDialogCancel,
|
||||||
|
AlertDialogContent,
|
||||||
|
AlertDialogDescription,
|
||||||
|
AlertDialogFooter,
|
||||||
|
AlertDialogHeader,
|
||||||
|
AlertDialogTitle,
|
||||||
|
} from "~/client/components/ui/alert-dialog";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "~/client/components/ui/dialog";
|
||||||
|
import { Input } from "~/client/components/ui/input";
|
||||||
|
import { Label } from "~/client/components/ui/label";
|
||||||
|
import { Tooltip, TooltipContent, TooltipTrigger } from "~/client/components/ui/tooltip";
|
||||||
|
import { getIsSecureContext } from "~/client/functions/is-secure-context";
|
||||||
|
import { authClient } from "~/client/lib/auth-client";
|
||||||
|
import { logger } from "~/client/lib/logger";
|
||||||
|
import { useTimeFormat } from "~/client/lib/datetime";
|
||||||
|
import { cn } from "~/client/lib/utils";
|
||||||
|
|
||||||
|
type PasskeyEntry = {
|
||||||
|
id: string;
|
||||||
|
name?: string | null;
|
||||||
|
createdAt: Date | string;
|
||||||
|
deviceType?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function PasskeysSection() {
|
||||||
|
const { formatDateTime } = useTimeFormat();
|
||||||
|
const isSecureContext = getIsSecureContext();
|
||||||
|
const { data: passkeys, isPending } = useQuery({
|
||||||
|
queryKey: ["passkeys"],
|
||||||
|
queryFn: async () => {
|
||||||
|
const { data, error } = await authClient.passkey.listUserPasskeys();
|
||||||
|
if (error) throw error;
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const [deletePasskeyOpen, setDeletePasskeyOpen] = useState(false);
|
||||||
|
const [addDialogOpen, setAddDialogOpen] = useState(false);
|
||||||
|
const [newPasskeyName, setNewPasskeyName] = useState("");
|
||||||
|
|
||||||
|
const [renameTarget, setRenameTarget] = useState<PasskeyEntry | null>(null);
|
||||||
|
const [renameValue, setRenameValue] = useState("");
|
||||||
|
|
||||||
|
const [deleteTarget, setDeleteTarget] = useState<PasskeyEntry | null>(null);
|
||||||
|
|
||||||
|
const addPasskeyMutation = useMutation({
|
||||||
|
mutationFn: async (name: string | undefined) => {
|
||||||
|
const { error } = await authClient.passkey.addPasskey({ name });
|
||||||
|
if (error) throw error;
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
toast.success("Passkey added");
|
||||||
|
setAddDialogOpen(false);
|
||||||
|
setNewPasskeyName("");
|
||||||
|
},
|
||||||
|
onError: (error: Error) => {
|
||||||
|
logger.error(error);
|
||||||
|
toast.error("Failed to add passkey", { description: error.message });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const renamePasskeyMutation = useMutation({
|
||||||
|
mutationFn: async ({ id, name }: { id: string; name: string }) => {
|
||||||
|
const { error } = await authClient.$fetch("/passkey/update-passkey", {
|
||||||
|
method: "POST",
|
||||||
|
body: { id, name },
|
||||||
|
});
|
||||||
|
if (error) throw error;
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
toast.success("Passkey renamed");
|
||||||
|
setRenameTarget(null);
|
||||||
|
setRenameValue("");
|
||||||
|
},
|
||||||
|
onError: (error: Error) => {
|
||||||
|
logger.error(error);
|
||||||
|
toast.error("Failed to rename passkey", { description: error.message });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const deletePasskeyMutation = useMutation({
|
||||||
|
mutationFn: async (id: string) => {
|
||||||
|
const { error } = await authClient.passkey.deletePasskey({ id });
|
||||||
|
if (error) throw error;
|
||||||
|
},
|
||||||
|
onMutate: () => {
|
||||||
|
setDeletePasskeyOpen(false);
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
toast.success("Passkey deleted");
|
||||||
|
setDeleteTarget(null);
|
||||||
|
},
|
||||||
|
onError: (error: Error) => {
|
||||||
|
logger.error(error);
|
||||||
|
toast.error("Failed to delete passkey", { description: error.message });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleAddPasskey = (e: React.ChangeEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!isSecureContext) return;
|
||||||
|
|
||||||
|
const name = newPasskeyName.trim() || undefined;
|
||||||
|
addPasskeyMutation.mutate(name);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRename = (e: React.ChangeEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!renameTarget) return;
|
||||||
|
const name = renameValue.trim();
|
||||||
|
if (!name) {
|
||||||
|
toast.error("Name is required");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
renamePasskeyMutation.mutate({ id: renameTarget.id, name });
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDelete = () => {
|
||||||
|
if (!deleteTarget) return;
|
||||||
|
deletePasskeyMutation.mutate(deleteTarget.id);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="border-t border-border/50 bg-card-header p-6">
|
||||||
|
<CardTitle className="flex items-center gap-2">
|
||||||
|
<Fingerprint className="size-5" />
|
||||||
|
Passkeys
|
||||||
|
</CardTitle>
|
||||||
|
<CardDescription className="mt-1.5">
|
||||||
|
Sign in faster and more securely with passkeys stored on your device or password manager. You can
|
||||||
|
add more than one.
|
||||||
|
</CardDescription>
|
||||||
|
</div>
|
||||||
|
<CardContent className="p-6 space-y-4">
|
||||||
|
<div className="flex items-start justify-between gap-4">
|
||||||
|
<p className="text-xs text-muted-foreground max-w-xl">
|
||||||
|
Passkeys use your device's biometrics or screen lock instead of a password. They are
|
||||||
|
phishing-resistant and cannot be reused across sites.
|
||||||
|
</p>
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<span className="inline-flex">
|
||||||
|
<Button onClick={() => setAddDialogOpen(true)} disabled={!isSecureContext}>
|
||||||
|
<Plus className="h-4 w-4 mr-2" />
|
||||||
|
Add passkey
|
||||||
|
</Button>
|
||||||
|
</span>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent className={cn({ hidden: isSecureContext })}>
|
||||||
|
<p>Passkeys can only be added over HTTPS or from localhost.</p>
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p className={cn("text-sm text-muted-foreground", { hidden: !isPending })}>Loading passkeys...</p>
|
||||||
|
<p className={cn("text-sm text-muted-foreground", { hidden: passkeys && passkeys.length > 0 })}>
|
||||||
|
No passkeys yet. Add one to enable passwordless sign-in.
|
||||||
|
</p>
|
||||||
|
<ul
|
||||||
|
className={cn("divide-y divide-border/50 rounded-md border border-border/50", {
|
||||||
|
hidden: passkeys?.length === 0,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{passkeys?.map((p) => (
|
||||||
|
<li key={p.id} className="flex items-center justify-between gap-4 p-3">
|
||||||
|
<div className="min-w-0 flex-1">
|
||||||
|
<p className="text-sm font-medium truncate">{p.name?.trim() || "Unnamed passkey"}</p>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
Added {formatDateTime(new Date(p.createdAt))}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
aria-label={`Rename passkey ${p.name?.trim() || "Unnamed passkey"}`}
|
||||||
|
title={`Rename passkey ${p.name?.trim() || "Unnamed passkey"}`}
|
||||||
|
onClick={() => {
|
||||||
|
setRenameTarget(p);
|
||||||
|
setRenameValue(p.name ?? "");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Pencil className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="destructive"
|
||||||
|
size="sm"
|
||||||
|
aria-label={`Delete passkey ${p.name?.trim() || "Unnamed passkey"}`}
|
||||||
|
title={`Delete passkey ${p.name?.trim() || "Unnamed passkey"}`}
|
||||||
|
onClick={() => {
|
||||||
|
setDeleteTarget(p);
|
||||||
|
setDeletePasskeyOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Trash2 className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</CardContent>
|
||||||
|
|
||||||
|
<Dialog
|
||||||
|
open={addDialogOpen}
|
||||||
|
onOpenChange={(open) => {
|
||||||
|
setAddDialogOpen(open);
|
||||||
|
if (!open) setNewPasskeyName("");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DialogContent>
|
||||||
|
<form onSubmit={handleAddPasskey}>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Add a passkey</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Give this passkey a name so you can recognize it later (e.g. "MacBook Touch ID").
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<div className="space-y-4 py-4">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="passkey-name">Name (optional)</Label>
|
||||||
|
<Input
|
||||||
|
id="passkey-name"
|
||||||
|
value={newPasskeyName}
|
||||||
|
onChange={(e) => setNewPasskeyName(e.target.value)}
|
||||||
|
placeholder="My Laptop"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button type="button" variant="outline" onClick={() => setAddDialogOpen(false)}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button type="submit" loading={addPasskeyMutation.isPending} disabled={!isSecureContext}>
|
||||||
|
<Fingerprint className="h-4 w-4 mr-2" />
|
||||||
|
Add passkey
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</form>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
|
||||||
|
<Dialog
|
||||||
|
open={Boolean(renameTarget)}
|
||||||
|
onOpenChange={(open) => {
|
||||||
|
if (!open) {
|
||||||
|
setRenameTarget(null);
|
||||||
|
setRenameValue("");
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DialogContent>
|
||||||
|
<form onSubmit={handleRename}>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Rename passkey</DialogTitle>
|
||||||
|
<DialogDescription>Choose a name to recognize this passkey.</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<div className="space-y-4 py-4">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="passkey-rename">Name</Label>
|
||||||
|
<Input
|
||||||
|
id="passkey-rename"
|
||||||
|
value={renameValue}
|
||||||
|
onChange={(e) => setRenameValue(e.target.value)}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button type="button" variant="outline" onClick={() => setRenameTarget(null)}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button type="submit" loading={renamePasskeyMutation.isPending}>
|
||||||
|
Save
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</form>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
|
||||||
|
<AlertDialog open={deletePasskeyOpen} onOpenChange={setDeletePasskeyOpen}>
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>Delete passkey?</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
This will remove "{deleteTarget?.name?.trim() || "this passkey"}" from your account. You
|
||||||
|
won't be able to use it to sign in anymore.
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel disabled={deletePasskeyMutation.isPending}>Cancel</AlertDialogCancel>
|
||||||
|
<AlertDialogAction
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
handleDelete();
|
||||||
|
}}
|
||||||
|
disabled={deletePasskeyMutation.isPending}
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -1,11 +1,21 @@
|
||||||
import { useMutation } from "@tanstack/react-query";
|
import { useMutation } from "@tanstack/react-query";
|
||||||
import { Download, Fingerprint, KeyRound, User, X, Settings as SettingsIcon, Building2 } from "lucide-react";
|
import {
|
||||||
|
AlertTriangle,
|
||||||
|
Download,
|
||||||
|
Fingerprint,
|
||||||
|
KeyRound,
|
||||||
|
User,
|
||||||
|
X,
|
||||||
|
Settings as SettingsIcon,
|
||||||
|
Building2,
|
||||||
|
} from "lucide-react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { downloadResticPasswordMutation } from "~/client/api-client/@tanstack/react-query.gen";
|
import { downloadResticPasswordMutation } from "~/client/api-client/@tanstack/react-query.gen";
|
||||||
import type { GetOrgMembersResponse, GetSsoSettingsResponse } from "~/client/api-client/types.gen";
|
import type { GetOrgMembersResponse, GetSsoSettingsResponse } from "~/client/api-client/types.gen";
|
||||||
import { Button } from "~/client/components/ui/button";
|
import { Button } from "~/client/components/ui/button";
|
||||||
import { Card, CardContent, CardDescription, CardTitle } from "~/client/components/ui/card";
|
import { Card, CardContent, CardDescription, CardTitle } from "~/client/components/ui/card";
|
||||||
|
import { Alert, AlertDescription, AlertTitle } from "~/client/components/ui/alert";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
|
|
@ -29,12 +39,18 @@ import {
|
||||||
useTimeFormat,
|
useTimeFormat,
|
||||||
} from "~/client/lib/datetime";
|
} from "~/client/lib/datetime";
|
||||||
import { logger } from "~/client/lib/logger";
|
import { logger } from "~/client/lib/logger";
|
||||||
|
import { parseError } from "~/client/lib/errors";
|
||||||
import { type AppContext } from "~/context";
|
import { type AppContext } from "~/context";
|
||||||
import { TwoFactorSection } from "../components/two-factor-section";
|
import { TwoFactorSection } from "../components/two-factor-section";
|
||||||
|
import { PasskeysSection } from "../components/passkeys-section";
|
||||||
import { useNavigate, useSearch } from "@tanstack/react-router";
|
import { useNavigate, useSearch } from "@tanstack/react-router";
|
||||||
import { SsoSettingsSection } from "~/client/modules/sso/components/sso-settings-section";
|
import { SsoSettingsSection } from "~/client/modules/sso/components/sso-settings-section";
|
||||||
import { OrgMembersSection } from "../components/org-members-section";
|
import { OrgMembersSection } from "../components/org-members-section";
|
||||||
import { useOrganizationContext } from "~/client/hooks/use-org-context";
|
import { useOrganizationContext } from "~/client/hooks/use-org-context";
|
||||||
|
import { cn } from "~/client/lib/utils";
|
||||||
|
|
||||||
|
const RECOVERY_KEY_CREDENTIAL_REQUIRED_MESSAGE =
|
||||||
|
"Downloading the recovery key requires a local credential password. Ask an operator to run `docker exec -it zerobyte bun run cli reset-password` for your user, then sign in with that password and try again.";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
appContext: AppContext;
|
appContext: AppContext;
|
||||||
|
|
@ -49,6 +65,7 @@ export function SettingsPage({ appContext, initialMembers, initialSsoSettings, i
|
||||||
const [confirmPassword, setConfirmPassword] = useState("");
|
const [confirmPassword, setConfirmPassword] = useState("");
|
||||||
const [downloadDialogOpen, setDownloadDialogOpen] = useState(false);
|
const [downloadDialogOpen, setDownloadDialogOpen] = useState(false);
|
||||||
const [downloadPassword, setDownloadPassword] = useState("");
|
const [downloadPassword, setDownloadPassword] = useState("");
|
||||||
|
const [downloadBlockedMessage, setDownloadBlockedMessage] = useState<string | null>(null);
|
||||||
const [isChangingPassword, setIsChangingPassword] = useState(false);
|
const [isChangingPassword, setIsChangingPassword] = useState(false);
|
||||||
const { dateFormat, timeFormat } = useRootLoaderData();
|
const { dateFormat, timeFormat } = useRootLoaderData();
|
||||||
|
|
||||||
|
|
@ -59,6 +76,7 @@ export function SettingsPage({ appContext, initialMembers, initialSsoSettings, i
|
||||||
const { activeMember, activeOrganization } = useOrganizationContext();
|
const { activeMember, activeOrganization } = useOrganizationContext();
|
||||||
const isOrgAdmin = activeMember?.role === "owner" || activeMember?.role === "admin";
|
const isOrgAdmin = activeMember?.role === "owner" || activeMember?.role === "admin";
|
||||||
const { formatDateTime } = useTimeFormat();
|
const { formatDateTime } = useTimeFormat();
|
||||||
|
const hasCredentialPassword = appContext.user?.hasCredentialPassword !== false;
|
||||||
|
|
||||||
const handleLogout = async () => {
|
const handleLogout = async () => {
|
||||||
await authClient.signOut({
|
await authClient.signOut({
|
||||||
|
|
@ -85,15 +103,18 @@ export function SettingsPage({ appContext, initialMembers, initialSsoSettings, i
|
||||||
document.body.appendChild(a);
|
document.body.appendChild(a);
|
||||||
a.click();
|
a.click();
|
||||||
document.body.removeChild(a);
|
document.body.removeChild(a);
|
||||||
window.URL.revokeObjectURL(url);
|
window.setTimeout(() => window.URL.revokeObjectURL(url), 60_000);
|
||||||
|
|
||||||
toast.success("Restic password file downloaded successfully");
|
toast.success("Restic password file downloaded successfully");
|
||||||
setDownloadDialogOpen(false);
|
setDownloadDialogOpen(false);
|
||||||
setDownloadPassword("");
|
setDownloadPassword("");
|
||||||
|
setDownloadBlockedMessage(null);
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
|
const message = parseError(error)?.message;
|
||||||
|
setDownloadBlockedMessage(message?.includes("credential password") ? message : null);
|
||||||
toast.error("Failed to download Restic password", {
|
toast.error("Failed to download Restic password", {
|
||||||
description: error.message,
|
description: message,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
@ -145,6 +166,7 @@ export function SettingsPage({ appContext, initialMembers, initialSsoSettings, i
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setDownloadBlockedMessage(null);
|
||||||
downloadResticPassword.mutate({
|
downloadResticPassword.mutate({
|
||||||
body: {
|
body: {
|
||||||
password: downloadPassword,
|
password: downloadPassword,
|
||||||
|
|
@ -213,11 +235,22 @@ export function SettingsPage({ appContext, initialMembers, initialSsoSettings, i
|
||||||
<CardContent className="p-6 space-y-4">
|
<CardContent className="p-6 space-y-4">
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="username">Username</Label>
|
<Label htmlFor="username">Username</Label>
|
||||||
<Input id="username" value={appContext.user?.username} disabled className="max-w-md" />
|
<Input
|
||||||
|
id="username"
|
||||||
|
value={appContext.user?.username}
|
||||||
|
disabled
|
||||||
|
className="max-w-md"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="email">Email</Label>
|
<Label htmlFor="email">Email</Label>
|
||||||
<Input id="email" type="email" value={appContext.user?.email} disabled className="max-w-md" />
|
<Input
|
||||||
|
id="email"
|
||||||
|
type="email"
|
||||||
|
value={appContext.user?.email}
|
||||||
|
disabled
|
||||||
|
className="max-w-md"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
|
|
||||||
|
|
@ -237,7 +270,9 @@ export function SettingsPage({ appContext, initialMembers, initialSsoSettings, i
|
||||||
<Label htmlFor="date-format">Date format</Label>
|
<Label htmlFor="date-format">Date format</Label>
|
||||||
<Select
|
<Select
|
||||||
value={dateFormat}
|
value={dateFormat}
|
||||||
onValueChange={(value) => void handleDateFormatChange(value as DateFormatPreference)}
|
onValueChange={(value) =>
|
||||||
|
void handleDateFormatChange(value as DateFormatPreference)
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<SelectTrigger id="date-format">
|
<SelectTrigger id="date-format">
|
||||||
<SelectValue />
|
<SelectValue />
|
||||||
|
|
@ -255,7 +290,9 @@ export function SettingsPage({ appContext, initialMembers, initialSsoSettings, i
|
||||||
<Label htmlFor="time-format">Time format</Label>
|
<Label htmlFor="time-format">Time format</Label>
|
||||||
<Select
|
<Select
|
||||||
value={timeFormat}
|
value={timeFormat}
|
||||||
onValueChange={(value) => void handleTimeFormatChange(value as TimeFormatPreference)}
|
onValueChange={(value) =>
|
||||||
|
void handleTimeFormatChange(value as TimeFormatPreference)
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<SelectTrigger id="time-format">
|
<SelectTrigger id="time-format">
|
||||||
<SelectValue />
|
<SelectValue />
|
||||||
|
|
@ -270,18 +307,26 @@ export function SettingsPage({ appContext, initialMembers, initialSsoSettings, i
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p className="text-sm text-muted-foreground">Preview: {formatDateTime(new Date())}</p>
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Preview: {formatDateTime(new Date())}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
|
|
||||||
<div className="border-t border-border/50 bg-card-header p-6">
|
<div
|
||||||
|
className={cn("border-t border-border/50 bg-card-header p-6", {
|
||||||
|
hidden: !hasCredentialPassword,
|
||||||
|
})}
|
||||||
|
>
|
||||||
<CardTitle className="flex items-center gap-2">
|
<CardTitle className="flex items-center gap-2">
|
||||||
<KeyRound className="size-5" />
|
<KeyRound className="size-5" />
|
||||||
Change Password
|
Change Password
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
<CardDescription className="mt-1.5">Update your password to keep your account secure</CardDescription>
|
<CardDescription className="mt-1.5">
|
||||||
|
Update your password to keep your account secure
|
||||||
|
</CardDescription>
|
||||||
</div>
|
</div>
|
||||||
<CardContent className="p-6">
|
<CardContent className={cn("p-6", { hidden: !hasCredentialPassword })}>
|
||||||
<form onSubmit={handleChangePassword} className="space-y-4">
|
<form onSubmit={handleChangePassword} className="space-y-4">
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="current-password">Current Password</Label>
|
<Label htmlFor="current-password">Current Password</Label>
|
||||||
|
|
@ -305,7 +350,9 @@ export function SettingsPage({ appContext, initialMembers, initialSsoSettings, i
|
||||||
required
|
required
|
||||||
minLength={8}
|
minLength={8}
|
||||||
/>
|
/>
|
||||||
<p className="text-xs text-muted-foreground">Must be at least 8 characters long</p>
|
<p className="text-xs text-muted-foreground">
|
||||||
|
Must be at least 8 characters long
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="confirm-password">Confirm New Password</Label>
|
<Label htmlFor="confirm-password">Confirm New Password</Label>
|
||||||
|
|
@ -331,13 +378,15 @@ export function SettingsPage({ appContext, initialMembers, initialSsoSettings, i
|
||||||
<Download className="size-5" />
|
<Download className="size-5" />
|
||||||
Backup Recovery Key
|
Backup Recovery Key
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
<CardDescription className="mt-1.5">Download your recovery key for Restic backups</CardDescription>
|
<CardDescription className="mt-1.5">
|
||||||
|
Download your recovery key for Restic backups
|
||||||
|
</CardDescription>
|
||||||
</div>
|
</div>
|
||||||
<CardContent className="p-6 space-y-4">
|
<CardContent className="p-6 space-y-4">
|
||||||
<p className="text-sm text-muted-foreground max-w-2xl">
|
<p className="text-sm text-muted-foreground max-w-2xl">
|
||||||
This file contains the encryption password used by Restic to secure your backups. Store it in a safe
|
This file contains the encryption password used by Restic to secure your backups.
|
||||||
place (like a password manager or encrypted storage). If you lose access to this server, you'll need
|
Store it in a safe place (like a password manager or encrypted storage). If you lose
|
||||||
this file to recover your backup data.
|
access to this server, you'll need this file to recover your backup data.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<Dialog open={downloadDialogOpen} onOpenChange={setDownloadDialogOpen}>
|
<Dialog open={downloadDialogOpen} onOpenChange={setDownloadDialogOpen}>
|
||||||
|
|
@ -352,11 +401,26 @@ export function SettingsPage({ appContext, initialMembers, initialSsoSettings, i
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>Download Recovery Key</DialogTitle>
|
<DialogTitle>Download Recovery Key</DialogTitle>
|
||||||
<DialogDescription>
|
<DialogDescription>
|
||||||
For security reasons, please enter your account password to download the recovery key file.
|
{!hasCredentialPassword
|
||||||
|
? "A local credential password is required before this recovery key can be downloaded."
|
||||||
|
: "For security reasons, please enter your account password to download the recovery key file."}
|
||||||
</DialogDescription>
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<div className="space-y-4 py-4">
|
<div className="space-y-4 py-4">
|
||||||
<div className="space-y-2">
|
<Alert
|
||||||
|
variant="warning"
|
||||||
|
className={cn({
|
||||||
|
hidden: hasCredentialPassword && !downloadBlockedMessage,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<AlertTriangle className="size-5" />
|
||||||
|
<AlertTitle>Local password required</AlertTitle>
|
||||||
|
<AlertDescription>
|
||||||
|
{downloadBlockedMessage ??
|
||||||
|
RECOVERY_KEY_CREDENTIAL_REQUIRED_MESSAGE}
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
<div className={cn("space-y-2", { hidden: !hasCredentialPassword })}>
|
||||||
<Label htmlFor="download-password">Your Password</Label>
|
<Label htmlFor="download-password">Your Password</Label>
|
||||||
<Input
|
<Input
|
||||||
id="download-password"
|
id="download-password"
|
||||||
|
|
@ -380,7 +444,11 @@ export function SettingsPage({ appContext, initialMembers, initialSsoSettings, i
|
||||||
<X className="h-4 w-4 mr-2" />
|
<X className="h-4 w-4 mr-2" />
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="submit" loading={downloadResticPassword.isPending}>
|
<Button
|
||||||
|
type="submit"
|
||||||
|
loading={downloadResticPassword.isPending}
|
||||||
|
className={cn({ hidden: !hasCredentialPassword })}
|
||||||
|
>
|
||||||
<Download className="h-4 w-4 mr-2" />
|
<Download className="h-4 w-4 mr-2" />
|
||||||
Download
|
Download
|
||||||
</Button>
|
</Button>
|
||||||
|
|
@ -391,6 +459,8 @@ export function SettingsPage({ appContext, initialMembers, initialSsoSettings, i
|
||||||
</CardContent>
|
</CardContent>
|
||||||
|
|
||||||
<TwoFactorSection twoFactorEnabled={appContext.user?.twoFactorEnabled} />
|
<TwoFactorSection twoFactorEnabled={appContext.user?.twoFactorEnabled} />
|
||||||
|
|
||||||
|
<PasskeysSection />
|
||||||
</Card>
|
</Card>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
|
|
||||||
|
|
@ -402,7 +472,9 @@ export function SettingsPage({ appContext, initialMembers, initialSsoSettings, i
|
||||||
<Fingerprint className="size-5" />
|
<Fingerprint className="size-5" />
|
||||||
Organization Details
|
Organization Details
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
<CardDescription className="mt-1.5">Reference details for the active organization</CardDescription>
|
<CardDescription className="mt-1.5">
|
||||||
|
Reference details for the active organization
|
||||||
|
</CardDescription>
|
||||||
</div>
|
</div>
|
||||||
<CardContent className="p-6 space-y-2">
|
<CardContent className="p-6 space-y-2">
|
||||||
<Label htmlFor="organization-id">Organization ID</Label>
|
<Label htmlFor="organization-id">Organization ID</Label>
|
||||||
|
|
@ -421,7 +493,9 @@ export function SettingsPage({ appContext, initialMembers, initialSsoSettings, i
|
||||||
<Building2 className="size-5" />
|
<Building2 className="size-5" />
|
||||||
Members
|
Members
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
<CardDescription className="mt-1.5">Manage organization members and roles</CardDescription>
|
<CardDescription className="mt-1.5">
|
||||||
|
Manage organization members and roles
|
||||||
|
</CardDescription>
|
||||||
</div>
|
</div>
|
||||||
<CardContent className="p-6">
|
<CardContent className="p-6">
|
||||||
<OrgMembersSection initialMembers={initialMembers} />
|
<OrgMembersSection initialMembers={initialMembers} />
|
||||||
|
|
@ -434,10 +508,15 @@ export function SettingsPage({ appContext, initialMembers, initialSsoSettings, i
|
||||||
<SettingsIcon className="size-5" />
|
<SettingsIcon className="size-5" />
|
||||||
Single Sign-On
|
Single Sign-On
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
<CardDescription className="mt-1.5">Configure OIDC provider settings</CardDescription>
|
<CardDescription className="mt-1.5">
|
||||||
|
Configure OIDC provider settings
|
||||||
|
</CardDescription>
|
||||||
</div>
|
</div>
|
||||||
<CardContent className="p-6">
|
<CardContent className="p-6">
|
||||||
<SsoSettingsSection initialSettings={initialSsoSettings} initialOrigin={initialOrigin} />
|
<SsoSettingsSection
|
||||||
|
initialSettings={initialSsoSettings}
|
||||||
|
initialOrigin={initialOrigin}
|
||||||
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
|
|
|
||||||
54
app/client/modules/sso/components/sso-login-buttons.tsx
Normal file
54
app/client/modules/sso/components/sso-login-buttons.tsx
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
import { useMutation } from "@tanstack/react-query";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
import { Button } from "~/client/components/ui/button";
|
||||||
|
import { authClient } from "~/client/lib/auth-client";
|
||||||
|
import { logger } from "~/client/lib/logger";
|
||||||
|
|
||||||
|
type SsoProvider = {
|
||||||
|
providerId: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type SsoLoginButtonsProps = {
|
||||||
|
providers: SsoProvider[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export function SsoLoginButtons({ providers }: SsoLoginButtonsProps) {
|
||||||
|
const ssoLoginMutation = useMutation({
|
||||||
|
mutationFn: async (providerId: string) => {
|
||||||
|
const callbackPath = "/login";
|
||||||
|
const { data, error } = await authClient.signIn.sso({
|
||||||
|
providerId: providerId,
|
||||||
|
callbackURL: callbackPath,
|
||||||
|
errorCallbackURL: "/api/v1/auth/login-error",
|
||||||
|
});
|
||||||
|
if (error) throw error;
|
||||||
|
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
onSuccess: (data) => {
|
||||||
|
window.location.href = data.url;
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
logger.error(error);
|
||||||
|
toast.error("SSO Login failed", { description: error.message });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{providers.map((provider) => (
|
||||||
|
<Button
|
||||||
|
key={provider.providerId}
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
className="w-full"
|
||||||
|
loading={ssoLoginMutation.isPending}
|
||||||
|
disabled={ssoLoginMutation.isPending}
|
||||||
|
onClick={() => ssoLoginMutation.mutate(provider.providerId)}
|
||||||
|
>
|
||||||
|
Log in with {provider.providerId}
|
||||||
|
</Button>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -1,58 +0,0 @@
|
||||||
import { useMutation, useSuspenseQuery } from "@tanstack/react-query";
|
|
||||||
import { toast } from "sonner";
|
|
||||||
import { Button } from "~/client/components/ui/button";
|
|
||||||
import { authClient } from "~/client/lib/auth-client";
|
|
||||||
import { logger } from "~/client/lib/logger";
|
|
||||||
import { getPublicSsoProvidersOptions } from "~/client/api-client/@tanstack/react-query.gen";
|
|
||||||
|
|
||||||
export function SsoLoginSection() {
|
|
||||||
const { data: ssoProviders } = useSuspenseQuery({
|
|
||||||
...getPublicSsoProvidersOptions(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const ssoLoginMutation = useMutation({
|
|
||||||
mutationFn: async (providerId: string) => {
|
|
||||||
const callbackPath = "/login";
|
|
||||||
const { data, error } = await authClient.signIn.sso({
|
|
||||||
providerId: providerId,
|
|
||||||
callbackURL: callbackPath,
|
|
||||||
errorCallbackURL: "/api/v1/auth/login-error",
|
|
||||||
});
|
|
||||||
if (error) throw error;
|
|
||||||
|
|
||||||
return data;
|
|
||||||
},
|
|
||||||
onSuccess: (data) => {
|
|
||||||
window.location.href = data.url;
|
|
||||||
},
|
|
||||||
onError: (error) => {
|
|
||||||
logger.error(error);
|
|
||||||
toast.error("SSO Login failed", { description: error.message });
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (ssoProviders.providers.length === 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="pt-4 border-t border-border/60 space-y-3">
|
|
||||||
<p className="text-sm font-medium">Alternative Sign-in</p>
|
|
||||||
<div className="flex flex-col gap-2">
|
|
||||||
{ssoProviders.providers.map((provider) => (
|
|
||||||
<Button
|
|
||||||
key={provider.providerId}
|
|
||||||
type="button"
|
|
||||||
variant="outline"
|
|
||||||
className="w-full"
|
|
||||||
loading={ssoLoginMutation.isPending}
|
|
||||||
disabled={ssoLoginMutation.isPending}
|
|
||||||
onClick={() => ssoLoginMutation.mutate(provider.providerId)}
|
|
||||||
>
|
|
||||||
Log in with {provider.providerId}
|
|
||||||
</Button>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
@ -25,7 +25,7 @@ import {
|
||||||
smbConfigSchema,
|
smbConfigSchema,
|
||||||
volumeConfigSchema,
|
volumeConfigSchema,
|
||||||
webdavConfigSchema,
|
webdavConfigSchema,
|
||||||
} from "~/schemas/volumes";
|
} from "@zerobyte/contracts/volumes";
|
||||||
import { testConnectionMutation } from "../../../api-client/@tanstack/react-query.gen";
|
import { testConnectionMutation } from "../../../api-client/@tanstack/react-query.gen";
|
||||||
import { Tooltip, TooltipContent, TooltipTrigger } from "../../../components/ui/tooltip";
|
import { Tooltip, TooltipContent, TooltipTrigger } from "../../../components/ui/tooltip";
|
||||||
import { useSystemInfo } from "~/client/hooks/use-system-info";
|
import { useSystemInfo } from "~/client/hooks/use-system-info";
|
||||||
|
|
@ -66,10 +66,10 @@ type Props = {
|
||||||
const defaultValuesForType = {
|
const defaultValuesForType = {
|
||||||
directory: { backend: "directory" as const, path: "/" },
|
directory: { backend: "directory" as const, path: "/" },
|
||||||
nfs: { backend: "nfs" as const, port: 2049, version: "4.1" as const },
|
nfs: { backend: "nfs" as const, port: 2049, version: "4.1" as const },
|
||||||
smb: { backend: "smb" as const, port: 445, vers: "3.0" as const },
|
smb: { backend: "smb" as const, port: 445, vers: "3.0" as const, mapToContainerUidGid: false },
|
||||||
webdav: { backend: "webdav" as const, port: 80, ssl: false, path: "/webdav" },
|
webdav: { backend: "webdav" as const, port: 80, ssl: false, path: "/webdav" },
|
||||||
rclone: { backend: "rclone" as const, path: "/" },
|
rclone: { backend: "rclone" as const, path: "/" },
|
||||||
sftp: { backend: "sftp" as const, port: 22, path: "/", skipHostKeyCheck: false },
|
sftp: { backend: "sftp" as const, port: 22, path: "/", skipHostKeyCheck: false, allowLegacySshRsa: false },
|
||||||
};
|
};
|
||||||
|
|
||||||
export const CreateVolumeForm = ({ onSubmit, mode = "create", initialValues, formId, loading, className }: Props) => {
|
export const CreateVolumeForm = ({ onSubmit, mode = "create", initialValues, formId, loading, className }: Props) => {
|
||||||
|
|
@ -230,7 +230,10 @@ export const CreateVolumeForm = ({ onSubmit, mode = "create", initialValues, for
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
<TooltipTrigger asChild>
|
<TooltipTrigger asChild>
|
||||||
<div>
|
<div>
|
||||||
<SelectItem disabled={!capabilities.rclone || !capabilities.sysAdmin} value="rclone">
|
<SelectItem
|
||||||
|
disabled={!capabilities.rclone || !capabilities.sysAdmin}
|
||||||
|
value="rclone"
|
||||||
|
>
|
||||||
rclone
|
rclone
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -238,7 +241,11 @@ export const CreateVolumeForm = ({ onSubmit, mode = "create", initialValues, for
|
||||||
<TooltipContent className={cn({ hidden: capabilities.sysAdmin })}>
|
<TooltipContent className={cn({ hidden: capabilities.sysAdmin })}>
|
||||||
<p>Remote mounts require SYS_ADMIN capability</p>
|
<p>Remote mounts require SYS_ADMIN capability</p>
|
||||||
</TooltipContent>
|
</TooltipContent>
|
||||||
<TooltipContent className={cn({ hidden: !capabilities.sysAdmin || capabilities.rclone })}>
|
<TooltipContent
|
||||||
|
className={cn({
|
||||||
|
hidden: !capabilities.sysAdmin || capabilities.rclone,
|
||||||
|
})}
|
||||||
|
>
|
||||||
<p>Setup rclone to use this backend</p>
|
<p>Setup rclone to use this backend</p>
|
||||||
</TooltipContent>
|
</TooltipContent>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,7 @@ export const NFSForm = ({ form }: Props) => {
|
||||||
<div className="flex items-center space-x-2">
|
<div className="flex items-center space-x-2">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
aria-label="Mount volume as read-only"
|
||||||
checked={field.value ?? false}
|
checked={field.value ?? false}
|
||||||
onChange={(e) => field.onChange(e.target.checked)}
|
onChange={(e) => field.onChange(e.target.checked)}
|
||||||
className="rounded border-gray-300"
|
className="rounded border-gray-300"
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,7 @@ export const RcloneForm = ({ form }: Props) => {
|
||||||
<div className="flex items-center space-x-2">
|
<div className="flex items-center space-x-2">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
aria-label="Mount volume as read-only"
|
||||||
checked={field.value ?? false}
|
checked={field.value ?? false}
|
||||||
onChange={(e) => field.onChange(e.target.checked)}
|
onChange={(e) => field.onChange(e.target.checked)}
|
||||||
className="rounded border-gray-300"
|
className="rounded border-gray-300"
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import { Input } from "../../../../components/ui/input";
|
||||||
import { SecretInput } from "../../../../components/ui/secret-input";
|
import { SecretInput } from "../../../../components/ui/secret-input";
|
||||||
import { Textarea } from "../../../../components/ui/textarea";
|
import { Textarea } from "../../../../components/ui/textarea";
|
||||||
import { Switch } from "../../../../components/ui/switch";
|
import { Switch } from "../../../../components/ui/switch";
|
||||||
|
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "../../../../components/ui/collapsible";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
form: UseFormReturn<FormValues>;
|
form: UseFormReturn<FormValues>;
|
||||||
|
|
@ -78,7 +79,9 @@ export const SFTPForm = ({ form }: Props) => {
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<SecretInput placeholder="••••••••" value={field.value ?? ""} onChange={field.onChange} />
|
<SecretInput placeholder="••••••••" value={field.value ?? ""} onChange={field.onChange} />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription>Password for SFTP authentication (optional if using private key).</FormDescription>
|
<FormDescription>
|
||||||
|
Password for SFTP authentication (optional if using private key).
|
||||||
|
</FormDescription>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
|
|
@ -98,7 +101,9 @@ export const SFTPForm = ({ form }: Props) => {
|
||||||
value={field.value ?? ""}
|
value={field.value ?? ""}
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription>SSH private key for authentication (optional if using password).</FormDescription>
|
<FormDescription>
|
||||||
|
SSH private key for authentication (optional if using password).
|
||||||
|
</FormDescription>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
|
|
@ -158,6 +163,29 @@ export const SFTPForm = ({ form }: Props) => {
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
<Collapsible>
|
||||||
|
<CollapsibleTrigger>Advanced Settings</CollapsibleTrigger>
|
||||||
|
<CollapsibleContent className="pb-4 pt-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="allowLegacySshRsa"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem className="flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm">
|
||||||
|
<div className="space-y-0.5">
|
||||||
|
<FormLabel>Allow legacy SSH RSA/SHA1 algorithms</FormLabel>
|
||||||
|
<FormDescription>
|
||||||
|
Only enable this for legacy SFTP servers that offer <code>ssh-rsa</code> only.
|
||||||
|
It permits RSA/SHA1 signatures, which are weaker than modern SSH algorithms.
|
||||||
|
</FormDescription>
|
||||||
|
</div>
|
||||||
|
<FormControl>
|
||||||
|
<Switch checked={field.value ?? false} onCheckedChange={field.onChange} />
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</CollapsibleContent>
|
||||||
|
</Collapsible>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ export const SMBForm = ({ form }: Props) => {
|
||||||
<div className="flex items-center space-x-2">
|
<div className="flex items-center space-x-2">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
aria-label="Connect as guest"
|
||||||
checked={field.value ?? false}
|
checked={field.value ?? false}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
field.onChange(e.target.checked);
|
field.onChange(e.target.checked);
|
||||||
|
|
@ -168,6 +169,33 @@ export const SMBForm = ({ form }: Props) => {
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="mapToContainerUidGid"
|
||||||
|
defaultValue={false}
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Ownership Mapping</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
aria-label="Map all files to container user/group"
|
||||||
|
checked={field.value ?? false}
|
||||||
|
onChange={(e) => field.onChange(e.target.checked)}
|
||||||
|
className="rounded border-gray-300"
|
||||||
|
/>
|
||||||
|
<span className="text-sm">Map all files to container user/group</span>
|
||||||
|
</div>
|
||||||
|
</FormControl>
|
||||||
|
<FormDescription>
|
||||||
|
Keep the old behavior by forcing the SMB mount to present every file and directory as owned
|
||||||
|
by the container user and group instead of using server reported ownership.
|
||||||
|
</FormDescription>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="readOnly"
|
name="readOnly"
|
||||||
|
|
@ -179,6 +207,7 @@ export const SMBForm = ({ form }: Props) => {
|
||||||
<div className="flex items-center space-x-2">
|
<div className="flex items-center space-x-2">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
aria-label="Mount volume as read-only"
|
||||||
checked={field.value ?? false}
|
checked={field.value ?? false}
|
||||||
onChange={(e) => field.onChange(e.target.checked)}
|
onChange={(e) => field.onChange(e.target.checked)}
|
||||||
className="rounded border-gray-300"
|
className="rounded border-gray-300"
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,7 @@ export const WebDAVForm = ({ form }: Props) => {
|
||||||
<div className="flex items-center space-x-2">
|
<div className="flex items-center space-x-2">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
aria-label="Enable HTTPS for secure connections"
|
||||||
checked={field.value ?? false}
|
checked={field.value ?? false}
|
||||||
onChange={(e) => field.onChange(e.target.checked)}
|
onChange={(e) => field.onChange(e.target.checked)}
|
||||||
className="rounded border-gray-300"
|
className="rounded border-gray-300"
|
||||||
|
|
@ -128,6 +129,7 @@ export const WebDAVForm = ({ form }: Props) => {
|
||||||
<div className="flex items-center space-x-2">
|
<div className="flex items-center space-x-2">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
aria-label="Mount volume as read-only"
|
||||||
checked={field.value ?? false}
|
checked={field.value ?? false}
|
||||||
onChange={(e) => field.onChange(e.target.checked)}
|
onChange={(e) => field.onChange(e.target.checked)}
|
||||||
className="rounded border-gray-300"
|
className="rounded border-gray-300"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,18 @@
|
||||||
import { useSuspenseQuery } from "@tanstack/react-query";
|
import { useSuspenseQuery } from "@tanstack/react-query";
|
||||||
|
import {
|
||||||
|
flexRender,
|
||||||
|
getCoreRowModel,
|
||||||
|
getFilteredRowModel,
|
||||||
|
getSortedRowModel,
|
||||||
|
type ColumnDef,
|
||||||
|
type ColumnFiltersState,
|
||||||
|
type SortingState,
|
||||||
|
useReactTable,
|
||||||
|
} from "@tanstack/react-table";
|
||||||
import { HardDrive, Plus, RotateCcw } from "lucide-react";
|
import { HardDrive, Plus, RotateCcw } from "lucide-react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
import { listVolumesOptions } from "~/client/api-client/@tanstack/react-query.gen";
|
||||||
|
import { DataTableSortHeader } from "~/client/components/data-table-sort-header";
|
||||||
import { EmptyState } from "~/client/components/empty-state";
|
import { EmptyState } from "~/client/components/empty-state";
|
||||||
import { StatusDot } from "~/client/components/status-dot";
|
import { StatusDot } from "~/client/components/status-dot";
|
||||||
import { Button } from "~/client/components/ui/button";
|
import { Button } from "~/client/components/ui/button";
|
||||||
|
|
@ -9,7 +21,6 @@ import { Input } from "~/client/components/ui/input";
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "~/client/components/ui/select";
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "~/client/components/ui/select";
|
||||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "~/client/components/ui/table";
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "~/client/components/ui/table";
|
||||||
import { VolumeIcon } from "~/client/components/volume-icon";
|
import { VolumeIcon } from "~/client/components/volume-icon";
|
||||||
import { listVolumesOptions } from "~/client/api-client/@tanstack/react-query.gen";
|
|
||||||
import type { VolumeStatus } from "~/client/lib/types";
|
import type { VolumeStatus } from "~/client/lib/types";
|
||||||
import { useNavigate } from "@tanstack/react-router";
|
import { useNavigate } from "@tanstack/react-router";
|
||||||
import { cn } from "~/client/lib/utils";
|
import { cn } from "~/client/lib/utils";
|
||||||
|
|
@ -24,33 +35,66 @@ const getVolumeStatusVariant = (status: VolumeStatus): "success" | "neutral" | "
|
||||||
return statusMap[status];
|
return statusMap[status];
|
||||||
};
|
};
|
||||||
|
|
||||||
export function VolumesPage() {
|
type VolumeRow = {
|
||||||
const [searchQuery, setSearchQuery] = useState("");
|
shortId: string;
|
||||||
const [statusFilter, setStatusFilter] = useState("");
|
name: string;
|
||||||
const [backendFilter, setBackendFilter] = useState("");
|
type: "directory" | "nfs" | "smb" | "webdav" | "sftp" | "rclone";
|
||||||
|
status: VolumeStatus;
|
||||||
|
};
|
||||||
|
|
||||||
const clearFilters = () => {
|
const volumeColumns: ColumnDef<VolumeRow>[] = [
|
||||||
setSearchQuery("");
|
{
|
||||||
setStatusFilter("");
|
accessorKey: "name",
|
||||||
setBackendFilter("");
|
header: ({ column }) => <DataTableSortHeader column={column} title="Name" sortDirection={column.getIsSorted()} />,
|
||||||
};
|
cell: ({ row }) => (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span>{row.original.name}</span>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "type",
|
||||||
|
header: ({ column }) => (
|
||||||
|
<DataTableSortHeader column={column} title="Backend" sortDirection={column.getIsSorted()} />
|
||||||
|
),
|
||||||
|
cell: ({ row }) => <VolumeIcon backend={row.original.type} />,
|
||||||
|
filterFn: (row, id, value) => row.getValue(id) === value,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "status",
|
||||||
|
header: ({ column }) => (
|
||||||
|
<DataTableSortHeader column={column} title="Status" sortDirection={column.getIsSorted()} center />
|
||||||
|
),
|
||||||
|
cell: ({ row }) => <StatusDot variant={getVolumeStatusVariant(row.original.status)} label={row.original.status} />,
|
||||||
|
filterFn: (row, id, value) => row.getValue(id) === value,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export function VolumesPage() {
|
||||||
|
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);
|
||||||
|
const [sorting, setSorting] = useState<SortingState>([]);
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const { data } = useSuspenseQuery({ ...listVolumesOptions() });
|
||||||
|
|
||||||
const { data } = useSuspenseQuery({
|
const table = useReactTable({
|
||||||
...listVolumesOptions(),
|
data,
|
||||||
|
columns: volumeColumns,
|
||||||
|
state: { columnFilters, sorting },
|
||||||
|
onColumnFiltersChange: setColumnFilters,
|
||||||
|
onSortingChange: setSorting,
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
getFilteredRowModel: getFilteredRowModel(),
|
||||||
|
getSortedRowModel: getSortedRowModel(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const filteredVolumes =
|
const rows = table.getRowModel().rows;
|
||||||
data.filter((volume) => {
|
const hasFilters = columnFilters.length > 0;
|
||||||
const matchesSearch = volume.name.toLowerCase().includes(searchQuery.toLowerCase());
|
|
||||||
const matchesStatus = !statusFilter || volume.status === statusFilter;
|
const clearFilters = () => table.resetColumnFilters();
|
||||||
const matchesBackend = !backendFilter || volume.type === backendFilter;
|
|
||||||
return matchesSearch && matchesStatus && matchesBackend;
|
|
||||||
}) || [];
|
|
||||||
|
|
||||||
const hasNoVolumes = data.length === 0;
|
const hasNoVolumes = data.length === 0;
|
||||||
const hasNoFilteredVolumes = filteredVolumes.length === 0 && !hasNoVolumes;
|
const hasNoFilteredVolumes = rows.length === 0 && !hasNoVolumes;
|
||||||
|
|
||||||
if (hasNoVolumes) {
|
if (hasNoVolumes) {
|
||||||
return (
|
return (
|
||||||
|
|
@ -68,6 +112,10 @@ export function VolumesPage() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const search = (table.getColumn("name")?.getFilterValue() as string) ?? "";
|
||||||
|
const status = (table.getColumn("status")?.getFilterValue() as string) ?? "";
|
||||||
|
const type = (table.getColumn("type")?.getFilterValue() as string) ?? "";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="p-0 gap-0">
|
<Card className="p-0 gap-0">
|
||||||
<div className="flex flex-col lg:flex-row items-stretch lg:items-center gap-2 md:justify-between p-4 bg-card-header py-4">
|
<div className="flex flex-col lg:flex-row items-stretch lg:items-center gap-2 md:justify-between p-4 bg-card-header py-4">
|
||||||
|
|
@ -75,10 +123,10 @@ export function VolumesPage() {
|
||||||
<Input
|
<Input
|
||||||
className="w-full lg:w-45 min-w-45"
|
className="w-full lg:w-45 min-w-45"
|
||||||
placeholder="Search…"
|
placeholder="Search…"
|
||||||
value={searchQuery}
|
value={search}
|
||||||
onChange={(e) => setSearchQuery(e.target.value)}
|
onChange={(e) => table.getColumn("name")?.setFilterValue(e.target.value)}
|
||||||
/>
|
/>
|
||||||
<Select value={statusFilter} onValueChange={setStatusFilter}>
|
<Select value={status} onValueChange={(value) => table.getColumn("status")?.setFilterValue(value)}>
|
||||||
<SelectTrigger className="w-full lg:w-45 min-w-45">
|
<SelectTrigger className="w-full lg:w-45 min-w-45">
|
||||||
<SelectValue placeholder="All status" />
|
<SelectValue placeholder="All status" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
|
|
@ -88,7 +136,7 @@ export function VolumesPage() {
|
||||||
<SelectItem value="error">Error</SelectItem>
|
<SelectItem value="error">Error</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
<Select value={backendFilter} onValueChange={setBackendFilter}>
|
<Select value={type} onValueChange={(value) => table.getColumn("type")?.setFilterValue(value)}>
|
||||||
<SelectTrigger className="w-full lg:w-45 min-w-45">
|
<SelectTrigger className="w-full lg:w-45 min-w-45">
|
||||||
<SelectValue placeholder="All backends" />
|
<SelectValue placeholder="All backends" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
|
|
@ -101,7 +149,7 @@ export function VolumesPage() {
|
||||||
<SelectItem value="rclone">rclone</SelectItem>
|
<SelectItem value="rclone">rclone</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
{(searchQuery || statusFilter || backendFilter) && (
|
{hasFilters && (
|
||||||
<Button onClick={clearFilters} className="w-full lg:w-auto mt-2 lg:mt-0 lg:ml-2">
|
<Button onClick={clearFilters} className="w-full lg:w-auto mt-2 lg:mt-0 lg:ml-2">
|
||||||
<RotateCcw className="h-4 w-4 mr-2" />
|
<RotateCcw className="h-4 w-4 mr-2" />
|
||||||
Clear filters
|
Clear filters
|
||||||
|
|
@ -116,15 +164,26 @@ export function VolumesPage() {
|
||||||
<div className="overflow-x-auto">
|
<div className="overflow-x-auto">
|
||||||
<Table className="border-t">
|
<Table className="border-t">
|
||||||
<TableHeader className="bg-card-header">
|
<TableHeader className="bg-card-header">
|
||||||
<TableRow>
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
<TableHead className="w-25 uppercase">Name</TableHead>
|
<TableRow key={headerGroup.id}>
|
||||||
<TableHead className="uppercase text-left">Backend</TableHead>
|
{headerGroup.headers.map((header) => (
|
||||||
<TableHead className="uppercase text-center">Status</TableHead>
|
<TableHead
|
||||||
</TableRow>
|
key={header.id}
|
||||||
|
className={cn("uppercase", {
|
||||||
|
"w-25": header.column.id === "name",
|
||||||
|
"text-left": header.column.id === "type",
|
||||||
|
"text-center": header.column.id === "status",
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
|
||||||
|
</TableHead>
|
||||||
|
))}
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
<TableRow className={cn({ hidden: !hasNoFilteredVolumes })}>
|
<TableRow className={cn({ hidden: !hasNoFilteredVolumes })}>
|
||||||
<TableCell colSpan={4} className="text-center py-12">
|
<TableCell colSpan={3} className="text-center py-12">
|
||||||
<div className="flex flex-col items-center gap-3">
|
<div className="flex flex-col items-center gap-3">
|
||||||
<p className="text-muted-foreground">No volumes match your filters.</p>
|
<p className="text-muted-foreground">No volumes match your filters.</p>
|
||||||
<Button onClick={clearFilters} variant="outline" size="sm">
|
<Button onClick={clearFilters} variant="outline" size="sm">
|
||||||
|
|
@ -134,26 +193,24 @@ export function VolumesPage() {
|
||||||
</div>
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
{filteredVolumes.map((volume) => (
|
{rows.map((row) => (
|
||||||
<TableRow
|
<TableRow
|
||||||
key={volume.shortId}
|
key={row.original.shortId}
|
||||||
className="hover:bg-muted/50 hover:cursor-pointer transition-colors h-12"
|
className="hover:bg-muted/50 hover:cursor-pointer transition-colors h-12"
|
||||||
onClick={() => navigate({ to: `/volumes/${volume.shortId}` })}
|
onClick={() => navigate({ to: `/volumes/${row.original.shortId}` })}
|
||||||
>
|
>
|
||||||
<TableCell className="font-medium font-mono text-strong-accent">
|
{row.getVisibleCells().map((cell) => (
|
||||||
<div className="flex items-center gap-2">
|
<TableCell
|
||||||
<span>{volume.name}</span>
|
key={cell.id}
|
||||||
</div>
|
className={cn("font-mono", {
|
||||||
</TableCell>
|
"font-medium text-strong-accent": cell.column.id === "name",
|
||||||
<TableCell className="font-mono text-muted-foreground">
|
"text-muted-foreground": cell.column.id === "type",
|
||||||
<VolumeIcon backend={volume.type} />
|
"text-center": cell.column.id === "status",
|
||||||
</TableCell>
|
})}
|
||||||
<TableCell className="text-center font-mono">
|
>
|
||||||
<StatusDot
|
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
||||||
variant={getVolumeStatusVariant(volume.status)}
|
</TableCell>
|
||||||
label={volume.status[0].toUpperCase() + volume.status.slice(1)}
|
))}
|
||||||
/>
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
|
|
@ -164,8 +221,8 @@ export function VolumesPage() {
|
||||||
"No volumes match filters."
|
"No volumes match filters."
|
||||||
) : (
|
) : (
|
||||||
<span className="font-mono">
|
<span className="font-mono">
|
||||||
<span className="text-strong-accent font-bold">{filteredVolumes.length}</span> volume
|
<span className="text-strong-accent font-bold">{rows.length}</span> volume
|
||||||
{filteredVolumes.length > 1 ? "s" : ""}
|
{rows.length > 1 ? "s" : ""}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,9 @@ function ConfigRow({ icon, label, value, mono }: ConfigRowProps) {
|
||||||
<div className="flex items-center gap-3 py-3 first:pt-0 last:pb-0">
|
<div className="flex items-center gap-3 py-3 first:pt-0 last:pb-0">
|
||||||
<span className="text-muted-foreground shrink-0">{icon}</span>
|
<span className="text-muted-foreground shrink-0">{icon}</span>
|
||||||
<span className="text-sm text-muted-foreground w-40 shrink-0">{label}</span>
|
<span className="text-sm text-muted-foreground w-40 shrink-0">{label}</span>
|
||||||
<span className={cn("text-sm break-all", { "font-mono bg-muted/50 px-2 py-0.5 rounded": mono })}>{value}</span>
|
<span className={cn("text-sm break-all", { "font-mono bg-muted/50 px-2 py-0.5 rounded": mono })}>
|
||||||
|
{value}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -43,12 +45,19 @@ function BackendConfigRows({ volume }: { volume: Volume }) {
|
||||||
|
|
||||||
switch (config.backend) {
|
switch (config.backend) {
|
||||||
case "directory":
|
case "directory":
|
||||||
return <ConfigRow icon={<FolderOpen className="h-4 w-4" />} label="Directory Path" value={config.path} mono />;
|
return (
|
||||||
|
<ConfigRow icon={<FolderOpen className="h-4 w-4" />} label="Directory Path" value={config.path} mono />
|
||||||
|
);
|
||||||
case "nfs":
|
case "nfs":
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ConfigRow icon={<FolderOpen className="h-4 w-4" />} label="Server" value={config.server} mono />
|
<ConfigRow icon={<FolderOpen className="h-4 w-4" />} label="Server" value={config.server} mono />
|
||||||
<ConfigRow icon={<FolderOpen className="h-4 w-4" />} label="Export Path" value={config.exportPath} mono />
|
<ConfigRow
|
||||||
|
icon={<FolderOpen className="h-4 w-4" />}
|
||||||
|
label="Export Path"
|
||||||
|
value={config.exportPath}
|
||||||
|
mono
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
case "smb":
|
case "smb":
|
||||||
|
|
@ -84,6 +93,8 @@ function BackendConfigRows({ volume }: { volume: Volume }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function DonutChart({ statfs }: { statfs: StatFs }) {
|
function DonutChart({ statfs }: { statfs: StatFs }) {
|
||||||
|
const { used = 0, total = 0 } = statfs;
|
||||||
|
|
||||||
const chartData = useMemo(
|
const chartData = useMemo(
|
||||||
() => [
|
() => [
|
||||||
{ name: "Used", value: statfs.used, fill: "var(--strong-accent)" },
|
{ name: "Used", value: statfs.used, fill: "var(--strong-accent)" },
|
||||||
|
|
@ -93,8 +104,8 @@ function DonutChart({ statfs }: { statfs: StatFs }) {
|
||||||
);
|
);
|
||||||
|
|
||||||
const usagePercentage = useMemo(() => {
|
const usagePercentage = useMemo(() => {
|
||||||
return Math.round((statfs.used / statfs.total) * 100);
|
return Math.round((used / total) * 100);
|
||||||
}, [statfs]);
|
}, [used, total]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ChartContainer config={{}} className="mx-auto aspect-square max-h-[200px]">
|
<ChartContainer config={{}} className="mx-auto aspect-square max-h-[200px]">
|
||||||
|
|
@ -114,10 +125,18 @@ function DonutChart({ statfs }: { statfs: StatFs }) {
|
||||||
if (viewBox && "cx" in viewBox && "cy" in viewBox) {
|
if (viewBox && "cx" in viewBox && "cy" in viewBox) {
|
||||||
return (
|
return (
|
||||||
<text x={viewBox.cx} y={viewBox.cy} textAnchor="middle" dominantBaseline="middle">
|
<text x={viewBox.cx} y={viewBox.cy} textAnchor="middle" dominantBaseline="middle">
|
||||||
<tspan x={viewBox.cx} y={viewBox.cy} className="fill-foreground text-2xl font-bold">
|
<tspan
|
||||||
|
x={viewBox.cx}
|
||||||
|
y={viewBox.cy}
|
||||||
|
className="fill-foreground text-2xl font-bold"
|
||||||
|
>
|
||||||
{usagePercentage}%
|
{usagePercentage}%
|
||||||
</tspan>
|
</tspan>
|
||||||
<tspan x={viewBox.cx} y={(viewBox.cy || 0) + 20} className="fill-muted-foreground text-xs">
|
<tspan
|
||||||
|
x={viewBox.cx}
|
||||||
|
y={(viewBox.cy || 0) + 20}
|
||||||
|
className="fill-muted-foreground text-xs"
|
||||||
|
>
|
||||||
Used
|
Used
|
||||||
</tspan>
|
</tspan>
|
||||||
</text>
|
</text>
|
||||||
|
|
@ -132,7 +151,9 @@ function DonutChart({ statfs }: { statfs: StatFs }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const VolumeInfoTabContent = ({ volume, statfs }: Props) => {
|
export const VolumeInfoTabContent = ({ volume, statfs }: Props) => {
|
||||||
const hasStorage = statfs.total > 0;
|
const { total = 0, used = 0, free = 0 } = statfs;
|
||||||
|
|
||||||
|
const hasStorage = total > 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="px-6 py-6 @container/inner">
|
<Card className="px-6 py-6 @container/inner">
|
||||||
|
|
@ -144,7 +165,11 @@ export const VolumeInfoTabContent = ({ volume, statfs }: Props) => {
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
<div className="space-y-0 divide-y divide-border/50">
|
<div className="space-y-0 divide-y divide-border/50">
|
||||||
<ConfigRow icon={<HardDrive className="h-4 w-4" />} label="Name" value={volume.name} />
|
<ConfigRow icon={<HardDrive className="h-4 w-4" />} label="Name" value={volume.name} />
|
||||||
<ConfigRow icon={<HardDrive className="h-4 w-4" />} label="Backend" value={backendLabels[volume.type]} />
|
<ConfigRow
|
||||||
|
icon={<HardDrive className="h-4 w-4" />}
|
||||||
|
label="Backend"
|
||||||
|
value={backendLabels[volume.type]}
|
||||||
|
/>
|
||||||
<BackendConfigRows volume={volume} />
|
<BackendConfigRows volume={volume} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -162,21 +187,21 @@ export const VolumeInfoTabContent = ({ volume, statfs }: Props) => {
|
||||||
<HardDrive className="h-4 w-4 text-muted-foreground" />
|
<HardDrive className="h-4 w-4 text-muted-foreground" />
|
||||||
<span className="text-sm font-medium">Total</span>
|
<span className="text-sm font-medium">Total</span>
|
||||||
</div>
|
</div>
|
||||||
<ByteSize bytes={statfs.total} className="font-mono text-sm" />
|
<ByteSize bytes={total} className="font-mono text-sm" />
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center justify-between p-3 rounded-lg bg-muted/50">
|
<div className="flex items-center justify-between p-3 rounded-lg bg-muted/50">
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
<div className="h-3 w-3 rounded-full bg-strong-accent" />
|
<div className="h-3 w-3 rounded-full bg-strong-accent" />
|
||||||
<span className="text-sm font-medium">Used</span>
|
<span className="text-sm font-medium">Used</span>
|
||||||
</div>
|
</div>
|
||||||
<ByteSize bytes={statfs.used} className="font-mono text-sm" />
|
<ByteSize bytes={used} className="font-mono text-sm" />
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center justify-between p-3 rounded-lg bg-muted/50">
|
<div className="flex items-center justify-between p-3 rounded-lg bg-muted/50">
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
<div className="h-3 w-3 rounded-full bg-primary" />
|
<div className="h-3 w-3 rounded-full bg-primary" />
|
||||||
<span className="text-sm font-medium">Free</span>
|
<span className="text-sm font-medium">Free</span>
|
||||||
</div>
|
</div>
|
||||||
<ByteSize bytes={statfs.free} className="font-mono text-sm" />
|
<ByteSize bytes={free} className="font-mono text-sm" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ type User = {
|
||||||
dateFormat: string;
|
dateFormat: string;
|
||||||
timeFormat: string;
|
timeFormat: string;
|
||||||
twoFactorEnabled?: boolean | null;
|
twoFactorEnabled?: boolean | null;
|
||||||
|
hasCredentialPassword?: boolean;
|
||||||
role?: string | null | undefined;
|
role?: string | null | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -14,4 +15,5 @@ export type AppContext = {
|
||||||
user: User | null;
|
user: User | null;
|
||||||
hasUsers: boolean;
|
hasUsers: boolean;
|
||||||
sidebarOpen: boolean;
|
sidebarOpen: boolean;
|
||||||
|
hasSkippedRecoveryKeyDownload: boolean;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE `volumes_table` ADD `agent_id` text DEFAULT 'local' NOT NULL;--> statement-breakpoint
|
||||||
|
CREATE INDEX `volumes_table_agent_id_idx` ON `volumes_table` (`agent_id`);
|
||||||
2505
app/drizzle/20260416123510_supreme_stone_men/snapshot.json
Normal file
2505
app/drizzle/20260416123510_supreme_stone_men/snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
17
app/drizzle/20260428161759_productive_namor/migration.sql
Normal file
17
app/drizzle/20260428161759_productive_namor/migration.sql
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
CREATE TABLE `passkey` (
|
||||||
|
`id` text PRIMARY KEY,
|
||||||
|
`name` text,
|
||||||
|
`public_key` text NOT NULL,
|
||||||
|
`user_id` text NOT NULL,
|
||||||
|
`credential_id` text NOT NULL,
|
||||||
|
`counter` integer NOT NULL,
|
||||||
|
`device_type` text NOT NULL,
|
||||||
|
`backed_up` integer NOT NULL,
|
||||||
|
`transports` text,
|
||||||
|
`created_at` integer DEFAULT (unixepoch() * 1000) NOT NULL,
|
||||||
|
`aaguid` text,
|
||||||
|
CONSTRAINT `fk_passkey_user_id_users_table_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users_table`(`id`) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE INDEX `passkey_userId_idx` ON `passkey` (`user_id`);--> statement-breakpoint
|
||||||
|
CREATE INDEX `passkey_credentialID_idx` ON `passkey` (`credential_id`);
|
||||||
2491
app/drizzle/20260428161759_productive_namor/snapshot.json
Normal file
2491
app/drizzle/20260428161759_productive_namor/snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
1
app/drizzle/20260429214453_classy_namora/migration.sql
Normal file
1
app/drizzle/20260429214453_classy_namora/migration.sql
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE `backup_schedules_table` ADD `backup_webhooks` text;
|
||||||
2341
app/drizzle/20260429214453_classy_namora/snapshot.json
Normal file
2341
app/drizzle/20260429214453_classy_namora/snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,3 @@
|
||||||
|
ALTER TABLE `notification_destinations_table` ADD `status` text DEFAULT 'unknown' NOT NULL;--> statement-breakpoint
|
||||||
|
ALTER TABLE `notification_destinations_table` ADD `last_checked` integer;--> statement-breakpoint
|
||||||
|
ALTER TABLE `notification_destinations_table` ADD `last_error` text;
|
||||||
2371
app/drizzle/20260502085340_sudden_maria_hill/snapshot.json
Normal file
2371
app/drizzle/20260502085340_sudden_maria_hill/snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
16
app/drizzle/20260505165117_early_purple_man/migration.sql
Normal file
16
app/drizzle/20260505165117_early_purple_man/migration.sql
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
CREATE TABLE `agents_table` (
|
||||||
|
`id` text PRIMARY KEY,
|
||||||
|
`organization_id` text,
|
||||||
|
`name` text NOT NULL,
|
||||||
|
`kind` text NOT NULL,
|
||||||
|
`status` text DEFAULT 'offline' NOT NULL,
|
||||||
|
`capabilities` text DEFAULT '{}' NOT NULL,
|
||||||
|
`last_seen_at` integer,
|
||||||
|
`last_ready_at` integer,
|
||||||
|
`created_at` integer DEFAULT (unixepoch() * 1000) NOT NULL,
|
||||||
|
`updated_at` integer DEFAULT (unixepoch() * 1000) NOT NULL,
|
||||||
|
CONSTRAINT `fk_agents_table_organization_id_organization_id_fk` FOREIGN KEY (`organization_id`) REFERENCES `organization`(`id`) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE INDEX `agents_table_organization_id_idx` ON `agents_table` (`organization_id`);--> statement-breakpoint
|
||||||
|
CREATE INDEX `agents_table_status_idx` ON `agents_table` (`status`);
|
||||||
2521
app/drizzle/20260505165117_early_purple_man/snapshot.json
Normal file
2521
app/drizzle/20260505165117_early_purple_man/snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
28
app/drizzle/20260518202140_numerous_prodigy/migration.sql
Normal file
28
app/drizzle/20260518202140_numerous_prodigy/migration.sql
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
CREATE TABLE `repository_lock_waiters` (
|
||||||
|
`id` text PRIMARY KEY,
|
||||||
|
`repository_id` text NOT NULL,
|
||||||
|
`type` text NOT NULL,
|
||||||
|
`operation` text NOT NULL,
|
||||||
|
`owner_id` text NOT NULL,
|
||||||
|
`requested_at` integer NOT NULL,
|
||||||
|
`expires_at` integer NOT NULL,
|
||||||
|
`heartbeat_at` integer NOT NULL
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE TABLE `repository_locks` (
|
||||||
|
`id` text PRIMARY KEY,
|
||||||
|
`repository_id` text NOT NULL,
|
||||||
|
`type` text NOT NULL,
|
||||||
|
`operation` text NOT NULL,
|
||||||
|
`owner_id` text NOT NULL,
|
||||||
|
`acquired_at` integer NOT NULL,
|
||||||
|
`expires_at` integer NOT NULL,
|
||||||
|
`heartbeat_at` integer NOT NULL
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE INDEX `repository_lock_waiters_repository_id_idx` ON `repository_lock_waiters` (`repository_id`);--> statement-breakpoint
|
||||||
|
CREATE INDEX `repository_lock_waiters_expires_at_idx` ON `repository_lock_waiters` (`expires_at`);--> statement-breakpoint
|
||||||
|
CREATE INDEX `repository_lock_waiters_owner_id_idx` ON `repository_lock_waiters` (`owner_id`);--> statement-breakpoint
|
||||||
|
CREATE INDEX `repository_locks_repository_id_idx` ON `repository_locks` (`repository_id`);--> statement-breakpoint
|
||||||
|
CREATE INDEX `repository_locks_expires_at_idx` ON `repository_locks` (`expires_at`);--> statement-breakpoint
|
||||||
|
CREATE INDEX `repository_locks_owner_id_idx` ON `repository_locks` (`owner_id`);
|
||||||
2811
app/drizzle/20260518202140_numerous_prodigy/snapshot.json
Normal file
2811
app/drizzle/20260518202140_numerous_prodigy/snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
1
app/drizzle/20260522174225_organic_nehzno/migration.sql
Normal file
1
app/drizzle/20260522174225_organic_nehzno/migration.sql
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE `two_factor` ADD `verified` integer DEFAULT true NOT NULL;
|
||||||
2821
app/drizzle/20260522174225_organic_nehzno/snapshot.json
Normal file
2821
app/drizzle/20260522174225_organic_nehzno/snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
22
app/drizzle/20260530131042_wakeful_santa_claus/migration.sql
Normal file
22
app/drizzle/20260530131042_wakeful_santa_claus/migration.sql
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
CREATE TABLE `tasks` (
|
||||||
|
`id` text PRIMARY KEY,
|
||||||
|
`organization_id` text NOT NULL,
|
||||||
|
`kind` text NOT NULL,
|
||||||
|
`status` text NOT NULL,
|
||||||
|
`resource_type` text NOT NULL,
|
||||||
|
`resource_id` text NOT NULL,
|
||||||
|
`target_agent_id` text,
|
||||||
|
`input` text NOT NULL,
|
||||||
|
`progress` text,
|
||||||
|
`result` text,
|
||||||
|
`error` text,
|
||||||
|
`cancellation_requested` integer DEFAULT false NOT NULL,
|
||||||
|
`created_at` integer DEFAULT (unixepoch() * 1000) NOT NULL,
|
||||||
|
`started_at` integer,
|
||||||
|
`updated_at` integer DEFAULT (unixepoch() * 1000) NOT NULL,
|
||||||
|
`finished_at` integer,
|
||||||
|
CONSTRAINT `fk_tasks_organization_id_organization_id_fk` FOREIGN KEY (`organization_id`) REFERENCES `organization`(`id`) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE INDEX `tasks_org_kind_resource_status_idx` ON `tasks` (`organization_id`,`kind`,`resource_type`,`resource_id`,`status`);--> statement-breakpoint
|
||||||
|
CREATE INDEX `tasks_org_status_updated_at_idx` ON `tasks` (`organization_id`,`status`,`updated_at`);
|
||||||
3215
app/drizzle/20260530131042_wakeful_santa_claus/snapshot.json
Normal file
3215
app/drizzle/20260530131042_wakeful_santa_claus/snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
2
app/lib/recovery-key-skip.ts
Normal file
2
app/lib/recovery-key-skip.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
export const RECOVERY_KEY_DOWNLOAD_SKIPPED_COOKIE_NAME = "zerobyte_recovery_key_download_skipped";
|
||||||
|
export const RECOVERY_KEY_DOWNLOAD_SKIPPED_COOKIE_MAX_AGE = 60 * 60;
|
||||||
|
|
@ -1,9 +1,13 @@
|
||||||
|
export const PASSKEY_LOGIN_FAILED_ERROR = "PASSKEY_LOGIN_FAILED";
|
||||||
|
|
||||||
export const LOGIN_ERROR_CODES = [
|
export const LOGIN_ERROR_CODES = [
|
||||||
"ACCOUNT_LINK_REQUIRED",
|
"ACCOUNT_LINK_REQUIRED",
|
||||||
"EMAIL_NOT_VERIFIED",
|
"EMAIL_NOT_VERIFIED",
|
||||||
"INVITE_REQUIRED",
|
"INVITE_REQUIRED",
|
||||||
"BANNED_USER",
|
"BANNED_USER",
|
||||||
"SSO_LOGIN_FAILED",
|
"SSO_LOGIN_FAILED",
|
||||||
|
PASSKEY_LOGIN_FAILED_ERROR,
|
||||||
|
"ERROR_INVALID_RP_ID",
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export type LoginErrorCode = (typeof LOGIN_ERROR_CODES)[number];
|
export type LoginErrorCode = (typeof LOGIN_ERROR_CODES)[number];
|
||||||
|
|
@ -20,5 +24,9 @@ export function getLoginErrorDescription(errorCode: LoginErrorCode): string {
|
||||||
return "You have been banned from this application. Please contact support if you believe this is an error.";
|
return "You have been banned from this application. Please contact support if you believe this is an error.";
|
||||||
case "SSO_LOGIN_FAILED":
|
case "SSO_LOGIN_FAILED":
|
||||||
return "SSO authentication failed. Please try again.";
|
return "SSO authentication failed. Please try again.";
|
||||||
|
case PASSKEY_LOGIN_FAILED_ERROR:
|
||||||
|
return "Passkey sign-in failed. The passkey didn't verify your identity with a PIN, biometrics, or screen lock. Please use a verified passkey or sign in with your password.";
|
||||||
|
case "ERROR_INVALID_RP_ID":
|
||||||
|
return "You can only sign in with a passkey on the domain set by the BASE_URL environment variable";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
import { createMiddleware } from "@tanstack/react-start";
|
import { createMiddleware } from "@tanstack/react-start";
|
||||||
import { redirect } from "@tanstack/react-router";
|
import { redirect } from "@tanstack/react-router";
|
||||||
import { auth } from "~/server/lib/auth";
|
import { auth } from "~/server/lib/auth";
|
||||||
import { getRequestHeaders } from "@tanstack/react-start/server";
|
import { getCookie, getRequestHeaders } from "@tanstack/react-start/server";
|
||||||
import { authService } from "~/server/modules/auth/auth.service";
|
import { authService } from "~/server/modules/auth/auth.service";
|
||||||
import { isAuthRoute } from "~/lib/auth-routes";
|
import { isAuthRoute } from "~/lib/auth-routes";
|
||||||
|
import { RECOVERY_KEY_DOWNLOAD_SKIPPED_COOKIE_NAME } from "~/lib/recovery-key-skip";
|
||||||
|
|
||||||
export const authMiddleware = createMiddleware().server(async ({ next, request }) => {
|
export const authMiddleware = createMiddleware().server(async ({ next, request }) => {
|
||||||
const headers = getRequestHeaders();
|
const headers = getRequestHeaders();
|
||||||
|
|
@ -20,7 +21,13 @@ export const authMiddleware = createMiddleware().server(async ({ next, request }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session?.user?.id) {
|
if (session?.user?.id) {
|
||||||
if (!session.user.hasDownloadedResticPassword && pathname !== "/download-recovery-key") {
|
const hasSkippedRecoveryKeyDownload = getCookie(RECOVERY_KEY_DOWNLOAD_SKIPPED_COOKIE_NAME) === session.user.id;
|
||||||
|
|
||||||
|
if (
|
||||||
|
!session.user.hasDownloadedResticPassword &&
|
||||||
|
!hasSkippedRecoveryKeyDownload &&
|
||||||
|
pathname !== "/download-recovery-key"
|
||||||
|
) {
|
||||||
throw redirect({ to: "/download-recovery-key" });
|
throw redirect({ to: "/download-recovery-key" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,24 @@
|
||||||
import { createFileRoute } from "@tanstack/react-router";
|
import { createFileRoute } from "@tanstack/react-router";
|
||||||
|
import { createServerFn } from "@tanstack/react-start";
|
||||||
|
import { getRequestHeaders } from "@tanstack/react-start/server";
|
||||||
import { DownloadRecoveryKeyPage } from "~/client/modules/auth/routes/download-recovery-key";
|
import { DownloadRecoveryKeyPage } from "~/client/modules/auth/routes/download-recovery-key";
|
||||||
|
import { auth } from "~/server/lib/auth";
|
||||||
|
import { userHasCredentialPassword } from "~/server/modules/auth/helpers";
|
||||||
|
|
||||||
|
const getRecoveryKeyUserState = createServerFn({ method: "GET" }).handler(async () => {
|
||||||
|
const headers = getRequestHeaders();
|
||||||
|
const session = await auth.api.getSession({ headers });
|
||||||
|
|
||||||
|
return {
|
||||||
|
hasCredentialPassword: session?.user ? await userHasCredentialPassword(session.user.id) : false,
|
||||||
|
userId: session?.user.id ?? null,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
export const Route = createFileRoute("/(auth)/download-recovery-key")({
|
export const Route = createFileRoute("/(auth)/download-recovery-key")({
|
||||||
component: DownloadRecoveryKeyPage,
|
component: RouteComponent,
|
||||||
errorComponent: () => <div>Failed to load recovery key</div>,
|
errorComponent: () => <div>Failed to load recovery key</div>,
|
||||||
|
loader: async () => getRecoveryKeyUserState(),
|
||||||
head: () => ({
|
head: () => ({
|
||||||
meta: [
|
meta: [
|
||||||
{ title: "Zerobyte - Download Recovery Key" },
|
{ title: "Zerobyte - Download Recovery Key" },
|
||||||
|
|
@ -14,3 +29,9 @@ export const Route = createFileRoute("/(auth)/download-recovery-key")({
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function RouteComponent() {
|
||||||
|
const { hasCredentialPassword, userId } = Route.useLoaderData();
|
||||||
|
|
||||||
|
return <DownloadRecoveryKeyPage hasCredentialPassword={hasCredentialPassword} userId={userId} />;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { createFileRoute } from "@tanstack/react-router";
|
import { createFileRoute, redirect } from "@tanstack/react-router";
|
||||||
import { createServerFn } from "@tanstack/react-start";
|
import { createServerFn } from "@tanstack/react-start";
|
||||||
import { getCookie, getRequestHeaders } from "@tanstack/react-start/server";
|
import { getCookie, getRequestHeaders } from "@tanstack/react-start/server";
|
||||||
import { Layout } from "~/client/components/layout";
|
import { Layout } from "~/client/components/layout";
|
||||||
|
|
@ -7,17 +7,27 @@ import { authMiddleware } from "~/middleware/auth";
|
||||||
import { auth } from "~/server/lib/auth";
|
import { auth } from "~/server/lib/auth";
|
||||||
import { getOrganizationContext } from "~/server/lib/functions/organization-context";
|
import { getOrganizationContext } from "~/server/lib/functions/organization-context";
|
||||||
import { getServerConstants } from "~/server/lib/functions/server-constants";
|
import { getServerConstants } from "~/server/lib/functions/server-constants";
|
||||||
|
import { userHasCredentialPassword } from "~/server/modules/auth/helpers";
|
||||||
import { authService } from "~/server/modules/auth/auth.service";
|
import { authService } from "~/server/modules/auth/auth.service";
|
||||||
|
import { RECOVERY_KEY_DOWNLOAD_SKIPPED_COOKIE_NAME } from "~/lib/recovery-key-skip";
|
||||||
|
|
||||||
export const fetchUser = createServerFn({ method: "GET" }).handler(async () => {
|
export const fetchUser = createServerFn({ method: "GET" }).handler(async () => {
|
||||||
const headers = getRequestHeaders();
|
const headers = getRequestHeaders();
|
||||||
const session = await auth.api.getSession({ headers });
|
const session = await auth.api.getSession({ headers });
|
||||||
const hasUsers = await authService.hasUsers();
|
const hasUsers = await authService.hasUsers();
|
||||||
|
const hasCredentialPassword = session?.user ? await userHasCredentialPassword(session.user.id) : false;
|
||||||
|
|
||||||
const sidebarCookie = getCookie(SIDEBAR_COOKIE_NAME);
|
const sidebarCookie = getCookie(SIDEBAR_COOKIE_NAME);
|
||||||
const sidebarOpen = !sidebarCookie ? true : sidebarCookie === "true";
|
const sidebarOpen = !sidebarCookie ? true : sidebarCookie === "true";
|
||||||
|
const hasSkippedRecoveryKeyDownload =
|
||||||
|
!!session?.user && getCookie(RECOVERY_KEY_DOWNLOAD_SKIPPED_COOKIE_NAME) === session.user.id;
|
||||||
|
|
||||||
return { user: session?.user ?? null, hasUsers, sidebarOpen };
|
return {
|
||||||
|
user: session?.user ? { ...session.user, hasCredentialPassword } : null,
|
||||||
|
hasUsers,
|
||||||
|
sidebarOpen,
|
||||||
|
hasSkippedRecoveryKeyDownload,
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
export const Route = createFileRoute("/(dashboard)")({
|
export const Route = createFileRoute("/(dashboard)")({
|
||||||
|
|
@ -39,6 +49,14 @@ export const Route = createFileRoute("/(dashboard)")({
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if (
|
||||||
|
authContext.user &&
|
||||||
|
!authContext.user.hasDownloadedResticPassword &&
|
||||||
|
!authContext.hasSkippedRecoveryKeyDownload
|
||||||
|
) {
|
||||||
|
throw redirect({ to: "/download-recovery-key" });
|
||||||
|
}
|
||||||
|
|
||||||
return authContext;
|
return authContext;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { z } from "zod";
|
||||||
import { resticBackupProgressMetricsSchema, resticBackupRunSummarySchema } from "@zerobyte/core/restic";
|
import { resticBackupProgressMetricsSchema, resticBackupRunSummarySchema } from "@zerobyte/core/restic";
|
||||||
|
|
||||||
const backupEventStatusSchema = z.enum(["success", "error", "stopped", "warning"]);
|
const backupEventStatusSchema = z.enum(["success", "error", "stopped", "warning"]);
|
||||||
const restoreEventStatusSchema = z.enum(["success", "error"]);
|
const restoreEventStatusSchema = z.enum(["success", "error", "cancelled"]);
|
||||||
|
|
||||||
const backupEventBaseSchema = z.object({
|
const backupEventBaseSchema = z.object({
|
||||||
scheduleId: z.string(),
|
scheduleId: z.string(),
|
||||||
|
|
@ -15,6 +15,7 @@ const organizationScopedSchema = z.object({
|
||||||
});
|
});
|
||||||
|
|
||||||
const restoreEventBaseSchema = z.object({
|
const restoreEventBaseSchema = z.object({
|
||||||
|
restoreId: z.string(),
|
||||||
repositoryId: z.string(),
|
repositoryId: z.string(),
|
||||||
snapshotId: z.string(),
|
snapshotId: z.string(),
|
||||||
});
|
});
|
||||||
|
|
@ -51,6 +52,8 @@ const restoreProgressEventSchema = restoreEventBaseSchema.extend(restoreProgress
|
||||||
const restoreCompletedEventSchema = restoreEventBaseSchema.extend({
|
const restoreCompletedEventSchema = restoreEventBaseSchema.extend({
|
||||||
status: restoreEventStatusSchema,
|
status: restoreEventStatusSchema,
|
||||||
error: z.string().optional(),
|
error: z.string().optional(),
|
||||||
|
filesRestored: z.number().optional(),
|
||||||
|
filesSkipped: z.number().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const serverBackupStartedEventSchema = organizationScopedSchema.extend(backupStartedEventSchema.shape);
|
const serverBackupStartedEventSchema = organizationScopedSchema.extend(backupStartedEventSchema.shape);
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,13 @@ export const NOTIFICATION_TYPES = {
|
||||||
|
|
||||||
export type NotificationType = keyof typeof NOTIFICATION_TYPES;
|
export type NotificationType = keyof typeof NOTIFICATION_TYPES;
|
||||||
|
|
||||||
|
const headerNamePattern = /^[A-Za-z0-9-]+$/;
|
||||||
|
const notificationHeaderSchema = z.string().refine((header) => {
|
||||||
|
const [key, value] = header.split(":", 2);
|
||||||
|
|
||||||
|
return !!key && headerNamePattern.test(key.trim()) && (value?.trim().length ?? 0) > 0;
|
||||||
|
}, "Headers must use non-empty Key: Value format with valid header names");
|
||||||
|
|
||||||
export const emailNotificationConfigSchema = z.object({
|
export const emailNotificationConfigSchema = z.object({
|
||||||
type: z.literal("email"),
|
type: z.literal("email"),
|
||||||
smtpHost: z.string().min(1),
|
smtpHost: z.string().min(1),
|
||||||
|
|
@ -79,7 +86,7 @@ export const genericNotificationConfigSchema = z.object({
|
||||||
url: z.string().min(1),
|
url: z.string().min(1),
|
||||||
method: z.enum(["GET", "POST"]),
|
method: z.enum(["GET", "POST"]),
|
||||||
contentType: z.string().optional(),
|
contentType: z.string().optional(),
|
||||||
headers: z.array(z.string()).optional(),
|
headers: z.array(notificationHeaderSchema).optional(),
|
||||||
useJson: z.boolean().optional(),
|
useJson: z.boolean().optional(),
|
||||||
titleKey: z.string().optional(),
|
titleKey: z.string().optional(),
|
||||||
messageKey: z.string().optional(),
|
messageKey: z.string().optional(),
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,12 @@ const serverEventPayloads = {
|
||||||
"volume:unmounted": payload<{ organizationId: string; volumeName: string }>(),
|
"volume:unmounted": payload<{ organizationId: string; volumeName: string }>(),
|
||||||
"volume:updated": payload<{ organizationId: string; volumeName: string }>(),
|
"volume:updated": payload<{ organizationId: string; volumeName: string }>(),
|
||||||
"volume:status_changed": payload<{ organizationId: string; volumeName: string; status: string }>(),
|
"volume:status_changed": payload<{ organizationId: string; volumeName: string; status: string }>(),
|
||||||
|
"notification:updated": payload<{
|
||||||
|
organizationId: string;
|
||||||
|
notificationId: number;
|
||||||
|
notificationName: string;
|
||||||
|
status: "healthy" | "error" | "unknown";
|
||||||
|
}>(),
|
||||||
"doctor:started": payload<{ organizationId: string; repositoryId: string; repositoryName: string }>(),
|
"doctor:started": payload<{ organizationId: string; repositoryId: string; repositoryName: string }>(),
|
||||||
"doctor:completed": payload<
|
"doctor:completed": payload<
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import { Scalar } from "@scalar/hono-api-reference";
|
import { Scalar } from "@scalar/hono-api-reference";
|
||||||
|
import type { Context, Next } from "hono";
|
||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
import { bodyLimit } from "hono/body-limit";
|
import { bodyLimit } from "hono/body-limit";
|
||||||
import { cors } from "hono/cors";
|
import { cors } from "hono/cors";
|
||||||
import { logger as honoLogger } from "hono/logger";
|
|
||||||
import { secureHeaders } from "hono/secure-headers";
|
import { secureHeaders } from "hono/secure-headers";
|
||||||
import { rateLimiter } from "hono-rate-limiter";
|
import { rateLimiter } from "hono-rate-limiter";
|
||||||
import { openAPIRouteHandler } from "hono-openapi";
|
import { openAPIRouteHandler } from "hono-openapi";
|
||||||
|
|
@ -21,6 +21,20 @@ import { config } from "./core/config";
|
||||||
import { auth } from "~/server/lib/auth";
|
import { auth } from "~/server/lib/auth";
|
||||||
import { db } from "./db/db";
|
import { db } from "./db/db";
|
||||||
|
|
||||||
|
const requestLogger = async (c: Context, next: Next) => {
|
||||||
|
const method = c.req.method;
|
||||||
|
const path = c.req.path;
|
||||||
|
const start = performance.now();
|
||||||
|
|
||||||
|
logger.debug(`<-- ${method} ${path}`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await next();
|
||||||
|
} finally {
|
||||||
|
logger.debug(`--> ${method} ${path} ${c.res.status} ${Math.round(performance.now() - start)}ms`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const generalDescriptor = (app: Hono) =>
|
const generalDescriptor = (app: Hono) =>
|
||||||
openAPIRouteHandler(app, {
|
openAPIRouteHandler(app, {
|
||||||
documentation: {
|
documentation: {
|
||||||
|
|
@ -49,7 +63,7 @@ export const createApp = () => {
|
||||||
|
|
||||||
if (config.environment === "production") {
|
if (config.environment === "production") {
|
||||||
app.use(secureHeaders());
|
app.use(secureHeaders());
|
||||||
app.use(honoLogger());
|
app.use(requestLogger);
|
||||||
}
|
}
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
|
|
@ -86,14 +100,14 @@ export const createApp = () => {
|
||||||
app.get("/api/v1/docs", requireAuth, scalarDescriptor);
|
app.get("/api/v1/docs", requireAuth, scalarDescriptor);
|
||||||
|
|
||||||
app.onError((err, c) => {
|
app.onError((err, c) => {
|
||||||
logger.error(`${c.req.url}: ${err.message}`);
|
const { status, message, details } = handleServiceError(err);
|
||||||
|
|
||||||
|
logger.error(`${c.req.url}: ${message}`);
|
||||||
|
|
||||||
if (err.cause instanceof Error) {
|
if (err.cause instanceof Error) {
|
||||||
logger.error(err.cause.message);
|
logger.error(err.cause.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { status, message, details } = handleServiceError(err);
|
|
||||||
|
|
||||||
return c.json(details ? { message, details } : { message }, status as 500);
|
return c.json(details ? { message, details } : { message }, status as 500);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ describe("parseConfig", () => {
|
||||||
ENABLE_DEV_PANEL: "true",
|
ENABLE_DEV_PANEL: "true",
|
||||||
SERVER_IP: "0.0.0.0",
|
SERVER_IP: "0.0.0.0",
|
||||||
SERVER_IDLE_TIMEOUT: "120",
|
SERVER_IDLE_TIMEOUT: "120",
|
||||||
|
WEBHOOK_TIMEOUT: "90",
|
||||||
PORT: "8080",
|
PORT: "8080",
|
||||||
APP_VERSION: "1.2.3",
|
APP_VERSION: "1.2.3",
|
||||||
MIGRATIONS_PATH: "/tmp/migrations",
|
MIGRATIONS_PATH: "/tmp/migrations",
|
||||||
|
|
@ -57,6 +58,7 @@ describe("parseConfig", () => {
|
||||||
environment: "development",
|
environment: "development",
|
||||||
serverIp: "0.0.0.0",
|
serverIp: "0.0.0.0",
|
||||||
serverIdleTimeout: 120,
|
serverIdleTimeout: 120,
|
||||||
|
webhookTimeout: 90,
|
||||||
resticHostname: "configured-restic-host",
|
resticHostname: "configured-restic-host",
|
||||||
port: 8080,
|
port: 8080,
|
||||||
migrationsPath: "/tmp/migrations",
|
migrationsPath: "/tmp/migrations",
|
||||||
|
|
@ -73,6 +75,7 @@ describe("parseConfig", () => {
|
||||||
},
|
},
|
||||||
provisioningPath: "/tmp/provisioning",
|
provisioningPath: "/tmp/provisioning",
|
||||||
allowedHosts: ["example.com", "admin.example.com", "localhost:3000"],
|
allowedHosts: ["example.com", "admin.example.com", "localhost:3000"],
|
||||||
|
webhookAllowedOrigins: [],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,17 @@
|
||||||
import { describe, expect, test } from "vitest";
|
import { describe, expect, test, vi } from "vitest";
|
||||||
|
import { eq } from "drizzle-orm";
|
||||||
|
import { db } from "~/server/db/db";
|
||||||
|
import { repositoryLocksTable, repositoryLockWaitersTable } from "~/server/db/schema";
|
||||||
import { repoMutex } from "../repository-mutex";
|
import { repoMutex } from "../repository-mutex";
|
||||||
|
|
||||||
|
const acquireWithin = <T>(promise: Promise<T>, ms = 500) =>
|
||||||
|
Promise.race([
|
||||||
|
promise,
|
||||||
|
new Promise<never>((_, reject) => {
|
||||||
|
setTimeout(() => reject(new Error(`Timed out after ${ms}ms`)), ms);
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
describe("RepositoryMutex", () => {
|
describe("RepositoryMutex", () => {
|
||||||
test("should prioritize waiting exclusive locks over new shared locks", async () => {
|
test("should prioritize waiting exclusive locks over new shared locks", async () => {
|
||||||
const repoId = "test-repo";
|
const repoId = "test-repo";
|
||||||
|
|
@ -123,6 +134,37 @@ describe("RepositoryMutex", () => {
|
||||||
expect(repoMutex.isLocked(repoId)).toBe(false);
|
expect(repoMutex.isLocked(repoId)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("should reject aborted queued acquisitions only after waiter cleanup finishes", async () => {
|
||||||
|
const repoId = "abort-waits-for-cleanup";
|
||||||
|
const releaseHolder = await repoMutex.acquireExclusive(repoId, "holder");
|
||||||
|
const controller = new AbortController();
|
||||||
|
const waitingAcquisition = repoMutex.acquireShared(repoId, "waiter", controller.signal);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||||
|
|
||||||
|
const waitersBeforeAbort = await db.query.repositoryLockWaitersTable.findMany({
|
||||||
|
where: { repositoryId: { eq: repoId } },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(waitersBeforeAbort.map((waiter) => waiter.operation)).toEqual(["waiter"]);
|
||||||
|
|
||||||
|
controller.abort(new Error("stop"));
|
||||||
|
await expect(waitingAcquisition).rejects.toThrow("stop");
|
||||||
|
|
||||||
|
const waitersAfterAbort = await db.query.repositoryLockWaitersTable.findMany({
|
||||||
|
where: { repositoryId: { eq: repoId } },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(waitersAfterAbort).toEqual([]);
|
||||||
|
expect(repoMutex.isLocked(repoId)).toBe(true);
|
||||||
|
} finally {
|
||||||
|
releaseHolder();
|
||||||
|
await db.delete(repositoryLockWaitersTable).where(eq(repositoryLockWaitersTable.repositoryId, repoId));
|
||||||
|
await db.delete(repositoryLocksTable).where(eq(repositoryLocksTable.repositoryId, repoId));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test("should allow concurrent shared locks", async () => {
|
test("should allow concurrent shared locks", async () => {
|
||||||
const repoId = "concurrent-shared";
|
const repoId = "concurrent-shared";
|
||||||
const release1 = await repoMutex.acquireShared(repoId, "op1");
|
const release1 = await repoMutex.acquireShared(repoId, "op1");
|
||||||
|
|
@ -327,6 +369,43 @@ describe("RepositoryMutex", () => {
|
||||||
expect(repoMutex.isLocked(repoB)).toBe(false);
|
expect(repoMutex.isLocked(repoB)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("should not leave a promoted shared lock behind if that waiter aborts before observing acquisition", async () => {
|
||||||
|
vi.useFakeTimers();
|
||||||
|
const repoId = "shared-abort-after-promotion";
|
||||||
|
const releaseExclusive = await repoMutex.acquireExclusive(repoId, "holder");
|
||||||
|
const firstSharedPromise = repoMutex.acquireShared(repoId, "shared-1");
|
||||||
|
|
||||||
|
try {
|
||||||
|
await vi.advanceTimersByTimeAsync(100);
|
||||||
|
|
||||||
|
const controller = new AbortController();
|
||||||
|
const secondSharedPromise = repoMutex.acquireShared(repoId, "shared-2", controller.signal);
|
||||||
|
|
||||||
|
await vi.advanceTimersByTimeAsync(140);
|
||||||
|
releaseExclusive();
|
||||||
|
|
||||||
|
// The first shared waiter wakes first and promotes both shared waiters.
|
||||||
|
await vi.advanceTimersByTimeAsync(10);
|
||||||
|
const releaseShared1 = await firstSharedPromise;
|
||||||
|
|
||||||
|
controller.abort(new Error("abort after promotion"));
|
||||||
|
await expect(secondSharedPromise).rejects.toThrow("abort after promotion");
|
||||||
|
|
||||||
|
releaseShared1();
|
||||||
|
|
||||||
|
const remainingLocks = await db.query.repositoryLocksTable.findMany({
|
||||||
|
where: { repositoryId: { eq: repoId } },
|
||||||
|
orderBy: { operation: "asc" },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(remainingLocks).toEqual([]);
|
||||||
|
} finally {
|
||||||
|
await db.delete(repositoryLockWaitersTable).where(eq(repositoryLockWaitersTable.repositoryId, repoId));
|
||||||
|
await db.delete(repositoryLocksTable).where(eq(repositoryLocksTable.repositoryId, repoId));
|
||||||
|
vi.useRealTimers();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test("should safely handle multiple calls to the release function", async () => {
|
test("should safely handle multiple calls to the release function", async () => {
|
||||||
const repoId = "idempotent-release";
|
const repoId = "idempotent-release";
|
||||||
|
|
||||||
|
|
@ -376,4 +455,100 @@ describe("RepositoryMutex", () => {
|
||||||
releaseExclusive();
|
releaseExclusive();
|
||||||
expect(repoMutex.isLocked(repoId)).toBe(false);
|
expect(repoMutex.isLocked(repoId)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("should ignore and clean expired active lock rows during acquisition", async () => {
|
||||||
|
const repoId = "expired-active-lock";
|
||||||
|
const expiredLockId = "expired-active-lock-row";
|
||||||
|
const now = Date.now();
|
||||||
|
|
||||||
|
await db.insert(repositoryLocksTable).values({
|
||||||
|
id: expiredLockId,
|
||||||
|
repositoryId: repoId,
|
||||||
|
type: "exclusive",
|
||||||
|
operation: "stale-check",
|
||||||
|
ownerId: "stale-owner",
|
||||||
|
acquiredAt: now - 10_000,
|
||||||
|
expiresAt: now - 1,
|
||||||
|
heartbeatAt: now - 10_000,
|
||||||
|
});
|
||||||
|
|
||||||
|
const releaseShared = await acquireWithin(repoMutex.acquireShared(repoId, "backup"));
|
||||||
|
|
||||||
|
try {
|
||||||
|
const expiredLock = await db.query.repositoryLocksTable.findFirst({
|
||||||
|
where: { id: { eq: expiredLockId } },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(expiredLock).toBeUndefined();
|
||||||
|
expect(repoMutex.isLocked(repoId)).toBe(true);
|
||||||
|
} finally {
|
||||||
|
releaseShared();
|
||||||
|
await db.delete(repositoryLocksTable).where(eq(repositoryLocksTable.repositoryId, repoId));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should ignore and clean expired waiters during acquisition", async () => {
|
||||||
|
const repoId = "expired-waiter";
|
||||||
|
const expiredWaiterId = "expired-waiter-row";
|
||||||
|
const now = Date.now();
|
||||||
|
|
||||||
|
await db.insert(repositoryLockWaitersTable).values({
|
||||||
|
id: expiredWaiterId,
|
||||||
|
repositoryId: repoId,
|
||||||
|
type: "exclusive",
|
||||||
|
operation: "stale-exclusive",
|
||||||
|
ownerId: "stale-owner",
|
||||||
|
requestedAt: now - 10_000,
|
||||||
|
expiresAt: now - 1,
|
||||||
|
heartbeatAt: now - 10_000,
|
||||||
|
});
|
||||||
|
|
||||||
|
const releaseShared = await acquireWithin(repoMutex.acquireShared(repoId, "backup"));
|
||||||
|
|
||||||
|
try {
|
||||||
|
const expiredWaiter = await db.query.repositoryLockWaitersTable.findFirst({
|
||||||
|
where: { id: { eq: expiredWaiterId } },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(expiredWaiter).toBeUndefined();
|
||||||
|
expect(repoMutex.isLocked(repoId)).toBe(true);
|
||||||
|
} finally {
|
||||||
|
releaseShared();
|
||||||
|
await db.delete(repositoryLockWaitersTable).where(eq(repositoryLockWaitersTable.repositoryId, repoId));
|
||||||
|
await db.delete(repositoryLocksTable).where(eq(repositoryLocksTable.repositoryId, repoId));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should release only the caller lock row", async () => {
|
||||||
|
const repoId = "release-own-row";
|
||||||
|
const foreignLockId = "foreign-release-own-row";
|
||||||
|
const releaseShared = await repoMutex.acquireShared(repoId, "owned-shared");
|
||||||
|
const now = Date.now();
|
||||||
|
|
||||||
|
try {
|
||||||
|
await db.insert(repositoryLocksTable).values({
|
||||||
|
id: foreignLockId,
|
||||||
|
repositoryId: repoId,
|
||||||
|
type: "shared",
|
||||||
|
operation: "foreign-shared",
|
||||||
|
ownerId: "foreign-owner",
|
||||||
|
acquiredAt: now,
|
||||||
|
expiresAt: now + 60_000,
|
||||||
|
heartbeatAt: now,
|
||||||
|
});
|
||||||
|
|
||||||
|
releaseShared();
|
||||||
|
|
||||||
|
const remainingLocks = await db.query.repositoryLocksTable.findMany({
|
||||||
|
where: { repositoryId: { eq: repoId } },
|
||||||
|
orderBy: { operation: "asc" },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(remainingLocks.map((lock) => lock.operation)).toEqual(["foreign-shared"]);
|
||||||
|
expect(repoMutex.isLocked(repoId)).toBe(true);
|
||||||
|
} finally {
|
||||||
|
releaseShared();
|
||||||
|
await db.delete(repositoryLocksTable).where(eq(repositoryLocksTable.repositoryId, repoId));
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,42 +1,25 @@
|
||||||
import { readFileSync } from "node:fs";
|
import { readFileSync } from "node:fs";
|
||||||
import os from "node:os";
|
|
||||||
import { prettifyError, z } from "zod";
|
import { prettifyError, z } from "zod";
|
||||||
import "dotenv/config";
|
import "dotenv/config";
|
||||||
|
import { resolveResticHostname } from "../../../apps/agent/src/restic/hostname";
|
||||||
import { buildAllowedHosts } from "../lib/auth/base-url";
|
import { buildAllowedHosts } from "../lib/auth/base-url";
|
||||||
import { toMessage } from "@zerobyte/core/utils";
|
import { toMessage } from "@zerobyte/core/utils";
|
||||||
|
|
||||||
const unquote = (str: string) => str.trim().replace(/^(['"])(.*)\1$/, "$2");
|
const unquote = (str: string) => str.trim().replace(/^(['"])(.*)\1$/, "$2");
|
||||||
const getResticHostname = () => {
|
|
||||||
try {
|
|
||||||
const mountinfo = readFileSync("/proc/self/mountinfo", "utf-8");
|
|
||||||
const hostnameLine = mountinfo.split("\n").find((line) => line.includes(" /etc/hostname "));
|
|
||||||
const hostname = os.hostname();
|
|
||||||
|
|
||||||
if (hostnameLine) {
|
|
||||||
const containerIdMatch = hostnameLine.match(/[0-9a-f]{64}/);
|
|
||||||
const containerId = containerIdMatch ? containerIdMatch[0] : null;
|
|
||||||
|
|
||||||
if (containerId?.startsWith(hostname)) {
|
|
||||||
return "zerobyte";
|
|
||||||
}
|
|
||||||
|
|
||||||
return hostname || "zerobyte";
|
|
||||||
}
|
|
||||||
} catch {}
|
|
||||||
|
|
||||||
return "zerobyte";
|
|
||||||
};
|
|
||||||
|
|
||||||
const envSchema = z
|
const envSchema = z
|
||||||
.object({
|
.object({
|
||||||
NODE_ENV: z.enum(["development", "production", "test"]).default("production"),
|
NODE_ENV: z.enum(["development", "production", "test"]).default("production"),
|
||||||
SERVER_IP: z.string().default("localhost"),
|
SERVER_IP: z.string().default("localhost"),
|
||||||
SERVER_IDLE_TIMEOUT: z.coerce.number().int().default(60),
|
SERVER_IDLE_TIMEOUT: z.coerce.number().int().default(60),
|
||||||
|
WEBHOOK_TIMEOUT: z.coerce.number().int().default(60),
|
||||||
RESTIC_HOSTNAME: z.string().optional(),
|
RESTIC_HOSTNAME: z.string().optional(),
|
||||||
PORT: z.coerce.number().int().default(4096),
|
PORT: z.coerce.number().int().default(4096),
|
||||||
MIGRATIONS_PATH: z.string().optional(),
|
MIGRATIONS_PATH: z.string().optional(),
|
||||||
APP_VERSION: z.string().default("dev"),
|
APP_VERSION: z.string().default("dev"),
|
||||||
TRUSTED_ORIGINS: z.string().optional(),
|
TRUSTED_ORIGINS: z.string().optional(),
|
||||||
|
PORTLESS_URL: z.string().optional(),
|
||||||
|
PORTLESS_TAILSCALE_URL: z.string().optional(),
|
||||||
TRUST_PROXY: z.string().default("false"),
|
TRUST_PROXY: z.string().default("false"),
|
||||||
DISABLE_RATE_LIMITING: z.string().default("false"),
|
DISABLE_RATE_LIMITING: z.string().default("false"),
|
||||||
APP_SECRET: z.preprocess((value) => (value === "" ? undefined : value), z.string().min(32).max(256).optional()),
|
APP_SECRET: z.preprocess((value) => (value === "" ? undefined : value), z.string().min(32).max(256).optional()),
|
||||||
|
|
@ -44,12 +27,28 @@ const envSchema = z
|
||||||
BASE_URL: z.string(),
|
BASE_URL: z.string(),
|
||||||
ENABLE_DEV_PANEL: z.string().default("false"),
|
ENABLE_DEV_PANEL: z.string().default("false"),
|
||||||
ENABLE_LOCAL_AGENT: z.string().default("false"),
|
ENABLE_LOCAL_AGENT: z.string().default("false"),
|
||||||
|
WEBHOOK_ALLOWED_ORIGINS: z.string().optional(),
|
||||||
PROVISIONING_PATH: z.string().optional(),
|
PROVISIONING_PATH: z.string().optional(),
|
||||||
})
|
})
|
||||||
.transform((s, ctx) => {
|
.transform((s, ctx) => {
|
||||||
const baseUrl = unquote(s.BASE_URL);
|
let baseUrl = unquote(s.BASE_URL);
|
||||||
const trustedOrigins = s.TRUSTED_ORIGINS?.split(",").map(unquote).filter(Boolean).concat(baseUrl) ?? [baseUrl];
|
const trustedOrigins = s.TRUSTED_ORIGINS?.split(",").map(unquote).filter(Boolean) ?? [];
|
||||||
const authOrigins = [baseUrl, ...trustedOrigins];
|
|
||||||
|
if (s.NODE_ENV === "development") {
|
||||||
|
if (s.PORTLESS_URL) {
|
||||||
|
trustedOrigins.push(unquote(s.PORTLESS_URL));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s.PORTLESS_TAILSCALE_URL) {
|
||||||
|
baseUrl = unquote(s.PORTLESS_TAILSCALE_URL);
|
||||||
|
trustedOrigins.push(baseUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
trustedOrigins.push(baseUrl);
|
||||||
|
const uniqueTrustedOrigins = Array.from(new Set(trustedOrigins));
|
||||||
|
const webhookAllowedOrigins = s.WEBHOOK_ALLOWED_ORIGINS?.split(",").map(unquote).filter(Boolean) ?? [];
|
||||||
|
const authOrigins = [baseUrl, ...uniqueTrustedOrigins];
|
||||||
const { allowedHosts, invalidOrigins } = buildAllowedHosts(authOrigins);
|
const { allowedHosts, invalidOrigins } = buildAllowedHosts(authOrigins);
|
||||||
let appSecret = s.APP_SECRET;
|
let appSecret = s.APP_SECRET;
|
||||||
|
|
||||||
|
|
@ -120,11 +119,12 @@ const envSchema = z
|
||||||
environment: s.NODE_ENV,
|
environment: s.NODE_ENV,
|
||||||
serverIp: s.SERVER_IP,
|
serverIp: s.SERVER_IP,
|
||||||
serverIdleTimeout: s.SERVER_IDLE_TIMEOUT,
|
serverIdleTimeout: s.SERVER_IDLE_TIMEOUT,
|
||||||
resticHostname: s.RESTIC_HOSTNAME || getResticHostname(),
|
webhookTimeout: s.WEBHOOK_TIMEOUT,
|
||||||
|
resticHostname: s.RESTIC_HOSTNAME || resolveResticHostname(),
|
||||||
port: s.PORT,
|
port: s.PORT,
|
||||||
migrationsPath: s.MIGRATIONS_PATH,
|
migrationsPath: s.MIGRATIONS_PATH,
|
||||||
appVersion: s.APP_VERSION,
|
appVersion: s.APP_VERSION,
|
||||||
trustedOrigins: trustedOrigins,
|
trustedOrigins: uniqueTrustedOrigins,
|
||||||
trustProxy: s.TRUST_PROXY === "true",
|
trustProxy: s.TRUST_PROXY === "true",
|
||||||
appSecret: appSecret ?? "",
|
appSecret: appSecret ?? "",
|
||||||
baseUrl,
|
baseUrl,
|
||||||
|
|
@ -136,6 +136,7 @@ const envSchema = z
|
||||||
},
|
},
|
||||||
provisioningPath: s.PROVISIONING_PATH,
|
provisioningPath: s.PROVISIONING_PATH,
|
||||||
allowedHosts,
|
allowedHosts,
|
||||||
|
webhookAllowedOrigins,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,10 @@ export const RESTIC_CACHE_DIR = process.env.RESTIC_CACHE_DIR || "/var/lib/zeroby
|
||||||
|
|
||||||
export const DATABASE_URL = process.env.ZEROBYTE_DATABASE_URL || "/var/lib/zerobyte/data/zerobyte.db";
|
export const DATABASE_URL = process.env.ZEROBYTE_DATABASE_URL || "/var/lib/zerobyte/data/zerobyte.db";
|
||||||
export const RESTIC_PASS_FILE = process.env.RESTIC_PASS_FILE || "/var/lib/zerobyte/data/restic.pass";
|
export const RESTIC_PASS_FILE = process.env.RESTIC_PASS_FILE || "/var/lib/zerobyte/data/restic.pass";
|
||||||
export const SSH_KEYS_DIR = "/var/lib/zerobyte/ssh";
|
|
||||||
|
|
||||||
export const RCLONE_CONFIG_DIR = process.env.RCLONE_CONFIG_DIR || "/root/.config/rclone";
|
export const RCLONE_CONFIG_DIR = process.env.RCLONE_CONFIG_DIR || "/root/.config/rclone";
|
||||||
export const RCLONE_CONFIG_FILE = path.join(RCLONE_CONFIG_DIR, "rclone.conf");
|
export const RCLONE_CONFIG_FILE = path.join(RCLONE_CONFIG_DIR, "rclone.conf");
|
||||||
export const RESTORE_BLOCKED_ROOTS = [REPOSITORY_BASE, RESTIC_CACHE_DIR, SSH_KEYS_DIR, RCLONE_CONFIG_DIR, "/app"];
|
export const RESTORE_BLOCKED_ROOTS = [REPOSITORY_BASE, RESTIC_CACHE_DIR, RCLONE_CONFIG_DIR, "/app"];
|
||||||
|
|
||||||
export const DEFAULT_EXCLUDES = [RESTIC_PASS_FILE, REPOSITORY_BASE];
|
export const DEFAULT_EXCLUDES = [RESTIC_PASS_FILE, REPOSITORY_BASE];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,13 @@
|
||||||
|
import { and, eq, lte } from "drizzle-orm";
|
||||||
import { logger } from "@zerobyte/core/node";
|
import { logger } from "@zerobyte/core/node";
|
||||||
|
import { db } from "../db/db";
|
||||||
|
import {
|
||||||
|
repositoryLocksTable,
|
||||||
|
repositoryLockWaitersTable,
|
||||||
|
type RepositoryLock,
|
||||||
|
type RepositoryLockWaiter,
|
||||||
|
} from "../db/schema";
|
||||||
|
import { Effect, Exit, Fiber, Schedule, Scope } from "effect";
|
||||||
|
|
||||||
type LockType = "shared" | "exclusive";
|
type LockType = "shared" | "exclusive";
|
||||||
|
|
||||||
|
|
@ -8,420 +17,545 @@ interface LockRequest {
|
||||||
operation: string;
|
operation: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface LockHolder {
|
interface AcquiredLock {
|
||||||
id: string;
|
id: string;
|
||||||
|
repositoryId: string;
|
||||||
|
type: LockType;
|
||||||
operation: string;
|
operation: string;
|
||||||
acquiredAt: number;
|
acquiredAt: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RepositoryLockState {
|
type RepositoryMutexTransaction = Parameters<Parameters<typeof db.transaction>[0]>[0];
|
||||||
sharedHolders: Map<string, LockHolder>;
|
type HeartbeatTarget = "lock" | "waiter";
|
||||||
exclusiveHolder: LockHolder | null;
|
type QueueAttempt = { status: "acquired"; lock: AcquiredLock } | { status: "waiting" } | { status: "missing" };
|
||||||
waitQueue: Array<{
|
|
||||||
type: LockType;
|
const LOCK_LEASE_MS = 30_000;
|
||||||
operation: string;
|
const LOCK_HEARTBEAT_MS = 5_000;
|
||||||
resolve: (lockId: string) => void;
|
const LOCK_POLL_MS = 250;
|
||||||
}>;
|
const LOCK_POLL_CLEANUP_MS = 5_000;
|
||||||
|
|
||||||
|
const REPOSITORY_MUTEX_INSTANCE = Symbol.for("zerobyte.repositoryMutex.instance");
|
||||||
|
function getRepositoryMutex() {
|
||||||
|
const globalObject = globalThis as typeof globalThis & Record<symbol, RepositoryMutex | undefined>;
|
||||||
|
const mutex = globalObject[REPOSITORY_MUTEX_INSTANCE];
|
||||||
|
|
||||||
|
if (mutex) return mutex;
|
||||||
|
|
||||||
|
const newMutex = new RepositoryMutex();
|
||||||
|
globalObject[REPOSITORY_MUTEX_INSTANCE] = newMutex;
|
||||||
|
return newMutex;
|
||||||
}
|
}
|
||||||
|
|
||||||
class RepositoryMutex {
|
class RepositoryMutex {
|
||||||
private locks = new Map<string, RepositoryLockState>();
|
private ownerId = `owner_${Bun.randomUUIDv7()}`;
|
||||||
private changeListeners = new Map<string, Set<() => void>>();
|
private nextPollCleanupAt = 0;
|
||||||
private lockIdCounter = 0;
|
|
||||||
|
|
||||||
private getOrCreateState(repositoryId: string): RepositoryLockState {
|
|
||||||
let state = this.locks.get(repositoryId);
|
|
||||||
if (!state) {
|
|
||||||
state = {
|
|
||||||
sharedHolders: new Map(),
|
|
||||||
exclusiveHolder: null,
|
|
||||||
waitQueue: [],
|
|
||||||
};
|
|
||||||
this.locks.set(repositoryId, state);
|
|
||||||
}
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
private generateLockId(): string {
|
private generateLockId(): string {
|
||||||
return `lock_${++this.lockIdCounter}_${Date.now()}`;
|
return `lock_${Bun.randomUUIDv7()}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private cleanupStateIfEmpty(repositoryId: string): void {
|
private abortReason(signal: AbortSignal): Error {
|
||||||
const state = this.locks.get(repositoryId);
|
return signal.reason || new Error("Operation aborted");
|
||||||
if (state && state.sharedHolders.size === 0 && !state.exclusiveHolder && state.waitQueue.length === 0) {
|
|
||||||
this.locks.delete(repositoryId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private notifyChange(repositoryId: string): void {
|
private cleanupExpired(tx: RepositoryMutexTransaction, now: number) {
|
||||||
const listeners = this.changeListeners.get(repositoryId);
|
tx.delete(repositoryLocksTable).where(lte(repositoryLocksTable.expiresAt, now)).run();
|
||||||
if (!listeners) {
|
tx.delete(repositoryLockWaitersTable).where(lte(repositoryLockWaitersTable.expiresAt, now)).run();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const listener of listeners) {
|
|
||||||
listener();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private canAcquireImmediately(state: RepositoryLockState | undefined, type: LockType): boolean {
|
private cleanupExpiredDuringPolling(tx: RepositoryMutexTransaction, now: number) {
|
||||||
if (!state) {
|
if (now < this.nextPollCleanupAt) return;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
this.cleanupExpired(tx, now);
|
||||||
|
this.nextPollCleanupAt = now + LOCK_POLL_CLEANUP_MS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private getActiveLocks(tx: RepositoryMutexTransaction, repositoryId: string, now: number) {
|
||||||
|
return tx.query.repositoryLocksTable
|
||||||
|
.findMany({
|
||||||
|
where: { AND: [{ repositoryId: { eq: repositoryId } }, { expiresAt: { gt: now } }] },
|
||||||
|
orderBy: { acquiredAt: "asc", id: "asc" },
|
||||||
|
})
|
||||||
|
.sync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private getWaiters(tx: RepositoryMutexTransaction, repositoryId: string, now: number) {
|
||||||
|
return tx.query.repositoryLockWaitersTable
|
||||||
|
.findMany({
|
||||||
|
where: { AND: [{ repositoryId: { eq: repositoryId } }, { expiresAt: { gt: now } }] },
|
||||||
|
orderBy: { requestedAt: "asc", id: "asc" },
|
||||||
|
})
|
||||||
|
.sync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private getActiveLockById(tx: RepositoryMutexTransaction, lockId: string, now: number) {
|
||||||
|
return tx.query.repositoryLocksTable
|
||||||
|
.findFirst({ where: { AND: [{ id: { eq: lockId } }, { expiresAt: { gt: now } }] } })
|
||||||
|
.sync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private getWaiterById(tx: RepositoryMutexTransaction, waiterId: string, now: number) {
|
||||||
|
return tx.query.repositoryLockWaitersTable
|
||||||
|
.findFirst({ where: { AND: [{ id: { eq: waiterId } }, { expiresAt: { gt: now } }] } })
|
||||||
|
.sync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private canAcquireImmediately(type: LockType, activeLocks: RepositoryLock[], waiters: RepositoryLockWaiter[]) {
|
||||||
if (type === "shared") {
|
if (type === "shared") {
|
||||||
const hasExclusiveInQueue = state.waitQueue.some((item) => item.type === "exclusive");
|
return (
|
||||||
return !state.exclusiveHolder && !hasExclusiveInQueue;
|
!activeLocks.some((lock) => lock.type === "exclusive") &&
|
||||||
|
!waiters.some((waiter) => waiter.type === "exclusive")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return !state.exclusiveHolder && state.sharedHolders.size === 0 && state.waitQueue.length === 0;
|
return activeLocks.length === 0 && waiters.length === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private waitForChange(repositoryIds: string[], signal?: AbortSignal) {
|
private insertLock(
|
||||||
if (signal?.aborted) {
|
tx: RepositoryMutexTransaction,
|
||||||
throw signal.reason || new Error("Operation aborted");
|
request: LockRequest & { id: string; ownerId: string },
|
||||||
|
now: number,
|
||||||
|
) {
|
||||||
|
const lock = {
|
||||||
|
id: request.id,
|
||||||
|
repositoryId: request.repositoryId,
|
||||||
|
type: request.type,
|
||||||
|
operation: request.operation,
|
||||||
|
ownerId: request.ownerId,
|
||||||
|
acquiredAt: now,
|
||||||
|
expiresAt: now + LOCK_LEASE_MS,
|
||||||
|
heartbeatAt: now,
|
||||||
|
};
|
||||||
|
|
||||||
|
tx.insert(repositoryLocksTable).values(lock).run();
|
||||||
|
|
||||||
|
return lock;
|
||||||
|
}
|
||||||
|
|
||||||
|
private tryAcquireManyRows(requests: LockRequest[]) {
|
||||||
|
const now = Date.now();
|
||||||
|
|
||||||
|
return db.transaction((tx) => {
|
||||||
|
this.cleanupExpired(tx, now);
|
||||||
|
|
||||||
|
for (const request of requests) {
|
||||||
|
const activeLocks = this.getActiveLocks(tx, request.repositoryId, now);
|
||||||
|
const waiters = this.getWaiters(tx, request.repositoryId, now);
|
||||||
|
|
||||||
|
if (!this.canAcquireImmediately(request.type, activeLocks, waiters)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return requests.map((request) =>
|
||||||
|
this.insertLock(tx, { ...request, id: this.generateLockId(), ownerId: this.ownerId }, now),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private tryAcquireImmediately(request: LockRequest) {
|
||||||
|
return Effect.gen(this, function* () {
|
||||||
|
const locks = this.tryAcquireManyRows([request]);
|
||||||
|
if (!locks || locks.length === 0) return null;
|
||||||
|
|
||||||
|
const [lock] = locks;
|
||||||
|
return yield* this.createRelease(lock);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private createWaiter(request: LockRequest, waiterId: string) {
|
||||||
|
return Effect.sync(() => {
|
||||||
|
const now = Date.now();
|
||||||
|
db.transaction((tx) => {
|
||||||
|
this.cleanupExpired(tx, now);
|
||||||
|
tx.insert(repositoryLockWaitersTable)
|
||||||
|
.values({
|
||||||
|
id: waiterId,
|
||||||
|
repositoryId: request.repositoryId,
|
||||||
|
type: request.type,
|
||||||
|
operation: request.operation,
|
||||||
|
ownerId: this.ownerId,
|
||||||
|
requestedAt: now,
|
||||||
|
expiresAt: now + LOCK_LEASE_MS,
|
||||||
|
heartbeatAt: now,
|
||||||
|
})
|
||||||
|
.run();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private deleteWaiter(waiterId: string) {
|
||||||
|
return Effect.sync(() =>
|
||||||
|
db
|
||||||
|
.delete(repositoryLockWaitersTable)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(repositoryLockWaitersTable.id, waiterId),
|
||||||
|
eq(repositoryLockWaitersTable.ownerId, this.ownerId),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.run(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private deleteWaiterRow(tx: RepositoryMutexTransaction, waiterId: string): void {
|
||||||
|
tx.delete(repositoryLockWaitersTable).where(eq(repositoryLockWaitersTable.id, waiterId)).run();
|
||||||
|
}
|
||||||
|
|
||||||
|
private promoteWaiter(tx: RepositoryMutexTransaction, waiter: RepositoryLockWaiter, now: number) {
|
||||||
|
this.deleteWaiterRow(tx, waiter.id);
|
||||||
|
return this.insertLock(tx, { ...waiter, id: waiter.id }, now);
|
||||||
|
}
|
||||||
|
|
||||||
|
private getLeadingSharedWaiters(waiters: RepositoryLockWaiter[]) {
|
||||||
|
const leadingSharedWaiters: RepositoryLockWaiter[] = [];
|
||||||
|
for (const waiter of waiters) {
|
||||||
|
if (waiter.type === "exclusive") break;
|
||||||
|
|
||||||
|
leadingSharedWaiters.push(waiter);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise<void>((resolve, reject) => {
|
return leadingSharedWaiters;
|
||||||
const uniqueRepositoryIds = [...new Set(repositoryIds)];
|
}
|
||||||
const cleanupCallbacks: Array<() => void> = [];
|
|
||||||
let settled = false;
|
|
||||||
|
|
||||||
const settle = (callback: () => void) => {
|
private tryPromoteWaiter(waiterId: string): QueueAttempt {
|
||||||
if (settled) {
|
const now = Date.now();
|
||||||
return;
|
|
||||||
|
return db.transaction((tx) => {
|
||||||
|
this.cleanupExpiredDuringPolling(tx, now);
|
||||||
|
|
||||||
|
const activeLock = this.getActiveLockById(tx, waiterId, now);
|
||||||
|
if (activeLock) {
|
||||||
|
return { status: "acquired", lock: activeLock };
|
||||||
|
}
|
||||||
|
|
||||||
|
const waiter = this.getWaiterById(tx, waiterId, now);
|
||||||
|
if (!waiter) {
|
||||||
|
return { status: "missing" };
|
||||||
|
}
|
||||||
|
|
||||||
|
const activeLocks = this.getActiveLocks(tx, waiter.repositoryId, now);
|
||||||
|
const waiters = this.getWaiters(tx, waiter.repositoryId, now);
|
||||||
|
|
||||||
|
if (waiter.type === "exclusive") {
|
||||||
|
if (activeLocks.length > 0 || waiters[0]?.id !== waiter.id) {
|
||||||
|
return { status: "waiting" };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return { status: "acquired", lock: this.promoteWaiter(tx, waiter, now) };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (activeLocks.some((lock) => lock.type === "exclusive")) {
|
||||||
|
return { status: "waiting" };
|
||||||
|
}
|
||||||
|
|
||||||
|
const leadingSharedWaiters = this.getLeadingSharedWaiters(waiters);
|
||||||
|
if (!leadingSharedWaiters.some((queuedWaiter) => queuedWaiter.id === waiter.id)) {
|
||||||
|
return { status: "waiting" };
|
||||||
|
}
|
||||||
|
|
||||||
|
let acquiredLock: AcquiredLock | null = null;
|
||||||
|
for (const sharedWaiter of leadingSharedWaiters) {
|
||||||
|
const lock = this.promoteWaiter(tx, sharedWaiter, now);
|
||||||
|
|
||||||
|
if (sharedWaiter.id === waiter.id) {
|
||||||
|
acquiredLock = lock;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!acquiredLock) {
|
||||||
|
return { status: "waiting" };
|
||||||
|
}
|
||||||
|
|
||||||
|
return { status: "acquired", lock: acquiredLock };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private waitForQueuedLock(request: LockRequest) {
|
||||||
|
const waiterId = this.generateLockId();
|
||||||
|
|
||||||
|
const attempt = Effect.sync(() => this.tryPromoteWaiter(waiterId)).pipe(
|
||||||
|
Effect.flatMap((attempt) => {
|
||||||
|
if (attempt.status === "acquired") {
|
||||||
|
return Effect.succeed(attempt.lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attempt.status === "missing") {
|
||||||
|
return Effect.gen(this, function* () {
|
||||||
|
yield* this.createWaiter(request, waiterId);
|
||||||
|
yield* this.startHeartbeat("waiter", waiterId);
|
||||||
|
|
||||||
|
return yield* Effect.fail("retry");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return Effect.fail("retry");
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
const cleanupAbandonedWaiter = Effect.gen(this, function* () {
|
||||||
|
yield* this.deleteWaiter(waiterId);
|
||||||
|
yield* this.release({ id: waiterId });
|
||||||
|
});
|
||||||
|
|
||||||
|
return Effect.scoped(
|
||||||
|
Effect.gen(this, function* () {
|
||||||
|
const lock = yield* attempt.pipe(
|
||||||
|
Effect.retry(Schedule.spaced(LOCK_POLL_MS)),
|
||||||
|
Effect.onExit((exit) => {
|
||||||
|
if (Exit.isSuccess(exit)) {
|
||||||
|
return Effect.void;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cleanupAbandonedWaiter;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
return yield* this.createRelease(lock);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
isLocked(repositoryId: string) {
|
||||||
|
const now = Date.now();
|
||||||
|
|
||||||
|
return db.transaction((tx) => {
|
||||||
|
this.cleanupExpired(tx, now);
|
||||||
|
return this.getActiveLocks(tx, repositoryId, now).length > 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private createReleaseMany(locks: AcquiredLock[]) {
|
||||||
|
return Effect.gen(this, function* () {
|
||||||
|
const releases = yield* Effect.all(locks.map((lock) => this.createRelease(lock)));
|
||||||
|
let released = false;
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (released) return;
|
||||||
|
|
||||||
|
released = true;
|
||||||
|
for (const release of releases.toReversed()) {
|
||||||
|
release();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private createRelease(lock: AcquiredLock) {
|
||||||
|
return Effect.gen(this, function* () {
|
||||||
|
const heartbeatFiber = yield* this.startHeartbeat("lock", lock.id);
|
||||||
|
let released = false;
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (released) return;
|
||||||
|
|
||||||
|
released = true;
|
||||||
|
Effect.runFork(Fiber.interrupt(heartbeatFiber));
|
||||||
|
Effect.runSync(this.release(lock));
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private release(lock: Pick<AcquiredLock, "id">) {
|
||||||
|
return Effect.gen(this, function* () {
|
||||||
|
const releasedLock = yield* Effect.sync(() =>
|
||||||
|
db.transaction((tx) => {
|
||||||
|
const row = tx.query.repositoryLocksTable
|
||||||
|
.findFirst({ where: { AND: [{ id: { eq: lock.id } }, { ownerId: { eq: this.ownerId } }] } })
|
||||||
|
.sync();
|
||||||
|
|
||||||
|
if (!row) return null;
|
||||||
|
|
||||||
|
tx.delete(repositoryLocksTable)
|
||||||
|
.where(
|
||||||
|
and(eq(repositoryLocksTable.id, lock.id), eq(repositoryLocksTable.ownerId, this.ownerId)),
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
|
||||||
|
return row;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!releasedLock) return;
|
||||||
|
|
||||||
|
const duration = Date.now() - releasedLock.acquiredAt;
|
||||||
|
|
||||||
|
yield* logger.effect.debug(
|
||||||
|
`[Mutex] Released ${releasedLock.type} lock for repo ${releasedLock.repositoryId}: ${releasedLock.operation} (held for ${duration}ms)`,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private startHeartbeat(
|
||||||
|
target: "waiter",
|
||||||
|
lockId: string,
|
||||||
|
): Effect.Effect<Fiber.RuntimeFiber<void, never>, never, Scope.Scope>;
|
||||||
|
private startHeartbeat(
|
||||||
|
target: "lock",
|
||||||
|
lockId: string,
|
||||||
|
): Effect.Effect<Fiber.RuntimeFiber<void, never>, never, never>;
|
||||||
|
private startHeartbeat(
|
||||||
|
target: HeartbeatTarget,
|
||||||
|
lockId: string,
|
||||||
|
): Effect.Effect<Fiber.RuntimeFiber<unknown, never>, never, Scope.Scope> {
|
||||||
|
const heartbeat = Effect.gen(this, function* () {
|
||||||
|
const now = Date.now();
|
||||||
|
const values = { heartbeatAt: now, expiresAt: now + LOCK_LEASE_MS };
|
||||||
|
|
||||||
|
if (target === "lock") {
|
||||||
|
yield* Effect.try(() => {
|
||||||
|
db.update(repositoryLocksTable)
|
||||||
|
.set(values)
|
||||||
|
.where(and(eq(repositoryLocksTable.id, lockId), eq(repositoryLocksTable.ownerId, this.ownerId)))
|
||||||
|
.run();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
yield* Effect.try(() => {
|
||||||
|
db.update(repositoryLockWaitersTable)
|
||||||
|
.set(values)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(repositoryLockWaitersTable.id, lockId),
|
||||||
|
eq(repositoryLockWaitersTable.ownerId, this.ownerId),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).pipe(
|
||||||
|
Effect.catchAll((error) =>
|
||||||
|
logger.effect.warn(`[Mutex] Failed to heartbeat ${target} ${lockId}: ${String(error)}`),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
const repeat = heartbeat.pipe(Effect.repeat(Schedule.spaced(LOCK_HEARTBEAT_MS)));
|
||||||
|
|
||||||
|
if (target === "waiter") {
|
||||||
|
// For waiters, we can stop heartbeating when the releaser is dropped, so we use a scoped fiber
|
||||||
|
return repeat.pipe(Effect.forkScoped);
|
||||||
|
}
|
||||||
|
|
||||||
|
// For locks, the heartbeat must outlive the acquire scope.
|
||||||
|
// It is interrupted manually by the returned release function.
|
||||||
|
// TODO: max lifetime for lock heartbeats to prevent leaks if the releaser is never called?
|
||||||
|
return repeat.pipe(Effect.forkDaemon);
|
||||||
|
}
|
||||||
|
|
||||||
|
private acquireSharedEffect(repositoryId: string, operation: string) {
|
||||||
|
return Effect.gen(this, function* () {
|
||||||
|
const request: LockRequest = { repositoryId, type: "shared", operation };
|
||||||
|
const releaseLock = yield* this.tryAcquireImmediately(request);
|
||||||
|
if (releaseLock) return releaseLock;
|
||||||
|
|
||||||
|
yield* logger.effect.debug(`[Mutex] Waiting for shared lock on repo ${repositoryId}: ${operation}`);
|
||||||
|
return yield* this.waitForQueuedLock(request);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private acquireExclusiveEffect(repositoryId: string, operation: string) {
|
||||||
|
return Effect.gen(this, function* () {
|
||||||
|
const request: LockRequest = { repositoryId, type: "exclusive", operation };
|
||||||
|
const releaseLock = yield* this.tryAcquireImmediately(request);
|
||||||
|
if (releaseLock) {
|
||||||
|
yield* logger.effect.debug(`[Mutex] Acquired exclusive lock for repo ${repositoryId}: ${operation}`);
|
||||||
|
return releaseLock;
|
||||||
|
}
|
||||||
|
|
||||||
|
yield* logger.effect.debug(`[Mutex] Waiting for exclusive lock on repo ${repositoryId}: ${operation}`);
|
||||||
|
const queuedReleaseLock = yield* this.waitForQueuedLock(request);
|
||||||
|
yield* logger.effect.debug(`[Mutex] Acquired exclusive lock for repo ${repositoryId}: ${operation}`);
|
||||||
|
return queuedReleaseLock;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private acquireManyEffect(requests: LockRequest[]) {
|
||||||
|
return Effect.gen(this, function* () {
|
||||||
|
if (requests.length === 0) {
|
||||||
|
return () => {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const seenRepositoryIds = new Set<string>();
|
||||||
|
for (const request of requests) {
|
||||||
|
if (seenRepositoryIds.has(request.repositoryId)) {
|
||||||
|
throw new Error(`Duplicate repository lock request: ${request.repositoryId}`);
|
||||||
|
}
|
||||||
|
seenRepositoryIds.add(request.repositoryId);
|
||||||
|
}
|
||||||
|
|
||||||
|
const sortedRequests = [...requests].sort((a, b) => a.repositoryId.localeCompare(b.repositoryId));
|
||||||
|
|
||||||
|
const locks = yield* Effect.sync(() => this.tryAcquireManyRows(sortedRequests)).pipe(
|
||||||
|
Effect.flatMap((locks) => {
|
||||||
|
if (locks) return Effect.succeed(locks);
|
||||||
|
return Effect.fail("retry");
|
||||||
|
}),
|
||||||
|
Effect.retry(Schedule.spaced(LOCK_POLL_MS)),
|
||||||
|
);
|
||||||
|
|
||||||
|
return yield* this.createReleaseMany(locks);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private runWithSignal<A, E>(effect: Effect.Effect<A, E>, signal?: AbortSignal) {
|
||||||
|
if (!signal) return Effect.runPromise(effect);
|
||||||
|
|
||||||
|
if (signal.aborted) {
|
||||||
|
return Promise.reject(this.abortReason(signal));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Promise<A>((resolve, reject) => {
|
||||||
|
const fiber = Effect.runFork(effect);
|
||||||
|
let settled = false;
|
||||||
|
let aborting = false;
|
||||||
|
|
||||||
|
const complete = (callback: () => void) => {
|
||||||
|
if (settled) return;
|
||||||
|
|
||||||
settled = true;
|
settled = true;
|
||||||
for (const cleanup of cleanupCallbacks) {
|
signal.removeEventListener("abort", onAbort);
|
||||||
cleanup();
|
|
||||||
}
|
|
||||||
callback();
|
callback();
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const repositoryId of uniqueRepositoryIds) {
|
const onAbort = () => {
|
||||||
let listeners = this.changeListeners.get(repositoryId);
|
aborting = true;
|
||||||
if (!listeners) {
|
Effect.runPromise(Fiber.interrupt(fiber)).then(
|
||||||
listeners = new Set();
|
(exit) =>
|
||||||
this.changeListeners.set(repositoryId, listeners);
|
complete(() => {
|
||||||
}
|
if (Exit.isSuccess(exit)) {
|
||||||
|
resolve(exit.value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const listener = () => settle(resolve);
|
reject(this.abortReason(signal));
|
||||||
listeners.add(listener);
|
}),
|
||||||
|
(error) => complete(() => reject(error)),
|
||||||
cleanupCallbacks.push(() => {
|
);
|
||||||
const currentListeners = this.changeListeners.get(repositoryId);
|
|
||||||
if (!currentListeners) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentListeners.delete(listener);
|
|
||||||
if (currentListeners.size === 0) {
|
|
||||||
this.changeListeners.delete(repositoryId);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (signal) {
|
|
||||||
const onAbort = () => {
|
|
||||||
settle(() => reject(signal.reason || new Error("Operation aborted")));
|
|
||||||
};
|
|
||||||
|
|
||||||
signal.addEventListener("abort", onAbort);
|
|
||||||
cleanupCallbacks.push(() => {
|
|
||||||
signal.removeEventListener("abort", onAbort);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private tryAcquireMany(requests: LockRequest[]) {
|
|
||||||
for (const request of requests) {
|
|
||||||
if (!this.canAcquireImmediately(this.locks.get(request.repositoryId), request.type)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const releases = requests.map((request) => {
|
|
||||||
const state = this.getOrCreateState(request.repositoryId);
|
|
||||||
const lockId = this.generateLockId();
|
|
||||||
|
|
||||||
if (request.type === "shared") {
|
|
||||||
state.sharedHolders.set(lockId, {
|
|
||||||
id: lockId,
|
|
||||||
operation: request.operation,
|
|
||||||
acquiredAt: Date.now(),
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
state.exclusiveHolder = {
|
|
||||||
id: lockId,
|
|
||||||
operation: request.operation,
|
|
||||||
acquiredAt: Date.now(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.createRelease(request.type, request.repositoryId, lockId);
|
|
||||||
});
|
|
||||||
|
|
||||||
let released = false;
|
|
||||||
return () => {
|
|
||||||
if (released) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
released = true;
|
|
||||||
for (const release of releases.toReversed()) {
|
|
||||||
release();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async acquireShared(repositoryId: string, operation: string, signal?: AbortSignal): Promise<() => void> {
|
|
||||||
if (signal?.aborted) {
|
|
||||||
throw signal.reason || new Error("Operation aborted");
|
|
||||||
}
|
|
||||||
|
|
||||||
const state = this.getOrCreateState(repositoryId);
|
|
||||||
|
|
||||||
const hasExclusiveInQueue = state.waitQueue.some((item) => item.type === "exclusive");
|
|
||||||
|
|
||||||
if (!state.exclusiveHolder && !hasExclusiveInQueue) {
|
|
||||||
const lockId = this.generateLockId();
|
|
||||||
state.sharedHolders.set(lockId, {
|
|
||||||
id: lockId,
|
|
||||||
operation,
|
|
||||||
acquiredAt: Date.now(),
|
|
||||||
});
|
|
||||||
return () => this.releaseShared(repositoryId, lockId);
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.debug(
|
|
||||||
`[Mutex] Waiting for shared lock on repo ${repositoryId}: ${operation} (exclusive held by: ${state.exclusiveHolder?.operation ?? "none"}, queue: ${state.waitQueue.length})`,
|
|
||||||
);
|
|
||||||
|
|
||||||
let onAbort: () => void = () => {};
|
|
||||||
let lockId: string | undefined;
|
|
||||||
try {
|
|
||||||
lockId = await new Promise<string>((resolve, reject) => {
|
|
||||||
const waiter = { type: "shared" as const, operation, resolve };
|
|
||||||
state.waitQueue.push(waiter);
|
|
||||||
|
|
||||||
if (signal) {
|
|
||||||
onAbort = () => {
|
|
||||||
const index = state.waitQueue.indexOf(waiter);
|
|
||||||
if (index !== -1) {
|
|
||||||
state.waitQueue.splice(index, 1);
|
|
||||||
this.cleanupStateIfEmpty(repositoryId);
|
|
||||||
this.notifyChange(repositoryId);
|
|
||||||
reject(signal.reason || new Error("Operation aborted"));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
signal.addEventListener("abort", onAbort);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} finally {
|
|
||||||
signal?.removeEventListener("abort", onAbort);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (signal?.aborted) {
|
|
||||||
if (lockId) {
|
|
||||||
this.releaseShared(repositoryId, lockId);
|
|
||||||
}
|
|
||||||
throw signal.reason || new Error("Operation aborted");
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.createRelease("shared", repositoryId, lockId!);
|
|
||||||
}
|
|
||||||
|
|
||||||
async acquireExclusive(repositoryId: string, operation: string, signal?: AbortSignal): Promise<() => void> {
|
|
||||||
if (signal?.aborted) {
|
|
||||||
throw signal.reason || new Error("Operation aborted");
|
|
||||||
}
|
|
||||||
|
|
||||||
const state = this.getOrCreateState(repositoryId);
|
|
||||||
|
|
||||||
if (!state.exclusiveHolder && state.sharedHolders.size === 0 && state.waitQueue.length === 0) {
|
|
||||||
const lockId = this.generateLockId();
|
|
||||||
state.exclusiveHolder = {
|
|
||||||
id: lockId,
|
|
||||||
operation,
|
|
||||||
acquiredAt: Date.now(),
|
|
||||||
};
|
};
|
||||||
return () => this.releaseExclusive(repositoryId, lockId);
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.debug(
|
signal.addEventListener("abort", onAbort, { once: true });
|
||||||
`[Mutex] Waiting for exclusive lock on repo ${repositoryId}: ${operation} (shared: ${state.sharedHolders.size}, exclusive: ${state.exclusiveHolder ? "yes" : "no"}, queue: ${state.waitQueue.length})`,
|
|
||||||
);
|
|
||||||
|
|
||||||
let onAbort: () => void = () => {};
|
Effect.runPromise(Fiber.join(fiber)).then(
|
||||||
let lockId: string | undefined;
|
(value) => complete(() => resolve(value)),
|
||||||
try {
|
(error) => {
|
||||||
lockId = await new Promise<string>((resolve, reject) => {
|
if (!aborting) {
|
||||||
const waiter = { type: "exclusive" as const, operation, resolve };
|
complete(() => reject(error));
|
||||||
state.waitQueue.push(waiter);
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (signal) {
|
async acquireShared(repositoryId: string, operation: string, signal?: AbortSignal) {
|
||||||
onAbort = () => {
|
return await this.runWithSignal(this.acquireSharedEffect(repositoryId, operation), signal);
|
||||||
const index = state.waitQueue.indexOf(waiter);
|
}
|
||||||
if (index !== -1) {
|
|
||||||
state.waitQueue.splice(index, 1);
|
|
||||||
this.cleanupStateIfEmpty(repositoryId);
|
|
||||||
this.notifyChange(repositoryId);
|
|
||||||
reject(signal.reason || new Error("Operation aborted"));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
signal.addEventListener("abort", onAbort);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} finally {
|
|
||||||
signal?.removeEventListener("abort", onAbort);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (signal?.aborted) {
|
async acquireExclusive(repositoryId: string, operation: string, signal?: AbortSignal) {
|
||||||
if (lockId) {
|
return await this.runWithSignal(this.acquireExclusiveEffect(repositoryId, operation), signal);
|
||||||
this.releaseExclusive(repositoryId, lockId);
|
|
||||||
}
|
|
||||||
throw signal.reason || new Error("Operation aborted");
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.debug(`[Mutex] Acquired exclusive lock for repo ${repositoryId}: ${operation} (${lockId})`);
|
|
||||||
|
|
||||||
return this.createRelease("exclusive", repositoryId, lockId!);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async acquireMany(requests: LockRequest[], signal?: AbortSignal) {
|
async acquireMany(requests: LockRequest[], signal?: AbortSignal) {
|
||||||
if (signal?.aborted) {
|
return await this.runWithSignal(this.acquireManyEffect(requests), signal);
|
||||||
throw signal.reason || new Error("Operation aborted");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (requests.length === 0) {
|
|
||||||
return () => {};
|
|
||||||
}
|
|
||||||
|
|
||||||
const seenRepositoryIds = new Set<string>();
|
|
||||||
for (const request of requests) {
|
|
||||||
if (seenRepositoryIds.has(request.repositoryId)) {
|
|
||||||
throw new Error(`Duplicate repository lock request: ${request.repositoryId}`);
|
|
||||||
}
|
|
||||||
seenRepositoryIds.add(request.repositoryId);
|
|
||||||
}
|
|
||||||
|
|
||||||
const sortedRequests = [...requests].sort((a, b) => a.repositoryId.localeCompare(b.repositoryId));
|
|
||||||
while (true) {
|
|
||||||
const releaseLocks = this.tryAcquireMany(sortedRequests);
|
|
||||||
if (releaseLocks) {
|
|
||||||
return releaseLocks;
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.waitForChange(
|
|
||||||
sortedRequests.map((request) => request.repositoryId),
|
|
||||||
signal,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (signal?.aborted) {
|
|
||||||
throw signal.reason || new Error("Operation aborted");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private releaseShared(repositoryId: string, lockId: string): void {
|
|
||||||
const state = this.locks.get(repositoryId);
|
|
||||||
if (!state) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const holder = state.sharedHolders.get(lockId);
|
|
||||||
if (!holder) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
state.sharedHolders.delete(lockId);
|
|
||||||
const duration = Date.now() - holder.acquiredAt;
|
|
||||||
logger.debug(`[Mutex] Released shared lock for repo ${repositoryId}: ${holder.operation} (held for ${duration}ms)`);
|
|
||||||
|
|
||||||
this.processWaitQueue(repositoryId);
|
|
||||||
this.cleanupStateIfEmpty(repositoryId);
|
|
||||||
this.notifyChange(repositoryId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private releaseExclusive(repositoryId: string, lockId: string): void {
|
|
||||||
const state = this.locks.get(repositoryId);
|
|
||||||
if (!state) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!state.exclusiveHolder || state.exclusiveHolder.id !== lockId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const duration = Date.now() - state.exclusiveHolder.acquiredAt;
|
|
||||||
logger.debug(
|
|
||||||
`[Mutex] Released exclusive lock for repo ${repositoryId}: ${state.exclusiveHolder.operation} (held for ${duration}ms)`,
|
|
||||||
);
|
|
||||||
state.exclusiveHolder = null;
|
|
||||||
|
|
||||||
this.processWaitQueue(repositoryId);
|
|
||||||
this.cleanupStateIfEmpty(repositoryId);
|
|
||||||
this.notifyChange(repositoryId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private processWaitQueue(repositoryId: string): void {
|
|
||||||
const state = this.locks.get(repositoryId);
|
|
||||||
if (!state || state.waitQueue.length === 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state.exclusiveHolder) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const firstWaiter = state.waitQueue[0];
|
|
||||||
|
|
||||||
if (firstWaiter.type === "exclusive") {
|
|
||||||
if (state.sharedHolders.size === 0) {
|
|
||||||
state.waitQueue.shift();
|
|
||||||
const lockId = this.generateLockId();
|
|
||||||
state.exclusiveHolder = {
|
|
||||||
id: lockId,
|
|
||||||
operation: firstWaiter.operation,
|
|
||||||
acquiredAt: Date.now(),
|
|
||||||
};
|
|
||||||
firstWaiter.resolve(lockId);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
while (state.waitQueue.length > 0 && state.waitQueue[0].type === "shared") {
|
|
||||||
const waiter = state.waitQueue.shift();
|
|
||||||
if (!waiter) break;
|
|
||||||
const lockId = this.generateLockId();
|
|
||||||
state.sharedHolders.set(lockId, {
|
|
||||||
id: lockId,
|
|
||||||
operation: waiter.operation,
|
|
||||||
acquiredAt: Date.now(),
|
|
||||||
});
|
|
||||||
waiter.resolve(lockId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
isLocked(repositoryId: string): boolean {
|
|
||||||
const state = this.locks.get(repositoryId);
|
|
||||||
if (!state) return false;
|
|
||||||
return state.exclusiveHolder !== null || state.sharedHolders.size > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private createRelease(type: LockType, repositoryId: string, lockId: string) {
|
|
||||||
let released = false;
|
|
||||||
return () => {
|
|
||||||
if (released) return;
|
|
||||||
released = true;
|
|
||||||
if (type === "shared") {
|
|
||||||
this.releaseShared(repositoryId, lockId);
|
|
||||||
} else {
|
|
||||||
this.releaseExclusive(repositoryId, lockId);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const repoMutex = new RepositoryMutex();
|
export const repoMutex = getRepositoryMutex();
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ const runMigrations = async () => {
|
||||||
migrate(db, { migrationsFolder });
|
migrate(db, { migrationsFolder });
|
||||||
|
|
||||||
sqlite.run("PRAGMA foreign_keys = ON;");
|
sqlite.run("PRAGMA foreign_keys = ON;");
|
||||||
|
sqlite.run("PRAGMA busy_timeout = 5000;");
|
||||||
};
|
};
|
||||||
|
|
||||||
export const runDbMigrations = () => {
|
export const runDbMigrations = () => {
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ export const relations = defineRelations(schema, (r) => ({
|
||||||
sessions: r.many.sessionsTable(),
|
sessions: r.many.sessionsTable(),
|
||||||
members: r.many.member(),
|
members: r.many.member(),
|
||||||
twoFactors: r.many.twoFactor(),
|
twoFactors: r.many.twoFactor(),
|
||||||
|
passkeys: r.many.passkey(),
|
||||||
ssoProviders: r.many.ssoProvider(),
|
ssoProviders: r.many.ssoProvider(),
|
||||||
organizations: r.many.organization({
|
organizations: r.many.organization({
|
||||||
from: r.usersTable.id.through(r.member.userId),
|
from: r.usersTable.id.through(r.member.userId),
|
||||||
|
|
@ -95,10 +96,17 @@ export const relations = defineRelations(schema, (r) => ({
|
||||||
to: r.usersTable.id,
|
to: r.usersTable.id,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
passkey: {
|
||||||
|
usersTable: r.one.usersTable({
|
||||||
|
from: r.passkey.userId,
|
||||||
|
to: r.usersTable.id,
|
||||||
|
}),
|
||||||
|
},
|
||||||
organization: {
|
organization: {
|
||||||
users: r.many.usersTable({
|
users: r.many.usersTable({
|
||||||
alias: "usersTable_id_organization_id_via_member",
|
alias: "usersTable_id_organization_id_via_member",
|
||||||
}),
|
}),
|
||||||
|
agents: r.many.agentsTable(),
|
||||||
backupSchedules: r.many.backupSchedulesTable(),
|
backupSchedules: r.many.backupSchedulesTable(),
|
||||||
notificationDestinations: r.many.notificationDestinationsTable(),
|
notificationDestinations: r.many.notificationDestinationsTable(),
|
||||||
repositories: r.many.repositoriesTable(),
|
repositories: r.many.repositoriesTable(),
|
||||||
|
|
@ -119,6 +127,13 @@ export const relations = defineRelations(schema, (r) => ({
|
||||||
optional: false,
|
optional: false,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
agentsTable: {
|
||||||
|
organization: r.one.organization({
|
||||||
|
from: r.agentsTable.organizationId,
|
||||||
|
to: r.organization.id,
|
||||||
|
optional: true,
|
||||||
|
}),
|
||||||
|
},
|
||||||
volumesTable: {
|
volumesTable: {
|
||||||
backupSchedules: r.many.backupSchedulesTable(),
|
backupSchedules: r.many.backupSchedulesTable(),
|
||||||
organization: r.one.organization({
|
organization: r.one.organization({
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue