convet webm to mp4 okay

This commit is contained in:
2025-10-02 12:13:14 +02:00
parent 11adfa3e21
commit db2a159eb5
3 changed files with 430 additions and 20 deletions
+58 -20
View File
@@ -12,7 +12,7 @@ import useMinuit from "react-native-minuit/src/hooks/useMinuit.js";
import { responsiveHeight } from "react-native-responsive-dimensions";
import { background, img } from "../../assets";
import MusicLandHeader from "../../components/MusicLandHeader";
import { projectsRef, serverTimestamp } from "../../config/firebase";
import firebase, { projectsRef, serverTimestamp } from "../../config/firebase";
import { uploadFileToFirebase } from "../../helpers/uploadToFirebase";
import Page from "../../layouts/Page";
import { Routes } from "../../navigation";
@@ -23,6 +23,31 @@ import { FONT_FAMILY } from "../../styles/Fonts";
import { size } from "../../styles/Style";
import CreateLyricsHeader from "../Writing/components/CreateLyricsHeader";
const guessExtension = (inputUri = "") => {
const cleaned = inputUri.split("?")[0] || "";
const match = cleaned.match(/\.([a-z0-9]+)$/i);
if (match && match[1]) return match[1].toLowerCase();
if (Platform.OS === "web") return "webm";
return "mp4";
};
const uploadSourceRecording = async ({ uri, uid, projectId }) => {
if (!uri) throw new Error("Aucune vidéo trouvée");
if (!uid) throw new Error("Utilisateur non authentifié");
const extension = guessExtension(uri);
const sourcePath = `users/${uid}/projects/${projectId}/recordings/source-${Date.now()}.${extension}`;
await uploadFileToFirebase({
uri,
path: sourcePath,
shouldCompress: false,
fileType: "VIDEO",
});
return { sourcePath };
};
const DownloadSongs = ({ route }) => {
const { currentUID } = useUserData();
const { action, uri, project } = route.params || {};
@@ -33,16 +58,30 @@ const DownloadSongs = ({ route }) => {
if (action === "playback" && project?.id) {
// Publication du playback
console.log("project id : ", project.id);
let tempSourcePath = null;
try {
setIsLoading(true);
const { resultURI = null } = await uploadFileToFirebase({
uri: uri,
path: `users/${currentUID}/projects/${project.id}/playback.mp4`,
shouldCompress: true,
fileType: "VIDEO",
const { sourcePath } = await uploadSourceRecording({
uri,
uid: currentUID,
projectId: project.id,
});
tempSourcePath = sourcePath;
const callable = firebase
.functions()
.httpsCallable("upload-uploadProjectMedia");
const { data: result } = await callable({
sourcePath,
projectId: project.id,
storagePath: `users/${currentUID}/projects/${project.id}/playback.mp4`,
projectField: "playbackUrl",
deleteSource: true,
metadata: { source: "downloadSongs" },
});
if (!resultURI) throw new Error("Téléversement de l'image impossible");
const resultURI = result?.url || null;
if (resultURI) {
await projectsRef.doc(project.id).set(
@@ -63,10 +102,15 @@ const DownloadSongs = ({ route }) => {
});
}
} catch (error) {
console.log("error upload playback", error);
console.log("[DownloadSongs] error upload playback", error);
if (tempSourcePath) {
try {
await firebase.storage().ref(tempSourcePath).delete();
} catch {}
}
setTooltip({
type: "error",
text: "Erreur lors de la publication du playback",
text: String(error?.message || "Erreur lors de la publication du playback"),
});
} finally {
setIsLoading(false);
@@ -109,17 +153,11 @@ const DownloadSongs = ({ route }) => {
<View style={{ gap: 10 }}>
<Pressable
style={styles.itemContainer}
onPress={
() => {
console.log("test");
handleDownloadUri();
}
// navigate(Routes.DownloadPrices, {
// action,
// uri,
// })
}
onPress={handleDownloadUri}
// navigate(Routes.DownloadPrices, {
// action,
// uri,
// })
>
<BlurView
style={styles.blurView}