完成书签的备份下载

This commit is contained in:
HelloWorld 2020-04-13 21:49:21 +08:00
parent 6636b698ff
commit e6af3742ac
3 changed files with 24 additions and 7 deletions

View File

@ -11,7 +11,7 @@ function md5(str) {
module.exports = class extends Base {
async __before() {
if (['userRegister', 'userLogin', 'noteShare'].indexOf(this.ctx.action) >= 0) {
if (['userRegister', 'userLogin', 'noteShare', 'bookmarkDownload'].indexOf(this.ctx.action) >= 0) {
return;
}
try {
@ -508,9 +508,26 @@ module.exports = class extends Base {
await fs.ensureFile(filePath);
await fs.writeFile(filePath, $.xml());
this.json({ code: 0, data: `runtime/backup/${fileName}` });
setTimeout(() => fs.remove(filePath), 10000);
// await this.download(filePath, fileName)
this.json({ code: 0, data: fileName });
setTimeout(async () => {
let exists = await fs.pathExists(filePath);
if (exists) {
await fs.remove(filePath);
}
}, 1000 * 60 * 10); // 十分钟内没下载就给删掉
}
async bookmarkDownloadAction() {
let fileName = this.get('fileName');
let filePath = path.join(think.ROOT_PATH, 'runtime', 'backup', fileName);
let exists = await fs.pathExists(filePath);
if (exists) {
await this.download(filePath);
await fs.remove(filePath);
} else {
this.body = "文件不存在!";
}
}
// 获取文章

View File

@ -113,8 +113,8 @@ app.controller('settingsCtr', ['$scope', '$stateParams', '$filter', '$state', '$
}
$scope.exportBookmark = async function () {
let data = await get('bookmarkBackup');
console.log(data);
let fileName = await get('bookmarkBackup');
$window.open(`${document.location.origin}/api/bookmarkDownload?fileName=${fileName}`, '_blank');
}
setTimeout(function () {