This commit is contained in:
parent
20e1fa989a
commit
1f5e5472c9
|
@ -9,7 +9,7 @@ from services.schema import mutation, query
|
||||||
from orm.shout import Shout, ShoutAuthor, ShoutTopic
|
from orm.shout import Shout, ShoutAuthor, ShoutTopic
|
||||||
from orm.topic import Topic
|
from orm.topic import Topic
|
||||||
from reaction import reactions_follow, reactions_unfollow
|
from reaction import reactions_follow, reactions_unfollow
|
||||||
from services.presence import notify_shout
|
from services.notify import notify_shout
|
||||||
|
|
||||||
|
|
||||||
@query.field("loadDrafts")
|
@query.field("loadDrafts")
|
||||||
|
|
|
@ -6,7 +6,7 @@ from resolvers.community import community_follow, community_unfollow
|
||||||
from services.following import FollowingManager, FollowingResult
|
from services.following import FollowingManager, FollowingResult
|
||||||
from services.db import local_session
|
from services.db import local_session
|
||||||
from orm.author import Author
|
from orm.author import Author
|
||||||
from services.presence import notify_follower
|
from services.notify import notify_follower
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -52,7 +52,7 @@ async def unfollow(_, info, what, slug):
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
author = session.query(Author.id).where(Author.slug == slug).one()
|
author = session.query(Author.id).where(Author.slug == slug).one()
|
||||||
follower = session.query(Author).where(Author.id == follower_id).one()
|
follower = session.query(Author).where(Author.id == follower_id).one()
|
||||||
notify_follower(follower.dict(), author.id)
|
notify_follower(follower.dict(), author.id, "unfollow")
|
||||||
elif what == "TOPIC":
|
elif what == "TOPIC":
|
||||||
if topic_unfollow(follower_id, slug):
|
if topic_unfollow(follower_id, slug):
|
||||||
result = FollowingResult("DELETED", 'topic', slug)
|
result = FollowingResult("DELETED", 'topic', slug)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
from sqlalchemy import and_, asc, desc, select, text, func, case
|
from sqlalchemy import and_, asc, desc, select, text, func, case
|
||||||
from sqlalchemy.orm import aliased
|
from sqlalchemy.orm import aliased
|
||||||
from services.presence import notify_reaction
|
from services.notify import notify_reaction
|
||||||
from services.auth import login_required
|
from services.auth import login_required
|
||||||
from base.exceptions import OperationNotAllowed
|
from base.exceptions import OperationNotAllowed
|
||||||
from services.db import local_session
|
from services.db import local_session
|
||||||
|
|
|
@ -165,7 +165,7 @@ type AuthorStat {
|
||||||
|
|
||||||
type Author {
|
type Author {
|
||||||
id: Int!
|
id: Int!
|
||||||
user: Int!
|
user: String!
|
||||||
slug: String!
|
slug: String!
|
||||||
name: String
|
name: String
|
||||||
pic: String
|
pic: String
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
from starlette.exceptions import HTTPException
|
|
||||||
|
|
||||||
|
|
||||||
# TODO: remove traceback from logs for defined exceptions
|
|
||||||
|
|
||||||
|
|
||||||
class BaseHttpException(HTTPException):
|
|
||||||
states_code = 500
|
|
||||||
detail = "500 Server error"
|
|
||||||
|
|
||||||
|
|
||||||
class ExpiredToken(BaseHttpException):
|
|
||||||
states_code = 401
|
|
||||||
detail = "401 Expired Token"
|
|
||||||
|
|
||||||
|
|
||||||
class InvalidToken(BaseHttpException):
|
|
||||||
states_code = 401
|
|
||||||
detail = "401 Invalid Token"
|
|
||||||
|
|
||||||
|
|
||||||
class Unauthorized(BaseHttpException):
|
|
||||||
states_code = 401
|
|
||||||
detail = "401 Unauthorized"
|
|
||||||
|
|
||||||
|
|
||||||
class ObjectNotExist(BaseHttpException):
|
|
||||||
code = 404
|
|
||||||
detail = "404 Object Does Not Exist"
|
|
||||||
|
|
||||||
|
|
||||||
class OperationNotAllowed(BaseHttpException):
|
|
||||||
states_code = 403
|
|
||||||
detail = "403 Operation Is Not Allowed"
|
|
||||||
|
|
||||||
|
|
||||||
class InvalidPassword(BaseHttpException):
|
|
||||||
states_code = 403
|
|
||||||
message = "403 Invalid Password"
|
|
|
@ -12,7 +12,7 @@ class Following:
|
||||||
queue = asyncio.Queue()
|
queue = asyncio.Queue()
|
||||||
|
|
||||||
def __init__(self, kind, uid):
|
def __init__(self, kind, uid):
|
||||||
self.kind = kind # author topic shout chat
|
self.kind = kind # author topic shout community
|
||||||
self.uid = uid
|
self.uid = uid
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ class SearchService:
|
||||||
"limit": limit,
|
"limit": limit,
|
||||||
"offset": offset,
|
"offset": offset,
|
||||||
}
|
}
|
||||||
|
# FIXME: use elastic request here
|
||||||
payload = await load_shouts_by(None, None, options)
|
payload = await load_shouts_by(None, None, options)
|
||||||
await redis.execute("SET", text, json.dumps(payload))
|
await redis.execute("SET", text, json.dumps(payload))
|
||||||
return payload
|
return payload
|
||||||
|
|
|
@ -1,67 +0,0 @@
|
||||||
import sys
|
|
||||||
import uvicorn
|
|
||||||
from uvicorn.main import logger
|
|
||||||
|
|
||||||
from settings import PORT
|
|
||||||
|
|
||||||
log_settings = {
|
|
||||||
"version": 1,
|
|
||||||
"disable_existing_loggers": True,
|
|
||||||
"formatters": {
|
|
||||||
"default": {
|
|
||||||
"()": "uvicorn.logging.DefaultFormatter",
|
|
||||||
"fmt": "%(levelprefix)s %(message)s",
|
|
||||||
"use_colors": None,
|
|
||||||
},
|
|
||||||
"access": {
|
|
||||||
"()": "uvicorn.logging.AccessFormatter",
|
|
||||||
"fmt": '%(levelprefix)s %(client_addr)s - "%(request_line)s" %(status_code)s',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"handlers": {
|
|
||||||
"default": {
|
|
||||||
"formatter": "default",
|
|
||||||
"class": "logging.StreamHandler",
|
|
||||||
"stream": "ext://sys.stderr",
|
|
||||||
},
|
|
||||||
"access": {
|
|
||||||
"formatter": "access",
|
|
||||||
"class": "logging.StreamHandler",
|
|
||||||
"stream": "ext://sys.stdout",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"loggers": {
|
|
||||||
"uvicorn": {"handlers": ["default"], "level": "INFO"},
|
|
||||||
"uvicorn.error": {"level": "INFO", "handlers": ["default"], "propagate": True},
|
|
||||||
"uvicorn.access": {"handlers": ["access"], "level": "INFO", "propagate": False},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
local_headers = [
|
|
||||||
("Access-Control-Allow-Methods", "GET, POST, OPTIONS, HEAD"),
|
|
||||||
("Access-Control-Allow-Origin", "https://localhost:3000"),
|
|
||||||
(
|
|
||||||
"Access-Control-Allow-Headers",
|
|
||||||
"DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization",
|
|
||||||
),
|
|
||||||
("Access-Control-Expose-Headers", "Content-Length,Content-Range"),
|
|
||||||
("Access-Control-Allow-Credentials", "true"),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def exception_handler(_et, exc, _tb):
|
|
||||||
logger.error(..., exc_info=(type(exc), exc, exc.__traceback__))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
sys.excepthook = exception_handler
|
|
||||||
if "dev" in sys.argv:
|
|
||||||
import os
|
|
||||||
os.environ.set("MODE", "development")
|
|
||||||
uvicorn.run(
|
|
||||||
"main:app",
|
|
||||||
host="0.0.0.0",
|
|
||||||
port=PORT,
|
|
||||||
proxy_headers=True,
|
|
||||||
server_header=True
|
|
||||||
)
|
|
|
@ -1,14 +0,0 @@
|
||||||
from os import environ
|
|
||||||
|
|
||||||
PORT = 8080
|
|
||||||
DB_URL = (
|
|
||||||
environ.get("DATABASE_URL")
|
|
||||||
or environ.get("DB_URL")
|
|
||||||
or "postgresql://postgres@localhost:5432/discoursio"
|
|
||||||
)
|
|
||||||
REDIS_URL = environ.get("REDIS_URL") or "redis://127.0.0.1"
|
|
||||||
API_BASE = environ.get("API_BASE") or ""
|
|
||||||
AUTH_URL = environ.get("AUTH_URL") or ""
|
|
||||||
MODE = environ.get("MODE") or "production"
|
|
||||||
SENTRY_DSN = environ.get("SENTRY_DSN")
|
|
||||||
DEV_SERVER_PID_FILE_NAME = "dev-server.pid"
|
|
Loading…
Reference in New Issue
Block a user