Browse Source

fix: chat_msg media_dir path — strip filename from g_cc.db_path

g_cc.db_path is '/data/.../files/chats.db' (file path), but media blocks
are written to '/data/.../files/media/<channel>/'. chat_msg was concatenating
'chats.db/media/...' — now strips the database filename, using only the
directory portion for the media path.
topo_upd
evgeny 2 months ago
parent
commit
39d6f19d97
  1. 9
      src/chat/chat_msg.c
  2. 7
      tools/chatgui-android/libutun_lite/voice_recorder.c

9
src/chat/chat_msg.c

@ -101,7 +101,16 @@ static void chat_core_submit_media_message(struct chat_msg_submit* req) {
if (!si) { DEBUG_ERROR(DEBUG_CATEGORY_DB_SYNC, "%s: no db_sync instance for ch=%s", CC_ID, req->channel_id); return; }
char media_dir[1024];
{
/* g_cc.db_path is a file path (e.g. /data/.../chats.db).
Extract directory portion for media path. */
const char* last_slash = strrchr(g_cc.db_path, '/');
if (last_slash)
snprintf(media_dir, sizeof(media_dir), "%.*s/media/%s",
(int)(last_slash - g_cc.db_path), g_cc.db_path, req->channel_id);
else
snprintf(media_dir, sizeof(media_dir), "%s/media/%s", g_cc.db_path, req->channel_id);
}
uint32_t num_blocks = req->media_num_blocks;
uint64_t block_size = 0;

7
tools/chatgui-android/libutun_lite/voice_recorder.c

@ -85,6 +85,7 @@ int voice_recorder_init(const char* db_path) {
DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "voice_recorder_init: db=%s preset=%d compressor=%d",
g_rec->db_path, g_rec->preset, g_rec->compressor_enabled);
debug_set_category_level(DEBUG_CATEGORY_GENERAL, DEBUG_LEVEL_INFO);
pthread_mutex_unlock(&g_init_mtx);
return 0;
}
@ -339,8 +340,8 @@ int voice_recorder_stop(int* out_duration_ms) {
opus_codec_encoder_destroy(enc);
float duration_sec = (float)frame_count * FRAME_MS / 1000.0f;
DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "voice_recorder_stop: %d frames (%.1fs) dur=%lldms compressor=%d",
frame_count, duration_sec, (long long)elapsed_ms, g_rec->compressor_enabled);
DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "voice_recorder_stop: wrote %d frames (%.1fs) dur=%lldms compressor=%d path=%s",
frame_count, duration_sec, (long long)elapsed_ms, g_rec->compressor_enabled, temp_path);
if (frame_count <= 0) {
unlink(temp_path);
@ -356,6 +357,8 @@ int voice_recorder_stop(int* out_duration_ms) {
uint32_t block_size = media_calc_block_size(file_size);
int num_blocks = (int)((file_size + block_size - 1) / block_size);
DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "voice_recorder_stop: file_size=%llu block_size=%u num_blocks=%d",
(unsigned long long)file_size, block_size, num_blocks);
/* split file into blocks */
FILE* src = fopen(temp_path, "rb");

Loading…
Cancel
Save