Spaces:
Running
Running
Fyaz Mohammed commited on
Commit ·
1b3eebd
1
Parent(s): e7261d3
patch 1
Browse files- AGENTS.md +1 -1
- Thunder/__main__.py +5 -1
- Thunder/bot/plugins/stream.py +6 -4
- Thunder/server/stream_routes.py +2 -2
- Thunder/template/req.html +5 -5
- Thunder/utils/canonical_files.py +2 -2
AGENTS.md
CHANGED
|
@@ -18,7 +18,7 @@ pip install -r requirements.txt
|
|
| 18 |
|
| 19 |
## Project Structure
|
| 20 |
|
| 21 |
-
```
|
| 22 |
Thunder/
|
| 23 |
├── __init__.py # __version__, StartTime
|
| 24 |
├── __main__.py # Entry: start_services() via asyncio
|
|
|
|
| 18 |
|
| 19 |
## Project Structure
|
| 20 |
|
| 21 |
+
```text
|
| 22 |
Thunder/
|
| 23 |
├── __init__.py # __version__, StartTime
|
| 24 |
├── __main__.py # Entry: start_services() via asyncio
|
Thunder/__main__.py
CHANGED
|
@@ -239,6 +239,10 @@ async def start_services():
|
|
| 239 |
await rate_limiter.shutdown()
|
| 240 |
except Exception:
|
| 241 |
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
try:
|
| 243 |
await drain_background_touch_tasks()
|
| 244 |
except Exception as e:
|
|
@@ -298,7 +302,7 @@ async def start_services():
|
|
| 298 |
await db.close()
|
| 299 |
print(" ✓ Database connection closed")
|
| 300 |
except Exception as e:
|
| 301 |
-
logger.error(
|
| 302 |
|
| 303 |
|
| 304 |
async def schedule_token_cleanup():
|
|
|
|
| 239 |
await rate_limiter.shutdown()
|
| 240 |
except Exception:
|
| 241 |
pass
|
| 242 |
+
try:
|
| 243 |
+
await db.close()
|
| 244 |
+
except Exception as e:
|
| 245 |
+
logger.error(f"Error during database cleanup: {e}", exc_info=True)
|
| 246 |
try:
|
| 247 |
await drain_background_touch_tasks()
|
| 248 |
except Exception as e:
|
|
|
|
| 302 |
await db.close()
|
| 303 |
print(" ✓ Database connection closed")
|
| 304 |
except Exception as e:
|
| 305 |
+
logger.error("Error during database cleanup", exc_info=True)
|
| 306 |
|
| 307 |
|
| 308 |
async def schedule_token_cleanup():
|
Thunder/bot/plugins/stream.py
CHANGED
|
@@ -467,9 +467,9 @@ async def process_single(
|
|
| 467 |
return None
|
| 468 |
links = await gen_links(stored_msg, shortener=shortener_val)
|
| 469 |
canonical_reply_id = stored_msg.id
|
| 470 |
-
if notification_msg:
|
| 471 |
-
await safe_edit_message(
|
| 472 |
-
notification_msg,
|
| 473 |
MSG_LINKS.format(
|
| 474 |
file_name=links['media_name'],
|
| 475 |
file_size=links['media_size'],
|
|
@@ -480,7 +480,9 @@ async def process_single(
|
|
| 480 |
disable_web_page_preview=True,
|
| 481 |
reply_markup=get_link_buttons(links)
|
| 482 |
)
|
| 483 |
-
|
|
|
|
|
|
|
| 484 |
await send_link(msg, links)
|
| 485 |
if msg.chat.type != enums.ChatType.PRIVATE and msg.from_user and not original_request_msg:
|
| 486 |
await send_dm_links(bot, msg.from_user.id, links, msg.chat.title or "the chat")
|
|
|
|
| 467 |
return None
|
| 468 |
links = await gen_links(stored_msg, shortener=shortener_val)
|
| 469 |
canonical_reply_id = stored_msg.id
|
| 470 |
+
if notification_msg:
|
| 471 |
+
result = await safe_edit_message(
|
| 472 |
+
notification_msg,
|
| 473 |
MSG_LINKS.format(
|
| 474 |
file_name=links['media_name'],
|
| 475 |
file_size=links['media_size'],
|
|
|
|
| 480 |
disable_web_page_preview=True,
|
| 481 |
reply_markup=get_link_buttons(links)
|
| 482 |
)
|
| 483 |
+
if not result:
|
| 484 |
+
await send_link(msg, links)
|
| 485 |
+
elif not original_request_msg:
|
| 486 |
await send_link(msg, links)
|
| 487 |
if msg.chat.type != enums.ChatType.PRIVATE and msg.from_user and not original_request_msg:
|
| 488 |
await send_dm_links(bot, msg.from_user.id, links, msg.chat.title or "the chat")
|
Thunder/server/stream_routes.py
CHANGED
|
@@ -28,7 +28,7 @@ routes = web.RouteTableDef()
|
|
| 28 |
SECURE_HASH_LENGTH = 6
|
| 29 |
CHUNK_SIZE = 1024 * 1024
|
| 30 |
MAX_CONCURRENT_PER_CLIENT = 8
|
| 31 |
-
RANGE_REGEX = re.compile(r"bytes=(?P<start>\d*)-(?P<end>\d*)")
|
| 32 |
PATTERN_HASH_FIRST = re.compile(
|
| 33 |
rf"^([a-zA-Z0-9_-]{{{SECURE_HASH_LENGTH}}})(\d+)(?:/.*)?$")
|
| 34 |
PATTERN_ID_FIRST = re.compile(r"^(\d+)(?:/.*)?$")
|
|
@@ -116,7 +116,7 @@ def parse_range_header(range_header: str, file_size: int) -> tuple[int, int]:
|
|
| 116 |
if not range_header:
|
| 117 |
return 0, file_size - 1
|
| 118 |
|
| 119 |
-
match = RANGE_REGEX.
|
| 120 |
if not match:
|
| 121 |
raise web.HTTPBadRequest(text=f"Invalid range header: {range_header}")
|
| 122 |
|
|
|
|
| 28 |
SECURE_HASH_LENGTH = 6
|
| 29 |
CHUNK_SIZE = 1024 * 1024
|
| 30 |
MAX_CONCURRENT_PER_CLIENT = 8
|
| 31 |
+
RANGE_REGEX = re.compile(r"^bytes=(?P<start>\d*)-(?P<end>\d*)$")
|
| 32 |
PATTERN_HASH_FIRST = re.compile(
|
| 33 |
rf"^([a-zA-Z0-9_-]{{{SECURE_HASH_LENGTH}}})(\d+)(?:/.*)?$")
|
| 34 |
PATTERN_ID_FIRST = re.compile(r"^(\d+)(?:/.*)?$")
|
|
|
|
| 116 |
if not range_header:
|
| 117 |
return 0, file_size - 1
|
| 118 |
|
| 119 |
+
match = RANGE_REGEX.fullmatch(range_header)
|
| 120 |
if not match:
|
| 121 |
raise web.HTTPBadRequest(text=f"Invalid range header: {range_header}")
|
| 122 |
|
Thunder/template/req.html
CHANGED
|
@@ -162,14 +162,14 @@
|
|
| 162 |
</svg>
|
| 163 |
VLC
|
| 164 |
</a>
|
| 165 |
-
<a href="intent:{{ src|safe }}#Intent;action=android.intent.action.VIEW;type=video/*;package=com.mxtech.videoplayer.ad;S.title={{ file_name }};end"
|
| 166 |
class="player-link">
|
| 167 |
<svg viewBox="0 0 24 24">
|
| 168 |
<circle cx="12" cy="12" r="10" />
|
| 169 |
</svg>
|
| 170 |
MX Player
|
| 171 |
</a>
|
| 172 |
-
<a href="intent:{{ src|safe }}#Intent;action=android.intent.action.VIEW;type=video/*;package=com.mxtech.videoplayer.pro;S.title={{ file_name }};end"
|
| 173 |
class="player-link">
|
| 174 |
<svg viewBox="0 0 24 24">
|
| 175 |
<circle cx="12" cy="12" r="10" />
|
|
@@ -183,21 +183,21 @@
|
|
| 183 |
</svg>
|
| 184 |
Splayer
|
| 185 |
</a>
|
| 186 |
-
<a href="intent:{{ src|safe }}#Intent;action=android.intent.action.VIEW;type=video/*;package=dev.anilbeesetti.nextplayer;S.title={{ file_name }};end"
|
| 187 |
class="player-link">
|
| 188 |
<svg viewBox="0 0 24 24">
|
| 189 |
<circle cx="12" cy="12" r="10" />
|
| 190 |
</svg>
|
| 191 |
Next Player
|
| 192 |
</a>
|
| 193 |
-
<a href="intent:{{ src|safe }}#Intent;action=android.intent.action.VIEW;type=video/*;package=org.courville.nova;S.title={{ file_name }};end"
|
| 194 |
class="player-link">
|
| 195 |
<svg viewBox="0 0 24 24">
|
| 196 |
<circle cx="12" cy="12" r="10" />
|
| 197 |
</svg>
|
| 198 |
Nova Player
|
| 199 |
</a>
|
| 200 |
-
<a href="intent:{{ src|safe }}#Intent;action=android.intent.action.VIEW;type=video/*;package=is.xyz.mpv;S.title={{ file_name }};end"
|
| 201 |
class="player-link">
|
| 202 |
<svg viewBox="0 0 24 24">
|
| 203 |
<circle cx="12" cy="12" r="10" />
|
|
|
|
| 162 |
</svg>
|
| 163 |
VLC
|
| 164 |
</a>
|
| 165 |
+
<a href="intent:{{ src|safe }}#Intent;action=android.intent.action.VIEW;type=video/*;package=com.mxtech.videoplayer.ad;S.title={{ file_name | urlencode }};end"
|
| 166 |
class="player-link">
|
| 167 |
<svg viewBox="0 0 24 24">
|
| 168 |
<circle cx="12" cy="12" r="10" />
|
| 169 |
</svg>
|
| 170 |
MX Player
|
| 171 |
</a>
|
| 172 |
+
<a href="intent:{{ src|safe }}#Intent;action=android.intent.action.VIEW;type=video/*;package=com.mxtech.videoplayer.pro;S.title={{ file_name | urlencode }};end"
|
| 173 |
class="player-link">
|
| 174 |
<svg viewBox="0 0 24 24">
|
| 175 |
<circle cx="12" cy="12" r="10" />
|
|
|
|
| 183 |
</svg>
|
| 184 |
Splayer
|
| 185 |
</a>
|
| 186 |
+
<a href="intent:{{ src|safe }}#Intent;action=android.intent.action.VIEW;type=video/*;package=dev.anilbeesetti.nextplayer;S.title={{ file_name | urlencode }};end"
|
| 187 |
class="player-link">
|
| 188 |
<svg viewBox="0 0 24 24">
|
| 189 |
<circle cx="12" cy="12" r="10" />
|
| 190 |
</svg>
|
| 191 |
Next Player
|
| 192 |
</a>
|
| 193 |
+
<a href="intent:{{ src|safe }}#Intent;action=android.intent.action.VIEW;type=video/*;package=org.courville.nova;S.title={{ file_name | urlencode }};end"
|
| 194 |
class="player-link">
|
| 195 |
<svg viewBox="0 0 24 24">
|
| 196 |
<circle cx="12" cy="12" r="10" />
|
| 197 |
</svg>
|
| 198 |
Nova Player
|
| 199 |
</a>
|
| 200 |
+
<a href="intent:{{ src|safe }}#Intent;action=android.intent.action.VIEW;type=video/*;package=is.xyz.mpv;S.title={{ file_name | urlencode }};end"
|
| 201 |
class="player-link">
|
| 202 |
<svg viewBox="0 0 24 24">
|
| 203 |
<circle cx="12" cy="12" r="10" />
|
Thunder/utils/canonical_files.py
CHANGED
|
@@ -448,8 +448,8 @@ async def get_or_create_canonical_file(
|
|
| 448 |
if stored_message:
|
| 449 |
try:
|
| 450 |
await stored_message.delete()
|
| 451 |
-
except Exception:
|
| 452 |
-
|
| 453 |
raise
|
| 454 |
except FloodWait:
|
| 455 |
raise
|
|
|
|
| 448 |
if stored_message:
|
| 449 |
try:
|
| 450 |
await stored_message.delete()
|
| 451 |
+
except Exception as e:
|
| 452 |
+
logger.warning(f"Failed to delete stored message {stored_message.id} in BIN_CHANNEL: {e}", exc_info=True)
|
| 453 |
raise
|
| 454 |
except FloodWait:
|
| 455 |
raise
|