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