mioku-service-webui 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/auth.ts +48 -0
- package/config-page-loader.ts +109 -0
- package/database.ts +322 -0
- package/datasources.ts +187 -0
- package/index.ts +231 -0
- package/package.json +20 -0
- package/routes/ai.ts +191 -0
- package/routes/config.ts +52 -0
- package/routes/db.ts +218 -0
- package/routes/index.ts +6 -0
- package/routes/manage.ts +92 -0
- package/routes/store.ts +475 -0
- package/routes/webui.ts +35 -0
- package/system.ts +1894 -0
- package/types.ts +45 -0
- package/utils.ts +114 -0
package/types.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// 管理类型
|
|
2
|
+
export type ManagedTarget = "plugin" | "service";
|
|
3
|
+
|
|
4
|
+
// 包管理器
|
|
5
|
+
export type PackageManager = "npm" | "pnpm" | "bun";
|
|
6
|
+
|
|
7
|
+
export interface WebUISettings {
|
|
8
|
+
port: number;
|
|
9
|
+
host: string;
|
|
10
|
+
packageManager: PackageManager;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface AuthConfig {
|
|
14
|
+
token: string;
|
|
15
|
+
createdAt: number;
|
|
16
|
+
expiresAt: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface InstallRequest {
|
|
20
|
+
repoUrl: string;
|
|
21
|
+
target: ManagedTarget;
|
|
22
|
+
packageManager?: PackageManager;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface UpdateRequest {
|
|
26
|
+
name: string;
|
|
27
|
+
target: ManagedTarget;
|
|
28
|
+
packageManager?: PackageManager;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface RemoveRequest {
|
|
32
|
+
name: string;
|
|
33
|
+
target: ManagedTarget;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface ChangeRepoRequest {
|
|
37
|
+
name: string;
|
|
38
|
+
target: ManagedTarget;
|
|
39
|
+
repoUrl: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface UpdateAllRequest {
|
|
43
|
+
target: ManagedTarget;
|
|
44
|
+
packageManager?: PackageManager;
|
|
45
|
+
}
|
package/utils.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import type { PackageManager, WebUISettings } from "./types";
|
|
5
|
+
|
|
6
|
+
export const WEEK_MS = 7 * 24 * 60 * 60 * 1000;
|
|
7
|
+
export const SETTINGS_PATH = path.join(process.cwd(), "config", "webui", "settings.json");
|
|
8
|
+
export const AUTH_PATH = path.join(process.cwd(), "config", "webui", "auth.json");
|
|
9
|
+
export const ROOT_PACKAGE_PATH = path.join(process.cwd(), "package.json");
|
|
10
|
+
export const LOCAL_CONFIG_PATH = path.join(process.cwd(), "config", "mioku.json");
|
|
11
|
+
|
|
12
|
+
export const WEBUI_DIST = path.join(process.cwd(), "src", "services", "webui", "dist");
|
|
13
|
+
export const PLUGINS_DIR = path.join(process.cwd(), "plugins");
|
|
14
|
+
export const SERVICES_DIR = path.join(process.cwd(), "src", "services");
|
|
15
|
+
export const CHAT_CONFIG_DIR = path.join(process.cwd(), "config", "chat");
|
|
16
|
+
export const CHAT_DATA_DIR = path.join(process.cwd(), "data", "chat");
|
|
17
|
+
export const LOGS_DIR = path.join(process.cwd(), "logs");
|
|
18
|
+
|
|
19
|
+
export const defaultWebUISettings: WebUISettings = {
|
|
20
|
+
port: 3339,
|
|
21
|
+
host: "0.0.0.0",
|
|
22
|
+
packageManager: "bun",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export function ensureDir(dirPath: string): void {
|
|
26
|
+
if (!fs.existsSync(dirPath)) {
|
|
27
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function readJsonFile<T>(filePath: string, fallback: T): T {
|
|
32
|
+
try {
|
|
33
|
+
if (!fs.existsSync(filePath)) {
|
|
34
|
+
return fallback;
|
|
35
|
+
}
|
|
36
|
+
return JSON.parse(fs.readFileSync(filePath, "utf-8")) as T;
|
|
37
|
+
} catch {
|
|
38
|
+
return fallback;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function writeJsonFile(filePath: string, data: unknown): void {
|
|
43
|
+
ensureDir(path.dirname(filePath));
|
|
44
|
+
fs.writeFileSync(filePath, JSON.stringify(data, null, 2), "utf-8");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function safeNameFromRepo(repoUrl: string): string {
|
|
48
|
+
const last = repoUrl.split("/").pop() || "package";
|
|
49
|
+
return last.replace(/\.git$/, "").replace(/[^a-zA-Z0-9._-]/g, "-");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function normalizeManagedPackageName(
|
|
53
|
+
repoUrl: string,
|
|
54
|
+
target: PackageManager extends never ? never : "plugin" | "service",
|
|
55
|
+
): string {
|
|
56
|
+
const raw = safeNameFromRepo(repoUrl);
|
|
57
|
+
if (target === "plugin" && raw.startsWith("mioku-plugin-")) {
|
|
58
|
+
return raw.slice("mioku-plugin-".length) || raw;
|
|
59
|
+
}
|
|
60
|
+
if (target === "service" && raw.startsWith("mioku-service-")) {
|
|
61
|
+
return raw.slice("mioku-service-".length) || raw;
|
|
62
|
+
}
|
|
63
|
+
return raw;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function runCommand(
|
|
67
|
+
command: string,
|
|
68
|
+
args: string[],
|
|
69
|
+
cwd: string,
|
|
70
|
+
): Promise<{ stdout: string; stderr: string; code: number }> {
|
|
71
|
+
return new Promise((resolve) => {
|
|
72
|
+
const child = spawn(command, args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
|
|
73
|
+
let stdout = "";
|
|
74
|
+
let stderr = "";
|
|
75
|
+
|
|
76
|
+
child.stdout.on("data", (chunk) => {
|
|
77
|
+
stdout += String(chunk);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
child.stderr.on("data", (chunk) => {
|
|
81
|
+
stderr += String(chunk);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
child.on("close", (code) => {
|
|
85
|
+
resolve({ stdout, stderr, code: code ?? 1 });
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
child.on("error", (error) => {
|
|
89
|
+
resolve({ stdout, stderr: `${stderr}\n${error.message}`.trim(), code: 1 });
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function getInstallCommand(packageManager: PackageManager): { cmd: string; args: string[] } {
|
|
95
|
+
if (packageManager === "npm") {
|
|
96
|
+
return { cmd: "npm", args: ["install"] };
|
|
97
|
+
}
|
|
98
|
+
if (packageManager === "pnpm") {
|
|
99
|
+
return { cmd: "pnpm", args: ["install"] };
|
|
100
|
+
}
|
|
101
|
+
return { cmd: "bun", args: ["install"] };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function normalizePackageManager(input?: string): PackageManager {
|
|
105
|
+
if (input === "npm" || input === "pnpm" || input === "bun") {
|
|
106
|
+
return input;
|
|
107
|
+
}
|
|
108
|
+
return "bun";
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function isValidRepoUrl(url: string): boolean {
|
|
112
|
+
const gitLike = /^(https?:\/\/|git@|ssh:\/\/).+/;
|
|
113
|
+
return gitLike.test(url.trim());
|
|
114
|
+
}
|