Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🕊 Some Small Edit.. #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import sys
import os

from dotenv import load_dotenv
load_dotenv("config.env")

try:
port = int(os.environ.get("PORT", "8080"))
port = int(os.environ.get("PORT", 8080))
except Exception as e:
print(e)
port = -1
Expand All @@ -27,8 +29,7 @@
sys.exit(1)

try:
index_settings_str = os.environ["INDEX_SETTINGS"].strip()
index_settings = json.loads(index_settings_str)
index_settings = json.load(open("index_settings.json"))
except Exception:
traceback.print_exc()
print("\n\nPlease set the INDEX_SETTINGS environment variable correctly")
Expand Down
2 changes: 1 addition & 1 deletion app/views/faviconicon_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
class FaviconIconView:
async def faviconicon(self, req):
favicon_path = logo_folder.joinpath("favicon.ico")
text = "T"
if not favicon_path.exists():
W, H = (360, 360)
color = tuple((random.randint(0, 255) for _ in range(3)))
im = Image.new("RGB", (W, H), color)
draw = ImageDraw.Draw(im)
font = ImageFont.truetype("arial.ttf", 50)
text = "T"
w, h = draw.textsize(text, font=font)
draw.text(((W - w) / 2, (H - h) / 2), text, fill="white", font=font)
im.save(favicon_path)
Expand Down
25 changes: 11 additions & 14 deletions app/views/info_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,17 @@ async def info(self, req):
"authenticated": req.app["is_authenticated"],
}
reply_btns = []
if message.reply_markup:
if isinstance(message.reply_markup, types.ReplyInlineMarkup):
reply_btns = [
[
{"url": button.url, "text": button.text}
for button in button_row.buttons
if isinstance(button, types.KeyboardButtonUrl)
]
for button_row in message.reply_markup.rows
if message.reply_markup and isinstance(
message.reply_markup, types.ReplyInlineMarkup
):
reply_btns = [
[
{"url": button.url, "text": button.text}
for button in button_row.buttons
if isinstance(button, types.KeyboardButtonUrl)
]
for button_row in message.reply_markup.rows
]

if message.file and not isinstance(message.media, types.MessageMediaWebPage):
file_name = get_file_name(message)
Expand All @@ -60,11 +61,7 @@ async def info(self, req):
elif "image/" in message.file.mime_type:
media["image"] = True

if message.text:
caption = message.raw_text
else:
caption = ""

caption = message.raw_text if message.text else ""
caption_html = Markup.escape(caption).__str__().replace("\n", "<br>")
return_val.update(
{
Expand Down
29 changes: 14 additions & 15 deletions app/views/middlewhere.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,29 @@ async def _do_cookies_auth_check(request):
def middleware_factory():
@middleware
async def factory(request, handler):
if request.app["is_authenticated"] and str(request.rel_url.path) not in [
if not request.app["is_authenticated"] or str(request.rel_url.path) in [
"/login",
"/logout",
"/favicon.ico",
]:
url = request.app.router["login_page"].url_for()
if str(request.rel_url) != "/":
url = url.with_query(redirect_to=str(request.rel_url))
return await handler(request)
url = request.app.router["login_page"].url_for()
if str(request.rel_url) != "/":
url = url.with_query(redirect_to=str(request.rel_url))

basic_auth_check_resp = _do_basic_auth_check(request)
basic_auth_check_resp = _do_basic_auth_check(request)

if basic_auth_check_resp is True:
return await handler(request)
if basic_auth_check_resp is True:
return await handler(request)

cookies_auth_check_resp = await _do_cookies_auth_check(request)
cookies_auth_check_resp = await _do_cookies_auth_check(request)

if cookies_auth_check_resp is not None:
return await handler(request)
if cookies_auth_check_resp is not None:
return await handler(request)

if isinstance(basic_auth_check_resp, Response):
return basic_auth_check_resp
if isinstance(basic_auth_check_resp, Response):
return basic_auth_check_resp

return HTTPFound(url)

return await handler(request)
return HTTPFound(url)

return factory
2 changes: 1 addition & 1 deletion app/views/thumbnail_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def thumbnail_get(self, req):
location = types.InputPhotoFileLocation

if not thumbnails:
color = tuple([random.randint(0, 255) for i in range(3)])
color = tuple(random.randint(0, 255) for _ in range(3))
im = Image.new("RGB", (100, 100), color)
temp = io.BytesIO()
im.save(temp, "PNG")
Expand Down
15 changes: 15 additions & 0 deletions config.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
API_ID = 1111111
API_HASH = "123123123"
SESSION_STRING = "alşsdaişdlaislşdaişsdlialşsdiaslşdşlasd"

HOST = "127.0.0.1"
PORT = "1453"

# DEBUG =
# BLOCK_DOWNLOADS =
# RESULTS_PER_PAGE =
# TGINDEX_USERNAME =
# PASSWORD =
# SHORT_URL_LEN =
# SESSION_COOKIE_LIFETIME =
# SECRET_KEY =
8 changes: 8 additions & 0 deletions index_settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"index_all": true,
"index_private": false,
"index_group": false,
"index_channel": true,
"exclude_chats": [],
"include_chats": []
}
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
aiohtt
aiohttp
aiohttp-jinja2
telethon
cryptg
pillow
aiohttp_session[secure]
python-dotenv
Flask
Werkzeug