fix: install from app key
This commit is contained in:
parent
a5d0e66b3c
commit
b2d968b70d
@ -154,6 +154,7 @@ router.get('/api/micro-app/download/:id', async (req, res) => {
|
||||
return;
|
||||
}
|
||||
res.setHeader('Content-Disposition', `attachment; filename="${encodeURIComponent(fileName)}"`);
|
||||
res.setHeader('app-key', file.data?.key || id);
|
||||
res.writeHead(200, { 'Content-Type': 'application/octet-stream' });
|
||||
try {
|
||||
const stream = await minioClient.getObject(bucketName, objectName);
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { app } from '@/app.ts';
|
||||
import { MicroAppModel } from './models.ts';
|
||||
import { appPathCheck, getAppPathKeys, installApp, installAppFromKey } from './module/install-app.ts';
|
||||
import { appPathCheck, installApp } from './module/install-app.ts';
|
||||
import { getAppPathKeys, installAppFromKey } from './module/manager.ts';
|
||||
import { loadApp } from './module/load-app.ts';
|
||||
import { manager } from './manager-app.ts';
|
||||
|
||||
|
@ -10,6 +10,7 @@ type MicroAppData = {
|
||||
hash: string;
|
||||
name: string;
|
||||
};
|
||||
key?: string;
|
||||
data?: any;
|
||||
collection?: any; // 上传的信息汇总
|
||||
};
|
||||
|
@ -6,7 +6,7 @@ import fs from 'fs';
|
||||
import path from 'path';
|
||||
import * as tar from 'tar';
|
||||
import { appsPath } from '../lib/index.ts';
|
||||
|
||||
import { installAppFromKey } from './manager.ts';
|
||||
export type InstallAppOpts = {
|
||||
path?: string;
|
||||
key?: string;
|
||||
@ -49,47 +49,3 @@ export const installApp = async (opts: InstallAppOpts) => {
|
||||
});
|
||||
return installAppFromKey(key);
|
||||
};
|
||||
export const installAppFromKey = async (key: string) => {
|
||||
const directory = path.join(appsPath, key);
|
||||
if (!fileIsExist(directory)) {
|
||||
throw new Error('App not found');
|
||||
}
|
||||
const pkgs = path.join(directory, 'package.json');
|
||||
if (!fileIsExist(pkgs)) {
|
||||
throw new Error('Invalid package.json');
|
||||
}
|
||||
const json = fs.readFileSync(pkgs, 'utf-8');
|
||||
const pkg = JSON.parse(json);
|
||||
const { name, version, app } = pkg;
|
||||
if (!name || !version || !app) {
|
||||
throw new Error('Invalid package.json');
|
||||
}
|
||||
const readmeFile = path.join(directory, 'README.md');
|
||||
let readmeDesc = '';
|
||||
if (fileIsExist(readmeFile)) {
|
||||
readmeDesc = fs.readFileSync(readmeFile, 'utf-8');
|
||||
}
|
||||
let showAppInfo = {
|
||||
key,
|
||||
status: 'inactive',
|
||||
type: app?.type || 'system-app',
|
||||
description: readmeDesc || '',
|
||||
version,
|
||||
//
|
||||
entry: app?.entry || '',
|
||||
path: directory,
|
||||
origin: app,
|
||||
};
|
||||
app.key = key;
|
||||
fs.writeFileSync(pkgs, JSON.stringify(pkg, null, 2));
|
||||
return { pkg, showAppInfo };
|
||||
};
|
||||
export const getAppPathKeys = async () => {
|
||||
let files = fs.readdirSync(appsPath);
|
||||
files = files.filter((file) => {
|
||||
const stat = fs.statSync(path.join(appsPath, file));
|
||||
if (file === 'node_modules') return false;
|
||||
return stat.isDirectory();
|
||||
});
|
||||
return files;
|
||||
};
|
||||
|
@ -5,6 +5,9 @@ import { merge } from 'lodash-es';
|
||||
import { deleteFileAppInfo } from './load-app.ts';
|
||||
import { fileIsExist } from '@kevisual/use-config';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import { appsPath } from '../lib/index.ts';
|
||||
|
||||
// 共享
|
||||
export const existDenpend = [
|
||||
'sequelize', // commonjs
|
||||
@ -249,3 +252,48 @@ export class Manager<T extends AppInfo = any> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const installAppFromKey = async (key: string) => {
|
||||
const directory = path.join(appsPath, key);
|
||||
if (!fileIsExist(directory)) {
|
||||
throw new Error('App not found');
|
||||
}
|
||||
const pkgs = path.join(directory, 'package.json');
|
||||
if (!fileIsExist(pkgs)) {
|
||||
throw new Error('Invalid package.json');
|
||||
}
|
||||
const json = fs.readFileSync(pkgs, 'utf-8');
|
||||
const pkg = JSON.parse(json);
|
||||
const { name, version, app } = pkg;
|
||||
if (!name || !version || !app) {
|
||||
throw new Error('Invalid package.json');
|
||||
}
|
||||
const readmeFile = path.join(directory, 'README.md');
|
||||
let readmeDesc = '';
|
||||
if (fileIsExist(readmeFile)) {
|
||||
readmeDesc = fs.readFileSync(readmeFile, 'utf-8');
|
||||
}
|
||||
let showAppInfo = {
|
||||
key,
|
||||
status: 'inactive',
|
||||
type: app?.type || 'system-app',
|
||||
description: readmeDesc || '',
|
||||
version,
|
||||
//
|
||||
entry: app?.entry || '',
|
||||
path: directory,
|
||||
origin: app,
|
||||
};
|
||||
app.key = key;
|
||||
fs.writeFileSync(pkgs, JSON.stringify(pkg, null, 2));
|
||||
return { pkg, showAppInfo };
|
||||
};
|
||||
export const getAppPathKeys = async () => {
|
||||
let files = fs.readdirSync(appsPath);
|
||||
files = files.filter((file) => {
|
||||
const stat = fs.statSync(path.join(appsPath, file));
|
||||
if (file === 'node_modules') return false;
|
||||
return stat.isDirectory();
|
||||
});
|
||||
return files;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user