完成书签的备份下载

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

@ -108,7 +108,7 @@ GRANT ALL ON *.* TO 'test'@'%'; // 给刚创建的test用户数据库所有的
use mybookmarks; //选择刚创建的数据库。
source /home/lcq/schema.sql; // 执行schema.sql文件创建数据库表格。注意将路径换为你schema.sql所在路径。
```
3、如果你是全新部署你可忽略此步骤。如果之前部署过此应用那么需要执行update.sql文件需要升级。注意升级之前请务必备份数据库确认是否需要运行此升级sql文件也很简单看一下你之前的数据库mybookmarks下面有没有`tags_bookmarks`这个数据表。如果有,那么需要执行。执行方法还是如上类似`source /home/lcq/update.sql;`。
3、如果你是全新部署你可忽略此步骤。如果之前部署过此应用那么需要执行update.sql文件需要升级。注意升级之前请务必备份数据库确认是否需要运行此升级sql文件也很简单看一下你之前的数据库mybookmarks下面有没有`tags_bookmarks`这个数据表。如果有,那么需要执行。执行方法还是如上类似`source /home/lcq/update.sql;`。
4、安装Node.js。Node.js版本至少要求12.0以上。不会的话请按照上面步骤1、3提供的方法自行解决。
5、克隆代码`git clone git@github.com:luchenqun/my-bookmark.git`,切换到项目根目录下面,执行`npm install`安装package。
6、在根目录更新`pm2.json`文件,只需要更新`cwd`项即可。该项为你项目所在的路径。更新`src/config/adapter.js`下面`exports.model`关于你的MySQL的账号密码信息。注意该账号必须要有写数据库的权限

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 () {