update download app show me
This commit is contained in:
@@ -25,10 +25,14 @@ type InstallAppOpts = {
|
||||
* 是否是客户端, 下载到 assistant-config的下面
|
||||
*/
|
||||
isClient?: boolean;
|
||||
/**
|
||||
* 是否是web, 下载到 web-config的下面
|
||||
*/
|
||||
appType?: 'app' | 'web';
|
||||
};
|
||||
export const installApp = async (app: Package, opts: InstallAppOpts = {}) => {
|
||||
// const _app = demoData;
|
||||
const { appDir = '', kevisualUrl = 'https://kevisual.cn' } = opts;
|
||||
const { appDir = '', kevisualUrl = 'https://kevisual.cn', isClient = false, appType = 'web' } = opts;
|
||||
const _app = app;
|
||||
try {
|
||||
let files = _app.data.files || [];
|
||||
@@ -38,13 +42,19 @@ export const installApp = async (app: Package, opts: InstallAppOpts = {}) => {
|
||||
|
||||
const downFiles = files.map((file: any) => {
|
||||
const noVersionPath = file.path.replace(`/${version}`, '');
|
||||
let downloadPath = noVersionPath;
|
||||
if (appType === 'app') {
|
||||
downloadPath = noVersionPath.replace(`${user}/${key}/`, '');
|
||||
}
|
||||
return {
|
||||
...file,
|
||||
downloadPath: path.join(appDir, noVersionPath),
|
||||
downloadPath: path.join(appDir, downloadPath),
|
||||
downloadUrl: `${kevisualUrl}/${noVersionPath}`,
|
||||
};
|
||||
});
|
||||
const downloadTasks: DownloadTask[] = downFiles as any;
|
||||
console.log('downloadTasks', downloadTasks);
|
||||
// return;
|
||||
for (const file of downloadTasks) {
|
||||
const downloadPath = file.downloadPath;
|
||||
const downloadUrl = file.downloadUrl;
|
||||
@@ -52,18 +62,19 @@ export const installApp = async (app: Package, opts: InstallAppOpts = {}) => {
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
}
|
||||
console.log('downloadUrl', downloadUrl);
|
||||
const res = await fetch(downloadUrl);
|
||||
const blob = await res.blob();
|
||||
fs.writeFileSync(downloadPath, Buffer.from(await blob.arrayBuffer()));
|
||||
}
|
||||
let indexHtml = files.find((file: any) => file.name === 'index.html');
|
||||
if (!indexHtml) {
|
||||
files.push({
|
||||
name: 'index.html',
|
||||
path: `${user}/${key}/index.html`,
|
||||
});
|
||||
fs.writeFileSync(path.join(appDir, `${user}/${key}/index.html`), JSON.stringify(app, null, 2));
|
||||
}
|
||||
// if (!indexHtml) {
|
||||
// files.push({
|
||||
// name: 'index.html',
|
||||
// path: `${user}/${key}/index.html`,
|
||||
// });
|
||||
// fs.writeFileSync(path.join(appDir, `${user}/${key}/index.html`), JSON.stringify(app, null, 2));
|
||||
// }
|
||||
_app.data.files = files;
|
||||
return {
|
||||
code: 200,
|
||||
|
||||
Reference in New Issue
Block a user