few changes
This commit is contained in:
parent
b73f31558c
commit
b699c2b695
|
@ -6,3 +6,4 @@ venv/
|
|||
logo/
|
||||
app.json
|
||||
Procfile
|
||||
.vscode
|
|
@ -1,4 +1,5 @@
|
|||
from pathlib import Path
|
||||
import platform
|
||||
import traceback
|
||||
import json
|
||||
import sys
|
||||
|
@ -10,7 +11,9 @@ try:
|
|||
except ValueError:
|
||||
port = -1
|
||||
if not 1 <= port <= 65535:
|
||||
print("Please make sure the PORT environment variable is an integer between 1 and 65535")
|
||||
print(
|
||||
"Please make sure the PORT environment variable is an integer between 1 and 65535"
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
|
@ -41,5 +44,7 @@ host = os.environ.get("HOST", "0.0.0.0")
|
|||
debug = bool(os.environ.get("DEBUG"))
|
||||
block_downloads = bool(os.environ.get("BLOCK_DOWNLOADS"))
|
||||
results_per_page = int(os.environ.get("RESULTS_PER_PAGE", "20"))
|
||||
logo_folder = Path('logo/')
|
||||
logo_folder = Path(
|
||||
"/Temp/logo/" if platform.system() == 'Windows' else '/tmp/logo'
|
||||
)
|
||||
logo_folder.mkdir(exist_ok=True)
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import random
|
||||
import string
|
||||
import logging
|
||||
|
||||
from aiohttp import web
|
||||
|
@ -14,17 +12,17 @@ log = logging.getLogger(__name__)
|
|||
async def setup_routes(app, handler):
|
||||
h = handler
|
||||
client = h.client
|
||||
index_all = index_settings['index_all']
|
||||
index_private = index_settings['index_private']
|
||||
index_group = index_settings['index_group']
|
||||
index_channel = index_settings['index_channel']
|
||||
exclude_chats = index_settings['exclude_chats']
|
||||
include_chats = index_settings['include_chats']
|
||||
routes = [
|
||||
web.get('/', h.home)
|
||||
]
|
||||
index_all = index_settings["index_all"]
|
||||
index_private = index_settings["index_private"]
|
||||
index_group = index_settings["index_group"]
|
||||
index_channel = index_settings["index_channel"]
|
||||
exclude_chats = index_settings["exclude_chats"]
|
||||
include_chats = index_settings["include_chats"]
|
||||
routes = [web.get("/", h.home)]
|
||||
if index_all:
|
||||
#print(await client.get_dialogs())
|
||||
# print(await client.get_dialogs())
|
||||
# dialogs = await client.get_dialogs()
|
||||
# for chat in dialogs:
|
||||
async for chat in client.iter_dialogs():
|
||||
alias_id = None
|
||||
if chat.id in exclude_chats:
|
||||
|
@ -33,25 +31,27 @@ async def setup_routes(app, handler):
|
|||
entity = chat.entity
|
||||
|
||||
if isinstance(entity, User) and not index_private:
|
||||
print(f'{chat.title}, private: {index_private}')
|
||||
log.debug(f"{chat.title}, private: {index_private}")
|
||||
continue
|
||||
elif isinstance(entity, Channel) and not index_channel:
|
||||
print(f'{chat.title}, channel: {index_channel}')
|
||||
log.debug(f"{chat.title}, channel: {index_channel}")
|
||||
continue
|
||||
elif isinstance(entity, Chat) and not index_group:
|
||||
print(f'{chat.title}, group: {index_group}')
|
||||
log.debug(f"{chat.title}, group: {index_group}")
|
||||
continue
|
||||
|
||||
alias_id = h.generate_alias_id(chat)
|
||||
p = "/{chat:" + alias_id + "}"
|
||||
routes.extend([
|
||||
web.get(p, h.index),
|
||||
web.get(p + r"/logo", h.logo),
|
||||
web.get(p + r"/{id:\d+}/view", h.info),
|
||||
web.get(p + r"/{id:\d+}/download", h.download_get),
|
||||
web.head(p + r"/{id:\d+}/download", h.download_head),
|
||||
web.get(p + r"/{id:\d+}/thumbnail", h.thumbnail_get),
|
||||
])
|
||||
routes.extend(
|
||||
[
|
||||
web.get(p, h.index),
|
||||
web.get(p + r"/logo", h.logo),
|
||||
web.get(p + r"/{id:\d+}/view", h.info),
|
||||
web.get(p + r"/{id:\d+}/download", h.download_get),
|
||||
web.head(p + r"/{id:\d+}/download", h.download_head),
|
||||
web.get(p + r"/{id:\d+}/thumbnail", h.thumbnail_get),
|
||||
]
|
||||
)
|
||||
log.debug(f"Index added for {chat.id} at /{alias_id}")
|
||||
|
||||
else:
|
||||
|
@ -59,14 +59,16 @@ async def setup_routes(app, handler):
|
|||
chat = await client.get_entity(chat_id)
|
||||
alias_id = h.generate_alias_id(chat)
|
||||
p = "/{chat:" + alias_id + "}"
|
||||
routes.extend([
|
||||
web.get(p, h.index),
|
||||
web.get(p + r"/logo", h.logo),
|
||||
web.get(p + r"/{id:\d+}/view", h.info),
|
||||
web.get(p + r"/{id:\d+}/download", h.download_get),
|
||||
web.head(p + r"/{id:\d+}/download", h.download_head),
|
||||
web.get(p + r"/{id:\d+}/thumbnail", h.thumbnail_get),
|
||||
])
|
||||
routes.extend(
|
||||
[
|
||||
web.get(p, h.index),
|
||||
web.get(p + r"/logo", h.logo),
|
||||
web.get(p + r"/{id:\d+}/view", h.info),
|
||||
web.get(p + r"/{id:\d+}/download", h.download_get),
|
||||
web.head(p + r"/{id:\d+}/download", h.download_head),
|
||||
web.get(p + r"/{id:\d+}/thumbnail", h.thumbnail_get),
|
||||
]
|
||||
)
|
||||
log.debug(f"Index added for {chat.id} at /{alias_id}")
|
||||
routes.append(web.view(r'/{wildcard:.*}', h.wildcard))
|
||||
routes.append(web.view(r"/{wildcard:.*}", h.wildcard))
|
||||
app.add_routes(routes)
|
||||
|
|
Loading…
Reference in New Issue