Fix #1385 issue with saving GIFs in web app

This commit is contained in:
JannisX11 2022-04-21 19:49:07 +02:00
parent 8e1a547320
commit 9adc6fc4f2

View File

@ -33,7 +33,7 @@ const Screencam = {
background,
play: formData.play,
turnspeed: formData.turn,
}, Screencam.returnScreenshot)
})
}
}),
screenshotPreview(preview, options, cb) {
@ -105,7 +105,7 @@ const Screencam = {
})
}, 40)
},
async returnScreenshot(dataUrl, cb) {
async returnScreenshot(dataUrl, cb, blob) {
if (cb) {
cb(dataUrl);
@ -160,7 +160,7 @@ const Screencam = {
type: tl('data.image'),
savetype: is_gif ? 'binary' : 'image',
name: Project.name.replace(/\.geo$/, ''),
content: is_gif ? Buffer(dataUrl.split(',')[1], 'base64') : dataUrl,
content: is_gif ? (isApp ? Buffer(dataUrl.split(',')[1], 'base64') : blob) : dataUrl,
})
}
}
@ -185,6 +185,7 @@ const Screencam = {
let recording = false;
let loop = null;
let crop = Screencam.gif_crop;
let has_finished;
function getProgress() {
switch (options.length_mode) {
@ -253,13 +254,16 @@ const Screencam = {
}, interval)
gif.on('finished', blob => {
if (has_finished) return;
has_finished = true;
var reader = new FileReader();
reader.onload = () => {
if (!options.silent) {
Blockbench.setProgress();
Blockbench.setStatusBarText();
}
Screencam.returnScreenshot(reader.result, cb);
Screencam.returnScreenshot(reader.result, cb, blob);
}
reader.readAsDataURL(blob);
});
@ -401,7 +405,6 @@ const Screencam = {
Blockbench.showQuickMessage('message.timelapse_start');
function saveImage(image) {
console.trace(image)
var path = `${options.destination}${osfs}${getFileName(index)}`;
fs.writeFile(path, image, (e, b) => {});