Compare commits

..
37 Commits
Author SHA1 Message Date
stoat-release[bot]andgithub-actions[bot] ba798490e2 chore(main): release 0.11.0 (#525)
Co-authored-by: stoat-release[bot] <245062572+stoat-release[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-10 20:48:36 +00:00
Paul Makles 5132270f2e feat: appeal to the almighty Spamhaus (#524) 2026-02-10 20:46:49 +00:00
Tanner Stirrat 4a0957b5ec Update repo readme header (#511)
Update README.md

Signed-off-by: Tanner Stirrat <tstirrat@gmail.com>
2026-02-09 20:51:56 +00:00
stoat-release[bot]andgithub-actions[bot] 1bfb2a7214 chore(main): release 0.10.3 (#509)
* chore(main): release 0.10.3

* chore: update Cargo.lock

Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

---------

Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: stoat-release[bot] <245062572+stoat-release[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-09 20:51:30 +00:00
Paul Makles 84483cee7a fix: update Revolt -> Stoat in email titles/desc. (#508) 2026-02-07 16:24:53 +00:00
stoat-release[bot]andgithub-actions[bot] 4bfd79c42c chore(main): release 0.10.2 (#506)
Co-authored-by: stoat-release[bot] <245062572+stoat-release[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-25 22:43:56 +00:00
Paul Makles 413aa04dca fix: thumbnailification requires rgb8/rgba8 (#505) 2026-01-25 22:36:31 +00:00
stoat-release[bot]andgithub-actions[bot] 5d3e65e076 chore(main): release 0.10.1 (#504)
Co-authored-by: stoat-release[bot] <245062572+stoat-release[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-25 21:27:20 +00:00
Paul Makles 98da8a28a0 fix: use Rust 1.92.0 for Docker build (#503) 2026-01-25 21:03:34 +00:00
stoat-release[bot]andgithub-actions[bot] 84b57dee57 chore(main): release 0.10.0 (#502)
Co-authored-by: stoat-release[bot] <245062572+stoat-release[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-25 20:58:16 +00:00
stoat-tofu[bot] 1fef495d5e chore: modify .github/workflows/git-town.yml 2026-01-25 20:50:19 +00:00
stoat-tofu[bot] 310d82819d chore: modify .github/workflows/git-town.yml 2026-01-25 20:44:37 +00:00
stoat-tofu[bot] 5611dab86f chore: modify .github/workflows/git-town.yml 2026-01-25 20:41:30 +00:00
Paul Makles 01ded209c6 feat: repository architecture for files crate w. added tests (#498) 2026-01-25 20:32:22 +00:00
Angelo Kontaxis a1a21252d0 fix: expose ratelimit headers via cors (#496) 2026-01-25 19:43:06 +00:00
Angelo Kontaxis 0dc5442498 feat: allow kicking members from voice channels (#495) 2026-01-25 19:42:48 +00:00
Paul Makles 9fb55f74dc chore: add git-town to mise tools (#497) 2026-01-24 23:46:10 +00:00
stoat-tofu[bot] 24cfc33907 chore: modify .github/workflows/git-town.yml 2026-01-24 23:44:00 +00:00
stoat-tofu[bot] ce2a4eccbd chore: modify .github/workflows/git-town.yml 2026-01-24 23:36:32 +00:00
stoat-tofu[bot] ff68679bad chore: modify .github/workflows/git-town.yml 2026-01-24 23:35:02 +00:00
stoat-tofu[bot] 9bdb7d7feb chore: modify .github/workflows/git-town.yml 2026-01-24 02:20:09 +00:00
stoat-tofu[bot] 3c51fad74d chore: modify .github/workflows/git-town.yml 2026-01-24 02:18:41 +00:00
stoat-tofu[bot] 4344419cdb chore: modify .github/workflows/git-town.yml 2026-01-24 02:10:51 +00:00
stoat-tofu[bot] 65efea020d chore: modify .github/workflows/git-town.yml 2026-01-24 02:01:05 +00:00
stoat-tofu[bot] b9360b4d88 chore: modify .github/workflows/git-town.yml 2026-01-24 01:54:01 +00:00
stoat-tofu[bot] 12c187a386 chore: modify .github/workflows/git-town.yml 2026-01-24 01:11:53 +00:00
Paul Makles 2846f09c45 chore: switch to mise for tooling & update crates for publishing (#494) 2026-01-21 23:41:58 +00:00
50835f08c8 chore(main): release 0.9.4 (#491)
Co-authored-by: stoat-release[bot] <245062572+stoat-release[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: izzy <me@insrt.uk>
2026-01-10 17:55:04 +00:00
stoat-tofu[bot] c413fbcb58 chore: modify .github/workflows/release-webhook.yml 2026-01-10 16:33:17 +00:00
Paul Makles c674a9fd4e fix: persist credentials for git repo (#492) 2026-01-10 16:25:29 +00:00
Paul Makles b2da2a8587 fix: checkout repo. before bumping lock (#490) 2026-01-10 16:22:42 +00:00
stoat-release[bot] d0ea88f1f8 chore(main): release 0.9.3 (#488)
Co-authored-by: stoat-release[bot] <245062572+stoat-release[bot]@users.noreply.github.com>
2026-01-10 16:04:28 +00:00
Paul Makles 92b466a5f0 chore: switch back to docker hub since we cache it now (#489) 2026-01-10 14:49:51 +00:00
Paul Makles aeeafebefc fix: pipeline fixes (#487) 2026-01-10 14:46:57 +00:00
stoat-tofu[bot] bf0048a052 chore: modify .github/workflows/release-webhook.yml 2026-01-10 13:19:24 +00:00
stoat-release[bot] b4ba02218f chore(main): release 0.9.2 (#486)
Co-authored-by: stoat-release[bot] <245062572+stoat-release[bot]@users.noreply.github.com>
2026-01-10 13:07:06 +00:00
Paul Makles d13609c372 fix: disable publish for services (#485) 2026-01-10 13:06:33 +00:00
91 changed files with 1904 additions and 748 deletions
+6 -12
View File
@@ -14,16 +14,10 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0
- uses: pnpm/action-setup@v4
with:
package_json_file: ./docs/package.json
- uses: actions/setup-node@v4
with:
node-version: lts/*
cache: pnpm
cache-dependency-path: ./docs/pnpm-lock.yaml
- name: Install dependencies - name: Setup Mise
run: pnpm install uses: immich-app/devtools/actions/use-mise@cd24790a7f5f6439ac32cc94f5523cb2de8bfa8c # use-mise-action-v1.1.0
- name: Test build website with:
run: pnpm run build github-token: ${{ secrets.GITHUB_TOKEN }}
- run: mise docs:build
+6 -12
View File
@@ -16,19 +16,13 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0
- uses: pnpm/action-setup@v4
with:
package_json_file: ./docs/package.json
- uses: actions/setup-node@v4
with:
node-version: lts/*
cache: pnpm
cache-dependency-path: ./docs/pnpm-lock.yaml
- name: Install dependencies - name: Setup Mise
run: pnpm install uses: immich-app/devtools/actions/use-mise@cd24790a7f5f6439ac32cc94f5523cb2de8bfa8c # use-mise-action-v1.1.0
- name: Build website with:
run: pnpm run build github-token: ${{ secrets.GITHUB_TOKEN }}
- run: mise docs:build
- name: Upload Build Artifact - name: Upload Build Artifact
uses: actions/upload-pages-artifact@v3 uses: actions/upload-pages-artifact@v3
+19
View File
@@ -0,0 +1,19 @@
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
+24
View File
@@ -0,0 +1,24 @@
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
+25 -23
View File
@@ -33,28 +33,30 @@ jobs:
token: ${{ steps.app-token.outputs.token }} token: ${{ steps.app-token.outputs.token }}
config-file: release-please-config.json config-file: release-please-config.json
publish-please: - name: Install latest stable
name: Publish Please uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # v1
needs: release-please
if: needs.release-please.outputs.release_created == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: app-token
uses: actions/create-github-app-token@v2
with: with:
app-id: ${{ secrets.GH_STOAT_RELEASE_APP_ID }} toolchain: stable
private-key: ${{ secrets.GH_STOAT_RELEASE_APP_PRIVATE_KEY }}
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
- name: Send release notification webhook 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: | run: |
RELEASE_URL="https://github.com/revoltchat/backend/releases/tag/${{ needs.release-please.outputs.tag_name }}" PR_NUMBER=$(echo '${{ steps.rp.outputs.prs }}' | jq -r '.[0].number')
curl -X POST "${{ secrets.STOAT_WEBHOOK_UPDATES_URL }}" \ gh pr checkout "$PR_NUMBER"
-H "Content-Type: application/json" \
-d "{\"content\": \"$RELEASE_URL\"}" cargo update -w
- name: Publish crates if git diff --quiet Cargo.lock; then
uses: katyo/publish-crates@v2 echo "No changes to Cargo.lock"
with: else
registry-token: ${{ secrets.CRATES_IO_PUBLISH_TOKEN }} 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
+19
View File
@@ -0,0 +1,19 @@
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\"}"
+13 -21
View File
@@ -18,49 +18,41 @@ jobs:
runs-on: arc-runner-set runs-on: arc-runner-set
steps: steps:
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
persist-credentials: false
# Using our own runners for now: # Using our own runners for now:
# - name: Free up disk space # - name: Free up disk space
# run: | # run: |
# sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc # sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc
- name: Install latest stable - name: Setup Mise
uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # v1 uses: immich-app/devtools/actions/use-mise@cd24790a7f5f6439ac32cc94f5523cb2de8bfa8c # use-mise-action-v1.1.0
with: with:
toolchain: stable github-token: ${{ secrets.GITHUB_TOKEN }}
components: rustfmt, clippy
- name: Install cargo-nextest
uses: taiki-e/install-action@a58ae9526b2c3acee9ad8e1926b950b7863305d4 # 2.65.16
with:
tool: cargo-nextest@0.9.119
- name: Run cargo build - run: mise build
run: cargo build - run: mise docker:start
- name: Run services in background - name: Reference Test
run: |
docker compose -f compose.yml up -d
- name: Run cargo test
env: env:
TEST_DB: REFERENCE TEST_DB: REFERENCE
run: | run: |
cargo nextest run mise test
- name: Run cargo test (with MongoDB) - name: MongoDB Test
env: env:
TEST_DB: MONGODB TEST_DB: MONGODB
MONGODB: mongodb://localhost MONGODB: mongodb://localhost
run: | run: |
cargo nextest run mise test
- 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: |
cargo build --bin revolt-delta && (cargo run --bin revolt-delta &) mise build --bin revolt-delta && (mise service:api &)
- 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'
+19
View File
@@ -0,0 +1,19 @@
[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:*" }]
+5
View File
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
#MISE description="Build project"
set -e
cargo build "$@"
+5
View File
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
#MISE description="Check project with clippy"
set -e
cargo clippy
+5
View File
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
#MISE description="Start Docker containers"
set -e
docker compose up -d
+5
View File
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
#MISE description="Stop Docker containers"
set -e
docker compose down
+7
View File
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
#MISE description="Start the Stoat Developers website"
#MISE depends=["docs:install"]
#MISE dir="{{config_root}}/docs"
set -e
pnpm build
+7
View File
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
#MISE description="Build the Stoat Developers website"
#MISE depends=["docs:install"]
#MISE dir="{{config_root}}/docs"
set -e
pnpm build
+6
View File
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
#MISE description="Install dependencies for docs site"
#MISE dir="{{config_root}}/docs"
set -e
pnpm i --frozen-lockfile
+5
View File
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
#MISE description="Publish project"
set -e
cargo publish "$@"
+5
View File
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
#MISE description="Run API server"
set -e
cargo run --bin revolt-delta
+5
View File
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
#MISE description="Run cron daemon"
set -e
cargo run --bin revolt-crond
+5
View File
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
#MISE description="Run events server"
set -e
cargo run --bin revolt-bonfire
+5
View File
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
#MISE description="Run file server"
set -e
cargo run --bin revolt-autumn
+5
View File
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
#MISE description="Run GIF proxy server"
set -e
cargo run --bin revolt-gifbox
+5
View File
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
#MISE description="Run proxy server"
set -e
cargo run --bin revolt-january
+5
View File
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
#MISE description="Run push daemon"
set -e
cargo run --bin revolt-pushd
+8
View File
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
#MISE description="Test project"
set -e
: "${TEST_DB:=REFERENCE}"
export TEST_DB
cargo nextest run
+1 -1
View File
@@ -1,3 +1,3 @@
{ {
".": "0.9.1" ".": "0.11.0"
} }
+63
View File
@@ -1,5 +1,68 @@
# Changelog # Changelog
## [0.11.0](https://github.com/stoatchat/stoatchat/compare/v0.10.3...v0.11.0) (2026-02-10)
### Features
* appeal to the almighty Spamhaus ([#524](https://github.com/stoatchat/stoatchat/issues/524)) ([5132270](https://github.com/stoatchat/stoatchat/commit/5132270f2edd6df25ce414daa42ed1b2aa6fa7a9))
## [0.10.3](https://github.com/stoatchat/stoatchat/compare/v0.10.2...v0.10.3) (2026-02-07)
### Bug Fixes
* update `Revolt` -&gt; `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) ## [0.9.1](https://github.com/stoatchat/stoatchat/compare/v0.9.0...v0.9.1) (2026-01-10)
Generated
+515 -237
View File
File diff suppressed because it is too large Load Diff
+32 -4
View File
@@ -14,9 +14,37 @@ redis23 = { package = "redis", version = "0.23.3", git = "https://github.com/rev
#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" }
# 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 -1
View File
@@ -1,5 +1,5 @@
# Build Stage # Build Stage
FROM --platform="${BUILDPLATFORM}" rust:1.86.0-slim-bookworm FROM --platform="${BUILDPLATFORM}" rust:1.92.0-slim-bookworm
USER 0:0 USER 0:0
WORKDIR /home/rust/src WORKDIR /home/rust/src
+1 -1
View File
@@ -1,5 +1,5 @@
# Build Stage # Build Stage
FROM rust:1.86.0-slim-bookworm FROM rust:1.92.0-slim-bookworm
USER 0:0 USER 0:0
WORKDIR /home/rust/src WORKDIR /home/rust/src
+4 -4
View File
@@ -1,6 +1,6 @@
<div align="center"> <div align="center">
<h1> <h1>
Revolt Backend Stoat Backend
[![Stars](https://img.shields.io/github/stars/revoltchat/backend?style=flat-square&logoColor=white)](https://github.com/revoltchat/backend/stargazers) [![Stars](https://img.shields.io/github/stars/revoltchat/backend?style=flat-square&logoColor=white)](https://github.com/revoltchat/backend/stargazers)
[![Forks](https://img.shields.io/github/forks/revoltchat/backend?style=flat-square&logoColor=white)](https://github.com/revoltchat/backend/network/members) [![Forks](https://img.shields.io/github/forks/revoltchat/backend?style=flat-square&logoColor=white)](https://github.com/revoltchat/backend/network/members)
@@ -43,13 +43,13 @@ Before contributing, make yourself familiar with [our contribution guidelines](h
Before getting started, you'll want to install: Before getting started, you'll want to install:
- Rust toolchain (rustup recommended) - mise
- 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!
> Just run `nix-shell` and continue. > Run `nix-shell` to activate mise.
As a heads-up, the development environment uses the following ports: As a heads-up, the development environment uses the following ports:
@@ -72,7 +72,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
cargo build mise 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.
+5 -1
View File
@@ -12,6 +12,10 @@ 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:
@@ -55,7 +59,7 @@ services:
# Mock SMTP server # Mock SMTP server
maildev: maildev:
image: soulteary/maildev image: maildev/maildev
ports: ports:
- "14025:25" - "14025:25"
- "14080:8080" - "14080:8080"
+3 -2
View File
@@ -1,8 +1,9 @@
[package] [package]
name = "revolt-bonfire" name = "revolt-bonfire"
version = "0.9.1" version = "0.11.0"
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
@@ -37,7 +38,7 @@ async-std = { version = "1.8.0", features = [
] } ] }
# core # core
authifier = { version = "1.0.15" } authifier = { version = "1.0.16" }
revolt-result = { path = "../core/result" } 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" }
+10 -4
View File
@@ -1,10 +1,11 @@
[package] [package]
name = "revolt-coalesced" name = "revolt-coalesced"
version = "0.9.1" version = "0.11.0"
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"]
@@ -15,8 +16,13 @@ default = ["tokio"]
[dependencies] [dependencies]
tokio = { version = "1.47.0", features = ["sync"], optional = true } tokio = { version = "1.47.0", features = ["sync"], optional = true }
indexmap = { version = "*", optional = true } indexmap = { version = "2.13.0", optional = true }
lru = { version = "*", optional = true } lru = { version = "0.16.3", optional = true }
[dev-dependencies] [dev-dependencies]
tokio = { version = "1.47.0", features = ["rt", "rt-multi-thread", "macros", "time"] } tokio = { version = "1.47.0", features = [
"rt",
"rt-multi-thread",
"macros",
"time",
] }
+3 -2
View File
@@ -1,10 +1,11 @@
[package] [package]
name = "revolt-config" name = "revolt-config"
version = "0.9.1" version = "0.11.0"
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
@@ -37,4 +38,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.9.1", path = "../result", optional = true } revolt-result = { version = "0.11.0", path = "../result", optional = true }
+13 -4
View File
@@ -1,4 +1,4 @@
use std::collections::HashMap; use std::{collections::HashMap, path::Path};
use cached::proc_macro::cached; use cached::proc_macro::cached;
use config::{Config, File, FileFormat}; use config::{Config, File, FileFormat};
@@ -94,10 +94,19 @@ static CONFIG_BUILDER: Lazy<RwLock<Config>> = Lazy::new(|| {
} }
} }
for path in CONFIG_SEARCH_PATHS { let cwd = std::env::current_dir().unwrap();
if std::path::Path::new(path).exists() { let mut cwd: Option<&Path> = Some(&cwd);
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()
+18 -11
View File
@@ -1,10 +1,11 @@
[package] [package]
name = "revolt-database" name = "revolt-database"
version = "0.9.1" version = "0.11.0"
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
@@ -15,8 +16,14 @@ 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", "schemars", "revolt_okapi", "revolt_rocket_okapi", "authifier/rocket_impl"] rocket-impl = [
axum-impl = ["axum"] "rocket",
"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"]
@@ -25,19 +32,19 @@ default = ["mongodb", "async-std-runtime", "tasks"]
[dependencies] [dependencies]
# Core # Core
revolt-config = { version = "0.9.1", path = "../config", features = [ revolt-config = { version = "0.11.0", path = "../config", features = [
"report-macros", "report-macros",
] } ] }
revolt-result = { version = "0.9.1", path = "../result" } revolt-result = { version = "0.11.0", path = "../result" }
revolt-models = { version = "0.9.1", path = "../models", features = [ revolt-models = { version = "0.11.0", path = "../models", features = [
"validator", "validator",
] } ] }
revolt-presence = { version = "0.9.1", path = "../presence" } revolt-presence = { version = "0.11.0", path = "../presence" }
revolt-permissions = { version = "0.9.1", path = "../permissions", features = [ revolt-permissions = { version = "0.11.0", path = "../permissions", features = [
"serde", "serde",
"bson", "bson",
] } ] }
revolt-parser = { version = "0.9.1", path = "../parser" } revolt-parser = { version = "0.11.0", path = "../parser" }
# Utility # Utility
log = "0.4" log = "0.4"
@@ -93,12 +100,12 @@ revolt_okapi = { version = "0.9.1", optional = true }
revolt_rocket_okapi = { version = "0.10.0", optional = true } revolt_rocket_okapi = { version = "0.10.0", optional = true }
# Authifier # Authifier
authifier = { version = "1.0.15" } authifier = { version = "1.0.16" }
# RabbitMQ # RabbitMQ
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 }
+12 -7
View File
@@ -10,6 +10,7 @@ use authifier::config::SMTPSettings;
use authifier::config::Shield; use authifier::config::Shield;
use authifier::config::Template; use authifier::config::Template;
use authifier::config::Templates; use authifier::config::Templates;
use authifier::config::EmailExpiryConfig;
use authifier::Authifier; use authifier::Authifier;
use rand::Rng; use rand::Rng;
use revolt_config::config; use revolt_config::config;
@@ -69,7 +70,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 +91,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,29 +138,33 @@ impl Database {
.api .api
.smtp .smtp
.reply_to .reply_to
.unwrap_or("support@revolt.chat".into()), .unwrap_or("support@stoat.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,
use_starttls: config.api.smtp.use_starttls, use_starttls: config.api.smtp.use_starttls,
}, },
expiry: Default::default(), expiry: EmailExpiryConfig {
expire_verification: 3600 * 24 * 7,
expire_password_reset: 3600 * 24,
expire_account_deletion: 3600 * 24,
},
templates: if config.production { templates: if config.production {
Templates { Templates {
verify: Template { verify: Template {
title: "Verify your Revolt account.".into(), title: "Verify your Stoat 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 Revolt password.".into(), title: "Reset your Stoat 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 Revolt account, reset your password." title: "You already have a Stoat 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),
@@ -72,6 +72,7 @@ auto_derived!(
CanReceive, CanReceive,
CanPublish, CanPublish,
JoinedAt, JoinedAt,
VoiceChannel,
} }
/// Member removal intention /// Member removal intention
@@ -224,13 +225,14 @@ 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,14 +330,15 @@ 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> {
Some(match self { match self {
FieldsMember::JoinedAt => "joined_at", FieldsMember::JoinedAt => Some("joined_at"),
FieldsMember::Avatar => "avatar", FieldsMember::Avatar => Some("avatar"),
FieldsMember::Nickname => "nickname", FieldsMember::Nickname => Some("nickname"),
FieldsMember::Roles => "roles", FieldsMember::Roles => Some("roles"),
FieldsMember::Timeout => "timeout", FieldsMember::Timeout => Some("timeout"),
FieldsMember::CanPublish => "can_publish", FieldsMember::CanPublish => Some("can_publish"),
FieldsMember::CanReceive => "can_receive", FieldsMember::CanReceive => Some("can_receive"),
}) FieldsMember::VoiceChannel => None,
}
} }
} }
@@ -691,6 +691,7 @@ 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,
} }
} }
} }
@@ -705,6 +706,7 @@ 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,
} }
} }
} }
@@ -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 Revolt or Revolt Platforms Ltd. This email has no association with Stoat 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 Revolt or Revolt Platforms Ltd. This email has no association with Stoat 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
+16 -6
View File
@@ -1,13 +1,20 @@
[package] [package]
name = "revolt-files" name = "revolt-files"
version = "0.9.1" version = "0.11.0"
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]
tracing = "0.1" anyhow = { workspace = true }
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"
@@ -20,14 +27,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.9.1", path = "../config", features = [ revolt-config = { version = "0.11.0", path = "../config", features = [
"report-macros", "report-macros",
] } ] }
revolt-result = { version = "0.9.1", path = "../result" } revolt-result = { version = "0.11.0", path = "../result" }
# image processing # image processing
jxl-oxide = "0.8.1" jxl-oxide = { workspace = true }
image = { version = "0.25.2" } image = { workspace = true }
# svg rendering # svg rendering
usvg = "0.44.0" usvg = "0.44.0"
@@ -36,3 +43,6 @@ tiny-skia = "0.11.4"
# encoding # encoding
webp = "0.3.0" webp = "0.3.0"
[dev-dependencies]
uuid = { workspace = true }
@@ -0,0 +1,75 @@
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);
}
}
@@ -0,0 +1,316 @@
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");
}
}
@@ -0,0 +1,7 @@
mod encryption_impl;
mod media_impl;
mod s3_impl;
pub use encryption_impl::EncryptionKey;
pub use media_impl::MediaImpl;
pub use s3_impl::S3Storage;
@@ -0,0 +1,118 @@
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(())
}
}
+138 -249
View File
@@ -1,293 +1,182 @@
use std::io::{BufRead, Read, Seek, Write}; mod implementation;
mod repositories;
use aes_gcm::{ pub use implementation::*;
aead::{AeadCore, AeadMutInPlace, OsRng}, pub use repositories::*;
Aes256Gcm, Key, KeyInit, Nonce,
};
use image::{DynamicImage, ImageBuffer};
use revolt_config::{config, report_internal_error, FilesS3};
use revolt_result::{create_error, Result};
use aws_sdk_s3::{ use std::io::{BufRead, Read, Seek};
config::{Credentials, Region},
Client, Config, use image::DynamicImage;
}; 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, nonce: &str) -> Result<Vec<u8>> { pub async fn fetch_from_s3(bucket_id: &str, path: &str, iv: &str) -> Result<Vec<u8>> {
let config = config().await; let encryption = implementation::EncryptionKey::from_config().await;
let client = create_client(config.files.s3); let storage = implementation::S3Storage::from_config(encryption).await;
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 config = config().await; let encryption = implementation::EncryptionKey::from_config().await;
let client = create_client(config.files.s3); let storage = implementation::S3Storage::from_config(encryption).await;
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 config = config().await; let encryption = implementation::EncryptionKey::from_config().await;
let client = create_client(config.files.s3); let storage = implementation::S3Storage::from_config(encryption).await;
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)> {
if let Ok(size) = imagesize::size(f.path()) let media = MediaImpl::new(Files {
.inspect_err(|err| tracing::error!("Failed to generate image size! {err:?}")) blocked_mime_types: Default::default(),
{ clamd_host: Default::default(),
Some((size.width, size.height)) encryption_key: Default::default(),
} else { limit: FilesLimit {
None 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(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)> {
match mime { let media = MediaImpl::new(Files {
"image/svg+xml" => { blocked_mime_types: Default::default(),
let tree = clamd_host: Default::default(),
report_internal_error!(usvg::Tree::from_data(v, &Default::default())).ok()?; encryption_key: Default::default(),
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(),
});
let size = tree.size(); media.image_size_vec(v, mime)
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)> {
if let Ok(data) = ffprobe::ffprobe(f.path()) let media = MediaImpl::new(Files {
.inspect_err(|err| tracing::error!("Failed to ffprobe file! {err:?}")) blocked_mime_types: Default::default(),
{ clamd_host: Default::default(),
// Use first valid stream encryption_key: Default::default(),
for stream in data.streams { limit: FilesLimit {
if let (Some(w), Some(h)) = (stream.width, stream.height) { max_mega_pixels: 0,
return Some((w, h)); 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(),
});
None media.video_size(f)
} 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> {
match mime { let media = MediaImpl::new(Files {
// Read image using jxl-oxide crate blocked_mime_types: Default::default(),
"image/jxl" => { clamd_host: Default::default(),
let jxl_image = report_internal_error!(jxl_oxide::JxlImage::builder().read(reader))?; encryption_key: Default::default(),
if let Ok(frame) = jxl_image.render_frame(0) { limit: FilesLimit {
match frame.color_channels().len() { max_mega_pixels: 0,
3 => Ok(DynamicImage::ImageRgb8( max_pixel_side: 0,
DynamicImage::ImageRgb32F( min_file_size: 0,
ImageBuffer::from_vec( min_resolution: [0, 0],
jxl_image.width(), },
jxl_image.height(), preview: Default::default(),
frame.image().buf().to_vec(), s3: FilesS3 {
) access_key_id: Default::default(),
.ok_or_else(|| create_error!(ImageProcessingFailed))?, default_bucket: Default::default(),
) endpoint: Default::default(),
.to_rgb8(), path_style_buckets: Default::default(),
)), region: Default::default(),
4 => Ok(DynamicImage::ImageRgba8( secret_access_key: Default::default(),
DynamicImage::ImageRgba32F( },
ImageBuffer::from_vec( scan_mime_types: Default::default(),
jxl_image.width(), webp_quality: Default::default(),
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))?;
let tree = report_internal_error!(usvg::Tree::from_data(&buf, &Default::default()))?; report_internal_error!(media.decode_image(reader, mime))
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 {
match mime { let media = MediaImpl::new(Files {
// Check if we can read using jxl-oxide crate blocked_mime_types: Default::default(),
"image/jxl" => jxl_oxide::JxlImage::builder() clamd_host: Default::default(),
.read(reader) encryption_key: Default::default(),
.inspect_err(|err| tracing::error!("Failed to read JXL! {err:?}")) limit: FilesLimit {
.is_ok(), max_mega_pixels: 0,
// Check if we can read using image-rs crate max_pixel_side: 0,
_ => !matches!( min_file_size: 0,
image::ImageReader::new(reader) min_resolution: [0, 0],
.with_guessed_format() },
.inspect_err(|err| tracing::error!("Failed to read image! {err:?}")) preview: Default::default(),
.map(|f| f.decode()), s3: FilesS3 {
Err(_) | Ok(Err(_)) 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.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> {
// Load configuration let media = MediaImpl::from_config().await;
let config = config().await; media.create_thumbnail(image, tag)
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()
}
} }
@@ -0,0 +1,6 @@
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)>;
}
@@ -0,0 +1,22 @@
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<()>;
}
@@ -0,0 +1,30 @@
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),
}
@@ -0,0 +1,7 @@
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};
Binary file not shown.

After

Width:  |  Height:  |  Size: 968 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 375 KiB

Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 382 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

@@ -0,0 +1,31 @@
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();
}
+42
View File
@@ -0,0 +1,42 @@
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();
}
+4 -3
View File
@@ -1,10 +1,11 @@
[package] [package]
name = "revolt-models" name = "revolt-models"
version = "0.9.1" version = "0.11.0"
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
@@ -20,8 +21,8 @@ default = ["serde", "partials", "rocket"]
[dependencies] [dependencies]
# Core # Core
revolt-config = { version = "0.9.1", path = "../config" } revolt-config = { version = "0.11.0", path = "../config" }
revolt-permissions = { version = "0.9.1", path = "../permissions" } revolt-permissions = { version = "0.11.0", path = "../permissions" }
# Utility # Utility
regex = "1.11" regex = "1.11"
@@ -95,6 +95,7 @@ auto_derived!(
CanReceive, CanReceive,
CanPublish, CanPublish,
JoinedAt, JoinedAt,
VoiceChannel,
} }
/// Member removal intention /// Member removal intention
+2 -1
View File
@@ -1,10 +1,11 @@
[package] [package]
name = "revolt-parser" name = "revolt-parser"
version = "0.9.1" version = "0.11.0"
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" }
+3 -2
View File
@@ -1,10 +1,11 @@
[package] [package]
name = "revolt-permissions" name = "revolt-permissions"
version = "0.9.1" version = "0.11.0"
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
@@ -21,7 +22,7 @@ async-std = { version = "1.8.0", features = ["attributes"] }
[dependencies] [dependencies]
# Core # Core
revolt-result = { version = "0.9.1", path = "../result" } revolt-result = { version = "0.11.0", path = "../result" }
# Utility # Utility
auto_ops = "0.3.0" auto_ops = "0.3.0"
+3 -2
View File
@@ -1,10 +1,11 @@
[package] [package]
name = "revolt-presence" name = "revolt-presence"
version = "0.9.1" version = "0.11.0"
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: User Presence" description = "Revolt Backend: User Presence"
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,7 +17,7 @@ redis-is-patched = []
async-std = { version = "1.8.0", features = ["attributes"] } async-std = { version = "1.8.0", features = ["attributes"] }
# Config for loading Redis URI # Config for loading Redis URI
revolt-config = { version = "0.9.1", path = "../config" } revolt-config = { version = "0.11.0", path = "../config" }
[dependencies] [dependencies]
# Utility # Utility
+14 -6
View File
@@ -1,18 +1,26 @@
[package] [package]
name = "revolt-ratelimits" name = "revolt-ratelimits"
version = "0.9.1" version = "0.11.0"
edition = "2024" edition = "2024"
license = "MIT"
authors = ["Zomatree <me@zomatree.live>", "Paul Makles <me@insrt.uk>"]
description = "Revolt Backend: Ratelimit Handler"
repository = "https://github.com/stoatchat/stoatchat"
[features] [features]
rocket = ["dep:rocket", "dep:revolt_rocket_okapi", "revolt-database/rocket-impl"] rocket = [
"dep:rocket",
"dep:revolt_rocket_okapi",
"revolt-database/rocket-impl",
]
axum = ["dep:axum", "revolt-database/axum-impl"] axum = ["dep:axum", "revolt-database/axum-impl"]
default = ["rocket", "axum"] default = ["rocket", "axum"]
[dependencies] [dependencies]
revolt-database = { version = "0.9.1", path = "../database"} revolt-database = { version = "0.11.0", path = "../database" }
revolt-result = { version = "0.9.1", path = "../result" } revolt-result = { version = "0.11.0", path = "../result" }
revolt-config = { version = "0.9.1", path = "../config" } revolt-config = { version = "0.11.0", path = "../config" }
rocket = { version = "0.5.1", optional = true } rocket = { version = "0.5.1", optional = true }
revolt_rocket_okapi = { version = "0.10.0", optional = true } revolt_rocket_okapi = { version = "0.10.0", optional = true }
@@ -20,7 +28,7 @@ revolt_rocket_okapi = { version = "0.10.0", optional = true }
axum = { version = "0.7.5", optional = true, features = ["macros"] } axum = { version = "0.7.5", optional = true, features = ["macros"] }
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
authifier = { version = "1.0.15" } authifier = { version = "1.0.16" }
dashmap = "5.2.0" dashmap = "5.2.0"
async-trait = "0.1.81" async-trait = "0.1.81"
log = "0.4" log = "0.4"
+3 -2
View File
@@ -1,10 +1,11 @@
[package] [package]
name = "revolt-result" name = "revolt-result"
version = "0.9.1" version = "0.11.0"
edition = "2021" edition = "2021"
license = "MIT" license = "MIT"
authors = ["Paul Makles <me@insrt.uk>"] authors = ["Paul Makles <me@insrt.uk>"]
description = "Revolt Backend: Result and Error types" description = "Revolt Backend: Result and Error types"
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 +39,4 @@ log = "0.4"
# Axum # Axum
axum = { version = "0.7.5", optional = true } axum = { version = "0.7.5", optional = true }
sentry = { version = "0.31.5", optional = true } sentry = { version = "0.31.5", optional = true }
+6 -5
View File
@@ -1,10 +1,11 @@
[package] [package]
name = "revolt-crond" name = "revolt-crond"
version = "0.9.1" version = "0.11.0"
license = "AGPL-3.0-or-later" license = "AGPL-3.0-or-later"
authors = ["Paul Makles <me@insrt.uk>"] authors = ["Paul Makles <me@insrt.uk>"]
edition = "2021" edition = "2021"
description = "Revolt Daemon Service: Timed data clean up tasks" description = "Revolt Daemon Service: Timed data clean up tasks"
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
@@ -16,7 +17,7 @@ log = "0.4"
tokio = { version = "1" } tokio = { version = "1" }
# Core # Core
revolt-database = { version = "0.9.1", path = "../../core/database" } revolt-database = { version = "0.11.0", path = "../../core/database" }
revolt-result = { version = "0.9.1", path = "../../core/result" } revolt-result = { version = "0.11.0", path = "../../core/result" }
revolt-config = { version = "0.9.1", path = "../../core/config" } revolt-config = { version = "0.11.0", path = "../../core/config" }
revolt-files = { version = "0.9.1", path = "../../core/files" } revolt-files = { version = "0.11.0", path = "../../core/files" }
+9 -8
View File
@@ -1,20 +1,21 @@
[package] [package]
name = "revolt-pushd" name = "revolt-pushd"
version = "0.9.1" version = "0.11.0"
edition = "2021" edition = "2021"
license = "AGPL-3.0-or-later" license = "AGPL-3.0-or-later"
publish = false
[dependencies] [dependencies]
revolt-result = { version = "0.9.1", path = "../../core/result" } revolt-result = { version = "0.11.0", path = "../../core/result" }
revolt-config = { version = "0.9.1", path = "../../core/config", features = [ revolt-config = { version = "0.11.0", path = "../../core/config", features = [
"report-macros", "report-macros",
"anyhow" "anyhow",
] } ] }
revolt-database = { version = "0.9.1", path = "../../core/database" } revolt-database = { version = "0.11.0", path = "../../core/database" }
revolt-models = { version = "0.9.1", path = "../../core/models", features = [ revolt-models = { version = "0.11.0", path = "../../core/models", features = [
"validator", "validator",
] } ] }
revolt-presence = { version = "0.9.1", path = "../../core/presence", features = [ revolt-presence = { version = "0.11.0", path = "../../core/presence", features = [
"redis-is-patched", "redis-is-patched",
] } ] }
@@ -29,7 +30,7 @@ tokio = "1.39.2"
async-trait = "0.1.81" async-trait = "0.1.81"
ulid = "1.0.0" ulid = "1.0.0"
authifier = "1.0.15" authifier = "1.0.16"
log = "0.4.11" log = "0.4.11"
pretty_env_logger = "0.4.0" pretty_env_logger = "0.4.0"
+2 -1
View File
@@ -1,8 +1,9 @@
[package] [package]
name = "revolt-voice-ingress" name = "revolt-voice-ingress"
version = "0.9.1" version = "0.11.0"
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
+4 -3
View File
@@ -1,9 +1,10 @@
[package] [package]
name = "revolt-delta" name = "revolt-delta"
version = "0.9.1" version = "0.11.0"
license = "AGPL-3.0-or-later" license = "AGPL-3.0-or-later"
authors = ["Paul Makles <paulmakles@gmail.com>"] authors = ["Paul Makles <paulmakles@gmail.com>"]
edition = "2018" edition = "2018"
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
@@ -56,7 +57,7 @@ lettre = "0.10.0-alpha.4"
rocket = { version = "0.5.1", default-features = false, features = ["json"] } rocket = { version = "0.5.1", default-features = false, features = ["json"] }
rocket_cors = { git = "https://github.com/lawliet89/rocket_cors", rev = "072d90359b23e9b291df6b672c07c93de9c46011" } rocket_cors = { git = "https://github.com/lawliet89/rocket_cors", rev = "072d90359b23e9b291df6b672c07c93de9c46011" }
rocket_empty = { version = "0.1.1", features = ["schema"] } rocket_empty = { version = "0.1.1", features = ["schema"] }
rocket_authifier = { version = "1.0.15" } rocket_authifier = { version = "1.0.16" }
rocket_prometheus = "0.10.0-rc.3" rocket_prometheus = "0.10.0-rc.3"
# spec generation # spec generation
@@ -67,7 +68,7 @@ revolt_rocket_okapi = { version = "0.10.0", features = ["swagger"] }
amqprs = { version = "1.7.0" } amqprs = { version = "1.7.0" }
# core # core
authifier = "1.0.15" authifier = "1.0.16"
revolt-config = { path = "../core/config" } revolt-config = { path = "../core/config" }
revolt-database = { path = "../core/database", features = [ revolt-database = { path = "../core/database", features = [
"rocket-impl", "rocket-impl",
+9
View File
@@ -70,6 +70,15 @@ pub async fn web() -> Rocket<Build> {
.iter() .iter()
.map(|s| FromStr::from_str(s).unwrap()) .map(|s| FromStr::from_str(s).unwrap())
.collect(), .collect(),
expose_headers: [
"X-Ratelimit-Limit",
"X-Ratelimit-Bucket",
"X-Ratelimit-Remaining",
"X-Ratelimit-Reset-After",
]
.iter()
.map(|s| s.to_string())
.collect(),
..Default::default() ..Default::default()
} }
.to_cors() .to_cors()
@@ -1,4 +1,7 @@
use revolt_database::{util::{permissions::DatabasePermissionQuery, reference::Reference}, Channel, Database, FieldsMessage, PartialMessage, SystemMessage, User, AMQP}; use revolt_database::{
util::{permissions::DatabasePermissionQuery, reference::Reference},
Channel, Database, FieldsMessage, PartialMessage, SystemMessage, User, AMQP,
};
use revolt_models::v0::MessageAuthor; use revolt_models::v0::MessageAuthor;
use revolt_permissions::{calculate_channel_permissions, ChannelPermission}; use revolt_permissions::{calculate_channel_permissions, ChannelPermission};
use revolt_result::{create_error, Result}; use revolt_result::{create_error, Result};
+24 -6
View File
@@ -98,13 +98,21 @@ pub async fn edit(
permissions.throw_if_lacking_channel_permission(ChannelPermission::DeafenMembers)?; permissions.throw_if_lacking_channel_permission(ChannelPermission::DeafenMembers)?;
} }
let new_voice_channel = if let Some(new_channel) = &data.voice_channel { if data.voice_channel.is_some() && data.remove.contains(&FieldsMember::VoiceChannel) {
return Err(create_error!(InvalidOperation))
}
if data.voice_channel.is_some() || data.remove.contains(&FieldsMember::VoiceChannel) {
if !voice_client.is_enabled() { if !voice_client.is_enabled() {
return Err(create_error!(LiveKitUnavailable)); return Err(create_error!(LiveKitUnavailable));
}; };
permissions.throw_if_lacking_channel_permission(ChannelPermission::MoveMembers)?; if member.id.user != user.id {
permissions.throw_if_lacking_channel_permission(ChannelPermission::MoveMembers)?;
}
}
let new_voice_channel = if let Some(new_channel) = &data.voice_channel {
// ensure the channel we are moving them to is in the server and is a voice channel // ensure the channel we are moving them to is in the server and is a voice channel
let channel = Reference::from_unchecked(new_channel) let channel = Reference::from_unchecked(new_channel)
@@ -116,6 +124,9 @@ pub async fn edit(
Err(create_error!(UnknownChannel))? Err(create_error!(UnknownChannel))?
} }
let channel_permissions = calculate_channel_permissions(&mut query.clone().channel(&channel)).await;
channel_permissions.throw_if_lacking_channel_permission(ChannelPermission::Connect)?;
if get_user_voice_channel_in_server(&target_user.id, &server.id) if get_user_voice_channel_in_server(&target_user.id, &server.id)
.await? .await?
.is_none() .is_none()
@@ -189,10 +200,8 @@ pub async fn edit(
partial.avatar = Some(File::use_user_avatar(db, &avatar, &user.id, &user.id).await?); partial.avatar = Some(File::use_user_avatar(db, &avatar, &user.id, &user.id).await?);
} }
let remove_contains_voice = remove.contains(FieldsMember::CanPublish) || remove.contains(FieldsMember::CanReceive);
member member
.update(db, partial, remove.into_iter().map(Into::into).collect()) .update(db, partial, remove.clone().into_iter().map(Into::into).collect())
.await?; .await?;
if let Some(new_voice_channel) = new_voice_channel { if let Some(new_voice_channel) = new_voice_channel {
@@ -234,7 +243,7 @@ pub async fn edit(
.private(target_user.id.clone()) .private(target_user.id.clone())
.await; .await;
}; };
} else if can_publish.is_some() || can_receive.is_some() || remove_contains_voice { } else if can_publish.is_some() || can_receive.is_some() || remove.contains(FieldsMember::CanPublish) || remove.contains(FieldsMember::CanReceive) {
if let Some(channel) = get_user_voice_channel_in_server(&target_user.id, &server.id).await? if let Some(channel) = get_user_voice_channel_in_server(&target_user.id, &server.id).await?
{ {
let node = get_channel_node(&channel).await?.unwrap(); let node = get_channel_node(&channel).await?.unwrap();
@@ -253,5 +262,14 @@ pub async fn edit(
}; };
}; };
if remove.contains(&FieldsMember::VoiceChannel) {
if let Some(channel) = get_user_voice_channel_in_server(&target_user.id, &server.id).await?
{
let node = get_channel_node(&channel).await?.unwrap();
voice_client.remove_user(&node, &user.id, &channel).await?;
};
}
Ok(Json(member.into())) Ok(Json(member.into()))
} }
+7 -6
View File
@@ -1,8 +1,9 @@
[package] [package]
name = "revolt-autumn" name = "revolt-autumn"
version = "0.9.1" version = "0.11.0"
edition = "2021" edition = "2021"
license = "AGPL-3.0-or-later" license = "AGPL-3.0-or-later"
publish = false
[dependencies] [dependencies]
# ID generation # ID generation
@@ -43,16 +44,16 @@ tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] } tracing-subscriber = { version = "0.3", features = ["env-filter"] }
# Core crates # Core crates
revolt-files = { version = "0.9.1", path = "../../core/files" } revolt-files = { version = "0.11.0", path = "../../core/files" }
revolt-config = { version = "0.9.1", path = "../../core/config" } revolt-config = { version = "0.11.0", path = "../../core/config" }
revolt-database = { version = "0.9.1", path = "../../core/database", features = [ revolt-database = { version = "0.11.0", path = "../../core/database", features = [
"axum-impl", "axum-impl",
] } ] }
revolt-result = { version = "0.9.1", path = "../../core/result", features = [ revolt-result = { version = "0.11.0", path = "../../core/result", features = [
"utoipa", "utoipa",
"axum", "axum",
] } ] }
revolt-ratelimits = { version = "0.9.1", path = "../../core/ratelimits", features = ["axum"] } revolt-ratelimits = { version = "0.11.0", path = "../../core/ratelimits", features = ["axum"] }
# Axum / web server # Axum / web server
tempfile = "3.12.0" tempfile = "3.12.0"
+6
View File
@@ -34,6 +34,12 @@ pub async fn router() -> Router<AppState> {
let cors = CorsLayer::new() let cors = CorsLayer::new()
.allow_methods([Method::POST]) .allow_methods([Method::POST])
.allow_headers(AllowHeaders::mirror_request()) .allow_headers(AllowHeaders::mirror_request())
.expose_headers(vec![
"X-RateLimit-Limit".try_into().unwrap(),
"X-RateLimit-Bucket".try_into().unwrap(),
"X-RateLimit-Remaining".try_into().unwrap(),
"X-RateLimit-Reset-After".try_into().unwrap(),
])
.allow_origin(Any); .allow_origin(Any);
Router::new() Router::new()
+9 -7
View File
@@ -1,8 +1,9 @@
[package] [package]
name = "revolt-gifbox" name = "revolt-gifbox"
version = "0.9.1" version = "0.11.0"
edition = "2021" edition = "2021"
license = "AGPL-3.0-or-later" license = "AGPL-3.0-or-later"
publish = false
[dependencies] [dependencies]
# Serialisation # Serialisation
@@ -16,25 +17,26 @@ tokio = { version = "1.0", features = ["full"] }
reqwest = { version = "0.12", features = ["json"] } reqwest = { version = "0.12", features = ["json"] }
# Core crates # Core crates
revolt-config = { version = "0.9.1", path = "../../core/config" } revolt-config = { version = "0.11.0", path = "../../core/config" }
revolt-models = { version = "0.9.1", path = "../../core/models" } revolt-models = { version = "0.11.0", path = "../../core/models" }
revolt-result = { version = "0.9.1", path = "../../core/result", features = [ revolt-result = { version = "0.11.0", path = "../../core/result", features = [
"utoipa", "utoipa",
"axum", "axum",
] } ] }
revolt-coalesced = { version = "0.9.1", path = "../../core/coalesced", features = [ revolt-coalesced = { version = "0.11.0", path = "../../core/coalesced", features = [
"queue", "queue",
] } ] }
revolt-database = { version = "0.9.1", path = "../../core/database", features = [ revolt-database = { version = "0.11.0", path = "../../core/database", features = [
"axum-impl", "axum-impl",
] } ] }
revolt-ratelimits = { version = "0.9.1", path = "../../core/ratelimits", features = [ revolt-ratelimits = { version = "0.11.0", path = "../../core/ratelimits", features = [
"axum", "axum",
] } ] }
# Axum / web server # Axum / web server
axum = { version = "0.7.5" } axum = { version = "0.7.5" }
axum-extra = { version = "0.9", features = ["typed-header"] } axum-extra = { version = "0.9", features = ["typed-header"] }
tower-http = { version = "0.5.2", features = ["cors"] }
# OpenAPI & documentation generation # OpenAPI & documentation generation
utoipa-scalar = { version = "0.1.0", features = ["axum"] } utoipa-scalar = { version = "0.1.0", features = ["axum"] }
+17 -1
View File
@@ -1,5 +1,9 @@
use crate::AppState; use crate::AppState;
use axum::routing::{get, Router}; use axum::{
http::Method,
routing::{get, Router},
};
use tower_http::cors::{AllowHeaders, Any, CorsLayer};
pub mod categories; pub mod categories;
pub mod root; pub mod root;
@@ -7,9 +11,21 @@ pub mod search;
pub mod trending; pub mod trending;
pub fn router() -> Router<AppState> { pub fn router() -> Router<AppState> {
let cors = CorsLayer::new()
.allow_methods([Method::GET])
.allow_headers(AllowHeaders::mirror_request())
.expose_headers(vec![
"X-RateLimit-Limit".try_into().unwrap(),
"X-RateLimit-Bucket".try_into().unwrap(),
"X-RateLimit-Remaining".try_into().unwrap(),
"X-RateLimit-Reset-After".try_into().unwrap(),
])
.allow_origin(Any);
Router::new() Router::new()
.route("/", get(root::root)) .route("/", get(root::root))
.route("/categories", get(categories::categories)) .route("/categories", get(categories::categories))
.route("/search", get(search::search)) .route("/search", get(search::search))
.route("/trending", get(trending::trending)) .route("/trending", get(trending::trending))
.layer(cors)
} }
+6 -5
View File
@@ -1,8 +1,9 @@
[package] [package]
name = "revolt-january" name = "revolt-january"
version = "0.9.1" version = "0.11.0"
edition = "2021" edition = "2021"
license = "AGPL-3.0-or-later" license = "AGPL-3.0-or-later"
publish = false
[dependencies] [dependencies]
# Utility # Utility
@@ -32,13 +33,13 @@ tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] } tracing-subscriber = { version = "0.3", features = ["env-filter"] }
# Core crates # Core crates
revolt-config = { version = "0.9.1", path = "../../core/config" } revolt-config = { version = "0.11.0", path = "../../core/config" }
revolt-models = { version = "0.9.1", path = "../../core/models" } revolt-models = { version = "0.11.0", path = "../../core/models" }
revolt-result = { version = "0.9.1", path = "../../core/result", features = [ revolt-result = { version = "0.11.0", path = "../../core/result", features = [
"utoipa", "utoipa",
"axum", "axum",
] } ] }
revolt-files = { version = "0.9.1", path = "../../core/files" } revolt-files = { version = "0.11.0", path = "../../core/files" }
# Axum / web server # Axum / web server
axum = { version = "0.7.5" } axum = { version = "0.7.5" }
+36 -23
View File
@@ -1,28 +1,41 @@
{ { pkgs ? import (fetchTarball {
pkgs ? import <nixpkgs> { }, url = "https://github.com/NixOS/nixpkgs/archive/77ef7a29d276c6d8303aece3444d61118ef71ac2.tar.gz";
sha256 = "0pm4l48jq8plzrrrisimahxqlcpx7qqq9c99hylmf7p3zlc3phsy";
}) {},
}: }:
pkgs.mkShell rec { let
buildInputs = [ nix-ld-libs = pkgs.buildEnv {
# Tools name = "nix-ld-libs";
pkgs.git paths = with pkgs; [
pkgs.just stdenv.cc.cc.lib
zlib
openssl.out
];
pathsToLink = [ "/lib" ];
};
# Cargo in pkgs.mkShell {
pkgs.cargo packages = with pkgs; [
pkgs.cargo-nextest mise
pkgs.cargo-release cargo-binstall
(writeShellScriptBin "fish" ''
# Rust exec ${pkgs.fish}/bin/fish -C 'mise activate fish | source' "$@"
pkgs.rustc '')
pkgs.clippy
pkgs.rustfmt
pkgs.pkg-config
pkgs.openssl.dev
# mdbook
pkgs.mdbook
]; ];
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; buildInputs = with pkgs; [
} pkg-config
openssl.dev
];
shellHook = ''
export TMPDIR=/tmp
export NIX_LD="${pkgs.stdenv.cc.libc}/lib/ld-linux-x86-64.so.2"
export NIX_LD_LIBRARY_PATH="${nix-ld-libs}/lib"
export LD_LIBRARY_PATH="${nix-ld-libs}/lib''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
export MISE_NODE_COMPILE=false
eval "$(mise activate bash)"
'';
}
+8
View File
@@ -0,0 +1,8 @@
# See https://www.git-town.com/configuration-file for details
[branches]
main = "main"
[hosting]
forge-type = "github"
github-connector = "gh"
-21
View File
@@ -1,21 +0,0 @@
publish:
cargo publish --package revolt-parser
cargo publish --package revolt-result
cargo publish --package revolt-config
cargo publish --package revolt-files
cargo publish --package revolt-permissions
cargo publish --package revolt-models
cargo publish --package revolt-presence
cargo publish --package revolt-database
patch:
cargo release version patch --execute
minor:
cargo release version minor --execute
major:
cargo release version major --execute
release:
scripts/try-tag-and-release.sh
+1 -1
View File
@@ -1,2 +1,2 @@
[toolchain] [toolchain]
channel = "stable" channel = "1.92.0"
-15
View File
@@ -1,15 +0,0 @@
#!/usr/bin/env bash
set -e
cargo build \
--bin revolt-delta \
--bin revolt-bonfire \
--bin revolt-autumn \
--bin revolt-january \
--bin revolt-gifbox
trap 'pkill -f revolt-' SIGINT
cargo run --bin revolt-delta &
cargo run --bin revolt-bonfire &
cargo run --bin revolt-autumn &
cargo run --bin revolt-january &
cargo run --bin revolt-gifbox
-14
View File
@@ -1,14 +0,0 @@
#!/usr/bin/env bash
date=$(date +'%Y%m%d')
incr=1
while [ $(git tag -l "$date-$incr") ]; do
incr=$((incr+1))
done
tag=$date-$incr
echo About to tag and push $tag in 3 seconds...
sleep 3s
git tag $tag
git push --atomic origin $(git rev-parse --abbrev-ref HEAD) $tag
+1 -1
View File
@@ -1 +1 @@
0.9.1 0.11.0