Skip to content

Commit

Permalink
Merge pull request #284 from meower-media/develop
Browse files Browse the repository at this point in the history
Deploy fixes
  • Loading branch information
showierdata9978 authored Aug 14, 2024
2 parents ed5a047 + 015e0a8 commit 493e6df
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 56 deletions.
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ GRPC_AUTH_ADDRESS="0.0.0.0:5000"
GRPC_AUTH_TOKEN=

GRPC_UPLOADS_ADDRESS=
GRPC_UPLOADS_TOKEN=
GRPC_UPLOADS_TOKEN=

CHAT_EMOJIS_LIMIT=250
CHAT_STICKERS_LIMIT=50
26 changes: 0 additions & 26 deletions .github/workflows/build-and-push-main.yml

This file was deleted.

27 changes: 27 additions & 0 deletions .github/workflows/publish-ghcr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Publish to GHCR.io

on:
push:
branches: [ "*" ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GHCR.io
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Get short SHA
run: echo "SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_ENV

- name: Build and push images
run: |
IMAGE_NAME=ghcr.io/${{ github.repository }}
docker buildx build --push -t $IMAGE_NAME:${{ env.SHORT_SHA }} .
24 changes: 24 additions & 0 deletions .github/workflows/publish-latest-ghcr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Publish latest to GHCR.io

on:
push:
branches: [ "main" ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GHCR.io
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Build and push images
run: |
IMAGE_NAME=ghcr.io/${{ github.repository }}
docker buildx build --push -t $IMAGE_NAME:latest .
37 changes: 13 additions & 24 deletions rest_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@
from pydantic import BaseModel
import time, os

from .auth import auth_bp
from .me import me_bp
from .home import home_bp
from .inbox import inbox_bp
from .posts import posts_bp
from .users import users_bp
from .chats import chats_bp
from .search import search_bp
from .v0 import v0


from .admin import admin_bp

from database import db, blocked_ips, registration_blocked_ips
Expand Down Expand Up @@ -97,7 +92,7 @@ async def check_auth(headers: TokenHeader):

@app.get("/") # Welcome message
async def index():
return {
return {
"captcha": {
"enabled": os.getenv("CAPTCHA_SECRET") is not None,
"sitekey": os.getenv("CAPTCHA_SITEKEY")
Expand All @@ -108,7 +103,7 @@ async def index():
@app.get("/favicon.ico") # Favicon, my ass. We need no favicon for an API.
@hide
async def favicon_my_ass():
return "", 200
return "", 200


@app.get("/status")
Expand Down Expand Up @@ -167,12 +162,12 @@ async def validation_error(e):

@app.errorhandler(400) # Bad request
async def bad_request(e):
return {"error": True, "type": "badRequest"}, 400
return {"error": True, "type": "badRequest"}, 400


@app.errorhandler(401) # Unauthorized
async def unauthorized(e):
return {"error": True, "type": "Unauthorized"}, 401
return {"error": True, "type": "Unauthorized"}, 401


@app.errorhandler(403) # Missing permissions
Expand All @@ -182,22 +177,22 @@ async def missing_permissions(e):

@app.errorhandler(404) # We do need a 404 handler.
async def not_found(e):
return {"error": True, "type": "notFound"}, 404
return {"error": True, "type": "notFound"}, 404


@app.errorhandler(405) # Method not allowed
async def method_not_allowed(e):
return {"error": True, "type": "methodNotAllowed"}, 405
return {"error": True, "type": "methodNotAllowed"}, 405


@app.errorhandler(429) # Too many requests
async def too_many_requests(e):
return {"error": True, "type": "tooManyRequests"}, 429
return {"error": True, "type": "tooManyRequests"}, 429


@app.errorhandler(500) # Internal
async def internal(e):
return {"error": True, "type": "Internal"}, 500
return {"error": True, "type": "Internal"}, 500


@app.errorhandler(501) # Not implemented
Expand All @@ -206,12 +201,6 @@ async def not_implemented(e):


# Register blueprints
app.register_blueprint(auth_bp)
app.register_blueprint(me_bp)
app.register_blueprint(home_bp)
app.register_blueprint(inbox_bp)
app.register_blueprint(posts_bp)
app.register_blueprint(users_bp)
app.register_blueprint(chats_bp)
app.register_blueprint(search_bp)
app.register_blueprint(admin_bp)
app.register_blueprint(v0, url_prefix="/v0")
app.register_blueprint(v0, url_prefix="/", name="root")
22 changes: 22 additions & 0 deletions rest_api/v0/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from quart import Blueprint

from .search import search_bp
from .chats import chats_bp
from .inbox import inbox_bp
from .posts import posts_bp
from .users import users_bp
from .auth import auth_bp
from .home import home_bp
from .me import me_bp

v0 = Blueprint("v0", __name__)

v0.register_blueprint(auth_bp)
v0.register_blueprint(me_bp)
v0.register_blueprint(home_bp)
v0.register_blueprint(inbox_bp)
v0.register_blueprint(posts_bp)
v0.register_blueprint(users_bp)
v0.register_blueprint(chats_bp)
v0.register_blueprint(search_bp)

File renamed without changes.
10 changes: 5 additions & 5 deletions rest_api/chats.py → rest_api/v0/chats.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from quart_schema import validate_querystring, validate_request
from pydantic import BaseModel, Field
from typing import Optional, Literal
import pymongo, uuid, time, re
import pymongo, uuid, time, re, os

import security
from database import db, get_total_pages
Expand Down Expand Up @@ -203,7 +203,7 @@ async def update_chat(chat_id, data: ChatBody):
if data.icon is None or chat["icon"] == data.icon:
app.supporter.create_post(chat_id, "Server", f"@{request.user} changed the icon of the group chat.", chat_members=chat["members"])
if data.allow_pinning is not None:
chat["allow_pinning"] = data.allow_pinning
updated_vals["allow_pinning"] = data.allow_pinning

# Update chat
db.chats.update_one({"_id": chat_id}, {"$set": updated_vals})
Expand Down Expand Up @@ -648,12 +648,12 @@ async def create_chat_emote(chat_id: str, emote_type: Literal["emojis", "sticker
if chat["type"] != 1 and chat["owner"] != request.user:
abort(403)

# Make sure there's not too many emotes in the chat (100 for emojis, 25 for stickers)
# Make sure there's not too many emotes in the chat (250 for emojis, 50 for stickers)
if emote_type == "emojis":
if db.chat_emojis.count_documents({"chat_id": chat_id}, limit=100) >= 100:
if db.chat_emojis.count_documents({"chat_id": chat_id}, limit=250) >= int(os.getenv("CHAT_EMOJIS_LIMIT", 250)):
return {"error": True, "type": "tooManyEmojis"}, 403
elif emote_type == "stickers":
if db.chat_stickers.count_documents({"chat_id": chat_id}, limit=25) >= 25:
if db.chat_stickers.count_documents({"chat_id": chat_id}, limit=50) >= int(os.getenv("CHAT_STICKERS_LIMIT", 50)):
return {"error": True, "type": "tooManyStickers"}, 403

# Claim file
Expand Down
2 changes: 2 additions & 0 deletions rest_api/home.py → rest_api/v0/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class Config:
@home_bp.get("/")
@validate_querystring(GetHomeQueryArgs)
async def get_home_posts(query_args: GetHomeQueryArgs):
if not request.user:
query_args.page = 1
query = {"post_origin": "home", "isDeleted": False}
return {
"error": False,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 493e6df

Please sign in to comment.