fix convert service

This commit is contained in:
user 2025-04-26 13:13:47 +03:00
parent 2476d3b3b6
commit d2ff332490
1 changed files with 6 additions and 26 deletions

View File

@ -65,40 +65,20 @@ async def convert_loop(memory):
# Для прочих типов сохраняем raw копию и выходим # Для прочих типов сохраняем raw копию и выходим
if content_kind == "other": if content_kind == "other":
raw_hash = unprocessed_encrypted_content.hash make_log("ConvertProcess", f"Content {unprocessed_encrypted_content.id} processed. Converted content: {converted_content}", level="info")
raw_content = StoredContent(
type="local/content_raw",
hash=raw_hash,
user_id=unprocessed_encrypted_content.user_id,
filename=unprocessed_encrypted_content.filename,
meta={'source': 'raw_copy'},
created=datetime.now(),
)
session.add(raw_content)
session.commit()
# Копируем файл в UPLOADS_DIR
dst = os.path.join(UPLOADS_DIR, raw_hash)
try:
os.remove(dst)
except FileNotFoundError:
pass
shutil.copy2(input_file_path, dst)
# Обновляем оригинальный объект
unprocessed_encrypted_content.btfs_cid = ContentId( unprocessed_encrypted_content.btfs_cid = ContentId(
version=2, content_hash=b58decode(raw_hash) version=2, content_hash=b58decode(converted_content['high' if content_kind=='video' else 'low'])
).serialize_v2() ).serialize_v2()
unprocessed_encrypted_content.ipfs_cid = ContentId( unprocessed_encrypted_content.ipfs_cid = ContentId(
version=2, content_hash=b58decode(raw_hash) version=2, content_hash=b58decode(converted_content['low'])
).serialize_v2() ).serialize_v2()
unprocessed_encrypted_content.meta = { unprocessed_encrypted_content.meta = {
**unprocessed_encrypted_content.meta, **unprocessed_encrypted_content.meta,
'converted_content': {'raw': raw_hash} 'converted_content': {
option_name: decrypted_content.hash for option_name in ['high', 'low', 'low_preview']
}
} }
session.commit() session.commit()
make_log("ConvertProcess", f"Raw content saved for {raw_hash}", level="info")
return return
# ==== Конвертация для видео или аудио: оригинальная логика ==== # ==== Конвертация для видео или аудио: оригинальная логика ====