Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7780aa69c0 | ||
|
|
d198796fde | ||
|
|
43c94b68b0 | ||
|
|
ac60b2c795 |
No files matched your search
@@ -7,20 +7,19 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
paths:
|
paths:
|
||||||
- "Dockerfile"
|
- "Dockerfile"
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
packages: write
|
packages: write
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.head_ref || github.ref }}
|
group: ${{ github.head_ref }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
base:
|
base:
|
||||||
name: Test base image build
|
name: Test base image build
|
||||||
runs-on: arc-runner-set
|
runs-on: ubuntu-latest
|
||||||
if: github.event_name == 'pull_request'
|
if: github.event_name == 'pull_request'
|
||||||
steps:
|
steps:
|
||||||
# Configure build environment
|
# Configure build environment
|
||||||
@@ -41,7 +40,7 @@ jobs:
|
|||||||
cache-to: type=gha,scope=buildx-base-multi-arch,mode=max
|
cache-to: type=gha,scope=buildx-base-multi-arch,mode=max
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
runs-on: arc-runner-set
|
runs-on: self-hosted
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request'
|
||||||
name: Publish Docker images
|
name: Publish Docker images
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@@ -14,10 +14,16 @@ jobs:
|
|||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
- uses: pnpm/action-setup@v4
|
||||||
- name: Setup Mise
|
|
||||||
uses: immich-app/devtools/actions/use-mise@cd24790a7f5f6439ac32cc94f5523cb2de8bfa8c # use-mise-action-v1.1.0
|
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
package_json_file: ./docs/package.json
|
||||||
|
- uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: lts/*
|
||||||
|
cache: pnpm
|
||||||
|
cache-dependency-path: ./docs/pnpm-lock.yaml
|
||||||
|
|
||||||
- run: mise docs:build
|
- name: Install dependencies
|
||||||
|
run: pnpm install
|
||||||
|
- name: Test build website
|
||||||
|
run: pnpm run build
|
||||||
@@ -16,13 +16,19 @@ jobs:
|
|||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
- uses: pnpm/action-setup@v4
|
||||||
- name: Setup Mise
|
|
||||||
uses: immich-app/devtools/actions/use-mise@cd24790a7f5f6439ac32cc94f5523cb2de8bfa8c # use-mise-action-v1.1.0
|
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
package_json_file: ./docs/package.json
|
||||||
|
- uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: lts/*
|
||||||
|
cache: pnpm
|
||||||
|
cache-dependency-path: ./docs/pnpm-lock.yaml
|
||||||
|
|
||||||
- run: mise docs:build
|
- name: Install dependencies
|
||||||
|
run: pnpm install
|
||||||
|
- name: Build website
|
||||||
|
run: pnpm run build
|
||||||
|
|
||||||
- name: Upload Build Artifact
|
- name: Upload Build Artifact
|
||||||
uses: actions/upload-pages-artifact@v3
|
uses: actions/upload-pages-artifact@v3
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
name: Git Town
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
git-town:
|
|
||||||
name: Display the branch stack
|
|
||||||
runs-on: ubuntu-slim
|
|
||||||
|
|
||||||
if: ${{ !startsWith(github.head_ref, 'release-please--') }}
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
pull-requests: write
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
|
||||||
- uses: stoatchat/action-git-town@4bc5c942e4603bffa0806b51d5fe5f0bc5deb0ac
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
name: Publish Crates
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
release:
|
|
||||||
types: [published]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
publish:
|
|
||||||
name: Publish Crates
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
|
|
||||||
- name: Setup Mise
|
|
||||||
uses: immich-app/devtools/actions/use-mise@cd24790a7f5f6439ac32cc94f5523cb2de8bfa8c # use-mise-action-v1.1.0
|
|
||||||
with:
|
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Publish
|
|
||||||
run: mise publish --workspace
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
name: Release Please
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [main] # updates/opens the release PR when commits land on main
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
pull-requests: write
|
|
||||||
id-token: write
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: release-please
|
|
||||||
cancel-in-progress: true
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
release-please:
|
|
||||||
name: Release Please
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
outputs:
|
|
||||||
release_created: ${{ steps.rp.outputs.release_created }}
|
|
||||||
tag_name: ${{ steps.rp.outputs.tag_name }}
|
|
||||||
steps:
|
|
||||||
- id: app-token
|
|
||||||
uses: actions/create-github-app-token@v2
|
|
||||||
with:
|
|
||||||
app-id: ${{ secrets.GH_STOAT_RELEASE_APP_ID }}
|
|
||||||
private-key: ${{ secrets.GH_STOAT_RELEASE_APP_PRIVATE_KEY }}
|
|
||||||
- id: rp
|
|
||||||
uses: googleapis/release-please-action@v4
|
|
||||||
with:
|
|
||||||
token: ${{ steps.app-token.outputs.token }}
|
|
||||||
config-file: release-please-config.json
|
|
||||||
|
|
||||||
- name: Install latest stable
|
|
||||||
uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # v1
|
|
||||||
with:
|
|
||||||
toolchain: stable
|
|
||||||
|
|
||||||
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
|
||||||
with:
|
|
||||||
token: ${{ steps.app-token.outputs.token }}
|
|
||||||
- name: Update Cargo.lock
|
|
||||||
if: ${{ steps.rp.outputs.prs_created == 'true' || steps.rp.outputs.prs_updated == 'true' }}
|
|
||||||
env:
|
|
||||||
GH_TOKEN: ${{ steps.app-token.outputs.token }}
|
|
||||||
run: |
|
|
||||||
PR_NUMBER=$(echo '${{ steps.rp.outputs.prs }}' | jq -r '.[0].number')
|
|
||||||
gh pr checkout "$PR_NUMBER"
|
|
||||||
|
|
||||||
cargo update -w
|
|
||||||
|
|
||||||
if git diff --quiet Cargo.lock; then
|
|
||||||
echo "No changes to Cargo.lock"
|
|
||||||
else
|
|
||||||
git config user.name "github-actions[bot]"
|
|
||||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
||||||
git add Cargo.lock
|
|
||||||
git commit -s -m "chore: update Cargo.lock"
|
|
||||||
git push
|
|
||||||
fi
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
name: Release Webhook
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
release:
|
|
||||||
types: [published]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
release-webhook:
|
|
||||||
name: Send Release Webhook
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Send release notification webhook
|
|
||||||
run: |
|
|
||||||
RELEASE_URL="https://github.com/${{ github.repository }}/releases/tag/${{ github.event.release.tag_name }}"
|
|
||||||
curl -X POST "${{ secrets.STOAT_WEBHOOK_UPDATES_URL }}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "{\"content\": \"$RELEASE_URL\"}"
|
|
||||||
@@ -6,7 +6,7 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.head_ref || github.ref }}
|
group: ${{ github.head_ref }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
env:
|
env:
|
||||||
@@ -15,54 +15,63 @@ env:
|
|||||||
jobs:
|
jobs:
|
||||||
check:
|
check:
|
||||||
name: Rust project
|
name: Rust project
|
||||||
runs-on: arc-runner-set
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
- uses: actions/checkout@v2
|
||||||
|
- name: Free up disk space
|
||||||
|
run: |
|
||||||
|
sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc
|
||||||
|
|
||||||
|
- name: Install latest stable
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
toolchain: stable
|
||||||
|
override: true
|
||||||
# Using our own runners for now:
|
components: rustfmt, clippy
|
||||||
# - name: Free up disk space
|
- name: Install cargo-nextest
|
||||||
# run: |
|
uses: baptiste0928/cargo-install@v1
|
||||||
# sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc
|
|
||||||
|
|
||||||
- name: Setup Mise
|
|
||||||
uses: immich-app/devtools/actions/use-mise@cd24790a7f5f6439ac32cc94f5523cb2de8bfa8c # use-mise-action-v1.1.0
|
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
crate: cargo-nextest
|
||||||
|
args: --locked
|
||||||
|
|
||||||
- run: mise build
|
- name: Run cargo build
|
||||||
- run: mise docker:start
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: build
|
||||||
|
|
||||||
- name: Reference Test
|
- name: Run services in background
|
||||||
|
run: |
|
||||||
|
docker compose -f compose.yml up -d
|
||||||
|
|
||||||
|
- name: Run cargo test
|
||||||
env:
|
env:
|
||||||
TEST_DB: REFERENCE
|
TEST_DB: REFERENCE
|
||||||
run: |
|
run: |
|
||||||
mise test
|
cargo nextest run
|
||||||
|
|
||||||
- name: MongoDB Test
|
- name: Run cargo test (with MongoDB)
|
||||||
env:
|
env:
|
||||||
TEST_DB: MONGODB
|
TEST_DB: MONGODB
|
||||||
MONGODB: mongodb://localhost
|
MONGODB: mongodb://localhost
|
||||||
run: |
|
run: |
|
||||||
mise test
|
cargo nextest run
|
||||||
|
|
||||||
- name: Start API in background
|
- name: Start API in background
|
||||||
if: github.event_name != 'pull_request' && github.ref_name == 'main'
|
if: github.event_name != 'pull_request' && github.ref_name == 'main'
|
||||||
env:
|
env:
|
||||||
TEST_DB: REFERENCE
|
TEST_DB: REFERENCE
|
||||||
run: |
|
run: |
|
||||||
mise build --bin revolt-delta && (mise service:api &)
|
cargo build --bin revolt-delta && (cargo run --bin revolt-delta &)
|
||||||
|
|
||||||
- name: Wait for API to go up
|
- name: Wait for API to go up
|
||||||
if: github.event_name != 'pull_request' && github.ref_name == 'main'
|
if: github.event_name != 'pull_request' && github.ref_name == 'main'
|
||||||
uses: nev7n/wait_for_response@7fef3c1a6e8939d0b09062f14fec50d3c5d15fa1 # v1.0.1
|
uses: nev7n/wait_for_response@v1
|
||||||
with:
|
with:
|
||||||
url: "http://localhost:14702/"
|
url: "http://localhost:14702/"
|
||||||
|
|
||||||
- name: Checkout API repository
|
- name: Checkout API repository
|
||||||
if: github.event_name != 'pull_request' && github.ref_name == 'main'
|
if: github.event_name != 'pull_request' && github.ref_name == 'main'
|
||||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
repository: stoatchat/javascript-client-api
|
repository: stoatchat/javascript-client-api
|
||||||
path: api
|
path: api
|
||||||
@@ -74,10 +83,10 @@ jobs:
|
|||||||
|
|
||||||
- name: Commit changes
|
- name: Commit changes
|
||||||
if: github.event_name != 'pull_request' && github.ref_name == 'main'
|
if: github.event_name != 'pull_request' && github.ref_name == 'main'
|
||||||
uses: EndBug/add-and-commit@a94899bca583c204427a224a7af87c02f9b325d5 # v9.1.4
|
uses: EndBug/add-and-commit@v4
|
||||||
with:
|
with:
|
||||||
cwd: "api"
|
cwd: "api"
|
||||||
add: "*.json"
|
add: "*.json"
|
||||||
author_name: Stoat CI
|
author_name: Revolt CI
|
||||||
author_email: stoat-ci@users.noreply.github.com
|
author_email: revolt-ci@users.noreply.github.com
|
||||||
message: "chore: generate OpenAPI specification"
|
message: "chore: generate OpenAPI specification"
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
[tools]
|
|
||||||
node = "25.4.0"
|
|
||||||
pnpm = "10.28.1"
|
|
||||||
|
|
||||||
gh = "2.25.0"
|
|
||||||
|
|
||||||
rust = "1.92.0"
|
|
||||||
"cargo:cargo-nextest" = "0.9.122"
|
|
||||||
|
|
||||||
"github:git-town/git-town" = "22.4.0"
|
|
||||||
|
|
||||||
[settings]
|
|
||||||
experimental = true
|
|
||||||
idiomatic_version_file_enable_tools = ["rust"]
|
|
||||||
|
|
||||||
[tasks.start]
|
|
||||||
description = "Run all services"
|
|
||||||
depends = ["docker:start", "build"]
|
|
||||||
run = [{ task = "service:*" }]
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
#MISE description="Build project"
|
|
||||||
set -e
|
|
||||||
|
|
||||||
cargo build "$@"
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
#MISE description="Check project with clippy"
|
|
||||||
set -e
|
|
||||||
|
|
||||||
cargo clippy
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
#MISE description="Start Docker containers"
|
|
||||||
set -e
|
|
||||||
|
|
||||||
docker compose up -d
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
#MISE description="Stop Docker containers"
|
|
||||||
set -e
|
|
||||||
|
|
||||||
docker compose down
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
#MISE description="Start the Stoat Developers website"
|
|
||||||
#MISE depends=["docs:install"]
|
|
||||||
#MISE dir="{{config_root}}/docs"
|
|
||||||
set -e
|
|
||||||
|
|
||||||
pnpm build
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
#MISE description="Build the Stoat Developers website"
|
|
||||||
#MISE depends=["docs:install"]
|
|
||||||
#MISE dir="{{config_root}}/docs"
|
|
||||||
set -e
|
|
||||||
|
|
||||||
pnpm build
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
#MISE description="Install dependencies for docs site"
|
|
||||||
#MISE dir="{{config_root}}/docs"
|
|
||||||
set -e
|
|
||||||
|
|
||||||
pnpm i --frozen-lockfile
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
#MISE description="Publish project"
|
|
||||||
set -e
|
|
||||||
|
|
||||||
cargo publish "$@"
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
#MISE description="Run API server"
|
|
||||||
set -e
|
|
||||||
|
|
||||||
cargo run --bin revolt-delta
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
#MISE description="Run cron daemon"
|
|
||||||
set -e
|
|
||||||
|
|
||||||
cargo run --bin revolt-crond
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
#MISE description="Run events server"
|
|
||||||
set -e
|
|
||||||
|
|
||||||
cargo run --bin revolt-bonfire
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
#MISE description="Run file server"
|
|
||||||
set -e
|
|
||||||
|
|
||||||
cargo run --bin revolt-autumn
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
#MISE description="Run GIF proxy server"
|
|
||||||
set -e
|
|
||||||
|
|
||||||
cargo run --bin revolt-gifbox
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
#MISE description="Run proxy server"
|
|
||||||
set -e
|
|
||||||
|
|
||||||
cargo run --bin revolt-january
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
#MISE description="Run push daemon"
|
|
||||||
set -e
|
|
||||||
|
|
||||||
cargo run --bin revolt-pushd
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
#MISE description="Test project"
|
|
||||||
set -e
|
|
||||||
|
|
||||||
: "${TEST_DB:=REFERENCE}"
|
|
||||||
export TEST_DB
|
|
||||||
|
|
||||||
cargo nextest run
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
".": "0.10.3"
|
|
||||||
}
|
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
# Changelog
|
|
||||||
|
|
||||||
## [0.10.3](https://github.com/stoatchat/stoatchat/compare/v0.10.2...v0.10.3) (2026-02-07)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* update `Revolt` -> `Stoat` in email titles/desc. ([#508](https://github.com/stoatchat/stoatchat/issues/508)) ([84483ce](https://github.com/stoatchat/stoatchat/commit/84483cee7af3e5dfa16f7fe13e334c4d9f5abd60))
|
|
||||||
|
|
||||||
## [0.10.2](https://github.com/stoatchat/stoatchat/compare/v0.10.1...v0.10.2) (2026-01-25)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* thumbnailification requires rgb8/rgba8 ([#505](https://github.com/stoatchat/stoatchat/issues/505)) ([413aa04](https://github.com/stoatchat/stoatchat/commit/413aa04dcaf8bff3935ed1e5f31432e11a03ce6f))
|
|
||||||
|
|
||||||
## [0.10.1](https://github.com/stoatchat/stoatchat/compare/v0.10.0...v0.10.1) (2026-01-25)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* use Rust 1.92.0 for Docker build ([#503](https://github.com/stoatchat/stoatchat/issues/503)) ([98da8a2](https://github.com/stoatchat/stoatchat/commit/98da8a28a0aa2fee4e8eee1d86bd7c49e3187477))
|
|
||||||
|
|
||||||
## [0.10.0](https://github.com/stoatchat/stoatchat/compare/v0.9.4...v0.10.0) (2026-01-25)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* allow kicking members from voice channels ([#495](https://github.com/stoatchat/stoatchat/issues/495)) ([0dc5442](https://github.com/stoatchat/stoatchat/commit/0dc544249825a49c793309edee5ec1838458a6da))
|
|
||||||
* repository architecture for files crate w. added tests ([#498](https://github.com/stoatchat/stoatchat/issues/498)) ([01ded20](https://github.com/stoatchat/stoatchat/commit/01ded209c62208fc906d6aab9b08c04e860e10ef))
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* expose ratelimit headers via cors ([#496](https://github.com/stoatchat/stoatchat/issues/496)) ([a1a2125](https://github.com/stoatchat/stoatchat/commit/a1a21252d0ad58937e41f16e5fb86f96bebd2a51))
|
|
||||||
|
|
||||||
## [0.9.4](https://github.com/stoatchat/stoatchat/compare/v0.9.3...v0.9.4) (2026-01-10)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* checkout repo. before bumping lock ([#490](https://github.com/stoatchat/stoatchat/issues/490)) ([b2da2a8](https://github.com/stoatchat/stoatchat/commit/b2da2a858787853be43136fd526a0bd72baf78ef))
|
|
||||||
* persist credentials for git repo ([#492](https://github.com/stoatchat/stoatchat/issues/492)) ([c674a9f](https://github.com/stoatchat/stoatchat/commit/c674a9fd4e0abbd51569870e4b38074d4a1de03c))
|
|
||||||
|
|
||||||
## [0.9.3](https://github.com/stoatchat/stoatchat/compare/v0.9.2...v0.9.3) (2026-01-10)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* pipeline fixes ([#487](https://github.com/stoatchat/stoatchat/issues/487)) ([aeeafeb](https://github.com/stoatchat/stoatchat/commit/aeeafebefc36a43a656cf797c9251ca50292733c))
|
|
||||||
|
|
||||||
## [0.9.2](https://github.com/stoatchat/stoatchat/compare/v0.9.1...v0.9.2) (2026-01-10)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* disable publish for services ([#485](https://github.com/stoatchat/stoatchat/issues/485)) ([d13609c](https://github.com/stoatchat/stoatchat/commit/d13609c37279d6a40445dcd99564e5c3dd03bac1))
|
|
||||||
|
|
||||||
## [0.9.1](https://github.com/stoatchat/stoatchat/compare/v0.9.0...v0.9.1) (2026-01-10)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* **ci:** pipeline fixes (marked as fix to force release) ([#483](https://github.com/stoatchat/stoatchat/issues/483)) ([303e52b](https://github.com/stoatchat/stoatchat/commit/303e52b476585eea81c33837f1b01506ce387684))
|
|
||||||
|
|
||||||
## [0.9.0](https://github.com/stoatchat/stoatchat/compare/v0.8.8...v0.9.0) (2026-01-10)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* add id field to role ([#470](https://github.com/stoatchat/stoatchat/issues/470)) ([2afea56](https://github.com/stoatchat/stoatchat/commit/2afea56e56017f02de98e67316b4457568ad5b26))
|
|
||||||
* add ratelimits to gifbox ([1542047](https://github.com/stoatchat/stoatchat/commit/154204742d21cbeff6e2577b00f50b495ea44631))
|
|
||||||
* include groups and dms in fetch mutuals ([caa8607](https://github.com/stoatchat/stoatchat/commit/caa86074680d46223cebc20f41e9c91c41ec825d))
|
|
||||||
* include member payload in ServerMemberJoin event ([480f210](https://github.com/stoatchat/stoatchat/commit/480f210ce85271e13d1dac58a5dae08de108579d))
|
|
||||||
* initial work on tenor gif searching ([b0c977b](https://github.com/stoatchat/stoatchat/commit/b0c977b324b8144c1152589546eb8fec5954c3e7))
|
|
||||||
* make message lexer use unowned string ([1561481](https://github.com/stoatchat/stoatchat/commit/1561481eb4cdc0f385fbf0a81e4950408050e11f))
|
|
||||||
* ready payload field customisation ([db57706](https://github.com/stoatchat/stoatchat/commit/db577067948f13e830b5fb773034e9713a1abaff))
|
|
||||||
* require auth for search ([b5cd5e3](https://github.com/stoatchat/stoatchat/commit/b5cd5e30ef7d5e56e8964fb7c543965fa6bf5a4a))
|
|
||||||
* trending and categories routes ([5885e06](https://github.com/stoatchat/stoatchat/commit/5885e067a627b8fff1c8ce2bf9e852ff8cf3f07a))
|
|
||||||
* voice chats v2 ([#414](https://github.com/stoatchat/stoatchat/issues/414)) ([d567155](https://github.com/stoatchat/stoatchat/commit/d567155f124e4da74115b1a8f810062f7c6559d9))
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* add license to revolt-parser ([5335124](https://github.com/stoatchat/stoatchat/commit/53351243064cac8d499dd74284be73928fa78a43))
|
|
||||||
* allow for disabling default features ([65fbd36](https://github.com/stoatchat/stoatchat/commit/65fbd3662462aed1333b79e59155fa6377e83fcc))
|
|
||||||
* apple music to use original url instead of metadata url ([bfe4018](https://github.com/stoatchat/stoatchat/commit/bfe4018e436a4075bae780dd4d35a9b58315e12f))
|
|
||||||
* apply uname fix to january and autumn ([8f9015a](https://github.com/stoatchat/stoatchat/commit/8f9015a6ff181d208d9269ab8691bd417d39811a))
|
|
||||||
* **ci:** publish images under stoatchat and remove docker hub ([d65c1a1](https://github.com/stoatchat/stoatchat/commit/d65c1a1ab3bdc7e5684b03f280af77d881661a3d))
|
|
||||||
* correct miniz_oxide in lockfile ([#478](https://github.com/stoatchat/stoatchat/issues/478)) ([5d27a91](https://github.com/stoatchat/stoatchat/commit/5d27a91e901dd2ea3e860aeaed8468db6c5f3214))
|
|
||||||
* correct shebang for try-tag-and-release ([050ba16](https://github.com/stoatchat/stoatchat/commit/050ba16d4adad5d0fb247867aa3e94e3d42bd12d))
|
|
||||||
* correct string_cache in lockfile ([#479](https://github.com/stoatchat/stoatchat/issues/479)) ([0b178fc](https://github.com/stoatchat/stoatchat/commit/0b178fc791583064bf9ca94b1d39b42d021e1d79))
|
|
||||||
* don't remove timeouts when a member leaves a server ([#409](https://github.com/stoatchat/stoatchat/issues/409)) ([e635bc2](https://github.com/stoatchat/stoatchat/commit/e635bc23ec857d648d5705e1a3875d7bc3402b0d))
|
|
||||||
* don't update the same field while trying to remove it ([f4ee35f](https://github.com/stoatchat/stoatchat/commit/f4ee35fb093ca49f0a64ff4b17fd61587df28145)), closes [#392](https://github.com/stoatchat/stoatchat/issues/392)
|
|
||||||
* github webhook incorrect payload and formatting ([#468](https://github.com/stoatchat/stoatchat/issues/468)) ([dc9c82a](https://github.com/stoatchat/stoatchat/commit/dc9c82aa4e9667ea6639256c65ac8de37a24d1f7))
|
|
||||||
* implement Serialize to ClientMessage ([dea0f67](https://github.com/stoatchat/stoatchat/commit/dea0f675dde7a63c7a59b38d469f878b7a8a3af4))
|
|
||||||
* newly created roles should be ranked the lowest ([947eb15](https://github.com/stoatchat/stoatchat/commit/947eb15771ed6785b3dcd16c354c03ded5e4cbe0))
|
|
||||||
* permit empty `remove` array in edit requests ([6ad3da5](https://github.com/stoatchat/stoatchat/commit/6ad3da5f35f989a2e7d8e29718b98374248e76af))
|
|
||||||
* preserve order of replies in message ([#447](https://github.com/stoatchat/stoatchat/issues/447)) ([657a3f0](https://github.com/stoatchat/stoatchat/commit/657a3f08e5d652814bbf0647e089ed9ebb139bbf))
|
|
||||||
* prevent timing out members which have TimeoutMembers permission ([e36fc97](https://github.com/stoatchat/stoatchat/commit/e36fc9738bac0de4f3fcbccba521f1e3754f7ae7))
|
|
||||||
* relax settings name regex ([3a34159](https://github.com/stoatchat/stoatchat/commit/3a3415915f0d0fdce1499d47a2b7fa097f5946ea))
|
|
||||||
* remove authentication tag bytes from attachment download ([32e6600](https://github.com/stoatchat/stoatchat/commit/32e6600272b885c595c094f0bc69459250220dcb))
|
|
||||||
* rename openapi operation ids ([6048587](https://github.com/stoatchat/stoatchat/commit/6048587d348fbca0dc3a9b47690c56df8fece576)), closes [#406](https://github.com/stoatchat/stoatchat/issues/406)
|
|
||||||
* respond with 201 if no body in requests ([#465](https://github.com/stoatchat/stoatchat/issues/465)) ([24fedf8](https://github.com/stoatchat/stoatchat/commit/24fedf8c4d9cd3160bdec97aa451520f8beaa739))
|
|
||||||
* swap to using reqwest for query building ([38dd4d1](https://github.com/stoatchat/stoatchat/commit/38dd4d10797b3e6e397fc219e818f379bdff19f2))
|
|
||||||
* use `trust_cloudflare` config value instead of env var ([cc7a796](https://github.com/stoatchat/stoatchat/commit/cc7a7962a882e1627fcd0bc75858a017415e8cfc))
|
|
||||||
* use our own result types instead of tenors types ([a92152d](https://github.com/stoatchat/stoatchat/commit/a92152d86da136997817e797c7af8e38731cdde8))
|
|
||||||
@@ -11,40 +11,13 @@ members = [
|
|||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
redis23 = { package = "redis", version = "0.23.3", git = "https://github.com/revoltchat/redis-rs", rev = "523b2937367e17bd0073722bf6e23d06042cb4e4" }
|
redis23 = { package = "redis", version = "0.23.3", git = "https://github.com/revoltchat/redis-rs", rev = "523b2937367e17bd0073722bf6e23d06042cb4e4" }
|
||||||
#authifier = { package = "authifier", version = "1.0.10", path = "../authifier/crates/authifier" }
|
authifier = { package = "authifier", version = "1.0.10", path = "../authifier/crates/authifier" }
|
||||||
#rocket_authifier = { package = "rocket_authifier", version = "1.0.10", path = "../authifier/crates/rocket_authifier" }
|
rocket_authifier = { package = "rocket_authifier", version = "1.0.10", path = "../authifier/crates/rocket_authifier" }
|
||||||
|
iso8601-timestamp = { path = "../iso8601-timestamp" }
|
||||||
|
|
||||||
|
# I'm 99% sure this is overloading the GitHub worker
|
||||||
|
# hence builds have been failing since, let's just
|
||||||
|
# disable it for now. In the future, we could use this
|
||||||
|
# if we were rolling our own CI (that is now).
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = true
|
lto = true
|
||||||
|
|
||||||
[workspace.dependencies]
|
|
||||||
# Async
|
|
||||||
async-trait = "0.1.89"
|
|
||||||
tokio = { version = "1.49.0", features = ["macros", "rt"] }
|
|
||||||
|
|
||||||
# Error Handling
|
|
||||||
anyhow = "1.0.100"
|
|
||||||
thiserror = "2.0.18"
|
|
||||||
|
|
||||||
# Other Utilities
|
|
||||||
uuid = { version = "1.19.0", features = ["v4"] }
|
|
||||||
|
|
||||||
# Axum (HTTP server)
|
|
||||||
axum-macros = "0.4.1"
|
|
||||||
axum_typed_multipart = "0.12.1"
|
|
||||||
axum = { version = "0.7.5", features = ["multipart"] }
|
|
||||||
tower-http = { version = "0.5.2", features = ["cors", "trace"] }
|
|
||||||
|
|
||||||
# Image Processing
|
|
||||||
jxl-oxide = { version = "0.12.5", features = ["image"] }
|
|
||||||
image = "0.25.9"
|
|
||||||
|
|
||||||
# OpenTelemetry
|
|
||||||
tracing = "0.1.44"
|
|
||||||
tracing-subscriber = { version = "0.3.22", features = [
|
|
||||||
"env-filter",
|
|
||||||
] } # consider https://crates.io/crates/better-tracing
|
|
||||||
opentelemetry = { version = "0.31.0", features = ["logs"] }
|
|
||||||
opentelemetry_sdk = { version = "0.31.0", features = ["logs"] }
|
|
||||||
opentelemetry-otlp = { version = "0.31.0", features = ["logs"] }
|
|
||||||
opentelemetry-appender-tracing = { version = "0.31.1" }
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
# Build Stage
|
# Build Stage
|
||||||
FROM --platform="${BUILDPLATFORM}" rust:1.92.0-slim-bookworm
|
FROM --platform="${BUILDPLATFORM}" rust:1.86.0-slim-bookworm
|
||||||
USER 0:0
|
USER 0:0
|
||||||
WORKDIR /home/rust/src
|
WORKDIR /home/rust/src
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Build Stage
|
# Build Stage
|
||||||
FROM rust:1.92.0-slim-bookworm
|
FROM rust:1.86.0-slim-bookworm
|
||||||
USER 0:0
|
USER 0:0
|
||||||
WORKDIR /home/rust/src
|
WORKDIR /home/rust/src
|
||||||
|
|
||||||
|
|||||||
@@ -37,19 +37,22 @@ The services and libraries that power the Revolt service.<br/>
|
|||||||
|
|
||||||
Rust 1.86.0 or higher.
|
Rust 1.86.0 or higher.
|
||||||
|
|
||||||
|
> [!CAUTION]
|
||||||
|
> The events server has a significant performance regression between Rust 1.77.2 and 1.78.0 onwards, see [issue #341](https://github.com/revoltchat/backend/issues/341). This is currently solved by build time options but we are looking for a proper fix.
|
||||||
|
|
||||||
## Development Guide
|
## Development Guide
|
||||||
|
|
||||||
Before contributing, make yourself familiar with [our contribution guidelines](https://developers.revolt.chat/contrib.html) and the [technical documentation for this project](https://revoltchat.github.io/backend/).
|
Before contributing, make yourself familiar with [our contribution guidelines](https://developers.revolt.chat/contrib.html) and the [technical documentation for this project](https://revoltchat.github.io/backend/).
|
||||||
|
|
||||||
Before getting started, you'll want to install:
|
Before getting started, you'll want to install:
|
||||||
|
|
||||||
- mise
|
- Rust toolchain (rustup recommended)
|
||||||
- Docker
|
- Docker
|
||||||
- Git
|
- Git
|
||||||
- mold (optional, faster compilation)
|
- mold (optional, faster compilation)
|
||||||
|
|
||||||
> A **default.nix** is available for Nix users!
|
> A **default.nix** is available for Nix users!
|
||||||
> Run `nix-shell` to activate mise.
|
> Just run `nix-shell` and continue.
|
||||||
|
|
||||||
As a heads-up, the development environment uses the following ports:
|
As a heads-up, the development environment uses the following ports:
|
||||||
|
|
||||||
@@ -72,7 +75,7 @@ Now you can clone and build the project:
|
|||||||
```bash
|
```bash
|
||||||
git clone https://github.com/revoltchat/backend revolt-backend
|
git clone https://github.com/revoltchat/backend revolt-backend
|
||||||
cd revolt-backend
|
cd revolt-backend
|
||||||
mise build
|
cargo build
|
||||||
```
|
```
|
||||||
|
|
||||||
A default configuration `Revolt.toml` is present in this project that is suited for development.
|
A default configuration `Revolt.toml` is present in this project that is suited for development.
|
||||||
|
|||||||
@@ -12,10 +12,6 @@ services:
|
|||||||
- "27017:27017"
|
- "27017:27017"
|
||||||
volumes:
|
volumes:
|
||||||
- ./.data/db:/data/db
|
- ./.data/db:/data/db
|
||||||
ulimits:
|
|
||||||
nofile:
|
|
||||||
soft: 65536
|
|
||||||
hard: 65536
|
|
||||||
|
|
||||||
# MinIO
|
# MinIO
|
||||||
minio:
|
minio:
|
||||||
@@ -59,7 +55,7 @@ services:
|
|||||||
|
|
||||||
# Mock SMTP server
|
# Mock SMTP server
|
||||||
maildev:
|
maildev:
|
||||||
image: maildev/maildev
|
image: soulteary/maildev
|
||||||
ports:
|
ports:
|
||||||
- "14025:25"
|
- "14025:25"
|
||||||
- "14080:8080"
|
- "14080:8080"
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-bonfire"
|
name = "revolt-bonfire"
|
||||||
version = "0.10.3"
|
version = "0.8.9"
|
||||||
license = "AGPL-3.0-or-later"
|
license = "AGPL-3.0-or-later"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
publish = false
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
@@ -43,7 +42,7 @@ revolt-result = { path = "../core/result" }
|
|||||||
revolt-models = { path = "../core/models" }
|
revolt-models = { path = "../core/models" }
|
||||||
revolt-config = { path = "../core/config" }
|
revolt-config = { path = "../core/config" }
|
||||||
revolt-database = { path = "../core/database", features = ["voice"] }
|
revolt-database = { path = "../core/database", features = ["voice"] }
|
||||||
revolt-permissions = { path = "../core/permissions" }
|
revolt-permissions = { version = "0.8.9", path = "../core/permissions" }
|
||||||
revolt-presence = { path = "../core/presence", features = ["redis-is-patched"] }
|
revolt-presence = { path = "../core/presence", features = ["redis-is-patched"] }
|
||||||
|
|
||||||
# redis
|
# redis
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-coalesced"
|
name = "revolt-coalesced"
|
||||||
version = "0.10.3"
|
version = "0.8.9"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
authors = ["Paul Makles <me@insrt.uk>", "Zomatree <me@zomatree.live>"]
|
authors = ["Paul Makles <me@insrt.uk>", "Zomatree <me@zomatree.live>"]
|
||||||
description = "Revolt Backend: Coalescion service"
|
description = "Revolt Backend: Coalescion service"
|
||||||
repository = "https://github.com/stoatchat/stoatchat"
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
tokio = ["dep:tokio"]
|
tokio = ["dep:tokio"]
|
||||||
@@ -16,13 +15,8 @@ default = ["tokio"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tokio = { version = "1.47.0", features = ["sync"], optional = true }
|
tokio = { version = "1.47.0", features = ["sync"], optional = true }
|
||||||
indexmap = { version = "2.13.0", optional = true }
|
indexmap = { version = "*", optional = true }
|
||||||
lru = { version = "0.16.3", optional = true }
|
lru = { version = "*", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tokio = { version = "1.47.0", features = [
|
tokio = { version = "1.47.0", features = ["rt", "rt-multi-thread", "macros", "time"] }
|
||||||
"rt",
|
|
||||||
"rt-multi-thread",
|
|
||||||
"macros",
|
|
||||||
"time",
|
|
||||||
] }
|
|
||||||
@@ -15,7 +15,7 @@ use crate::{CoalescionServiceConfig, Error};
|
|||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
/// # Coalescion service
|
/// Coalescion service
|
||||||
///
|
///
|
||||||
/// See module description for example usage.
|
/// See module description for example usage.
|
||||||
pub struct CoalescionService<Id: Hash + Clone + Eq> {
|
pub struct CoalescionService<Id: Hash + Clone + Eq> {
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-config"
|
name = "revolt-config"
|
||||||
version = "0.10.3"
|
version = "0.8.9"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
authors = ["Paul Makles <me@insrt.uk>"]
|
authors = ["Paul Makles <me@insrt.uk>"]
|
||||||
description = "Revolt Backend: Configuration"
|
description = "Revolt Backend: Configuration"
|
||||||
repository = "https://github.com/stoatchat/stoatchat"
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
@@ -38,4 +37,4 @@ sentry = { version = "0.31.5", optional = true }
|
|||||||
sentry-anyhow = { version = "0.38.1", optional = true }
|
sentry-anyhow = { version = "0.38.1", optional = true }
|
||||||
|
|
||||||
# Core
|
# Core
|
||||||
revolt-result = { version = "0.10.3", path = "../result", optional = true }
|
revolt-result = { version = "0.8.9", path = "../result", optional = true }
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
use std::{collections::HashMap, path::Path};
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use cached::proc_macro::cached;
|
use cached::proc_macro::cached;
|
||||||
use config::{Config, File, FileFormat};
|
use config::{Config, File, FileFormat};
|
||||||
@@ -94,21 +94,12 @@ static CONFIG_BUILDER: Lazy<RwLock<Config>> = Lazy::new(|| {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let cwd = std::env::current_dir().unwrap();
|
for path in CONFIG_SEARCH_PATHS {
|
||||||
let mut cwd: Option<&Path> = Some(&cwd);
|
if std::path::Path::new(path).exists() {
|
||||||
|
builder = builder.add_source(File::new(path, FileFormat::Toml));
|
||||||
while let Some(path) = cwd {
|
|
||||||
for config_path in CONFIG_SEARCH_PATHS {
|
|
||||||
let config_path = path.join(config_path);
|
|
||||||
if config_path.exists() {
|
|
||||||
builder = builder
|
|
||||||
.add_source(File::new(config_path.to_str().unwrap(), FileFormat::Toml));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cwd = path.parent();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.build().unwrap()
|
builder.build().unwrap()
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-database"
|
name = "revolt-database"
|
||||||
version = "0.10.3"
|
version = "0.8.9"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "AGPL-3.0-or-later"
|
license = "AGPL-3.0-or-later"
|
||||||
authors = ["Paul Makles <me@insrt.uk>"]
|
authors = ["Paul Makles <me@insrt.uk>"]
|
||||||
description = "Revolt Backend: Database Implementation"
|
description = "Revolt Backend: Database Implementation"
|
||||||
repository = "https://github.com/stoatchat/stoatchat"
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
@@ -16,14 +15,8 @@ mongodb = ["dep:mongodb", "bson", "authifier/database-mongodb"]
|
|||||||
# ... Other
|
# ... Other
|
||||||
tasks = ["isahc", "linkify", "url-escape"]
|
tasks = ["isahc", "linkify", "url-escape"]
|
||||||
async-std-runtime = ["async-std", "authifier/async-std-runtime"]
|
async-std-runtime = ["async-std", "authifier/async-std-runtime"]
|
||||||
rocket-impl = [
|
rocket-impl = ["rocket"]
|
||||||
"rocket",
|
axum-impl = ["axum"]
|
||||||
"schemars",
|
|
||||||
"revolt_okapi",
|
|
||||||
"revolt_rocket_okapi",
|
|
||||||
"authifier/rocket_impl",
|
|
||||||
]
|
|
||||||
axum-impl = ["axum", "revolt-result/axum"]
|
|
||||||
redis-is-patched = ["revolt-presence/redis-is-patched"]
|
redis-is-patched = ["revolt-presence/redis-is-patched"]
|
||||||
voice = ["livekit-api", "livekit-protocol", "livekit-runtime"]
|
voice = ["livekit-api", "livekit-protocol", "livekit-runtime"]
|
||||||
|
|
||||||
@@ -32,19 +25,19 @@ default = ["mongodb", "async-std-runtime", "tasks"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# Core
|
# Core
|
||||||
revolt-config = { version = "0.10.3", path = "../config", features = [
|
revolt-config = { version = "0.8.9", path = "../config", features = [
|
||||||
"report-macros",
|
"report-macros",
|
||||||
] }
|
] }
|
||||||
revolt-result = { version = "0.10.3", path = "../result" }
|
revolt-result = { version = "0.8.9", path = "../result" }
|
||||||
revolt-models = { version = "0.10.3", path = "../models", features = [
|
revolt-models = { version = "0.8.9", path = "../models", features = [
|
||||||
"validator",
|
"validator",
|
||||||
] }
|
] }
|
||||||
revolt-presence = { version = "0.10.3", path = "../presence" }
|
revolt-presence = { version = "0.8.9", path = "../presence" }
|
||||||
revolt-permissions = { version = "0.10.3", path = "../permissions", features = [
|
revolt-permissions = { version = "0.8.9", path = "../permissions", features = [
|
||||||
"serde",
|
"serde",
|
||||||
"bson",
|
"bson",
|
||||||
] }
|
] }
|
||||||
revolt-parser = { version = "0.10.3", path = "../parser" }
|
revolt-parser = { version = "0.8.9", path = "../parser" }
|
||||||
|
|
||||||
# Utility
|
# Utility
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
@@ -54,7 +47,7 @@ ulid = "1.0.0"
|
|||||||
nanoid = "0.4.0"
|
nanoid = "0.4.0"
|
||||||
base64 = "0.21.3"
|
base64 = "0.21.3"
|
||||||
once_cell = "1.17"
|
once_cell = "1.17"
|
||||||
indexmap = "1.9.1"
|
indexmap = "2.12.0"
|
||||||
decancer = "1.6.2"
|
decancer = "1.6.2"
|
||||||
deadqueue = "0.2.4"
|
deadqueue = "0.2.4"
|
||||||
linkify = { optional = true, version = "0.8.1" }
|
linkify = { optional = true, version = "0.8.1" }
|
||||||
@@ -66,7 +59,7 @@ isahc = { optional = true, version = "1.7", features = ["json"] }
|
|||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
revolt_optional_struct = "0.2.0"
|
revolt_optional_struct = "0.2.0"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
iso8601-timestamp = { version = "0.2.10", features = ["serde", "bson"] }
|
iso8601-timestamp = { version = "0.4.0", features = ["serde", "bson"] }
|
||||||
|
|
||||||
# Events
|
# Events
|
||||||
redis-kiss = { version = "0.1.4" }
|
redis-kiss = { version = "0.1.4" }
|
||||||
@@ -89,15 +82,15 @@ async-recursion = "1.0.4"
|
|||||||
async-std = { version = "1.8.0", features = ["attributes"], optional = true }
|
async-std = { version = "1.8.0", features = ["attributes"], optional = true }
|
||||||
|
|
||||||
# Axum Impl
|
# Axum Impl
|
||||||
axum = { version = "0.7.5", optional = true }
|
axum = { version = "0.8.6", optional = true }
|
||||||
|
|
||||||
# Rocket Impl
|
# Rocket Impl
|
||||||
schemars = { version = "0.8.8", optional = true }
|
|
||||||
rocket = { version = "0.5.1", default-features = false, features = [
|
rocket = { version = "0.5.1", default-features = false, features = [
|
||||||
"json",
|
"json",
|
||||||
], optional = true }
|
], optional = true }
|
||||||
revolt_okapi = { version = "0.9.1", optional = true }
|
|
||||||
revolt_rocket_okapi = { version = "0.10.0", optional = true }
|
# Openapi Schema
|
||||||
|
utoipa = { version = "5.4.0", optional = true }
|
||||||
|
|
||||||
# Authifier
|
# Authifier
|
||||||
authifier = { version = "1.0.15" }
|
authifier = { version = "1.0.15" }
|
||||||
@@ -106,6 +99,6 @@ authifier = { version = "1.0.15" }
|
|||||||
amqprs = { version = "1.7.0" }
|
amqprs = { version = "1.7.0" }
|
||||||
|
|
||||||
# Voice
|
# Voice
|
||||||
livekit-api = { version = "0.4.4", optional = true }
|
livekit-api = { version = "=0.4.4", optional = true}
|
||||||
livekit-protocol = { version = "0.4.0", optional = true }
|
livekit-protocol = { version = "=0.4.0", optional = true }
|
||||||
livekit-runtime = { version = "0.3.1", features = ["tokio"], optional = true }
|
livekit-runtime = { version = "=0.3.1", features = ["tokio"], optional = true }
|
||||||
@@ -47,7 +47,6 @@
|
|||||||
],
|
],
|
||||||
"roles": {
|
"roles": {
|
||||||
"__ID:5__": {
|
"__ID:5__": {
|
||||||
"_id": "__ID:5__",
|
|
||||||
"name": "Moderator",
|
"name": "Moderator",
|
||||||
"permissions": {
|
"permissions": {
|
||||||
"a": 545270208,
|
"a": 545270208,
|
||||||
@@ -56,7 +55,6 @@
|
|||||||
"rank": 1
|
"rank": 1
|
||||||
},
|
},
|
||||||
"__ID:6__": {
|
"__ID:6__": {
|
||||||
"_id": "__ID:6__",
|
|
||||||
"name": "Owner",
|
"name": "Owner",
|
||||||
"permissions": {
|
"permissions": {
|
||||||
"a": 0,
|
"a": 0,
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ impl DatabaseInfo {
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
#[cfg(not(feature = "mongodb"))]
|
#[cfg(not(feature = "mongodb"))]
|
||||||
return Err("MongoDB not enabled.".to_string());
|
return Err("MongoDB not enabled.".to_string())
|
||||||
} else {
|
} else {
|
||||||
DatabaseInfo::Reference.connect().await
|
DatabaseInfo::Reference.connect().await
|
||||||
}
|
}
|
||||||
@@ -90,7 +90,7 @@ impl DatabaseInfo {
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
#[cfg(not(feature = "mongodb"))]
|
#[cfg(not(feature = "mongodb"))]
|
||||||
return Err("MongoDB not enabled.".to_string());
|
return Err("MongoDB not enabled.".to_string())
|
||||||
}
|
}
|
||||||
_ => unreachable!("must specify REFERENCE or MONGODB"),
|
_ => unreachable!("must specify REFERENCE or MONGODB"),
|
||||||
}
|
}
|
||||||
@@ -137,7 +137,7 @@ impl Database {
|
|||||||
.api
|
.api
|
||||||
.smtp
|
.smtp
|
||||||
.reply_to
|
.reply_to
|
||||||
.unwrap_or("support@stoat.chat".into()),
|
.unwrap_or("support@revolt.chat".into()),
|
||||||
),
|
),
|
||||||
port: config.api.smtp.port,
|
port: config.api.smtp.port,
|
||||||
use_tls: config.api.smtp.use_tls,
|
use_tls: config.api.smtp.use_tls,
|
||||||
@@ -147,19 +147,19 @@ impl Database {
|
|||||||
templates: if config.production {
|
templates: if config.production {
|
||||||
Templates {
|
Templates {
|
||||||
verify: Template {
|
verify: Template {
|
||||||
title: "Verify your Stoat account.".into(),
|
title: "Verify your Revolt account.".into(),
|
||||||
text: include_str!("../../templates/verify.txt").into(),
|
text: include_str!("../../templates/verify.txt").into(),
|
||||||
url: format!("{}/login/verify/", config.hosts.app),
|
url: format!("{}/login/verify/", config.hosts.app),
|
||||||
html: Some(include_str!("../../templates/verify.html").into()),
|
html: Some(include_str!("../../templates/verify.html").into()),
|
||||||
},
|
},
|
||||||
reset: Template {
|
reset: Template {
|
||||||
title: "Reset your Stoat password.".into(),
|
title: "Reset your Revolt password.".into(),
|
||||||
text: include_str!("../../templates/reset.txt").into(),
|
text: include_str!("../../templates/reset.txt").into(),
|
||||||
url: format!("{}/login/reset/", config.hosts.app),
|
url: format!("{}/login/reset/", config.hosts.app),
|
||||||
html: Some(include_str!("../../templates/reset.html").into()),
|
html: Some(include_str!("../../templates/reset.html").into()),
|
||||||
},
|
},
|
||||||
reset_existing: Template {
|
reset_existing: Template {
|
||||||
title: "You already have a Stoat account, reset your password."
|
title: "You already have a Revolt account, reset your password."
|
||||||
.into(),
|
.into(),
|
||||||
text: include_str!("../../templates/reset-existing.txt").into(),
|
text: include_str!("../../templates/reset-existing.txt").into(),
|
||||||
url: format!("{}/login/reset/", config.hosts.app),
|
url: format!("{}/login/reset/", config.hosts.app),
|
||||||
|
|||||||
@@ -25,6 +25,10 @@ pub use mongodb;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate bson;
|
extern crate bson;
|
||||||
|
|
||||||
|
#[cfg(feature = "utoipa")]
|
||||||
|
#[macro_use]
|
||||||
|
extern crate utoipa;
|
||||||
|
|
||||||
#[cfg(not(feature = "async-std-runtime"))]
|
#[cfg(not(feature = "async-std-runtime"))]
|
||||||
compile_error!("async-std-runtime feature must be enabled.");
|
compile_error!("async-std-runtime feature must be enabled.");
|
||||||
|
|
||||||
@@ -60,7 +64,7 @@ macro_rules! database_derived {
|
|||||||
macro_rules! auto_derived {
|
macro_rules! auto_derived {
|
||||||
( $( $item:item )+ ) => {
|
( $( $item:item )+ ) => {
|
||||||
$(
|
$(
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||||
$item
|
$item
|
||||||
)+
|
)+
|
||||||
};
|
};
|
||||||
@@ -68,8 +72,8 @@ macro_rules! auto_derived {
|
|||||||
|
|
||||||
macro_rules! auto_derived_partial {
|
macro_rules! auto_derived_partial {
|
||||||
( $item:item, $name:expr ) => {
|
( $item:item, $name:expr ) => {
|
||||||
#[derive(OptionalStruct, Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
|
#[derive(OptionalStruct, Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||||
#[optional_derive(Serialize, Deserialize, Debug, Clone, Default, Eq, PartialEq)]
|
#[optional_derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
|
||||||
#[optional_name = $name]
|
#[optional_name = $name]
|
||||||
#[opt_skip_serializing_none]
|
#[opt_skip_serializing_none]
|
||||||
#[opt_some_priority]
|
#[opt_some_priority]
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ struct MigrationInfo {
|
|||||||
revision: i32,
|
revision: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const LATEST_REVISION: i32 = 50; // MUST BE +1 to last migration
|
pub const LATEST_REVISION: i32 = 49; // MUST BE +1 to last migration
|
||||||
|
|
||||||
pub async fn migrate_database(db: &MongoDb) {
|
pub async fn migrate_database(db: &MongoDb) {
|
||||||
let migrations = db.col::<Document>("migrations");
|
let migrations = db.col::<Document>("migrations");
|
||||||
@@ -1264,48 +1264,6 @@ pub async fn run_migrations(db: &MongoDb, revision: i32) -> i32 {
|
|||||||
.expect("Failed to update default_permissions");
|
.expect("Failed to update default_permissions");
|
||||||
};
|
};
|
||||||
|
|
||||||
if revision <= 49 {
|
|
||||||
info!("Running migration [revision 49 / 12-12-2025]: Add _id key to roles");
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
|
||||||
struct Server {
|
|
||||||
#[serde(rename = "_id")]
|
|
||||||
pub id: String,
|
|
||||||
#[serde(default = "HashMap::<String, Document>::new")]
|
|
||||||
pub roles: HashMap<String, Document>,
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut servers = db
|
|
||||||
.db()
|
|
||||||
.collection::<Server>("servers")
|
|
||||||
.find(doc! {
|
|
||||||
"roles": {
|
|
||||||
"$exists": true,
|
|
||||||
"$ne": {}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.map(|res| res.expect("Failed to decode Server { id, roles }"));
|
|
||||||
|
|
||||||
while let Some(server) = servers.next().await {
|
|
||||||
let mut doc = doc! {};
|
|
||||||
|
|
||||||
for id in server.roles.keys() {
|
|
||||||
doc.insert(
|
|
||||||
format!("roles.{id}._id"),
|
|
||||||
id,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
db.db()
|
|
||||||
.collection::<Server>("servers")
|
|
||||||
.update_one(doc! { "_id": &server.id }, doc! { "$set": doc })
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Reminder to update LATEST_REVISION when adding new migrations.
|
// Reminder to update LATEST_REVISION when adding new migrations.
|
||||||
LATEST_REVISION.max(revision)
|
LATEST_REVISION.max(revision)
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,7 @@ auto_derived!(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Composite primary key consisting of channel and user id
|
/// Composite primary key consisting of channel and user id
|
||||||
#[derive(Hash)]
|
#[derive(Hash, Eq)]
|
||||||
pub struct ChannelCompositeKey {
|
pub struct ChannelCompositeKey {
|
||||||
/// Channel Id
|
/// Channel Id
|
||||||
pub channel: String,
|
pub channel: String,
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ impl AbstractMessages for ReferenceDb {
|
|||||||
let mut messages = self.messages.lock().await;
|
let mut messages = self.messages.lock().await;
|
||||||
if let Some(message) = messages.get_mut(id) {
|
if let Some(message) = messages.get_mut(id) {
|
||||||
if let Some(users) = message.reactions.get_mut(emoji) {
|
if let Some(users) = message.reactions.get_mut(emoji) {
|
||||||
users.remove(&user.to_string());
|
users.swap_remove(&user.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -260,7 +260,7 @@ impl AbstractMessages for ReferenceDb {
|
|||||||
async fn clear_reaction(&self, id: &str, emoji: &str) -> Result<()> {
|
async fn clear_reaction(&self, id: &str, emoji: &str) -> Result<()> {
|
||||||
let mut messages = self.messages.lock().await;
|
let mut messages = self.messages.lock().await;
|
||||||
if let Some(message) = messages.get_mut(id) {
|
if let Some(message) = messages.get_mut(id) {
|
||||||
message.reactions.remove(emoji);
|
message.reactions.swap_remove(emoji);
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(create_error!(NotFound))
|
Err(create_error!(NotFound))
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ auto_derived_partial!(
|
|||||||
|
|
||||||
auto_derived!(
|
auto_derived!(
|
||||||
/// Composite primary key consisting of server and user id
|
/// Composite primary key consisting of server and user id
|
||||||
#[derive(Hash, Default)]
|
#[derive(Hash, Default, Eq)]
|
||||||
pub struct MemberCompositeKey {
|
pub struct MemberCompositeKey {
|
||||||
/// Server Id
|
/// Server Id
|
||||||
pub server: String,
|
pub server: String,
|
||||||
@@ -72,7 +72,6 @@ auto_derived!(
|
|||||||
CanReceive,
|
CanReceive,
|
||||||
CanPublish,
|
CanPublish,
|
||||||
JoinedAt,
|
JoinedAt,
|
||||||
VoiceChannel,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Member removal intention
|
/// Member removal intention
|
||||||
@@ -225,14 +224,13 @@ impl Member {
|
|||||||
|
|
||||||
pub fn remove_field(&mut self, field: &FieldsMember) {
|
pub fn remove_field(&mut self, field: &FieldsMember) {
|
||||||
match field {
|
match field {
|
||||||
FieldsMember::JoinedAt => {},
|
FieldsMember::JoinedAt => (),
|
||||||
FieldsMember::Avatar => self.avatar = None,
|
FieldsMember::Avatar => self.avatar = None,
|
||||||
FieldsMember::Nickname => self.nickname = None,
|
FieldsMember::Nickname => self.nickname = None,
|
||||||
FieldsMember::Roles => self.roles.clear(),
|
FieldsMember::Roles => self.roles.clear(),
|
||||||
FieldsMember::Timeout => self.timeout = None,
|
FieldsMember::Timeout => self.timeout = None,
|
||||||
FieldsMember::CanReceive => self.can_receive = true,
|
FieldsMember::CanReceive => self.can_receive = true,
|
||||||
FieldsMember::CanPublish => self.can_publish = true,
|
FieldsMember::CanPublish => self.can_publish = true,
|
||||||
FieldsMember::VoiceChannel => {},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -330,15 +330,14 @@ impl AbstractServerMembers for MongoDb {
|
|||||||
|
|
||||||
impl IntoDocumentPath for FieldsMember {
|
impl IntoDocumentPath for FieldsMember {
|
||||||
fn as_path(&self) -> Option<&'static str> {
|
fn as_path(&self) -> Option<&'static str> {
|
||||||
match self {
|
Some(match self {
|
||||||
FieldsMember::JoinedAt => Some("joined_at"),
|
FieldsMember::JoinedAt => "joined_at",
|
||||||
FieldsMember::Avatar => Some("avatar"),
|
FieldsMember::Avatar => "avatar",
|
||||||
FieldsMember::Nickname => Some("nickname"),
|
FieldsMember::Nickname => "nickname",
|
||||||
FieldsMember::Roles => Some("roles"),
|
FieldsMember::Roles => "roles",
|
||||||
FieldsMember::Timeout => Some("timeout"),
|
FieldsMember::Timeout => "timeout",
|
||||||
FieldsMember::CanPublish => Some("can_publish"),
|
FieldsMember::CanPublish => "can_publish",
|
||||||
FieldsMember::CanReceive => Some("can_receive"),
|
FieldsMember::CanReceive => "can_receive",
|
||||||
FieldsMember::VoiceChannel => None,
|
})
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,9 +68,6 @@ auto_derived_partial!(
|
|||||||
auto_derived_partial!(
|
auto_derived_partial!(
|
||||||
/// Role
|
/// Role
|
||||||
pub struct Role {
|
pub struct Role {
|
||||||
/// Unique Id
|
|
||||||
#[serde(rename = "_id")]
|
|
||||||
pub id: String,
|
|
||||||
/// Role name
|
/// Role name
|
||||||
pub name: String,
|
pub name: String,
|
||||||
/// Permissions available to this role
|
/// Permissions available to this role
|
||||||
@@ -249,6 +246,7 @@ impl Server {
|
|||||||
role.update(
|
role.update(
|
||||||
db,
|
db,
|
||||||
&self.id,
|
&self.id,
|
||||||
|
role_id,
|
||||||
PartialRole {
|
PartialRole {
|
||||||
permissions: Some(permissions),
|
permissions: Some(permissions),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
@@ -299,7 +297,6 @@ impl Role {
|
|||||||
/// Into optional struct
|
/// Into optional struct
|
||||||
pub fn into_optional(self) -> PartialRole {
|
pub fn into_optional(self) -> PartialRole {
|
||||||
PartialRole {
|
PartialRole {
|
||||||
id: Some(self.id),
|
|
||||||
name: Some(self.name),
|
name: Some(self.name),
|
||||||
permissions: Some(self.permissions),
|
permissions: Some(self.permissions),
|
||||||
colour: self.colour,
|
colour: self.colour,
|
||||||
@@ -309,29 +306,20 @@ impl Role {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Create a role
|
/// Create a role
|
||||||
pub async fn create(db: &Database, server: &Server, name: String) -> Result<Self> {
|
pub async fn create(&self, db: &Database, server_id: &str) -> Result<String> {
|
||||||
let role = Role {
|
let role_id = Ulid::new().to_string();
|
||||||
id: Ulid::new().to_string(),
|
db.insert_role(server_id, &role_id, self).await?;
|
||||||
name,
|
|
||||||
// Rank of the new role should be below the lowest role
|
|
||||||
rank: server.roles.len() as i64,
|
|
||||||
colour: None,
|
|
||||||
hoist: false,
|
|
||||||
permissions: Default::default(),
|
|
||||||
};
|
|
||||||
|
|
||||||
db.insert_role(&server.id, &role).await?;
|
|
||||||
|
|
||||||
EventV1::ServerRoleUpdate {
|
EventV1::ServerRoleUpdate {
|
||||||
id: server.id.clone(),
|
id: server_id.to_string(),
|
||||||
role_id: role.id.clone(),
|
role_id: role_id.to_string(),
|
||||||
data: role.clone().into_optional().into(),
|
data: self.clone().into_optional().into(),
|
||||||
clear: vec![],
|
clear: vec![],
|
||||||
}
|
}
|
||||||
.p(server.id.clone())
|
.p(server_id.to_string())
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
Ok(role)
|
Ok(role_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update server data
|
/// Update server data
|
||||||
@@ -339,6 +327,7 @@ impl Role {
|
|||||||
&mut self,
|
&mut self,
|
||||||
db: &Database,
|
db: &Database,
|
||||||
server_id: &str,
|
server_id: &str,
|
||||||
|
role_id: &str,
|
||||||
partial: PartialRole,
|
partial: PartialRole,
|
||||||
remove: Vec<FieldsRole>,
|
remove: Vec<FieldsRole>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
@@ -348,14 +337,14 @@ impl Role {
|
|||||||
|
|
||||||
self.apply_options(partial.clone());
|
self.apply_options(partial.clone());
|
||||||
|
|
||||||
db.update_role(server_id, &self.id, &partial, remove.clone())
|
db.update_role(server_id, role_id, &partial, remove.clone())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
EventV1::ServerRoleUpdate {
|
EventV1::ServerRoleUpdate {
|
||||||
id: server_id.to_string(),
|
id: server_id.to_string(),
|
||||||
role_id: self.id.clone(),
|
role_id: role_id.to_string(),
|
||||||
data: partial.into(),
|
data: partial.into(),
|
||||||
clear: remove.into_iter().map(Into::into).collect(),
|
clear: vec![],
|
||||||
}
|
}
|
||||||
.p(server_id.to_string())
|
.p(server_id.to_string())
|
||||||
.await;
|
.await;
|
||||||
@@ -371,15 +360,15 @@ impl Role {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Delete a role
|
/// Delete a role
|
||||||
pub async fn delete(self, db: &Database, server_id: &str) -> Result<()> {
|
pub async fn delete(self, db: &Database, server_id: &str, role_id: &str) -> Result<()> {
|
||||||
EventV1::ServerRoleDelete {
|
EventV1::ServerRoleDelete {
|
||||||
id: server_id.to_string(),
|
id: server_id.to_string(),
|
||||||
role_id: self.id.clone(),
|
role_id: role_id.to_string(),
|
||||||
}
|
}
|
||||||
.p(server_id.to_string())
|
.p(server_id.to_string())
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
db.delete_role(server_id, &self.id).await
|
db.delete_role(server_id, role_id).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ pub trait AbstractServers: Sync + Send {
|
|||||||
async fn delete_server(&self, id: &str) -> Result<()>;
|
async fn delete_server(&self, id: &str) -> Result<()>;
|
||||||
|
|
||||||
/// Insert a new role into server object
|
/// Insert a new role into server object
|
||||||
async fn insert_role(&self, server_id: &str, role: &Role) -> Result<()>;
|
async fn insert_role(&self, server_id: &str, role_id: &str, role: &Role) -> Result<()>;
|
||||||
|
|
||||||
/// Update an existing role on a server
|
/// Update an existing role on a server
|
||||||
async fn update_role(
|
async fn update_role(
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ impl AbstractServers for MongoDb {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Insert a new role into server object
|
/// Insert a new role into server object
|
||||||
async fn insert_role(&self, server_id: &str, role: &Role) -> Result<()> {
|
async fn insert_role(&self, server_id: &str, role_id: &str, role: &Role) -> Result<()> {
|
||||||
self.col::<Document>(COL)
|
self.col::<Document>(COL)
|
||||||
.update_one(
|
.update_one(
|
||||||
doc! {
|
doc! {
|
||||||
@@ -77,7 +77,7 @@ impl AbstractServers for MongoDb {
|
|||||||
},
|
},
|
||||||
doc! {
|
doc! {
|
||||||
"$set": {
|
"$set": {
|
||||||
"roles.".to_owned() + &role.id: to_document(role)
|
"roles.".to_owned() + role_id: to_document(role)
|
||||||
.map_err(|_| create_database_error!("to_document", "role"))?
|
.map_err(|_| create_database_error!("to_document", "role"))?
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -72,10 +72,10 @@ impl AbstractServers for ReferenceDb {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Insert a new role into server object
|
/// Insert a new role into server object
|
||||||
async fn insert_role(&self, server_id: &str, role: &Role) -> Result<()> {
|
async fn insert_role(&self, server_id: &str, role_id: &str, role: &Role) -> Result<()> {
|
||||||
let mut servers = self.servers.lock().await;
|
let mut servers = self.servers.lock().await;
|
||||||
if let Some(server) = servers.get_mut(server_id) {
|
if let Some(server) = servers.get_mut(server_id) {
|
||||||
server.roles.insert(role.id.clone(), role.clone());
|
server.roles.insert(role_id.to_string(), role.clone());
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(create_error!(NotFound))
|
Err(create_error!(NotFound))
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ use revolt_result::{create_error, Error, Result};
|
|||||||
|
|
||||||
use crate::{Database, User};
|
use crate::{Database, User};
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl<S> FromRequestParts<S> for User
|
impl<S> FromRequestParts<S> for User
|
||||||
where
|
where
|
||||||
Database: FromRef<S>,
|
Database: FromRef<S>,
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ mod model;
|
|||||||
mod ops;
|
mod ops;
|
||||||
#[cfg(feature = "rocket-impl")]
|
#[cfg(feature = "rocket-impl")]
|
||||||
mod rocket;
|
mod rocket;
|
||||||
#[cfg(feature = "rocket-impl")]
|
|
||||||
mod schema;
|
|
||||||
|
|
||||||
pub use model::*;
|
pub use model::*;
|
||||||
pub use ops::*;
|
pub use ops::*;
|
||||||
@@ -15,7 +15,7 @@ use serde_json::json;
|
|||||||
use ulid::Ulid;
|
use ulid::Ulid;
|
||||||
|
|
||||||
auto_derived_partial!(
|
auto_derived_partial!(
|
||||||
/// # User
|
/// User
|
||||||
pub struct User {
|
pub struct User {
|
||||||
/// Unique Id
|
/// Unique Id
|
||||||
#[serde(rename = "_id")]
|
#[serde(rename = "_id")]
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
use revolt_okapi::openapi3::{SecurityScheme, SecuritySchemeData};
|
|
||||||
use revolt_rocket_okapi::{
|
|
||||||
gen::OpenApiGenerator,
|
|
||||||
request::{OpenApiFromRequest, RequestHeaderInput},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::User;
|
|
||||||
|
|
||||||
impl OpenApiFromRequest<'_> for User {
|
|
||||||
fn from_request_input(
|
|
||||||
_gen: &mut OpenApiGenerator,
|
|
||||||
_name: String,
|
|
||||||
_required: bool,
|
|
||||||
) -> revolt_rocket_okapi::Result<RequestHeaderInput> {
|
|
||||||
let mut requirements = schemars::Map::new();
|
|
||||||
requirements.insert("Session Token".to_owned(), vec![]);
|
|
||||||
|
|
||||||
Ok(RequestHeaderInput::Security(
|
|
||||||
"Session Token".to_owned(),
|
|
||||||
SecurityScheme {
|
|
||||||
data: SecuritySchemeData::ApiKey {
|
|
||||||
name: "x-session-token".to_owned(),
|
|
||||||
location: "header".to_owned(),
|
|
||||||
},
|
|
||||||
description: Some("Used to authenticate as a user.".to_owned()),
|
|
||||||
extensions: schemars::Map::new(),
|
|
||||||
},
|
|
||||||
requirements,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,7 +17,7 @@ use super::DelayedTask;
|
|||||||
use crate::Channel::TextChannel;
|
use crate::Channel::TextChannel;
|
||||||
|
|
||||||
/// Enumeration of possible events
|
/// Enumeration of possible events
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum AckEvent {
|
pub enum AckEvent {
|
||||||
/// Add mentions for a channel
|
/// Add mentions for a channel
|
||||||
ProcessMessage {
|
ProcessMessage {
|
||||||
|
|||||||
@@ -691,7 +691,6 @@ impl From<crate::FieldsMember> for FieldsMember {
|
|||||||
crate::FieldsMember::CanReceive => FieldsMember::CanReceive,
|
crate::FieldsMember::CanReceive => FieldsMember::CanReceive,
|
||||||
crate::FieldsMember::CanPublish => FieldsMember::CanPublish,
|
crate::FieldsMember::CanPublish => FieldsMember::CanPublish,
|
||||||
crate::FieldsMember::JoinedAt => FieldsMember::JoinedAt,
|
crate::FieldsMember::JoinedAt => FieldsMember::JoinedAt,
|
||||||
crate::FieldsMember::VoiceChannel => FieldsMember::VoiceChannel,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -706,7 +705,6 @@ impl From<FieldsMember> for crate::FieldsMember {
|
|||||||
FieldsMember::CanReceive => crate::FieldsMember::CanReceive,
|
FieldsMember::CanReceive => crate::FieldsMember::CanReceive,
|
||||||
FieldsMember::CanPublish => crate::FieldsMember::CanPublish,
|
FieldsMember::CanPublish => crate::FieldsMember::CanPublish,
|
||||||
FieldsMember::JoinedAt => crate::FieldsMember::JoinedAt,
|
FieldsMember::JoinedAt => crate::FieldsMember::JoinedAt,
|
||||||
FieldsMember::VoiceChannel => crate::FieldsMember::VoiceChannel,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -898,7 +896,6 @@ impl From<SystemMessageChannels> for crate::SystemMessageChannels {
|
|||||||
impl From<crate::Role> for Role {
|
impl From<crate::Role> for Role {
|
||||||
fn from(value: crate::Role) -> Self {
|
fn from(value: crate::Role) -> Self {
|
||||||
Role {
|
Role {
|
||||||
id: value.id,
|
|
||||||
name: value.name,
|
name: value.name,
|
||||||
permissions: value.permissions,
|
permissions: value.permissions,
|
||||||
colour: value.colour,
|
colour: value.colour,
|
||||||
@@ -911,7 +908,6 @@ impl From<crate::Role> for Role {
|
|||||||
impl From<Role> for crate::Role {
|
impl From<Role> for crate::Role {
|
||||||
fn from(value: Role) -> crate::Role {
|
fn from(value: Role) -> crate::Role {
|
||||||
crate::Role {
|
crate::Role {
|
||||||
id: value.id,
|
|
||||||
name: value.name,
|
name: value.name,
|
||||||
permissions: value.permissions,
|
permissions: value.permissions,
|
||||||
colour: value.colour,
|
colour: value.colour,
|
||||||
@@ -924,7 +920,6 @@ impl From<Role> for crate::Role {
|
|||||||
impl From<crate::PartialRole> for PartialRole {
|
impl From<crate::PartialRole> for PartialRole {
|
||||||
fn from(value: crate::PartialRole) -> Self {
|
fn from(value: crate::PartialRole) -> Self {
|
||||||
PartialRole {
|
PartialRole {
|
||||||
id: value.id,
|
|
||||||
name: value.name,
|
name: value.name,
|
||||||
permissions: value.permissions,
|
permissions: value.permissions,
|
||||||
colour: value.colour,
|
colour: value.colour,
|
||||||
@@ -937,7 +932,6 @@ impl From<crate::PartialRole> for PartialRole {
|
|||||||
impl From<PartialRole> for crate::PartialRole {
|
impl From<PartialRole> for crate::PartialRole {
|
||||||
fn from(value: PartialRole) -> crate::PartialRole {
|
fn from(value: PartialRole) -> crate::PartialRole {
|
||||||
crate::PartialRole {
|
crate::PartialRole {
|
||||||
id: value.id,
|
|
||||||
name: value.name,
|
name: value.name,
|
||||||
permissions: value.permissions,
|
permissions: value.permissions,
|
||||||
colour: value.colour,
|
colour: value.colour,
|
||||||
|
|||||||
@@ -10,16 +10,16 @@ use once_cell::sync::Lazy;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct IdempotencyKey {
|
#[cfg_attr(feature = "utoipa", derive(IntoParams))]
|
||||||
key: String,
|
#[cfg_attr(feature = "utoipa", into_params(names("Idempotency-Key"), parameter_in=Header))]
|
||||||
}
|
pub struct IdempotencyKey(String);
|
||||||
|
|
||||||
static TOKEN_CACHE: Lazy<Mutex<lru::LruCache<String, ()>>> =
|
static TOKEN_CACHE: Lazy<Mutex<lru::LruCache<String, ()>>> =
|
||||||
Lazy::new(|| Mutex::new(lru::LruCache::new(NonZeroUsize::new(1000).unwrap())));
|
Lazy::new(|| Mutex::new(lru::LruCache::new(NonZeroUsize::new(1000).unwrap())));
|
||||||
|
|
||||||
impl IdempotencyKey {
|
impl IdempotencyKey {
|
||||||
pub fn unchecked_from_string(key: String) -> Self {
|
pub fn unchecked_from_string(key: String) -> Self {
|
||||||
Self { key }
|
Self(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Backwards compatibility.
|
// Backwards compatibility.
|
||||||
@@ -32,56 +32,56 @@ impl IdempotencyKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cache.put(v.clone(), ());
|
cache.put(v.clone(), ());
|
||||||
self.key = v;
|
self.0 = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_key(self) -> String {
|
pub fn into_key(self) -> String {
|
||||||
self.key
|
self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rocket-impl")]
|
// #[cfg(feature = "rocket-impl")]
|
||||||
use revolt_rocket_okapi::{
|
// use revolt_rocket_okapi::{
|
||||||
gen::OpenApiGenerator,
|
// gen::OpenApiGenerator,
|
||||||
request::{OpenApiFromRequest, RequestHeaderInput},
|
// request::{OpenApiFromRequest, RequestHeaderInput},
|
||||||
revolt_okapi::openapi3::{Parameter, ParameterValue},
|
// revolt_okapi::openapi3::{Parameter, ParameterValue},
|
||||||
};
|
// };
|
||||||
|
|
||||||
#[cfg(feature = "rocket-impl")]
|
// #[cfg(feature = "rocket-impl")]
|
||||||
use schemars::schema::{InstanceType, SchemaObject, SingleOrVec};
|
// use schemars::schema::{InstanceType, SchemaObject, SingleOrVec};
|
||||||
|
|
||||||
#[cfg(feature = "rocket-impl")]
|
// #[cfg(feature = "rocket-impl")]
|
||||||
impl OpenApiFromRequest<'_> for IdempotencyKey {
|
// impl OpenApiFromRequest<'_> for IdempotencyKey {
|
||||||
fn from_request_input(
|
// fn from_request_input(
|
||||||
_gen: &mut OpenApiGenerator,
|
// _gen: &mut OpenApiGenerator,
|
||||||
_name: String,
|
// _name: String,
|
||||||
_required: bool,
|
// _required: bool,
|
||||||
) -> revolt_rocket_okapi::Result<RequestHeaderInput> {
|
// ) -> revolt_rocket_okapi::Result<RequestHeaderInput> {
|
||||||
Ok(RequestHeaderInput::Parameter(Parameter {
|
// Ok(RequestHeaderInput::Parameter(Parameter {
|
||||||
name: "Idempotency-Key".to_string(),
|
// name: "Idempotency-Key".to_string(),
|
||||||
description: Some("Unique key to prevent duplicate requests".to_string()),
|
// description: Some("Unique key to prevent duplicate requests".to_string()),
|
||||||
allow_empty_value: false,
|
// allow_empty_value: false,
|
||||||
required: false,
|
// required: false,
|
||||||
deprecated: false,
|
// deprecated: false,
|
||||||
extensions: schemars::Map::new(),
|
// extensions: schemars::Map::new(),
|
||||||
location: "header".to_string(),
|
// location: "header".to_string(),
|
||||||
value: ParameterValue::Schema {
|
// value: ParameterValue::Schema {
|
||||||
allow_reserved: false,
|
// allow_reserved: false,
|
||||||
example: None,
|
// example: None,
|
||||||
examples: None,
|
// examples: None,
|
||||||
explode: None,
|
// explode: None,
|
||||||
style: None,
|
// style: None,
|
||||||
schema: SchemaObject {
|
// schema: SchemaObject {
|
||||||
instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::String))),
|
// instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::String))),
|
||||||
..Default::default()
|
// ..Default::default()
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
}))
|
// }))
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
#[cfg(feature = "rocket-impl")]
|
#[cfg(feature = "rocket-impl")]
|
||||||
use rocket::{
|
use rocket::{
|
||||||
@@ -110,18 +110,16 @@ impl<'r> FromRequest<'r> for IdempotencyKey {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let idempotency = IdempotencyKey { key };
|
let idempotency = IdempotencyKey(key);
|
||||||
let mut cache = TOKEN_CACHE.lock().await;
|
let mut cache = TOKEN_CACHE.lock().await;
|
||||||
if cache.get(&idempotency.key).is_some() {
|
if cache.get(&idempotency.0).is_some() {
|
||||||
return Outcome::Error((Status::Conflict, create_error!(DuplicateNonce)));
|
return Outcome::Error((Status::Conflict, create_error!(DuplicateNonce)));
|
||||||
}
|
}
|
||||||
|
|
||||||
cache.put(idempotency.key.clone(), ());
|
cache.put(idempotency.0.clone(), ());
|
||||||
return Outcome::Success(idempotency);
|
return Outcome::Success(idempotency);
|
||||||
}
|
}
|
||||||
|
|
||||||
Outcome::Success(IdempotencyKey {
|
Outcome::Success(IdempotencyKey(ulid::Ulid::new().to_string()))
|
||||||
key: ulid::Ulid::new().to_string(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,5 +5,7 @@ pub mod idempotency;
|
|||||||
pub mod permissions;
|
pub mod permissions;
|
||||||
pub mod reference;
|
pub mod reference;
|
||||||
pub mod test_fixtures;
|
pub mod test_fixtures;
|
||||||
|
#[cfg(feature = "utoipa")]
|
||||||
|
pub mod utoipa;
|
||||||
|
|
||||||
pub use funcs::*;
|
pub use funcs::*;
|
||||||
@@ -3,11 +3,6 @@ use std::str::FromStr;
|
|||||||
use revolt_result::Result;
|
use revolt_result::Result;
|
||||||
#[cfg(feature = "rocket-impl")]
|
#[cfg(feature = "rocket-impl")]
|
||||||
use rocket::request::FromParam;
|
use rocket::request::FromParam;
|
||||||
#[cfg(feature = "rocket-impl")]
|
|
||||||
use schemars::{
|
|
||||||
schema::{InstanceType, Schema, SchemaObject, SingleOrVec},
|
|
||||||
JsonSchema,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Bot, Channel, Database, Emoji, Invite, Member, Message, Server, ServerBan, User, Webhook,
|
Bot, Channel, Database, Emoji, Invite, Member, Message, Server, ServerBan, User, Webhook,
|
||||||
@@ -112,17 +107,3 @@ impl<'r> FromParam<'r> for Reference<'r> {
|
|||||||
Ok(Reference::from_unchecked(param))
|
Ok(Reference::from_unchecked(param))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rocket-impl")]
|
|
||||||
impl<'a> JsonSchema for Reference<'a> {
|
|
||||||
fn schema_name() -> String {
|
|
||||||
"Id".to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn json_schema(_gen: &mut schemars::gen::SchemaGenerator) -> Schema {
|
|
||||||
Schema::Object(SchemaObject {
|
|
||||||
instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::String))),
|
|
||||||
..Default::default()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
use utoipa::{
|
||||||
|
openapi::{
|
||||||
|
schema::SchemaType,
|
||||||
|
security::{ApiKey, ApiKeyValue, SecurityScheme},
|
||||||
|
ObjectBuilder, OpenApi, RefOr, Schema, Type,
|
||||||
|
},
|
||||||
|
Modify, PartialSchema, ToSchema,
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::util::reference::Reference;
|
||||||
|
|
||||||
|
pub struct TokenSecurity;
|
||||||
|
|
||||||
|
impl Modify for TokenSecurity {
|
||||||
|
fn modify(&self, openapi: &mut OpenApi) {
|
||||||
|
let components = openapi.components.get_or_insert_default();
|
||||||
|
|
||||||
|
components.add_security_scheme(
|
||||||
|
"Session-Token",
|
||||||
|
SecurityScheme::ApiKey(ApiKey::Header(ApiKeyValue::new(
|
||||||
|
"X-Session-Token".to_string(),
|
||||||
|
))),
|
||||||
|
);
|
||||||
|
|
||||||
|
components.add_security_scheme(
|
||||||
|
"Bot-Token",
|
||||||
|
SecurityScheme::ApiKey(ApiKey::Header(ApiKeyValue::new("X-Bot-Ticket".to_string()))),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToSchema for Reference<'_> {
|
||||||
|
fn name() -> std::borrow::Cow<'static, str> {
|
||||||
|
std::borrow::Cow::Borrowed("Reference")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialSchema for Reference<'_> {
|
||||||
|
fn schema() -> RefOr<Schema> {
|
||||||
|
RefOr::T(
|
||||||
|
ObjectBuilder::new()
|
||||||
|
.description(Some("An id referencing a stoat model."))
|
||||||
|
.schema_type(SchemaType::Type(Type::String))
|
||||||
|
.examples(["01FD58YK5W7QRV5H3D64KTQYX3"])
|
||||||
|
.build()
|
||||||
|
.into(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,6 @@ Please navigate to: {{url}}
|
|||||||
|
|
||||||
This email is intended for {{email}}
|
This email is intended for {{email}}
|
||||||
|
|
||||||
This email has no association with Stoat or Revolt Platforms Ltd.
|
This email has no association with Revolt or Revolt Platforms Ltd.
|
||||||
Learn more about third party instances here:
|
Learn more about third party instances here:
|
||||||
https://developers.revolt.chat/faq.html
|
https://developers.revolt.chat/faq.html
|
||||||
@@ -5,6 +5,6 @@ Please navigate to: {{url}}
|
|||||||
|
|
||||||
This email is intended for {{email}}
|
This email is intended for {{email}}
|
||||||
|
|
||||||
This email has no association with Stoat or Revolt Platforms Ltd.
|
This email has no association with Revolt or Revolt Platforms Ltd.
|
||||||
Learn more about third party instances here:
|
Learn more about third party instances here:
|
||||||
https://developers.revolt.chat/faq.html
|
https://developers.revolt.chat/faq.html
|
||||||
@@ -1,20 +1,13 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-files"
|
name = "revolt-files"
|
||||||
version = "0.10.3"
|
version = "0.8.9"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "AGPL-3.0-or-later"
|
license = "AGPL-3.0-or-later"
|
||||||
authors = ["Paul Makles <me@insrt.uk>"]
|
authors = ["Paul Makles <me@insrt.uk>"]
|
||||||
description = "Revolt Backend: S3 and encryption subroutines"
|
description = "Revolt Backend: S3 and encryption subroutines"
|
||||||
repository = "https://github.com/stoatchat/stoatchat"
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = { workspace = true }
|
tracing = "0.1"
|
||||||
thiserror = { workspace = true }
|
|
||||||
|
|
||||||
tracing = { workspace = true }
|
|
||||||
|
|
||||||
tokio = { workspace = true }
|
|
||||||
async-trait = { workspace = true }
|
|
||||||
|
|
||||||
ffprobe = "0.4.0"
|
ffprobe = "0.4.0"
|
||||||
imagesize = "0.13.0"
|
imagesize = "0.13.0"
|
||||||
@@ -27,14 +20,14 @@ typenum = "1.17.0"
|
|||||||
aws-config = "1.5.5"
|
aws-config = "1.5.5"
|
||||||
aws-sdk-s3 = { version = "1.46.0", features = ["behavior-version-latest"] }
|
aws-sdk-s3 = { version = "1.46.0", features = ["behavior-version-latest"] }
|
||||||
|
|
||||||
revolt-config = { version = "0.10.3", path = "../config", features = [
|
revolt-config = { version = "0.8.9", path = "../config", features = [
|
||||||
"report-macros",
|
"report-macros",
|
||||||
] }
|
] }
|
||||||
revolt-result = { version = "0.10.3", path = "../result" }
|
revolt-result = { version = "0.8.9", path = "../result" }
|
||||||
|
|
||||||
# image processing
|
# image processing
|
||||||
jxl-oxide = { workspace = true }
|
jxl-oxide = "0.8.1"
|
||||||
image = { workspace = true }
|
image = { version = "0.25.2" }
|
||||||
|
|
||||||
# svg rendering
|
# svg rendering
|
||||||
usvg = "0.44.0"
|
usvg = "0.44.0"
|
||||||
@@ -43,6 +36,3 @@ tiny-skia = "0.11.4"
|
|||||||
|
|
||||||
# encoding
|
# encoding
|
||||||
webp = "0.3.0"
|
webp = "0.3.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
uuid = { workspace = true }
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
use aes_gcm::{
|
|
||||||
aead::{Aead, AeadCore, AeadMutInPlace, OsRng},
|
|
||||||
Aes256Gcm, Key, KeyInit, Nonce,
|
|
||||||
};
|
|
||||||
use base64::{prelude::BASE64_STANDARD, Engine};
|
|
||||||
|
|
||||||
use crate::EncryptionRepository;
|
|
||||||
|
|
||||||
pub struct EncryptionKey {
|
|
||||||
key: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EncryptionKey {
|
|
||||||
pub async fn from_config() -> EncryptionKey {
|
|
||||||
EncryptionKey::new(revolt_config::config().await.files.encryption_key)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new(key: String) -> EncryptionKey {
|
|
||||||
EncryptionKey { key }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn create_cipher(&self) -> Aes256Gcm {
|
|
||||||
let key = &BASE64_STANDARD
|
|
||||||
.decode(self.key.clone())
|
|
||||||
.expect("valid base64 string")[..];
|
|
||||||
let key: &Key<Aes256Gcm> = key.into();
|
|
||||||
Aes256Gcm::new(key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EncryptionRepository for EncryptionKey {
|
|
||||||
fn decrypt_buffer(&self, mut buf: Vec<u8>, iv: &str) -> anyhow::Result<Vec<u8>> {
|
|
||||||
let iv = &BASE64_STANDARD.decode(iv).unwrap()[..];
|
|
||||||
let iv: &Nonce<typenum::consts::U12> = iv.into();
|
|
||||||
|
|
||||||
self.create_cipher()
|
|
||||||
.decrypt_in_place(iv, b"", &mut buf)
|
|
||||||
.map_err(|error| {
|
|
||||||
tracing::error!("{}", error);
|
|
||||||
anyhow::anyhow!("EncryptionRepository: decryption failed")
|
|
||||||
})?;
|
|
||||||
|
|
||||||
Ok(buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn encrypt_buffer(&self, buf: &[u8]) -> anyhow::Result<(Vec<u8>, String)> {
|
|
||||||
let iv = Aes256Gcm::generate_nonce(&mut OsRng);
|
|
||||||
|
|
||||||
let buf = self.create_cipher().encrypt(&iv, buf).map_err(|error| {
|
|
||||||
tracing::error!("{}", error);
|
|
||||||
anyhow::anyhow!("EncryptionRepository: encryption failed")
|
|
||||||
})?;
|
|
||||||
|
|
||||||
Ok((buf, BASE64_STANDARD.encode(iv)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_encrypt_and_decrypt() {
|
|
||||||
let encryption =
|
|
||||||
EncryptionKey::new("XkbJ8gBzrouQ+15Ri23xCC81+aZE26Z6+gXzglFxOD4=".to_string());
|
|
||||||
|
|
||||||
let buf: Vec<u8> = vec![67];
|
|
||||||
let (ciphertext, iv) = encryption.encrypt_buffer(&buf[..]).unwrap();
|
|
||||||
assert_eq!(ciphertext.len(), 17);
|
|
||||||
|
|
||||||
let plaintext = encryption.decrypt_buffer(ciphertext, &iv).unwrap();
|
|
||||||
assert_eq!(plaintext.len(), 1);
|
|
||||||
assert_eq!(plaintext[0], 67);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,316 +0,0 @@
|
|||||||
use anyhow::Result;
|
|
||||||
use image::{DynamicImage, ImageBuffer, ImageReader};
|
|
||||||
use jxl_oxide::integration::JxlDecoder;
|
|
||||||
use revolt_config::report_internal_error;
|
|
||||||
use std::io::{BufRead, Read, Seek};
|
|
||||||
use tempfile::NamedTempFile;
|
|
||||||
use tiny_skia::Pixmap;
|
|
||||||
|
|
||||||
use crate::{MediaError, MediaRepository};
|
|
||||||
|
|
||||||
pub struct MediaImpl {
|
|
||||||
config: revolt_config::Files,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MediaImpl {
|
|
||||||
pub async fn from_config() -> MediaImpl {
|
|
||||||
MediaImpl {
|
|
||||||
config: revolt_config::config().await.files,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new(config: revolt_config::Files) -> MediaImpl {
|
|
||||||
MediaImpl { config }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MediaRepository for MediaImpl {
|
|
||||||
fn image_size(&self, f: &NamedTempFile) -> Option<(usize, usize)> {
|
|
||||||
if let Ok(size) = imagesize::size(f.path())
|
|
||||||
.inspect_err(|err| tracing::error!("Failed to generate image size! {err:?}"))
|
|
||||||
{
|
|
||||||
Some((size.width, size.height))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn image_size_vec(&self, v: &[u8], mime: &str) -> Option<(usize, usize)> {
|
|
||||||
match mime {
|
|
||||||
"image/svg+xml" => {
|
|
||||||
let tree =
|
|
||||||
report_internal_error!(usvg::Tree::from_data(v, &Default::default())).ok()?;
|
|
||||||
|
|
||||||
let size = tree.size();
|
|
||||||
Some((size.width() as usize, size.height() as usize))
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
if let Ok(size) = imagesize::blob_size(v)
|
|
||||||
.inspect_err(|err| tracing::error!("Failed to generate image size! {err:?}"))
|
|
||||||
{
|
|
||||||
Some((size.width, size.height))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn decode_image<R: Read + BufRead + Seek>(
|
|
||||||
&self,
|
|
||||||
reader: &mut R,
|
|
||||||
mime: &str,
|
|
||||||
) -> Result<DynamicImage, MediaError> {
|
|
||||||
match mime {
|
|
||||||
"image/jxl" => {
|
|
||||||
let decoder =
|
|
||||||
JxlDecoder::new(reader).map_err(|e| MediaError::from(anyhow::anyhow!(e)))?;
|
|
||||||
|
|
||||||
DynamicImage::from_decoder(decoder)
|
|
||||||
.map_err(|e| MediaError::from(anyhow::anyhow!(e)))
|
|
||||||
}
|
|
||||||
"image/svg+xml" => {
|
|
||||||
let mut buf = Vec::new();
|
|
||||||
reader
|
|
||||||
.read_to_end(&mut buf)
|
|
||||||
.map_err(|e| MediaError::from(anyhow::anyhow!(e)))?;
|
|
||||||
|
|
||||||
let tree: usvg::Tree = usvg::Tree::from_data(&buf, &Default::default())
|
|
||||||
.map_err(|e| MediaError::from(anyhow::anyhow!(e)))?;
|
|
||||||
|
|
||||||
let size = tree.size();
|
|
||||||
let mut pixmap = Pixmap::new(size.width() as u32, size.height() as u32)
|
|
||||||
.ok_or_else(|| MediaError::ImageProcessingFailed {
|
|
||||||
cause: "failed to create Pixmap, likely zero sized".to_string(),
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let mut pixmap_mut = pixmap.as_mut();
|
|
||||||
resvg::render(&tree, Default::default(), &mut pixmap_mut);
|
|
||||||
|
|
||||||
Ok(DynamicImage::ImageRgba8(
|
|
||||||
ImageBuffer::from_vec(
|
|
||||||
size.width() as u32,
|
|
||||||
size.height() as u32,
|
|
||||||
pixmap.data().to_vec(),
|
|
||||||
)
|
|
||||||
.ok_or_else(|| MediaError::ImageProcessingFailed {
|
|
||||||
cause: "buffer is not big enough".to_string(),
|
|
||||||
})?,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
let image: ImageReader<&mut R> = image::ImageReader::new(reader)
|
|
||||||
.with_guessed_format()
|
|
||||||
.map_err(|e| MediaError::from(anyhow::anyhow!(e)))?;
|
|
||||||
|
|
||||||
let image: Result<DynamicImage, MediaError> = image
|
|
||||||
.decode()
|
|
||||||
.map_err(|e| MediaError::from(anyhow::anyhow!(e)));
|
|
||||||
|
|
||||||
image
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_valid_image<R: Read + BufRead + Seek>(&self, reader: &mut R, mime: &str) -> bool {
|
|
||||||
match mime {
|
|
||||||
"image/jxl" => jxl_oxide::JxlImage::builder()
|
|
||||||
.read(reader)
|
|
||||||
.inspect_err(|err| tracing::error!("Failed to read JXL! {err:?}"))
|
|
||||||
.is_ok(),
|
|
||||||
_ => !matches!(
|
|
||||||
image::ImageReader::new(reader)
|
|
||||||
.with_guessed_format()
|
|
||||||
.inspect_err(|err| tracing::error!("Failed to read image! {err:?}"))
|
|
||||||
.map(|f| f.decode()),
|
|
||||||
Err(_) | Ok(Err(_))
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn create_thumbnail(&self, image: DynamicImage, tag: &str) -> Vec<u8> {
|
|
||||||
let [w, h] = self.config.preview.get(tag).unwrap();
|
|
||||||
|
|
||||||
let image = image.thumbnail(image.width().min(*w as u32), image.height().min(*h as u32));
|
|
||||||
let image = match image {
|
|
||||||
DynamicImage::ImageRgb8(_) => image,
|
|
||||||
DynamicImage::ImageRgba8(_) => image,
|
|
||||||
_ => {
|
|
||||||
if image.has_alpha() {
|
|
||||||
image.to_rgba8().into()
|
|
||||||
} else {
|
|
||||||
image.to_rgb8().into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let encoder = webp::Encoder::from_image(&image).expect("Could not create encoder.");
|
|
||||||
if self.config.webp_quality != 100.0 {
|
|
||||||
encoder.encode(self.config.webp_quality).to_vec()
|
|
||||||
} else {
|
|
||||||
encoder.encode_lossless().to_vec()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn video_size(&self, f: &NamedTempFile) -> Option<(i64, i64)> {
|
|
||||||
if let Ok(data) = ffprobe::ffprobe(f.path())
|
|
||||||
.inspect_err(|err| tracing::error!("Failed to ffprobe file! {err:?}"))
|
|
||||||
{
|
|
||||||
for stream in data.streams {
|
|
||||||
if let (Some(w), Some(h)) = (stream.width, stream.height) {
|
|
||||||
return Some((w, h));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use std::io::Cursor;
|
|
||||||
|
|
||||||
use crate::{MediaImpl, MediaRepository};
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn asset_test_jpeg() {
|
|
||||||
let media = MediaImpl::from_config().await;
|
|
||||||
let buf = include_bytes!("../../tests/assets/test.jpeg");
|
|
||||||
assert_eq!(media.image_size_vec(buf, "image/jpeg"), Some((655, 582)));
|
|
||||||
|
|
||||||
let mut reader = Cursor::new(buf);
|
|
||||||
let image = media.decode_image(&mut reader, "image/jpeg").unwrap();
|
|
||||||
media.create_thumbnail(image, "attachments");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn asset_test_jpeg_extra_bytes() {
|
|
||||||
let media = MediaImpl::from_config().await;
|
|
||||||
let buf = [
|
|
||||||
&include_bytes!("../../tests/assets/test.jpeg")[..],
|
|
||||||
&[0u8; 16],
|
|
||||||
]
|
|
||||||
.concat();
|
|
||||||
assert_eq!(media.image_size_vec(&buf, "image/jpeg"), Some((655, 582)));
|
|
||||||
|
|
||||||
let mut reader = Cursor::new(buf);
|
|
||||||
let image = media.decode_image(&mut reader, "image/jpeg").unwrap();
|
|
||||||
media.create_thumbnail(image, "emojis");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn asset_test_png() {
|
|
||||||
let media = MediaImpl::from_config().await;
|
|
||||||
let buf = include_bytes!("../../tests/assets/test.png");
|
|
||||||
assert_eq!(media.image_size_vec(buf, "image/png"), Some((900, 900)));
|
|
||||||
|
|
||||||
let mut reader = Cursor::new(buf);
|
|
||||||
let image = media.decode_image(&mut reader, "image/png").unwrap();
|
|
||||||
media.create_thumbnail(image, "emojis");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn asset_test_png_extra_bytes() {
|
|
||||||
let media = MediaImpl::from_config().await;
|
|
||||||
let buf = [
|
|
||||||
&include_bytes!("../../tests/assets/test.png")[..],
|
|
||||||
&[0u8; 16],
|
|
||||||
]
|
|
||||||
.concat();
|
|
||||||
assert_eq!(media.image_size_vec(&buf, "image/png"), Some((900, 900)));
|
|
||||||
|
|
||||||
let mut reader = Cursor::new(buf);
|
|
||||||
let image = media.decode_image(&mut reader, "image/png").unwrap();
|
|
||||||
media.create_thumbnail(image, "emojis");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn asset_test_floating_point_png() {
|
|
||||||
let media = MediaImpl::from_config().await;
|
|
||||||
let buf = include_bytes!("../../tests/assets/test-float.png");
|
|
||||||
assert_eq!(media.image_size_vec(buf, "image/png"), Some((300, 300)));
|
|
||||||
|
|
||||||
let mut reader = Cursor::new(buf);
|
|
||||||
let image = media.decode_image(&mut reader, "image/png").unwrap();
|
|
||||||
media.create_thumbnail(image, "avatars");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn asset_test_corrupted_png() {
|
|
||||||
let media = MediaImpl::from_config().await;
|
|
||||||
let buf = include_bytes!("../../tests/assets/corrupted.png");
|
|
||||||
assert_eq!(media.image_size_vec(buf, "image/png"), Some((900, 900)));
|
|
||||||
|
|
||||||
let mut reader = Cursor::new(buf);
|
|
||||||
media.decode_image(&mut reader, "image/png").unwrap_err();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn asset_test_animated_png() {
|
|
||||||
let media = MediaImpl::from_config().await;
|
|
||||||
let buf = include_bytes!("../../tests/assets/anim-icos.apng");
|
|
||||||
assert_eq!(media.image_size_vec(buf, "image/png"), Some((128, 128)));
|
|
||||||
|
|
||||||
let mut reader = Cursor::new(buf);
|
|
||||||
let image = media.decode_image(&mut reader, "image/png").unwrap();
|
|
||||||
media.create_thumbnail(image, "attachments");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn asset_test_jxl() {
|
|
||||||
let media = MediaImpl::from_config().await;
|
|
||||||
let buf = include_bytes!("../../tests/assets/dice.jxl");
|
|
||||||
assert_eq!(media.image_size_vec(buf, "image/jxl"), Some((800, 600)));
|
|
||||||
|
|
||||||
let mut reader = Cursor::new(buf);
|
|
||||||
let image = media.decode_image(&mut reader, "image/jxl").unwrap();
|
|
||||||
media.create_thumbnail(image, "attachments");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn asset_test_animated_jxl() {
|
|
||||||
let media = MediaImpl::from_config().await;
|
|
||||||
let buf = include_bytes!("../../tests/assets/anim-icos.jxl");
|
|
||||||
assert_eq!(media.image_size_vec(buf, "image/jxl"), Some((128, 128)));
|
|
||||||
|
|
||||||
let mut reader = Cursor::new(buf);
|
|
||||||
let image = media.decode_image(&mut reader, "image/jxl").unwrap();
|
|
||||||
media.create_thumbnail(image, "attachments");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn asset_test_webp() {
|
|
||||||
let media = MediaImpl::from_config().await;
|
|
||||||
let buf = include_bytes!("../../tests/assets/dice.webp");
|
|
||||||
assert_eq!(media.image_size_vec(buf, "image/webp"), Some((800, 600)));
|
|
||||||
|
|
||||||
let mut reader = Cursor::new(buf);
|
|
||||||
let image = media.decode_image(&mut reader, "image/webp").unwrap();
|
|
||||||
media.create_thumbnail(image, "attachments");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn asset_test_animated_webp() {
|
|
||||||
let media = MediaImpl::from_config().await;
|
|
||||||
let buf = include_bytes!("../../tests/assets/anim-icos.webp");
|
|
||||||
assert_eq!(media.image_size_vec(buf, "image/webp"), Some((128, 128)));
|
|
||||||
|
|
||||||
let mut reader = Cursor::new(buf);
|
|
||||||
let image = media.decode_image(&mut reader, "image/webp").unwrap();
|
|
||||||
media.create_thumbnail(image, "attachments");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn asset_test_animated_gif() {
|
|
||||||
let media = MediaImpl::from_config().await;
|
|
||||||
let buf = include_bytes!("../../tests/assets/anim-icos.gif");
|
|
||||||
assert_eq!(media.image_size_vec(buf, "image/gif"), Some((128, 128)));
|
|
||||||
|
|
||||||
let mut reader = Cursor::new(buf);
|
|
||||||
let image = media.decode_image(&mut reader, "image/gif").unwrap();
|
|
||||||
media.create_thumbnail(image, "attachments");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
mod encryption_impl;
|
|
||||||
mod media_impl;
|
|
||||||
mod s3_impl;
|
|
||||||
|
|
||||||
pub use encryption_impl::EncryptionKey;
|
|
||||||
pub use media_impl::MediaImpl;
|
|
||||||
pub use s3_impl::S3Storage;
|
|
||||||
@@ -1,118 +0,0 @@
|
|||||||
use std::io::Write;
|
|
||||||
|
|
||||||
use anyhow::Context;
|
|
||||||
use aws_sdk_s3::{
|
|
||||||
config::{Credentials, Region},
|
|
||||||
Client, Config,
|
|
||||||
};
|
|
||||||
use revolt_config::FilesS3;
|
|
||||||
|
|
||||||
use crate::{EncryptionRepository, FileStorageRepository};
|
|
||||||
|
|
||||||
pub struct S3Storage<ER: EncryptionRepository> {
|
|
||||||
client: Client,
|
|
||||||
encryption: ER,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<ER: EncryptionRepository> S3Storage<ER> {
|
|
||||||
pub async fn from_config(encryption: ER) -> S3Storage<ER> {
|
|
||||||
S3Storage::new(encryption, revolt_config::config().await.files.s3)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new(encryption: ER, s3_config: FilesS3) -> S3Storage<ER> {
|
|
||||||
let provider_name = "my-creds";
|
|
||||||
let creds = Credentials::new(
|
|
||||||
s3_config.access_key_id,
|
|
||||||
s3_config.secret_access_key,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
provider_name,
|
|
||||||
);
|
|
||||||
|
|
||||||
let config = Config::builder()
|
|
||||||
.region(Region::new(s3_config.region))
|
|
||||||
.endpoint_url(s3_config.endpoint)
|
|
||||||
.force_path_style(s3_config.path_style_buckets)
|
|
||||||
.credentials_provider(creds)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
S3Storage {
|
|
||||||
client: Client::from_conf(config),
|
|
||||||
encryption,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl<ER: EncryptionRepository> FileStorageRepository for S3Storage<ER> {
|
|
||||||
async fn create_bucket(&self, bucket_id: &str) -> anyhow::Result<()> {
|
|
||||||
self.client
|
|
||||||
.create_bucket()
|
|
||||||
.bucket(bucket_id)
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
.with_context(|| format!("failed to create bucket {bucket_id}"))?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn fetch_and_decrypt_file(
|
|
||||||
&self,
|
|
||||||
bucket_id: &str,
|
|
||||||
path: &str,
|
|
||||||
iv: &str,
|
|
||||||
) -> anyhow::Result<Vec<u8>> {
|
|
||||||
let mut object = self
|
|
||||||
.client
|
|
||||||
.get_object()
|
|
||||||
.bucket(bucket_id)
|
|
||||||
.key(path)
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
.with_context(|| format!("failed to get object at {path} in {bucket_id}"))?;
|
|
||||||
|
|
||||||
let mut buf = vec![];
|
|
||||||
while let Some(bytes) = object.body.next().await {
|
|
||||||
let data = bytes?;
|
|
||||||
buf.write_all(&data)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
if iv.is_empty() {
|
|
||||||
Ok(buf)
|
|
||||||
} else {
|
|
||||||
self.encryption.decrypt_buffer(buf, iv)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn encrypt_and_upload_file(
|
|
||||||
&self,
|
|
||||||
bucket_id: &str,
|
|
||||||
path: &str,
|
|
||||||
buf: &[u8],
|
|
||||||
) -> anyhow::Result<String> {
|
|
||||||
let (buf, iv) = self.encryption.encrypt_buffer(buf)?;
|
|
||||||
|
|
||||||
self.client
|
|
||||||
.put_object()
|
|
||||||
.bucket(bucket_id)
|
|
||||||
.key(path)
|
|
||||||
.body(buf.into())
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
.with_context(|| format!("failed to put object at {path} in {bucket_id}"))?;
|
|
||||||
|
|
||||||
Ok(iv)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn delete_file(&self, bucket_id: &str, path: &str) -> anyhow::Result<()> {
|
|
||||||
self.client
|
|
||||||
.delete_object()
|
|
||||||
.bucket(bucket_id)
|
|
||||||
.key(path)
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
.with_context(|| format!("failed to delete object at {path} in {bucket_id}"))?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,182 +1,293 @@
|
|||||||
mod implementation;
|
use std::io::{BufRead, Read, Seek, Write};
|
||||||
mod repositories;
|
|
||||||
|
|
||||||
pub use implementation::*;
|
use aes_gcm::{
|
||||||
pub use repositories::*;
|
aead::{AeadCore, AeadMutInPlace, OsRng},
|
||||||
|
Aes256Gcm, Key, KeyInit, Nonce,
|
||||||
|
};
|
||||||
|
use image::{DynamicImage, ImageBuffer};
|
||||||
|
use revolt_config::{config, report_internal_error, FilesS3};
|
||||||
|
use revolt_result::{create_error, Result};
|
||||||
|
|
||||||
use std::io::{BufRead, Read, Seek};
|
use aws_sdk_s3::{
|
||||||
|
config::{Credentials, Region},
|
||||||
use image::DynamicImage;
|
Client, Config,
|
||||||
use revolt_config::{report_internal_error, Files, FilesLimit, FilesS3};
|
};
|
||||||
use revolt_result::Result;
|
|
||||||
|
|
||||||
|
use base64::prelude::*;
|
||||||
use tempfile::NamedTempFile;
|
use tempfile::NamedTempFile;
|
||||||
|
use tiny_skia::Pixmap;
|
||||||
|
|
||||||
|
/// Size of the authentication tag in the buffer
|
||||||
pub const AUTHENTICATION_TAG_SIZE_BYTES: usize = 16;
|
pub const AUTHENTICATION_TAG_SIZE_BYTES: usize = 16;
|
||||||
|
|
||||||
|
/// Create an S3 client
|
||||||
|
pub fn create_client(s3_config: FilesS3) -> Client {
|
||||||
|
let provider_name = "my-creds";
|
||||||
|
let creds = Credentials::new(
|
||||||
|
s3_config.access_key_id,
|
||||||
|
s3_config.secret_access_key,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
provider_name,
|
||||||
|
);
|
||||||
|
|
||||||
|
let config = Config::builder()
|
||||||
|
.region(Region::new(s3_config.region))
|
||||||
|
.endpoint_url(s3_config.endpoint)
|
||||||
|
.force_path_style(s3_config.path_style_buckets)
|
||||||
|
.credentials_provider(creds)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Client::from_conf(config)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create an AES-256-GCM cipher
|
||||||
|
pub fn create_cipher(key: &str) -> Aes256Gcm {
|
||||||
|
let key = &BASE64_STANDARD.decode(key).expect("valid base64 string")[..];
|
||||||
|
let key: &Key<Aes256Gcm> = key.into();
|
||||||
|
Aes256Gcm::new(key)
|
||||||
|
}
|
||||||
|
|
||||||
/// Fetch a file from S3 (and decrypt it)
|
/// Fetch a file from S3 (and decrypt it)
|
||||||
pub async fn fetch_from_s3(bucket_id: &str, path: &str, iv: &str) -> Result<Vec<u8>> {
|
pub async fn fetch_from_s3(bucket_id: &str, path: &str, nonce: &str) -> Result<Vec<u8>> {
|
||||||
let encryption = implementation::EncryptionKey::from_config().await;
|
let config = config().await;
|
||||||
let storage = implementation::S3Storage::from_config(encryption).await;
|
let client = create_client(config.files.s3);
|
||||||
report_internal_error!(storage.fetch_and_decrypt_file(bucket_id, path, iv).await)
|
|
||||||
|
// Send a request for the file
|
||||||
|
let mut obj =
|
||||||
|
report_internal_error!(client.get_object().bucket(bucket_id).key(path).send().await)?;
|
||||||
|
|
||||||
|
// Read the file from remote
|
||||||
|
let mut buf = vec![];
|
||||||
|
while let Some(bytes) = obj.body.next().await {
|
||||||
|
let data = report_internal_error!(bytes)?;
|
||||||
|
report_internal_error!(buf.write_all(&data))?;
|
||||||
|
// is there a more efficient way to do this?
|
||||||
|
// we just want the Vec<u8>
|
||||||
|
}
|
||||||
|
|
||||||
|
// File is not encrypted
|
||||||
|
if nonce.is_empty() {
|
||||||
|
return Ok(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recover nonce as bytes
|
||||||
|
let nonce = &BASE64_STANDARD.decode(nonce).unwrap()[..];
|
||||||
|
let nonce: &Nonce<typenum::consts::U12> = nonce.into();
|
||||||
|
|
||||||
|
// Decrypt the file
|
||||||
|
create_cipher(&config.files.encryption_key)
|
||||||
|
.decrypt_in_place(nonce, b"", &mut buf)
|
||||||
|
.map_err(|_| create_error!(InternalError))?;
|
||||||
|
|
||||||
|
// Remove the authentication tag bytes that were added during encryption
|
||||||
|
buf.truncate(buf.len() - AUTHENTICATION_TAG_SIZE_BYTES);
|
||||||
|
|
||||||
|
Ok(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Encrypt and upload a file to S3 (returning its nonce/IV)
|
/// Encrypt and upload a file to S3 (returning its nonce/IV)
|
||||||
pub async fn upload_to_s3(bucket_id: &str, path: &str, buf: &[u8]) -> Result<String> {
|
pub async fn upload_to_s3(bucket_id: &str, path: &str, buf: &[u8]) -> Result<String> {
|
||||||
let encryption = implementation::EncryptionKey::from_config().await;
|
let config = config().await;
|
||||||
let storage = implementation::S3Storage::from_config(encryption).await;
|
let client = create_client(config.files.s3);
|
||||||
report_internal_error!(storage.encrypt_and_upload_file(bucket_id, path, buf).await)
|
|
||||||
|
// Generate a nonce
|
||||||
|
let nonce = Aes256Gcm::generate_nonce(&mut OsRng);
|
||||||
|
|
||||||
|
// Extend the buffer for in-place encryption
|
||||||
|
let mut buf = [buf, &[0; AUTHENTICATION_TAG_SIZE_BYTES]].concat();
|
||||||
|
|
||||||
|
// Encrypt the file in place
|
||||||
|
create_cipher(&config.files.encryption_key)
|
||||||
|
.encrypt_in_place(&nonce, b"", &mut buf)
|
||||||
|
.map_err(|_| create_error!(InternalError))?;
|
||||||
|
|
||||||
|
// Upload the file to remote
|
||||||
|
report_internal_error!(
|
||||||
|
client
|
||||||
|
.put_object()
|
||||||
|
.bucket(bucket_id)
|
||||||
|
.key(path)
|
||||||
|
.body(buf.into())
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
)?;
|
||||||
|
|
||||||
|
Ok(BASE64_STANDARD.encode(nonce))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Delete a file from S3 by path
|
/// Delete a file from S3 by path
|
||||||
pub async fn delete_from_s3(bucket_id: &str, path: &str) -> Result<()> {
|
pub async fn delete_from_s3(bucket_id: &str, path: &str) -> Result<()> {
|
||||||
let encryption = implementation::EncryptionKey::from_config().await;
|
let config = config().await;
|
||||||
let storage = implementation::S3Storage::from_config(encryption).await;
|
let client = create_client(config.files.s3);
|
||||||
report_internal_error!(storage.delete_file(bucket_id, path).await)
|
|
||||||
|
report_internal_error!(
|
||||||
|
client
|
||||||
|
.delete_object()
|
||||||
|
.bucket(bucket_id)
|
||||||
|
.key(path)
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determine size of image at temp file
|
/// Determine size of image at temp file
|
||||||
pub fn image_size(f: &NamedTempFile) -> Option<(usize, usize)> {
|
pub fn image_size(f: &NamedTempFile) -> Option<(usize, usize)> {
|
||||||
let media = MediaImpl::new(Files {
|
if let Ok(size) = imagesize::size(f.path())
|
||||||
blocked_mime_types: Default::default(),
|
.inspect_err(|err| tracing::error!("Failed to generate image size! {err:?}"))
|
||||||
clamd_host: Default::default(),
|
{
|
||||||
encryption_key: Default::default(),
|
Some((size.width, size.height))
|
||||||
limit: FilesLimit {
|
} else {
|
||||||
max_mega_pixels: 0,
|
None
|
||||||
max_pixel_side: 0,
|
}
|
||||||
min_file_size: 0,
|
|
||||||
min_resolution: [0, 0],
|
|
||||||
},
|
|
||||||
preview: Default::default(),
|
|
||||||
s3: FilesS3 {
|
|
||||||
access_key_id: Default::default(),
|
|
||||||
default_bucket: Default::default(),
|
|
||||||
endpoint: Default::default(),
|
|
||||||
path_style_buckets: Default::default(),
|
|
||||||
region: Default::default(),
|
|
||||||
secret_access_key: Default::default(),
|
|
||||||
},
|
|
||||||
scan_mime_types: Default::default(),
|
|
||||||
webp_quality: Default::default(),
|
|
||||||
});
|
|
||||||
|
|
||||||
media.image_size(f)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determine size of image with buffer
|
/// Determine size of image with buffer
|
||||||
pub fn image_size_vec(v: &[u8], mime: &str) -> Option<(usize, usize)> {
|
pub fn image_size_vec(v: &[u8], mime: &str) -> Option<(usize, usize)> {
|
||||||
let media = MediaImpl::new(Files {
|
match mime {
|
||||||
blocked_mime_types: Default::default(),
|
"image/svg+xml" => {
|
||||||
clamd_host: Default::default(),
|
let tree =
|
||||||
encryption_key: Default::default(),
|
report_internal_error!(usvg::Tree::from_data(v, &Default::default())).ok()?;
|
||||||
limit: FilesLimit {
|
|
||||||
max_mega_pixels: 0,
|
|
||||||
max_pixel_side: 0,
|
|
||||||
min_file_size: 0,
|
|
||||||
min_resolution: [0, 0],
|
|
||||||
},
|
|
||||||
preview: Default::default(),
|
|
||||||
s3: FilesS3 {
|
|
||||||
access_key_id: Default::default(),
|
|
||||||
default_bucket: Default::default(),
|
|
||||||
endpoint: Default::default(),
|
|
||||||
path_style_buckets: Default::default(),
|
|
||||||
region: Default::default(),
|
|
||||||
secret_access_key: Default::default(),
|
|
||||||
},
|
|
||||||
scan_mime_types: Default::default(),
|
|
||||||
webp_quality: Default::default(),
|
|
||||||
});
|
|
||||||
|
|
||||||
media.image_size_vec(v, mime)
|
let size = tree.size();
|
||||||
|
Some((size.width() as usize, size.height() as usize))
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
if let Ok(size) = imagesize::blob_size(v)
|
||||||
|
.inspect_err(|err| tracing::error!("Failed to generate image size! {err:?}"))
|
||||||
|
{
|
||||||
|
Some((size.width, size.height))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determine size of video at temp file
|
/// Determine size of video at temp file
|
||||||
pub fn video_size(f: &NamedTempFile) -> Option<(i64, i64)> {
|
pub fn video_size(f: &NamedTempFile) -> Option<(i64, i64)> {
|
||||||
let media = MediaImpl::new(Files {
|
if let Ok(data) = ffprobe::ffprobe(f.path())
|
||||||
blocked_mime_types: Default::default(),
|
.inspect_err(|err| tracing::error!("Failed to ffprobe file! {err:?}"))
|
||||||
clamd_host: Default::default(),
|
{
|
||||||
encryption_key: Default::default(),
|
// Use first valid stream
|
||||||
limit: FilesLimit {
|
for stream in data.streams {
|
||||||
max_mega_pixels: 0,
|
if let (Some(w), Some(h)) = (stream.width, stream.height) {
|
||||||
max_pixel_side: 0,
|
return Some((w, h));
|
||||||
min_file_size: 0,
|
}
|
||||||
min_resolution: [0, 0],
|
}
|
||||||
},
|
|
||||||
preview: Default::default(),
|
|
||||||
s3: FilesS3 {
|
|
||||||
access_key_id: Default::default(),
|
|
||||||
default_bucket: Default::default(),
|
|
||||||
endpoint: Default::default(),
|
|
||||||
path_style_buckets: Default::default(),
|
|
||||||
region: Default::default(),
|
|
||||||
secret_access_key: Default::default(),
|
|
||||||
},
|
|
||||||
scan_mime_types: Default::default(),
|
|
||||||
webp_quality: Default::default(),
|
|
||||||
});
|
|
||||||
|
|
||||||
media.video_size(f)
|
None
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Decode image from reader
|
/// Decode image from reader
|
||||||
pub fn decode_image<R: Read + BufRead + Seek>(reader: &mut R, mime: &str) -> Result<DynamicImage> {
|
pub fn decode_image<R: Read + BufRead + Seek>(reader: &mut R, mime: &str) -> Result<DynamicImage> {
|
||||||
let media = MediaImpl::new(Files {
|
match mime {
|
||||||
blocked_mime_types: Default::default(),
|
// Read image using jxl-oxide crate
|
||||||
clamd_host: Default::default(),
|
"image/jxl" => {
|
||||||
encryption_key: Default::default(),
|
let jxl_image = report_internal_error!(jxl_oxide::JxlImage::builder().read(reader))?;
|
||||||
limit: FilesLimit {
|
if let Ok(frame) = jxl_image.render_frame(0) {
|
||||||
max_mega_pixels: 0,
|
match frame.color_channels().len() {
|
||||||
max_pixel_side: 0,
|
3 => Ok(DynamicImage::ImageRgb8(
|
||||||
min_file_size: 0,
|
DynamicImage::ImageRgb32F(
|
||||||
min_resolution: [0, 0],
|
ImageBuffer::from_vec(
|
||||||
},
|
jxl_image.width(),
|
||||||
preview: Default::default(),
|
jxl_image.height(),
|
||||||
s3: FilesS3 {
|
frame.image().buf().to_vec(),
|
||||||
access_key_id: Default::default(),
|
)
|
||||||
default_bucket: Default::default(),
|
.ok_or_else(|| create_error!(ImageProcessingFailed))?,
|
||||||
endpoint: Default::default(),
|
)
|
||||||
path_style_buckets: Default::default(),
|
.to_rgb8(),
|
||||||
region: Default::default(),
|
)),
|
||||||
secret_access_key: Default::default(),
|
4 => Ok(DynamicImage::ImageRgba8(
|
||||||
},
|
DynamicImage::ImageRgba32F(
|
||||||
scan_mime_types: Default::default(),
|
ImageBuffer::from_vec(
|
||||||
webp_quality: Default::default(),
|
jxl_image.width(),
|
||||||
});
|
jxl_image.height(),
|
||||||
|
frame.image().buf().to_vec(),
|
||||||
|
)
|
||||||
|
.ok_or_else(|| create_error!(ImageProcessingFailed))?,
|
||||||
|
)
|
||||||
|
.to_rgba8(),
|
||||||
|
)),
|
||||||
|
_ => Err(create_error!(ImageProcessingFailed)),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err(create_error!(ImageProcessingFailed))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Read image using resvg
|
||||||
|
"image/svg+xml" => {
|
||||||
|
// usvg doesn't support Read trait so copy to buffer
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
report_internal_error!(reader.read_to_end(&mut buf))?;
|
||||||
|
|
||||||
report_internal_error!(media.decode_image(reader, mime))
|
let tree = report_internal_error!(usvg::Tree::from_data(&buf, &Default::default()))?;
|
||||||
|
let size = tree.size();
|
||||||
|
let mut pixmap = Pixmap::new(size.width() as u32, size.height() as u32)
|
||||||
|
.ok_or_else(|| create_error!(ImageProcessingFailed))?;
|
||||||
|
|
||||||
|
let mut pixmap_mut = pixmap.as_mut();
|
||||||
|
resvg::render(&tree, Default::default(), &mut pixmap_mut);
|
||||||
|
|
||||||
|
Ok(DynamicImage::ImageRgba8(
|
||||||
|
ImageBuffer::from_vec(
|
||||||
|
size.width() as u32,
|
||||||
|
size.height() as u32,
|
||||||
|
pixmap.data().to_vec(),
|
||||||
|
)
|
||||||
|
.ok_or_else(|| create_error!(ImageProcessingFailed))?,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
// Check if we can read using image-rs crate
|
||||||
|
_ => report_internal_error!(report_internal_error!(
|
||||||
|
image::ImageReader::new(reader).with_guessed_format()
|
||||||
|
)?
|
||||||
|
.decode()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check whether given reader has a valid image
|
/// Check whether given reader has a valid image
|
||||||
pub fn is_valid_image<R: Read + BufRead + Seek>(reader: &mut R, mime: &str) -> bool {
|
pub fn is_valid_image<R: Read + BufRead + Seek>(reader: &mut R, mime: &str) -> bool {
|
||||||
let media = MediaImpl::new(Files {
|
match mime {
|
||||||
blocked_mime_types: Default::default(),
|
// Check if we can read using jxl-oxide crate
|
||||||
clamd_host: Default::default(),
|
"image/jxl" => jxl_oxide::JxlImage::builder()
|
||||||
encryption_key: Default::default(),
|
.read(reader)
|
||||||
limit: FilesLimit {
|
.inspect_err(|err| tracing::error!("Failed to read JXL! {err:?}"))
|
||||||
max_mega_pixels: 0,
|
.is_ok(),
|
||||||
max_pixel_side: 0,
|
// Check if we can read using image-rs crate
|
||||||
min_file_size: 0,
|
_ => !matches!(
|
||||||
min_resolution: [0, 0],
|
image::ImageReader::new(reader)
|
||||||
},
|
.with_guessed_format()
|
||||||
preview: Default::default(),
|
.inspect_err(|err| tracing::error!("Failed to read image! {err:?}"))
|
||||||
s3: FilesS3 {
|
.map(|f| f.decode()),
|
||||||
access_key_id: Default::default(),
|
Err(_) | Ok(Err(_))
|
||||||
default_bucket: Default::default(),
|
),
|
||||||
endpoint: Default::default(),
|
}
|
||||||
path_style_buckets: Default::default(),
|
|
||||||
region: Default::default(),
|
|
||||||
secret_access_key: Default::default(),
|
|
||||||
},
|
|
||||||
scan_mime_types: Default::default(),
|
|
||||||
webp_quality: Default::default(),
|
|
||||||
});
|
|
||||||
|
|
||||||
media.is_valid_image(reader, mime)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create thumbnail from given image
|
/// Create thumbnail from given image
|
||||||
pub async fn create_thumbnail(image: DynamicImage, tag: &str) -> Vec<u8> {
|
pub async fn create_thumbnail(image: DynamicImage, tag: &str) -> Vec<u8> {
|
||||||
let media = MediaImpl::from_config().await;
|
// Load configuration
|
||||||
media.create_thumbnail(image, tag)
|
let config = config().await;
|
||||||
|
let [w, h] = config.files.preview.get(tag).unwrap();
|
||||||
|
|
||||||
|
// Create thumbnail
|
||||||
|
//.resize(width as u32, height as u32, image::imageops::FilterType::Gaussian)
|
||||||
|
// resize is about 2.5x slower,
|
||||||
|
// thumbnail doesn't have terrible quality
|
||||||
|
// so we use thumbnail
|
||||||
|
let image = image.thumbnail(image.width().min(*w as u32), image.height().min(*h as u32));
|
||||||
|
|
||||||
|
// Encode it into WEBP
|
||||||
|
let encoder = webp::Encoder::from_image(&image).expect("Could not create encoder.");
|
||||||
|
if config.files.webp_quality != 100.0 {
|
||||||
|
encoder.encode(config.files.webp_quality).to_vec()
|
||||||
|
} else {
|
||||||
|
encoder.encode_lossless().to_vec()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
use anyhow::Result;
|
|
||||||
|
|
||||||
pub trait EncryptionRepository: Send + Sync + 'static {
|
|
||||||
fn decrypt_buffer(&self, buf: Vec<u8>, iv: &str) -> anyhow::Result<Vec<u8>>;
|
|
||||||
fn encrypt_buffer(&self, buf: &[u8]) -> Result<(Vec<u8>, String)>;
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
use anyhow::Result;
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
pub trait FileStorageRepository: Send + Sync + 'static {
|
|
||||||
async fn create_bucket(&self, bucket_id: &str) -> anyhow::Result<()>;
|
|
||||||
|
|
||||||
async fn fetch_and_decrypt_file(
|
|
||||||
&self,
|
|
||||||
bucket_id: &str,
|
|
||||||
path: &str,
|
|
||||||
iv: &str,
|
|
||||||
) -> Result<Vec<u8>>;
|
|
||||||
|
|
||||||
async fn encrypt_and_upload_file(
|
|
||||||
&self,
|
|
||||||
bucket_id: &str,
|
|
||||||
path: &str,
|
|
||||||
buf: &[u8],
|
|
||||||
) -> Result<String>;
|
|
||||||
|
|
||||||
async fn delete_file(&self, bucket_id: &str, path: &str) -> Result<()>;
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
use anyhow::Result;
|
|
||||||
use image::DynamicImage;
|
|
||||||
use std::io::{BufRead, Read, Seek};
|
|
||||||
use tempfile::NamedTempFile;
|
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
pub trait MediaRepository: Send + Sync + 'static {
|
|
||||||
fn image_size(&self, f: &NamedTempFile) -> Option<(usize, usize)>;
|
|
||||||
fn image_size_vec(&self, v: &[u8], mime: &str) -> Option<(usize, usize)>;
|
|
||||||
|
|
||||||
fn decode_image<R: Read + BufRead + Seek>(
|
|
||||||
&self,
|
|
||||||
reader: &mut R,
|
|
||||||
mime: &str,
|
|
||||||
) -> Result<DynamicImage, MediaError>;
|
|
||||||
|
|
||||||
fn is_valid_image<R: Read + BufRead + Seek>(&self, reader: &mut R, mime: &str) -> bool;
|
|
||||||
|
|
||||||
fn create_thumbnail(&self, image: DynamicImage, tag: &str) -> Vec<u8>;
|
|
||||||
|
|
||||||
fn video_size(&self, f: &NamedTempFile) -> Option<(i64, i64)>;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
|
||||||
pub enum MediaError {
|
|
||||||
#[error("image processing failed because {cause}")]
|
|
||||||
ImageProcessingFailed { cause: String },
|
|
||||||
#[error(transparent)]
|
|
||||||
Unknown(#[from] anyhow::Error),
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
mod encryption_repository;
|
|
||||||
mod file_storage_repository;
|
|
||||||
mod media_repository;
|
|
||||||
|
|
||||||
pub use encryption_repository::EncryptionRepository;
|
|
||||||
pub use file_storage_repository::FileStorageRepository;
|
|
||||||
pub use media_repository::{MediaError, MediaRepository};
|
|
||||||
|
Before Width: | Height: | Size: 969 KiB |
|
Before Width: | Height: | Size: 375 KiB |
|
Before Width: | Height: | Size: 382 KiB |
|
Before Width: | Height: | Size: 4.4 KiB |
|
Before Width: | Height: | Size: 64 KiB |
|
Before Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 4.4 KiB |
@@ -1,31 +0,0 @@
|
|||||||
use std::io::Cursor;
|
|
||||||
|
|
||||||
use revolt_files::{EncryptionKey, FileStorageRepository, MediaImpl, MediaRepository, S3Storage};
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn test_image_roundtrip_png() {
|
|
||||||
let media = MediaImpl::from_config().await;
|
|
||||||
let encryption = EncryptionKey::from_config().await;
|
|
||||||
let s3 = S3Storage::from_config(encryption).await;
|
|
||||||
|
|
||||||
let buf = include_bytes!("./assets/test.png");
|
|
||||||
let bucket_id = uuid::Uuid::new_v4().to_string();
|
|
||||||
|
|
||||||
s3.create_bucket(&bucket_id).await.unwrap();
|
|
||||||
|
|
||||||
let mut reader = Cursor::new(buf);
|
|
||||||
media.decode_image(&mut reader, "image/png").unwrap();
|
|
||||||
|
|
||||||
let iv = s3
|
|
||||||
.encrypt_and_upload_file(&bucket_id, "/my-file", buf)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let buf = s3
|
|
||||||
.fetch_and_decrypt_file(&bucket_id, "/my-file", &iv)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let mut reader = Cursor::new(buf);
|
|
||||||
media.decode_image(&mut reader, "image/png").unwrap();
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
use revolt_files::{EncryptionKey, FileStorageRepository, S3Storage};
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn test_upload_and_download() {
|
|
||||||
let encryption = EncryptionKey::from_config().await;
|
|
||||||
let s3 = S3Storage::from_config(encryption).await;
|
|
||||||
|
|
||||||
let buf = [67];
|
|
||||||
let bucket_id = uuid::Uuid::new_v4().to_string();
|
|
||||||
|
|
||||||
s3.create_bucket(&bucket_id).await.unwrap();
|
|
||||||
|
|
||||||
let iv = s3
|
|
||||||
.encrypt_and_upload_file(&bucket_id, "/my-file", &buf)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let buf = s3
|
|
||||||
.fetch_and_decrypt_file(&bucket_id, "/my-file", &iv)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(buf.len(), 1);
|
|
||||||
assert_eq!(buf[0], 67);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn test_upload_and_delete() {
|
|
||||||
let encryption = EncryptionKey::from_config().await;
|
|
||||||
let s3 = S3Storage::from_config(encryption).await;
|
|
||||||
|
|
||||||
let buf = [67];
|
|
||||||
let bucket_id = uuid::Uuid::new_v4().to_string();
|
|
||||||
|
|
||||||
s3.create_bucket(&bucket_id).await.unwrap();
|
|
||||||
|
|
||||||
s3.encrypt_and_upload_file(&bucket_id, "/my-file", &buf)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
s3.delete_file(&bucket_id, "/my-file").await.unwrap();
|
|
||||||
}
|
|
||||||
@@ -1,32 +1,31 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-models"
|
name = "revolt-models"
|
||||||
version = "0.10.3"
|
version = "0.8.9"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
authors = ["Paul Makles <me@insrt.uk>"]
|
authors = ["Paul Makles <me@insrt.uk>"]
|
||||||
description = "Revolt Backend: API Models"
|
description = "Revolt Backend: API Models"
|
||||||
repository = "https://github.com/stoatchat/stoatchat"
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
serde = ["dep:serde", "revolt-permissions/serde", "indexmap/serde"]
|
serde = ["dep:serde", "revolt-permissions/serde", "indexmap/serde"]
|
||||||
schemas = ["dep:schemars", "revolt-permissions/schemas"]
|
|
||||||
utoipa = ["dep:utoipa"]
|
|
||||||
validator = ["dep:validator"]
|
validator = ["dep:validator"]
|
||||||
rocket = ["dep:rocket"]
|
rocket = ["dep:rocket"]
|
||||||
partials = ["dep:revolt_optional_struct", "serde", "schemas", "utoipa"]
|
partials = ["dep:revolt_optional_struct", "serde", "utoipa"]
|
||||||
|
|
||||||
default = ["serde", "partials", "rocket"]
|
default = ["serde", "partials", "rocket"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# Core
|
# Core
|
||||||
revolt-config = { version = "0.10.3", path = "../config" }
|
revolt-config = { version = "0.8.9", path = "../config" }
|
||||||
revolt-permissions = { version = "0.10.3", path = "../permissions" }
|
revolt-permissions = { version = "0.8.9", path = "../permissions", features = [
|
||||||
|
"utoipa",
|
||||||
|
] }
|
||||||
|
|
||||||
# Utility
|
# Utility
|
||||||
regex = "1.11"
|
regex = "1.11"
|
||||||
indexmap = "1.9.3"
|
indexmap = "2.12.0"
|
||||||
once_cell = "1.17.1"
|
once_cell = "1.17.1"
|
||||||
num_enum = "0.6.1"
|
num_enum = "0.6.1"
|
||||||
|
|
||||||
@@ -36,11 +35,10 @@ rocket = { optional = true, version = "0.5.0-rc.2", default-features = false }
|
|||||||
# Serialisation
|
# Serialisation
|
||||||
revolt_optional_struct = { version = "0.2.0", optional = true }
|
revolt_optional_struct = { version = "0.2.0", optional = true }
|
||||||
serde = { version = "1", features = ["derive"], optional = true }
|
serde = { version = "1", features = ["derive"], optional = true }
|
||||||
iso8601-timestamp = { version = "0.2.11", features = ["schema", "bson"] }
|
iso8601-timestamp = { version = "0.4.0", features = ["utoipa", "bson"] }
|
||||||
|
|
||||||
# Spec Generation
|
# Spec Generation
|
||||||
schemars = { version = "0.8.8", optional = true, features = ["indexmap1"] }
|
utoipa = { version = "5.4.0", features = ["indexmap"], optional = true }
|
||||||
utoipa = { version = "4.2.3", optional = true }
|
|
||||||
|
|
||||||
# Validation
|
# Validation
|
||||||
validator = { version = "0.16.0", optional = true, features = ["derive"] }
|
validator = { version = "0.16.0", optional = true, features = ["derive"] }
|
||||||
@@ -2,10 +2,6 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
|
|
||||||
#[cfg(feature = "schemas")]
|
|
||||||
#[macro_use]
|
|
||||||
extern crate schemars;
|
|
||||||
|
|
||||||
#[cfg(feature = "utoipa")]
|
#[cfg(feature = "utoipa")]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate utoipa;
|
extern crate utoipa;
|
||||||
@@ -21,9 +17,8 @@ macro_rules! auto_derived {
|
|||||||
( $( $item:item )+ ) => {
|
( $( $item:item )+ ) => {
|
||||||
$(
|
$(
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
#[cfg_attr(feature = "schemas", derive(JsonSchema))]
|
|
||||||
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
|
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
$item
|
$item
|
||||||
)+
|
)+
|
||||||
};
|
};
|
||||||
@@ -32,19 +27,8 @@ macro_rules! auto_derived {
|
|||||||
#[cfg(feature = "partials")]
|
#[cfg(feature = "partials")]
|
||||||
macro_rules! auto_derived_partial {
|
macro_rules! auto_derived_partial {
|
||||||
( $item:item, $name:expr ) => {
|
( $item:item, $name:expr ) => {
|
||||||
#[derive(
|
#[derive(OptionalStruct, Debug, Clone, PartialEq, Serialize, Deserialize, ToSchema)]
|
||||||
OptionalStruct, Debug, Clone, Eq, PartialEq, Serialize, Deserialize, JsonSchema,
|
#[optional_derive(Debug, Clone, PartialEq, Serialize, Deserialize, ToSchema, Default)]
|
||||||
)]
|
|
||||||
#[optional_derive(
|
|
||||||
Debug,
|
|
||||||
Clone,
|
|
||||||
Eq,
|
|
||||||
PartialEq,
|
|
||||||
Serialize,
|
|
||||||
Deserialize,
|
|
||||||
JsonSchema,
|
|
||||||
Default
|
|
||||||
)]
|
|
||||||
#[optional_name = $name]
|
#[optional_name = $name]
|
||||||
#[opt_skip_serializing_none]
|
#[opt_skip_serializing_none]
|
||||||
#[opt_some_priority]
|
#[opt_some_priority]
|
||||||
@@ -55,7 +39,7 @@ macro_rules! auto_derived_partial {
|
|||||||
#[cfg(not(feature = "partials"))]
|
#[cfg(not(feature = "partials"))]
|
||||||
macro_rules! auto_derived_partial {
|
macro_rules! auto_derived_partial {
|
||||||
( $item:item, $name:expr ) => {
|
( $item:item, $name:expr ) => {
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ToSchema)]
|
||||||
$item
|
$item
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,10 +86,10 @@ auto_derived!(
|
|||||||
/// Information for the webhook
|
/// Information for the webhook
|
||||||
#[cfg_attr(feature = "validator", derive(Validate))]
|
#[cfg_attr(feature = "validator", derive(Validate))]
|
||||||
pub struct CreateWebhookBody {
|
pub struct CreateWebhookBody {
|
||||||
#[validate(length(min = 1, max = 32))]
|
#[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
|
||||||
#[validate(length(min = 1, max = 128))]
|
#[cfg_attr(feature = "validator", validate(length(min = 1, max = 128)))]
|
||||||
pub avatar: Option<String>,
|
pub avatar: Option<String>,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -271,6 +271,7 @@ auto_derived!(
|
|||||||
|
|
||||||
/// Options when deleting a channel
|
/// Options when deleting a channel
|
||||||
#[cfg_attr(feature = "rocket", derive(FromForm))]
|
#[cfg_attr(feature = "rocket", derive(FromForm))]
|
||||||
|
#[cfg_attr(feature = "utoipa", derive(IntoParams))]
|
||||||
pub struct OptionsChannelDelete {
|
pub struct OptionsChannelDelete {
|
||||||
/// Whether to not send a leave message
|
/// Whether to not send a leave message
|
||||||
pub leave_silently: Option<bool>,
|
pub leave_silently: Option<bool>,
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
auto_derived!(
|
||||||
|
/// hCaptcha Configuration
|
||||||
|
pub struct CaptchaFeature {
|
||||||
|
/// Whether captcha is enabled
|
||||||
|
pub enabled: bool,
|
||||||
|
/// Client key used for solving captcha
|
||||||
|
pub key: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Generic Service Configuration
|
||||||
|
pub struct Feature {
|
||||||
|
/// Whether the service is enabled
|
||||||
|
pub enabled: bool,
|
||||||
|
/// URL pointing to the service
|
||||||
|
pub url: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// # Information about a livekit node
|
||||||
|
pub struct VoiceNode {
|
||||||
|
pub name: String,
|
||||||
|
pub lat: f64,
|
||||||
|
pub lon: f64,
|
||||||
|
pub public_url: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// # Voice Server Configuration
|
||||||
|
pub struct VoiceFeature {
|
||||||
|
/// Whether voice is enabled
|
||||||
|
pub enabled: bool,
|
||||||
|
/// All livekit nodes
|
||||||
|
pub nodes: Vec<VoiceNode>,
|
||||||
|
}
|
||||||
|
/// Feature Configuration
|
||||||
|
pub struct RevoltFeatures {
|
||||||
|
/// hCaptcha configuration
|
||||||
|
pub captcha: CaptchaFeature,
|
||||||
|
/// Whether email verification is enabled
|
||||||
|
pub email: bool,
|
||||||
|
/// Whether this server is invite only
|
||||||
|
pub invite_only: bool,
|
||||||
|
/// File server service configuration
|
||||||
|
pub autumn: Feature,
|
||||||
|
/// Proxy service configuration
|
||||||
|
pub january: Feature,
|
||||||
|
/// Voice server configuration
|
||||||
|
pub livekit: VoiceFeature,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Build Information
|
||||||
|
pub struct BuildInformation {
|
||||||
|
/// Commit Hash
|
||||||
|
pub commit_sha: String,
|
||||||
|
/// Commit Timestamp
|
||||||
|
pub commit_timestamp: String,
|
||||||
|
/// Git Semver
|
||||||
|
pub semver: String,
|
||||||
|
/// Git Origin URL
|
||||||
|
pub origin_url: String,
|
||||||
|
/// Build Timestamp
|
||||||
|
pub timestamp: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Server Configuration
|
||||||
|
pub struct RevoltConfig {
|
||||||
|
/// Revolt API Version
|
||||||
|
pub revolt: String,
|
||||||
|
/// Features enabled on this Revolt node
|
||||||
|
pub features: RevoltFeatures,
|
||||||
|
/// WebSocket URL
|
||||||
|
pub ws: String,
|
||||||
|
/// URL pointing to the client serving this node
|
||||||
|
pub app: String,
|
||||||
|
/// Web Push VAPID public key
|
||||||
|
pub vapid: String,
|
||||||
|
/// Build information
|
||||||
|
pub build: BuildInformation,
|
||||||
|
}
|
||||||
|
);
|
||||||
@@ -46,7 +46,7 @@ auto_derived!(
|
|||||||
#[cfg_attr(feature = "validator", derive(Validate))]
|
#[cfg_attr(feature = "validator", derive(Validate))]
|
||||||
pub struct DataCreateEmoji {
|
pub struct DataCreateEmoji {
|
||||||
/// Server name
|
/// Server name
|
||||||
#[validate(length(min = 1, max = 32), regex = "RE_EMOJI")]
|
#[cfg_attr(feature = "validator", validate(length(min = 1, max = 32), regex = "RE_EMOJI"))]
|
||||||
pub name: String,
|
pub name: String,
|
||||||
/// Parent information
|
/// Parent information
|
||||||
pub parent: EmojiParent,
|
pub parent: EmojiParent,
|
||||||
|
|||||||
@@ -141,17 +141,17 @@ auto_derived!(
|
|||||||
pub struct Masquerade {
|
pub struct Masquerade {
|
||||||
/// Replace the display name shown on this message
|
/// Replace the display name shown on this message
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
#[validate(length(min = 1, max = 32))]
|
#[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
/// Replace the avatar shown on this message (URL to image file)
|
/// Replace the avatar shown on this message (URL to image file)
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
#[validate(length(min = 1, max = 256))]
|
#[cfg_attr(feature = "validator", validate(length(min = 1, max = 256)))]
|
||||||
pub avatar: Option<String>,
|
pub avatar: Option<String>,
|
||||||
/// Replace the display role colour shown on this message
|
/// Replace the display role colour shown on this message
|
||||||
///
|
///
|
||||||
/// Must have `ManageRole` permission to use
|
/// Must have `ManageRole` permission to use
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
#[validate(length(min = 1, max = 128), regex = "RE_COLOUR")]
|
#[cfg_attr(feature = "validator", validate(length(min = 1, max = 128), regex = "RE_COLOUR"))]
|
||||||
pub colour: Option<String>,
|
pub colour: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,6 +281,7 @@ auto_derived!(
|
|||||||
/// Options for querying messages
|
/// Options for querying messages
|
||||||
#[cfg_attr(feature = "validator", derive(Validate))]
|
#[cfg_attr(feature = "validator", derive(Validate))]
|
||||||
#[cfg_attr(feature = "rocket", derive(FromForm))]
|
#[cfg_attr(feature = "rocket", derive(FromForm))]
|
||||||
|
#[cfg_attr(feature = "utoipa", derive(IntoParams))]
|
||||||
pub struct OptionsQueryMessages {
|
pub struct OptionsQueryMessages {
|
||||||
/// Maximum number of messages to fetch
|
/// Maximum number of messages to fetch
|
||||||
///
|
///
|
||||||
@@ -353,12 +354,13 @@ auto_derived!(
|
|||||||
)]
|
)]
|
||||||
pub struct OptionsBulkDelete {
|
pub struct OptionsBulkDelete {
|
||||||
/// Message IDs
|
/// Message IDs
|
||||||
#[validate(length(min = 1, max = 100))]
|
#[cfg_attr(feature = "validator", validate(length(min = 1, max = 100)))]
|
||||||
pub ids: Vec<String>,
|
pub ids: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Options for removing reaction
|
/// Options for removing reaction
|
||||||
#[cfg_attr(feature = "rocket", derive(FromForm))]
|
#[cfg_attr(feature = "rocket", derive(FromForm))]
|
||||||
|
#[cfg_attr(feature = "utoipa", derive(IntoParams))]
|
||||||
pub struct OptionsUnreact {
|
pub struct OptionsUnreact {
|
||||||
/// Remove a specific user's reaction
|
/// Remove a specific user's reaction
|
||||||
pub user_id: Option<String>,
|
pub user_id: Option<String>,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ mod channel_invites;
|
|||||||
mod channel_unreads;
|
mod channel_unreads;
|
||||||
mod channel_webhooks;
|
mod channel_webhooks;
|
||||||
mod channels;
|
mod channels;
|
||||||
|
mod config;
|
||||||
mod embeds;
|
mod embeds;
|
||||||
mod emojis;
|
mod emojis;
|
||||||
mod files;
|
mod files;
|
||||||
@@ -20,6 +21,7 @@ pub use channel_invites::*;
|
|||||||
pub use channel_unreads::*;
|
pub use channel_unreads::*;
|
||||||
pub use channel_webhooks::*;
|
pub use channel_webhooks::*;
|
||||||
pub use channels::*;
|
pub use channels::*;
|
||||||
|
pub use config::*;
|
||||||
pub use embeds::*;
|
pub use embeds::*;
|
||||||
pub use emojis::*;
|
pub use emojis::*;
|
||||||
pub use files::*;
|
pub use files::*;
|
||||||
|
|||||||
@@ -95,7 +95,6 @@ auto_derived!(
|
|||||||
CanReceive,
|
CanReceive,
|
||||||
CanPublish,
|
CanPublish,
|
||||||
JoinedAt,
|
JoinedAt,
|
||||||
VoiceChannel,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Member removal intention
|
/// Member removal intention
|
||||||
@@ -117,6 +116,7 @@ auto_derived!(
|
|||||||
|
|
||||||
/// Options for fetching all members
|
/// Options for fetching all members
|
||||||
#[cfg_attr(feature = "rocket", derive(FromForm))]
|
#[cfg_attr(feature = "rocket", derive(FromForm))]
|
||||||
|
#[cfg_attr(feature = "utoipa", derive(IntoParams))]
|
||||||
pub struct OptionsFetchAllMembers {
|
pub struct OptionsFetchAllMembers {
|
||||||
/// Whether to exclude offline users
|
/// Whether to exclude offline users
|
||||||
pub exclude_offline: Option<bool>,
|
pub exclude_offline: Option<bool>,
|
||||||
|
|||||||
@@ -85,9 +85,6 @@ auto_derived_partial!(
|
|||||||
auto_derived_partial!(
|
auto_derived_partial!(
|
||||||
/// Role
|
/// Role
|
||||||
pub struct Role {
|
pub struct Role {
|
||||||
/// Unique Id
|
|
||||||
#[cfg_attr(feature = "serde", serde(rename = "_id"))]
|
|
||||||
pub id: String,
|
|
||||||
/// Role name
|
/// Role name
|
||||||
pub name: String,
|
pub name: String,
|
||||||
/// Permissions available to this role
|
/// Permissions available to this role
|
||||||
@@ -184,7 +181,6 @@ auto_derived!(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Response after creating new role
|
/// Response after creating new role
|
||||||
// TODO: remove this in favor of just Role
|
|
||||||
pub struct NewRoleResponse {
|
pub struct NewRoleResponse {
|
||||||
/// Id of the role
|
/// Id of the role
|
||||||
pub id: String,
|
pub id: String,
|
||||||
@@ -202,6 +198,7 @@ auto_derived!(
|
|||||||
|
|
||||||
/// Options when fetching server
|
/// Options when fetching server
|
||||||
#[cfg_attr(feature = "rocket", derive(FromForm))]
|
#[cfg_attr(feature = "rocket", derive(FromForm))]
|
||||||
|
#[cfg_attr(feature = "utoipa", derive(IntoParams))]
|
||||||
pub struct OptionsFetchServer {
|
pub struct OptionsFetchServer {
|
||||||
/// Whether to include channels
|
/// Whether to include channels
|
||||||
pub include_channels: Option<bool>,
|
pub include_channels: Option<bool>,
|
||||||
@@ -288,6 +285,7 @@ auto_derived!(
|
|||||||
|
|
||||||
/// Options when leaving a server
|
/// Options when leaving a server
|
||||||
#[cfg_attr(feature = "rocket", derive(FromForm))]
|
#[cfg_attr(feature = "rocket", derive(FromForm))]
|
||||||
|
#[cfg_attr(feature = "utoipa", derive(IntoParams))]
|
||||||
pub struct OptionsServerDelete {
|
pub struct OptionsServerDelete {
|
||||||
/// Whether to not send a leave message
|
/// Whether to not send a leave message
|
||||||
pub leave_silently: Option<bool>,
|
pub leave_silently: Option<bool>,
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ auto_derived!(
|
|||||||
|
|
||||||
/// Additional options for inserting settings
|
/// Additional options for inserting settings
|
||||||
#[cfg_attr(feature = "rocket", derive(FromForm))]
|
#[cfg_attr(feature = "rocket", derive(FromForm))]
|
||||||
|
#[cfg_attr(feature = "utoipa", derive(IntoParams))]
|
||||||
pub struct OptionsSetSettings {
|
pub struct OptionsSetSettings {
|
||||||
/// Timestamp of settings change.
|
/// Timestamp of settings change.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ auto_derived!(
|
|||||||
#[cfg_attr(feature = "validator", derive(Validate))]
|
#[cfg_attr(feature = "validator", derive(Validate))]
|
||||||
pub struct UserStatus {
|
pub struct UserStatus {
|
||||||
/// Custom status text
|
/// Custom status text
|
||||||
#[validate(length(min = 0, max = 128))]
|
#[cfg_attr(feature = "validator", validate(length(min = 0, max = 128)))]
|
||||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||||
pub text: Option<String>,
|
pub text: Option<String>,
|
||||||
/// Current presence option
|
/// Current presence option
|
||||||
@@ -155,7 +155,7 @@ auto_derived!(
|
|||||||
#[cfg_attr(feature = "validator", derive(Validate))]
|
#[cfg_attr(feature = "validator", derive(Validate))]
|
||||||
pub struct UserProfile {
|
pub struct UserProfile {
|
||||||
/// Text content on user's profile
|
/// Text content on user's profile
|
||||||
#[validate(length(min = 0, max = 2000))]
|
#[cfg_attr(feature = "validator", validate(length(min = 0, max = 2000)))]
|
||||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||||
pub content: Option<String>,
|
pub content: Option<String>,
|
||||||
/// Background visible on user's profile
|
/// Background visible on user's profile
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-parser"
|
name = "revolt-parser"
|
||||||
version = "0.10.3"
|
version = "0.8.9"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
authors = ["Zomatree <me@zomatree.live>", "Paul Makles <me@insrt.uk>"]
|
authors = ["Zomatree <me@zomatree.live>", "Paul Makles <me@insrt.uk>"]
|
||||||
description = "Revolt Backend: Message Parser"
|
description = "Revolt Backend: Message Parser"
|
||||||
repository = "https://github.com/stoatchat/stoatchat"
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
logos = { version = "0.15" }
|
logos = { version = "0.15" }
|
||||||
@@ -1,28 +1,25 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-permissions"
|
name = "revolt-permissions"
|
||||||
version = "0.10.3"
|
version = "0.8.9"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
authors = ["Paul Makles <me@insrt.uk>"]
|
authors = ["Paul Makles <me@insrt.uk>"]
|
||||||
description = "Revolt Backend: Permission Logic"
|
description = "Revolt Backend: Permission Logic"
|
||||||
repository = "https://github.com/stoatchat/stoatchat"
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
bson = ["dep:bson"]
|
bson = ["dep:bson"]
|
||||||
serde = ["dep:serde"]
|
serde = ["dep:serde"]
|
||||||
schemas = ["dep:schemars"]
|
|
||||||
try-from-primitive = ["dep:num_enum"]
|
try-from-primitive = ["dep:num_enum"]
|
||||||
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
# Async
|
# Async
|
||||||
async-std = { version = "1.8.0", features = ["attributes"] }
|
async-std = { version = "1.8.0", features = ["attributes"] }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# Core
|
# Core
|
||||||
revolt-result = { version = "0.10.3", path = "../result" }
|
revolt-result = { version = "0.8.9", path = "../result" }
|
||||||
|
|
||||||
# Utility
|
# Utility
|
||||||
auto_ops = "0.3.0"
|
auto_ops = "0.3.0"
|
||||||
@@ -37,4 +34,4 @@ serde = { version = "1", features = ["derive"], optional = true }
|
|||||||
bson = { version = "2.1.0", optional = true }
|
bson = { version = "2.1.0", optional = true }
|
||||||
|
|
||||||
# Spec Generation
|
# Spec Generation
|
||||||
schemars = { version = "0.8.8", optional = true }
|
utoipa = { version = "5.4.0", optional = true }
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
#[cfg(feature = "schemas")]
|
#[cfg(feature = "utoipa")]
|
||||||
use schemars::JsonSchema;
|
use utoipa::ToSchema;
|
||||||
|
|
||||||
/// Representation of a single permission override
|
/// Representation of a single permission override
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
#[derive(Debug, Clone, Eq, PartialEq, Default)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
#[cfg_attr(feature = "schemas", derive(JsonSchema))]
|
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
|
||||||
pub struct Override {
|
pub struct Override {
|
||||||
/// Allow bit flags
|
/// Allow bit flags
|
||||||
pub allow: u64,
|
pub allow: u64,
|
||||||
@@ -15,7 +15,7 @@ pub struct Override {
|
|||||||
/// Data permissions Field - contains both allow and deny
|
/// Data permissions Field - contains both allow and deny
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
#[cfg_attr(feature = "schemas", derive(JsonSchema))]
|
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
|
||||||
pub struct DataPermissionsField {
|
pub struct DataPermissionsField {
|
||||||
pub permissions: Override,
|
pub permissions: Override,
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@ pub struct DataPermissionsField {
|
|||||||
/// Data permissions Value - contains allow
|
/// Data permissions Value - contains allow
|
||||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
#[cfg_attr(feature = "schemas", derive(JsonSchema))]
|
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
|
||||||
pub struct DataPermissionsValue {
|
pub struct DataPermissionsValue {
|
||||||
pub permissions: u64,
|
pub permissions: u64,
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ pub struct DataPermissionsValue {
|
|||||||
/// Data permissions Poly - can contain either Value or Field
|
/// Data permissions Poly - can contain either Value or Field
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
#[cfg_attr(feature = "schemas", derive(JsonSchema))]
|
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
|
||||||
#[cfg_attr(feature = "serde", serde(untagged))]
|
#[cfg_attr(feature = "serde", serde(untagged))]
|
||||||
pub enum DataPermissionPoly {
|
pub enum DataPermissionPoly {
|
||||||
Value {
|
Value {
|
||||||
@@ -48,7 +48,7 @@ pub enum DataPermissionPoly {
|
|||||||
/// as it appears on models and in the database
|
/// as it appears on models and in the database
|
||||||
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq)]
|
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
#[cfg_attr(feature = "schemas", derive(JsonSchema))]
|
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
|
||||||
pub struct OverrideField {
|
pub struct OverrideField {
|
||||||
/// Allow bit flags
|
/// Allow bit flags
|
||||||
pub a: i64,
|
pub a: i64,
|
||||||
|
|||||||