feat: 下载page到本地
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user