fix: remove abearxiong/use-config

This commit is contained in:
2024-11-22 22:11:30 +08:00
parent 40f42ca89b
commit 503727c6c4
23 changed files with 134 additions and 26 deletions

View File

@@ -1,12 +1,10 @@
import { minioClient } from '@/app.ts';
import { bucketName } from '@/modules/minio.ts';
import { checkFileExistsSync } from '@/routes/page/module/cache-file.ts';
import { useFileStore } from '@abearxiong/use-file-store';
import { fileIsExist } from '../lib/file.ts';
import fs from 'fs';
import path from 'path';
import * as tar from 'tar';
const appsPath = useFileStore('apps', { needExists: true });
import { appsPath } from '../lib/index.ts';
export type InstallAppOpts = {
path?: string;
@@ -15,7 +13,7 @@ export type InstallAppOpts = {
export const appCheck = async (opts: InstallAppOpts) => {
const { key } = opts;
const directory = path.join(appsPath, key);
if (checkFileExistsSync(directory)) {
if (fileIsExist(directory)) {
return true;
}
return false;
@@ -25,7 +23,7 @@ export const installApp = async (opts: InstallAppOpts) => {
const fileStream = await minioClient.getObject(bucketName, opts.path);
const pathName = opts.path.split('/').pop();
const directory = path.join(appsPath, key);
if (!checkFileExistsSync(directory)) {
if (!fileIsExist(directory)) {
fs.mkdirSync(directory, { recursive: true });
}
const filePath = path.join(directory, pathName);
@@ -44,7 +42,7 @@ export const installApp = async (opts: InstallAppOpts) => {
cwd: extractPath,
});
const pkgs = path.join(extractPath, 'package.json');
if (!checkFileExistsSync(pkgs)) {
if (!fileIsExist(pkgs)) {
throw new Error('Invalid package.json');
}
const json = fs.readFileSync(pkgs, 'utf-8');
@@ -58,3 +56,5 @@ export const installApp = async (opts: InstallAppOpts) => {
// fs.unlinkSync(filePath);
return { path: filePath };
};