feat: 下载page到本地

This commit is contained in:
2024-10-08 17:10:32 +08:00
parent 54e3ccb3ff
commit 8cdd54af04
9 changed files with 361 additions and 8 deletions

View File

@@ -5,7 +5,7 @@ import { v4 as uuidv4 } from 'uuid';
import { ContainerModel } from '../container/models/index.ts';
import { Op } from 'sequelize';
import { AppListModel, AppModel } from '../app-manager/index.ts';
import { cachePage } from './module/cache-file.ts';
import { cachePage, getZip } from './module/cache-file.ts';
import _ from 'lodash';
import semver from 'semver';
@@ -67,3 +67,26 @@ app
}
})
.addTo(app);
app
.route({
path: 'page',
key: 'download',
middleware: ['auth'],
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
const { id } = ctx.query;
const page = await PageModel.findByPk(id);
if (!page) {
throw new CustomError('page not found');
}
try {
const files = await getZip(page, { tokenUser });
ctx.body = files;
} catch (e) {
console.log('error', e);
throw new CustomError(e.message || 'download error');
}
})
.addTo(app);