mirror of
https://github.com/rommapp/romm.git
synced 2026-12-04 12:52:19 +01:00
42 lines
1.5 KiB
JavaScript
42 lines
1.5 KiB
JavaScript
import JSZip from "jszip"
|
|
import { toRaw } from "vue"
|
|
import { saveAs } from 'file-saver'
|
|
|
|
|
|
export async function downloadRom(rom, emitter, filesToDownload=[]) {
|
|
console.log("Downloading "+rom.file_name)
|
|
emitter.emit('snackbarScan', {'msg': "Downloading "+rom.file_name+"...", 'icon': 'mdi-download', 'color': 'green'})
|
|
if(rom.multi){
|
|
var files = []
|
|
toRaw(filesToDownload).forEach(f => {files.push(toRaw(f))})
|
|
var zipFilename = rom.file_name+".zip"
|
|
const zip = new JSZip()
|
|
var count = 0
|
|
if (files.length == 0){ files = rom.files }
|
|
files.forEach(async function (file_part) {
|
|
var file_full_path = "/assets"+rom.file_path+"/"+rom.file_name+"/"+file_part
|
|
console.log("downloading part: "+file_full_path)
|
|
var file = await fetch(file_full_path)
|
|
var fileBlob = await file.blob()
|
|
var f = zip.folder(rom.file_name);
|
|
f.file(file_part, fileBlob, { binary: true });
|
|
count ++
|
|
if (count == files.length) {
|
|
zip.generateAsync({ type: 'blob' }).then(function (content) {
|
|
saveAs(content, zipFilename);
|
|
});
|
|
}
|
|
})
|
|
}
|
|
else{
|
|
var file_full_path = "/assets"+rom.file_path+"/"+rom.file_name
|
|
var file = await fetch(file_full_path)
|
|
var fileBlob = await file.blob()
|
|
saveAs(fileBlob, rom.file_name)
|
|
}
|
|
}
|
|
|
|
export async function downloadSave(rom, emitter) {
|
|
console.log("Downloading "+rom.file_name+" save file")
|
|
}
|