diff --git a/.gitignore b/.gitignore index 7198ba9..1d9b33c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ /out /Telegram_provider/dataBase.db /Telegram_provider/.env -/FileUploaderBot/.env \ No newline at end of file +/FileUploaderBot/.env +/.ruff_cache \ No newline at end of file diff --git a/Telegram_provider/main.py b/Telegram_provider/main.py index 2246a05..4f490a7 100644 --- a/Telegram_provider/main.py +++ b/Telegram_provider/main.py @@ -35,15 +35,15 @@ async def send_login_message(message: types.Message): builder = InlineKeyboardBuilder() builder.add(types.InlineKeyboardButton( text="Log in", - callback_data=f"log_login") + callback_data="log_login") ) builder.add(types.InlineKeyboardButton( text="Register", - callback_data=f"log_register") + callback_data="log_register") ) - await message.answer(f"_To access your files from any device, sign in. " + \ - "The files will be linked to your account and you will have full access to them._", + await message.answer("_To access your files from any device, sign in. " + \ + "The files will be linked to your account and you will have full access to them._", reply_markup=builder.as_markup(), parse_mode="Markdown") @@ -56,7 +56,7 @@ async def start(message: types.Message, state: FSMContext): await message.answer("*Attention! This bot is in open beta testing, so there may be significant bugs and errors in operation.\n*" + \ f"Current version: {version}", parse_mode="Markdown") await message.answer(f"Hello, {message.from_user.full_name}!\n" + \ - f"I am the Telegram provider of the fu.andcool.ru service. To get started, send me the file that needs to be uploaded.") + "I am the Telegram provider of the fu.andcool.ru service. To get started, send me the file that needs to be uploaded.") @dp.message(Command('account')) @@ -72,7 +72,7 @@ async def account(message: types.Message, state: FSMContext): builder = InlineKeyboardBuilder() builder.add(types.InlineKeyboardButton( text="Log out", - callback_data=f"logout") + callback_data="logout") ) await message.answer(f"Logged in as **{user_obj.username}**\n", @@ -87,7 +87,7 @@ async def account(message: types.Message, state: FSMContext): @dp.callback_query(F.data.startswith("log_")) async def log(callback: types.CallbackQuery, state: FSMContext): await callback.message.delete() - message = await callback.message.answer(f"OK, now send me the data from your account in the format:\n```\nMy cool username\nMy cool password```", + message = await callback.message.answer("OK, now send me the data from your account in the format:\n```\nMy cool username\nMy cool password```", parse_mode="Markdown") await state.set_state(States.wait_to_data) await state.update_data(login_register=callback.data.replace("log_", "")) @@ -126,7 +126,7 @@ async def log_reg(message: types.Message, state: FSMContext): @dp.callback_query(F.data == "logout") -async def log(callback: types.CallbackQuery, state: FSMContext): +async def logout(callback: types.CallbackQuery, state: FSMContext): user_db = await db.user.find_first(where={"user_id": callback.from_user.id}) if not user_db: await callback.message.answer("You are not logged in") @@ -204,7 +204,7 @@ async def send_file(message: types.Message, state: FSMContext): file = await bot.get_file(file_id) bio = io.BytesIO() - filename = f"voice.mp3" + filename = "voice.mp3" file_bytes = await bot.download(file_id, destination=bio) bio.seek(0) @@ -246,7 +246,7 @@ async def delete_file(callback: types.CallbackQuery, state: FSMContext): except Exception as e: await callback.message.edit_text("❌Delete error: " + str(e)) -async def start(): +async def start_bot(): """Асинхронная функция для запуска диспатчера""" await db.connect() # Connecting to database @@ -264,4 +264,4 @@ async def start(): if __name__ == '__main__': - asyncio.run(start()) + asyncio.run(start_bot()) diff --git a/config.py b/config.py index d941dfc..ad01d0b 100644 --- a/config.py +++ b/config.py @@ -4,7 +4,6 @@ "aac": "audio/aac", "mp3": "audio/mpeg", - "mpeg": "audio/mpeg", "ogg": "audio/ogg", "gif": "image/gif", diff --git a/imports.py b/imports.py deleted file mode 100644 index b69d962..0000000 --- a/imports.py +++ /dev/null @@ -1,24 +0,0 @@ -from fastapi import FastAPI, UploadFile, Request, Header -from fastapi.responses import JSONResponse, FileResponse, Response -from typing import Annotated, Union -import uvicorn -from config import * -import aiohttp -import utils -from slowapi.errors import RateLimitExceeded -from slowapi import Limiter, _rate_limit_exceeded_handler -from slowapi.util import get_remote_address -from fastapi.middleware.cors import CORSMiddleware -import time -import aiofiles -from prisma import Prisma -import uuid -import os -from datetime import datetime -from dotenv import load_dotenv -import jwt -import bcrypt -import random -import json - -rate_limit_exceeded_handler = _rate_limit_exceeded_handler diff --git a/main.py b/main.py index 754ed01..60e3783 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,28 @@ created by AndcoolSystems, 2023-2024 """ -from imports import * +from fastapi import FastAPI, UploadFile, Request, Header +from fastapi.responses import JSONResponse, FileResponse, Response +from typing import Annotated, Union +import uvicorn +from config import filetypes, default, accessLifeTime, accessLifeTimeBot +import aiohttp +import utils +from slowapi.errors import RateLimitExceeded +from slowapi import Limiter, _rate_limit_exceeded_handler +from slowapi.util import get_remote_address +from fastapi.middleware.cors import CORSMiddleware +import time +import aiofiles +from prisma import Prisma +import uuid +import os +from datetime import datetime +from dotenv import load_dotenv +import jwt +import bcrypt +import random +import json def custom_key_func(request: Request): @@ -28,7 +49,7 @@ def dynamic_limit_provider_upload(key: str): db = Prisma() load_dotenv() app.state.limiter = limiter -app.add_exception_handler(RateLimitExceeded, rate_limit_exceeded_handler) +app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler) app.add_middleware( # Disable CORS CORSMiddleware, @@ -483,7 +504,7 @@ async def login_token(request: Request, @app.post("/api/login/discord/{code}") # login handler @limiter.limit(dynamic_limit_provider) -async def login(code: str, +async def login_discord(code: str, request: Request, user_agent: Union[str, None] = Header(default=None)): @@ -500,7 +521,7 @@ async def login(code: str, response_json = {} async with aiohttp.ClientSession() as session: - async with session.post(f'https://discord.com/api/v10/oauth2/token', data=data, headers=headers, auth=auth) as response: + async with session.post('https://discord.com/api/v10/oauth2/token', data=data, headers=headers, auth=auth) as response: response_json = await response.json() if response.status != 200: return JSONResponse({"status": "error", "message": "Internal error, please, log in again"}, status_code=401) @@ -732,7 +753,7 @@ async def transfer( try: body = await request.json() - except: + except Exception: return JSONResponse( content={"status": "error", "message": "Couldn't parse request body"}, status_code=400, @@ -755,7 +776,7 @@ async def transfer( await db.file.update( where={"id": file.id}, data={"user_id": token_db.user_id} ) - except: + except Exception: non_success.append(requested_file) return {"status": "success", "message": "transfered", "unsuccess": non_success} @@ -903,7 +924,7 @@ async def generate_invite( @app.post("/api/join/{invite_link}") # join handler @limiter.limit(dynamic_limit_provider) -async def delete_group( +async def join_group( invite_link: str, request: Request, Authorization: Annotated[Union[str, None], Header(convert_underscores=False)] = None, @@ -959,7 +980,7 @@ async def delete_group( @app.get("/api/invite_info/{invite_link}") # invite info handler @limiter.limit(dynamic_limit_provider) -async def delete_group( +async def invite_link( invite_link: str, request: Request, Authorization: Annotated[Union[str, None], Header(convert_underscores=False)] = None, @@ -995,7 +1016,7 @@ async def delete_group( @app.post("/api/leave/{group_id}") # leave handler @limiter.limit(dynamic_limit_provider) -async def delete_group( +async def leave_group( group_id: int, request: Request, Authorization: Annotated[Union[str, None], Header(convert_underscores=False)] = None, diff --git a/web/uploaders/index.html b/web/uploaders/index.html index 8a873bc..5b816e7 100644 --- a/web/uploaders/index.html +++ b/web/uploaders/index.html @@ -24,8 +24,8 @@

File uploader


by AndcoolSystems

Bots

-

Discord

-

Telegram

+

Discord bot by kwixie_

+

Telegram bot

ShareX

Click here to download the ShareX config