forked from jmug/stoatchat
Compare commits
110
Commits
20240829-2
...
handmade
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35cfb9a489 | ||
|
|
7297a64856 | ||
|
|
720cd46879 | ||
|
|
7d099d5ae7 | ||
|
|
8847b3c5ba | ||
|
|
eb5f5f91cd | ||
|
|
52e1f0ddde | ||
|
|
defc9ec79b | ||
|
|
7026961df4 | ||
|
|
078380d305 | ||
|
|
add3f40b23 | ||
|
|
7216e9909b | ||
|
|
a1e6a19210 | ||
|
|
5f39403ce7 | ||
|
|
e525ffe5e4 | ||
|
|
e3723d647e | ||
|
|
5f84daa9db | ||
|
|
e957af4ca3 | ||
|
|
439bacf067 | ||
|
|
fa55e88dd9 | ||
|
|
71e7fe3086 | ||
|
|
03f2e3b1bf | ||
|
|
8bbb579d23 | ||
|
|
6448af071b | ||
|
|
c2a0ab71df | ||
|
|
7a17165c24 | ||
|
|
d7213fa409 | ||
|
|
479f0402ca | ||
|
|
b62eeef80c | ||
|
|
7b15006a50 | ||
|
|
ac731e547d | ||
|
|
443f374f23 | ||
|
|
42367f477c | ||
|
|
3cb91151ca | ||
|
|
4c46054bff | ||
|
|
f01794af93 | ||
|
|
49f7f9549c | ||
|
|
72e3129557 | ||
|
|
75a07a84c0 | ||
|
|
b55765d7c7 | ||
|
|
ed5ded5e45 | ||
|
|
249749e14d | ||
|
|
4c00a7dfb7 | ||
|
|
acc4317246 | ||
|
|
b9ae333b02 | ||
|
|
bf0fc504a9 | ||
|
|
705e517871 | ||
|
|
6f99ac2160 | ||
|
|
2fcc714546 | ||
|
|
1e72f7bc77 | ||
|
|
af0d24c7c6 | ||
|
|
ab58177dfa | ||
|
|
df07426019 | ||
|
|
c30d9a2620 | ||
|
|
7b44317705 | ||
|
|
876068a37e | ||
|
|
397b9878e1 | ||
|
|
d9deadc65a | ||
|
|
58d3c5cc2e | ||
|
|
520fb02fb6 | ||
|
|
2cb12a3d59 | ||
|
|
18888eae5f | ||
|
|
f31020fb6e | ||
|
|
bb202079e0 | ||
|
|
bb6bcda8bd | ||
|
|
68099bd2b7 | ||
|
|
a8db1cb40d | ||
|
|
efa7ba78ed | ||
|
|
25fc692dc1 | ||
|
|
530d68fe89 | ||
|
|
afd8c906ba | ||
|
|
c596dd5458 | ||
|
|
ed78b253ff | ||
|
|
66c84e0ad9 | ||
|
|
21335b3297 | ||
|
|
8fc791f81a | ||
|
|
1689ee5ddc | ||
|
|
7a061bb3c6 | ||
|
|
6c3b8eaa92 | ||
|
|
5e1b2e165f | ||
|
|
e270b5df6a | ||
|
|
cbf9e81256 | ||
|
|
3080ec1f5a | ||
|
|
4fd66b2719 | ||
|
|
916f47e2f5 | ||
|
|
a3c5b1bf87 | ||
|
|
ace6c30ba5 | ||
|
|
f4104612b2 | ||
|
|
6209bc7152 | ||
|
|
1a6a8a809b | ||
|
|
5485781e7c | ||
|
|
8b21825ffe | ||
|
|
530ff4f9c7 | ||
|
|
2eb596fe99 | ||
|
|
0bbb9e7072 | ||
|
|
2433fa661a | ||
|
|
70bdeecf77 | ||
|
|
24dc96f80f | ||
|
|
ebbbb5e174 | ||
|
|
78757ac7f1 | ||
|
|
01368960f3 | ||
|
|
ae1d5d07e3 | ||
|
|
5ad72abca7 | ||
|
|
c1b92ef56e | ||
|
|
acbc1b8956 | ||
|
|
bce24c8b1b | ||
|
|
31262315e7 | ||
|
|
d8acaa1107 | ||
|
|
730039eda6 | ||
|
|
79e1388000 |
-107
@@ -1,107 +0,0 @@
|
|||||||
# MongoDB URI
|
|
||||||
MONGODB=mongodb://localhost
|
|
||||||
AUTUMN_MONGO_URI=mongodb://database
|
|
||||||
REDIS_URI=redis://localhost/
|
|
||||||
|
|
||||||
# URL to where the Revolt app is publicly accessible
|
|
||||||
REVOLT_APP_URL=http://local.revolt.chat:5000
|
|
||||||
|
|
||||||
# URL to where the API is publicly accessible
|
|
||||||
REVOLT_PUBLIC_URL=http://local.revolt.chat:8000
|
|
||||||
VITE_API_URL=http://local.revolt.chat:8000
|
|
||||||
|
|
||||||
# URL to where the WebSocket server is publicly accessible
|
|
||||||
REVOLT_EXTERNAL_WS_URL=ws://local.revolt.chat:9000
|
|
||||||
|
|
||||||
# URL to where Autumn is publicly available
|
|
||||||
AUTUMN_PUBLIC_URL=http://local.revolt.chat:3000
|
|
||||||
|
|
||||||
# URL to where January is publicly available
|
|
||||||
JANUARY_PUBLIC_URL=http://local.revolt.chat:7000
|
|
||||||
|
|
||||||
# URL to where Vortex is publicly available
|
|
||||||
# VOSO_PUBLIC_URL=https://voso.revolt.chat
|
|
||||||
|
|
||||||
|
|
||||||
##
|
|
||||||
## hCaptcha Settings
|
|
||||||
##
|
|
||||||
|
|
||||||
# If you are sure that you don't want to use hCaptcha, set to 1.
|
|
||||||
REVOLT_UNSAFE_NO_CAPTCHA=1
|
|
||||||
|
|
||||||
# hCaptcha API key
|
|
||||||
# REVOLT_HCAPTCHA_KEY=0x0000000000000000000000000000000000000000
|
|
||||||
|
|
||||||
# hCaptcha site key
|
|
||||||
# REVOLT_HCAPTCHA_SITEKEY=10000000-ffff-ffff-ffff-000000000001
|
|
||||||
|
|
||||||
|
|
||||||
##
|
|
||||||
## Email Settings
|
|
||||||
##
|
|
||||||
|
|
||||||
# If you are sure that you don't want to use email verification, set to 1.
|
|
||||||
REVOLT_UNSAFE_NO_EMAIL=1
|
|
||||||
|
|
||||||
# SMTP host
|
|
||||||
# REVOLT_SMTP_HOST=smtp.example.com
|
|
||||||
|
|
||||||
# SMTP username
|
|
||||||
# REVOLT_SMTP_USERNAME=noreply@example.com
|
|
||||||
|
|
||||||
# SMTP password
|
|
||||||
# REVOLT_SMTP_PASSWORD=CHANGEME
|
|
||||||
|
|
||||||
# SMTP From header
|
|
||||||
# REVOLT_SMTP_FROM=Revolt <noreply@example.com>
|
|
||||||
|
|
||||||
|
|
||||||
##
|
|
||||||
## Application Settings
|
|
||||||
##
|
|
||||||
|
|
||||||
# Whether to enable staging only features
|
|
||||||
REVOLT_IS_STAGING=1
|
|
||||||
|
|
||||||
# Whether to only allow users to sign up if they have an invite code
|
|
||||||
REVOLT_INVITE_ONLY=0
|
|
||||||
|
|
||||||
# Maximum number of people that can be in a group chat
|
|
||||||
REVOLT_MAX_GROUP_SIZE=150
|
|
||||||
|
|
||||||
# VAPID keys for push notifications
|
|
||||||
# Generate using this guide: https://gitlab.insrt.uk/revolt/delta/-/wikis/vapid
|
|
||||||
# --> Please replace these keys before going into production! <--
|
|
||||||
REVOLT_VAPID_PRIVATE_KEY=LS0tLS1CRUdJTiBFQyBQUklWQVRFIEtFWS0tLS0tCk1IY0NBUUVFSUJSUWpyTWxLRnBiVWhsUHpUbERvcEliYk1yeVNrNXpKYzVYVzIxSjJDS3hvQW9HQ0NxR1NNNDkKQXdFSG9VUURRZ0FFWnkrQkg2TGJQZ2hEa3pEempXOG0rUXVPM3pCajRXT1phdkR6ZU00c0pqbmFwd1psTFE0WAp1ZDh2TzVodU94QWhMQlU3WWRldVovWHlBdFpWZmNyQi9BPT0KLS0tLS1FTkQgRUMgUFJJVkFURSBLRVktLS0tLQo=
|
|
||||||
REVOLT_VAPID_PUBLIC_KEY=BGcvgR-i2z4IQ5Mw841vJvkLjt8wY-FjmWrw83jOLCY52qcGZS0OF7nfLzuYbjsQISwVO2HXrmf18gLWVX3Kwfw=
|
|
||||||
|
|
||||||
|
|
||||||
##
|
|
||||||
## Vortex configuration
|
|
||||||
##
|
|
||||||
|
|
||||||
# VOSO_MANAGE_TOKEN=CHANGEME
|
|
||||||
|
|
||||||
|
|
||||||
##
|
|
||||||
## Autumn configuration
|
|
||||||
##
|
|
||||||
|
|
||||||
# S3 Region
|
|
||||||
AUTUMN_S3_REGION=minio
|
|
||||||
|
|
||||||
# S3 Endpoint
|
|
||||||
AUTUMN_S3_ENDPOINT=http://minio:9000
|
|
||||||
|
|
||||||
# MinIO Root User
|
|
||||||
MINIO_ROOT_USER=minioautumn
|
|
||||||
|
|
||||||
# MinIO Root Password
|
|
||||||
MINIO_ROOT_PASSWORD=minioautumn
|
|
||||||
|
|
||||||
# AWS Access Key ID
|
|
||||||
AWS_ACCESS_KEY_ID=minioautumn
|
|
||||||
|
|
||||||
# AWS Secret Key
|
|
||||||
AWS_SECRET_ACCESS_KEY=minioautumn
|
|
||||||
+103
-115
@@ -1,125 +1,113 @@
|
|||||||
name: Docker Test & Publish
|
name: Docker
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
# branches:
|
branches:
|
||||||
# - "main"
|
- "handmade"
|
||||||
tags:
|
|
||||||
- "*"
|
|
||||||
paths-ignore:
|
|
||||||
- ".github/**"
|
|
||||||
- "!.github/workflows/docker.yml"
|
|
||||||
- ".vscode/**"
|
|
||||||
- "doc/**"
|
|
||||||
- ".gitignore"
|
|
||||||
- "LICENSE"
|
|
||||||
- "README"
|
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- "main"
|
- "handmade"
|
||||||
paths:
|
release:
|
||||||
- "Dockerfile"
|
types:
|
||||||
workflow_dispatch:
|
- published
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
packages: write
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
base:
|
# Builds the shared base image: the whole Rust workspace compiled once.
|
||||||
runs-on: ubuntu-latest
|
# Every service image (currently only pushd) is derived from this so the
|
||||||
name: Build base image
|
# workspace is built a single time per release. On non-release events this
|
||||||
steps:
|
# still runs as a compile check, but nothing is pushed.
|
||||||
# Configure build environment
|
base:
|
||||||
- name: Checkout
|
runs-on: ubuntu-latest
|
||||||
uses: actions/checkout@v3
|
steps:
|
||||||
- name: Set up Docker Buildx
|
- name: Checkout
|
||||||
uses: docker/setup-buildx-action@v2
|
uses: actions/checkout@v4
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
- name: Resolve registry host and owner
|
||||||
|
id: registry
|
||||||
|
# Owner is lowercased: Docker repository names must be lowercase.
|
||||||
|
run: |
|
||||||
|
echo "host=${GITHUB_SERVER_URL#*://}" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "owner=$(echo "$GITHUB_REPOSITORY_OWNER" | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
|
||||||
|
- name: Base image ref
|
||||||
|
id: base
|
||||||
|
run: echo "image=${{ steps.registry.outputs.host }}/${{ steps.registry.outputs.owner }}/handmade-revolt-backend-base" >> "$GITHUB_OUTPUT"
|
||||||
|
- name: Login to registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
if: github.event_name == 'release'
|
||||||
|
with:
|
||||||
|
registry: ${{ steps.registry.outputs.host }}
|
||||||
|
username: ${{ secrets.PACKAGE_PUBLISH_USERNAME }}
|
||||||
|
password: ${{ secrets.PACKAGE_PUBLISH_TOKEN }}
|
||||||
|
- name: Build base image
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: Dockerfile
|
||||||
|
push: ${{ github.event_name == 'release' }}
|
||||||
|
platforms: linux/amd64
|
||||||
|
# Pinned to the commit so the publish job below consumes this
|
||||||
|
# exact base.
|
||||||
|
tags: |
|
||||||
|
${{ steps.base.outputs.image }}:latest
|
||||||
|
${{ steps.base.outputs.image }}:${{ github.sha }}
|
||||||
|
|
||||||
# Authenticate with GHCR
|
# Builds individual service images from the base. Only runs on release.
|
||||||
- name: Login to Github Container Registry
|
publish:
|
||||||
if: ${{ github.event_name != 'pull_request' }}
|
needs: [base]
|
||||||
uses: docker/login-action@v2
|
runs-on: ubuntu-latest
|
||||||
with:
|
if: github.event_name == 'release'
|
||||||
registry: ghcr.io
|
strategy:
|
||||||
username: ${{ github.actor }}
|
matrix:
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
include:
|
||||||
|
- { project: pushd, path: crates/daemons/pushd, image: handmade-revolt-backend-pushd }
|
||||||
- name: Build base image
|
- { project: delta, path: crates/delta, image: handmade-revolt-backend-server }
|
||||||
uses: docker/build-push-action@v4
|
- { project: bonfire, path: crates/bonfire, image: handmade-revolt-backend-bonfire }
|
||||||
with:
|
- { project: autumn, path: crates/services/autumn, image: handmade-revolt-backend-autumn }
|
||||||
context: .
|
- { project: january, path: crates/services/january, image: handmade-revolt-backend-january }
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
- { project: crond, path: crates/daemons/crond, image: handmade-revolt-backend-crond }
|
||||||
platforms: linux/amd64,linux/arm64
|
name: Build ${{ matrix.project }} image
|
||||||
tags: ghcr.io/${{ github.repository_owner }}/base:latest
|
steps:
|
||||||
cache-from: type=gha,scope=buildx-base-multi-arch
|
- name: Checkout
|
||||||
cache-to: type=gha,scope=buildx-base-multi-arch,mode=max
|
uses: actions/checkout@v4
|
||||||
|
- name: Set up Docker Buildx
|
||||||
publish:
|
uses: docker/setup-buildx-action@v3
|
||||||
needs: [base]
|
- name: Resolve registry host and owner
|
||||||
runs-on: ubuntu-latest
|
id: registry
|
||||||
if: github.event_name != 'pull_request'
|
# Owner is lowercased: Docker repository names must be lowercase,
|
||||||
strategy:
|
# but the org (e.g. HMC) may be uppercase.
|
||||||
matrix:
|
run: |
|
||||||
project: [delta, bonfire]
|
echo "host=${GITHUB_SERVER_URL#*://}" >> "$GITHUB_OUTPUT"
|
||||||
name: Build ${{ matrix.project }} image
|
echo "owner=$(echo "$GITHUB_REPOSITORY_OWNER" | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
|
||||||
steps:
|
- name: Docker meta
|
||||||
# Configure build environment
|
id: meta
|
||||||
- name: Checkout
|
uses: docker/metadata-action@v5
|
||||||
uses: actions/checkout@v3
|
with:
|
||||||
- name: Set up Docker Buildx
|
images: ${{ steps.registry.outputs.host }}/${{ steps.registry.outputs.owner }}/${{ matrix.image }}
|
||||||
uses: docker/setup-buildx-action@v2
|
tags: |
|
||||||
|
type=semver,pattern={{version}}
|
||||||
# Authenticate with Docker Hub and GHCR
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
- name: Login to DockerHub
|
type=raw,value=latest
|
||||||
uses: docker/login-action@v2
|
env:
|
||||||
with:
|
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
|
||||||
registry: docker.io
|
- name: Login to registry
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
uses: docker/login-action@v3
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
with:
|
||||||
- name: Login to Github Container Registry
|
registry: ${{ steps.registry.outputs.host }}
|
||||||
uses: docker/login-action@v2
|
username: ${{ secrets.PACKAGE_PUBLISH_USERNAME }}
|
||||||
with:
|
password: ${{ secrets.PACKAGE_PUBLISH_TOKEN }}
|
||||||
registry: ghcr.io
|
- name: Build and publish
|
||||||
username: ${{ github.actor }}
|
uses: docker/build-push-action@v6
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
with:
|
||||||
|
context: .
|
||||||
# Resolve the correct project
|
file: ${{ matrix.path }}/Dockerfile
|
||||||
- uses: kanga333/variable-mapper@master
|
push: true
|
||||||
id: export
|
platforms: linux/amd64
|
||||||
with:
|
build-args: |
|
||||||
key: "${{ matrix.project }}"
|
BASE_IMAGE=${{ steps.registry.outputs.host }}/${{ steps.registry.outputs.owner }}/handmade-revolt-backend-base:${{ github.sha }}
|
||||||
map: |
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
{
|
annotations: ${{ steps.meta.outputs.annotations }}
|
||||||
"delta": {
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
"path": "crates/delta",
|
|
||||||
"tag": "${{ github.repository_owner }}/server"
|
|
||||||
},
|
|
||||||
"bonfire": {
|
|
||||||
"path": "crates/bonfire",
|
|
||||||
"tag": "${{ github.repository_owner }}/bonfire"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
export_to: output
|
|
||||||
|
|
||||||
# Configure metadata
|
|
||||||
- name: Docker meta
|
|
||||||
id: meta
|
|
||||||
uses: docker/metadata-action@v4
|
|
||||||
with:
|
|
||||||
images: |
|
|
||||||
docker.io/${{ steps.export.outputs.tag }}
|
|
||||||
ghcr.io/${{ steps.export.outputs.tag }}
|
|
||||||
|
|
||||||
# Build crate image
|
|
||||||
- name: Publish
|
|
||||||
uses: docker/build-push-action@v4
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
push: true
|
|
||||||
platforms: linux/amd64,linux/arm64
|
|
||||||
file: ${{ steps.export.outputs.path }}/Dockerfile
|
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
|
||||||
build-args: |
|
|
||||||
BASE_IMAGE=ghcr.io/${{ github.repository_owner }}/base:latest
|
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
|
||||||
|
|||||||
@@ -41,11 +41,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Run services in background
|
- name: Run services in background
|
||||||
run: |
|
run: |
|
||||||
docker compose -f docker-compose.db.yml up -d
|
docker compose -f compose.yml up -d
|
||||||
|
|
||||||
- name: Copy .env.example
|
|
||||||
run: |
|
|
||||||
cp .env.example .env
|
|
||||||
|
|
||||||
- name: Run cargo test
|
- name: Run cargo test
|
||||||
env:
|
env:
|
||||||
@@ -71,7 +67,7 @@ jobs:
|
|||||||
if: github.event_name != 'pull_request' && github.ref_name == 'main'
|
if: github.event_name != 'pull_request' && github.ref_name == 'main'
|
||||||
uses: nev7n/wait_for_response@v1
|
uses: nev7n/wait_for_response@v1
|
||||||
with:
|
with:
|
||||||
url: "http://localhost:8000/"
|
url: "http://localhost:14702/"
|
||||||
|
|
||||||
- name: Checkout API repository
|
- name: Checkout API repository
|
||||||
if: github.event_name != 'pull_request' && github.ref_name == 'main'
|
if: github.event_name != 'pull_request' && github.ref_name == 'main'
|
||||||
@@ -83,7 +79,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Download OpenAPI specification
|
- name: Download OpenAPI specification
|
||||||
if: github.event_name != 'pull_request' && github.ref_name == 'main'
|
if: github.event_name != 'pull_request' && github.ref_name == 'main'
|
||||||
run: curl http://localhost:8000/openapi.json -o api/OpenAPI.json
|
run: curl http://localhost:14702/openapi.json -o api/OpenAPI.json
|
||||||
|
|
||||||
- name: Commit changes
|
- name: Commit changes
|
||||||
if: github.event_name != 'pull_request' && github.ref_name == 'main'
|
if: github.event_name != 'pull_request' && github.ref_name == 'main'
|
||||||
|
|||||||
+4
-1
@@ -1,5 +1,6 @@
|
|||||||
Rocket.toml
|
Rocket.toml
|
||||||
Revolt.toml
|
Revolt.*.toml
|
||||||
|
compose.override.yml
|
||||||
|
|
||||||
target
|
target
|
||||||
.data
|
.data
|
||||||
@@ -7,3 +8,5 @@ target
|
|||||||
|
|
||||||
.vercel
|
.vercel
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
.idea
|
||||||
Vendored
+2
-2
@@ -2,5 +2,5 @@
|
|||||||
"editor.formatOnSave": true,
|
"editor.formatOnSave": true,
|
||||||
"rust-analyzer.checkOnSave.command": "clippy",
|
"rust-analyzer.checkOnSave.command": "clippy",
|
||||||
"nixEnvSelector.suggestion": false,
|
"nixEnvSelector.suggestion": false,
|
||||||
"nixEnvSelector.nixFile": "${workspaceRoot}/default.nix"
|
"nixEnvSelector.nixFile": "${workspaceFolder}/default.nix"
|
||||||
}
|
}
|
||||||
Generated
+2042
-362
File diff suppressed because it is too large
Load Diff
+9
-1
@@ -1,16 +1,24 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
members = [
|
members = [
|
||||||
"crates/delta",
|
"crates/delta",
|
||||||
"crates/bonfire",
|
"crates/bonfire",
|
||||||
"crates/core/*",
|
"crates/core/*",
|
||||||
"crates/services/*",
|
"crates/services/*",
|
||||||
"crates/bindings/*",
|
"crates/bindings/*",
|
||||||
|
"crates/daemons/*",
|
||||||
]
|
]
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
# mobc-redis = { git = "https://github.com/insertish/mobc", rev = "8b880bb59f2ba80b4c7bc40c649c113d8857a186" }
|
|
||||||
redis22 = { package = "redis", version = "0.22.3", git = "https://github.com/revoltchat/redis-rs", rev = "1a41faf356fd21aebba71cea7eb7eb2653e5f0ef" }
|
redis22 = { package = "redis", version = "0.22.3", git = "https://github.com/revoltchat/redis-rs", rev = "1a41faf356fd21aebba71cea7eb7eb2653e5f0ef" }
|
||||||
redis23 = { package = "redis", version = "0.23.1", git = "https://github.com/revoltchat/redis-rs", rev = "f8ca28ab85da59d2ccde526b4d2fb390eff5a5f9" }
|
redis23 = { package = "redis", version = "0.23.1", git = "https://github.com/revoltchat/redis-rs", rev = "f8ca28ab85da59d2ccde526b4d2fb390eff5a5f9" }
|
||||||
# authifier = { package = "authifier", version = "1.0.8", path = "../authifier/crates/authifier" }
|
# authifier = { package = "authifier", version = "1.0.8", path = "../authifier/crates/authifier" }
|
||||||
# rocket_authifier = { package = "rocket_authifier", version = "1.0.8", path = "../authifier/crates/rocket_authifier" }
|
# rocket_authifier = { package = "rocket_authifier", version = "1.0.8", 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.
|
||||||
|
# [profile.release]
|
||||||
|
# lto = true
|
||||||
|
|||||||
+4
-1
@@ -1,5 +1,5 @@
|
|||||||
# Build Stage
|
# Build Stage
|
||||||
FROM --platform="${BUILDPLATFORM}" rust:1.70.0-slim
|
FROM --platform="${BUILDPLATFORM}" rust:1.77.2-slim-bookworm
|
||||||
USER 0:0
|
USER 0:0
|
||||||
WORKDIR /home/rust/src
|
WORKDIR /home/rust/src
|
||||||
|
|
||||||
@@ -28,6 +28,9 @@ COPY crates/core/permissions/Cargo.toml ./crates/core/permissions/
|
|||||||
COPY crates/core/presence/Cargo.toml ./crates/core/presence/
|
COPY crates/core/presence/Cargo.toml ./crates/core/presence/
|
||||||
COPY crates/core/result/Cargo.toml ./crates/core/result/
|
COPY crates/core/result/Cargo.toml ./crates/core/result/
|
||||||
COPY crates/services/autumn/Cargo.toml ./crates/services/autumn/
|
COPY crates/services/autumn/Cargo.toml ./crates/services/autumn/
|
||||||
|
COPY crates/services/january/Cargo.toml ./crates/services/january/
|
||||||
|
COPY crates/daemons/crond/Cargo.toml ./crates/daemons/crond/
|
||||||
|
COPY crates/daemons/pushd/Cargo.toml ./crates/daemons/pushd/
|
||||||
RUN sh /tmp/build-image-layer.sh deps
|
RUN sh /tmp/build-image-layer.sh deps
|
||||||
|
|
||||||
# Build all apps
|
# Build all apps
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Build Stage
|
# Build Stage
|
||||||
FROM rust:1.70.0-slim
|
FROM rust:1.77.2-slim-bookworm
|
||||||
USER 0:0
|
USER 0:0
|
||||||
WORKDIR /home/rust/src
|
WORKDIR /home/rust/src
|
||||||
|
|
||||||
@@ -24,6 +24,9 @@ COPY crates/core/permissions/Cargo.toml ./crates/core/permissions/
|
|||||||
COPY crates/core/presence/Cargo.toml ./crates/core/presence/
|
COPY crates/core/presence/Cargo.toml ./crates/core/presence/
|
||||||
COPY crates/core/result/Cargo.toml ./crates/core/result/
|
COPY crates/core/result/Cargo.toml ./crates/core/result/
|
||||||
COPY crates/services/autumn/Cargo.toml ./crates/services/autumn/
|
COPY crates/services/autumn/Cargo.toml ./crates/services/autumn/
|
||||||
|
COPY crates/services/january/Cargo.toml ./crates/services/january/
|
||||||
|
COPY crates/daemons/crond/Cargo.toml ./crates/daemons/crond/
|
||||||
|
COPY crates/daemons/pushd/Cargo.toml ./crates/daemons/pushd/
|
||||||
RUN sh /tmp/build-image-layer.sh deps
|
RUN sh /tmp/build-image-layer.sh deps
|
||||||
|
|
||||||
# Build all apps
|
# Build all apps
|
||||||
|
|||||||
@@ -1,24 +1,44 @@
|
|||||||
# Revolt Backend
|
<div align="center">
|
||||||
|
<h1>
|
||||||
|
Revolt Backend
|
||||||
|
|
||||||
|
[](https://github.com/revoltchat/backend/stargazers)
|
||||||
|
[](https://github.com/revoltchat/backend/network/members)
|
||||||
|
[](https://github.com/revoltchat/backend/pulls)
|
||||||
|
[](https://github.com/revoltchat/backend/issues)
|
||||||
|
[](https://github.com/revoltchat/backend/graphs/contributors)
|
||||||
|
[](https://github.com/revoltchat/backend/blob/main/LICENSE)
|
||||||
|
</h1>
|
||||||
|
The services and libraries that power the Revolt service.<br/>
|
||||||
|
<br/>
|
||||||
|
|
||||||
This is a monorepo for the Revolt backend.
|
| Crate | Path | Description | |
|
||||||
|
| ------------------ | -------------------------------------------------- | ---------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| `core/config` | [crates/core/config](crates/core/config) | Core: Configuration |     |
|
||||||
|
| `core/database` | [crates/core/database](crates/core/database) | Core: Database Implementation |     |
|
||||||
|
| `core/files` | [crates/core/files](crates/core/files) | Core: S3 and encryption subroutines |     |
|
||||||
|
| `core/models` | [crates/core/models](crates/core/models) | Core: API Models |     |
|
||||||
|
| `core/permissions` | [crates/core/permissions](crates/core/permissions) | Core: Permission Logic |     |
|
||||||
|
| `core/presence` | [crates/core/presence](crates/core/presence) | Core: User Presence |     |
|
||||||
|
| `core/result` | [crates/core/result](crates/core/result) | Core: Result and Error types |     |
|
||||||
|
| `delta` | [crates/delta](crates/delta) | REST API server |  |
|
||||||
|
| `bonfire` | [crates/bonfire](crates/bonfire) | WebSocket events server |  |
|
||||||
|
| `services/january` | [crates/services/january](crates/services/january) | Proxy server |  |
|
||||||
|
| `services/autumn` | [crates/services/autumn](crates/services/autumn) | File server |  |
|
||||||
|
| `bindings/node` | [crates/bindings/node](crates/bindings/node) | Node.js bindings for the Revolt software |  |
|
||||||
|
| `daemons/crond` | [crates/daemons/crond](crates/daemons/crond) | Timed data clean up daemon server |  |
|
||||||
|
| `daemons/pushd` | [crates/daemons/pushd](crates/daemons/pushd) | Push notification daemon server |  |
|
||||||
|
|
||||||
| Crate | Path | Description |
|
</div>
|
||||||
| ------------------ | -------------------------------------------------- | ----------------------------- |
|
<br/>
|
||||||
| `core/config` | [crates/core/config](crates/core/config) | Core: Configuration |
|
|
||||||
| `core/database` | [crates/core/database](crates/core/database) | Core: Database Implementation |
|
|
||||||
| `core/models` | [crates/core/models](crates/core/models) | Core: API Models |
|
|
||||||
| `core/permissions` | [crates/core/permissions](crates/core/permissions) | Core: Permission Logic |
|
|
||||||
| `core/presence` | [crates/core/presence](crates/core/presence) | Core: User Presence |
|
|
||||||
| `core/result` | [crates/core/result](crates/core/result) | Core: Result and Error types |
|
|
||||||
| `delta` | [crates/delta](crates/delta) | REST API server |
|
|
||||||
| `bonfire` | [crates/bonfire](crates/bonfire) | WebSocket events server |
|
|
||||||
|
|
||||||
Note: `january`, `autumn`, and `vortex` are yet to be moved into this monorepo.
|
|
||||||
|
|
||||||
## Minimum Supported Rust Version
|
## Minimum Supported Rust Version
|
||||||
|
|
||||||
Rust 1.76 or higher.
|
Rust 1.76 or higher.
|
||||||
|
|
||||||
|
> [!CAUTION]
|
||||||
|
> The events server has a significant performance regression between Rust 1.77.2 and 1.78.0 onwards, see [issue #341](https://github.com/revoltchat/backend/issues/341).
|
||||||
|
|
||||||
## Development Guide
|
## Development Guide
|
||||||
|
|
||||||
Before contributing, make yourself familiar with [our contribution guidelines](https://developers.revolt.chat/contrib.html) and the [technical documentation for this project](https://revoltchat.github.io/backend/).
|
Before contributing, make yourself familiar with [our contribution guidelines](https://developers.revolt.chat/contrib.html) and the [technical documentation for this project](https://revoltchat.github.io/backend/).
|
||||||
@@ -33,6 +53,21 @@ Before getting started, you'll want to install:
|
|||||||
> A **default.nix** is available for Nix users!
|
> A **default.nix** is available for Nix users!
|
||||||
> Just run `nix-shell` and continue.
|
> Just run `nix-shell` and continue.
|
||||||
|
|
||||||
|
As a heads-up, the development environment uses the following ports:
|
||||||
|
|
||||||
|
| Service | Port |
|
||||||
|
| ------------------------- | :------------: |
|
||||||
|
| MongoDB | 27017 |
|
||||||
|
| Redis | 6379 |
|
||||||
|
| MinIO | 14009 |
|
||||||
|
| Maildev | 14025<br>14080 |
|
||||||
|
| Revolt Web App | 14701 |
|
||||||
|
| RabbitMQ | 5672<br>15672 |
|
||||||
|
| `crates/delta` | 14702 |
|
||||||
|
| `crates/bonfire` | 14703 |
|
||||||
|
| `crates/services/autumn` | 14704 |
|
||||||
|
| `crates/services/january` | 14705 |
|
||||||
|
|
||||||
Now you can clone and build the project:
|
Now you can clone and build the project:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -41,34 +76,53 @@ cd revolt-backend
|
|||||||
cargo build
|
cargo build
|
||||||
```
|
```
|
||||||
|
|
||||||
If you want to run the API and event servers:
|
A default configuration `Revolt.toml` is present in this project that is suited for development.
|
||||||
|
|
||||||
```bash
|
If you'd like to change anything, create a `Revolt.overrides.toml` file and specify relevant variables.
|
||||||
# create environment file (will be deprecated in future)
|
|
||||||
cp .env.example .env
|
|
||||||
|
|
||||||
# (optionally) copy the default configuration file
|
> [!TIP]
|
||||||
cp crates/core/config/Revolt.toml Revolt.toml
|
> Use Sentry to catch unexpected service errors:
|
||||||
# configure as necessary...
|
>
|
||||||
```
|
> ```toml
|
||||||
|
> # Revolt.overrides.toml
|
||||||
|
> [sentry]
|
||||||
|
> api = "https://abc@your.sentry/1"
|
||||||
|
> events = "https://abc@your.sentry/1"
|
||||||
|
> files = "https://abc@your.sentry/1"
|
||||||
|
> proxy = "https://abc@your.sentry/1"
|
||||||
|
> ```
|
||||||
|
|
||||||
You may want to copy the following configuration:
|
> [!TIP]
|
||||||
|
> If you have port conflicts on common services, you can try the following:
|
||||||
```toml
|
>
|
||||||
# Revolt.toml
|
> ```yaml
|
||||||
[database]
|
> # compose.override.yml
|
||||||
mongodb = "mongodb://localhost"
|
> services:
|
||||||
redis = "redis://localhost"
|
> redis:
|
||||||
|
> ports: !override
|
||||||
[hosts]
|
> - "14079:6379"
|
||||||
app = "http://local.revolt.chat"
|
>
|
||||||
api = "http://local.revolt.chat:8000"
|
> database:
|
||||||
events = "ws://local.revolt.chat:9000"
|
> ports: !override
|
||||||
autumn = "http://local.revolt.chat:3000"
|
> - "14017:27017"
|
||||||
january = "http://local.revolt.chat:7000"
|
>
|
||||||
voso_legacy = ""
|
> rabbit:
|
||||||
voso_legacy_ws = ""
|
> ports: !override
|
||||||
```
|
> - "14072:5672"
|
||||||
|
> - "14672:15672"
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> And corresponding Revolt configuration:
|
||||||
|
>
|
||||||
|
> ```toml
|
||||||
|
> # Revolt.overrides.toml
|
||||||
|
> [database]
|
||||||
|
> mongodb = "mongodb://127.0.0.1:14017"
|
||||||
|
> redis = "redis://127.0.0.1:14079/"
|
||||||
|
>
|
||||||
|
> [rabbit]
|
||||||
|
> port = 14072
|
||||||
|
> ```
|
||||||
|
|
||||||
Then continue:
|
Then continue:
|
||||||
|
|
||||||
@@ -76,13 +130,23 @@ Then continue:
|
|||||||
# start other necessary services
|
# start other necessary services
|
||||||
docker compose up -d
|
docker compose up -d
|
||||||
|
|
||||||
|
# run everything together
|
||||||
|
./scripts/start.sh
|
||||||
|
# .. or individually
|
||||||
# run the API server
|
# run the API server
|
||||||
cargo run --bin revolt-delta
|
cargo run --bin revolt-delta
|
||||||
# run the events server
|
# run the events server
|
||||||
cargo run --bin revolt-bonfire
|
cargo run --bin revolt-bonfire
|
||||||
|
# run the file server
|
||||||
|
cargo run --bin revolt-autumn
|
||||||
|
# run the proxy server
|
||||||
|
cargo run --bin revolt-january
|
||||||
|
# run the push daemon (not usually needed in regular development)
|
||||||
|
cargo run --bin revolt-pushd
|
||||||
|
|
||||||
# hint:
|
# hint:
|
||||||
# mold -run <cargo build, cargo run, etc...>
|
# mold -run <cargo build, cargo run, etc...>
|
||||||
|
# mold -run ./scripts/start.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
You can start a web client by doing the following:
|
You can start a web client by doing the following:
|
||||||
@@ -96,10 +160,13 @@ git clone --recursive https://github.com/revoltchat/revite
|
|||||||
cd revite
|
cd revite
|
||||||
yarn
|
yarn
|
||||||
yarn build:deps
|
yarn build:deps
|
||||||
yarn dev --port 3001
|
echo "VITE_API_URL=http://local.revolt.chat:14702" > .env.local
|
||||||
|
yarn dev --port 14701
|
||||||
```
|
```
|
||||||
|
|
||||||
Then go to https://local.revolt.chat:3001
|
Then go to http://local.revolt.chat:14701 to create an account/login.
|
||||||
|
|
||||||
|
When signing up, go to http://localhost:14080 to find confirmation/password reset emails.
|
||||||
|
|
||||||
## Deployment Guide
|
## Deployment Guide
|
||||||
|
|
||||||
|
|||||||
+52
@@ -0,0 +1,52 @@
|
|||||||
|
# ⚠️ This configuration is intended for development environment.
|
||||||
|
# If you'd like to override anything, create a Revolt.override.toml
|
||||||
|
|
||||||
|
[database]
|
||||||
|
# MongoDB connection URL
|
||||||
|
# Defaults to the container name specified in self-hosted
|
||||||
|
mongodb = "mongodb://127.0.0.1:27017"
|
||||||
|
# Redis connection URL
|
||||||
|
# Defaults to the container name specified in self-hosted
|
||||||
|
redis = "redis://127.0.0.1:6379/"
|
||||||
|
|
||||||
|
[rabbit]
|
||||||
|
host = "127.0.0.1"
|
||||||
|
|
||||||
|
[hosts]
|
||||||
|
# Web locations of various services
|
||||||
|
# Defaults assume all services are reverse-proxied
|
||||||
|
# See https://github.com/revoltchat/self-hosted/blob/master/Caddyfile
|
||||||
|
#
|
||||||
|
# Remember to change these to https/wss where appropriate in production!
|
||||||
|
app = "http://local.revolt.chat:14701"
|
||||||
|
api = "http://local.revolt.chat:14702"
|
||||||
|
events = "ws://local.revolt.chat:14703"
|
||||||
|
autumn = "http://local.revolt.chat:14704"
|
||||||
|
january = "http://local.revolt.chat:14705"
|
||||||
|
voso_legacy = ""
|
||||||
|
voso_legacy_ws = ""
|
||||||
|
|
||||||
|
[api]
|
||||||
|
|
||||||
|
[api.smtp]
|
||||||
|
# Email server configuration for verification
|
||||||
|
# Defaults to no email verification (host field is empty)
|
||||||
|
host = "localhost"
|
||||||
|
username = "smtp"
|
||||||
|
password = "smtp"
|
||||||
|
from_address = "development@revolt.chat"
|
||||||
|
reply_to = "support@revolt.chat"
|
||||||
|
port = 14025
|
||||||
|
use_tls = false
|
||||||
|
|
||||||
|
[files.s3]
|
||||||
|
# S3 protocol endpoint
|
||||||
|
endpoint = "http://127.0.0.1:14009"
|
||||||
|
# S3 region name
|
||||||
|
region = "minio"
|
||||||
|
# S3 protocol key ID
|
||||||
|
access_key_id = "minioautumn"
|
||||||
|
# S3 protocol access key
|
||||||
|
secret_access_key = "minioautumn"
|
||||||
|
# Bucket to upload to by default
|
||||||
|
default_bucket = "revolt-uploads"
|
||||||
+66
@@ -0,0 +1,66 @@
|
|||||||
|
services:
|
||||||
|
# Redis
|
||||||
|
redis:
|
||||||
|
image: eqalpha/keydb
|
||||||
|
ports:
|
||||||
|
- "6379:6379"
|
||||||
|
|
||||||
|
# MongoDB
|
||||||
|
database:
|
||||||
|
image: mongo
|
||||||
|
ports:
|
||||||
|
- "27017:27017"
|
||||||
|
volumes:
|
||||||
|
- ./.data/db:/data/db
|
||||||
|
|
||||||
|
# MinIO
|
||||||
|
minio:
|
||||||
|
image: minio/minio
|
||||||
|
command: server /data
|
||||||
|
environment:
|
||||||
|
MINIO_ROOT_USER: minioautumn
|
||||||
|
MINIO_ROOT_PASSWORD: minioautumn
|
||||||
|
volumes:
|
||||||
|
- ./.data/minio:/data
|
||||||
|
ports:
|
||||||
|
- "14009:9000"
|
||||||
|
- "14010:9001"
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
# Create buckets for minio.
|
||||||
|
createbuckets:
|
||||||
|
image: minio/mc
|
||||||
|
depends_on:
|
||||||
|
- minio
|
||||||
|
entrypoint: >
|
||||||
|
/bin/sh -c "while ! /usr/bin/mc ready minio; do
|
||||||
|
/usr/bin/mc config host add minio http://minio:9000 minioautumn minioautumn;
|
||||||
|
echo 'Waiting minio...' && sleep 1;
|
||||||
|
done; /usr/bin/mc mb minio/revolt-uploads; exit 0;"
|
||||||
|
|
||||||
|
# Rabbit
|
||||||
|
rabbit:
|
||||||
|
image: rabbitmq:3-management
|
||||||
|
environment:
|
||||||
|
RABBITMQ_DEFAULT_USER: rabbituser
|
||||||
|
RABBITMQ_DEFAULT_PASS: rabbitpass
|
||||||
|
volumes:
|
||||||
|
- ./.data/rabbit:/var/lib/rabbitmq
|
||||||
|
#- ./rabbit_plugins:/opt/rabbitmq/plugins/
|
||||||
|
#- ./rabbit_enabled_plugins:/etc/rabbitmq/enabled_plugins
|
||||||
|
# uncomment this if you need to enable other plugins
|
||||||
|
ports:
|
||||||
|
- "5672:5672"
|
||||||
|
- "15672:15672" # management UI, for development
|
||||||
|
|
||||||
|
# Mock SMTP server
|
||||||
|
maildev:
|
||||||
|
image: soulteary/maildev
|
||||||
|
ports:
|
||||||
|
- "14025:25"
|
||||||
|
- "14080:8080"
|
||||||
|
environment:
|
||||||
|
MAILDEV_SMTP_PORT: 25
|
||||||
|
MAILDEV_WEB_PORT: 8080
|
||||||
|
MAILDEV_INCOMING_USER: smtp
|
||||||
|
MAILDEV_INCOMING_PASS: smtp
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-nodejs-bindings"
|
name = "revolt-nodejs-bindings"
|
||||||
version = "0.7.16"
|
version = "0.8.2"
|
||||||
description = "Node.js bindings for the Revolt software"
|
description = "Node.js bindings for the Revolt software"
|
||||||
authors = ["Paul Makles <me@insrt.uk>"]
|
authors = ["Paul Makles <me@insrt.uk>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
@@ -20,5 +20,6 @@ serde = { version = "1", features = ["derive"] }
|
|||||||
|
|
||||||
async-std = "1.12.0"
|
async-std = "1.12.0"
|
||||||
|
|
||||||
revolt-result = { version = "0.7.16", path = "../../core/result" }
|
revolt-config = { version = "0.8.2", path = "../../core/config" }
|
||||||
revolt-database = { version = "0.7.16", path = "../../core/database" }
|
revolt-result = { version = "0.8.2", path = "../../core/result" }
|
||||||
|
revolt-database = { version = "0.8.2", path = "../../core/database" }
|
||||||
|
|||||||
Vendored
+18
@@ -18,6 +18,12 @@ export declare interface Err {
|
|||||||
location: string;
|
location: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialises background tasks and logging, must be called before anything else!
|
||||||
|
* Can be called multiple times!
|
||||||
|
*/
|
||||||
|
export declare function init();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a new handle to the Revolt database
|
* Gets a new handle to the Revolt database
|
||||||
* @returns {Database} Handle
|
* @returns {Database} Handle
|
||||||
@@ -64,3 +70,15 @@ export declare function proc_channels_create_dm(
|
|||||||
userA: string,
|
userA: string,
|
||||||
userB: string
|
userB: string
|
||||||
): Promise<Channel & { error: Err }>;
|
): Promise<Channel & { error: Err }>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Suspend a user
|
||||||
|
* @param {string} user User
|
||||||
|
* @param {number} duration Duration (in days), set to 0 for indefinite
|
||||||
|
* @param {string} reason Pipe-separated list of reasons (e.g. reason1|reason2|reason3)
|
||||||
|
*/
|
||||||
|
export declare function proc_users_suspend(
|
||||||
|
user: OpaqueUser,
|
||||||
|
duration: number,
|
||||||
|
reason: string
|
||||||
|
): Promise<{ error: Err }>;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "revolt-nodejs-bindings",
|
"name": "revolt-nodejs-bindings",
|
||||||
"version": "0.7.15",
|
"version": "0.7.15-rev0.0.3",
|
||||||
"description": "Node.js bindings for the Revolt software",
|
"description": "Node.js bindings for the Revolt software",
|
||||||
"main": "index.node",
|
"main": "index.node",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -1,9 +1,35 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
|
|
||||||
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
use neon::prelude::*;
|
use neon::prelude::*;
|
||||||
use revolt_database::{Database, DatabaseInfo};
|
use revolt_database::{Database, DatabaseInfo};
|
||||||
|
|
||||||
|
fn js_init(mut cx: FunctionContext) -> JsResult<JsUndefined> {
|
||||||
|
// static INIT: OnceLock<()> = OnceLock::new();
|
||||||
|
// if INIT.get().is_none() {
|
||||||
|
// INIT.get_or_init(|| {
|
||||||
|
// async_std::task::block_on(async {
|
||||||
|
// revolt_config::configure!(api);
|
||||||
|
|
||||||
|
// match DatabaseInfo::Auto.connect().await {
|
||||||
|
// Ok(db) => {
|
||||||
|
// let authifier_db = db.clone().to_authifier().await.database;
|
||||||
|
// revolt_database::tasks::start_workers(db, authifier_db);
|
||||||
|
// Ok(())
|
||||||
|
// }
|
||||||
|
// Err(err) => Err(err),
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// .or_else(|err| cx.throw_error(err))
|
||||||
|
// .unwrap();
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
|
Ok(cx.undefined())
|
||||||
|
}
|
||||||
|
|
||||||
struct DatabaseBinding(Database, Channel);
|
struct DatabaseBinding(Database, Channel);
|
||||||
impl Finalize for DatabaseBinding {}
|
impl Finalize for DatabaseBinding {}
|
||||||
impl DatabaseBinding {
|
impl DatabaseBinding {
|
||||||
@@ -136,6 +162,9 @@ macro_rules! shim {
|
|||||||
|
|
||||||
#[neon::main]
|
#[neon::main]
|
||||||
fn main(mut cx: ModuleContext) -> NeonResult<()> {
|
fn main(mut cx: ModuleContext) -> NeonResult<()> {
|
||||||
|
// initialise required background stuff
|
||||||
|
cx.export_function("init", js_init)?;
|
||||||
|
|
||||||
// database & model stuff
|
// database & model stuff
|
||||||
cx.export_function("database", js_database)?;
|
cx.export_function("database", js_database)?;
|
||||||
cx.export_function("model_data", js_data)?;
|
cx.export_function("model_data", js_data)?;
|
||||||
@@ -178,10 +207,12 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> {
|
|||||||
shim!(
|
shim!(
|
||||||
cx,
|
cx,
|
||||||
proc_users_suspend,
|
proc_users_suspend,
|
||||||
,
|
duration JsNumber 1
|
||||||
|
reason JsString 2,
|
||||||
user User 0,
|
user User 0,
|
||||||
|db| async move {
|
|db| async move {
|
||||||
user.suspend(&db).await
|
let duration = duration as usize;
|
||||||
|
user.suspend(&db, if duration == 0 { None } else { Some(duration) }, Some(reason.split('|').map(|x| x.to_owned()).collect())).await
|
||||||
},
|
},
|
||||||
&user,
|
&user,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-bonfire"
|
name = "revolt-bonfire"
|
||||||
version = "0.7.16"
|
version = "0.8.2"
|
||||||
license = "AGPL-3.0-or-later"
|
license = "AGPL-3.0-or-later"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
@@ -36,12 +36,12 @@ async-std = { version = "1.8.0", features = [
|
|||||||
] }
|
] }
|
||||||
|
|
||||||
# core
|
# core
|
||||||
authifier = { version = "1.0.8" }
|
authifier = { version = "1.0.9" }
|
||||||
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" }
|
||||||
revolt-database = { path = "../core/database" }
|
revolt-database = { path = "../core/database" }
|
||||||
revolt-permissions = { version = "0.7.16", path = "../core/permissions" }
|
revolt-permissions = { version = "0.8.2", path = "../core/permissions" }
|
||||||
revolt-presence = { path = "../core/presence", features = ["redis-is-patched"] }
|
revolt-presence = { path = "../core/presence", features = ["redis-is-patched"] }
|
||||||
|
|
||||||
# redis
|
# redis
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
# Build Stage
|
# Build Stage
|
||||||
FROM ghcr.io/revoltchat/base:latest AS builder
|
FROM ghcr.io/revoltchat/base:latest AS builder
|
||||||
|
FROM debian:12 AS debian
|
||||||
|
|
||||||
# Bundle Stage
|
# Bundle Stage
|
||||||
FROM debian:bullseye-slim
|
FROM gcr.io/distroless/cc-debian12:nonroot
|
||||||
RUN apt-get update && \
|
|
||||||
apt-get install -y ca-certificates && \
|
|
||||||
apt-get clean
|
|
||||||
COPY --from=builder /home/rust/src/target/release/revolt-bonfire ./
|
COPY --from=builder /home/rust/src/target/release/revolt-bonfire ./
|
||||||
EXPOSE 9000
|
COPY --from=debian /usr/bin/uname /usr/bin/uname
|
||||||
|
|
||||||
|
EXPOSE 14703
|
||||||
|
USER nonroot
|
||||||
CMD ["./revolt-bonfire"]
|
CMD ["./revolt-bonfire"]
|
||||||
|
|||||||
@@ -19,11 +19,14 @@ async fn main() {
|
|||||||
database::connect().await;
|
database::connect().await;
|
||||||
|
|
||||||
// Clean up the current region information.
|
// Clean up the current region information.
|
||||||
clear_region(None).await;
|
let no_clear_region = env::var("NO_CLEAR_PRESENCE").unwrap_or_else(|_| "0".into()) == "1";
|
||||||
|
if !no_clear_region {
|
||||||
|
clear_region(None).await;
|
||||||
|
}
|
||||||
|
|
||||||
// Setup a TCP listener to accept WebSocket connections on.
|
// Setup a TCP listener to accept WebSocket connections on.
|
||||||
// By default, we bind to port 9000 on all interfaces.
|
// By default, we bind to port 14703 on all interfaces.
|
||||||
let bind = env::var("HOST").unwrap_or_else(|_| "0.0.0.0:9000".into());
|
let bind = env::var("HOST").unwrap_or_else(|_| "0.0.0.0:14703".into());
|
||||||
info!("Listening on host {bind}");
|
info!("Listening on host {bind}");
|
||||||
let try_socket = TcpListener::bind(bind).await;
|
let try_socket = TcpListener::bind(bind).await;
|
||||||
let listener = try_socket.expect("Failed to bind");
|
let listener = try_socket.expect("Failed to bind");
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ use futures::{
|
|||||||
FutureExt, SinkExt, StreamExt, TryStreamExt,
|
FutureExt, SinkExt, StreamExt, TryStreamExt,
|
||||||
};
|
};
|
||||||
use redis_kiss::{PayloadType, REDIS_PAYLOAD_TYPE, REDIS_URI};
|
use redis_kiss::{PayloadType, REDIS_PAYLOAD_TYPE, REDIS_URI};
|
||||||
|
use revolt_config::report_internal_error;
|
||||||
use revolt_database::{
|
use revolt_database::{
|
||||||
events::{client::EventV1, server::ClientMessage},
|
events::{client::EventV1, server::ClientMessage},
|
||||||
Database, User, UserHint,
|
Database, User, UserHint,
|
||||||
@@ -78,7 +79,9 @@ pub async fn client(db: &'static Database, stream: TcpStream, addr: SocketAddr)
|
|||||||
// Try to authenticate the user.
|
// Try to authenticate the user.
|
||||||
let Some(token) = config.get_session_token().as_ref() else {
|
let Some(token) = config.get_session_token().as_ref() else {
|
||||||
write
|
write
|
||||||
.send(config.encode(&create_error!(InvalidSession)))
|
.send(config.encode(&EventV1::Error {
|
||||||
|
data: create_error!(InvalidSession),
|
||||||
|
}))
|
||||||
.await
|
.await
|
||||||
.ok();
|
.ok();
|
||||||
return;
|
return;
|
||||||
@@ -87,7 +90,10 @@ pub async fn client(db: &'static Database, stream: TcpStream, addr: SocketAddr)
|
|||||||
let (user, session_id) = match User::from_token(db, token, UserHint::Any).await {
|
let (user, session_id) = match User::from_token(db, token, UserHint::Any).await {
|
||||||
Ok(user) => user,
|
Ok(user) => user,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
write.send(config.encode(&err)).await.ok();
|
write
|
||||||
|
.send(config.encode(&EventV1::Error { data: err }))
|
||||||
|
.await
|
||||||
|
.ok();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -99,27 +105,21 @@ pub async fn client(db: &'static Database, stream: TcpStream, addr: SocketAddr)
|
|||||||
let user_id = state.cache.user_id.clone();
|
let user_id = state.cache.user_id.clone();
|
||||||
|
|
||||||
// Notify socket we have authenticated.
|
// Notify socket we have authenticated.
|
||||||
if let Err(err) = write.send(config.encode(&EventV1::Authenticated)).await {
|
if report_internal_error!(write.send(config.encode(&EventV1::Authenticated)).await).is_err() {
|
||||||
error!("Failed to write: {err:?}");
|
|
||||||
sentry::capture_error(&err);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Download required data to local cache and send Ready payload.
|
// Download required data to local cache and send Ready payload.
|
||||||
let ready_payload = match state
|
let ready_payload = match report_internal_error!(
|
||||||
.generate_ready_payload(db, config.get_ready_payload_fields())
|
state
|
||||||
.await
|
.generate_ready_payload(db, config.get_ready_payload_fields())
|
||||||
{
|
.await
|
||||||
|
) {
|
||||||
Ok(ready_payload) => ready_payload,
|
Ok(ready_payload) => ready_payload,
|
||||||
Err(err) => {
|
Err(_) => return,
|
||||||
sentry::capture_error(&err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(err) = write.send(config.encode(&ready_payload)).await {
|
if report_internal_error!(write.send(config.encode(&ready_payload)).await).is_err() {
|
||||||
error!("Failed to write: {err:?}");
|
|
||||||
sentry::capture_error(&err);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,21 +214,16 @@ async fn listener(
|
|||||||
write: &Mutex<WsWriter>,
|
write: &Mutex<WsWriter>,
|
||||||
) {
|
) {
|
||||||
let redis_config = RedisConfig::from_url(&REDIS_URI).unwrap();
|
let redis_config = RedisConfig::from_url(&REDIS_URI).unwrap();
|
||||||
let subscriber = match fred::types::Builder::from_config(redis_config).build_subscriber_client()
|
let subscriber = match report_internal_error!(
|
||||||
{
|
fred::types::Builder::from_config(redis_config).build_subscriber_client()
|
||||||
|
) {
|
||||||
Ok(subscriber) => subscriber,
|
Ok(subscriber) => subscriber,
|
||||||
Err(err) => {
|
Err(_) => return,
|
||||||
error!("Failed to build a subscriber: {err:?}");
|
|
||||||
sentry::capture_error(&err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(err) = subscriber.init().await {
|
if report_internal_error!(subscriber.init().await).is_err() {
|
||||||
error!("Failed to init subscriber: {err:?}");
|
|
||||||
sentry::capture_error(&err);
|
|
||||||
return;
|
return;
|
||||||
};
|
}
|
||||||
|
|
||||||
// Handle Redis connection dropping
|
// Handle Redis connection dropping
|
||||||
let (clean_up_s, clean_up_r) = async_channel::bounded(1);
|
let (clean_up_s, clean_up_r) = async_channel::bounded(1);
|
||||||
@@ -249,17 +244,13 @@ async fn listener(
|
|||||||
// Check for state changes for subscriptions.
|
// Check for state changes for subscriptions.
|
||||||
match state.apply_state().await {
|
match state.apply_state().await {
|
||||||
SubscriptionStateChange::Reset => {
|
SubscriptionStateChange::Reset => {
|
||||||
if let Err(err) = subscriber.unsubscribe_all().await {
|
if report_internal_error!(subscriber.unsubscribe_all().await).is_err() {
|
||||||
error!("Unsubscribe all failed: {err:?}");
|
|
||||||
sentry::capture_error(&err);
|
|
||||||
break 'out;
|
break 'out;
|
||||||
}
|
}
|
||||||
|
|
||||||
let subscribed = state.subscribed.read().await;
|
let subscribed = state.subscribed.read().await;
|
||||||
for id in subscribed.iter() {
|
for id in subscribed.iter() {
|
||||||
if let Err(err) = subscriber.subscribe(id).await {
|
if report_internal_error!(subscriber.subscribe(id).await).is_err() {
|
||||||
error!("Subscribe failed: {err:?}");
|
|
||||||
sentry::capture_error(&err);
|
|
||||||
break 'out;
|
break 'out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -272,9 +263,7 @@ async fn listener(
|
|||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
info!("{addr:?} unsubscribing from {id}");
|
info!("{addr:?} unsubscribing from {id}");
|
||||||
|
|
||||||
if let Err(err) = subscriber.unsubscribe(id).await {
|
if report_internal_error!(subscriber.unsubscribe(id).await).is_err() {
|
||||||
error!("Unsubscribe failed: {err:?}");
|
|
||||||
sentry::capture_error(&err);
|
|
||||||
break 'out;
|
break 'out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -283,9 +272,7 @@ async fn listener(
|
|||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
info!("{addr:?} subscribing to {id}");
|
info!("{addr:?} subscribing to {id}");
|
||||||
|
|
||||||
if let Err(err) = subscriber.subscribe(id).await {
|
if report_internal_error!(subscriber.subscribe(id).await).is_err() {
|
||||||
error!("Subscribe failed: {err:?}");
|
|
||||||
sentry::capture_error(&err);
|
|
||||||
break 'out;
|
break 'out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -310,38 +297,32 @@ async fn listener(
|
|||||||
_ = t2 => {},
|
_ = t2 => {},
|
||||||
message = t1 => {
|
message = t1 => {
|
||||||
// Handle incoming events.
|
// Handle incoming events.
|
||||||
let message = match message {
|
let message = match report_internal_error!(message) {
|
||||||
Ok(message) => message,
|
Ok(message) => message,
|
||||||
Err(e) => {
|
Err(_) => break 'out
|
||||||
error!("Error while consuming pub/sub messages: {e:?}");
|
|
||||||
sentry::capture_error(&e);
|
|
||||||
break 'out;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let event = match *REDIS_PAYLOAD_TYPE {
|
let event = match *REDIS_PAYLOAD_TYPE {
|
||||||
PayloadType::Json => message
|
PayloadType::Json => message
|
||||||
.value
|
.value
|
||||||
.as_str()
|
.as_str()
|
||||||
.and_then(|s| serde_json::from_str::<EventV1>(s.as_ref()).ok()),
|
.and_then(|s| report_internal_error!(serde_json::from_str::<EventV1>(s.as_ref())).ok()),
|
||||||
PayloadType::Msgpack => message
|
PayloadType::Msgpack => message
|
||||||
.value
|
.value
|
||||||
.as_bytes()
|
.as_bytes()
|
||||||
.and_then(|b| rmp_serde::from_slice::<EventV1>(b).ok()),
|
.and_then(|b| report_internal_error!(rmp_serde::from_slice::<EventV1>(b)).ok()),
|
||||||
PayloadType::Bincode => message
|
PayloadType::Bincode => message
|
||||||
.value
|
.value
|
||||||
.as_bytes()
|
.as_bytes()
|
||||||
.and_then(|b| bincode::deserialize::<EventV1>(b).ok()),
|
.and_then(|b| report_internal_error!(bincode::deserialize::<EventV1>(b)).ok()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(mut event) = event else {
|
let Some(mut event) = event else {
|
||||||
let err = format!(
|
let err = format!(
|
||||||
"Failed to deserialise an event for {}! Introspection: `{:?}`",
|
"Failed to deserialise event for {}: `{:?}`",
|
||||||
message.channel,
|
message.channel,
|
||||||
message
|
message
|
||||||
.value
|
.value
|
||||||
.as_string()
|
|
||||||
.map(|x| x.chars().take(32).collect::<String>())
|
|
||||||
);
|
);
|
||||||
|
|
||||||
error!("{}", err);
|
error!("{}", err);
|
||||||
@@ -393,10 +374,7 @@ async fn listener(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(err) = subscriber.quit().await {
|
report_internal_error!(subscriber.quit().await).ok();
|
||||||
error!("{}", err);
|
|
||||||
sentry::capture_error(&err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-config"
|
name = "revolt-config"
|
||||||
version = "0.7.16"
|
version = "0.8.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
authors = ["Paul Makles <me@insrt.uk>"]
|
authors = ["Paul Makles <me@insrt.uk>"]
|
||||||
@@ -9,12 +9,12 @@ description = "Revolt Backend: Configuration"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
report-macros = ["revolt-result"]
|
||||||
test = ["async-std"]
|
test = ["async-std"]
|
||||||
default = ["test"]
|
default = ["test"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# Utility
|
# Utility
|
||||||
dotenv = "0.15.0"
|
|
||||||
config = "0.13.3"
|
config = "0.13.3"
|
||||||
cached = "0.44.0"
|
cached = "0.44.0"
|
||||||
once_cell = "1.18.0"
|
once_cell = "1.18.0"
|
||||||
@@ -32,3 +32,6 @@ pretty_env_logger = "0.4.0"
|
|||||||
|
|
||||||
# Sentry
|
# Sentry
|
||||||
sentry = "0.31.5"
|
sentry = "0.31.5"
|
||||||
|
|
||||||
|
# Core
|
||||||
|
revolt-result = { version = "0.8.2", path = "../result", optional = true }
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
[database]
|
[database]
|
||||||
mongodb = "mongodb://localhost"
|
mongodb = "mongodb://localhost"
|
||||||
redis = "redis://localhost/"
|
redis = "redis://localhost/"
|
||||||
|
|
||||||
|
[rabbit]
|
||||||
|
host = "127.0.0.1"
|
||||||
|
port = 5672
|
||||||
|
username = "rabbituser"
|
||||||
|
password = "rabbitpass"
|
||||||
|
|||||||
+128
-53
@@ -20,6 +20,12 @@ january = "http://local.revolt.chat/january"
|
|||||||
voso_legacy = ""
|
voso_legacy = ""
|
||||||
voso_legacy_ws = ""
|
voso_legacy_ws = ""
|
||||||
|
|
||||||
|
[rabbit]
|
||||||
|
host = "rabbit"
|
||||||
|
port = 5672
|
||||||
|
username = "rabbituser"
|
||||||
|
password = "rabbitpass"
|
||||||
|
|
||||||
[api]
|
[api]
|
||||||
|
|
||||||
[api.registration]
|
[api.registration]
|
||||||
@@ -34,38 +40,10 @@ host = ""
|
|||||||
username = ""
|
username = ""
|
||||||
password = ""
|
password = ""
|
||||||
from_address = "noreply@example.com"
|
from_address = "noreply@example.com"
|
||||||
reply_to = "noreply@example.com"
|
# reply_to = "noreply@example.com"
|
||||||
port = 587
|
# port = 587
|
||||||
use_tls = true
|
# use_tls = true
|
||||||
|
|
||||||
[api.vapid]
|
|
||||||
# Generate your own keys:
|
|
||||||
# 1. Run `openssl ecparam -name prime256v1 -genkey -noout -out vapid_private.pem`
|
|
||||||
# 2. Find `private_key` using `base64 vapid_private.pem`
|
|
||||||
# 3. Find `public_key` using `openssl ec -in vapid_private.pem -outform DER|tail -c 65|base64|tr '/+' '_-'|tr -d '\n'`
|
|
||||||
private_key = "LS0tLS1CRUdJTiBFQyBQUklWQVRFIEtFWS0tLS0tCk1IY0NBUUVFSUJSUWpyTWxLRnBiVWhsUHpUbERvcEliYk1yeVNrNXpKYzVYVzIxSjJDS3hvQW9HQ0NxR1NNNDkKQXdFSG9VUURRZ0FFWnkrQkg2TGJQZ2hEa3pEempXOG0rUXVPM3pCajRXT1phdkR6ZU00c0pqbmFwd1psTFE0WAp1ZDh2TzVodU94QWhMQlU3WWRldVovWHlBdFpWZmNyQi9BPT0KLS0tLS1FTkQgRUMgUFJJVkFURSBLRVktLS0tLQo"
|
|
||||||
public_key = "BGcvgR-i2z4IQ5Mw841vJvkLjt8wY-FjmWrw83jOLCY52qcGZS0OF7nfLzuYbjsQISwVO2HXrmf18gLWVX3Kwfw="
|
|
||||||
|
|
||||||
[api.fcm]
|
|
||||||
# Google Firebase Cloud Messaging Service Account Key
|
|
||||||
# Obtained from the cloud messaging console
|
|
||||||
key_type = ""
|
|
||||||
project_id = ""
|
|
||||||
private_key_id = ""
|
|
||||||
private_key = ""
|
|
||||||
client_email = ""
|
|
||||||
client_id = ""
|
|
||||||
auth_uri = ""
|
|
||||||
token_uri = ""
|
|
||||||
auth_provider_x509_cert_url = ""
|
|
||||||
client_x509_cert_url = ""
|
|
||||||
|
|
||||||
[api.apn]
|
|
||||||
# Apple Push Notifications keys for sending notifications
|
|
||||||
sandbox = false
|
|
||||||
pkcs8 = ""
|
|
||||||
key_id = ""
|
|
||||||
team_id = ""
|
|
||||||
|
|
||||||
[api.security]
|
[api.security]
|
||||||
# Authifier Shield API key
|
# Authifier Shield API key
|
||||||
@@ -84,12 +62,72 @@ hcaptcha_sitekey = ""
|
|||||||
# Maximum concurrent connections (to proxy server)
|
# Maximum concurrent connections (to proxy server)
|
||||||
max_concurrent_connections = 50
|
max_concurrent_connections = 50
|
||||||
|
|
||||||
|
[pushd]
|
||||||
|
# this changes the names of the queues to not overlap
|
||||||
|
# prod/beta if they happen to be on the same exchange/instance.
|
||||||
|
# Usually they have to be, so that messages sent from one or the other get sent to everyone
|
||||||
|
production = true
|
||||||
|
|
||||||
|
# none of these should need changing
|
||||||
|
exchange = "revolt.notifications"
|
||||||
|
message_queue = "notifications.origin.message"
|
||||||
|
fr_accepted_queue = "notifications.ingest.fr_accepted" # friend request accepted
|
||||||
|
fr_received_queue = "notifications.ingest.fr_received" # friend request received
|
||||||
|
generic_queue = "notifications.ingest.generic" # generic messages (title + body)
|
||||||
|
ack_queue = "notifications.process.ack" # updates badges for apple devices
|
||||||
|
|
||||||
|
[pushd.vapid]
|
||||||
|
queue = "notifications.outbound.vapid"
|
||||||
|
private_key = "LS0tLS1CRUdJTiBFQyBQUklWQVRFIEtFWS0tLS0tCk1IY0NBUUVFSUJSUWpyTWxLRnBiVWhsUHpUbERvcEliYk1yeVNrNXpKYzVYVzIxSjJDS3hvQW9HQ0NxR1NNNDkKQXdFSG9VUURRZ0FFWnkrQkg2TGJQZ2hEa3pEempXOG0rUXVPM3pCajRXT1phdkR6ZU00c0pqbmFwd1psTFE0WAp1ZDh2TzVodU94QWhMQlU3WWRldVovWHlBdFpWZmNyQi9BPT0KLS0tLS1FTkQgRUMgUFJJVkFURSBLRVktLS0tLQo"
|
||||||
|
public_key = "BGcvgR-i2z4IQ5Mw841vJvkLjt8wY-FjmWrw83jOLCY52qcGZS0OF7nfLzuYbjsQISwVO2HXrmf18gLWVX3Kwfw="
|
||||||
|
|
||||||
|
[pushd.fcm]
|
||||||
|
queue = "notifications.outbound.fcm"
|
||||||
|
key_type = ""
|
||||||
|
project_id = ""
|
||||||
|
private_key_id = ""
|
||||||
|
private_key = ""
|
||||||
|
client_email = ""
|
||||||
|
client_id = ""
|
||||||
|
auth_uri = ""
|
||||||
|
token_uri = ""
|
||||||
|
auth_provider_x509_cert_url = ""
|
||||||
|
client_x509_cert_url = ""
|
||||||
|
|
||||||
|
[pushd.apn]
|
||||||
|
sandbox = false
|
||||||
|
queue = "notifications.outbound.apn"
|
||||||
|
pkcs8 = ""
|
||||||
|
key_id = ""
|
||||||
|
team_id = ""
|
||||||
|
|
||||||
|
|
||||||
[files]
|
[files]
|
||||||
# Encryption key for stored files
|
# Encryption key for stored files
|
||||||
# Generate your own key using `openssl rand -base64 32`
|
# Generate your own key using `openssl rand -base64 32`
|
||||||
encryption_key = "qcuMA+ssxhMyKaNAKBGFfryfFtUH8NDlamQyDwGW6fU="
|
encryption_key = "qcuMA+ssxhMyKaNAKBGFfryfFtUH8NDlamQyDwGW6fU="
|
||||||
|
# Quality used for lossy WebP previews (set to 100 for lossless)
|
||||||
|
webp_quality = 80.0
|
||||||
|
# Mime types that cannot be uploaded or served
|
||||||
|
#
|
||||||
|
# Example for Windows executables and Android installation files:
|
||||||
|
# ["application/vnd.microsoft.portable-executable", "application/vnd.android.package-archive"]
|
||||||
|
blocked_mime_types = []
|
||||||
|
# ClamAV service
|
||||||
|
# hostname:port
|
||||||
|
clamd_host = ""
|
||||||
|
# Mime types that should be virus scanned
|
||||||
|
#
|
||||||
|
# Leave empty to scan all file types
|
||||||
|
scan_mime_types = [
|
||||||
|
"application/vnd.microsoft.portable-executable",
|
||||||
|
"application/vnd.android.package-archive",
|
||||||
|
"application/zip",
|
||||||
|
]
|
||||||
|
|
||||||
[files.limit]
|
[files.limit]
|
||||||
|
# Minimum file size (in bytes)
|
||||||
|
min_file_size = 1
|
||||||
# Minimum image resolution
|
# Minimum image resolution
|
||||||
min_resolution = [1, 1]
|
min_resolution = [1, 1]
|
||||||
# Maximum MP of images
|
# Maximum MP of images
|
||||||
@@ -112,23 +150,28 @@ emojis = [128, 128]
|
|||||||
#
|
#
|
||||||
# Backblaze B2:
|
# Backblaze B2:
|
||||||
# - endpoint is listed on the "Buckets" page
|
# - endpoint is listed on the "Buckets" page
|
||||||
|
# - path_style_buckets is set to true
|
||||||
# - region is `eu-central-003` string from endpoint URL
|
# - region is `eu-central-003` string from endpoint URL
|
||||||
# - access_key_id is keyID generated on the "Application Keys" page
|
# - access_key_id is keyID generated on the "Application Keys" page
|
||||||
# - secret_access_key is token generated on the "Application Keys" page
|
# - secret_access_key is token generated on the "Application Keys" page
|
||||||
# - default_bucket matches the name of the bucket you've created
|
# - default_bucket matches the name of the bucket you've created
|
||||||
|
|
||||||
# S3 protocol endpoint
|
# S3 protocol endpoint
|
||||||
endpoint = ""
|
endpoint = "http://minio:9000"
|
||||||
|
# Whether to use path-style buckets
|
||||||
|
# Generally true, except for MinIO
|
||||||
|
path_style_buckets = false
|
||||||
# S3 region name
|
# S3 region name
|
||||||
region = ""
|
region = "minio"
|
||||||
# S3 protocol key ID
|
# S3 protocol key ID
|
||||||
access_key_id = ""
|
access_key_id = "minioautumn"
|
||||||
# S3 protocol access key
|
# S3 protocol access key
|
||||||
secret_access_key = ""
|
secret_access_key = "minioautumn"
|
||||||
# Bucket to upload to by default
|
|
||||||
default_bucket = "revolt-uploads"
|
default_bucket = "revolt-uploads"
|
||||||
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
# Bucket to upload to by default
|
||||||
# Feature gate options
|
# Feature gate options
|
||||||
webhooks_enabled = false
|
webhooks_enabled = false
|
||||||
|
|
||||||
@@ -143,44 +186,76 @@ server_emoji = 100
|
|||||||
server_roles = 200
|
server_roles = 200
|
||||||
server_channels = 200
|
server_channels = 200
|
||||||
|
|
||||||
# How many days since creation a user is considered new
|
# How many hours since creation a user is considered new
|
||||||
new_user_days = 3
|
new_user_hours = 72
|
||||||
|
|
||||||
# Maximum permissible body size in bytes for uploads
|
# Maximum permissible body size in bytes for uploads
|
||||||
# (should be greater than any one file upload limit)
|
# (should be greater than any one file upload limit)
|
||||||
body_limit_size = 20_000_000
|
body_limit_size = 20_000_000
|
||||||
|
|
||||||
[features.limits.new_user]
|
[features.limits.new_user]
|
||||||
|
# Limits imposed on new users
|
||||||
|
|
||||||
|
# Number of outgoing friend requests permitted at any time
|
||||||
outgoing_friend_requests = 5
|
outgoing_friend_requests = 5
|
||||||
|
|
||||||
|
# Maximum number of owned bots
|
||||||
bots = 2
|
bots = 2
|
||||||
message_length = 2000
|
|
||||||
message_attachments = 5
|
|
||||||
servers = 100
|
|
||||||
|
|
||||||
attachment_size = 20_000_000
|
# Message content length
|
||||||
avatar_size = 4_000_000
|
message_length = 2000
|
||||||
background_size = 6_000_000
|
|
||||||
icon_size = 2_500_000
|
# Number of attachments that can be included
|
||||||
banner_size = 6_000_000
|
message_attachments = 5
|
||||||
emoji_size = 500_000
|
|
||||||
|
# Maximum number of servers the user can create/join
|
||||||
|
servers = 50
|
||||||
|
|
||||||
|
[features.limits.new_user.file_upload_size_limit]
|
||||||
|
# Maximum file size limits (in bytes)
|
||||||
|
attachments = 20_000_000
|
||||||
|
avatars = 4_000_000
|
||||||
|
backgrounds = 6_000_000
|
||||||
|
icons = 2_500_000
|
||||||
|
banners = 6_000_000
|
||||||
|
emojis = 500_000
|
||||||
|
|
||||||
[features.limits.default]
|
[features.limits.default]
|
||||||
|
# Limits imposed on users by default
|
||||||
|
|
||||||
|
# Number of outgoing friend requests permitted at any time
|
||||||
outgoing_friend_requests = 10
|
outgoing_friend_requests = 10
|
||||||
|
|
||||||
|
# Maximum number of owned bots
|
||||||
bots = 5
|
bots = 5
|
||||||
|
|
||||||
|
# Message content length
|
||||||
message_length = 2000
|
message_length = 2000
|
||||||
|
|
||||||
|
# Number of attachments that can be included
|
||||||
message_attachments = 5
|
message_attachments = 5
|
||||||
|
|
||||||
|
# Maximum number of servers the user can create/join
|
||||||
servers = 100
|
servers = 100
|
||||||
|
|
||||||
attachment_size = 20_000_000
|
[features.limits.default.file_upload_size_limit]
|
||||||
avatar_size = 4_000_000
|
# Maximum file size limits (in bytes)
|
||||||
background_size = 6_000_000
|
attachments = 20_000_000
|
||||||
icon_size = 2_500_000
|
avatars = 4_000_000
|
||||||
banner_size = 6_000_000
|
backgrounds = 6_000_000
|
||||||
emoji_size = 500_000
|
icons = 2_500_000
|
||||||
|
banners = 6_000_000
|
||||||
|
emojis = 500_000
|
||||||
|
|
||||||
|
[features.advanced]
|
||||||
|
# The max amount of messages the rabbitmq provider/db mention adder job will delay for before forcing handling of a channel.
|
||||||
|
# default: 5
|
||||||
|
process_message_delay_limit = 5
|
||||||
|
|
||||||
[sentry]
|
[sentry]
|
||||||
# Configuration for Sentry error reporting
|
# Configuration for Sentry error reporting
|
||||||
api = ""
|
api = ""
|
||||||
events = ""
|
events = ""
|
||||||
|
files = ""
|
||||||
|
proxy = ""
|
||||||
|
crond = ""
|
||||||
|
|||||||
+177
-34
@@ -6,11 +6,60 @@ use futures_locks::RwLock;
|
|||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
pub use sentry::capture_error;
|
pub use sentry::{capture_error, capture_message, Level};
|
||||||
|
|
||||||
#[cfg(not(debug_assertions))]
|
#[cfg(feature = "report-macros")]
|
||||||
use std::env;
|
#[macro_export]
|
||||||
|
macro_rules! report_error {
|
||||||
|
( $expr: expr, $error: ident $( $tt:tt )? ) => {
|
||||||
|
$expr
|
||||||
|
.inspect_err(|err| {
|
||||||
|
$crate::capture_message(
|
||||||
|
&format!("{err:?} ({}:{}:{})", file!(), line!(), column!()),
|
||||||
|
$crate::Level::Error,
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.map_err(|_| ::revolt_result::create_error!($error))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "report-macros")]
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! capture_internal_error {
|
||||||
|
( $expr: expr ) => {
|
||||||
|
$crate::capture_message(
|
||||||
|
&format!("{:?} ({}:{}:{})", $expr, file!(), line!(), column!()),
|
||||||
|
$crate::Level::Error,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "report-macros")]
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! report_internal_error {
|
||||||
|
( $expr: expr ) => {
|
||||||
|
$expr
|
||||||
|
.inspect_err(|err| {
|
||||||
|
$crate::capture_message(
|
||||||
|
&format!("{err:?} ({}:{}:{})", file!(), line!(), column!()),
|
||||||
|
$crate::Level::Error,
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.map_err(|_| ::revolt_result::create_error!(InternalError))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Paths to search for configuration
|
||||||
|
static CONFIG_SEARCH_PATHS: [&str; 3] = [
|
||||||
|
// current working directory
|
||||||
|
"Revolt.toml",
|
||||||
|
// current working directory - overrides file
|
||||||
|
"Revolt.overrides.toml",
|
||||||
|
// root directory, for Docker containers
|
||||||
|
"/Revolt.toml",
|
||||||
|
];
|
||||||
|
|
||||||
|
/// Configuration builder
|
||||||
static CONFIG_BUILDER: Lazy<RwLock<Config>> = Lazy::new(|| {
|
static CONFIG_BUILDER: Lazy<RwLock<Config>> = Lazy::new(|| {
|
||||||
RwLock::new({
|
RwLock::new({
|
||||||
let mut builder = Config::builder().add_source(File::from_str(
|
let mut builder = Config::builder().add_source(File::from_str(
|
||||||
@@ -23,22 +72,32 @@ static CONFIG_BUILDER: Lazy<RwLock<Config>> = Lazy::new(|| {
|
|||||||
include_str!("../Revolt.test.toml"),
|
include_str!("../Revolt.test.toml"),
|
||||||
FileFormat::Toml,
|
FileFormat::Toml,
|
||||||
));
|
));
|
||||||
} else if std::path::Path::new("Revolt.toml").exists() {
|
}
|
||||||
builder = builder.add_source(File::new("Revolt.toml", FileFormat::Toml));
|
|
||||||
|
for path in CONFIG_SEARCH_PATHS {
|
||||||
|
if std::path::Path::new(path).exists() {
|
||||||
|
builder = builder.add_source(File::new(path, FileFormat::Toml));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.build().unwrap()
|
builder.build().unwrap()
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
// https://gifbox.me/view/gT5mqxYKCZv-twilight-meow
|
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Clone)]
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
pub struct Database {
|
pub struct Database {
|
||||||
pub mongodb: String,
|
pub mongodb: String,
|
||||||
pub redis: String,
|
pub redis: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
|
pub struct Rabbit {
|
||||||
|
pub host: String,
|
||||||
|
pub port: u16,
|
||||||
|
pub username: String,
|
||||||
|
pub password: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Clone)]
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
pub struct Hosts {
|
pub struct Hosts {
|
||||||
pub app: String,
|
pub app: String,
|
||||||
@@ -67,13 +126,15 @@ pub struct ApiSmtp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Clone)]
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
pub struct ApiVapid {
|
pub struct PushVapid {
|
||||||
|
pub queue: String,
|
||||||
pub private_key: String,
|
pub private_key: String,
|
||||||
pub public_key: String,
|
pub public_key: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Clone)]
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
pub struct ApiFcm {
|
pub struct PushFcm {
|
||||||
|
pub queue: String,
|
||||||
pub key_type: String,
|
pub key_type: String,
|
||||||
pub project_id: String,
|
pub project_id: String,
|
||||||
pub private_key_id: String,
|
pub private_key_id: String,
|
||||||
@@ -87,7 +148,8 @@ pub struct ApiFcm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Clone)]
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
pub struct ApiApn {
|
pub struct PushApn {
|
||||||
|
pub queue: String,
|
||||||
pub sandbox: bool,
|
pub sandbox: bool,
|
||||||
pub pkcs8: String,
|
pub pkcs8: String,
|
||||||
pub key_id: String,
|
pub key_id: String,
|
||||||
@@ -117,13 +179,85 @@ pub struct ApiWorkers {
|
|||||||
pub struct Api {
|
pub struct Api {
|
||||||
pub registration: ApiRegistration,
|
pub registration: ApiRegistration,
|
||||||
pub smtp: ApiSmtp,
|
pub smtp: ApiSmtp,
|
||||||
pub vapid: ApiVapid,
|
|
||||||
pub fcm: ApiFcm,
|
|
||||||
pub apn: ApiApn,
|
|
||||||
pub security: ApiSecurity,
|
pub security: ApiSecurity,
|
||||||
pub workers: ApiWorkers,
|
pub workers: ApiWorkers,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
|
pub struct Pushd {
|
||||||
|
pub production: bool,
|
||||||
|
pub exchange: String,
|
||||||
|
pub message_queue: String,
|
||||||
|
pub fr_accepted_queue: String,
|
||||||
|
pub fr_received_queue: String,
|
||||||
|
pub generic_queue: String,
|
||||||
|
pub ack_queue: String,
|
||||||
|
|
||||||
|
pub vapid: PushVapid,
|
||||||
|
pub fcm: PushFcm,
|
||||||
|
pub apn: PushApn,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Pushd {
|
||||||
|
fn get_routing_key(&self, key: String) -> String {
|
||||||
|
match self.production {
|
||||||
|
true => key + "-prd",
|
||||||
|
false => key + "-tst",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_ack_routing_key(&self) -> String {
|
||||||
|
self.get_routing_key(self.ack_queue.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_message_routing_key(&self) -> String {
|
||||||
|
self.get_routing_key(self.message_queue.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_fr_accepted_routing_key(&self) -> String {
|
||||||
|
self.get_routing_key(self.fr_accepted_queue.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_fr_received_routing_key(&self) -> String {
|
||||||
|
self.get_routing_key(self.fr_received_queue.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_generic_routing_key(&self) -> String {
|
||||||
|
self.get_routing_key(self.generic_queue.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
|
pub struct FilesLimit {
|
||||||
|
pub min_file_size: usize,
|
||||||
|
pub min_resolution: [usize; 2],
|
||||||
|
pub max_mega_pixels: usize,
|
||||||
|
pub max_pixel_side: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
|
pub struct FilesS3 {
|
||||||
|
pub endpoint: String,
|
||||||
|
pub path_style_buckets: bool,
|
||||||
|
pub region: String,
|
||||||
|
pub access_key_id: String,
|
||||||
|
pub secret_access_key: String,
|
||||||
|
pub default_bucket: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
|
pub struct Files {
|
||||||
|
pub encryption_key: String,
|
||||||
|
pub webp_quality: f32,
|
||||||
|
pub blocked_mime_types: Vec<String>,
|
||||||
|
pub clamd_host: String,
|
||||||
|
pub scan_mime_types: Vec<String>,
|
||||||
|
|
||||||
|
pub limit: FilesLimit,
|
||||||
|
pub preview: HashMap<String, [usize; 2]>,
|
||||||
|
pub s3: FilesS3,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Clone)]
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
pub struct GlobalLimits {
|
pub struct GlobalLimits {
|
||||||
pub group_size: usize,
|
pub group_size: usize,
|
||||||
@@ -134,7 +268,7 @@ pub struct GlobalLimits {
|
|||||||
pub server_roles: usize,
|
pub server_roles: usize,
|
||||||
pub server_channels: usize,
|
pub server_channels: usize,
|
||||||
|
|
||||||
pub new_user_days: usize,
|
pub new_user_hours: usize,
|
||||||
|
|
||||||
pub body_limit_size: usize,
|
pub body_limit_size: usize,
|
||||||
}
|
}
|
||||||
@@ -148,12 +282,7 @@ pub struct FeaturesLimits {
|
|||||||
pub message_attachments: usize,
|
pub message_attachments: usize,
|
||||||
pub servers: usize,
|
pub servers: usize,
|
||||||
|
|
||||||
pub attachment_size: usize,
|
pub file_upload_size_limit: HashMap<String, usize>,
|
||||||
pub avatar_size: usize,
|
|
||||||
pub background_size: usize,
|
|
||||||
pub icon_size: usize,
|
|
||||||
pub banner_size: usize,
|
|
||||||
pub emoji_size: usize,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Clone)]
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
@@ -167,23 +296,45 @@ pub struct FeaturesLimitsCollection {
|
|||||||
pub roles: HashMap<String, FeaturesLimits>,
|
pub roles: HashMap<String, FeaturesLimits>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
|
pub struct FeaturesAdvanced {
|
||||||
|
#[serde(default)]
|
||||||
|
pub process_message_delay_limit: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for FeaturesAdvanced {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
process_message_delay_limit: 5,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Clone)]
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
pub struct Features {
|
pub struct Features {
|
||||||
pub limits: FeaturesLimitsCollection,
|
pub limits: FeaturesLimitsCollection,
|
||||||
pub webhooks_enabled: bool,
|
pub webhooks_enabled: bool,
|
||||||
|
#[serde(default)]
|
||||||
|
pub advanced: FeaturesAdvanced,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Clone)]
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
pub struct Sentry {
|
pub struct Sentry {
|
||||||
pub api: String,
|
pub api: String,
|
||||||
pub events: String,
|
pub events: String,
|
||||||
|
pub files: String,
|
||||||
|
pub proxy: String,
|
||||||
|
pub crond: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Clone)]
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
pub database: Database,
|
pub database: Database,
|
||||||
|
pub rabbit: Rabbit,
|
||||||
pub hosts: Hosts,
|
pub hosts: Hosts,
|
||||||
pub api: Api,
|
pub api: Api,
|
||||||
|
pub pushd: Pushd,
|
||||||
|
pub files: Files,
|
||||||
pub features: Features,
|
pub features: Features,
|
||||||
pub sentry: Sentry,
|
pub sentry: Sentry,
|
||||||
}
|
}
|
||||||
@@ -191,22 +342,10 @@ pub struct Settings {
|
|||||||
impl Settings {
|
impl Settings {
|
||||||
pub fn preflight_checks(&self) {
|
pub fn preflight_checks(&self) {
|
||||||
if self.api.smtp.host.is_empty() {
|
if self.api.smtp.host.is_empty() {
|
||||||
#[cfg(not(debug_assertions))]
|
|
||||||
if !env::var("REVOLT_UNSAFE_NO_EMAIL").map_or(false, |v| v == *"1") {
|
|
||||||
panic!("Running in production without email is not recommended, set REVOLT_UNSAFE_NO_EMAIL=1 to override.");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
log::warn!("No SMTP settings specified! Remember to configure email.");
|
log::warn!("No SMTP settings specified! Remember to configure email.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.api.security.captcha.hcaptcha_key.is_empty() {
|
if self.api.security.captcha.hcaptcha_key.is_empty() {
|
||||||
#[cfg(not(debug_assertions))]
|
|
||||||
if !env::var("REVOLT_UNSAFE_NO_CAPTCHA").map_or(false, |v| v == *"1") {
|
|
||||||
panic!("Running in production without CAPTCHA is not recommended, set REVOLT_UNSAFE_NO_CAPTCHA=1 to override.");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
log::warn!("No Captcha key specified! Remember to add hCaptcha key.");
|
log::warn!("No Captcha key specified! Remember to add hCaptcha key.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -230,8 +369,6 @@ pub async fn config() -> Settings {
|
|||||||
|
|
||||||
/// Configure logging and common Rust variables
|
/// Configure logging and common Rust variables
|
||||||
pub async fn setup_logging(release: &'static str, dsn: String) -> Option<sentry::ClientInitGuard> {
|
pub async fn setup_logging(release: &'static str, dsn: String) -> Option<sentry::ClientInitGuard> {
|
||||||
dotenv::dotenv().ok();
|
|
||||||
|
|
||||||
if std::env::var("RUST_LOG").is_err() {
|
if std::env::var("RUST_LOG").is_err() {
|
||||||
std::env::set_var("RUST_LOG", "info");
|
std::env::set_var("RUST_LOG", "info");
|
||||||
}
|
}
|
||||||
@@ -240,6 +377,12 @@ pub async fn setup_logging(release: &'static str, dsn: String) -> Option<sentry:
|
|||||||
std::env::set_var("ROCKET_ADDRESS", "0.0.0.0");
|
std::env::set_var("ROCKET_ADDRESS", "0.0.0.0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if std::env::var("REDIS_URL").is_err() {
|
||||||
|
// Configure redis-kiss library
|
||||||
|
let config = config().await;
|
||||||
|
std::env::set_var("REDIS_URI", config.database.redis);
|
||||||
|
}
|
||||||
|
|
||||||
pretty_env_logger::init();
|
pretty_env_logger::init();
|
||||||
log::info!("Starting {release}");
|
log::info!("Starting {release}");
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-database"
|
name = "revolt-database"
|
||||||
version = "0.7.16"
|
version = "0.8.2"
|
||||||
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>"]
|
||||||
@@ -16,6 +16,7 @@ mongodb = ["dep:mongodb", "bson"]
|
|||||||
tasks = ["isahc", "linkify", "url-escape"]
|
tasks = ["isahc", "linkify", "url-escape"]
|
||||||
async-std-runtime = ["async-std"]
|
async-std-runtime = ["async-std"]
|
||||||
rocket-impl = ["rocket", "schemars", "revolt_okapi", "revolt_rocket_okapi"]
|
rocket-impl = ["rocket", "schemars", "revolt_okapi", "revolt_rocket_okapi"]
|
||||||
|
axum-impl = ["axum"]
|
||||||
redis-is-patched = ["revolt-presence/redis-is-patched"]
|
redis-is-patched = ["revolt-presence/redis-is-patched"]
|
||||||
|
|
||||||
# Default Features
|
# Default Features
|
||||||
@@ -23,13 +24,15 @@ default = ["mongodb", "async-std-runtime", "tasks"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# Core
|
# Core
|
||||||
revolt-config = { version = "0.7.16", path = "../config" }
|
revolt-config = { version = "0.8.2", path = "../config", features = [
|
||||||
revolt-result = { version = "0.7.16", path = "../result" }
|
"report-macros",
|
||||||
revolt-models = { version = "0.7.16", path = "../models", features = [
|
] }
|
||||||
|
revolt-result = { version = "0.8.2", path = "../result" }
|
||||||
|
revolt-models = { version = "0.8.2", path = "../models", features = [
|
||||||
"validator",
|
"validator",
|
||||||
] }
|
] }
|
||||||
revolt-presence = { version = "0.7.16", path = "../presence" }
|
revolt-presence = { version = "0.8.2", path = "../presence" }
|
||||||
revolt-permissions = { version = "0.7.16", path = "../permissions", features = [
|
revolt-permissions = { version = "0.8.2", path = "../permissions", features = [
|
||||||
"serde",
|
"serde",
|
||||||
"bson",
|
"bson",
|
||||||
] }
|
] }
|
||||||
@@ -76,13 +79,16 @@ async-recursion = "1.0.4"
|
|||||||
# Async
|
# Async
|
||||||
async-std = { version = "1.8.0", features = ["attributes"], optional = true }
|
async-std = { version = "1.8.0", features = ["attributes"], optional = true }
|
||||||
|
|
||||||
|
# Axum Impl
|
||||||
|
axum = { version = "0.7.5", optional = true }
|
||||||
|
|
||||||
# Rocket Impl
|
# Rocket Impl
|
||||||
schemars = { version = "0.8.8", optional = true }
|
schemars = { version = "0.8.8", optional = true }
|
||||||
rocket = { version = "0.5.0-rc.2", default-features = false, features = [
|
rocket = { version = "0.5.1", default-features = false, features = [
|
||||||
"json",
|
"json",
|
||||||
], optional = true }
|
], optional = true }
|
||||||
revolt_okapi = { version = "0.9.1", optional = true }
|
revolt_okapi = { version = "0.9.1", optional = true }
|
||||||
revolt_rocket_okapi = { version = "0.9.1", optional = true }
|
revolt_rocket_okapi = { version = "0.10.0", optional = true }
|
||||||
|
|
||||||
# Notifications
|
# Notifications
|
||||||
fcm_v1 = "0.3.0"
|
fcm_v1 = "0.3.0"
|
||||||
@@ -90,4 +96,7 @@ web-push = "0.10.0"
|
|||||||
revolt_a2 = { version = "0.10", default-features = false, features = ["ring"] }
|
revolt_a2 = { version = "0.10", default-features = false, features = ["ring"] }
|
||||||
|
|
||||||
# Authifier
|
# Authifier
|
||||||
authifier = { version = "1.0.8" }
|
authifier = { version = "1.0.9", features = ["rocket_impl"] }
|
||||||
|
|
||||||
|
# RabbitMQ
|
||||||
|
amqprs = { version = "1.7.0" }
|
||||||
|
|||||||
@@ -0,0 +1,211 @@
|
|||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
use crate::events::rabbit::*;
|
||||||
|
use crate::User;
|
||||||
|
use amqprs::channel::BasicPublishArguments;
|
||||||
|
use amqprs::{channel::Channel, connection::Connection, error::Error as AMQPError};
|
||||||
|
use amqprs::{BasicProperties, FieldTable};
|
||||||
|
use revolt_models::v0::PushNotification;
|
||||||
|
use revolt_presence::filter_online;
|
||||||
|
|
||||||
|
use serde_json::to_string;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct AMQP {
|
||||||
|
#[allow(unused)]
|
||||||
|
connection: Connection,
|
||||||
|
channel: Channel,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AMQP {
|
||||||
|
pub fn new(connection: Connection, channel: Channel) -> AMQP {
|
||||||
|
AMQP {
|
||||||
|
connection,
|
||||||
|
channel,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn friend_request_accepted(
|
||||||
|
&self,
|
||||||
|
accepted_request_user: &User,
|
||||||
|
sent_request_user: &User,
|
||||||
|
) -> Result<(), AMQPError> {
|
||||||
|
let config = revolt_config::config().await;
|
||||||
|
let payload = FRAcceptedPayload {
|
||||||
|
accepted_user: accepted_request_user.to_owned(),
|
||||||
|
user: sent_request_user.id.clone(),
|
||||||
|
};
|
||||||
|
let payload = to_string(&payload).unwrap();
|
||||||
|
|
||||||
|
debug!(
|
||||||
|
"Sending friend request accept payload on channel {}: {}",
|
||||||
|
config.pushd.get_fr_accepted_routing_key(),
|
||||||
|
payload
|
||||||
|
);
|
||||||
|
self.channel
|
||||||
|
.basic_publish(
|
||||||
|
BasicProperties::default()
|
||||||
|
.with_content_type("application/json")
|
||||||
|
.with_persistence(true)
|
||||||
|
.finish(),
|
||||||
|
payload.into(),
|
||||||
|
BasicPublishArguments::new(
|
||||||
|
&config.pushd.exchange,
|
||||||
|
&config.pushd.get_fr_accepted_routing_key(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn friend_request_received(
|
||||||
|
&self,
|
||||||
|
received_request_user: &User,
|
||||||
|
sent_request_user: &User,
|
||||||
|
) -> Result<(), AMQPError> {
|
||||||
|
let config = revolt_config::config().await;
|
||||||
|
let payload = FRReceivedPayload {
|
||||||
|
from_user: sent_request_user.to_owned(),
|
||||||
|
user: received_request_user.id.clone(),
|
||||||
|
};
|
||||||
|
let payload = to_string(&payload).unwrap();
|
||||||
|
|
||||||
|
debug!(
|
||||||
|
"Sending friend request received payload on channel {}: {}",
|
||||||
|
config.pushd.get_fr_received_routing_key(),
|
||||||
|
payload
|
||||||
|
);
|
||||||
|
|
||||||
|
self.channel
|
||||||
|
.basic_publish(
|
||||||
|
BasicProperties::default()
|
||||||
|
.with_content_type("application/json")
|
||||||
|
.with_persistence(true)
|
||||||
|
.finish(),
|
||||||
|
payload.into(),
|
||||||
|
BasicPublishArguments::new(
|
||||||
|
&config.pushd.exchange,
|
||||||
|
&config.pushd.get_fr_received_routing_key(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn generic_message(
|
||||||
|
&self,
|
||||||
|
user: &User,
|
||||||
|
title: String,
|
||||||
|
body: String,
|
||||||
|
icon: Option<String>,
|
||||||
|
) -> Result<(), AMQPError> {
|
||||||
|
let config = revolt_config::config().await;
|
||||||
|
let payload = GenericPayload {
|
||||||
|
title,
|
||||||
|
body,
|
||||||
|
icon,
|
||||||
|
user: user.to_owned(),
|
||||||
|
};
|
||||||
|
let payload = to_string(&payload).unwrap();
|
||||||
|
|
||||||
|
debug!(
|
||||||
|
"Sending generic payload on channel {}: {}",
|
||||||
|
config.pushd.get_generic_routing_key(),
|
||||||
|
payload
|
||||||
|
);
|
||||||
|
|
||||||
|
self.channel
|
||||||
|
.basic_publish(
|
||||||
|
BasicProperties::default()
|
||||||
|
.with_content_type("application/json")
|
||||||
|
.with_persistence(true)
|
||||||
|
.finish(),
|
||||||
|
payload.into(),
|
||||||
|
BasicPublishArguments::new(
|
||||||
|
&config.pushd.exchange,
|
||||||
|
&config.pushd.get_generic_routing_key(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn message_sent(
|
||||||
|
&self,
|
||||||
|
recipients: Vec<String>,
|
||||||
|
payload: PushNotification,
|
||||||
|
) -> Result<(), AMQPError> {
|
||||||
|
if recipients.is_empty() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let config = revolt_config::config().await;
|
||||||
|
|
||||||
|
let online_ids = filter_online(&recipients).await;
|
||||||
|
let recipients = (&recipients.into_iter().collect::<HashSet<String>>() - &online_ids)
|
||||||
|
.into_iter()
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
|
let payload = MessageSentPayload {
|
||||||
|
notification: payload,
|
||||||
|
users: recipients,
|
||||||
|
};
|
||||||
|
let payload = to_string(&payload).unwrap();
|
||||||
|
|
||||||
|
debug!(
|
||||||
|
"Sending message payload on channel {}: {}",
|
||||||
|
config.pushd.get_message_routing_key(),
|
||||||
|
payload
|
||||||
|
);
|
||||||
|
|
||||||
|
self.channel
|
||||||
|
.basic_publish(
|
||||||
|
BasicProperties::default()
|
||||||
|
.with_content_type("application/json")
|
||||||
|
.with_persistence(true)
|
||||||
|
.finish(),
|
||||||
|
payload.into(),
|
||||||
|
BasicPublishArguments::new(
|
||||||
|
&config.pushd.exchange,
|
||||||
|
&config.pushd.get_message_routing_key(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn ack_message(
|
||||||
|
&self,
|
||||||
|
user_id: String,
|
||||||
|
channel_id: String,
|
||||||
|
message_id: String,
|
||||||
|
) -> Result<(), AMQPError> {
|
||||||
|
let config = revolt_config::config().await;
|
||||||
|
|
||||||
|
let payload = AckPayload {
|
||||||
|
user_id: user_id.clone(),
|
||||||
|
channel_id: channel_id.clone(),
|
||||||
|
message_id,
|
||||||
|
};
|
||||||
|
let payload = to_string(&payload).unwrap();
|
||||||
|
|
||||||
|
info!(
|
||||||
|
"Sending ack payload on channel {}: {}",
|
||||||
|
config.pushd.ack_queue, payload
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut headers = FieldTable::new();
|
||||||
|
headers.insert(
|
||||||
|
"x-deduplication-header".try_into().unwrap(),
|
||||||
|
format!("{}-{}", &user_id, &channel_id).into(),
|
||||||
|
);
|
||||||
|
|
||||||
|
self.channel
|
||||||
|
.basic_publish(
|
||||||
|
BasicProperties::default()
|
||||||
|
.with_content_type("application/json")
|
||||||
|
.with_persistence(true)
|
||||||
|
//.with_headers(headers)
|
||||||
|
.finish(),
|
||||||
|
payload.into(),
|
||||||
|
BasicPublishArguments::new(&config.pushd.exchange, &config.pushd.ack_queue),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
#[allow(clippy::module_inception)]
|
||||||
|
pub mod amqp;
|
||||||
@@ -1,6 +1,14 @@
|
|||||||
mod mongodb;
|
mod mongodb;
|
||||||
mod reference;
|
mod reference;
|
||||||
|
|
||||||
|
use authifier::config::Captcha;
|
||||||
|
use authifier::config::EmailVerificationConfig;
|
||||||
|
use authifier::config::ResolveIp;
|
||||||
|
use authifier::config::SMTPSettings;
|
||||||
|
use authifier::config::Shield;
|
||||||
|
use authifier::config::Template;
|
||||||
|
use authifier::config::Templates;
|
||||||
|
use authifier::Authifier;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use revolt_config::config;
|
use revolt_config::config;
|
||||||
|
|
||||||
@@ -87,3 +95,87 @@ impl DatabaseInfo {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Database {
|
||||||
|
/// Create an Authifier reference
|
||||||
|
pub async fn to_authifier(self) -> Authifier {
|
||||||
|
let config = config().await;
|
||||||
|
|
||||||
|
let mut auth_config = authifier::Config {
|
||||||
|
email_verification: if !config.api.smtp.host.is_empty() {
|
||||||
|
EmailVerificationConfig::Enabled {
|
||||||
|
smtp: SMTPSettings {
|
||||||
|
from: config.api.smtp.from_address,
|
||||||
|
host: config.api.smtp.host,
|
||||||
|
username: config.api.smtp.username,
|
||||||
|
password: config.api.smtp.password,
|
||||||
|
reply_to: Some(
|
||||||
|
config
|
||||||
|
.api
|
||||||
|
.smtp
|
||||||
|
.reply_to
|
||||||
|
.unwrap_or("support@revolt.chat".into()),
|
||||||
|
),
|
||||||
|
port: config.api.smtp.port,
|
||||||
|
use_tls: config.api.smtp.use_tls,
|
||||||
|
},
|
||||||
|
expiry: Default::default(),
|
||||||
|
templates: Templates {
|
||||||
|
verify: Template {
|
||||||
|
title: "Verify your Revolt account.".into(),
|
||||||
|
text: include_str!("../../templates/verify.txt").into(),
|
||||||
|
url: format!("{}/login/verify/", config.hosts.app),
|
||||||
|
html: Some(include_str!("../../templates/verify.html").into()),
|
||||||
|
},
|
||||||
|
reset: Template {
|
||||||
|
title: "Reset your Revolt password.".into(),
|
||||||
|
text: include_str!("../../templates/reset.txt").into(),
|
||||||
|
url: format!("{}/login/reset/", config.hosts.app),
|
||||||
|
html: Some(include_str!("../../templates/reset.html").into()),
|
||||||
|
},
|
||||||
|
deletion: Template {
|
||||||
|
title: "Confirm account deletion.".into(),
|
||||||
|
text: include_str!("../../templates/deletion.txt").into(),
|
||||||
|
url: format!("{}/delete/", config.hosts.app),
|
||||||
|
html: Some(include_str!("../../templates/deletion.html").into()),
|
||||||
|
},
|
||||||
|
welcome: None,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
EmailVerificationConfig::Disabled
|
||||||
|
},
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
auth_config.invite_only = config.api.registration.invite_only;
|
||||||
|
|
||||||
|
if !config.api.security.captcha.hcaptcha_key.is_empty() {
|
||||||
|
auth_config.captcha = Captcha::HCaptcha {
|
||||||
|
secret: config.api.security.captcha.hcaptcha_key,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if !config.api.security.authifier_shield_key.is_empty() {
|
||||||
|
auth_config.shield = Shield::Enabled {
|
||||||
|
api_key: config.api.security.authifier_shield_key,
|
||||||
|
strict: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.api.security.trust_cloudflare {
|
||||||
|
auth_config.resolve_ip = ResolveIp::Cloudflare;
|
||||||
|
}
|
||||||
|
|
||||||
|
Authifier {
|
||||||
|
database: match self {
|
||||||
|
Database::Reference(_) => Default::default(),
|
||||||
|
Database::MongoDb(MongoDb(client, _)) => authifier::Database::MongoDb(
|
||||||
|
authifier::database::MongoDb(client.database("revolt")),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
config: auth_config,
|
||||||
|
event_channel: Some(crate::tasks::authifier_relay::sender()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use std::{collections::HashMap, sync::Arc};
|
|||||||
use futures::lock::Mutex;
|
use futures::lock::Mutex;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Bot, Channel, ChannelCompositeKey, ChannelUnread, Emoji, File, Invite, Member,
|
Bot, Channel, ChannelCompositeKey, ChannelUnread, Emoji, File, FileHash, Invite, Member,
|
||||||
MemberCompositeKey, Message, RatelimitEvent, Report, Server, ServerBan, Snapshot, User,
|
MemberCompositeKey, Message, RatelimitEvent, Report, Server, ServerBan, Snapshot, User,
|
||||||
UserSettings, Webhook,
|
UserSettings, Webhook,
|
||||||
};
|
};
|
||||||
@@ -18,6 +18,7 @@ database_derived!(
|
|||||||
pub channel_unreads: Arc<Mutex<HashMap<ChannelCompositeKey, ChannelUnread>>>,
|
pub channel_unreads: Arc<Mutex<HashMap<ChannelCompositeKey, ChannelUnread>>>,
|
||||||
pub channel_webhooks: Arc<Mutex<HashMap<String, Webhook>>>,
|
pub channel_webhooks: Arc<Mutex<HashMap<String, Webhook>>>,
|
||||||
pub emojis: Arc<Mutex<HashMap<String, Emoji>>>,
|
pub emojis: Arc<Mutex<HashMap<String, Emoji>>>,
|
||||||
|
pub file_hashes: Arc<Mutex<HashMap<String, FileHash>>>,
|
||||||
pub files: Arc<Mutex<HashMap<String, File>>>,
|
pub files: Arc<Mutex<HashMap<String, File>>>,
|
||||||
pub messages: Arc<Mutex<HashMap<String, Message>>>,
|
pub messages: Arc<Mutex<HashMap<String, Message>>>,
|
||||||
pub ratelimit_events: Arc<Mutex<HashMap<String, RatelimitEvent>>>,
|
pub ratelimit_events: Arc<Mutex<HashMap<String, RatelimitEvent>>>,
|
||||||
|
|||||||
@@ -1,25 +1,16 @@
|
|||||||
use authifier::AuthifierEvent;
|
use authifier::AuthifierEvent;
|
||||||
|
use revolt_result::Error;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use revolt_models::v0::{
|
use revolt_models::v0::{
|
||||||
AppendMessage, Channel, ChannelUnread, Emoji, FieldsChannel, FieldsMember, FieldsMessage, FieldsRole, FieldsServer, FieldsUser, FieldsWebhook, Member, MemberCompositeKey, Message, PartialChannel, PartialMember, PartialMessage, PartialRole, PartialServer, PartialUser, PartialWebhook, RemovalIntention, Report, Server, User, UserSettings, Webhook
|
AppendMessage, Channel, ChannelUnread, Emoji, FieldsChannel, FieldsMember, FieldsMessage,
|
||||||
|
FieldsRole, FieldsServer, FieldsUser, FieldsWebhook, Member, MemberCompositeKey, Message,
|
||||||
|
PartialChannel, PartialMember, PartialMessage, PartialRole, PartialServer, PartialUser,
|
||||||
|
PartialWebhook, RemovalIntention, Report, Server, User, UserSettings, Webhook,
|
||||||
};
|
};
|
||||||
use revolt_result::Error;
|
|
||||||
|
|
||||||
use crate::Database;
|
use crate::Database;
|
||||||
|
|
||||||
/// WebSocket Client Errors
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
||||||
#[serde(tag = "error")]
|
|
||||||
pub enum WebSocketError {
|
|
||||||
LabelMe,
|
|
||||||
InternalError { at: String },
|
|
||||||
InvalidSession,
|
|
||||||
OnboardingNotFinished,
|
|
||||||
AlreadyAuthenticated,
|
|
||||||
MalformedData { msg: String },
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Ping Packet
|
/// Ping Packet
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
@@ -28,14 +19,6 @@ pub enum Ping {
|
|||||||
Number(usize),
|
Number(usize),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Untagged Error
|
|
||||||
#[derive(Serialize)]
|
|
||||||
#[serde(untagged)]
|
|
||||||
pub enum ErrorEvent {
|
|
||||||
Error(WebSocketError),
|
|
||||||
APIError(Error),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Fields provided in Ready payload
|
/// Fields provided in Ready payload
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
pub enum ReadyPayloadFields {
|
pub enum ReadyPayloadFields {
|
||||||
@@ -55,6 +38,8 @@ pub enum ReadyPayloadFields {
|
|||||||
pub enum EventV1 {
|
pub enum EventV1 {
|
||||||
/// Multiple events
|
/// Multiple events
|
||||||
Bulk { v: Vec<EventV1> },
|
Bulk { v: Vec<EventV1> },
|
||||||
|
/// Error event
|
||||||
|
Error { data: Error },
|
||||||
|
|
||||||
/// Successfully authenticated
|
/// Successfully authenticated
|
||||||
Authenticated,
|
Authenticated,
|
||||||
@@ -89,6 +74,7 @@ pub enum EventV1 {
|
|||||||
id: String,
|
id: String,
|
||||||
channel: String,
|
channel: String,
|
||||||
data: PartialMessage,
|
data: PartialMessage,
|
||||||
|
#[serde(default)]
|
||||||
clear: Vec<FieldsMessage>,
|
clear: Vec<FieldsMessage>,
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -140,6 +126,7 @@ pub enum EventV1 {
|
|||||||
ServerUpdate {
|
ServerUpdate {
|
||||||
id: String,
|
id: String,
|
||||||
data: PartialServer,
|
data: PartialServer,
|
||||||
|
#[serde(default)]
|
||||||
clear: Vec<FieldsServer>,
|
clear: Vec<FieldsServer>,
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -150,6 +137,7 @@ pub enum EventV1 {
|
|||||||
ServerMemberUpdate {
|
ServerMemberUpdate {
|
||||||
id: MemberCompositeKey,
|
id: MemberCompositeKey,
|
||||||
data: PartialMember,
|
data: PartialMember,
|
||||||
|
#[serde(default)]
|
||||||
clear: Vec<FieldsMember>,
|
clear: Vec<FieldsMember>,
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -168,6 +156,7 @@ pub enum EventV1 {
|
|||||||
id: String,
|
id: String,
|
||||||
role_id: String,
|
role_id: String,
|
||||||
data: PartialRole,
|
data: PartialRole,
|
||||||
|
#[serde(default)]
|
||||||
clear: Vec<FieldsRole>,
|
clear: Vec<FieldsRole>,
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -178,6 +167,7 @@ pub enum EventV1 {
|
|||||||
UserUpdate {
|
UserUpdate {
|
||||||
id: String,
|
id: String,
|
||||||
data: PartialUser,
|
data: PartialUser,
|
||||||
|
#[serde(default)]
|
||||||
clear: Vec<FieldsUser>,
|
clear: Vec<FieldsUser>,
|
||||||
event_id: Option<String>,
|
event_id: Option<String>,
|
||||||
},
|
},
|
||||||
@@ -212,6 +202,7 @@ pub enum EventV1 {
|
|||||||
ChannelUpdate {
|
ChannelUpdate {
|
||||||
id: String,
|
id: String,
|
||||||
data: PartialChannel,
|
data: PartialChannel,
|
||||||
|
#[serde(default)]
|
||||||
clear: Vec<FieldsChannel>,
|
clear: Vec<FieldsChannel>,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
pub mod client;
|
pub mod client;
|
||||||
|
pub mod rabbit;
|
||||||
pub mod server;
|
pub mod server;
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use revolt_models::v0::PushNotification;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::User;
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct MessageSentPayload {
|
||||||
|
pub notification: PushNotification,
|
||||||
|
pub users: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct FRAcceptedPayload {
|
||||||
|
pub accepted_user: User,
|
||||||
|
pub user: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct FRReceivedPayload {
|
||||||
|
pub from_user: User,
|
||||||
|
pub user: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct GenericPayload {
|
||||||
|
pub title: String,
|
||||||
|
pub body: String,
|
||||||
|
pub icon: Option<String>,
|
||||||
|
pub user: User,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
#[serde(tag = "type", content = "data")]
|
||||||
|
#[allow(clippy::large_enum_variant)]
|
||||||
|
pub enum PayloadKind {
|
||||||
|
MessageNotification(PushNotification),
|
||||||
|
FRAccepted(FRAcceptedPayload),
|
||||||
|
FRReceived(FRReceivedPayload),
|
||||||
|
BadgeUpdate(usize),
|
||||||
|
Generic(GenericPayload),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct PayloadToService {
|
||||||
|
pub notification: PayloadKind,
|
||||||
|
pub user_id: String,
|
||||||
|
pub session_id: String,
|
||||||
|
pub token: String,
|
||||||
|
pub extras: HashMap<String, String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct AckPayload {
|
||||||
|
pub user_id: String,
|
||||||
|
pub channel_id: String,
|
||||||
|
pub message_id: String,
|
||||||
|
}
|
||||||
@@ -16,6 +16,8 @@ extern crate revolt_optional_struct;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate revolt_result;
|
extern crate revolt_result;
|
||||||
|
|
||||||
|
pub use iso8601_timestamp;
|
||||||
|
|
||||||
#[cfg(feature = "mongodb")]
|
#[cfg(feature = "mongodb")]
|
||||||
pub use mongodb;
|
pub use mongodb;
|
||||||
|
|
||||||
@@ -23,6 +25,26 @@ pub use mongodb;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate bson;
|
extern crate bson;
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
macro_rules! query {
|
||||||
|
( $self: ident, $type: ident, $collection: expr, $($rest:expr),+ ) => {
|
||||||
|
Ok($self.$type($collection, $($rest),+).await.unwrap())
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
#[cfg(not(debug_assertions))]
|
||||||
|
macro_rules! query {
|
||||||
|
( $self: ident, $type: ident, $collection: expr, $($rest:expr),+ ) => {
|
||||||
|
$self.$type($collection, $($rest),+).await
|
||||||
|
.map_err(|err| {
|
||||||
|
revolt_config::capture_internal_error!(err);
|
||||||
|
create_database_error!(stringify!($type), $collection)
|
||||||
|
})
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! database_derived {
|
macro_rules! database_derived {
|
||||||
( $( $item:item )+ ) => {
|
( $( $item:item )+ ) => {
|
||||||
$(
|
$(
|
||||||
@@ -83,6 +105,9 @@ pub use models::*;
|
|||||||
pub mod events;
|
pub mod events;
|
||||||
pub mod tasks;
|
pub mod tasks;
|
||||||
|
|
||||||
|
mod amqp;
|
||||||
|
pub use amqp::amqp::AMQP;
|
||||||
|
|
||||||
/// Utility function to check if a boolean value is false
|
/// Utility function to check if a boolean value is false
|
||||||
pub fn if_false(t: &bool) -> bool {
|
pub fn if_false(t: &bool) -> bool {
|
||||||
!t
|
!t
|
||||||
@@ -91,4 +116,4 @@ pub fn if_false(t: &bool) -> bool {
|
|||||||
/// Utility function to check if an option doesnt contain true
|
/// Utility function to check if an option doesnt contain true
|
||||||
pub fn if_option_false(t: &Option<bool>) -> bool {
|
pub fn if_option_false(t: &Option<bool>) -> bool {
|
||||||
t != &Some(true)
|
t != &Some(true)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,6 +56,10 @@ pub async fn create_database(db: &MongoDb) {
|
|||||||
.await
|
.await
|
||||||
.expect("Failed to create attachments collection.");
|
.expect("Failed to create attachments collection.");
|
||||||
|
|
||||||
|
db.create_collection("attachment_hashes", None)
|
||||||
|
.await
|
||||||
|
.expect("Failed to create attachment_hashes collection.");
|
||||||
|
|
||||||
db.create_collection("user_settings", None)
|
db.create_collection("user_settings", None)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to create user_settings collection.");
|
.expect("Failed to create user_settings collection.");
|
||||||
@@ -209,6 +213,46 @@ pub async fn create_database(db: &MongoDb) {
|
|||||||
.await
|
.await
|
||||||
.expect("Failed to create server_members index.");
|
.expect("Failed to create server_members index.");
|
||||||
|
|
||||||
|
db.run_command(
|
||||||
|
doc! {
|
||||||
|
"createIndexes": "attachments",
|
||||||
|
"indexes": [
|
||||||
|
{
|
||||||
|
"key": {
|
||||||
|
"hash": 1_i32
|
||||||
|
},
|
||||||
|
"name": "hash"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": {
|
||||||
|
"used_for.id": 1_i32
|
||||||
|
},
|
||||||
|
"name": "used_for_id"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("Failed to create attachments index.");
|
||||||
|
|
||||||
|
db.run_command(
|
||||||
|
doc! {
|
||||||
|
"createIndexes": "attachment_hashes",
|
||||||
|
"indexes": [
|
||||||
|
{
|
||||||
|
"key": {
|
||||||
|
"processed_hash": 1_i32
|
||||||
|
},
|
||||||
|
"name": "processed_hash"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("Failed to create attachment_hashes index.");
|
||||||
|
|
||||||
db.collection("migrations")
|
db.collection("migrations")
|
||||||
.insert_one(
|
.insert_one(
|
||||||
doc! {
|
doc! {
|
||||||
|
|||||||
@@ -5,12 +5,13 @@ use crate::{
|
|||||||
bson::{doc, from_bson, from_document, to_document, Bson, DateTime, Document},
|
bson::{doc, from_bson, from_document, to_document, Bson, DateTime, Document},
|
||||||
options::FindOptions,
|
options::FindOptions,
|
||||||
},
|
},
|
||||||
Invite, MongoDb, DISCRIMINATOR_SEARCH_SPACE,
|
AbstractChannels, AbstractServers, Channel, Invite, MongoDb, DISCRIMINATOR_SEARCH_SPACE,
|
||||||
};
|
};
|
||||||
use bson::oid::ObjectId;
|
use bson::oid::ObjectId;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use rand::seq::SliceRandom;
|
use rand::seq::SliceRandom;
|
||||||
use revolt_permissions::DEFAULT_WEBHOOK_PERMISSIONS;
|
use revolt_permissions::DEFAULT_WEBHOOK_PERMISSIONS;
|
||||||
|
use revolt_result::{Error, ErrorType};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
|
||||||
@@ -20,7 +21,7 @@ struct MigrationInfo {
|
|||||||
revision: i32,
|
revision: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const LATEST_REVISION: i32 = 28;
|
pub const LATEST_REVISION: i32 = 31;
|
||||||
|
|
||||||
pub async fn migrate_database(db: &MongoDb) {
|
pub async fn migrate_database(db: &MongoDb) {
|
||||||
let migrations = db.col::<Document>("migrations");
|
let migrations = db.col::<Document>("migrations");
|
||||||
@@ -1094,7 +1095,137 @@ pub async fn run_migrations(db: &MongoDb, revision: i32) -> i32 {
|
|||||||
.expect("Failed to create message index.");
|
.expect("Failed to create message index.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to migrate fields on attachments, change `user_id`, `object_id`, etc to `parent`.
|
if revision <= 28 {
|
||||||
|
info!("Running migration [revision 28 / 10-09-2024]: Add support for new Autumn.");
|
||||||
|
|
||||||
|
db.db()
|
||||||
|
.create_collection("attachment_hashes", None)
|
||||||
|
.await
|
||||||
|
.ok();
|
||||||
|
|
||||||
|
db.db()
|
||||||
|
.run_command(
|
||||||
|
doc! {
|
||||||
|
"createIndexes": "attachments",
|
||||||
|
"indexes": [
|
||||||
|
{
|
||||||
|
"key": {
|
||||||
|
"hash": 1_i32
|
||||||
|
},
|
||||||
|
"name": "hash"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("Failed to create attachments index.");
|
||||||
|
|
||||||
|
db.db()
|
||||||
|
.run_command(
|
||||||
|
doc! {
|
||||||
|
"createIndexes": "attachment_hashes",
|
||||||
|
"indexes": [
|
||||||
|
{
|
||||||
|
"key": {
|
||||||
|
"processed_hash": 1_i32
|
||||||
|
},
|
||||||
|
"name": "processed_hash"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("Failed to create attachment_hashes index.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Revision 29 omitted due to bug.
|
||||||
|
|
||||||
|
if revision <= 30 {
|
||||||
|
info!("Running migration [revision 30 / 29-09-2024]: Add index for used_for.id to attachments.");
|
||||||
|
|
||||||
|
db.db()
|
||||||
|
.run_command(
|
||||||
|
doc! {
|
||||||
|
"createIndexes": "attachments",
|
||||||
|
"indexes": [
|
||||||
|
{
|
||||||
|
"key": {
|
||||||
|
"used_for.id": 1_i32
|
||||||
|
},
|
||||||
|
"name": "used_for_id"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("Failed to create attachments index.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if revision <= 31 {
|
||||||
|
info!("Running migration [revision 31 / 31-10-2024]: Add creator_id to webhooks and delete those whose channels don't exist.");
|
||||||
|
|
||||||
|
#[derive(serde::Serialize, serde::Deserialize)]
|
||||||
|
struct WebhookShell {
|
||||||
|
_id: String,
|
||||||
|
channel_id: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
let webhooks = db
|
||||||
|
.db()
|
||||||
|
.collection::<WebhookShell>("channel_webhooks")
|
||||||
|
.find(doc! {}, None)
|
||||||
|
.await
|
||||||
|
.expect("webhooks")
|
||||||
|
.filter_map(|s| async { s.ok() })
|
||||||
|
.collect::<Vec<WebhookShell>>()
|
||||||
|
.await;
|
||||||
|
|
||||||
|
for webhook in webhooks {
|
||||||
|
match db.fetch_channel(&webhook.channel_id).await {
|
||||||
|
Ok(channel) => {
|
||||||
|
let creator_id = match channel {
|
||||||
|
Channel::Group { owner, .. } => owner,
|
||||||
|
Channel::TextChannel { server, .. }
|
||||||
|
| Channel::VoiceChannel { server, .. } => {
|
||||||
|
let server = db.fetch_server(&server).await.expect("server");
|
||||||
|
server.owner
|
||||||
|
}
|
||||||
|
_ => unreachable!("not server or group channel!"),
|
||||||
|
};
|
||||||
|
|
||||||
|
db.db()
|
||||||
|
.collection::<Document>("channel_webhooks")
|
||||||
|
.update_one(
|
||||||
|
doc! {
|
||||||
|
"_id": webhook._id,
|
||||||
|
},
|
||||||
|
doc! {
|
||||||
|
"$set" : {
|
||||||
|
"creator_id": creator_id
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("update webhook");
|
||||||
|
}
|
||||||
|
Err(Error {
|
||||||
|
error_type: ErrorType::NotFound,
|
||||||
|
..
|
||||||
|
}) => {
|
||||||
|
db.db()
|
||||||
|
.collection::<WebhookShell>("channel_webhooks")
|
||||||
|
.delete_one(doc! { "_id": webhook._id }, None)
|
||||||
|
.await
|
||||||
|
.expect("failed to delete invalid webhook");
|
||||||
|
}
|
||||||
|
Err(err) => panic!("{err:?}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Reminder to update LATEST_REVISION when adding new migrations.
|
// Reminder to update LATEST_REVISION when adding new migrations.
|
||||||
LATEST_REVISION.max(revision)
|
LATEST_REVISION.max(revision)
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ pub trait AbstractChannelUnreads: Sync + Send {
|
|||||||
message_ids: &[String],
|
message_ids: &[String],
|
||||||
) -> Result<()>;
|
) -> Result<()>;
|
||||||
|
|
||||||
|
/// Fetch all unreads with mentions for a user.
|
||||||
|
async fn fetch_unread_mentions(&self, user_id: &str) -> Result<Vec<ChannelUnread>>;
|
||||||
|
|
||||||
/// Fetch all channel unreads for a user.
|
/// Fetch all channel unreads for a user.
|
||||||
async fn fetch_unreads(&self, user_id: &str) -> Result<Vec<ChannelUnread>>;
|
async fn fetch_unreads(&self, user_id: &str) -> Result<Vec<ChannelUnread>>;
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ impl AbstractChannelUnreads for MongoDb {
|
|||||||
doc! {
|
doc! {
|
||||||
"$pull": {
|
"$pull": {
|
||||||
"mentions": {
|
"mentions": {
|
||||||
"$lt": message_id
|
"$lte": message_id
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"$set": {
|
"$set": {
|
||||||
@@ -123,6 +123,18 @@ impl AbstractChannelUnreads for MongoDb {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn fetch_unread_mentions(&self, user_id: &str) -> Result<Vec<ChannelUnread>> {
|
||||||
|
query! {
|
||||||
|
self,
|
||||||
|
find,
|
||||||
|
COL,
|
||||||
|
doc! {
|
||||||
|
"_id.user": user_id,
|
||||||
|
"mentions": {"$ne": null}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Fetch unread for a specific user in a channel.
|
/// Fetch unread for a specific user in a channel.
|
||||||
async fn fetch_unread(&self, user_id: &str, channel_id: &str) -> Result<Option<ChannelUnread>> {
|
async fn fetch_unread(&self, user_id: &str, channel_id: &str) -> Result<Option<ChannelUnread>> {
|
||||||
query!(
|
query!(
|
||||||
@@ -135,5 +147,4 @@ impl AbstractChannelUnreads for MongoDb {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,15 @@ impl AbstractChannelUnreads for ReferenceDb {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn fetch_unread_mentions(&self, user_id: &str) -> Result<Vec<ChannelUnread>> {
|
||||||
|
let unreads = self.channel_unreads.lock().await;
|
||||||
|
Ok(unreads
|
||||||
|
.values()
|
||||||
|
.filter(|unread| unread.id.user == user_id && unread.mentions.is_some())
|
||||||
|
.cloned()
|
||||||
|
.collect())
|
||||||
|
}
|
||||||
|
|
||||||
/// Fetch all channel unreads for a user.
|
/// Fetch all channel unreads for a user.
|
||||||
async fn fetch_unreads(&self, user_id: &str) -> Result<Vec<ChannelUnread>> {
|
async fn fetch_unreads(&self, user_id: &str) -> Result<Vec<ChannelUnread>> {
|
||||||
let unreads = self.channel_unreads.lock().await;
|
let unreads = self.channel_unreads.lock().await;
|
||||||
@@ -92,9 +101,11 @@ impl AbstractChannelUnreads for ReferenceDb {
|
|||||||
async fn fetch_unread(&self, user_id: &str, channel_id: &str) -> Result<Option<ChannelUnread>> {
|
async fn fetch_unread(&self, user_id: &str, channel_id: &str) -> Result<Option<ChannelUnread>> {
|
||||||
let unreads = self.channel_unreads.lock().await;
|
let unreads = self.channel_unreads.lock().await;
|
||||||
|
|
||||||
Ok(unreads.get(&ChannelCompositeKey {
|
Ok(unreads
|
||||||
channel: channel_id.to_string(),
|
.get(&ChannelCompositeKey {
|
||||||
user: user_id.to_string()
|
channel: channel_id.to_string(),
|
||||||
}).cloned())
|
user: user_id.to_string(),
|
||||||
|
})
|
||||||
|
.cloned())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ auto_derived_partial!(
|
|||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub avatar: Option<File>,
|
pub avatar: Option<File>,
|
||||||
|
|
||||||
|
/// User that created this webhook
|
||||||
|
pub creator_id: String,
|
||||||
|
|
||||||
/// The channel this webhook belongs to
|
/// The channel this webhook belongs to
|
||||||
pub channel_id: String,
|
pub channel_id: String,
|
||||||
|
|
||||||
@@ -43,6 +46,7 @@ impl Default for Webhook {
|
|||||||
id: Default::default(),
|
id: Default::default(),
|
||||||
name: Default::default(),
|
name: Default::default(),
|
||||||
avatar: None,
|
avatar: None,
|
||||||
|
creator_id: Default::default(),
|
||||||
channel_id: Default::default(),
|
channel_id: Default::default(),
|
||||||
permissions: Default::default(),
|
permissions: Default::default(),
|
||||||
token: Default::default(),
|
token: Default::default(),
|
||||||
@@ -70,7 +74,7 @@ impl Webhook {
|
|||||||
if self.token.as_deref() == Some(token) {
|
if self.token.as_deref() == Some(token) {
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(create_error!(InvalidCredentials))
|
Err(create_error!(NotAuthenticated))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use ulid::Ulid;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
events::client::EventV1, tasks::ack::AckEvent, Database, File, IntoDocumentPath, PartialServer,
|
events::client::EventV1, tasks::ack::AckEvent, Database, File, IntoDocumentPath, PartialServer,
|
||||||
Server, SystemMessage, User,
|
Server, SystemMessage, User, AMQP,
|
||||||
};
|
};
|
||||||
|
|
||||||
auto_derived!(
|
auto_derived!(
|
||||||
@@ -337,6 +337,7 @@ impl Channel {
|
|||||||
pub async fn add_user_to_group(
|
pub async fn add_user_to_group(
|
||||||
&mut self,
|
&mut self,
|
||||||
db: &Database,
|
db: &Database,
|
||||||
|
amqp: &AMQP,
|
||||||
user: &User,
|
user: &User,
|
||||||
by_id: &str,
|
by_id: &str,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
@@ -373,6 +374,7 @@ impl Channel {
|
|||||||
.into_message(id.to_string())
|
.into_message(id.to_string())
|
||||||
.send(
|
.send(
|
||||||
db,
|
db,
|
||||||
|
Some(amqp),
|
||||||
MessageAuthor::System {
|
MessageAuthor::System {
|
||||||
username: &user.username,
|
username: &user.username,
|
||||||
avatar: user.avatar.as_ref().map(|file| file.id.as_ref()),
|
avatar: user.avatar.as_ref().map(|file| file.id.as_ref()),
|
||||||
@@ -639,7 +641,7 @@ impl Channel {
|
|||||||
.private(user.to_string())
|
.private(user.to_string())
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
crate::tasks::ack::queue(
|
crate::tasks::ack::queue_ack(
|
||||||
self.id().to_string(),
|
self.id().to_string(),
|
||||||
user.to_string(),
|
user.to_string(),
|
||||||
AckEvent::AckMessage {
|
AckEvent::AckMessage {
|
||||||
@@ -655,6 +657,7 @@ impl Channel {
|
|||||||
pub async fn remove_user_from_group(
|
pub async fn remove_user_from_group(
|
||||||
&self,
|
&self,
|
||||||
db: &Database,
|
db: &Database,
|
||||||
|
amqp: &AMQP,
|
||||||
user: &User,
|
user: &User,
|
||||||
by_id: Option<&str>,
|
by_id: Option<&str>,
|
||||||
silent: bool,
|
silent: bool,
|
||||||
@@ -686,6 +689,7 @@ impl Channel {
|
|||||||
.into_message(id.to_string())
|
.into_message(id.to_string())
|
||||||
.send(
|
.send(
|
||||||
db,
|
db,
|
||||||
|
Some(amqp),
|
||||||
MessageAuthor::System {
|
MessageAuthor::System {
|
||||||
username: name,
|
username: name,
|
||||||
avatar: None,
|
avatar: None,
|
||||||
@@ -725,6 +729,7 @@ impl Channel {
|
|||||||
.into_message(id.to_string())
|
.into_message(id.to_string())
|
||||||
.send(
|
.send(
|
||||||
db,
|
db,
|
||||||
|
Some(amqp),
|
||||||
MessageAuthor::System {
|
MessageAuthor::System {
|
||||||
username: &user.username,
|
username: &user.username,
|
||||||
avatar: user.avatar.as_ref().map(|file| file.id.as_ref()),
|
avatar: user.avatar.as_ref().map(|file| file.id.as_ref()),
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ impl AbstractChannels for MongoDb {
|
|||||||
|
|
||||||
// Delete associated attachments
|
// Delete associated attachments
|
||||||
self.delete_many_attachments(doc! {
|
self.delete_many_attachments(doc! {
|
||||||
"object_id": &id
|
"used_for.id": &id
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
mod model;
|
||||||
|
mod ops;
|
||||||
|
|
||||||
|
pub use model::*;
|
||||||
|
pub use ops::*;
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
use iso8601_timestamp::Timestamp;
|
||||||
|
|
||||||
|
use crate::File;
|
||||||
|
|
||||||
|
auto_derived_partial!(
|
||||||
|
/// File hash
|
||||||
|
pub struct FileHash {
|
||||||
|
/// Sha256 hash of the file
|
||||||
|
#[serde(rename = "_id")]
|
||||||
|
pub id: String,
|
||||||
|
/// Sha256 hash of file after it has been processed
|
||||||
|
pub processed_hash: String,
|
||||||
|
|
||||||
|
/// When this file was created in system
|
||||||
|
pub created_at: Timestamp,
|
||||||
|
|
||||||
|
/// The bucket this file is stored in
|
||||||
|
pub bucket_id: String,
|
||||||
|
/// The path at which this file exists in
|
||||||
|
pub path: String,
|
||||||
|
/// Cryptographic nonce used to encrypt this file
|
||||||
|
pub iv: String,
|
||||||
|
|
||||||
|
/// Parsed metadata of this file
|
||||||
|
pub metadata: Metadata,
|
||||||
|
/// Raw content type of this file
|
||||||
|
pub content_type: String,
|
||||||
|
/// Size of this file (in bytes)
|
||||||
|
pub size: isize,
|
||||||
|
},
|
||||||
|
"PartialFile"
|
||||||
|
);
|
||||||
|
|
||||||
|
auto_derived!(
|
||||||
|
/// Metadata associated with a file
|
||||||
|
#[serde(tag = "type")]
|
||||||
|
#[derive(Default)]
|
||||||
|
pub enum Metadata {
|
||||||
|
/// File is just a generic uncategorised file
|
||||||
|
#[default]
|
||||||
|
File,
|
||||||
|
/// File contains textual data and should be displayed as such
|
||||||
|
Text,
|
||||||
|
/// File is an image with specific dimensions
|
||||||
|
Image {
|
||||||
|
width: isize,
|
||||||
|
height: isize,
|
||||||
|
// animated: bool // TODO: https://docs.rs/image/latest/image/trait.AnimationDecoder.html for APNG support
|
||||||
|
},
|
||||||
|
/// File is a video with specific dimensions
|
||||||
|
Video { width: isize, height: isize },
|
||||||
|
/// File is audio
|
||||||
|
Audio,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
impl FileHash {
|
||||||
|
/// Create a file from a file hash
|
||||||
|
pub fn into_file(
|
||||||
|
&self,
|
||||||
|
id: String,
|
||||||
|
tag: String,
|
||||||
|
filename: String,
|
||||||
|
uploader_id: String,
|
||||||
|
) -> File {
|
||||||
|
File {
|
||||||
|
id,
|
||||||
|
tag,
|
||||||
|
filename,
|
||||||
|
hash: Some(self.id.clone()),
|
||||||
|
|
||||||
|
uploaded_at: Some(Timestamp::now_utc()),
|
||||||
|
uploader_id: Some(uploader_id),
|
||||||
|
|
||||||
|
used_for: None,
|
||||||
|
|
||||||
|
deleted: None,
|
||||||
|
reported: None,
|
||||||
|
|
||||||
|
// TODO: remove this data
|
||||||
|
metadata: self.metadata.clone(),
|
||||||
|
content_type: self.content_type.clone(),
|
||||||
|
size: self.size,
|
||||||
|
|
||||||
|
// TODO: superseded by "used_for"
|
||||||
|
message_id: None,
|
||||||
|
object_id: None,
|
||||||
|
server_id: None,
|
||||||
|
user_id: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
use revolt_result::Result;
|
||||||
|
|
||||||
|
use crate::FileHash;
|
||||||
|
|
||||||
|
mod mongodb;
|
||||||
|
mod reference;
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
pub trait AbstractAttachmentHashes: Sync + Send {
|
||||||
|
/// Insert a new attachment hash into the database.
|
||||||
|
async fn insert_attachment_hash(&self, hash: &FileHash) -> Result<()>;
|
||||||
|
|
||||||
|
/// Fetch an attachment hash entry by sha256 hash.
|
||||||
|
async fn fetch_attachment_hash(&self, hash: &str) -> Result<FileHash>;
|
||||||
|
|
||||||
|
/// Update an attachment hash nonce value.
|
||||||
|
async fn set_attachment_hash_nonce(&self, hash: &str, nonce: &str) -> Result<()>;
|
||||||
|
|
||||||
|
/// Delete attachment hash by id.
|
||||||
|
async fn delete_attachment_hash(&self, id: &str) -> Result<()>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
use revolt_result::Result;
|
||||||
|
|
||||||
|
use crate::FileHash;
|
||||||
|
use crate::MongoDb;
|
||||||
|
|
||||||
|
use super::AbstractAttachmentHashes;
|
||||||
|
|
||||||
|
static COL: &str = "attachment_hashes";
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl AbstractAttachmentHashes for MongoDb {
|
||||||
|
/// Insert a new attachment hash into the database.
|
||||||
|
async fn insert_attachment_hash(&self, hash: &FileHash) -> Result<()> {
|
||||||
|
query!(self, insert_one, COL, &hash).map(|_| ())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Fetch an attachment hash entry by sha256 hash.
|
||||||
|
async fn fetch_attachment_hash(&self, hash: &str) -> Result<FileHash> {
|
||||||
|
query!(
|
||||||
|
self,
|
||||||
|
find_one,
|
||||||
|
COL,
|
||||||
|
doc! {
|
||||||
|
"$or": [
|
||||||
|
{"_id": hash},
|
||||||
|
{"processed_hash": hash}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
)?
|
||||||
|
.ok_or_else(|| create_error!(NotFound))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Update an attachment hash nonce value.
|
||||||
|
async fn set_attachment_hash_nonce(&self, hash: &str, nonce: &str) -> Result<()> {
|
||||||
|
self.col::<FileHash>(COL)
|
||||||
|
.update_one(
|
||||||
|
doc! {
|
||||||
|
"_id": hash
|
||||||
|
},
|
||||||
|
doc! {
|
||||||
|
"$set": {
|
||||||
|
"iv": nonce
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map(|_| ())
|
||||||
|
.map_err(|_| create_database_error!("update_one", COL))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Delete attachment hash by id.
|
||||||
|
async fn delete_attachment_hash(&self, id: &str) -> Result<()> {
|
||||||
|
query!(self, delete_one_by_id, COL, id).map(|_| ())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
use revolt_result::Result;
|
||||||
|
|
||||||
|
use crate::FileHash;
|
||||||
|
use crate::ReferenceDb;
|
||||||
|
|
||||||
|
use super::AbstractAttachmentHashes;
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl AbstractAttachmentHashes for ReferenceDb {
|
||||||
|
/// Insert a new attachment hash into the database.
|
||||||
|
async fn insert_attachment_hash(&self, hash: &FileHash) -> Result<()> {
|
||||||
|
let mut hashes = self.file_hashes.lock().await;
|
||||||
|
if hashes.contains_key(&hash.id) {
|
||||||
|
Err(create_database_error!("insert", "attachment"))
|
||||||
|
} else {
|
||||||
|
hashes.insert(hash.id.to_string(), hash.clone());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Fetch an attachment hash entry by sha256 hash.
|
||||||
|
async fn fetch_attachment_hash(&self, hash_value: &str) -> Result<FileHash> {
|
||||||
|
let hashes = self.file_hashes.lock().await;
|
||||||
|
hashes
|
||||||
|
.values()
|
||||||
|
.find(|&hash| hash.id == hash_value || hash.processed_hash == hash_value)
|
||||||
|
.cloned()
|
||||||
|
.ok_or(create_error!(NotFound))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Update an attachment hash nonce value.
|
||||||
|
async fn set_attachment_hash_nonce(&self, hash: &str, nonce: &str) -> Result<()> {
|
||||||
|
let mut hashes = self.file_hashes.lock().await;
|
||||||
|
if let Some(file) = hashes.get_mut(hash) {
|
||||||
|
file.iv = nonce.to_owned();
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(create_error!(NotFound))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Delete attachment hash by id.
|
||||||
|
async fn delete_attachment_hash(&self, id: &str) -> Result<()> {
|
||||||
|
let mut file_hashes = self.file_hashes.lock().await;
|
||||||
|
if file_hashes.remove(id).is_some() {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(create_error!(NotFound))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
use crate::Database;
|
use crate::{Database, FileHash, Metadata};
|
||||||
|
|
||||||
|
use iso8601_timestamp::Timestamp;
|
||||||
use revolt_result::Result;
|
use revolt_result::Result;
|
||||||
|
|
||||||
auto_derived_partial!(
|
auto_derived_partial!(
|
||||||
@@ -12,12 +13,18 @@ auto_derived_partial!(
|
|||||||
pub tag: String,
|
pub tag: String,
|
||||||
/// Original filename
|
/// Original filename
|
||||||
pub filename: String,
|
pub filename: String,
|
||||||
/// Parsed metadata of this file
|
/// Hash of this file
|
||||||
pub metadata: Metadata,
|
pub hash: Option<String>, // these are Option<>s to not break file uploads on legacy Autumn
|
||||||
/// Raw content type of this file
|
|
||||||
pub content_type: String,
|
/// When this file was uploaded
|
||||||
/// Size of this file (in bytes)
|
pub uploaded_at: Option<Timestamp>, // these are Option<>s to not break file uploads on legacy Autumn
|
||||||
pub size: isize,
|
/// ID of user who uploaded this file
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub uploader_id: Option<String>, // these are Option<>s to not break file uploads on legacy Autumn
|
||||||
|
|
||||||
|
/// What the file was used for
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub used_for: Option<FileUsedFor>,
|
||||||
|
|
||||||
/// Whether this file was deleted
|
/// Whether this file was deleted
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
@@ -26,6 +33,14 @@ auto_derived_partial!(
|
|||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub reported: Option<bool>,
|
pub reported: Option<bool>,
|
||||||
|
|
||||||
|
// !!! DEPRECATED:
|
||||||
|
/// Parsed metadata of this file
|
||||||
|
pub metadata: Metadata,
|
||||||
|
/// Raw content type of this file
|
||||||
|
pub content_type: String,
|
||||||
|
/// Size of this file (in bytes)
|
||||||
|
pub size: isize,
|
||||||
|
|
||||||
// TODO: migrate this mess to having:
|
// TODO: migrate this mess to having:
|
||||||
// - author_id
|
// - author_id
|
||||||
// - parent: Parent { Message(id), User(id), etc }
|
// - parent: Parent { Message(id), User(id), etc }
|
||||||
@@ -44,64 +59,184 @@ auto_derived_partial!(
|
|||||||
);
|
);
|
||||||
|
|
||||||
auto_derived!(
|
auto_derived!(
|
||||||
/// Metadata associated with a file
|
/// Type of object file was used for
|
||||||
#[serde(tag = "type")]
|
pub enum FileUsedForType {
|
||||||
#[derive(Default)]
|
Message,
|
||||||
pub enum Metadata {
|
ServerBanner,
|
||||||
/// File is just a generic uncategorised file
|
Emoji,
|
||||||
#[default]
|
UserAvatar,
|
||||||
File,
|
WebhookAvatar,
|
||||||
/// File contains textual data and should be displayed as such
|
UserProfileBackground,
|
||||||
Text,
|
LegacyGroupIcon,
|
||||||
/// File is an image with specific dimensions
|
ChannelIcon,
|
||||||
Image { width: isize, height: isize },
|
ServerIcon,
|
||||||
/// File is a video with specific dimensions
|
}
|
||||||
Video { width: isize, height: isize },
|
|
||||||
/// File is audio
|
/// Information about what the file was used for
|
||||||
Audio,
|
pub struct FileUsedFor {
|
||||||
|
/// Type of the object
|
||||||
|
#[serde(rename = "type")]
|
||||||
|
pub object_type: FileUsedForType,
|
||||||
|
/// ID of the object
|
||||||
|
pub id: String,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
impl File {
|
impl File {
|
||||||
|
/// Get the hash entry for this file
|
||||||
|
pub async fn as_hash(&self, db: &Database) -> Result<FileHash> {
|
||||||
|
db.fetch_attachment_hash(self.hash.as_ref().unwrap()).await
|
||||||
|
}
|
||||||
|
|
||||||
/// Use a file for a message attachment
|
/// Use a file for a message attachment
|
||||||
pub async fn use_attachment(db: &Database, id: &str, parent: &str) -> Result<File> {
|
pub async fn use_attachment(
|
||||||
db.find_and_use_attachment(id, "attachments", "message", parent)
|
db: &Database,
|
||||||
.await
|
id: &str,
|
||||||
|
parent: &str,
|
||||||
|
uploader_id: &str,
|
||||||
|
) -> Result<File> {
|
||||||
|
db.find_and_use_attachment(
|
||||||
|
id,
|
||||||
|
"attachments",
|
||||||
|
FileUsedFor {
|
||||||
|
id: parent.to_owned(),
|
||||||
|
object_type: FileUsedForType::Message,
|
||||||
|
},
|
||||||
|
uploader_id.to_owned(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Use a file for a user profile background
|
/// Use a file for a user profile background
|
||||||
pub async fn use_background(db: &Database, id: &str, parent: &str) -> Result<File> {
|
pub async fn use_background(
|
||||||
db.find_and_use_attachment(id, "backgrounds", "user", parent)
|
db: &Database,
|
||||||
.await
|
id: &str,
|
||||||
|
parent: &str,
|
||||||
|
uploader_id: &str,
|
||||||
|
) -> Result<File> {
|
||||||
|
db.find_and_use_attachment(
|
||||||
|
id,
|
||||||
|
"backgrounds",
|
||||||
|
FileUsedFor {
|
||||||
|
id: parent.to_owned(),
|
||||||
|
object_type: FileUsedForType::UserProfileBackground,
|
||||||
|
},
|
||||||
|
uploader_id.to_owned(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Use a file for a user avatar
|
/// Use a file for a user avatar
|
||||||
pub async fn use_avatar(db: &Database, id: &str, parent: &str) -> Result<File> {
|
pub async fn use_user_avatar(
|
||||||
db.find_and_use_attachment(id, "avatars", "user", parent)
|
db: &Database,
|
||||||
.await
|
id: &str,
|
||||||
|
parent: &str,
|
||||||
|
uploader_id: &str,
|
||||||
|
) -> Result<File> {
|
||||||
|
db.find_and_use_attachment(
|
||||||
|
id,
|
||||||
|
"avatars",
|
||||||
|
FileUsedFor {
|
||||||
|
id: parent.to_owned(),
|
||||||
|
object_type: FileUsedForType::UserAvatar,
|
||||||
|
},
|
||||||
|
uploader_id.to_owned(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Use a file for an icon
|
/// Use a file for a webhook avatar
|
||||||
pub async fn use_icon(db: &Database, id: &str, parent: &str) -> Result<File> {
|
pub async fn use_webhook_avatar(
|
||||||
db.find_and_use_attachment(id, "icons", "object", parent)
|
db: &Database,
|
||||||
.await
|
id: &str,
|
||||||
|
parent: &str,
|
||||||
|
uploader_id: &str,
|
||||||
|
) -> Result<File> {
|
||||||
|
db.find_and_use_attachment(
|
||||||
|
id,
|
||||||
|
"avatars",
|
||||||
|
FileUsedFor {
|
||||||
|
id: parent.to_owned(),
|
||||||
|
object_type: FileUsedForType::WebhookAvatar,
|
||||||
|
},
|
||||||
|
uploader_id.to_owned(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Use a file for a server icon
|
/// Use a file for a server icon
|
||||||
pub async fn use_server_icon(db: &Database, id: &str, parent: &str) -> Result<File> {
|
pub async fn use_server_icon(
|
||||||
db.find_and_use_attachment(id, "icons", "object", parent)
|
db: &Database,
|
||||||
.await
|
id: &str,
|
||||||
|
parent: &str,
|
||||||
|
uploader_id: &str,
|
||||||
|
) -> Result<File> {
|
||||||
|
db.find_and_use_attachment(
|
||||||
|
id,
|
||||||
|
"icons",
|
||||||
|
FileUsedFor {
|
||||||
|
id: parent.to_owned(),
|
||||||
|
object_type: FileUsedForType::ServerIcon,
|
||||||
|
},
|
||||||
|
uploader_id.to_owned(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Use a file for a channel icon
|
||||||
|
pub async fn use_channel_icon(
|
||||||
|
db: &Database,
|
||||||
|
id: &str,
|
||||||
|
parent: &str,
|
||||||
|
uploader_id: &str,
|
||||||
|
) -> Result<File> {
|
||||||
|
db.find_and_use_attachment(
|
||||||
|
id,
|
||||||
|
"icons",
|
||||||
|
FileUsedFor {
|
||||||
|
id: parent.to_owned(),
|
||||||
|
object_type: FileUsedForType::ChannelIcon,
|
||||||
|
},
|
||||||
|
uploader_id.to_owned(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Use a file for a server banner
|
/// Use a file for a server banner
|
||||||
pub async fn use_banner(db: &Database, id: &str, parent: &str) -> Result<File> {
|
pub async fn use_server_banner(
|
||||||
db.find_and_use_attachment(id, "banners", "server", parent)
|
db: &Database,
|
||||||
.await
|
id: &str,
|
||||||
|
parent: &str,
|
||||||
|
uploader_id: &str,
|
||||||
|
) -> Result<File> {
|
||||||
|
db.find_and_use_attachment(
|
||||||
|
id,
|
||||||
|
"banners",
|
||||||
|
FileUsedFor {
|
||||||
|
id: parent.to_owned(),
|
||||||
|
object_type: FileUsedForType::ServerBanner,
|
||||||
|
},
|
||||||
|
uploader_id.to_owned(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Use a file for an emoji
|
/// Use a file for an emoji
|
||||||
pub async fn use_emoji(db: &Database, id: &str, parent: &str) -> Result<File> {
|
pub async fn use_emoji(
|
||||||
db.find_and_use_attachment(id, "emojis", "object", parent)
|
db: &Database,
|
||||||
.await
|
id: &str,
|
||||||
|
parent: &str,
|
||||||
|
uploader_id: &str,
|
||||||
|
) -> Result<File> {
|
||||||
|
db.find_and_use_attachment(
|
||||||
|
id,
|
||||||
|
"emojis",
|
||||||
|
FileUsedFor {
|
||||||
|
id: parent.to_owned(),
|
||||||
|
object_type: FileUsedForType::Emoji,
|
||||||
|
},
|
||||||
|
uploader_id.to_owned(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ use revolt_result::Result;
|
|||||||
|
|
||||||
use crate::File;
|
use crate::File;
|
||||||
|
|
||||||
|
use super::FileUsedFor;
|
||||||
|
|
||||||
mod mongodb;
|
mod mongodb;
|
||||||
mod reference;
|
mod reference;
|
||||||
|
|
||||||
@@ -10,13 +12,25 @@ pub trait AbstractAttachments: Sync + Send {
|
|||||||
/// Insert attachment into database.
|
/// Insert attachment into database.
|
||||||
async fn insert_attachment(&self, attachment: &File) -> Result<()>;
|
async fn insert_attachment(&self, attachment: &File) -> Result<()>;
|
||||||
|
|
||||||
|
/// Fetch an attachment by its id.
|
||||||
|
async fn fetch_attachment(&self, tag: &str, file_id: &str) -> Result<File>;
|
||||||
|
|
||||||
|
/// Fetch all deleted attachments.
|
||||||
|
async fn fetch_deleted_attachments(&self) -> Result<Vec<File>>;
|
||||||
|
|
||||||
|
/// Fetch all dangling attachments.
|
||||||
|
async fn fetch_dangling_files(&self) -> Result<Vec<File>>;
|
||||||
|
|
||||||
|
/// Count references to a given hash.
|
||||||
|
async fn count_file_hash_references(&self, hash: &str) -> Result<usize>;
|
||||||
|
|
||||||
/// Find an attachment by its details and mark it as used by a given parent.
|
/// Find an attachment by its details and mark it as used by a given parent.
|
||||||
async fn find_and_use_attachment(
|
async fn find_and_use_attachment(
|
||||||
&self,
|
&self,
|
||||||
id: &str,
|
id: &str,
|
||||||
tag: &str,
|
tag: &str,
|
||||||
parent_type: &str,
|
used_for: FileUsedFor,
|
||||||
parent_id: &str,
|
uploader_id: String,
|
||||||
) -> Result<File>;
|
) -> Result<File>;
|
||||||
|
|
||||||
/// Mark an attachment as having been reported.
|
/// Mark an attachment as having been reported.
|
||||||
@@ -27,4 +41,7 @@ pub trait AbstractAttachments: Sync + Send {
|
|||||||
|
|
||||||
/// Mark multiple attachments as having been deleted.
|
/// Mark multiple attachments as having been deleted.
|
||||||
async fn mark_attachments_as_deleted(&self, ids: &[String]) -> Result<()>;
|
async fn mark_attachments_as_deleted(&self, ids: &[String]) -> Result<()>;
|
||||||
|
|
||||||
|
/// Delete the attachment entry.
|
||||||
|
async fn delete_attachment(&self, id: &str) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
|
use bson::to_document;
|
||||||
use bson::Document;
|
use bson::Document;
|
||||||
|
use revolt_config::report_internal_error;
|
||||||
use revolt_result::Result;
|
use revolt_result::Result;
|
||||||
|
|
||||||
use crate::File;
|
use crate::File;
|
||||||
|
use crate::FileUsedFor;
|
||||||
use crate::MongoDb;
|
use crate::MongoDb;
|
||||||
|
|
||||||
use super::AbstractAttachments;
|
use super::AbstractAttachments;
|
||||||
@@ -15,15 +18,73 @@ impl AbstractAttachments for MongoDb {
|
|||||||
query!(self, insert_one, COL, &attachment).map(|_| ())
|
query!(self, insert_one, COL, &attachment).map(|_| ())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Fetch an attachment by its id.
|
||||||
|
async fn fetch_attachment(&self, tag: &str, file_id: &str) -> Result<File> {
|
||||||
|
query!(
|
||||||
|
self,
|
||||||
|
find_one,
|
||||||
|
COL,
|
||||||
|
doc! {
|
||||||
|
"_id": file_id,
|
||||||
|
"tag": tag
|
||||||
|
}
|
||||||
|
)?
|
||||||
|
.ok_or_else(|| create_error!(NotFound))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Fetch all deleted attachments.
|
||||||
|
async fn fetch_deleted_attachments(&self) -> Result<Vec<File>> {
|
||||||
|
query!(
|
||||||
|
self,
|
||||||
|
find,
|
||||||
|
COL,
|
||||||
|
doc! {
|
||||||
|
"deleted": true,
|
||||||
|
"reported": {
|
||||||
|
"$ne": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Fetch all dangling attachments.
|
||||||
|
async fn fetch_dangling_files(&self) -> Result<Vec<File>> {
|
||||||
|
query!(
|
||||||
|
self,
|
||||||
|
find,
|
||||||
|
COL,
|
||||||
|
doc! {
|
||||||
|
"used_for.type": {
|
||||||
|
"$exists": 0
|
||||||
|
},
|
||||||
|
"deleted": {
|
||||||
|
"$ne": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Count references to a given hash.
|
||||||
|
async fn count_file_hash_references(&self, hash: &str) -> Result<usize> {
|
||||||
|
query!(
|
||||||
|
self,
|
||||||
|
count_documents,
|
||||||
|
COL,
|
||||||
|
doc! {
|
||||||
|
"hash": hash
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.map(|count| count as usize)
|
||||||
|
}
|
||||||
|
|
||||||
/// Find an attachment by its details and mark it as used by a given parent.
|
/// Find an attachment by its details and mark it as used by a given parent.
|
||||||
async fn find_and_use_attachment(
|
async fn find_and_use_attachment(
|
||||||
&self,
|
&self,
|
||||||
id: &str,
|
id: &str,
|
||||||
tag: &str,
|
tag: &str,
|
||||||
parent_type: &str,
|
used_for: FileUsedFor,
|
||||||
parent_id: &str,
|
uploader_id: String,
|
||||||
) -> Result<File> {
|
) -> Result<File> {
|
||||||
let key = format!("{parent_type}_id");
|
|
||||||
let file = query!(
|
let file = query!(
|
||||||
self,
|
self,
|
||||||
find_one,
|
find_one,
|
||||||
@@ -31,7 +92,7 @@ impl AbstractAttachments for MongoDb {
|
|||||||
doc! {
|
doc! {
|
||||||
"_id": id,
|
"_id": id,
|
||||||
"tag": tag,
|
"tag": tag,
|
||||||
&key: {
|
"used_for": {
|
||||||
"$exists": false
|
"$exists": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,7 +106,8 @@ impl AbstractAttachments for MongoDb {
|
|||||||
},
|
},
|
||||||
doc! {
|
doc! {
|
||||||
"$set": {
|
"$set": {
|
||||||
key: parent_id
|
"used_for": report_internal_error!(to_document(&used_for))?,
|
||||||
|
"uploader_id": uploader_id
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None,
|
None,
|
||||||
@@ -97,7 +159,7 @@ impl AbstractAttachments for MongoDb {
|
|||||||
/// Mark multiple attachments as having been deleted.
|
/// Mark multiple attachments as having been deleted.
|
||||||
async fn mark_attachments_as_deleted(&self, ids: &[String]) -> Result<()> {
|
async fn mark_attachments_as_deleted(&self, ids: &[String]) -> Result<()> {
|
||||||
self.col::<Document>(COL)
|
self.col::<Document>(COL)
|
||||||
.update_one(
|
.update_many(
|
||||||
doc! {
|
doc! {
|
||||||
"_id": {
|
"_id": {
|
||||||
"$in": ids
|
"$in": ids
|
||||||
@@ -112,7 +174,12 @@ impl AbstractAttachments for MongoDb {
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
.map_err(|_| create_database_error!("update_one", COL))
|
.map_err(|_| create_database_error!("update_many", COL))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Delete the attachment entry.
|
||||||
|
async fn delete_attachment(&self, id: &str) -> Result<()> {
|
||||||
|
query!(self, delete_one_by_id, COL, id).map(|_| ())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use revolt_result::Result;
|
use revolt_result::Result;
|
||||||
|
|
||||||
use crate::File;
|
use crate::File;
|
||||||
|
use crate::FileUsedFor;
|
||||||
use crate::ReferenceDb;
|
use crate::ReferenceDb;
|
||||||
|
|
||||||
use super::AbstractAttachments;
|
use super::AbstractAttachments;
|
||||||
@@ -18,24 +19,68 @@ impl AbstractAttachments for ReferenceDb {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Fetch an attachment by its id.
|
||||||
|
async fn fetch_attachment(&self, tag: &str, file_id: &str) -> Result<File> {
|
||||||
|
let files = self.files.lock().await;
|
||||||
|
if let Some(file) = files.get(file_id) {
|
||||||
|
if file.tag == tag {
|
||||||
|
Ok(file.clone())
|
||||||
|
} else {
|
||||||
|
Err(create_error!(NotFound))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err(create_error!(NotFound))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Fetch all deleted attachments.
|
||||||
|
async fn fetch_deleted_attachments(&self) -> Result<Vec<File>> {
|
||||||
|
let files = self.files.lock().await;
|
||||||
|
Ok(files
|
||||||
|
.values()
|
||||||
|
.filter(|file| {
|
||||||
|
// file has been marked as deleted
|
||||||
|
file.deleted.is_some_and(|v| v)
|
||||||
|
// and it has not been reported
|
||||||
|
&& !file.reported.is_some_and(|v| v)
|
||||||
|
})
|
||||||
|
.cloned()
|
||||||
|
.collect())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Fetch all dangling attachments.
|
||||||
|
async fn fetch_dangling_files(&self) -> Result<Vec<File>> {
|
||||||
|
let files = self.files.lock().await;
|
||||||
|
Ok(files
|
||||||
|
.values()
|
||||||
|
.filter(|file| file.used_for.is_none() && !file.deleted.is_some_and(|v| v))
|
||||||
|
.cloned()
|
||||||
|
.collect())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Count references to a given hash.
|
||||||
|
async fn count_file_hash_references(&self, hash: &str) -> Result<usize> {
|
||||||
|
let files = self.files.lock().await;
|
||||||
|
Ok(files
|
||||||
|
.values()
|
||||||
|
.filter(|file| file.hash.as_ref().is_some_and(|h| h == hash))
|
||||||
|
.cloned()
|
||||||
|
.count())
|
||||||
|
}
|
||||||
|
|
||||||
/// Find an attachment by its details and mark it as used by a given parent.
|
/// Find an attachment by its details and mark it as used by a given parent.
|
||||||
async fn find_and_use_attachment(
|
async fn find_and_use_attachment(
|
||||||
&self,
|
&self,
|
||||||
id: &str,
|
id: &str,
|
||||||
tag: &str,
|
tag: &str,
|
||||||
parent_type: &str,
|
used_for: FileUsedFor,
|
||||||
parent_id: &str,
|
uploader_id: String,
|
||||||
) -> Result<File> {
|
) -> Result<File> {
|
||||||
let mut files = self.files.lock().await;
|
let mut files = self.files.lock().await;
|
||||||
if let Some(file) = files.get_mut(id) {
|
if let Some(file) = files.get_mut(id) {
|
||||||
if file.tag == tag {
|
if file.tag == tag {
|
||||||
match parent_type {
|
file.uploader_id = Some(uploader_id);
|
||||||
"message" => file.message_id = Some(parent_id.to_owned()),
|
file.used_for = Some(used_for);
|
||||||
"user" => file.user_id = Some(parent_id.to_owned()),
|
|
||||||
"object" => file.object_id = Some(parent_id.to_owned()),
|
|
||||||
"server" => file.server_id = Some(parent_id.to_owned()),
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(file.clone())
|
Ok(file.clone())
|
||||||
} else {
|
} else {
|
||||||
@@ -86,4 +131,14 @@ impl AbstractAttachments for ReferenceDb {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Delete the attachment entry.
|
||||||
|
async fn delete_attachment(&self, id: &str) -> Result<()> {
|
||||||
|
let mut files = self.files.lock().await;
|
||||||
|
if files.remove(id).is_some() {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(create_error!(NotFound))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use std::collections::HashSet;
|
use std::{collections::HashSet, hash::RandomState};
|
||||||
|
|
||||||
use indexmap::{IndexMap, IndexSet};
|
use indexmap::{IndexMap, IndexSet};
|
||||||
use iso8601_timestamp::Timestamp;
|
use iso8601_timestamp::Timestamp;
|
||||||
@@ -15,8 +15,8 @@ use validator::Validate;
|
|||||||
use crate::{
|
use crate::{
|
||||||
events::client::EventV1,
|
events::client::EventV1,
|
||||||
tasks::{self, ack::AckEvent},
|
tasks::{self, ack::AckEvent},
|
||||||
util::idempotency::IdempotencyKey,
|
util::{bulk_permissions::BulkDatabasePermissionQuery, idempotency::IdempotencyKey},
|
||||||
Channel, Database, Emoji, File, User,
|
Channel, Database, Emoji, File, User, AMQP,
|
||||||
};
|
};
|
||||||
|
|
||||||
auto_derived_partial!(
|
auto_derived_partial!(
|
||||||
@@ -230,6 +230,7 @@ impl Message {
|
|||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub async fn create_from_api(
|
pub async fn create_from_api(
|
||||||
db: &Database,
|
db: &Database,
|
||||||
|
amqp: Option<&AMQP>,
|
||||||
channel: Channel,
|
channel: Channel,
|
||||||
data: DataMessageSend,
|
data: DataMessageSend,
|
||||||
author: MessageAuthor<'_>,
|
author: MessageAuthor<'_>,
|
||||||
@@ -337,6 +338,50 @@ impl Message {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate the mentions go to users in the channel/server
|
||||||
|
if !mentions.is_empty() {
|
||||||
|
match channel {
|
||||||
|
Channel::DirectMessage { ref recipients, .. }
|
||||||
|
| Channel::Group { ref recipients, .. } => {
|
||||||
|
let recipients_hash: HashSet<&String, RandomState> =
|
||||||
|
HashSet::from_iter(recipients);
|
||||||
|
mentions.retain(|m| recipients_hash.contains(m));
|
||||||
|
}
|
||||||
|
Channel::TextChannel { ref server, .. }
|
||||||
|
| Channel::VoiceChannel { ref server, .. } => {
|
||||||
|
let mentions_vec = Vec::from_iter(mentions.iter().cloned());
|
||||||
|
|
||||||
|
let valid_members = db.fetch_members(server.as_str(), &mentions_vec[..]).await;
|
||||||
|
if let Ok(valid_members) = valid_members {
|
||||||
|
let valid_mentions: HashSet<&String, RandomState> =
|
||||||
|
HashSet::from_iter(valid_members.iter().map(|m| &m.id.user));
|
||||||
|
|
||||||
|
mentions.retain(|m| valid_mentions.contains(m)); // quick pass, validate mentions are in the server
|
||||||
|
|
||||||
|
if !mentions.is_empty() {
|
||||||
|
// if there are still mentions, drill down to a channel-level
|
||||||
|
let member_channel_view_perms =
|
||||||
|
BulkDatabasePermissionQuery::from_server_id(db, server)
|
||||||
|
.await
|
||||||
|
.channel(&channel)
|
||||||
|
.members(&valid_members)
|
||||||
|
.members_can_see_channel()
|
||||||
|
.await;
|
||||||
|
|
||||||
|
mentions
|
||||||
|
.retain(|m| *member_channel_view_perms.get(m).unwrap_or(&false));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
revolt_config::capture_error(&valid_members.unwrap_err());
|
||||||
|
return Err(create_error!(InternalError));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Channel::SavedMessages { .. } => {
|
||||||
|
mentions.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !mentions.is_empty() {
|
if !mentions.is_empty() {
|
||||||
message.mentions.replace(mentions.into_iter().collect());
|
message.mentions.replace(mentions.into_iter().collect());
|
||||||
}
|
}
|
||||||
@@ -370,10 +415,8 @@ impl Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for attachment_id in data.attachments.as_deref().unwrap_or_default() {
|
for attachment_id in data.attachments.as_deref().unwrap_or_default() {
|
||||||
attachments.push(
|
attachments
|
||||||
db.find_and_use_attachment(attachment_id, "attachments", "message", &message_id)
|
.push(File::use_attachment(db, attachment_id, &message_id, author.id()).await?);
|
||||||
.await?,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !attachments.is_empty() {
|
if !attachments.is_empty() {
|
||||||
@@ -393,7 +436,7 @@ impl Message {
|
|||||||
|
|
||||||
// Send the message
|
// Send the message
|
||||||
message
|
message
|
||||||
.send(db, author, user, member, &channel, generate_embeds)
|
.send(db, amqp, author, user, member, &channel, generate_embeds)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(message)
|
Ok(message)
|
||||||
@@ -407,6 +450,9 @@ impl Message {
|
|||||||
member: Option<v0::Member>,
|
member: Option<v0::Member>,
|
||||||
is_dm: bool,
|
is_dm: bool,
|
||||||
generate_embeds: bool,
|
generate_embeds: bool,
|
||||||
|
// This determines if this function should queue the mentions task or if somewhere else will.
|
||||||
|
// If this is true, you MUST call tasks::ack::queue yourself.
|
||||||
|
mentions_elsewhere: bool,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
db.insert_message(self).await?;
|
db.insert_message(self).await?;
|
||||||
|
|
||||||
@@ -419,13 +465,12 @@ impl Message {
|
|||||||
tasks::last_message_id::queue(self.channel.to_string(), self.id.to_string(), is_dm).await;
|
tasks::last_message_id::queue(self.channel.to_string(), self.id.to_string(), is_dm).await;
|
||||||
|
|
||||||
// Add mentions for affected users
|
// Add mentions for affected users
|
||||||
if let Some(mentions) = &self.mentions {
|
if !mentions_elsewhere {
|
||||||
for user in mentions {
|
if let Some(mentions) = &self.mentions {
|
||||||
tasks::ack::queue(
|
tasks::ack::queue_message(
|
||||||
self.channel.to_string(),
|
self.channel.to_string(),
|
||||||
user.to_string(),
|
AckEvent::ProcessMessage {
|
||||||
AckEvent::AddMention {
|
messages: vec![(None, self.clone(), mentions.clone(), true)],
|
||||||
ids: vec![self.id.to_string()],
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
@@ -448,9 +493,11 @@ impl Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Send a message
|
/// Send a message
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub async fn send(
|
pub async fn send(
|
||||||
&mut self,
|
&mut self,
|
||||||
db: &Database,
|
db: &Database,
|
||||||
|
amqp: Option<&AMQP>, // this is optional mostly for tests.
|
||||||
author: MessageAuthor<'_>,
|
author: MessageAuthor<'_>,
|
||||||
user: Option<v0::User>,
|
user: Option<v0::User>,
|
||||||
member: Option<v0::Member>,
|
member: Option<v0::Member>,
|
||||||
@@ -463,26 +510,36 @@ impl Message {
|
|||||||
member.clone(),
|
member.clone(),
|
||||||
matches!(channel, Channel::DirectMessage { .. }),
|
matches!(channel, Channel::DirectMessage { .. }),
|
||||||
generate_embeds,
|
generate_embeds,
|
||||||
|
true,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if !self.has_suppressed_notifications() {
|
if !self.has_suppressed_notifications() {
|
||||||
// Push out Web Push notifications
|
// send Push notifications
|
||||||
crate::tasks::web_push::queue(
|
tasks::ack::queue_message(
|
||||||
{
|
self.channel.to_string(),
|
||||||
match channel {
|
AckEvent::ProcessMessage {
|
||||||
Channel::DirectMessage { recipients, .. }
|
messages: vec![(
|
||||||
| Channel::Group { recipients, .. } => recipients.clone(),
|
Some(
|
||||||
Channel::TextChannel { .. } => self.mentions.clone().unwrap_or_default(),
|
PushNotification::from(
|
||||||
_ => vec![],
|
self.clone().into_model(user, member),
|
||||||
}
|
Some(author),
|
||||||
|
channel.to_owned().into(),
|
||||||
|
)
|
||||||
|
.await,
|
||||||
|
),
|
||||||
|
self.clone(),
|
||||||
|
match channel {
|
||||||
|
Channel::DirectMessage { recipients, .. }
|
||||||
|
| Channel::Group { recipients, .. } => recipients.clone(),
|
||||||
|
Channel::TextChannel { .. } => {
|
||||||
|
self.mentions.clone().unwrap_or_default()
|
||||||
|
}
|
||||||
|
_ => vec![],
|
||||||
|
},
|
||||||
|
self.has_suppressed_notifications(),
|
||||||
|
)],
|
||||||
},
|
},
|
||||||
PushNotification::from(
|
|
||||||
self.clone().into_model(user, member),
|
|
||||||
Some(author),
|
|
||||||
channel.id(),
|
|
||||||
)
|
|
||||||
.await,
|
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
@@ -499,10 +556,7 @@ impl Message {
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
let media = if let Some(id) = embed.media {
|
let media = if let Some(id) = embed.media {
|
||||||
Some(
|
Some(File::use_attachment(db, &id, &self.id, &self.author).await?)
|
||||||
db.find_and_use_attachment(&id, "attachments", "message", &self.id)
|
|
||||||
.await?,
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
@@ -661,7 +715,7 @@ impl Message {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let media: Option<v0::File> = if let Some(id) = embed.media {
|
let media: Option<v0::File> = if let Some(id) = embed.media {
|
||||||
Some(
|
Some(
|
||||||
db.find_and_use_attachment(&id, "attachments", "message", &self.id)
|
File::use_attachment(db, &id, &self.id, &self.author)
|
||||||
.await?
|
.await?
|
||||||
.into(),
|
.into(),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ impl AbstractMessages for MongoDb {
|
|||||||
COL,
|
COL,
|
||||||
older_message_filter,
|
older_message_filter,
|
||||||
FindOptions::builder()
|
FindOptions::builder()
|
||||||
.limit(limit / 2)
|
.limit(limit / 2 + 1)
|
||||||
.sort(doc! {
|
.sort(doc! {
|
||||||
"_id": -1_i32
|
"_id": -1_i32
|
||||||
})
|
})
|
||||||
@@ -171,7 +171,7 @@ impl AbstractMessages for MongoDb {
|
|||||||
self.find_with_options(
|
self.find_with_options(
|
||||||
COL,
|
COL,
|
||||||
doc! {
|
doc! {
|
||||||
"ids": {
|
"_id": {
|
||||||
"$in": ids
|
"$in": ids
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ mod channel_unreads;
|
|||||||
mod channel_webhooks;
|
mod channel_webhooks;
|
||||||
mod channels;
|
mod channels;
|
||||||
mod emojis;
|
mod emojis;
|
||||||
|
mod file_hashes;
|
||||||
mod files;
|
mod files;
|
||||||
mod messages;
|
mod messages;
|
||||||
mod ratelimit_events;
|
mod ratelimit_events;
|
||||||
@@ -23,6 +24,7 @@ pub use channel_unreads::*;
|
|||||||
pub use channel_webhooks::*;
|
pub use channel_webhooks::*;
|
||||||
pub use channels::*;
|
pub use channels::*;
|
||||||
pub use emojis::*;
|
pub use emojis::*;
|
||||||
|
pub use file_hashes::*;
|
||||||
pub use files::*;
|
pub use files::*;
|
||||||
pub use messages::*;
|
pub use messages::*;
|
||||||
pub use ratelimit_events::*;
|
pub use ratelimit_events::*;
|
||||||
@@ -46,6 +48,7 @@ pub trait AbstractDatabase:
|
|||||||
+ channel_unreads::AbstractChannelUnreads
|
+ channel_unreads::AbstractChannelUnreads
|
||||||
+ channel_webhooks::AbstractWebhooks
|
+ channel_webhooks::AbstractWebhooks
|
||||||
+ emojis::AbstractEmojis
|
+ emojis::AbstractEmojis
|
||||||
|
+ file_hashes::AbstractAttachmentHashes
|
||||||
+ files::AbstractAttachments
|
+ files::AbstractAttachments
|
||||||
+ messages::AbstractMessages
|
+ messages::AbstractMessages
|
||||||
+ ratelimit_events::AbstractRatelimitEvents
|
+ ratelimit_events::AbstractRatelimitEvents
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ impl Member {
|
|||||||
id: user.id.clone(),
|
id: user.id.clone(),
|
||||||
}
|
}
|
||||||
.into_message(id.to_string())
|
.into_message(id.to_string())
|
||||||
.send_without_notifications(db, None, None, false, false)
|
.send_without_notifications(db, None, None, false, false, false)
|
||||||
.await
|
.await
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
@@ -251,7 +251,7 @@ impl Member {
|
|||||||
}
|
}
|
||||||
.into_message(id.to_string())
|
.into_message(id.to_string())
|
||||||
// TODO: support notifications here in the future?
|
// TODO: support notifications here in the future?
|
||||||
.send_without_notifications(db, None, None, false, false)
|
.send_without_notifications(db, None, None, false, false, false)
|
||||||
.await
|
.await
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,17 +53,17 @@ impl AbstractServerMembers for ReferenceDb {
|
|||||||
/// Fetch multiple members by their ids
|
/// Fetch multiple members by their ids
|
||||||
async fn fetch_members<'a>(&self, server_id: &str, ids: &'a [String]) -> Result<Vec<Member>> {
|
async fn fetch_members<'a>(&self, server_id: &str, ids: &'a [String]) -> Result<Vec<Member>> {
|
||||||
let server_members = self.server_members.lock().await;
|
let server_members = self.server_members.lock().await;
|
||||||
ids.iter()
|
Ok(ids
|
||||||
.map(|id| {
|
.iter()
|
||||||
|
.filter_map(|id| {
|
||||||
server_members
|
server_members
|
||||||
.get(&MemberCompositeKey {
|
.get(&MemberCompositeKey {
|
||||||
server: server_id.to_string(),
|
server: server_id.to_string(),
|
||||||
user: id.to_string(),
|
user: id.to_string(),
|
||||||
})
|
})
|
||||||
.cloned()
|
.cloned()
|
||||||
.ok_or_else(|| create_error!(NotFound))
|
|
||||||
})
|
})
|
||||||
.collect()
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch member count of a server
|
/// Fetch member count of a server
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ impl MongoDb {
|
|||||||
|
|
||||||
// Update many attachments with parent id.
|
// Update many attachments with parent id.
|
||||||
self.delete_many_attachments(doc! {
|
self.delete_many_attachments(doc! {
|
||||||
"object_id": &server_id
|
"used_for.id": &server_id
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
use axum::{extract::FromRequestParts, http::request::Parts};
|
||||||
|
|
||||||
|
use revolt_result::{create_error, Error, Result};
|
||||||
|
|
||||||
|
use crate::{Database, User};
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl FromRequestParts<Database> for User {
|
||||||
|
type Rejection = Error;
|
||||||
|
|
||||||
|
async fn from_request_parts(parts: &mut Parts, db: &Database) -> Result<User> {
|
||||||
|
if let Some(Ok(bot_token)) = parts.headers.get("x-bot-token").map(|v| v.to_str()) {
|
||||||
|
let bot = db.fetch_bot_by_token(bot_token).await?;
|
||||||
|
db.fetch_user(&bot.id).await
|
||||||
|
} else if let Some(Ok(session_token)) =
|
||||||
|
parts.headers.get("x-session-token").map(|v| v.to_str())
|
||||||
|
{
|
||||||
|
let session = db.fetch_session_by_token(session_token).await?;
|
||||||
|
db.fetch_user(&session.user_id).await
|
||||||
|
} else {
|
||||||
|
Err(create_error!(NotAuthenticated))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#[cfg(feature = "axum-impl")]
|
||||||
|
mod axum;
|
||||||
mod model;
|
mod model;
|
||||||
mod ops;
|
mod ops;
|
||||||
#[cfg(feature = "rocket-impl")]
|
#[cfg(feature = "rocket-impl")]
|
||||||
@@ -5,6 +7,8 @@ mod rocket;
|
|||||||
#[cfg(feature = "rocket-impl")]
|
#[cfg(feature = "rocket-impl")]
|
||||||
mod schema;
|
mod schema;
|
||||||
|
|
||||||
|
#[cfg(feature = "axum-impl")]
|
||||||
|
pub use self::axum::*;
|
||||||
#[cfg(feature = "rocket-impl")]
|
#[cfg(feature = "rocket-impl")]
|
||||||
pub use self::rocket::*;
|
pub use self::rocket::*;
|
||||||
#[cfg(feature = "rocket-impl")]
|
#[cfg(feature = "rocket-impl")]
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
use std::{collections::HashSet, str::FromStr, time::Duration};
|
use std::{collections::HashSet, str::FromStr, time::Duration};
|
||||||
|
|
||||||
use crate::{events::client::EventV1, Database, File, RatelimitEvent};
|
use crate::{events::client::EventV1, Database, File, RatelimitEvent, AMQP};
|
||||||
|
|
||||||
|
use authifier::config::{EmailVerificationConfig, Template};
|
||||||
|
use iso8601_timestamp::Timestamp;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use rand::seq::SliceRandom;
|
use rand::seq::SliceRandom;
|
||||||
use revolt_config::{config, FeaturesLimits};
|
use revolt_config::{config, FeaturesLimits};
|
||||||
use revolt_models::v0;
|
use revolt_models::v0::{self, UserFlags};
|
||||||
use revolt_presence::filter_online;
|
use revolt_presence::filter_online;
|
||||||
use revolt_result::{create_error, Result};
|
use revolt_result::{create_error, Result};
|
||||||
|
use serde_json::json;
|
||||||
use ulid::Ulid;
|
use ulid::Ulid;
|
||||||
|
|
||||||
auto_derived_partial!(
|
auto_derived_partial!(
|
||||||
@@ -49,6 +52,10 @@ auto_derived_partial!(
|
|||||||
/// Bot information
|
/// Bot information
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub bot: Option<BotInformation>,
|
pub bot: Option<BotInformation>,
|
||||||
|
|
||||||
|
/// Time until user is unsuspended
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub suspended_until: Option<Timestamp>,
|
||||||
},
|
},
|
||||||
"PartialUser"
|
"PartialUser"
|
||||||
);
|
);
|
||||||
@@ -62,6 +69,10 @@ auto_derived!(
|
|||||||
ProfileContent,
|
ProfileContent,
|
||||||
ProfileBackground,
|
ProfileBackground,
|
||||||
DisplayName,
|
DisplayName,
|
||||||
|
|
||||||
|
// internal fields
|
||||||
|
Suspension,
|
||||||
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// User's relationship with another user (or themselves)
|
/// User's relationship with another user (or themselves)
|
||||||
@@ -141,7 +152,7 @@ pub static DISCRIMINATOR_SEARCH_SPACE: Lazy<HashSet<String>> = Lazy::new(|| {
|
|||||||
.collect::<HashSet<String>>();
|
.collect::<HashSet<String>>();
|
||||||
|
|
||||||
for discrim in [
|
for discrim in [
|
||||||
123, 1234, 1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999,
|
123, 1234, 1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999, 1488,
|
||||||
] {
|
] {
|
||||||
set.remove(&format!("{:0>4}", discrim));
|
set.remove(&format!("{:0>4}", discrim));
|
||||||
}
|
}
|
||||||
@@ -165,6 +176,7 @@ impl Default for User {
|
|||||||
flags: Default::default(),
|
flags: Default::default(),
|
||||||
privileged: Default::default(),
|
privileged: Default::default(),
|
||||||
bot: Default::default(),
|
bot: Default::default(),
|
||||||
|
suspended_until: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -206,7 +218,7 @@ impl User {
|
|||||||
.datetime()
|
.datetime()
|
||||||
.elapsed()
|
.elapsed()
|
||||||
.expect("time went backwards")
|
.expect("time went backwards")
|
||||||
<= Duration::from_secs(86400u64 * config.features.limits.global.new_user_days as u64)
|
<= Duration::from_secs(3600u64 * config.features.limits.global.new_user_hours as u64)
|
||||||
{
|
{
|
||||||
config.features.limits.new_user
|
config.features.limits.new_user
|
||||||
} else {
|
} else {
|
||||||
@@ -281,7 +293,14 @@ impl User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ensure none of the following substrings show up in the username
|
// Ensure none of the following substrings show up in the username
|
||||||
const BLOCKED_SUBSTRINGS: &[&str] = &["```"];
|
const BLOCKED_SUBSTRINGS: &[&str] = &[
|
||||||
|
"```",
|
||||||
|
"discord.gg",
|
||||||
|
"rvlt.gg",
|
||||||
|
"guilded.gg",
|
||||||
|
"https://",
|
||||||
|
"http://",
|
||||||
|
];
|
||||||
|
|
||||||
for substr in BLOCKED_SUBSTRINGS {
|
for substr in BLOCKED_SUBSTRINGS {
|
||||||
if username_lowercase.contains(substr) {
|
if username_lowercase.contains(substr) {
|
||||||
@@ -485,7 +504,12 @@ impl User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Add another user as a friend
|
/// Add another user as a friend
|
||||||
pub async fn add_friend(&mut self, db: &Database, target: &mut User) -> Result<()> {
|
pub async fn add_friend(
|
||||||
|
&mut self,
|
||||||
|
db: &Database,
|
||||||
|
amqp: &AMQP,
|
||||||
|
target: &mut User,
|
||||||
|
) -> Result<()> {
|
||||||
match self.relationship_with(&target.id) {
|
match self.relationship_with(&target.id) {
|
||||||
RelationshipStatus::User => Err(create_error!(NoEffect)),
|
RelationshipStatus::User => Err(create_error!(NoEffect)),
|
||||||
RelationshipStatus::Friend => Err(create_error!(AlreadyFriends)),
|
RelationshipStatus::Friend => Err(create_error!(AlreadyFriends)),
|
||||||
@@ -494,6 +518,8 @@ impl User {
|
|||||||
RelationshipStatus::BlockedOther => Err(create_error!(BlockedByOther)),
|
RelationshipStatus::BlockedOther => Err(create_error!(BlockedByOther)),
|
||||||
RelationshipStatus::Incoming => {
|
RelationshipStatus::Incoming => {
|
||||||
// Accept incoming friend request
|
// Accept incoming friend request
|
||||||
|
_ = amqp.friend_request_accepted(self, target).await;
|
||||||
|
|
||||||
self.apply_relationship(
|
self.apply_relationship(
|
||||||
db,
|
db,
|
||||||
target,
|
target,
|
||||||
@@ -522,6 +548,8 @@ impl User {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_ = amqp.friend_request_received(target, self).await;
|
||||||
|
|
||||||
// Send the friend request
|
// Send the friend request
|
||||||
self.apply_relationship(
|
self.apply_relationship(
|
||||||
db,
|
db,
|
||||||
@@ -659,17 +687,106 @@ impl User {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
FieldsUser::DisplayName => self.display_name = None,
|
FieldsUser::DisplayName => self.display_name = None,
|
||||||
|
FieldsUser::Suspension => self.suspended_until = None,
|
||||||
|
FieldsUser::None => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Suspend the user
|
/// Suspend the user
|
||||||
pub async fn suspend(&mut self, db: &Database) -> Result<()> {
|
///
|
||||||
// Remove sessions (logout all)
|
/// - If a duration is specified, the user will be automatically unsuspended after the given time.
|
||||||
// Mark user as suspended
|
/// - If a reason is specified, an email will be sent.
|
||||||
// Disable account
|
pub async fn suspend(
|
||||||
|
&mut self,
|
||||||
|
db: &Database,
|
||||||
|
duration_days: Option<usize>,
|
||||||
|
reason: Option<Vec<String>>,
|
||||||
|
) -> Result<()> {
|
||||||
|
let authifier = db.clone().to_authifier().await;
|
||||||
|
let mut account = authifier
|
||||||
|
.database
|
||||||
|
.find_account(&self.id)
|
||||||
|
.await
|
||||||
|
.map_err(|_| create_error!(InternalError))?;
|
||||||
|
|
||||||
|
account
|
||||||
|
.disable(&authifier)
|
||||||
|
.await
|
||||||
|
.map_err(|_| create_error!(InternalError))?;
|
||||||
|
|
||||||
|
account
|
||||||
|
.delete_all_sessions(&authifier, None)
|
||||||
|
.await
|
||||||
|
.map_err(|_| create_error!(InternalError))?;
|
||||||
|
|
||||||
|
self.update(
|
||||||
|
db,
|
||||||
|
PartialUser {
|
||||||
|
flags: Some(UserFlags::SuspendedUntil as i32),
|
||||||
|
suspended_until: duration_days.and_then(|dur| {
|
||||||
|
Timestamp::now_utc().checked_add(iso8601_timestamp::Duration::days(dur as i64))
|
||||||
|
}),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
vec![],
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if let Some(reason) = reason {
|
||||||
|
if let EmailVerificationConfig::Enabled { smtp, .. } =
|
||||||
|
authifier.config.email_verification
|
||||||
|
{
|
||||||
|
smtp.send_email(
|
||||||
|
account.email.clone(),
|
||||||
|
// maybe move this to common area?
|
||||||
|
&Template {
|
||||||
|
title: "Account Suspension".to_string(),
|
||||||
|
html: Some(include_str!("../../../templates/suspension.html").to_owned()),
|
||||||
|
text: include_str!("../../../templates/suspension.txt").to_owned(),
|
||||||
|
url: Default::default(),
|
||||||
|
},
|
||||||
|
json!({
|
||||||
|
"email": account.email,
|
||||||
|
"list": reason.join(", "),
|
||||||
|
"duration": duration_days,
|
||||||
|
"duration_display": if duration_days.is_some() {
|
||||||
|
"block"
|
||||||
|
} else {
|
||||||
|
"none"
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.map_err(|_| create_error!(InternalError))?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Unsuspend the user
|
||||||
|
pub async fn unsuspend(&mut self, db: &Database) -> Result<()> {
|
||||||
|
self.update(
|
||||||
|
db,
|
||||||
|
PartialUser {
|
||||||
|
flags: Some(0),
|
||||||
|
suspended_until: None,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
vec![],
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Permanently ban the user
|
||||||
|
///
|
||||||
|
/// - If a reason is specified, an email will be sent.
|
||||||
|
pub async fn ban(&mut self, _db: &Database, _reason: Option<String>) -> Result<()> {
|
||||||
|
// Send ban email (if reason provided)
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
/// Mark as deleted
|
/// Mark as deleted
|
||||||
pub async fn mark_deleted(&mut self, db: &Database) -> Result<()> {
|
pub async fn mark_deleted(&mut self, db: &Database) -> Result<()> {
|
||||||
self.update(
|
self.update(
|
||||||
@@ -685,6 +802,7 @@ impl User {
|
|||||||
FieldsUser::StatusPresence,
|
FieldsUser::StatusPresence,
|
||||||
FieldsUser::ProfileContent,
|
FieldsUser::ProfileContent,
|
||||||
FieldsUser::ProfileBackground,
|
FieldsUser::ProfileBackground,
|
||||||
|
FieldsUser::Suspension,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|||||||
@@ -346,6 +346,8 @@ impl IntoDocumentPath for FieldsUser {
|
|||||||
FieldsUser::StatusPresence => "status.presence",
|
FieldsUser::StatusPresence => "status.presence",
|
||||||
FieldsUser::StatusText => "status.text",
|
FieldsUser::StatusText => "status.text",
|
||||||
FieldsUser::DisplayName => "display_name",
|
FieldsUser::DisplayName => "display_name",
|
||||||
|
FieldsUser::Suspension => "suspended_until",
|
||||||
|
FieldsUser::None => "none",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ impl<'r> FromRequest<'r> for User {
|
|||||||
if let Some(user) = user {
|
if let Some(user) = user {
|
||||||
Outcome::Success(user.clone())
|
Outcome::Success(user.clone())
|
||||||
} else {
|
} else {
|
||||||
Outcome::Failure((Status::Unauthorized, authifier::Error::InvalidSession))
|
Outcome::Error((Status::Unauthorized, authifier::Error::InvalidSession))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,27 @@
|
|||||||
// Queue Type: Debounced
|
// Queue Type: Debounced
|
||||||
use crate::Database;
|
use crate::{Database, Message, AMQP};
|
||||||
|
|
||||||
use deadqueue::limited::Queue;
|
use deadqueue::limited::Queue;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use std::{collections::HashMap, time::Duration};
|
use revolt_models::v0::PushNotification;
|
||||||
|
use rocket::form::validate::Contains;
|
||||||
|
use std::{
|
||||||
|
collections::{HashMap, HashSet},
|
||||||
|
time::Duration,
|
||||||
|
};
|
||||||
|
use validator::HasLen;
|
||||||
|
|
||||||
use revolt_result::Result;
|
use revolt_result::Result;
|
||||||
|
|
||||||
use super::{apple_notifications::{self, ApnJob}, DelayedTask};
|
use super::DelayedTask;
|
||||||
|
|
||||||
/// Enumeration of possible events
|
/// Enumeration of possible events
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
pub enum AckEvent {
|
pub enum AckEvent {
|
||||||
/// Add mentions for a user in a channel
|
/// Add mentions for a channel
|
||||||
AddMention {
|
ProcessMessage {
|
||||||
/// Message IDs
|
/// push notification, message, recipients, push silenced
|
||||||
ids: Vec<String>,
|
messages: Vec<(Option<PushNotification>, Message, Vec<String>, bool)>,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Acknowledge message in a channel for a user
|
/// Acknowledge message in a channel for a user
|
||||||
@@ -30,7 +36,7 @@ struct Data {
|
|||||||
/// Channel to ack
|
/// Channel to ack
|
||||||
channel: String,
|
channel: String,
|
||||||
/// User to ack for
|
/// User to ack for
|
||||||
user: String,
|
user: Option<String>,
|
||||||
/// Event
|
/// Event
|
||||||
event: AckEvent,
|
event: AckEvent,
|
||||||
}
|
}
|
||||||
@@ -43,21 +49,49 @@ struct Task {
|
|||||||
static Q: Lazy<Queue<Data>> = Lazy::new(|| Queue::new(10_000));
|
static Q: Lazy<Queue<Data>> = Lazy::new(|| Queue::new(10_000));
|
||||||
|
|
||||||
/// Queue a new task for a worker
|
/// Queue a new task for a worker
|
||||||
pub async fn queue(channel: String, user: String, event: AckEvent) {
|
pub async fn queue_ack(channel: String, user: String, event: AckEvent) {
|
||||||
Q.try_push(Data {
|
Q.try_push(Data {
|
||||||
channel,
|
channel,
|
||||||
user,
|
user: Some(user),
|
||||||
event,
|
event,
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
info!("Queue is using {} slots from {}.", Q.len(), Q.capacity());
|
info!(
|
||||||
|
"Queue is using {} slots from {}. Queued type: ACK",
|
||||||
|
Q.len(),
|
||||||
|
Q.capacity()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn handle_ack_event(event: &AckEvent, db: &Database, authifier_db: &authifier::Database, user: &str, channel: &str) -> Result<()> {
|
pub async fn queue_message(channel: String, event: AckEvent) {
|
||||||
|
Q.try_push(Data {
|
||||||
|
channel,
|
||||||
|
user: None,
|
||||||
|
event,
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
|
||||||
|
info!(
|
||||||
|
"Queue is using {} slots from {}. Queued type: MENTION",
|
||||||
|
Q.len(),
|
||||||
|
Q.capacity()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn handle_ack_event(
|
||||||
|
event: &AckEvent,
|
||||||
|
db: &Database,
|
||||||
|
amqp: &AMQP,
|
||||||
|
user: &Option<String>,
|
||||||
|
channel: &str,
|
||||||
|
) -> Result<()> {
|
||||||
match &event {
|
match &event {
|
||||||
#[allow(clippy::disallowed_methods)] // event is sent by higher level function
|
#[allow(clippy::disallowed_methods)] // event is sent by higher level function
|
||||||
AckEvent::AckMessage { id } => {
|
AckEvent::AckMessage { id } => {
|
||||||
|
let user = user.as_ref().unwrap();
|
||||||
|
let user: &str = user.as_str();
|
||||||
|
|
||||||
let unread = db.fetch_unread(user, channel).await?;
|
let unread = db.fetch_unread(user, channel).await?;
|
||||||
let updated = db.acknowledge_message(channel, user, id).await?;
|
let updated = db.acknowledge_message(channel, user, id).await?;
|
||||||
|
|
||||||
@@ -68,21 +102,67 @@ pub async fn handle_ack_event(event: &AckEvent, db: &Database, authifier_db: &au
|
|||||||
let mentions_acked = before_mentions - after_mentions;
|
let mentions_acked = before_mentions - after_mentions;
|
||||||
|
|
||||||
if mentions_acked > 0 {
|
if mentions_acked > 0 {
|
||||||
if let Ok(sessions) = authifier_db.find_sessions(user).await {
|
if let Err(err) = amqp
|
||||||
for session in sessions {
|
.ack_message(user.to_string(), channel.to_string(), id.to_owned())
|
||||||
if let Some(sub) = session.subscription {
|
.await
|
||||||
if sub.endpoint == "apn" {
|
{
|
||||||
apple_notifications::queue(ApnJob::from_ack(session.id, user.to_string(), sub.auth)).await;
|
revolt_config::capture_error(&err);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
AckEvent::AddMention { ids } => {
|
AckEvent::ProcessMessage { messages } => {
|
||||||
db.add_mention_to_unread(channel, user, ids).await?;
|
let mut users: HashSet<&String> = HashSet::new();
|
||||||
|
debug!(
|
||||||
|
"Processing {} messages from channel {}",
|
||||||
|
messages.len(),
|
||||||
|
messages[0].1.channel
|
||||||
|
);
|
||||||
|
|
||||||
|
// find all the users we'll be notifying
|
||||||
|
messages
|
||||||
|
.iter()
|
||||||
|
.for_each(|(_, _, recipents, _)| users.extend(recipents.iter()));
|
||||||
|
|
||||||
|
debug!("Found {} users to notify.", users.len());
|
||||||
|
|
||||||
|
for user in users {
|
||||||
|
let message_ids: Vec<String> = messages
|
||||||
|
.iter()
|
||||||
|
.filter(|(_, _, recipients, _)| recipients.contains(user))
|
||||||
|
.map(|(_, message, _, _)| message.id.clone())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
if !message_ids.is_empty() {
|
||||||
|
db.add_mention_to_unread(channel, user, &message_ids)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
debug!("Added {} mentions for user {}", message_ids.len(), &user);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (push, _, recipients, silenced) in messages {
|
||||||
|
if *silenced || recipients.is_empty() || push.is_none() {
|
||||||
|
debug!(
|
||||||
|
"Rejecting push: silenced: {}, recipient count: {}, push exists: {:?}",
|
||||||
|
*silenced,
|
||||||
|
recipients.length(),
|
||||||
|
push
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
debug!(
|
||||||
|
"Sending push event to AMQP; message {} for {} users",
|
||||||
|
push.as_ref().unwrap().message.id,
|
||||||
|
recipients.len()
|
||||||
|
);
|
||||||
|
if let Err(err) = amqp
|
||||||
|
.message_sent(recipients.clone(), push.clone().unwrap())
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
revolt_config::capture_error(&err);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -90,9 +170,9 @@ pub async fn handle_ack_event(event: &AckEvent, db: &Database, authifier_db: &au
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Start a new worker
|
/// Start a new worker
|
||||||
pub async fn worker(db: Database, authifier_db: authifier::Database) {
|
pub async fn worker(db: Database, amqp: AMQP) {
|
||||||
let mut tasks = HashMap::<(String, String), DelayedTask<Task>>::new();
|
let mut tasks = HashMap::<(Option<String>, String, u8), DelayedTask<Task>>::new();
|
||||||
let mut keys = vec![];
|
let mut keys: Vec<(Option<String>, String, u8)> = vec![];
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// Find due tasks.
|
// Find due tasks.
|
||||||
@@ -106,12 +186,13 @@ pub async fn worker(db: Database, authifier_db: authifier::Database) {
|
|||||||
for key in &keys {
|
for key in &keys {
|
||||||
if let Some(task) = tasks.remove(key) {
|
if let Some(task) = tasks.remove(key) {
|
||||||
let Task { event } = task.data;
|
let Task { event } = task.data;
|
||||||
let (user, channel) = key;
|
let (user, channel, _) = key;
|
||||||
|
|
||||||
if let Err(err) = handle_ack_event(&event, &db, &authifier_db, user, channel).await {
|
if let Err(err) = handle_ack_event(&event, &db, &amqp, user, channel).await {
|
||||||
error!("{err:?} for {event:?}. ({user}, {channel})");
|
revolt_config::capture_error(&err);
|
||||||
|
error!("{err:?} for {event:?}. ({user:?}, {channel})");
|
||||||
} else {
|
} else {
|
||||||
info!("User {user} ack in {channel} with {event:?}");
|
info!("User {user:?} ack in {channel} with {event:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -126,20 +207,41 @@ pub async fn worker(db: Database, authifier_db: authifier::Database) {
|
|||||||
mut event,
|
mut event,
|
||||||
}) = Q.try_pop()
|
}) = Q.try_pop()
|
||||||
{
|
{
|
||||||
let key = (user, channel);
|
let key: (Option<String>, String, u8) = (
|
||||||
|
user,
|
||||||
|
channel,
|
||||||
|
match &event {
|
||||||
|
AckEvent::AckMessage { .. } => 0,
|
||||||
|
AckEvent::ProcessMessage { .. } => 1,
|
||||||
|
},
|
||||||
|
);
|
||||||
if let Some(task) = tasks.get_mut(&key) {
|
if let Some(task) = tasks.get_mut(&key) {
|
||||||
task.delay();
|
|
||||||
|
|
||||||
match &mut event {
|
match &mut event {
|
||||||
AckEvent::AddMention { ids } => {
|
AckEvent::ProcessMessage { messages: new_data } => {
|
||||||
if let AckEvent::AddMention { ids: existing } = &mut task.data.event {
|
if let AckEvent::ProcessMessage { messages: existing } =
|
||||||
existing.append(ids);
|
&mut task.data.event
|
||||||
|
{
|
||||||
|
// add the new message to the list of messages to be processed.
|
||||||
|
existing.append(new_data);
|
||||||
|
|
||||||
|
// put a cap on the amount of messages that can be queued, for particularly active channels
|
||||||
|
if (existing.length() as u16)
|
||||||
|
< revolt_config::config()
|
||||||
|
.await
|
||||||
|
.features
|
||||||
|
.advanced
|
||||||
|
.process_message_delay_limit
|
||||||
|
{
|
||||||
|
task.delay();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
task.data.event = event;
|
panic!("Somehow got an ack message in the add mention arm");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AckEvent::AckMessage { .. } => {
|
AckEvent::AckMessage { .. } => {
|
||||||
|
// replace the last acked message with the new acked message
|
||||||
task.data.event = event;
|
task.data.event = event;
|
||||||
|
task.delay();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,312 +0,0 @@
|
|||||||
use std::io::Cursor;
|
|
||||||
|
|
||||||
use base64::{
|
|
||||||
engine::{self},
|
|
||||||
Engine as _,
|
|
||||||
};
|
|
||||||
use deadqueue::limited::Queue;
|
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use revolt_a2::{
|
|
||||||
request::{
|
|
||||||
notification::{DefaultAlert, NotificationOptions},
|
|
||||||
payload::{APSAlert, APSSound, PayloadLike, APS},
|
|
||||||
},
|
|
||||||
Client, ClientConfig, Endpoint, Error, ErrorBody, ErrorReason, Priority, PushType, Response,
|
|
||||||
};
|
|
||||||
use revolt_config::config;
|
|
||||||
use revolt_models::v0::{Message, PushNotification};
|
|
||||||
|
|
||||||
use crate::Database;
|
|
||||||
|
|
||||||
/// Payload information, before assembly
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct ApnPayload {
|
|
||||||
message: Message,
|
|
||||||
url: String,
|
|
||||||
authorAvatar: String,
|
|
||||||
authorDisplayName: String,
|
|
||||||
channelName: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Debug)]
|
|
||||||
struct Payload<'a> {
|
|
||||||
aps: APS<'a>,
|
|
||||||
#[serde(skip_serializing)]
|
|
||||||
options: NotificationOptions<'a>,
|
|
||||||
#[serde(skip_serializing)]
|
|
||||||
device_token: &'a str,
|
|
||||||
|
|
||||||
message: &'a Message,
|
|
||||||
url: &'a str,
|
|
||||||
authorAvatar: &'a str,
|
|
||||||
authorDisplayName: &'a str,
|
|
||||||
channelName: &'a str,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> PayloadLike for Payload<'a> {
|
|
||||||
fn get_device_token(&self) -> &'a str {
|
|
||||||
self.device_token
|
|
||||||
}
|
|
||||||
fn get_options(&self) -> &NotificationOptions {
|
|
||||||
&self.options
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Task information
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct AlertJob {
|
|
||||||
/// Session Id
|
|
||||||
session_id: String,
|
|
||||||
|
|
||||||
/// Device token
|
|
||||||
device_token: String,
|
|
||||||
|
|
||||||
/// User Id
|
|
||||||
user_id: String,
|
|
||||||
|
|
||||||
/// Title
|
|
||||||
title: String,
|
|
||||||
|
|
||||||
/// Body
|
|
||||||
body: String,
|
|
||||||
|
|
||||||
/// Thread Id
|
|
||||||
thread_id: String,
|
|
||||||
|
|
||||||
/// Category (informs the client what kind of notification is being sent.)
|
|
||||||
category: String,
|
|
||||||
|
|
||||||
/// Payload used by the iOS client to modify the notification
|
|
||||||
custom_payload: ApnPayload,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AlertJob {
|
|
||||||
fn format_title(notification: &PushNotification) -> String {
|
|
||||||
// ideally this changes depending on context
|
|
||||||
// in a server, it would look like "Sendername, #channelname in servername"
|
|
||||||
// in a group, it would look like "Sendername in groupname"
|
|
||||||
// in a dm it should just be "Sendername".
|
|
||||||
// not sure how feasible all those are given the PushNotification object as it currently stands.
|
|
||||||
format!(
|
|
||||||
"{} in {}",
|
|
||||||
notification.author, notification.message.channel
|
|
||||||
) // TODO: this absolutely needs a channel name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct BadgeJob {
|
|
||||||
/// Session Id
|
|
||||||
session_id: String,
|
|
||||||
|
|
||||||
/// Device token
|
|
||||||
device_token: String,
|
|
||||||
|
|
||||||
/// User Id
|
|
||||||
user_id: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum JobType {
|
|
||||||
Alert(AlertJob),
|
|
||||||
Badge(BadgeJob),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct ApnJob {
|
|
||||||
job_type: JobType,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ApnJob {
|
|
||||||
pub fn from_notification(
|
|
||||||
session_id: String,
|
|
||||||
user_id: String,
|
|
||||||
device_token: String,
|
|
||||||
notification: &PushNotification,
|
|
||||||
) -> ApnJob {
|
|
||||||
ApnJob {
|
|
||||||
job_type: JobType::Alert(AlertJob {
|
|
||||||
session_id,
|
|
||||||
device_token,
|
|
||||||
user_id,
|
|
||||||
title: AlertJob::format_title(notification),
|
|
||||||
body: notification.body.to_string(),
|
|
||||||
thread_id: notification.tag.to_string(),
|
|
||||||
category: "ALERT_MESSAGE".to_string(),
|
|
||||||
custom_payload: ApnPayload {
|
|
||||||
message: notification.message.clone(),
|
|
||||||
url: notification.url.clone(),
|
|
||||||
authorAvatar: notification.icon.clone(),
|
|
||||||
authorDisplayName: notification.author.clone(),
|
|
||||||
channelName: "#fetchchannelnamehere".to_string(), // TODO: get actual channel name
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_ack(session_id: String, user_id: String, device_token: String) -> ApnJob {
|
|
||||||
ApnJob {
|
|
||||||
job_type: JobType::Badge(BadgeJob {
|
|
||||||
session_id,
|
|
||||||
device_token,
|
|
||||||
user_id,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum AssembledPayload<'a> {
|
|
||||||
Alert(Payload<'a>),
|
|
||||||
Default(revolt_a2::request::payload::Payload<'a>),
|
|
||||||
}
|
|
||||||
|
|
||||||
static Q: Lazy<Queue<ApnJob>> = Lazy::new(|| Queue::new(10_000));
|
|
||||||
|
|
||||||
/// Queue a new task for a worker
|
|
||||||
pub async fn queue(task: ApnJob) {
|
|
||||||
Q.try_push(task).ok();
|
|
||||||
info!("Queue is using {} slots from {}.", Q.len(), Q.capacity());
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_badge_count(db: &Database, user: &str) -> Option<u32> {
|
|
||||||
if let Ok(unreads) = db.fetch_unreads(user).await {
|
|
||||||
let mut mention_count = 0;
|
|
||||||
for channel in unreads {
|
|
||||||
if let Some(mentions) = channel.mentions {
|
|
||||||
mention_count += mentions.len() as u32
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Some(mention_count);
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Start a new worker
|
|
||||||
pub async fn worker(db: Database) {
|
|
||||||
let config = config().await;
|
|
||||||
if config.api.apn.pkcs8.is_empty()
|
|
||||||
|| config.api.apn.key_id.is_empty()
|
|
||||||
|| config.api.apn.team_id.is_empty()
|
|
||||||
{
|
|
||||||
eprintln!("Missing APN keys.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let endpoint = if config.api.apn.sandbox {
|
|
||||||
Endpoint::Sandbox
|
|
||||||
} else {
|
|
||||||
Endpoint::Production
|
|
||||||
};
|
|
||||||
|
|
||||||
let pkcs8 = engine::general_purpose::STANDARD
|
|
||||||
.decode(config.api.apn.pkcs8)
|
|
||||||
.expect("valid `pcks8`");
|
|
||||||
|
|
||||||
let client_config = ClientConfig::new(endpoint);
|
|
||||||
|
|
||||||
let client = Client::token(
|
|
||||||
&mut Cursor::new(pkcs8),
|
|
||||||
config.api.apn.key_id,
|
|
||||||
config.api.apn.team_id,
|
|
||||||
client_config,
|
|
||||||
)
|
|
||||||
.expect("could not create APN client");
|
|
||||||
|
|
||||||
let payload_options = NotificationOptions {
|
|
||||||
apns_id: None,
|
|
||||||
apns_push_type: Some(PushType::Alert),
|
|
||||||
apns_expiration: None,
|
|
||||||
apns_priority: Some(Priority::High),
|
|
||||||
apns_topic: Some("chat.revolt.app"),
|
|
||||||
apns_collapse_id: None,
|
|
||||||
};
|
|
||||||
|
|
||||||
loop {
|
|
||||||
let task = Q.pop().await;
|
|
||||||
let payload: AssembledPayload;
|
|
||||||
|
|
||||||
match task.job_type {
|
|
||||||
JobType::Alert(ref alert) => {
|
|
||||||
payload = AssembledPayload::Alert(Payload {
|
|
||||||
aps: APS {
|
|
||||||
alert: Some(APSAlert::Default(DefaultAlert {
|
|
||||||
title: Some(&alert.title),
|
|
||||||
subtitle: None,
|
|
||||||
body: Some(&alert.body),
|
|
||||||
title_loc_key: None,
|
|
||||||
title_loc_args: None,
|
|
||||||
action_loc_key: None,
|
|
||||||
loc_key: None,
|
|
||||||
loc_args: None,
|
|
||||||
launch_image: None,
|
|
||||||
})),
|
|
||||||
badge: get_badge_count(&db, &alert.user_id).await,
|
|
||||||
sound: Some(APSSound::Sound("default")),
|
|
||||||
thread_id: Some(&alert.thread_id),
|
|
||||||
content_available: None,
|
|
||||||
category: Some(&alert.category),
|
|
||||||
mutable_content: Some(1),
|
|
||||||
url_args: None,
|
|
||||||
},
|
|
||||||
device_token: &alert.device_token,
|
|
||||||
options: payload_options.clone(),
|
|
||||||
message: &alert.custom_payload.message,
|
|
||||||
url: &alert.custom_payload.url,
|
|
||||||
authorAvatar: &alert.custom_payload.authorAvatar,
|
|
||||||
authorDisplayName: &alert.custom_payload.authorDisplayName,
|
|
||||||
channelName: &alert.custom_payload.channelName,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
JobType::Badge(ref alert) => {
|
|
||||||
payload = AssembledPayload::Default(revolt_a2::request::payload::Payload {
|
|
||||||
aps: APS {
|
|
||||||
alert: None,
|
|
||||||
badge: get_badge_count(&db, &alert.user_id).await,
|
|
||||||
sound: None,
|
|
||||||
thread_id: None,
|
|
||||||
content_available: None,
|
|
||||||
category: None,
|
|
||||||
mutable_content: None,
|
|
||||||
url_args: None,
|
|
||||||
},
|
|
||||||
device_token: &alert.device_token,
|
|
||||||
options: payload_options.clone(),
|
|
||||||
data: std::collections::BTreeMap::new(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let resp = match payload {
|
|
||||||
AssembledPayload::Alert(p) => client.send(p).await,
|
|
||||||
AssembledPayload::Default(p) => client.send(p).await,
|
|
||||||
};
|
|
||||||
//println!("response from APNS: {:?}", resp);
|
|
||||||
|
|
||||||
if let Err(err) = resp {
|
|
||||||
match err {
|
|
||||||
Error::ResponseError(Response {
|
|
||||||
error:
|
|
||||||
Some(ErrorBody {
|
|
||||||
reason: ErrorReason::BadDeviceToken | ErrorReason::Unregistered,
|
|
||||||
..
|
|
||||||
}),
|
|
||||||
..
|
|
||||||
}) => {
|
|
||||||
if let Err(err) = db
|
|
||||||
.remove_push_subscription_by_session_id(match task.job_type {
|
|
||||||
JobType::Alert(ref a) => &a.session_id.as_str(),
|
|
||||||
JobType::Badge(ref a) => &a.session_id.as_str(),
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
revolt_config::capture_error(&err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
err => {
|
|
||||||
revolt_config::capture_error(&err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
use async_std::channel::{unbounded, Receiver, Sender};
|
||||||
|
use authifier::AuthifierEvent;
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
|
use crate::events::client::EventV1;
|
||||||
|
|
||||||
|
static Q: Lazy<(Sender<AuthifierEvent>, Receiver<AuthifierEvent>)> = Lazy::new(|| unbounded());
|
||||||
|
|
||||||
|
/// Get sender
|
||||||
|
pub fn sender() -> Sender<AuthifierEvent> {
|
||||||
|
Q.0.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Start a new worker
|
||||||
|
pub async fn worker() {
|
||||||
|
loop {
|
||||||
|
let event = Q.1.recv().await.unwrap();
|
||||||
|
match &event {
|
||||||
|
AuthifierEvent::CreateSession { .. } | AuthifierEvent::CreateAccount { .. } => {
|
||||||
|
EventV1::Auth(event).global().await
|
||||||
|
}
|
||||||
|
AuthifierEvent::DeleteSession { user_id, .. }
|
||||||
|
| AuthifierEvent::DeleteAllSessions { user_id, .. } => {
|
||||||
|
let id = user_id.to_string();
|
||||||
|
EventV1::Auth(event).private(id).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
//! Semi-important background task management
|
//! Semi-important background task management
|
||||||
|
|
||||||
use crate::Database;
|
use crate::{Database, AMQP};
|
||||||
|
|
||||||
use async_std::task;
|
use async_std::task;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
@@ -8,20 +8,18 @@ use std::time::Instant;
|
|||||||
const WORKER_COUNT: usize = 5;
|
const WORKER_COUNT: usize = 5;
|
||||||
|
|
||||||
pub mod ack;
|
pub mod ack;
|
||||||
pub mod apple_notifications;
|
pub mod authifier_relay;
|
||||||
pub mod last_message_id;
|
pub mod last_message_id;
|
||||||
pub mod process_embeds;
|
pub mod process_embeds;
|
||||||
pub mod web_push;
|
|
||||||
|
|
||||||
/// Spawn background workers
|
/// Spawn background workers
|
||||||
pub async fn start_workers(db: Database, authifier_db: authifier::Database) {
|
pub fn start_workers(db: Database, amqp: AMQP) {
|
||||||
task::spawn(apple_notifications::worker(db.clone()));
|
task::spawn(authifier_relay::worker());
|
||||||
|
|
||||||
for _ in 0..WORKER_COUNT {
|
for _ in 0..WORKER_COUNT {
|
||||||
task::spawn(ack::worker(db.clone(), authifier_db.clone()));
|
task::spawn(ack::worker(db.clone(), amqp.clone()));
|
||||||
task::spawn(last_message_id::worker(db.clone()));
|
task::spawn(last_message_id::worker(db.clone()));
|
||||||
task::spawn(process_embeds::worker(db.clone()));
|
task::spawn(process_embeds::worker(db.clone()));
|
||||||
task::spawn(web_push::worker(authifier_db.clone()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,206 +0,0 @@
|
|||||||
use std::{
|
|
||||||
collections::{HashMap, HashSet},
|
|
||||||
time::Duration,
|
|
||||||
};
|
|
||||||
|
|
||||||
use authifier::Database;
|
|
||||||
use base64::{
|
|
||||||
engine::{self},
|
|
||||||
Engine as _,
|
|
||||||
};
|
|
||||||
use deadqueue::limited::Queue;
|
|
||||||
use fcm_v1::auth::{Authenticator, ServiceAccountKey};
|
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use revolt_config::config;
|
|
||||||
use revolt_models::v0::PushNotification;
|
|
||||||
use revolt_presence::filter_online;
|
|
||||||
use serde_json::json;
|
|
||||||
use web_push::{
|
|
||||||
ContentEncoding, IsahcWebPushClient, SubscriptionInfo, SubscriptionKeys, VapidSignatureBuilder,
|
|
||||||
WebPushClient, WebPushMessageBuilder,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::apple_notifications;
|
|
||||||
|
|
||||||
/// Task information
|
|
||||||
#[derive(Debug)]
|
|
||||||
struct PushTask {
|
|
||||||
/// User IDs of the targets that are to receive this notification
|
|
||||||
recipients: Vec<String>,
|
|
||||||
/// Push Notification
|
|
||||||
payload: PushNotification,
|
|
||||||
}
|
|
||||||
|
|
||||||
static Q: Lazy<Queue<PushTask>> = Lazy::new(|| Queue::new(10_000));
|
|
||||||
|
|
||||||
/// Queue a new task for a worker
|
|
||||||
pub async fn queue(recipients: Vec<String>, payload: PushNotification) {
|
|
||||||
if recipients.is_empty() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let online_ids = filter_online(&recipients).await;
|
|
||||||
let recipients = (&recipients.into_iter().collect::<HashSet<String>>() - &online_ids)
|
|
||||||
.into_iter()
|
|
||||||
.collect::<Vec<String>>();
|
|
||||||
|
|
||||||
Q.try_push(PushTask {
|
|
||||||
recipients,
|
|
||||||
payload,
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
|
|
||||||
info!("Queue is using {} slots from {}.", Q.len(), Q.capacity());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Start a new worker
|
|
||||||
pub async fn worker(db: Database) {
|
|
||||||
let config = config().await;
|
|
||||||
|
|
||||||
let web_push_client = IsahcWebPushClient::new().unwrap();
|
|
||||||
let fcm_client = if config.api.fcm.key_type.is_empty() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(fcm_v1::Client::new(
|
|
||||||
Authenticator::service_account::<&str>(ServiceAccountKey {
|
|
||||||
key_type: Some(config.api.fcm.key_type),
|
|
||||||
project_id: Some(config.api.fcm.project_id.clone()),
|
|
||||||
private_key_id: Some(config.api.fcm.private_key_id),
|
|
||||||
private_key: config.api.fcm.private_key,
|
|
||||||
client_email: config.api.fcm.client_email,
|
|
||||||
client_id: Some(config.api.fcm.client_id),
|
|
||||||
auth_uri: Some(config.api.fcm.auth_uri),
|
|
||||||
token_uri: config.api.fcm.token_uri,
|
|
||||||
auth_provider_x509_cert_url: Some(config.api.fcm.auth_provider_x509_cert_url),
|
|
||||||
client_x509_cert_url: Some(config.api.fcm.client_x509_cert_url),
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
.unwrap(),
|
|
||||||
config.api.fcm.project_id,
|
|
||||||
false,
|
|
||||||
Duration::from_secs(5),
|
|
||||||
))
|
|
||||||
};
|
|
||||||
|
|
||||||
let web_push_private_key = engine::general_purpose::URL_SAFE_NO_PAD
|
|
||||||
.decode(config.api.vapid.private_key)
|
|
||||||
.expect("valid `VAPID_PRIVATE_KEY`");
|
|
||||||
|
|
||||||
loop {
|
|
||||||
let task = Q.pop().await;
|
|
||||||
|
|
||||||
if let Ok(sessions) = db.find_sessions_with_subscription(&task.recipients).await {
|
|
||||||
for session in sessions {
|
|
||||||
if let Some(sub) = session.subscription {
|
|
||||||
if sub.endpoint == "fcm" {
|
|
||||||
// Use Firebase Cloud Messaging
|
|
||||||
if let Some(client) = &fcm_client {
|
|
||||||
let PushNotification {
|
|
||||||
author,
|
|
||||||
icon,
|
|
||||||
image,
|
|
||||||
body,
|
|
||||||
tag: _,
|
|
||||||
timestamp,
|
|
||||||
url: _,
|
|
||||||
message,
|
|
||||||
} = &task.payload;
|
|
||||||
|
|
||||||
let message = fcm_v1::message::Message {
|
|
||||||
token: Some(sub.auth),
|
|
||||||
data: Some(HashMap::from([
|
|
||||||
(
|
|
||||||
"author".to_owned(),
|
|
||||||
serde_json::Value::String(author.clone()),
|
|
||||||
),
|
|
||||||
("icon".to_owned(), serde_json::Value::String(icon.clone())),
|
|
||||||
(
|
|
||||||
"image".to_owned(),
|
|
||||||
if let Some(image) = image {
|
|
||||||
serde_json::Value::String(image.clone())
|
|
||||||
} else {
|
|
||||||
serde_json::Value::Null
|
|
||||||
},
|
|
||||||
),
|
|
||||||
("body".to_owned(), serde_json::Value::String(body.clone())),
|
|
||||||
("timestamp".to_owned(), json!(timestamp)),
|
|
||||||
("message".to_owned(), json!(&message)),
|
|
||||||
])),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Err(err) = client.send(&message).await {
|
|
||||||
error!("Failed to send FCM notification! {:?}", err);
|
|
||||||
} else {
|
|
||||||
info!("Sent FCM notification to {:?}.", session.id);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
info!("No FCM token was specified!");
|
|
||||||
}
|
|
||||||
} else if sub.endpoint == "apn" {
|
|
||||||
apple_notifications::queue(apple_notifications::ApnJob::from_notification(
|
|
||||||
session.id,
|
|
||||||
session.user_id,
|
|
||||||
sub.auth,
|
|
||||||
&task.payload,
|
|
||||||
))
|
|
||||||
.await;
|
|
||||||
} else {
|
|
||||||
// Use Web Push Standard
|
|
||||||
let subscription = SubscriptionInfo {
|
|
||||||
endpoint: sub.endpoint,
|
|
||||||
keys: SubscriptionKeys {
|
|
||||||
auth: sub.auth,
|
|
||||||
p256dh: sub.p256dh,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
match VapidSignatureBuilder::from_pem(
|
|
||||||
std::io::Cursor::new(&web_push_private_key),
|
|
||||||
&subscription,
|
|
||||||
) {
|
|
||||||
Ok(sig_builder) => match sig_builder.build() {
|
|
||||||
Ok(signature) => {
|
|
||||||
let mut builder = WebPushMessageBuilder::new(&subscription);
|
|
||||||
builder.set_vapid_signature(signature);
|
|
||||||
|
|
||||||
let payload = json!(task.payload).to_string();
|
|
||||||
builder
|
|
||||||
.set_payload(ContentEncoding::AesGcm, payload.as_bytes());
|
|
||||||
|
|
||||||
match builder.build() {
|
|
||||||
Ok(msg) => match web_push_client.send(msg).await {
|
|
||||||
Ok(_) => {
|
|
||||||
info!(
|
|
||||||
"Sent Web Push notification to {:?}.",
|
|
||||||
session.id
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
error!("Hit error sending Web Push! {:?}", err)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(err) => {
|
|
||||||
error!(
|
|
||||||
"Failed to build message for {}! {:?}",
|
|
||||||
session.user_id, err
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => error!(
|
|
||||||
"Failed to build signature for {}! {:?}",
|
|
||||||
session.user_id, err
|
|
||||||
),
|
|
||||||
},
|
|
||||||
Err(err) => error!(
|
|
||||||
"Failed to create signature builder for {}! {:?}",
|
|
||||||
session.user_id, err
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
use revolt_models::v0::*;
|
use revolt_models::v0::*;
|
||||||
use revolt_permissions::{calculate_user_permissions, UserPermission};
|
use revolt_permissions::{calculate_user_permissions, UserPermission};
|
||||||
|
|
||||||
use crate::{util::permissions::DatabasePermissionQuery, Database};
|
use crate::{util::permissions::DatabasePermissionQuery, Database, FileUsedFor};
|
||||||
|
|
||||||
impl crate::Bot {
|
impl crate::Bot {
|
||||||
pub fn into_public_bot(self, user: crate::User) -> PublicBot {
|
pub fn into_public_bot(self, user: crate::User) -> PublicBot {
|
||||||
@@ -108,6 +108,7 @@ impl From<crate::Webhook> for Webhook {
|
|||||||
id: value.id,
|
id: value.id,
|
||||||
name: value.name,
|
name: value.name,
|
||||||
avatar: value.avatar.map(|file| file.into()),
|
avatar: value.avatar.map(|file| file.into()),
|
||||||
|
creator_id: value.creator_id,
|
||||||
channel_id: value.channel_id,
|
channel_id: value.channel_id,
|
||||||
token: value.token,
|
token: value.token,
|
||||||
permissions: value.permissions,
|
permissions: value.permissions,
|
||||||
@@ -121,6 +122,7 @@ impl From<crate::PartialWebhook> for PartialWebhook {
|
|||||||
id: value.id,
|
id: value.id,
|
||||||
name: value.name,
|
name: value.name,
|
||||||
avatar: value.avatar.map(|file| file.into()),
|
avatar: value.avatar.map(|file| file.into()),
|
||||||
|
creator_id: value.creator_id,
|
||||||
channel_id: value.channel_id,
|
channel_id: value.channel_id,
|
||||||
token: value.token,
|
token: value.token,
|
||||||
permissions: value.permissions,
|
permissions: value.permissions,
|
||||||
@@ -419,6 +421,10 @@ impl From<File> for crate::File {
|
|||||||
user_id: value.user_id,
|
user_id: value.user_id,
|
||||||
server_id: value.server_id,
|
server_id: value.server_id,
|
||||||
object_id: value.object_id,
|
object_id: value.object_id,
|
||||||
|
hash: None,
|
||||||
|
uploaded_at: None,
|
||||||
|
uploader_id: None,
|
||||||
|
used_for: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1171,6 +1177,7 @@ impl From<User> for crate::User {
|
|||||||
flags: Some(value.flags as i32),
|
flags: Some(value.flags as i32),
|
||||||
privileged: value.privileged,
|
privileged: value.privileged,
|
||||||
bot: value.bot.map(Into::into),
|
bot: value.bot.map(Into::into),
|
||||||
|
suspended_until: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1209,6 +1216,8 @@ impl From<FieldsUser> for crate::FieldsUser {
|
|||||||
FieldsUser::StatusPresence => crate::FieldsUser::StatusPresence,
|
FieldsUser::StatusPresence => crate::FieldsUser::StatusPresence,
|
||||||
FieldsUser::StatusText => crate::FieldsUser::StatusText,
|
FieldsUser::StatusText => crate::FieldsUser::StatusText,
|
||||||
FieldsUser::DisplayName => crate::FieldsUser::DisplayName,
|
FieldsUser::DisplayName => crate::FieldsUser::DisplayName,
|
||||||
|
|
||||||
|
FieldsUser::Internal => crate::FieldsUser::None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1222,6 +1231,9 @@ impl From<crate::FieldsUser> for FieldsUser {
|
|||||||
crate::FieldsUser::StatusPresence => FieldsUser::StatusPresence,
|
crate::FieldsUser::StatusPresence => FieldsUser::StatusPresence,
|
||||||
crate::FieldsUser::StatusText => FieldsUser::StatusText,
|
crate::FieldsUser::StatusText => FieldsUser::StatusText,
|
||||||
crate::FieldsUser::DisplayName => FieldsUser::DisplayName,
|
crate::FieldsUser::DisplayName => FieldsUser::DisplayName,
|
||||||
|
|
||||||
|
crate::FieldsUser::Suspension => FieldsUser::Internal,
|
||||||
|
crate::FieldsUser::None => FieldsUser::Internal,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1338,4 +1350,4 @@ impl From<FieldsMessage> for crate::FieldsMessage {
|
|||||||
FieldsMessage::Pinned => crate::FieldsMessage::Pinned,
|
FieldsMessage::Pinned => crate::FieldsMessage::Pinned,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,337 @@
|
|||||||
|
use std::{collections::HashMap, hash::RandomState};
|
||||||
|
|
||||||
|
use revolt_permissions::{
|
||||||
|
ChannelPermission, ChannelType, Override, OverrideField, PermissionValue, ALLOW_IN_TIMEOUT,
|
||||||
|
DEFAULT_PERMISSION_DIRECT_MESSAGE,
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::{Channel, Database, Member, Server, User};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct BulkDatabasePermissionQuery<'a> {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
database: &'a Database,
|
||||||
|
|
||||||
|
server: Server,
|
||||||
|
channel: Option<Channel>,
|
||||||
|
users: Option<Vec<User>>,
|
||||||
|
members: Option<Vec<Member>>,
|
||||||
|
|
||||||
|
// In case the users or members are fetched as part of the permissions checking operation
|
||||||
|
pub(crate) cached_users: Option<Vec<User>>,
|
||||||
|
pub(crate) cached_members: Option<Vec<Member>>,
|
||||||
|
|
||||||
|
cached_member_perms: Option<HashMap<String, PermissionValue>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'z, 'x> BulkDatabasePermissionQuery<'x> {
|
||||||
|
pub async fn members_can_see_channel(&'z mut self) -> HashMap<String, bool>
|
||||||
|
where
|
||||||
|
'z: 'x,
|
||||||
|
{
|
||||||
|
let member_perms = if self.cached_member_perms.is_some() {
|
||||||
|
// This isn't done as an if let to prevent borrow checker errors with the mut self call when the perms aren't cached.
|
||||||
|
let perms = self.cached_member_perms.as_ref().unwrap();
|
||||||
|
perms
|
||||||
|
.iter()
|
||||||
|
.map(|(m, p)| {
|
||||||
|
(
|
||||||
|
m.clone(),
|
||||||
|
p.has_channel_permission(ChannelPermission::ViewChannel),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
} else {
|
||||||
|
calculate_members_permissions(self)
|
||||||
|
.await
|
||||||
|
.iter()
|
||||||
|
.map(|(m, p)| {
|
||||||
|
(
|
||||||
|
m.clone(),
|
||||||
|
p.has_channel_permission(ChannelPermission::ViewChannel),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
};
|
||||||
|
member_perms
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'z> BulkDatabasePermissionQuery<'z> {
|
||||||
|
pub fn new(database: &Database, server: Server) -> BulkDatabasePermissionQuery<'_> {
|
||||||
|
BulkDatabasePermissionQuery {
|
||||||
|
database,
|
||||||
|
server,
|
||||||
|
channel: None,
|
||||||
|
users: None,
|
||||||
|
members: None,
|
||||||
|
cached_members: None,
|
||||||
|
cached_users: None,
|
||||||
|
cached_member_perms: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn from_server_id<'a>(
|
||||||
|
db: &'a Database,
|
||||||
|
server: &str,
|
||||||
|
) -> BulkDatabasePermissionQuery<'a> {
|
||||||
|
BulkDatabasePermissionQuery {
|
||||||
|
database: db,
|
||||||
|
server: db.fetch_server(server).await.unwrap(),
|
||||||
|
channel: None,
|
||||||
|
users: None,
|
||||||
|
members: None,
|
||||||
|
cached_members: None,
|
||||||
|
cached_users: None,
|
||||||
|
cached_member_perms: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn channel(self, channel: &'z Channel) -> BulkDatabasePermissionQuery {
|
||||||
|
BulkDatabasePermissionQuery {
|
||||||
|
channel: Some(channel.clone()),
|
||||||
|
..self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn members(self, members: &'z [Member]) -> BulkDatabasePermissionQuery {
|
||||||
|
BulkDatabasePermissionQuery {
|
||||||
|
members: Some(members.to_owned()),
|
||||||
|
..self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn users(self, users: &'z [User]) -> BulkDatabasePermissionQuery {
|
||||||
|
BulkDatabasePermissionQuery {
|
||||||
|
users: Some(users.to_owned()),
|
||||||
|
..self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the default channel permissions
|
||||||
|
/// Group channel defaults should be mapped to an allow-only override
|
||||||
|
#[allow(dead_code)]
|
||||||
|
async fn get_default_channel_permissions(&mut self) -> Override {
|
||||||
|
if let Some(channel) = &self.channel {
|
||||||
|
match channel {
|
||||||
|
Channel::Group { permissions, .. } => Override {
|
||||||
|
allow: permissions.unwrap_or(*DEFAULT_PERMISSION_DIRECT_MESSAGE as i64) as u64,
|
||||||
|
deny: 0,
|
||||||
|
},
|
||||||
|
Channel::TextChannel {
|
||||||
|
default_permissions,
|
||||||
|
..
|
||||||
|
}
|
||||||
|
| Channel::VoiceChannel {
|
||||||
|
default_permissions,
|
||||||
|
..
|
||||||
|
} => default_permissions.unwrap_or_default().into(),
|
||||||
|
_ => Default::default(),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
fn get_channel_type(&mut self) -> ChannelType {
|
||||||
|
if let Some(channel) = &self.channel {
|
||||||
|
match channel {
|
||||||
|
Channel::DirectMessage { .. } => ChannelType::DirectMessage,
|
||||||
|
Channel::Group { .. } => ChannelType::Group,
|
||||||
|
Channel::SavedMessages { .. } => ChannelType::SavedMessages,
|
||||||
|
Channel::TextChannel { .. } | Channel::VoiceChannel { .. } => {
|
||||||
|
ChannelType::ServerChannel
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ChannelType::Unknown
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the ordered role overrides (from lowest to highest) for this member in this channel
|
||||||
|
#[allow(dead_code)]
|
||||||
|
async fn get_channel_role_overrides(&mut self) -> &HashMap<String, OverrideField> {
|
||||||
|
if let Some(channel) = &self.channel {
|
||||||
|
match channel {
|
||||||
|
Channel::TextChannel {
|
||||||
|
role_permissions, ..
|
||||||
|
}
|
||||||
|
| Channel::VoiceChannel {
|
||||||
|
role_permissions, ..
|
||||||
|
} => role_permissions,
|
||||||
|
_ => panic!("Not supported for non-server channels"),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
panic!("No channel added to query")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Calculate members permissions in a server channel.
|
||||||
|
async fn calculate_members_permissions<'a>(
|
||||||
|
query: &'a mut BulkDatabasePermissionQuery<'a>,
|
||||||
|
) -> HashMap<String, PermissionValue> {
|
||||||
|
let mut resp = HashMap::new();
|
||||||
|
|
||||||
|
let (_, channel_role_permissions, channel_default_permissions) = match query
|
||||||
|
.channel
|
||||||
|
.as_ref()
|
||||||
|
.expect("A channel must be assigned to calculate channel permissions")
|
||||||
|
.clone()
|
||||||
|
{
|
||||||
|
Channel::TextChannel {
|
||||||
|
id,
|
||||||
|
role_permissions,
|
||||||
|
default_permissions,
|
||||||
|
..
|
||||||
|
}
|
||||||
|
| Channel::VoiceChannel {
|
||||||
|
id,
|
||||||
|
role_permissions,
|
||||||
|
default_permissions,
|
||||||
|
..
|
||||||
|
} => (id, role_permissions, default_permissions),
|
||||||
|
_ => panic!("Calculation of member permissions must be done on a server channel"),
|
||||||
|
};
|
||||||
|
|
||||||
|
if query.users.is_none() {
|
||||||
|
let ids: Vec<String> = query
|
||||||
|
.members
|
||||||
|
.as_ref()
|
||||||
|
.expect("No users or members added to the query")
|
||||||
|
.iter()
|
||||||
|
.map(|m| m.id.user.clone())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
query.cached_users = Some(
|
||||||
|
query
|
||||||
|
.database
|
||||||
|
.fetch_users(&ids[..])
|
||||||
|
.await
|
||||||
|
.expect("Failed to get data from the db"),
|
||||||
|
);
|
||||||
|
|
||||||
|
query.users = Some(query.cached_users.as_ref().unwrap().to_vec())
|
||||||
|
}
|
||||||
|
|
||||||
|
let users = query.users.as_ref().unwrap();
|
||||||
|
|
||||||
|
if query.members.is_none() {
|
||||||
|
let ids: Vec<String> = query
|
||||||
|
.users
|
||||||
|
.as_ref()
|
||||||
|
.expect("No users or members added to the query")
|
||||||
|
.iter()
|
||||||
|
.map(|m| m.id.clone())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
query.cached_members = Some(
|
||||||
|
query
|
||||||
|
.database
|
||||||
|
.fetch_members(&query.server.id, &ids[..])
|
||||||
|
.await
|
||||||
|
.expect("Failed to get data from the db"),
|
||||||
|
);
|
||||||
|
query.members = Some(query.cached_members.as_ref().unwrap().to_vec())
|
||||||
|
}
|
||||||
|
|
||||||
|
let members: HashMap<&String, &Member, RandomState> = HashMap::from_iter(
|
||||||
|
query
|
||||||
|
.members
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.iter()
|
||||||
|
.map(|m| (&m.id.user, m)),
|
||||||
|
);
|
||||||
|
|
||||||
|
for user in users {
|
||||||
|
let member = members.get(&user.id);
|
||||||
|
|
||||||
|
// User isn't a part of the server
|
||||||
|
if member.is_none() {
|
||||||
|
resp.insert(user.id.clone(), 0_u64.into());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let member = *member.unwrap();
|
||||||
|
|
||||||
|
if user.privileged {
|
||||||
|
resp.insert(
|
||||||
|
user.id.clone(),
|
||||||
|
PermissionValue::from(ChannelPermission::GrantAllSafe),
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if user.id == query.server.owner {
|
||||||
|
resp.insert(
|
||||||
|
user.id.clone(),
|
||||||
|
PermissionValue::from(ChannelPermission::GrantAllSafe),
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the user's server permissions
|
||||||
|
let mut permission = calculate_server_permissions(&query.server, user, member);
|
||||||
|
|
||||||
|
if let Some(defaults) = channel_default_permissions {
|
||||||
|
permission.apply(defaults.into());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the applicable role overrides
|
||||||
|
let mut roles = channel_role_permissions
|
||||||
|
.iter()
|
||||||
|
.filter(|(id, _)| member.roles.contains(id))
|
||||||
|
.filter_map(|(id, permission)| {
|
||||||
|
query.server.roles.get(id).map(|role| {
|
||||||
|
let v: Override = (*permission).into();
|
||||||
|
(role.rank, v)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.collect::<Vec<(i64, Override)>>();
|
||||||
|
|
||||||
|
roles.sort_by(|a, b| b.0.cmp(&a.0));
|
||||||
|
let overrides = roles.into_iter().map(|(_, v)| v);
|
||||||
|
|
||||||
|
for role_override in overrides {
|
||||||
|
permission.apply(role_override)
|
||||||
|
}
|
||||||
|
|
||||||
|
resp.insert(user.id.clone(), permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
resp
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Calculates a member's server permissions
|
||||||
|
fn calculate_server_permissions(server: &Server, user: &User, member: &Member) -> PermissionValue {
|
||||||
|
if user.privileged || server.owner == user.id {
|
||||||
|
return ChannelPermission::GrantAllSafe.into();
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut permissions: PermissionValue = server.default_permissions.into();
|
||||||
|
|
||||||
|
let mut roles = server
|
||||||
|
.roles
|
||||||
|
.iter()
|
||||||
|
.filter(|(id, _)| member.roles.contains(id))
|
||||||
|
.map(|(_, role)| {
|
||||||
|
let v: Override = role.permissions.into();
|
||||||
|
(role.rank, v)
|
||||||
|
})
|
||||||
|
.collect::<Vec<(i64, Override)>>();
|
||||||
|
|
||||||
|
roles.sort_by(|a, b| b.0.cmp(&a.0));
|
||||||
|
let role_overrides: Vec<Override> = roles.into_iter().map(|(_, v)| v).collect();
|
||||||
|
|
||||||
|
for role in role_overrides {
|
||||||
|
permissions.apply(role);
|
||||||
|
}
|
||||||
|
|
||||||
|
if member.in_timeout() {
|
||||||
|
permissions.restrict(*ALLOW_IN_TIMEOUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
permissions
|
||||||
|
}
|
||||||
@@ -102,7 +102,7 @@ impl<'r> FromRequest<'r> for IdempotencyKey {
|
|||||||
.map(|k| k.to_string())
|
.map(|k| k.to_string())
|
||||||
{
|
{
|
||||||
if key.len() > 64 {
|
if key.len() > 64 {
|
||||||
return Outcome::Failure((
|
return Outcome::Error((
|
||||||
Status::BadRequest,
|
Status::BadRequest,
|
||||||
create_error!(FailedValidation {
|
create_error!(FailedValidation {
|
||||||
error: "idempotency key too long".to_string(),
|
error: "idempotency key too long".to_string(),
|
||||||
@@ -113,7 +113,7 @@ impl<'r> FromRequest<'r> for IdempotencyKey {
|
|||||||
let idempotency = IdempotencyKey { key };
|
let idempotency = IdempotencyKey { key };
|
||||||
let mut cache = TOKEN_CACHE.lock().await;
|
let mut cache = TOKEN_CACHE.lock().await;
|
||||||
if cache.get(&idempotency.key).is_some() {
|
if cache.get(&idempotency.key).is_some() {
|
||||||
return Outcome::Failure((Status::Conflict, create_error!(DuplicateNonce)));
|
return Outcome::Error((Status::Conflict, create_error!(DuplicateNonce)));
|
||||||
}
|
}
|
||||||
|
|
||||||
cache.put(idempotency.key.clone(), ());
|
cache.put(idempotency.key.clone(), ());
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
pub mod bridge;
|
pub mod bridge;
|
||||||
|
pub mod bulk_permissions;
|
||||||
pub mod idempotency;
|
pub mod idempotency;
|
||||||
pub mod permissions;
|
pub mod permissions;
|
||||||
pub mod reference;
|
pub mod reference;
|
||||||
|
|||||||
@@ -0,0 +1,554 @@
|
|||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<!-- Compiled with Bootstrap Email version: 1.3.1 -->
|
||||||
|
<meta http-equiv="x-ua-compatible" content="ie=edge" />
|
||||||
|
<meta name="x-apple-disable-message-reformatting" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<meta
|
||||||
|
name="format-detection"
|
||||||
|
content="telephone=no, date=no, address=no, email=no"
|
||||||
|
/>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
|
<style type="text/css">
|
||||||
|
body,
|
||||||
|
table,
|
||||||
|
td {
|
||||||
|
font-family: Helvetica, Arial, sans-serif !important;
|
||||||
|
}
|
||||||
|
.ExternalClass {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.ExternalClass,
|
||||||
|
.ExternalClass p,
|
||||||
|
.ExternalClass span,
|
||||||
|
.ExternalClass font,
|
||||||
|
.ExternalClass td,
|
||||||
|
.ExternalClass div {
|
||||||
|
line-height: 150%;
|
||||||
|
}
|
||||||
|
a {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
* {
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
a[x-apple-data-detectors],
|
||||||
|
u + #body a,
|
||||||
|
#MessageViewBody a {
|
||||||
|
color: inherit;
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: inherit;
|
||||||
|
font-family: inherit;
|
||||||
|
font-weight: inherit;
|
||||||
|
line-height: inherit;
|
||||||
|
}
|
||||||
|
img {
|
||||||
|
-ms-interpolation-mode: bicubic;
|
||||||
|
}
|
||||||
|
table:not([class^="s-"]) {
|
||||||
|
font-family: Helvetica, Arial, sans-serif;
|
||||||
|
mso-table-lspace: 0pt;
|
||||||
|
mso-table-rspace: 0pt;
|
||||||
|
border-spacing: 0px;
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
table:not([class^="s-"]) td {
|
||||||
|
border-spacing: 0px;
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
@media screen and (max-width: 600px) {
|
||||||
|
.w-full,
|
||||||
|
.w-full > tbody > tr > td {
|
||||||
|
width: 100% !important;
|
||||||
|
}
|
||||||
|
.w-24,
|
||||||
|
.w-24 > tbody > tr > td {
|
||||||
|
width: 96px !important;
|
||||||
|
}
|
||||||
|
.p-lg-10:not(table),
|
||||||
|
.p-lg-10:not(.btn) > tbody > tr > td,
|
||||||
|
.p-lg-10.btn td a {
|
||||||
|
padding: 0 !important;
|
||||||
|
}
|
||||||
|
.p-3:not(table),
|
||||||
|
.p-3:not(.btn) > tbody > tr > td,
|
||||||
|
.p-3.btn td a {
|
||||||
|
padding: 12px !important;
|
||||||
|
}
|
||||||
|
.p-6:not(table),
|
||||||
|
.p-6:not(.btn) > tbody > tr > td,
|
||||||
|
.p-6.btn td a {
|
||||||
|
padding: 24px !important;
|
||||||
|
}
|
||||||
|
*[class*="s-lg-"] > tbody > tr > td {
|
||||||
|
font-size: 0 !important;
|
||||||
|
line-height: 0 !important;
|
||||||
|
height: 0 !important;
|
||||||
|
}
|
||||||
|
.s-4 > tbody > tr > td {
|
||||||
|
font-size: 16px !important;
|
||||||
|
line-height: 16px !important;
|
||||||
|
height: 16px !important;
|
||||||
|
}
|
||||||
|
.s-6 > tbody > tr > td {
|
||||||
|
font-size: 24px !important;
|
||||||
|
line-height: 24px !important;
|
||||||
|
height: 24px !important;
|
||||||
|
}
|
||||||
|
.s-10 > tbody > tr > td {
|
||||||
|
font-size: 40px !important;
|
||||||
|
line-height: 40px !important;
|
||||||
|
height: 40px !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body
|
||||||
|
class="bg-light"
|
||||||
|
style="
|
||||||
|
outline: 0;
|
||||||
|
width: 100%;
|
||||||
|
min-width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
-webkit-text-size-adjust: 100%;
|
||||||
|
-ms-text-size-adjust: 100%;
|
||||||
|
font-family: Helvetica, Arial, sans-serif;
|
||||||
|
line-height: 24px;
|
||||||
|
font-weight: normal;
|
||||||
|
font-size: 16px;
|
||||||
|
-moz-box-sizing: border-box;
|
||||||
|
-webkit-box-sizing: border-box;
|
||||||
|
box-sizing: border-box;
|
||||||
|
color: #000000;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
border-width: 0;
|
||||||
|
"
|
||||||
|
bgcolor="#f7fafc"
|
||||||
|
>
|
||||||
|
<table
|
||||||
|
class="bg-light body"
|
||||||
|
valign="top"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="
|
||||||
|
outline: 0;
|
||||||
|
width: 100%;
|
||||||
|
min-width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
-webkit-text-size-adjust: 100%;
|
||||||
|
-ms-text-size-adjust: 100%;
|
||||||
|
font-family: Helvetica, Arial, sans-serif;
|
||||||
|
line-height: 24px;
|
||||||
|
font-weight: normal;
|
||||||
|
font-size: 16px;
|
||||||
|
-moz-box-sizing: border-box;
|
||||||
|
-webkit-box-sizing: border-box;
|
||||||
|
box-sizing: border-box;
|
||||||
|
color: #000000;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
border-width: 0;
|
||||||
|
"
|
||||||
|
bgcolor="#f7fafc"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
valign="top"
|
||||||
|
style="line-height: 24px; font-size: 16px; margin: 0"
|
||||||
|
align="left"
|
||||||
|
bgcolor="#f7fafc"
|
||||||
|
>
|
||||||
|
<table
|
||||||
|
class="container"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
align="center"
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 16px;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0 16px;
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<!--[if (gte mso 9)|(IE)]>
|
||||||
|
<table align="center" role="presentation">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td width="600">
|
||||||
|
<![endif]-->
|
||||||
|
<table
|
||||||
|
align="center"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%; max-width: 600px; margin: 0 auto"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 16px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
>
|
||||||
|
<table
|
||||||
|
class="s-10 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 40px;
|
||||||
|
font-size: 40px;
|
||||||
|
width: 100%;
|
||||||
|
height: 40px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="40"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<table
|
||||||
|
class="ax-center"
|
||||||
|
role="presentation"
|
||||||
|
align="center"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="margin: 0 auto"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 16px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
alt="Revolt Logo"
|
||||||
|
class="w-24"
|
||||||
|
src="https://app.revolt.chat/assets/logo_round.png"
|
||||||
|
style="
|
||||||
|
height: auto;
|
||||||
|
line-height: 100%;
|
||||||
|
outline: none;
|
||||||
|
text-decoration: none;
|
||||||
|
display: block;
|
||||||
|
width: 96px;
|
||||||
|
border-style: none;
|
||||||
|
border-width: 0;
|
||||||
|
"
|
||||||
|
width="96"
|
||||||
|
/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<table
|
||||||
|
class="s-10 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 40px;
|
||||||
|
font-size: 40px;
|
||||||
|
width: 100%;
|
||||||
|
height: 40px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="40"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<table
|
||||||
|
class="card p-6 p-lg-10 space-y-4"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="
|
||||||
|
border-radius: 6px;
|
||||||
|
border-collapse: separate !important;
|
||||||
|
width: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
border: 1px solid #e2e8f0;
|
||||||
|
"
|
||||||
|
bgcolor="#ffffff"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 16px;
|
||||||
|
width: 100%;
|
||||||
|
margin: 0;
|
||||||
|
padding: 40px;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
bgcolor="#ffffff"
|
||||||
|
>
|
||||||
|
<h1
|
||||||
|
class="h3 fw-700"
|
||||||
|
style="
|
||||||
|
padding-top: 0;
|
||||||
|
padding-bottom: 0;
|
||||||
|
font-weight: 700 !important;
|
||||||
|
vertical-align: baseline;
|
||||||
|
font-size: 28px;
|
||||||
|
line-height: 33.6px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
>
|
||||||
|
Account Deletion
|
||||||
|
</h1>
|
||||||
|
<table
|
||||||
|
class="s-4 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 16px;
|
||||||
|
font-size: 16px;
|
||||||
|
width: 100%;
|
||||||
|
height: 16px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="16"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<p
|
||||||
|
class=""
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 16px;
|
||||||
|
width: 100%;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
>
|
||||||
|
You requested to have your account
|
||||||
|
deleted, if you did not perform this
|
||||||
|
action please take measures to secure your
|
||||||
|
account immediately.
|
||||||
|
</p>
|
||||||
|
<table
|
||||||
|
class="s-4 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 16px;
|
||||||
|
font-size: 16px;
|
||||||
|
width: 100%;
|
||||||
|
height: 16px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="16"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<table
|
||||||
|
class="btn btn-primary p-3 fw-700"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="
|
||||||
|
border-radius: 6px;
|
||||||
|
border-collapse: separate !important;
|
||||||
|
font-weight: 700 !important;
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 16px;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-weight: 700 !important;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="center"
|
||||||
|
bgcolor="#0d6efd"
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
href="{{url}}"
|
||||||
|
style="
|
||||||
|
color: #ffffff;
|
||||||
|
font-size: 16px;
|
||||||
|
font-family: Helvetica, Arial,
|
||||||
|
sans-serif;
|
||||||
|
text-decoration: none;
|
||||||
|
border-radius: 6px;
|
||||||
|
line-height: 20px;
|
||||||
|
display: block;
|
||||||
|
font-weight: 700 !important;
|
||||||
|
white-space: nowrap;
|
||||||
|
background-color: #0d6efd;
|
||||||
|
padding: 12px;
|
||||||
|
border: 1px solid #0d6efd;
|
||||||
|
"
|
||||||
|
>Confirm</a
|
||||||
|
>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<table
|
||||||
|
class="s-6 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 24px;
|
||||||
|
width: 100%;
|
||||||
|
height: 24px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="24"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<div
|
||||||
|
class="text-muted text-center"
|
||||||
|
style="color: #718096"
|
||||||
|
align="center"
|
||||||
|
>
|
||||||
|
This email is intended for {{email}}<br />
|
||||||
|
Sent from Revolt<br />
|
||||||
|
Made in Europe
|
||||||
|
</div>
|
||||||
|
<table
|
||||||
|
class="s-6 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 24px;
|
||||||
|
width: 100%;
|
||||||
|
height: 24px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="24"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<!--[if (gte mso 9)|(IE)]>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<![endif]-->
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
+1
-1
@@ -23,7 +23,7 @@
|
|||||||
<div class="text-muted text-center my-6">
|
<div class="text-muted text-center my-6">
|
||||||
This email is intended for {{email}}<br />
|
This email is intended for {{email}}<br />
|
||||||
Sent from Revolt<br />
|
Sent from Revolt<br />
|
||||||
Made in the EU
|
Made in Europe
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
+1
-1
@@ -4,4 +4,4 @@ Please navigate to: {{url}}
|
|||||||
|
|
||||||
This email is intended for {{email}}
|
This email is intended for {{email}}
|
||||||
Sent by Revolt
|
Sent by Revolt
|
||||||
Made in the EU
|
Made in Europe
|
||||||
@@ -0,0 +1,552 @@
|
|||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<!-- Compiled with Bootstrap Email version: 1.3.1 -->
|
||||||
|
<meta http-equiv="x-ua-compatible" content="ie=edge" />
|
||||||
|
<meta name="x-apple-disable-message-reformatting" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<meta
|
||||||
|
name="format-detection"
|
||||||
|
content="telephone=no, date=no, address=no, email=no"
|
||||||
|
/>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
|
<style type="text/css">
|
||||||
|
body,
|
||||||
|
table,
|
||||||
|
td {
|
||||||
|
font-family: Helvetica, Arial, sans-serif !important;
|
||||||
|
}
|
||||||
|
.ExternalClass {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.ExternalClass,
|
||||||
|
.ExternalClass p,
|
||||||
|
.ExternalClass span,
|
||||||
|
.ExternalClass font,
|
||||||
|
.ExternalClass td,
|
||||||
|
.ExternalClass div {
|
||||||
|
line-height: 150%;
|
||||||
|
}
|
||||||
|
a {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
* {
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
a[x-apple-data-detectors],
|
||||||
|
u + #body a,
|
||||||
|
#MessageViewBody a {
|
||||||
|
color: inherit;
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: inherit;
|
||||||
|
font-family: inherit;
|
||||||
|
font-weight: inherit;
|
||||||
|
line-height: inherit;
|
||||||
|
}
|
||||||
|
img {
|
||||||
|
-ms-interpolation-mode: bicubic;
|
||||||
|
}
|
||||||
|
table:not([class^="s-"]) {
|
||||||
|
font-family: Helvetica, Arial, sans-serif;
|
||||||
|
mso-table-lspace: 0pt;
|
||||||
|
mso-table-rspace: 0pt;
|
||||||
|
border-spacing: 0px;
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
table:not([class^="s-"]) td {
|
||||||
|
border-spacing: 0px;
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
@media screen and (max-width: 600px) {
|
||||||
|
.w-full,
|
||||||
|
.w-full > tbody > tr > td {
|
||||||
|
width: 100% !important;
|
||||||
|
}
|
||||||
|
.w-24,
|
||||||
|
.w-24 > tbody > tr > td {
|
||||||
|
width: 96px !important;
|
||||||
|
}
|
||||||
|
.p-lg-10:not(table),
|
||||||
|
.p-lg-10:not(.btn) > tbody > tr > td,
|
||||||
|
.p-lg-10.btn td a {
|
||||||
|
padding: 0 !important;
|
||||||
|
}
|
||||||
|
.p-3:not(table),
|
||||||
|
.p-3:not(.btn) > tbody > tr > td,
|
||||||
|
.p-3.btn td a {
|
||||||
|
padding: 12px !important;
|
||||||
|
}
|
||||||
|
.p-6:not(table),
|
||||||
|
.p-6:not(.btn) > tbody > tr > td,
|
||||||
|
.p-6.btn td a {
|
||||||
|
padding: 24px !important;
|
||||||
|
}
|
||||||
|
*[class*="s-lg-"] > tbody > tr > td {
|
||||||
|
font-size: 0 !important;
|
||||||
|
line-height: 0 !important;
|
||||||
|
height: 0 !important;
|
||||||
|
}
|
||||||
|
.s-4 > tbody > tr > td {
|
||||||
|
font-size: 16px !important;
|
||||||
|
line-height: 16px !important;
|
||||||
|
height: 16px !important;
|
||||||
|
}
|
||||||
|
.s-6 > tbody > tr > td {
|
||||||
|
font-size: 24px !important;
|
||||||
|
line-height: 24px !important;
|
||||||
|
height: 24px !important;
|
||||||
|
}
|
||||||
|
.s-10 > tbody > tr > td {
|
||||||
|
font-size: 40px !important;
|
||||||
|
line-height: 40px !important;
|
||||||
|
height: 40px !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body
|
||||||
|
class="bg-light"
|
||||||
|
style="
|
||||||
|
outline: 0;
|
||||||
|
width: 100%;
|
||||||
|
min-width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
-webkit-text-size-adjust: 100%;
|
||||||
|
-ms-text-size-adjust: 100%;
|
||||||
|
font-family: Helvetica, Arial, sans-serif;
|
||||||
|
line-height: 24px;
|
||||||
|
font-weight: normal;
|
||||||
|
font-size: 16px;
|
||||||
|
-moz-box-sizing: border-box;
|
||||||
|
-webkit-box-sizing: border-box;
|
||||||
|
box-sizing: border-box;
|
||||||
|
color: #000000;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
border-width: 0;
|
||||||
|
"
|
||||||
|
bgcolor="#f7fafc"
|
||||||
|
>
|
||||||
|
<table
|
||||||
|
class="bg-light body"
|
||||||
|
valign="top"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="
|
||||||
|
outline: 0;
|
||||||
|
width: 100%;
|
||||||
|
min-width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
-webkit-text-size-adjust: 100%;
|
||||||
|
-ms-text-size-adjust: 100%;
|
||||||
|
font-family: Helvetica, Arial, sans-serif;
|
||||||
|
line-height: 24px;
|
||||||
|
font-weight: normal;
|
||||||
|
font-size: 16px;
|
||||||
|
-moz-box-sizing: border-box;
|
||||||
|
-webkit-box-sizing: border-box;
|
||||||
|
box-sizing: border-box;
|
||||||
|
color: #000000;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
border-width: 0;
|
||||||
|
"
|
||||||
|
bgcolor="#f7fafc"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
valign="top"
|
||||||
|
style="line-height: 24px; font-size: 16px; margin: 0"
|
||||||
|
align="left"
|
||||||
|
bgcolor="#f7fafc"
|
||||||
|
>
|
||||||
|
<table
|
||||||
|
class="container"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
align="center"
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 16px;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0 16px;
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<!--[if (gte mso 9)|(IE)]>
|
||||||
|
<table align="center" role="presentation">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td width="600">
|
||||||
|
<![endif]-->
|
||||||
|
<table
|
||||||
|
align="center"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%; max-width: 600px; margin: 0 auto"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 16px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
>
|
||||||
|
<table
|
||||||
|
class="s-10 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 40px;
|
||||||
|
font-size: 40px;
|
||||||
|
width: 100%;
|
||||||
|
height: 40px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="40"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<table
|
||||||
|
class="ax-center"
|
||||||
|
role="presentation"
|
||||||
|
align="center"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="margin: 0 auto"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 16px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
alt="Revolt Logo"
|
||||||
|
class="w-24"
|
||||||
|
src="https://app.revolt.chat/assets/logo_round.png"
|
||||||
|
style="
|
||||||
|
height: auto;
|
||||||
|
line-height: 100%;
|
||||||
|
outline: none;
|
||||||
|
text-decoration: none;
|
||||||
|
display: block;
|
||||||
|
width: 96px;
|
||||||
|
border-style: none;
|
||||||
|
border-width: 0;
|
||||||
|
"
|
||||||
|
width="96"
|
||||||
|
/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<table
|
||||||
|
class="s-10 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 40px;
|
||||||
|
font-size: 40px;
|
||||||
|
width: 100%;
|
||||||
|
height: 40px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="40"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<table
|
||||||
|
class="card p-6 p-lg-10 space-y-4"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="
|
||||||
|
border-radius: 6px;
|
||||||
|
border-collapse: separate !important;
|
||||||
|
width: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
border: 1px solid #e2e8f0;
|
||||||
|
"
|
||||||
|
bgcolor="#ffffff"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 16px;
|
||||||
|
width: 100%;
|
||||||
|
margin: 0;
|
||||||
|
padding: 40px;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
bgcolor="#ffffff"
|
||||||
|
>
|
||||||
|
<h1
|
||||||
|
class="h3 fw-700"
|
||||||
|
style="
|
||||||
|
padding-top: 0;
|
||||||
|
padding-bottom: 0;
|
||||||
|
font-weight: 700 !important;
|
||||||
|
vertical-align: baseline;
|
||||||
|
font-size: 28px;
|
||||||
|
line-height: 33.6px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
>
|
||||||
|
Password Reset
|
||||||
|
</h1>
|
||||||
|
<table
|
||||||
|
class="s-4 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 16px;
|
||||||
|
font-size: 16px;
|
||||||
|
width: 100%;
|
||||||
|
height: 16px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="16"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<p
|
||||||
|
class=""
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 16px;
|
||||||
|
width: 100%;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
>
|
||||||
|
You requested a password reset, click
|
||||||
|
below to continue.
|
||||||
|
</p>
|
||||||
|
<table
|
||||||
|
class="s-4 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 16px;
|
||||||
|
font-size: 16px;
|
||||||
|
width: 100%;
|
||||||
|
height: 16px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="16"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<table
|
||||||
|
class="btn btn-primary p-3 fw-700"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="
|
||||||
|
border-radius: 6px;
|
||||||
|
border-collapse: separate !important;
|
||||||
|
font-weight: 700 !important;
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 16px;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-weight: 700 !important;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="center"
|
||||||
|
bgcolor="#0d6efd"
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
href="{{url}}"
|
||||||
|
style="
|
||||||
|
color: #ffffff;
|
||||||
|
font-size: 16px;
|
||||||
|
font-family: Helvetica, Arial,
|
||||||
|
sans-serif;
|
||||||
|
text-decoration: none;
|
||||||
|
border-radius: 6px;
|
||||||
|
line-height: 20px;
|
||||||
|
display: block;
|
||||||
|
font-weight: 700 !important;
|
||||||
|
white-space: nowrap;
|
||||||
|
background-color: #0d6efd;
|
||||||
|
padding: 12px;
|
||||||
|
border: 1px solid #0d6efd;
|
||||||
|
"
|
||||||
|
>Reset</a
|
||||||
|
>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<table
|
||||||
|
class="s-6 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 24px;
|
||||||
|
width: 100%;
|
||||||
|
height: 24px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="24"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<div
|
||||||
|
class="text-muted text-center"
|
||||||
|
style="color: #718096"
|
||||||
|
align="center"
|
||||||
|
>
|
||||||
|
This email is intended for {{email}}<br />
|
||||||
|
Sent from Revolt<br />
|
||||||
|
Made in Europe
|
||||||
|
</div>
|
||||||
|
<table
|
||||||
|
class="s-6 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 24px;
|
||||||
|
width: 100%;
|
||||||
|
height: 24px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="24"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<!--[if (gte mso 9)|(IE)]>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<![endif]-->
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
+1
-1
@@ -19,7 +19,7 @@
|
|||||||
<div class="text-muted text-center my-6">
|
<div class="text-muted text-center my-6">
|
||||||
This email is intended for {{email}}<br />
|
This email is intended for {{email}}<br />
|
||||||
Sent from Revolt<br />
|
Sent from Revolt<br />
|
||||||
Made in the EU
|
Made in Europe
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
@@ -4,4 +4,4 @@ Please navigate to: {{url}}
|
|||||||
|
|
||||||
This email is intended for {{email}}
|
This email is intended for {{email}}
|
||||||
Sent by Revolt
|
Sent by Revolt
|
||||||
Made in the EU
|
Made in Europe
|
||||||
@@ -0,0 +1,625 @@
|
|||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<!-- Compiled with Bootstrap Email version: 1.5.1 -->
|
||||||
|
<meta http-equiv="x-ua-compatible" content="ie=edge" />
|
||||||
|
<meta name="x-apple-disable-message-reformatting" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<meta
|
||||||
|
name="format-detection"
|
||||||
|
content="telephone=no, date=no, address=no, email=no"
|
||||||
|
/>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
|
<style type="text/css">
|
||||||
|
body,
|
||||||
|
table,
|
||||||
|
td {
|
||||||
|
font-family: Helvetica, Arial, sans-serif !important;
|
||||||
|
}
|
||||||
|
.ExternalClass {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.ExternalClass,
|
||||||
|
.ExternalClass p,
|
||||||
|
.ExternalClass span,
|
||||||
|
.ExternalClass font,
|
||||||
|
.ExternalClass td,
|
||||||
|
.ExternalClass div {
|
||||||
|
line-height: 150%;
|
||||||
|
}
|
||||||
|
a {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
* {
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
a[x-apple-data-detectors],
|
||||||
|
u + #body a,
|
||||||
|
#MessageViewBody a {
|
||||||
|
color: inherit;
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: inherit;
|
||||||
|
font-family: inherit;
|
||||||
|
font-weight: inherit;
|
||||||
|
line-height: inherit;
|
||||||
|
}
|
||||||
|
img {
|
||||||
|
-ms-interpolation-mode: bicubic;
|
||||||
|
}
|
||||||
|
table:not([class^="s-"]) {
|
||||||
|
font-family: Helvetica, Arial, sans-serif;
|
||||||
|
mso-table-lspace: 0pt;
|
||||||
|
mso-table-rspace: 0pt;
|
||||||
|
border-spacing: 0px;
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
table:not([class^="s-"]) td {
|
||||||
|
border-spacing: 0px;
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
@media screen and (max-width: 600px) {
|
||||||
|
.w-full,
|
||||||
|
.w-full > tbody > tr > td {
|
||||||
|
width: 100% !important;
|
||||||
|
}
|
||||||
|
.w-24,
|
||||||
|
.w-24 > tbody > tr > td {
|
||||||
|
width: 96px !important;
|
||||||
|
}
|
||||||
|
.p-lg-10:not(table),
|
||||||
|
.p-lg-10:not(.btn) > tbody > tr > td,
|
||||||
|
.p-lg-10.btn td a {
|
||||||
|
padding: 0 !important;
|
||||||
|
}
|
||||||
|
.p-6:not(table),
|
||||||
|
.p-6:not(.btn) > tbody > tr > td,
|
||||||
|
.p-6.btn td a {
|
||||||
|
padding: 24px !important;
|
||||||
|
}
|
||||||
|
*[class*="s-lg-"] > tbody > tr > td {
|
||||||
|
font-size: 0 !important;
|
||||||
|
line-height: 0 !important;
|
||||||
|
height: 0 !important;
|
||||||
|
}
|
||||||
|
.s-4 > tbody > tr > td {
|
||||||
|
font-size: 16px !important;
|
||||||
|
line-height: 16px !important;
|
||||||
|
height: 16px !important;
|
||||||
|
}
|
||||||
|
.s-6 > tbody > tr > td {
|
||||||
|
font-size: 24px !important;
|
||||||
|
line-height: 24px !important;
|
||||||
|
height: 24px !important;
|
||||||
|
}
|
||||||
|
.s-10 > tbody > tr > td {
|
||||||
|
font-size: 40px !important;
|
||||||
|
line-height: 40px !important;
|
||||||
|
height: 40px !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body
|
||||||
|
class="bg-light"
|
||||||
|
style="
|
||||||
|
outline: 0;
|
||||||
|
width: 100%;
|
||||||
|
min-width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
-webkit-text-size-adjust: 100%;
|
||||||
|
-ms-text-size-adjust: 100%;
|
||||||
|
font-family: Helvetica, Arial, sans-serif;
|
||||||
|
line-height: 24px;
|
||||||
|
font-weight: normal;
|
||||||
|
font-size: 16px;
|
||||||
|
-moz-box-sizing: border-box;
|
||||||
|
-webkit-box-sizing: border-box;
|
||||||
|
box-sizing: border-box;
|
||||||
|
color: #000000;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
border-width: 0;
|
||||||
|
"
|
||||||
|
bgcolor="#f7fafc"
|
||||||
|
>
|
||||||
|
<table
|
||||||
|
class="bg-light body"
|
||||||
|
valign="top"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="
|
||||||
|
outline: 0;
|
||||||
|
width: 100%;
|
||||||
|
min-width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
-webkit-text-size-adjust: 100%;
|
||||||
|
-ms-text-size-adjust: 100%;
|
||||||
|
font-family: Helvetica, Arial, sans-serif;
|
||||||
|
line-height: 24px;
|
||||||
|
font-weight: normal;
|
||||||
|
font-size: 16px;
|
||||||
|
-moz-box-sizing: border-box;
|
||||||
|
-webkit-box-sizing: border-box;
|
||||||
|
box-sizing: border-box;
|
||||||
|
color: #000000;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
border-width: 0;
|
||||||
|
"
|
||||||
|
bgcolor="#f7fafc"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
valign="top"
|
||||||
|
style="line-height: 24px; font-size: 16px; margin: 0"
|
||||||
|
align="left"
|
||||||
|
bgcolor="#f7fafc"
|
||||||
|
>
|
||||||
|
<table
|
||||||
|
class="container"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
align="center"
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 16px;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0 16px;
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<!--[if (gte mso 9)|(IE)]>
|
||||||
|
<table align="center" role="presentation">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td width="600">
|
||||||
|
<![endif]-->
|
||||||
|
<table
|
||||||
|
align="center"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%; max-width: 600px; margin: 0 auto"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 16px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
>
|
||||||
|
<table
|
||||||
|
class="s-10 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 40px;
|
||||||
|
font-size: 40px;
|
||||||
|
width: 100%;
|
||||||
|
height: 40px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="40"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<table
|
||||||
|
class="ax-center"
|
||||||
|
role="presentation"
|
||||||
|
align="center"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="margin: 0 auto"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 16px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
alt="Revolt Logo"
|
||||||
|
class="w-24"
|
||||||
|
src="https://app.revolt.chat/assets/logo_round.png"
|
||||||
|
style="
|
||||||
|
height: auto;
|
||||||
|
line-height: 100%;
|
||||||
|
outline: none;
|
||||||
|
text-decoration: none;
|
||||||
|
display: block;
|
||||||
|
width: 96px;
|
||||||
|
border-style: none;
|
||||||
|
border-width: 0;
|
||||||
|
"
|
||||||
|
width="96"
|
||||||
|
/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<table
|
||||||
|
class="s-10 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 40px;
|
||||||
|
font-size: 40px;
|
||||||
|
width: 100%;
|
||||||
|
height: 40px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="40"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<table
|
||||||
|
class="card p-6 p-lg-10 space-y-4"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="
|
||||||
|
border-radius: 6px;
|
||||||
|
border-collapse: separate !important;
|
||||||
|
width: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
border: 1px solid #e2e8f0;
|
||||||
|
"
|
||||||
|
bgcolor="#ffffff"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 16px;
|
||||||
|
width: 100%;
|
||||||
|
margin: 0;
|
||||||
|
padding: 40px;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
bgcolor="#ffffff"
|
||||||
|
>
|
||||||
|
<h1
|
||||||
|
class="h3 fw-700"
|
||||||
|
style="
|
||||||
|
padding-top: 0;
|
||||||
|
padding-bottom: 0;
|
||||||
|
font-weight: 700 !important;
|
||||||
|
vertical-align: baseline;
|
||||||
|
font-size: 28px;
|
||||||
|
line-height: 33.6px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
>
|
||||||
|
Account Suspended
|
||||||
|
</h1>
|
||||||
|
<table
|
||||||
|
class="s-4 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 16px;
|
||||||
|
font-size: 16px;
|
||||||
|
width: 100%;
|
||||||
|
height: 16px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="16"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<p
|
||||||
|
class=""
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 16px;
|
||||||
|
width: 100%;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
>
|
||||||
|
Your account has been suspended, for one
|
||||||
|
or more reasons:
|
||||||
|
</p>
|
||||||
|
<table
|
||||||
|
class="s-4 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 16px;
|
||||||
|
font-size: 16px;
|
||||||
|
width: 100%;
|
||||||
|
height: 16px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="16"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<ul class="">
|
||||||
|
{{list}}
|
||||||
|
</ul>
|
||||||
|
<table
|
||||||
|
class="s-4 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 16px;
|
||||||
|
font-size: 16px;
|
||||||
|
width: 100%;
|
||||||
|
height: 16px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="16"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<p
|
||||||
|
style="display: {{duration_display}}; line-height: 24px; font-size: 16px; width: 100%; margin: 0;"
|
||||||
|
class=""
|
||||||
|
align="left"
|
||||||
|
>
|
||||||
|
You will be able to use your account again
|
||||||
|
in {{duration}} days.
|
||||||
|
</p>
|
||||||
|
<table
|
||||||
|
class="s-4 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 16px;
|
||||||
|
font-size: 16px;
|
||||||
|
width: 100%;
|
||||||
|
height: 16px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="16"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<p
|
||||||
|
class=""
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 16px;
|
||||||
|
width: 100%;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
>
|
||||||
|
Further violations may result in a
|
||||||
|
permanent ban depending on severity,
|
||||||
|
please abide by the
|
||||||
|
<a
|
||||||
|
href="https://revolt.chat/aup"
|
||||||
|
style="color: #0d6efd"
|
||||||
|
>Acceptable Usage Policy</a
|
||||||
|
>.
|
||||||
|
</p>
|
||||||
|
<table
|
||||||
|
class="s-4 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 16px;
|
||||||
|
font-size: 16px;
|
||||||
|
width: 100%;
|
||||||
|
height: 16px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="16"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<p
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 16px;
|
||||||
|
width: 100%;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
>
|
||||||
|
Ban evasion is prohibited and will be
|
||||||
|
dealt with accordingly.
|
||||||
|
</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<table
|
||||||
|
class="s-6 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 24px;
|
||||||
|
width: 100%;
|
||||||
|
height: 24px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="24"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<div
|
||||||
|
class="text-muted text-center"
|
||||||
|
style="color: #718096"
|
||||||
|
align="center"
|
||||||
|
>
|
||||||
|
This email is intended for {{email}}<br />
|
||||||
|
Sent from Revolt<br />
|
||||||
|
Made in Europe
|
||||||
|
</div>
|
||||||
|
<table
|
||||||
|
class="s-6 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 24px;
|
||||||
|
width: 100%;
|
||||||
|
height: 24px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="24"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<!--[if (gte mso 9)|(IE)]>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<![endif]-->
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
|
<style>
|
||||||
|
/* Add custom classes and styles that you want inlined here */
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body class="bg-light">
|
||||||
|
<div class="container">
|
||||||
|
<img
|
||||||
|
alt="Revolt Logo"
|
||||||
|
class="ax-center my-10 w-24"
|
||||||
|
src="https://app.revolt.chat/assets/logo_round.png"
|
||||||
|
/>
|
||||||
|
<div class="card p-6 p-lg-10 space-y-4">
|
||||||
|
<h1 class="h3 fw-700">Account Suspended</h1>
|
||||||
|
<p>Your account has been suspended, for one or more reasons:</p>
|
||||||
|
<ul>
|
||||||
|
{{list}}
|
||||||
|
</ul>
|
||||||
|
<p style="display:{{duration_display}}">
|
||||||
|
You will be able to use your account again in {{duration}} days.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Further violations may result in a permanent ban depending on
|
||||||
|
severity, please abide by the
|
||||||
|
<a href="https://revolt.chat/aup">Acceptable Usage Policy</a>.
|
||||||
|
</p>
|
||||||
|
<p>Ban evasion is prohibited and will be dealt with accordingly.</p>
|
||||||
|
</div>
|
||||||
|
<div class="text-muted text-center my-6">
|
||||||
|
This email is intended for {{email}}<br />
|
||||||
|
Sent from Revolt<br />
|
||||||
|
Made in Europe
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
Your account has been suspended, for one or more reasons:
|
||||||
|
{{list}}
|
||||||
|
|
||||||
|
You will be able to use your account again in {{duration}} days.
|
||||||
|
|
||||||
|
Further violations may result in a permanent ban depending on severity, please abide by the Acceptable Usage Policy (https://revolt.chat/aup).
|
||||||
|
|
||||||
|
Ban evasion is prohibited and will be dealt with accordingly.
|
||||||
|
|
||||||
|
This email is intended for {{email}}
|
||||||
|
Sent by Revolt
|
||||||
|
Made in Europe
|
||||||
@@ -0,0 +1,552 @@
|
|||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<!-- Compiled with Bootstrap Email version: 1.3.1 -->
|
||||||
|
<meta http-equiv="x-ua-compatible" content="ie=edge" />
|
||||||
|
<meta name="x-apple-disable-message-reformatting" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<meta
|
||||||
|
name="format-detection"
|
||||||
|
content="telephone=no, date=no, address=no, email=no"
|
||||||
|
/>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
|
<style type="text/css">
|
||||||
|
body,
|
||||||
|
table,
|
||||||
|
td {
|
||||||
|
font-family: Helvetica, Arial, sans-serif !important;
|
||||||
|
}
|
||||||
|
.ExternalClass {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.ExternalClass,
|
||||||
|
.ExternalClass p,
|
||||||
|
.ExternalClass span,
|
||||||
|
.ExternalClass font,
|
||||||
|
.ExternalClass td,
|
||||||
|
.ExternalClass div {
|
||||||
|
line-height: 150%;
|
||||||
|
}
|
||||||
|
a {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
* {
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
a[x-apple-data-detectors],
|
||||||
|
u + #body a,
|
||||||
|
#MessageViewBody a {
|
||||||
|
color: inherit;
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: inherit;
|
||||||
|
font-family: inherit;
|
||||||
|
font-weight: inherit;
|
||||||
|
line-height: inherit;
|
||||||
|
}
|
||||||
|
img {
|
||||||
|
-ms-interpolation-mode: bicubic;
|
||||||
|
}
|
||||||
|
table:not([class^="s-"]) {
|
||||||
|
font-family: Helvetica, Arial, sans-serif;
|
||||||
|
mso-table-lspace: 0pt;
|
||||||
|
mso-table-rspace: 0pt;
|
||||||
|
border-spacing: 0px;
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
table:not([class^="s-"]) td {
|
||||||
|
border-spacing: 0px;
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
@media screen and (max-width: 600px) {
|
||||||
|
.w-full,
|
||||||
|
.w-full > tbody > tr > td {
|
||||||
|
width: 100% !important;
|
||||||
|
}
|
||||||
|
.w-24,
|
||||||
|
.w-24 > tbody > tr > td {
|
||||||
|
width: 96px !important;
|
||||||
|
}
|
||||||
|
.p-lg-10:not(table),
|
||||||
|
.p-lg-10:not(.btn) > tbody > tr > td,
|
||||||
|
.p-lg-10.btn td a {
|
||||||
|
padding: 0 !important;
|
||||||
|
}
|
||||||
|
.p-3:not(table),
|
||||||
|
.p-3:not(.btn) > tbody > tr > td,
|
||||||
|
.p-3.btn td a {
|
||||||
|
padding: 12px !important;
|
||||||
|
}
|
||||||
|
.p-6:not(table),
|
||||||
|
.p-6:not(.btn) > tbody > tr > td,
|
||||||
|
.p-6.btn td a {
|
||||||
|
padding: 24px !important;
|
||||||
|
}
|
||||||
|
*[class*="s-lg-"] > tbody > tr > td {
|
||||||
|
font-size: 0 !important;
|
||||||
|
line-height: 0 !important;
|
||||||
|
height: 0 !important;
|
||||||
|
}
|
||||||
|
.s-4 > tbody > tr > td {
|
||||||
|
font-size: 16px !important;
|
||||||
|
line-height: 16px !important;
|
||||||
|
height: 16px !important;
|
||||||
|
}
|
||||||
|
.s-6 > tbody > tr > td {
|
||||||
|
font-size: 24px !important;
|
||||||
|
line-height: 24px !important;
|
||||||
|
height: 24px !important;
|
||||||
|
}
|
||||||
|
.s-10 > tbody > tr > td {
|
||||||
|
font-size: 40px !important;
|
||||||
|
line-height: 40px !important;
|
||||||
|
height: 40px !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body
|
||||||
|
class="bg-light"
|
||||||
|
style="
|
||||||
|
outline: 0;
|
||||||
|
width: 100%;
|
||||||
|
min-width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
-webkit-text-size-adjust: 100%;
|
||||||
|
-ms-text-size-adjust: 100%;
|
||||||
|
font-family: Helvetica, Arial, sans-serif;
|
||||||
|
line-height: 24px;
|
||||||
|
font-weight: normal;
|
||||||
|
font-size: 16px;
|
||||||
|
-moz-box-sizing: border-box;
|
||||||
|
-webkit-box-sizing: border-box;
|
||||||
|
box-sizing: border-box;
|
||||||
|
color: #000000;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
border-width: 0;
|
||||||
|
"
|
||||||
|
bgcolor="#f7fafc"
|
||||||
|
>
|
||||||
|
<table
|
||||||
|
class="bg-light body"
|
||||||
|
valign="top"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="
|
||||||
|
outline: 0;
|
||||||
|
width: 100%;
|
||||||
|
min-width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
-webkit-text-size-adjust: 100%;
|
||||||
|
-ms-text-size-adjust: 100%;
|
||||||
|
font-family: Helvetica, Arial, sans-serif;
|
||||||
|
line-height: 24px;
|
||||||
|
font-weight: normal;
|
||||||
|
font-size: 16px;
|
||||||
|
-moz-box-sizing: border-box;
|
||||||
|
-webkit-box-sizing: border-box;
|
||||||
|
box-sizing: border-box;
|
||||||
|
color: #000000;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
border-width: 0;
|
||||||
|
"
|
||||||
|
bgcolor="#f7fafc"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
valign="top"
|
||||||
|
style="line-height: 24px; font-size: 16px; margin: 0"
|
||||||
|
align="left"
|
||||||
|
bgcolor="#f7fafc"
|
||||||
|
>
|
||||||
|
<table
|
||||||
|
class="container"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
align="center"
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 16px;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0 16px;
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<!--[if (gte mso 9)|(IE)]>
|
||||||
|
<table align="center" role="presentation">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td width="600">
|
||||||
|
<![endif]-->
|
||||||
|
<table
|
||||||
|
align="center"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%; max-width: 600px; margin: 0 auto"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 16px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
>
|
||||||
|
<table
|
||||||
|
class="s-10 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 40px;
|
||||||
|
font-size: 40px;
|
||||||
|
width: 100%;
|
||||||
|
height: 40px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="40"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<table
|
||||||
|
class="ax-center"
|
||||||
|
role="presentation"
|
||||||
|
align="center"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="margin: 0 auto"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 16px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
alt="Revolt Logo"
|
||||||
|
class="w-24"
|
||||||
|
src="https://app.revolt.chat/assets/logo_round.png"
|
||||||
|
style="
|
||||||
|
height: auto;
|
||||||
|
line-height: 100%;
|
||||||
|
outline: none;
|
||||||
|
text-decoration: none;
|
||||||
|
display: block;
|
||||||
|
width: 96px;
|
||||||
|
border-style: none;
|
||||||
|
border-width: 0;
|
||||||
|
"
|
||||||
|
width="96"
|
||||||
|
/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<table
|
||||||
|
class="s-10 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 40px;
|
||||||
|
font-size: 40px;
|
||||||
|
width: 100%;
|
||||||
|
height: 40px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="40"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<table
|
||||||
|
class="card p-6 p-lg-10 space-y-4"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="
|
||||||
|
border-radius: 6px;
|
||||||
|
border-collapse: separate !important;
|
||||||
|
width: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
border: 1px solid #e2e8f0;
|
||||||
|
"
|
||||||
|
bgcolor="#ffffff"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 16px;
|
||||||
|
width: 100%;
|
||||||
|
margin: 0;
|
||||||
|
padding: 40px;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
bgcolor="#ffffff"
|
||||||
|
>
|
||||||
|
<h1
|
||||||
|
class="h3 fw-700"
|
||||||
|
style="
|
||||||
|
padding-top: 0;
|
||||||
|
padding-bottom: 0;
|
||||||
|
font-weight: 700 !important;
|
||||||
|
vertical-align: baseline;
|
||||||
|
font-size: 28px;
|
||||||
|
line-height: 33.6px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
>
|
||||||
|
Almost there!
|
||||||
|
</h1>
|
||||||
|
<table
|
||||||
|
class="s-4 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 16px;
|
||||||
|
font-size: 16px;
|
||||||
|
width: 100%;
|
||||||
|
height: 16px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="16"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<p
|
||||||
|
class=""
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 16px;
|
||||||
|
width: 100%;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
>
|
||||||
|
To complete your sign up, we just need to
|
||||||
|
verify your email.
|
||||||
|
</p>
|
||||||
|
<table
|
||||||
|
class="s-4 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 16px;
|
||||||
|
font-size: 16px;
|
||||||
|
width: 100%;
|
||||||
|
height: 16px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="16"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<table
|
||||||
|
class="btn btn-primary p-3 fw-700"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="
|
||||||
|
border-radius: 6px;
|
||||||
|
border-collapse: separate !important;
|
||||||
|
font-weight: 700 !important;
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 16px;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-weight: 700 !important;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="center"
|
||||||
|
bgcolor="#0d6efd"
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
href="{{url}}"
|
||||||
|
style="
|
||||||
|
color: #ffffff;
|
||||||
|
font-size: 16px;
|
||||||
|
font-family: Helvetica, Arial,
|
||||||
|
sans-serif;
|
||||||
|
text-decoration: none;
|
||||||
|
border-radius: 6px;
|
||||||
|
line-height: 20px;
|
||||||
|
display: block;
|
||||||
|
font-weight: 700 !important;
|
||||||
|
white-space: nowrap;
|
||||||
|
background-color: #0d6efd;
|
||||||
|
padding: 12px;
|
||||||
|
border: 1px solid #0d6efd;
|
||||||
|
"
|
||||||
|
>Confirm</a
|
||||||
|
>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<table
|
||||||
|
class="s-6 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 24px;
|
||||||
|
width: 100%;
|
||||||
|
height: 24px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="24"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<div
|
||||||
|
class="text-muted text-center"
|
||||||
|
style="color: #718096"
|
||||||
|
align="center"
|
||||||
|
>
|
||||||
|
This email is intended for {{email}}<br />
|
||||||
|
Sent from Revolt<br />
|
||||||
|
Made in Europe
|
||||||
|
</div>
|
||||||
|
<table
|
||||||
|
class="s-6 w-full"
|
||||||
|
role="presentation"
|
||||||
|
border="0"
|
||||||
|
cellpadding="0"
|
||||||
|
cellspacing="0"
|
||||||
|
style="width: 100%"
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
style="
|
||||||
|
line-height: 24px;
|
||||||
|
font-size: 24px;
|
||||||
|
width: 100%;
|
||||||
|
height: 24px;
|
||||||
|
margin: 0;
|
||||||
|
"
|
||||||
|
align="left"
|
||||||
|
width="100%"
|
||||||
|
height="24"
|
||||||
|
>
|
||||||
|
 
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<!--[if (gte mso 9)|(IE)]>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<![endif]-->
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
+1
-1
@@ -20,7 +20,7 @@
|
|||||||
<div class="text-muted text-center my-6">
|
<div class="text-muted text-center my-6">
|
||||||
This email is intended for {{email}}<br />
|
This email is intended for {{email}}<br />
|
||||||
Sent from Revolt<br />
|
Sent from Revolt<br />
|
||||||
Made in the EU
|
Made in Europe
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
@@ -5,4 +5,4 @@ Please navigate to: {{url}}
|
|||||||
|
|
||||||
This email is intended for {{email}}
|
This email is intended for {{email}}
|
||||||
Sent by Revolt
|
Sent by Revolt
|
||||||
Made in the EU
|
Made in Europe
|
||||||
@@ -1,13 +1,38 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-files"
|
name = "revolt-files"
|
||||||
version = "0.7.16"
|
version = "0.8.2"
|
||||||
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"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
tracing = "0.1"
|
||||||
|
|
||||||
|
ffprobe = "0.4.0"
|
||||||
|
imagesize = "0.13.0"
|
||||||
|
tempfile = "3.12.0"
|
||||||
|
|
||||||
|
base64 = "0.22.1"
|
||||||
aes-gcm = "0.10.3"
|
aes-gcm = "0.10.3"
|
||||||
|
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.8.2", path = "../config", features = [
|
||||||
|
"report-macros",
|
||||||
|
] }
|
||||||
|
revolt-result = { version = "0.8.2", path = "../result" }
|
||||||
|
|
||||||
|
# image processing
|
||||||
|
jxl-oxide = "0.8.1"
|
||||||
|
image = { version = "0.25.2" }
|
||||||
|
|
||||||
|
# svg rendering
|
||||||
|
usvg = "0.44.0"
|
||||||
|
resvg = "0.44.0"
|
||||||
|
tiny-skia = "0.11.4"
|
||||||
|
|
||||||
|
# encoding
|
||||||
|
webp = "0.3.0"
|
||||||
|
|||||||
@@ -1,3 +1,290 @@
|
|||||||
// pub fn
|
use std::io::{BufRead, Read, Seek, Write};
|
||||||
|
|
||||||
pub fn decrypt(data: &mut [u8]) {}
|
use aes_gcm::{
|
||||||
|
aead::{AeadCore, AeadMutInPlace, OsRng},
|
||||||
|
Aes256Gcm, Key, KeyInit, Nonce,
|
||||||
|
};
|
||||||
|
use image::{DynamicImage, ImageBuffer};
|
||||||
|
use revolt_config::{config, report_internal_error, FilesS3};
|
||||||
|
use revolt_result::{create_error, Result};
|
||||||
|
|
||||||
|
use aws_sdk_s3::{
|
||||||
|
config::{Credentials, Region},
|
||||||
|
Client, Config,
|
||||||
|
};
|
||||||
|
|
||||||
|
use base64::prelude::*;
|
||||||
|
use tempfile::NamedTempFile;
|
||||||
|
use tiny_skia::Pixmap;
|
||||||
|
|
||||||
|
/// Size of the authentication tag in the buffer
|
||||||
|
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)
|
||||||
|
pub async fn fetch_from_s3(bucket_id: &str, path: &str, nonce: &str) -> Result<Vec<u8>> {
|
||||||
|
let config = config().await;
|
||||||
|
let client = create_client(config.files.s3);
|
||||||
|
|
||||||
|
// 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))?;
|
||||||
|
|
||||||
|
Ok(buf)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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> {
|
||||||
|
let config = config().await;
|
||||||
|
let client = create_client(config.files.s3);
|
||||||
|
|
||||||
|
// 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
|
||||||
|
pub async fn delete_from_s3(bucket_id: &str, path: &str) -> Result<()> {
|
||||||
|
let config = config().await;
|
||||||
|
let client = create_client(config.files.s3);
|
||||||
|
|
||||||
|
report_internal_error!(
|
||||||
|
client
|
||||||
|
.delete_object()
|
||||||
|
.bucket(bucket_id)
|
||||||
|
.key(path)
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Determine size of image at temp file
|
||||||
|
pub fn image_size(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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Determine size of image with buffer
|
||||||
|
pub fn image_size_vec(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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Determine size of video at temp file
|
||||||
|
pub fn video_size(f: &NamedTempFile) -> Option<(i64, i64)> {
|
||||||
|
if let Ok(data) = ffprobe::ffprobe(f.path())
|
||||||
|
.inspect_err(|err| tracing::error!("Failed to ffprobe file! {err:?}"))
|
||||||
|
{
|
||||||
|
// Use first valid stream
|
||||||
|
for stream in data.streams {
|
||||||
|
if let (Some(w), Some(h)) = (stream.width, stream.height) {
|
||||||
|
return Some((w, h));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Decode image from reader
|
||||||
|
pub fn decode_image<R: Read + BufRead + Seek>(reader: &mut R, mime: &str) -> Result<DynamicImage> {
|
||||||
|
match mime {
|
||||||
|
// Read image using jxl-oxide crate
|
||||||
|
"image/jxl" => {
|
||||||
|
let jxl_image = report_internal_error!(jxl_oxide::JxlImage::builder().read(reader))?;
|
||||||
|
if let Ok(frame) = jxl_image.render_frame(0) {
|
||||||
|
match frame.color_channels().len() {
|
||||||
|
3 => Ok(DynamicImage::ImageRgb8(
|
||||||
|
DynamicImage::ImageRgb32F(
|
||||||
|
ImageBuffer::from_vec(
|
||||||
|
jxl_image.width(),
|
||||||
|
jxl_image.height(),
|
||||||
|
frame.image().buf().to_vec(),
|
||||||
|
)
|
||||||
|
.ok_or_else(|| create_error!(ImageProcessingFailed))?,
|
||||||
|
)
|
||||||
|
.to_rgb8(),
|
||||||
|
)),
|
||||||
|
4 => Ok(DynamicImage::ImageRgba8(
|
||||||
|
DynamicImage::ImageRgba32F(
|
||||||
|
ImageBuffer::from_vec(
|
||||||
|
jxl_image.width(),
|
||||||
|
jxl_image.height(),
|
||||||
|
frame.image().buf().to_vec(),
|
||||||
|
)
|
||||||
|
.ok_or_else(|| create_error!(ImageProcessingFailed))?,
|
||||||
|
)
|
||||||
|
.to_rgba8(),
|
||||||
|
)),
|
||||||
|
_ => Err(create_error!(ImageProcessingFailed)),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err(create_error!(ImageProcessingFailed))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Read image using resvg
|
||||||
|
"image/svg+xml" => {
|
||||||
|
// usvg doesn't support Read trait so copy to buffer
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
report_internal_error!(reader.read_to_end(&mut buf))?;
|
||||||
|
|
||||||
|
let tree = report_internal_error!(usvg::Tree::from_data(&buf, &Default::default()))?;
|
||||||
|
let size = tree.size();
|
||||||
|
let mut pixmap = Pixmap::new(size.width() as u32, size.height() as u32)
|
||||||
|
.ok_or_else(|| create_error!(ImageProcessingFailed))?;
|
||||||
|
|
||||||
|
let mut pixmap_mut = pixmap.as_mut();
|
||||||
|
resvg::render(&tree, Default::default(), &mut pixmap_mut);
|
||||||
|
|
||||||
|
Ok(DynamicImage::ImageRgba8(
|
||||||
|
ImageBuffer::from_vec(
|
||||||
|
size.width() as u32,
|
||||||
|
size.height() as u32,
|
||||||
|
pixmap.data().to_vec(),
|
||||||
|
)
|
||||||
|
.ok_or_else(|| create_error!(ImageProcessingFailed))?,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
// Check if we can read using image-rs crate
|
||||||
|
_ => report_internal_error!(report_internal_error!(
|
||||||
|
image::ImageReader::new(reader).with_guessed_format()
|
||||||
|
)?
|
||||||
|
.decode()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check whether given reader has a valid image
|
||||||
|
pub fn is_valid_image<R: Read + BufRead + Seek>(reader: &mut R, mime: &str) -> bool {
|
||||||
|
match mime {
|
||||||
|
// Check if we can read using jxl-oxide crate
|
||||||
|
"image/jxl" => jxl_oxide::JxlImage::builder()
|
||||||
|
.read(reader)
|
||||||
|
.inspect_err(|err| tracing::error!("Failed to read JXL! {err:?}"))
|
||||||
|
.is_ok(),
|
||||||
|
// Check if we can read using image-rs crate
|
||||||
|
_ => !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(_))
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create thumbnail from given image
|
||||||
|
pub async fn create_thumbnail(image: DynamicImage, tag: &str) -> Vec<u8> {
|
||||||
|
// Load configuration
|
||||||
|
let config = config().await;
|
||||||
|
let [w, h] = config.files.preview.get(tag).unwrap();
|
||||||
|
|
||||||
|
// Create thumbnail
|
||||||
|
//.resize(width as u32, height as u32, image::imageops::FilterType::Gaussian)
|
||||||
|
// resize is about 2.5x slower,
|
||||||
|
// thumbnail doesn't have terrible quality
|
||||||
|
// so we use thumbnail
|
||||||
|
let image = image.thumbnail(image.width().min(*w as u32), image.height().min(*h as u32));
|
||||||
|
|
||||||
|
// Encode it into WEBP
|
||||||
|
let encoder = webp::Encoder::from_image(&image).expect("Could not create encoder.");
|
||||||
|
if config.files.webp_quality != 100.0 {
|
||||||
|
encoder.encode(config.files.webp_quality).to_vec()
|
||||||
|
} else {
|
||||||
|
encoder.encode_lossless().to_vec()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-models"
|
name = "revolt-models"
|
||||||
version = "0.7.16"
|
version = "0.8.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
authors = ["Paul Makles <me@insrt.uk>"]
|
authors = ["Paul Makles <me@insrt.uk>"]
|
||||||
@@ -11,16 +11,17 @@ description = "Revolt Backend: API Models"
|
|||||||
[features]
|
[features]
|
||||||
serde = ["dep:serde", "revolt-permissions/serde", "indexmap/serde"]
|
serde = ["dep:serde", "revolt-permissions/serde", "indexmap/serde"]
|
||||||
schemas = ["dep:schemars", "revolt-permissions/schemas"]
|
schemas = ["dep:schemars", "revolt-permissions/schemas"]
|
||||||
|
utoipa = ["dep:utoipa"]
|
||||||
validator = ["dep:validator"]
|
validator = ["dep:validator"]
|
||||||
rocket = ["dep:rocket"]
|
rocket = ["dep:rocket"]
|
||||||
partials = ["dep:revolt_optional_struct", "serde", "schemas"]
|
partials = ["dep:revolt_optional_struct", "serde", "schemas", "utoipa"]
|
||||||
|
|
||||||
default = ["serde", "partials", "rocket"]
|
default = ["serde", "partials", "rocket"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# Core
|
# Core
|
||||||
revolt-config = { version = "0.7.16", path = "../config" }
|
revolt-config = { version = "0.8.2", path = "../config" }
|
||||||
revolt-permissions = { version = "0.7.16", path = "../permissions" }
|
revolt-permissions = { version = "0.8.2", path = "../permissions" }
|
||||||
|
|
||||||
# Utility
|
# Utility
|
||||||
regex = "1"
|
regex = "1"
|
||||||
@@ -37,6 +38,7 @@ iso8601-timestamp = { version = "0.2.11", features = ["schema", "bson"] }
|
|||||||
|
|
||||||
# Spec Generation
|
# Spec Generation
|
||||||
schemars = { version = "0.8.8", optional = true, features = ["indexmap1"] }
|
schemars = { version = "0.8.8", optional = true, features = ["indexmap1"] }
|
||||||
|
utoipa = { version = "4.2.3", optional = true }
|
||||||
|
|
||||||
# Validation
|
# Validation
|
||||||
validator = { version = "0.16.0", optional = true, features = ["derive"] }
|
validator = { version = "0.16.0", optional = true, features = ["derive"] }
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ extern crate serde;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate schemars;
|
extern crate schemars;
|
||||||
|
|
||||||
|
#[cfg(feature = "utoipa")]
|
||||||
|
#[macro_use]
|
||||||
|
extern crate utoipa;
|
||||||
|
|
||||||
#[cfg(feature = "partials")]
|
#[cfg(feature = "partials")]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate revolt_optional_struct;
|
extern crate revolt_optional_struct;
|
||||||
@@ -18,6 +22,7 @@ macro_rules! auto_derived {
|
|||||||
$(
|
$(
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
#[cfg_attr(feature = "schemas", derive(JsonSchema))]
|
#[cfg_attr(feature = "schemas", derive(JsonSchema))]
|
||||||
|
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
$item
|
$item
|
||||||
)+
|
)+
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ auto_derived_partial!(
|
|||||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||||
pub avatar: Option<File>,
|
pub avatar: Option<File>,
|
||||||
|
|
||||||
|
/// User that created this webhook
|
||||||
|
pub creator_id: String,
|
||||||
|
|
||||||
/// The channel this webhook belongs to
|
/// The channel this webhook belongs to
|
||||||
pub channel_id: String,
|
pub channel_id: String,
|
||||||
|
|
||||||
|
|||||||
@@ -306,4 +306,18 @@ impl Channel {
|
|||||||
| Channel::VoiceChannel { id, .. } => id,
|
| Channel::VoiceChannel { id, .. } => id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This returns a Result because the recipient name can't be determined here without a db call,
|
||||||
|
/// which can't be done since this is models, which can't reference the database crate.
|
||||||
|
///
|
||||||
|
/// If it returns Err, you need to fetch the name from the db.
|
||||||
|
pub fn name(&self) -> Result<&str, ()> {
|
||||||
|
match self {
|
||||||
|
Channel::DirectMessage { .. } => Err(()),
|
||||||
|
Channel::SavedMessages { .. } => Ok("Saved Messages"),
|
||||||
|
Channel::TextChannel { name, .. }
|
||||||
|
| Channel::Group { name, .. }
|
||||||
|
| Channel::VoiceChannel { name, .. } => Ok(name),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ auto_derived!(
|
|||||||
/// URL to the original image
|
/// URL to the original image
|
||||||
pub url: String,
|
pub url: String,
|
||||||
/// Width of the image
|
/// Width of the image
|
||||||
pub width: isize,
|
pub width: usize,
|
||||||
/// Height of the image
|
/// Height of the image
|
||||||
pub height: isize,
|
pub height: usize,
|
||||||
/// Positioning and size
|
/// Positioning and size
|
||||||
pub size: ImageSize,
|
pub size: ImageSize,
|
||||||
}
|
}
|
||||||
@@ -26,9 +26,9 @@ auto_derived!(
|
|||||||
/// URL to the original video
|
/// URL to the original video
|
||||||
pub url: String,
|
pub url: String,
|
||||||
/// Width of the video
|
/// Width of the video
|
||||||
pub width: isize,
|
pub width: usize,
|
||||||
/// Height of the video
|
/// Height of the video
|
||||||
pub height: isize,
|
pub height: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Type of remote Twitch content
|
/// Type of remote Twitch content
|
||||||
@@ -86,7 +86,7 @@ auto_derived!(
|
|||||||
},
|
},
|
||||||
AppleMusic {
|
AppleMusic {
|
||||||
album_id: String,
|
album_id: String,
|
||||||
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
track_id: Option<String>,
|
track_id: Option<String>,
|
||||||
},
|
},
|
||||||
@@ -119,8 +119,6 @@ auto_derived!(
|
|||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub video: Option<Video>,
|
pub video: Option<Video>,
|
||||||
|
|
||||||
// #[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
// opengraph_type: Option<String>,
|
|
||||||
/// Site name
|
/// Site name
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub site_name: Option<String>,
|
pub site_name: Option<String>,
|
||||||
@@ -156,11 +154,56 @@ auto_derived!(
|
|||||||
|
|
||||||
/// Embed
|
/// Embed
|
||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
|
#[derive(Default)]
|
||||||
pub enum Embed {
|
pub enum Embed {
|
||||||
Website(WebsiteMetadata),
|
Website(WebsiteMetadata),
|
||||||
Image(Image),
|
Image(Image),
|
||||||
Video(Video),
|
Video(Video),
|
||||||
Text(Text),
|
Text(Text),
|
||||||
|
#[default]
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
impl WebsiteMetadata {
|
||||||
|
/// Truncate strings in metadata
|
||||||
|
pub fn truncate(&mut self) {
|
||||||
|
if let Some(s) = self.url.as_mut() {
|
||||||
|
s.truncate(256);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(s) = self.original_url.as_mut() {
|
||||||
|
s.truncate(256);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(s) = self.title.as_mut() {
|
||||||
|
s.truncate(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(s) = self.description.as_mut() {
|
||||||
|
s.truncate(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(s) = self.site_name.as_mut() {
|
||||||
|
s.truncate(32);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(s) = self.icon_url.as_mut() {
|
||||||
|
s.truncate(256);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(s) = self.colour.as_mut() {
|
||||||
|
s.truncate(32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check if this is considered "empty"
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
(self.title.is_none() || self.title.as_ref().is_some_and(|f| f.is_empty()))
|
||||||
|
&& (self.description.is_none()
|
||||||
|
|| self.description.as_ref().is_some_and(|f| f.is_empty()))
|
||||||
|
&& self.special.is_none()
|
||||||
|
&& self.video.is_none()
|
||||||
|
&& self.image.is_none()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ use rocket::{FromForm, FromFormField};
|
|||||||
|
|
||||||
use iso8601_timestamp::Timestamp;
|
use iso8601_timestamp::Timestamp;
|
||||||
|
|
||||||
use super::{Embed, File, Member, MessageWebhook, User, Webhook, RE_COLOUR};
|
use super::{Channel, Embed, File, Member, MessageWebhook, User, Webhook, RE_COLOUR};
|
||||||
|
|
||||||
pub static RE_MENTION: Lazy<Regex> =
|
pub static RE_MENTION: Lazy<Regex> =
|
||||||
Lazy::new(|| Regex::new(r"<@([0-9A-HJKMNP-TV-Z]{26})>").unwrap());
|
Lazy::new(|| Regex::new(r"<@([0-9A-HJKMNP-TV-Z]{26})>").unwrap());
|
||||||
@@ -209,6 +209,8 @@ auto_derived!(
|
|||||||
pub url: String,
|
pub url: String,
|
||||||
/// The message object itself, to send to clients for processing
|
/// The message object itself, to send to clients for processing
|
||||||
pub message: Message,
|
pub message: Message,
|
||||||
|
/// The channel object itself, for clients to process
|
||||||
|
pub channel: Channel,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Representation of a text embed before it is sent.
|
/// Representation of a text embed before it is sent.
|
||||||
@@ -278,7 +280,7 @@ auto_derived!(
|
|||||||
pub struct OptionsQueryMessages {
|
pub struct OptionsQueryMessages {
|
||||||
/// Maximum number of messages to fetch
|
/// Maximum number of messages to fetch
|
||||||
///
|
///
|
||||||
/// For fetching nearby messages, this is \`(limit + 1)\`.
|
/// For fetching nearby messages, this is \`(limit + 2)\`.
|
||||||
#[cfg_attr(feature = "validator", validate(range(min = 1, max = 100)))]
|
#[cfg_attr(feature = "validator", validate(range(min = 1, max = 100)))]
|
||||||
pub limit: Option<i64>,
|
pub limit: Option<i64>,
|
||||||
/// Message id before which messages should be fetched
|
/// Message id before which messages should be fetched
|
||||||
@@ -369,7 +371,7 @@ auto_derived!(
|
|||||||
|
|
||||||
/// Optional fields on message
|
/// Optional fields on message
|
||||||
pub enum FieldsMessage {
|
pub enum FieldsMessage {
|
||||||
Pinned
|
Pinned,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -442,7 +444,7 @@ impl From<SystemMessage> for String {
|
|||||||
|
|
||||||
impl PushNotification {
|
impl PushNotification {
|
||||||
/// Create a new notification from a given message, author and channel ID
|
/// Create a new notification from a given message, author and channel ID
|
||||||
pub async fn from(msg: Message, author: Option<MessageAuthor<'_>>, channel_id: &str) -> Self {
|
pub async fn from(msg: Message, author: Option<MessageAuthor<'_>>, channel: Channel) -> Self {
|
||||||
let config = config().await;
|
let config = config().await;
|
||||||
|
|
||||||
let icon = if let Some(author) = &author {
|
let icon = if let Some(author) = &author {
|
||||||
@@ -496,10 +498,11 @@ impl PushNotification {
|
|||||||
icon,
|
icon,
|
||||||
image,
|
image,
|
||||||
body,
|
body,
|
||||||
tag: channel_id.to_string(),
|
tag: channel.id().to_string(),
|
||||||
timestamp,
|
timestamp,
|
||||||
url: format!("{}/channel/{}/{}", config.hosts.app, channel_id, msg.id),
|
url: format!("{}/channel/{}/{}", config.hosts.app, channel.id(), msg.id),
|
||||||
message: msg,
|
message: msg,
|
||||||
|
channel,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,6 +88,9 @@ auto_derived!(
|
|||||||
ProfileContent,
|
ProfileContent,
|
||||||
ProfileBackground,
|
ProfileBackground,
|
||||||
DisplayName,
|
DisplayName,
|
||||||
|
|
||||||
|
/// Internal field, ignore this.
|
||||||
|
Internal,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// User's relationship with another user (or themselves)
|
/// User's relationship with another user (or themselves)
|
||||||
@@ -190,7 +193,7 @@ auto_derived!(
|
|||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
pub enum UserFlags {
|
pub enum UserFlags {
|
||||||
/// User has been suspended from the platform
|
/// User has been suspended from the platform
|
||||||
Suspended = 1,
|
SuspendedUntil = 1,
|
||||||
/// User has deleted their account
|
/// User has deleted their account
|
||||||
Deleted = 2,
|
Deleted = 2,
|
||||||
/// User was banned off the platform
|
/// User was banned off the platform
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-permissions"
|
name = "revolt-permissions"
|
||||||
version = "0.7.16"
|
version = "0.8.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
authors = ["Paul Makles <me@insrt.uk>"]
|
authors = ["Paul Makles <me@insrt.uk>"]
|
||||||
@@ -21,7 +21,7 @@ async-std = { version = "1.8.0", features = ["attributes"] }
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# Core
|
# Core
|
||||||
revolt-result = { version = "0.7.16", path = "../result" }
|
revolt-result = { version = "0.8.2", path = "../result" }
|
||||||
|
|
||||||
# Utility
|
# Utility
|
||||||
auto_ops = "0.3.0"
|
auto_ops = "0.3.0"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-presence"
|
name = "revolt-presence"
|
||||||
version = "0.7.16"
|
version = "0.8.2"
|
||||||
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>"]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-result"
|
name = "revolt-result"
|
||||||
version = "0.7.16"
|
version = "0.8.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
authors = ["Paul Makles <me@insrt.uk>"]
|
authors = ["Paul Makles <me@insrt.uk>"]
|
||||||
@@ -11,7 +11,9 @@ description = "Revolt Backend: Result and Error types"
|
|||||||
[features]
|
[features]
|
||||||
serde = ["dep:serde"]
|
serde = ["dep:serde"]
|
||||||
schemas = ["dep:schemars"]
|
schemas = ["dep:schemars"]
|
||||||
|
utoipa = ["dep:utoipa"]
|
||||||
rocket = ["dep:rocket", "dep:serde_json"]
|
rocket = ["dep:rocket", "dep:serde_json"]
|
||||||
|
axum = ["dep:axum", "dep:serde_json"]
|
||||||
okapi = ["dep:revolt_rocket_okapi", "dep:revolt_okapi", "schemas"]
|
okapi = ["dep:revolt_rocket_okapi", "dep:revolt_okapi", "schemas"]
|
||||||
|
|
||||||
default = ["serde"]
|
default = ["serde"]
|
||||||
@@ -23,8 +25,12 @@ serde = { version = "1", features = ["derive"], optional = true }
|
|||||||
|
|
||||||
# Spec Generation
|
# Spec Generation
|
||||||
schemars = { version = "0.8.8", optional = true }
|
schemars = { version = "0.8.8", optional = true }
|
||||||
|
utoipa = { version = "4.2.3", optional = true }
|
||||||
|
|
||||||
# Rocket
|
# Rocket
|
||||||
rocket = { optional = true, version = "0.5.0-rc.2", default-features = false }
|
rocket = { optional = true, version = "0.5.0-rc.2", default-features = false }
|
||||||
revolt_rocket_okapi = { version = "0.9.1", optional = true }
|
revolt_rocket_okapi = { version = "0.10.0", optional = true }
|
||||||
revolt_okapi = { version = "0.9.1", optional = true }
|
revolt_okapi = { version = "0.9.1", optional = true }
|
||||||
|
|
||||||
|
# Axum
|
||||||
|
axum = { version = "0.7.5", optional = true }
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
use axum::{http::StatusCode, response::IntoResponse, Json};
|
||||||
|
use rocket::http::Status;
|
||||||
|
|
||||||
|
use crate::{Error, ErrorType};
|
||||||
|
|
||||||
|
/// HTTP response builder for Error enum
|
||||||
|
impl IntoResponse for Error {
|
||||||
|
fn into_response(self) -> axum::response::Response {
|
||||||
|
let status = match self.error_type {
|
||||||
|
ErrorType::LabelMe => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
|
||||||
|
ErrorType::AlreadyOnboarded => StatusCode::FORBIDDEN,
|
||||||
|
|
||||||
|
ErrorType::UnknownUser => StatusCode::NOT_FOUND,
|
||||||
|
ErrorType::InvalidUsername => StatusCode::BAD_REQUEST,
|
||||||
|
ErrorType::UsernameTaken => StatusCode::CONFLICT,
|
||||||
|
ErrorType::DiscriminatorChangeRatelimited => StatusCode::TOO_MANY_REQUESTS,
|
||||||
|
ErrorType::AlreadyFriends => StatusCode::CONFLICT,
|
||||||
|
ErrorType::AlreadySentRequest => StatusCode::CONFLICT,
|
||||||
|
ErrorType::Blocked => StatusCode::CONFLICT,
|
||||||
|
ErrorType::BlockedByOther => StatusCode::FORBIDDEN,
|
||||||
|
ErrorType::NotFriends => StatusCode::FORBIDDEN,
|
||||||
|
ErrorType::TooManyPendingFriendRequests { .. } => StatusCode::BAD_REQUEST,
|
||||||
|
|
||||||
|
ErrorType::UnknownChannel => StatusCode::NOT_FOUND,
|
||||||
|
ErrorType::UnknownMessage => StatusCode::NOT_FOUND,
|
||||||
|
ErrorType::UnknownAttachment => StatusCode::BAD_REQUEST,
|
||||||
|
ErrorType::CannotEditMessage => StatusCode::FORBIDDEN,
|
||||||
|
ErrorType::CannotJoinCall => StatusCode::BAD_REQUEST,
|
||||||
|
ErrorType::TooManyAttachments { .. } => StatusCode::BAD_REQUEST,
|
||||||
|
ErrorType::TooManyReplies { .. } => StatusCode::BAD_REQUEST,
|
||||||
|
ErrorType::EmptyMessage => StatusCode::UNPROCESSABLE_ENTITY,
|
||||||
|
ErrorType::PayloadTooLarge => StatusCode::UNPROCESSABLE_ENTITY,
|
||||||
|
ErrorType::CannotRemoveYourself => StatusCode::BAD_REQUEST,
|
||||||
|
ErrorType::GroupTooLarge { .. } => StatusCode::FORBIDDEN,
|
||||||
|
ErrorType::AlreadyInGroup => StatusCode::CONFLICT,
|
||||||
|
ErrorType::NotInGroup => StatusCode::NOT_FOUND,
|
||||||
|
ErrorType::AlreadyPinned => StatusCode::BAD_REQUEST,
|
||||||
|
ErrorType::NotPinned => StatusCode::BAD_REQUEST,
|
||||||
|
|
||||||
|
ErrorType::UnknownServer => StatusCode::NOT_FOUND,
|
||||||
|
ErrorType::InvalidRole => StatusCode::NOT_FOUND,
|
||||||
|
ErrorType::Banned => StatusCode::FORBIDDEN,
|
||||||
|
ErrorType::AlreadyInServer => StatusCode::CONFLICT,
|
||||||
|
ErrorType::CannotTimeoutYourself => StatusCode::BAD_REQUEST,
|
||||||
|
|
||||||
|
ErrorType::TooManyServers { .. } => StatusCode::BAD_REQUEST,
|
||||||
|
ErrorType::TooManyEmbeds { .. } => StatusCode::BAD_REQUEST,
|
||||||
|
ErrorType::TooManyEmoji { .. } => StatusCode::BAD_REQUEST,
|
||||||
|
ErrorType::TooManyChannels { .. } => StatusCode::BAD_REQUEST,
|
||||||
|
ErrorType::TooManyRoles { .. } => StatusCode::BAD_REQUEST,
|
||||||
|
|
||||||
|
ErrorType::ReachedMaximumBots => StatusCode::BAD_REQUEST,
|
||||||
|
ErrorType::IsBot => StatusCode::BAD_REQUEST,
|
||||||
|
ErrorType::BotIsPrivate => StatusCode::FORBIDDEN,
|
||||||
|
|
||||||
|
ErrorType::CannotReportYourself => StatusCode::BAD_REQUEST,
|
||||||
|
|
||||||
|
ErrorType::MissingPermission { .. } => StatusCode::FORBIDDEN,
|
||||||
|
ErrorType::MissingUserPermission { .. } => StatusCode::FORBIDDEN,
|
||||||
|
ErrorType::NotElevated => StatusCode::FORBIDDEN,
|
||||||
|
ErrorType::NotPrivileged => StatusCode::FORBIDDEN,
|
||||||
|
ErrorType::CannotGiveMissingPermissions => StatusCode::FORBIDDEN,
|
||||||
|
ErrorType::NotOwner => StatusCode::FORBIDDEN,
|
||||||
|
|
||||||
|
ErrorType::DatabaseError { .. } => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
ErrorType::InternalError => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
ErrorType::InvalidOperation => StatusCode::BAD_REQUEST,
|
||||||
|
ErrorType::InvalidCredentials => StatusCode::UNAUTHORIZED,
|
||||||
|
ErrorType::InvalidProperty => StatusCode::BAD_REQUEST,
|
||||||
|
ErrorType::InvalidSession => StatusCode::UNAUTHORIZED,
|
||||||
|
ErrorType::NotAuthenticated => StatusCode::UNAUTHORIZED,
|
||||||
|
ErrorType::DuplicateNonce => StatusCode::CONFLICT,
|
||||||
|
ErrorType::VosoUnavailable => StatusCode::BAD_REQUEST,
|
||||||
|
ErrorType::NotFound => StatusCode::NOT_FOUND,
|
||||||
|
ErrorType::NoEffect => StatusCode::OK,
|
||||||
|
ErrorType::FailedValidation { .. } => StatusCode::BAD_REQUEST,
|
||||||
|
|
||||||
|
ErrorType::ProxyError => StatusCode::BAD_REQUEST,
|
||||||
|
ErrorType::FileTooSmall => StatusCode::UNPROCESSABLE_ENTITY,
|
||||||
|
ErrorType::FileTooLarge { .. } => StatusCode::UNPROCESSABLE_ENTITY,
|
||||||
|
ErrorType::FileTypeNotAllowed => StatusCode::BAD_REQUEST,
|
||||||
|
ErrorType::ImageProcessingFailed => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
ErrorType::NoEmbedData => StatusCode::BAD_REQUEST,
|
||||||
|
};
|
||||||
|
|
||||||
|
(status, Json(&self)).into_response()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,9 +8,16 @@ extern crate serde;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate schemars;
|
extern crate schemars;
|
||||||
|
|
||||||
|
#[cfg(feature = "utoipa")]
|
||||||
|
#[macro_use]
|
||||||
|
extern crate utoipa;
|
||||||
|
|
||||||
#[cfg(feature = "rocket")]
|
#[cfg(feature = "rocket")]
|
||||||
pub mod rocket;
|
pub mod rocket;
|
||||||
|
|
||||||
|
#[cfg(feature = "axum")]
|
||||||
|
pub mod axum;
|
||||||
|
|
||||||
#[cfg(feature = "okapi")]
|
#[cfg(feature = "okapi")]
|
||||||
pub mod okapi;
|
pub mod okapi;
|
||||||
|
|
||||||
@@ -20,6 +27,7 @@ pub type Result<T, E = Error> = std::result::Result<T, E>;
|
|||||||
/// Error information
|
/// Error information
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
#[cfg_attr(feature = "schemas", derive(JsonSchema))]
|
#[cfg_attr(feature = "schemas", derive(JsonSchema))]
|
||||||
|
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Error {
|
pub struct Error {
|
||||||
/// Type of error and additional information
|
/// Type of error and additional information
|
||||||
@@ -42,6 +50,7 @@ impl std::error::Error for Error {}
|
|||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
#[cfg_attr(feature = "serde", serde(tag = "type"))]
|
#[cfg_attr(feature = "serde", serde(tag = "type"))]
|
||||||
#[cfg_attr(feature = "schemas", derive(JsonSchema))]
|
#[cfg_attr(feature = "schemas", derive(JsonSchema))]
|
||||||
|
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum ErrorType {
|
pub enum ErrorType {
|
||||||
/// This error was not labeled :(
|
/// This error was not labeled :(
|
||||||
@@ -107,6 +116,7 @@ pub enum ErrorType {
|
|||||||
max: usize,
|
max: usize,
|
||||||
},
|
},
|
||||||
AlreadyInServer,
|
AlreadyInServer,
|
||||||
|
CannotTimeoutYourself,
|
||||||
|
|
||||||
// ? Bot related errors
|
// ? Bot related errors
|
||||||
ReachedMaximumBots,
|
ReachedMaximumBots,
|
||||||
@@ -138,6 +148,7 @@ pub enum ErrorType {
|
|||||||
InvalidCredentials,
|
InvalidCredentials,
|
||||||
InvalidProperty,
|
InvalidProperty,
|
||||||
InvalidSession,
|
InvalidSession,
|
||||||
|
NotAuthenticated,
|
||||||
DuplicateNonce,
|
DuplicateNonce,
|
||||||
NotFound,
|
NotFound,
|
||||||
NoEffect,
|
NoEffect,
|
||||||
@@ -145,6 +156,16 @@ pub enum ErrorType {
|
|||||||
error: String,
|
error: String,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// ? Micro-service errors
|
||||||
|
ProxyError,
|
||||||
|
FileTooSmall,
|
||||||
|
FileTooLarge {
|
||||||
|
max: usize,
|
||||||
|
},
|
||||||
|
FileTypeNotAllowed,
|
||||||
|
ImageProcessingFailed,
|
||||||
|
NoEmbedData,
|
||||||
|
|
||||||
// ? Legacy errors
|
// ? Legacy errors
|
||||||
VosoUnavailable,
|
VosoUnavailable,
|
||||||
}
|
}
|
||||||
@@ -169,23 +190,6 @@ macro_rules! create_database_error {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
macro_rules! query {
|
|
||||||
( $self: ident, $type: ident, $collection: expr, $($rest:expr),+ ) => {
|
|
||||||
Ok($self.$type($collection, $($rest),+).await.unwrap())
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
#[cfg(not(debug_assertions))]
|
|
||||||
macro_rules! query {
|
|
||||||
( $self: ident, $type: ident, $collection: expr, $($rest:expr),+ ) => {
|
|
||||||
$self.$type($collection, $($rest),+).await
|
|
||||||
.map_err(|_| create_database_error!(stringify!($type), $collection))
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::ErrorType;
|
use crate::ErrorType;
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ impl<'r> Responder<'r, 'static> for Error {
|
|||||||
ErrorType::InvalidRole => Status::NotFound,
|
ErrorType::InvalidRole => Status::NotFound,
|
||||||
ErrorType::Banned => Status::Forbidden,
|
ErrorType::Banned => Status::Forbidden,
|
||||||
ErrorType::AlreadyInServer => Status::Conflict,
|
ErrorType::AlreadyInServer => Status::Conflict,
|
||||||
|
ErrorType::CannotTimeoutYourself => Status::BadRequest,
|
||||||
|
|
||||||
ErrorType::TooManyServers { .. } => Status::BadRequest,
|
ErrorType::TooManyServers { .. } => Status::BadRequest,
|
||||||
ErrorType::TooManyEmbeds { .. } => Status::BadRequest,
|
ErrorType::TooManyEmbeds { .. } => Status::BadRequest,
|
||||||
@@ -73,11 +74,19 @@ impl<'r> Responder<'r, 'static> for Error {
|
|||||||
ErrorType::InvalidCredentials => Status::Unauthorized,
|
ErrorType::InvalidCredentials => Status::Unauthorized,
|
||||||
ErrorType::InvalidProperty => Status::BadRequest,
|
ErrorType::InvalidProperty => Status::BadRequest,
|
||||||
ErrorType::InvalidSession => Status::Unauthorized,
|
ErrorType::InvalidSession => Status::Unauthorized,
|
||||||
|
ErrorType::NotAuthenticated => Status::Unauthorized,
|
||||||
ErrorType::DuplicateNonce => Status::Conflict,
|
ErrorType::DuplicateNonce => Status::Conflict,
|
||||||
ErrorType::VosoUnavailable => Status::BadRequest,
|
ErrorType::VosoUnavailable => Status::BadRequest,
|
||||||
ErrorType::NotFound => Status::NotFound,
|
ErrorType::NotFound => Status::NotFound,
|
||||||
ErrorType::NoEffect => Status::Ok,
|
ErrorType::NoEffect => Status::Ok,
|
||||||
ErrorType::FailedValidation { .. } => Status::BadRequest,
|
ErrorType::FailedValidation { .. } => Status::BadRequest,
|
||||||
|
|
||||||
|
ErrorType::ProxyError => Status::BadRequest,
|
||||||
|
ErrorType::FileTooSmall => Status::UnprocessableEntity,
|
||||||
|
ErrorType::FileTooLarge { .. } => Status::UnprocessableEntity,
|
||||||
|
ErrorType::FileTypeNotAllowed => Status::BadRequest,
|
||||||
|
ErrorType::ImageProcessingFailed => Status::InternalServerError,
|
||||||
|
ErrorType::NoEmbedData => Status::BadRequest,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Serialize the error data structure into JSON.
|
// Serialize the error data structure into JSON.
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
[package]
|
||||||
|
name = "revolt-crond"
|
||||||
|
version = "0.8.2"
|
||||||
|
license = "AGPL-3.0-or-later"
|
||||||
|
authors = ["Paul Makles <me@insrt.uk>"]
|
||||||
|
edition = "2021"
|
||||||
|
description = "Revolt Daemon Service: Timed data clean up tasks"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
# Utility
|
||||||
|
log = "0.4"
|
||||||
|
|
||||||
|
# Async
|
||||||
|
tokio = { version = "1" }
|
||||||
|
|
||||||
|
# Core
|
||||||
|
revolt-database = { version = "0.8.2", path = "../../core/database" }
|
||||||
|
revolt-result = { version = "0.8.2", path = "../../core/result" }
|
||||||
|
revolt-config = { version = "0.8.2", path = "../../core/config" }
|
||||||
|
revolt-files = { version = "0.8.2", path = "../../core/files" }
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# Build Stage
|
||||||
|
FROM ghcr.io/revoltchat/base:latest AS builder
|
||||||
|
FROM debian:12 AS debian
|
||||||
|
|
||||||
|
# Bundle Stage
|
||||||
|
FROM gcr.io/distroless/cc-debian12:nonroot
|
||||||
|
COPY --from=builder /home/rust/src/target/release/revolt-crond ./
|
||||||
|
|
||||||
|
USER nonroot
|
||||||
|
CMD ["./revolt-crond"]
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
use revolt_config::configure;
|
||||||
|
use revolt_database::DatabaseInfo;
|
||||||
|
use revolt_result::Result;
|
||||||
|
use tasks::{file_deletion, prune_dangling_files};
|
||||||
|
use tokio::try_join;
|
||||||
|
|
||||||
|
pub mod tasks;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<()> {
|
||||||
|
configure!(crond);
|
||||||
|
|
||||||
|
let db = DatabaseInfo::Auto.connect().await.expect("database");
|
||||||
|
try_join!(
|
||||||
|
file_deletion::task(db.clone()),
|
||||||
|
prune_dangling_files::task(db)
|
||||||
|
)
|
||||||
|
.map(|_| ())
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user