fix bug
This commit is contained in:
parent
5f4d90d410
commit
21a83cf5b8
|
|
@ -99,10 +99,11 @@ async def t_inline_query_node_content(query: types.InlineQuery, memory=None, use
|
||||||
content_list = []
|
content_list = []
|
||||||
content = db_session.query(StoredContent).filter_by(hash=cid.content_hash_b58).first()
|
content = db_session.query(StoredContent).filter_by(hash=cid.content_hash_b58).first()
|
||||||
content_prod = content.open_content(db_session)
|
content_prod = content.open_content(db_session)
|
||||||
|
# Get both encrypted and decrypted content objects
|
||||||
encrypted_content = content_prod['encrypted_content']
|
encrypted_content = content_prod['encrypted_content']
|
||||||
decrypted_content = content_prod['decrypted_content']
|
decrypted_content = content_prod['decrypted_content']
|
||||||
|
|
||||||
decrypted_content_meta = decrypted_content.json_format()
|
decrypted_content_meta = decrypted_content.json_format()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
metadata_content = StoredContent.from_cid(db_session, content.json_format()['metadata_cid'])
|
metadata_content = StoredContent.from_cid(db_session, content.json_format()['metadata_cid'])
|
||||||
with open(metadata_content.filepath, 'r') as f:
|
with open(metadata_content.filepath, 'r') as f:
|
||||||
|
|
@ -133,12 +134,12 @@ async def t_inline_query_node_content(query: types.InlineQuery, memory=None, use
|
||||||
if hashtags_str:
|
if hashtags_str:
|
||||||
hashtags_str = hashtags_str + '\n'
|
hashtags_str = hashtags_str + '\n'
|
||||||
|
|
||||||
# Check if a preview file_id is cached for audio/video and if not, upload a trimmed preview to cache it.
|
# Upload preview of decrypted content (limit to 30 seconds)
|
||||||
if content_type_declared in ('audio', 'video'):
|
if content_type_declared in ('audio', 'video'):
|
||||||
if True or not encrypted_content.meta.get('telegram_file_cache_preview'):
|
if True or not decrypted_content.meta.get('telegram_file_cache_preview'):
|
||||||
try:
|
try:
|
||||||
# Construct URL for trimmed preview (limit to 30 seconds)
|
# Construct URL for trimmed preview using decrypted content
|
||||||
preview_url = f"{PROJECT_HOST}/api/v1/storage/{content.cid.serialize_v2(include_accept_type=True)}?seconds_limit=30"
|
preview_url = f"{PROJECT_HOST}/api/v1/storage/{decrypted_content.cid.serialize_v2(include_accept_type=True)}?seconds_limit=30"
|
||||||
if content_type_declared == 'video':
|
if content_type_declared == 'video':
|
||||||
preview_message = await query.bot.send_video(
|
preview_message = await query.bot.send_video(
|
||||||
chat_id=CACHE_CHAT_ID, # Cache chat id defined in configuration
|
chat_id=CACHE_CHAT_ID, # Cache chat id defined in configuration
|
||||||
|
|
@ -154,20 +155,21 @@ async def t_inline_query_node_content(query: types.InlineQuery, memory=None, use
|
||||||
caption="Preview upload" # English caption
|
caption="Preview upload" # English caption
|
||||||
)
|
)
|
||||||
preview_file_id = preview_message.audio.file_id
|
preview_file_id = preview_message.audio.file_id
|
||||||
# Save the preview file_id in encrypted_content.meta for future use
|
# Save the preview file_id in decrypted_content.meta for future use
|
||||||
encrypted_content.meta = {
|
decrypted_content.meta = {
|
||||||
**encrypted_content.meta,
|
**decrypted_content.meta,
|
||||||
'telegram_file_cache_preview': preview_file_id
|
'telegram_file_cache_preview': preview_file_id
|
||||||
}
|
}
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
make_log("OwnedContent", f"Error uploading preview {content_type_declared}: {e}", level='error')
|
make_log("OwnedContent", f"Error uploading preview {content_type_declared}: {e}", level='error')
|
||||||
|
|
||||||
|
# Create inline query result using decrypted content's file_id
|
||||||
if content_type_declared == 'audio':
|
if content_type_declared == 'audio':
|
||||||
content_list.append(
|
content_list.append(
|
||||||
types.InlineQueryResultCachedAudio(
|
types.InlineQueryResultCachedAudio(
|
||||||
id=f"NC_{content.id}_{int(datetime.now().timestamp() // 60)}",
|
id=f"NC_{content.id}_{int(datetime.now().timestamp() // 60)}",
|
||||||
audio_file_id=encrypted_content.meta.get('telegram_file_cache_preview', encrypted_content.meta['telegram_file_cache']),
|
audio_file_id=decrypted_content.meta.get('telegram_file_cache_preview', decrypted_content.meta['telegram_file_cache']),
|
||||||
title=title,
|
title=title,
|
||||||
performer=performer,
|
performer=performer,
|
||||||
caption=hashtags_str + user.translated('p_playerContext_preview'),
|
caption=hashtags_str + user.translated('p_playerContext_preview'),
|
||||||
|
|
@ -192,11 +194,9 @@ async def t_inline_query_node_content(query: types.InlineQuery, memory=None, use
|
||||||
content_list.append(
|
content_list.append(
|
||||||
types.InlineQueryResultCachedVideo(
|
types.InlineQueryResultCachedVideo(
|
||||||
id=f"NC_{content.id}_{int(datetime.now().timestamp() // 60)}",
|
id=f"NC_{content.id}_{int(datetime.now().timestamp() // 60)}",
|
||||||
video_file_id=encrypted_content.meta.get('telegram_file_cache_preview', encrypted_content.meta['telegram_file_cache']),
|
video_file_id=decrypted_content.meta.get('telegram_file_cache_preview', decrypted_content.meta['telegram_file_cache']),
|
||||||
title=title,
|
title=title,
|
||||||
caption=hashtags_str + user.translated('p_playerContext_preview'),
|
caption=hashtags_str + user.translated('p_playerContext_preview'),
|
||||||
# mime_type="video/mp4",
|
|
||||||
# thumbnail_url='https://raw.githubusercontent.com/my-mirror/assets/refs/heads/main/video_icon.png',
|
|
||||||
parse_mode='html',
|
parse_mode='html',
|
||||||
reply_markup=get_inline_keyboard([
|
reply_markup=get_inline_keyboard([
|
||||||
[{
|
[{
|
||||||
|
|
@ -219,7 +219,6 @@ async def t_inline_query_node_content(query: types.InlineQuery, memory=None, use
|
||||||
return await query.answer([], cache_time=1)
|
return await query.answer([], cache_time=1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def t_chosen_inline_result_node_content(query: types.ChosenInlineResult, memory=None, user=None, db_session=None, chat_wrap=None, **extra):
|
async def t_chosen_inline_result_node_content(query: types.ChosenInlineResult, memory=None, user=None, db_session=None, chat_wrap=None, **extra):
|
||||||
make_log("OwnedContent", f"Chosen inline result: {query.result_id}", level='info')
|
make_log("OwnedContent", f"Chosen inline result: {query.result_id}", level='info')
|
||||||
# return await query.answer([])
|
# return await query.answer([])
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue