Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise(function(resolve){
const blob = new Blob([text]);
const fileUrl = URL.createObjectURL(blob);
const option = {filename: fileName, url: fileUrl};
// Firefox supported saveAs since version 52
if (utils.IS_CHROME || (!utils.IS_ANDROID && utils.FIREFOX_VERSION >= 52)) {
option.saveAs = true;
}
browser.downloads.download(option).then(resolve);
});
},
export default async function exportSessions(id = null) {
log.log(logDir, "exportSessions()", id);
let sessions = await getSessions(id);
if (sessions == undefined) return;
if (!Array.isArray(sessions)) sessions = [sessions];
const downloadUrl = URL.createObjectURL(
new Blob([JSON.stringify(sessions, null, " ")], {
type: "aplication/json"
})
);
const fileName = generateFileName(sessions);
await browser.downloads
.download({
url: downloadUrl,
filename: `${fileName}.json`,
conflictAction: "uniquify",
saveAs: true
})
.catch(e => {
log.warn(logDir, "exportSessions()", e);
});
}
export async function exportSessions(id = null) {
let sessions = await getSessions(id);
if (sessions == undefined) return;
if (!Array.isArray(sessions)) sessions = [sessions];
const downloadUrl = URL.createObjectURL(
new Blob([JSON.stringify(sessions, null, " ")], {
type: "aplication/json"
})
);
const fileName = returnFileName(sessions);
await browser.downloads
.download({
url: downloadUrl,
filename: `${fileName}.json`,
conflictAction: "uniquify",
saveAs: true
})
.catch(() => {});
}
export function openDownloadFolder() {
browser.downloads.showDefaultFolder();
}
}, (choseDownload) => {
if (choseDownload) {
browser.downloads.download({
filename: project.name + "-logs.md",
url: createBlob("text/markdown", markdown),
saveAs: true,
conflictAction: "overwrite"
});
}
});
return Promise.reject();
return exportProject(project).then(snapshot => {
if (snapshot) {
project.snapshot = snapshot
Object.assign(project, Manager.emitDependencies())
}
return browser.downloads.download({
filename: sanitizeProjectName(project.name) + '.side',
url: createBlob(
'application/json',
beautify(JSON.stringify(project), { indent_size: 2 })
),
saveAs: true,
conflictAction: 'overwrite',
})
})
}
const sessions = await Sessions.getAll().catch(() => {});
if (!getSettings("ifBackup")) return;
if (sessions.length == 0) return;
log.log(logDir, "backupSessions()");
const downloadUrl = URL.createObjectURL(
new Blob([JSON.stringify(sessions, null, " ")], {
type: "aplication/json"
})
);
const backupFolder = replaceBackupFolderName(getSettings("backupFolder"));
const fileName = returnFileName(sessions);
await browser.downloads.download({
url: downloadUrl,
filename: `${backupFolder}${backupFolder == "" ? "" : "/"}${fileName}.json`,
conflictAction: "uniquify",
saveAs: false
});
}