[FIX] Audio names not being handled properly (#4685)
This commit is contained in:
parent
5387d31a68
commit
41b54d6d87
|
@ -4,12 +4,17 @@ import { sanitizeLikeString } from '../database/utils';
|
||||||
import { store } from '../store/auxStore';
|
import { store } from '../store/auxStore';
|
||||||
import log from './helpers/log';
|
import log from './helpers/log';
|
||||||
|
|
||||||
|
const DEFAULT_EXTENSION = 'mp3';
|
||||||
|
|
||||||
const sanitizeString = (value: string) => sanitizeLikeString(value.substring(value.lastIndexOf('/') + 1));
|
const sanitizeString = (value: string) => sanitizeLikeString(value.substring(value.lastIndexOf('/') + 1));
|
||||||
|
|
||||||
const parseFilename = (value: string) => {
|
const getExtension = (value: string) => {
|
||||||
const extension = value.substring(value.lastIndexOf('.') + 1);
|
let extension = DEFAULT_EXTENSION;
|
||||||
const filename = sanitizeString(value.substring(value.lastIndexOf('/') + 1).split('.')[0]);
|
const filename = value.split('/').pop();
|
||||||
return `${filename}.${extension}`;
|
if (filename?.includes('.')) {
|
||||||
|
extension = value.substring(value.lastIndexOf('.') + 1);
|
||||||
|
}
|
||||||
|
return extension;
|
||||||
};
|
};
|
||||||
|
|
||||||
const ensureDirAsync = async (dir: string, intermediates = true): Promise<void> => {
|
const ensureDirAsync = async (dir: string, intermediates = true): Promise<void> => {
|
||||||
|
@ -27,7 +32,7 @@ export const downloadAudioFile = async (url: string, fileUrl: string, messageId:
|
||||||
const serverUrl = store.getState().server.server;
|
const serverUrl = store.getState().server.server;
|
||||||
const serverUrlParsed = sanitizeString(serverUrl);
|
const serverUrlParsed = sanitizeString(serverUrl);
|
||||||
const folderPath = `${FileSystem.documentDirectory}audios/${serverUrlParsed}`;
|
const folderPath = `${FileSystem.documentDirectory}audios/${serverUrlParsed}`;
|
||||||
const filename = `${messageId}_${parseFilename(fileUrl)}`;
|
const filename = `${messageId}.${getExtension(fileUrl)}`;
|
||||||
const filePath = `${folderPath}/${filename}`;
|
const filePath = `${folderPath}/${filename}`;
|
||||||
await ensureDirAsync(folderPath);
|
await ensureDirAsync(folderPath);
|
||||||
const file = await FileSystem.getInfoAsync(filePath);
|
const file = await FileSystem.getInfoAsync(filePath);
|
||||||
|
|
Loading…
Reference in New Issue