more fixes web + mobile
This commit is contained in:
@@ -28,6 +28,32 @@ import { Palette } from "../../styles";
|
||||
import { FONT_FAMILY } from "../../styles/Fonts";
|
||||
import { size } from "../../styles/Style";
|
||||
import CreateLyricsHeader from "../Writing/components/CreateLyricsHeader";
|
||||
import { getBlobForUrl, releaseBlobUrl } from "../../utils/blobUrlCache";
|
||||
|
||||
const triggerWebDownload = (url, title) => {
|
||||
if (Platform.OS !== "web") return;
|
||||
if (!url) return;
|
||||
if (typeof document === "undefined") return;
|
||||
const baseName = (title || "Playback").toString().trim() || "Playback";
|
||||
const sanitized = baseName.replace(/[\\/:*?"<>|]/g, "-");
|
||||
const filename = `${sanitized}.mp4`;
|
||||
try {
|
||||
const anchor = document.createElement("a");
|
||||
anchor.href = url;
|
||||
anchor.download = filename;
|
||||
anchor.rel = "noopener noreferrer";
|
||||
document.body.appendChild(anchor);
|
||||
anchor.click();
|
||||
document.body.removeChild(anchor);
|
||||
} catch (error) {
|
||||
console.log("[DownloadSongs] web download fallback", {
|
||||
message: error?.message,
|
||||
});
|
||||
try {
|
||||
window.open(url, "_blank", "noopener,noreferrer");
|
||||
} catch {}
|
||||
}
|
||||
};
|
||||
|
||||
const guessExtension = (inputUri = "") => {
|
||||
const cleaned = inputUri.split("?")[0] || "";
|
||||
@@ -55,11 +81,17 @@ const uploadSourceRecording = async ({ uri, uid, projectId }) => {
|
||||
sourcePath,
|
||||
});
|
||||
|
||||
const cachedBlob = getBlobForUrl(uri);
|
||||
console.log("[DownloadSongs] uploadSourceRecording blob cache", {
|
||||
hasBlob: Boolean(cachedBlob),
|
||||
});
|
||||
|
||||
const { resultURI: videoUrl } = await uploadFileToFirebase({
|
||||
uri,
|
||||
path: sourcePath,
|
||||
shouldCompress: false,
|
||||
fileType: "VIDEO",
|
||||
blob: cachedBlob || undefined,
|
||||
});
|
||||
|
||||
return { sourcePath, videoUrl };
|
||||
@@ -97,6 +129,12 @@ const DownloadSongs = ({ route }) => {
|
||||
setIsAfterPlaybackVideoVisible(true);
|
||||
}, [action, afterPlaybackUrl]);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
releaseBlobUrl(uri || null);
|
||||
};
|
||||
}, [uri]);
|
||||
|
||||
const handleDownloadUri = async () => {
|
||||
if (action === "playback" && project?.id) {
|
||||
// Publication du playback
|
||||
@@ -128,6 +166,7 @@ const DownloadSongs = ({ route }) => {
|
||||
.httpsCallable("upload-mergeVideoAndAudio");
|
||||
|
||||
const payload = {
|
||||
projectId: project?.id,
|
||||
videoUrl,
|
||||
audioUrl,
|
||||
storagePath: `users/${currentUID}/projects/${project.id}/playback.mp4`,
|
||||
@@ -156,6 +195,7 @@ const DownloadSongs = ({ route }) => {
|
||||
type: "success",
|
||||
text: "Vidéo uploadée",
|
||||
});
|
||||
triggerWebDownload(resultURI, project?.title);
|
||||
if (tempSourcePath) {
|
||||
try {
|
||||
await firebase.storage().ref(tempSourcePath).delete();
|
||||
@@ -191,6 +231,7 @@ const DownloadSongs = ({ route }) => {
|
||||
),
|
||||
});
|
||||
} finally {
|
||||
releaseBlobUrl(uri || null);
|
||||
setIsLoading(false);
|
||||
}
|
||||
// Handle playback download
|
||||
|
||||
Reference in New Issue
Block a user