Skip to content

Commit 16f4888

Browse files
committed
feat: 新增自动重启,优化代码逻辑 close #19
1 parent ba71db1 commit 16f4888

File tree

24 files changed

+662
-214
lines changed

24 files changed

+662
-214
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ lerna-debug.log*
2525
node_modules/
2626
config/config/pm2.yaml
2727
index.js
28-
plugins/
28+
/plugins/
2929
pnpm-workspace.yaml
3030
@karinjs/
3131
/dist

config/config.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@karinjs/plugin-basic",
33
"version": "1.2.1",
4-
"description": "karin plugin for basic functions",
4+
"description": "Karin的基础插件,提供最基础的功能",
55
"homepage": "https://github.com/KarinJS/karin-plugin-basic",
66
"bugs": {
77
"url": "https://github.com/KarinJS/karin-plugin-basic/issues"

resources/img/logger.png

1.11 MB
Loading

resources/img/plugin.png

2.46 MB
Loading

resources/logger/index.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ body {
2525
padding: 30px;
2626
color: #0f172a;
2727
overflow: hidden;
28-
background: url('main.png') center/cover no-repeat, #e0f2ff;
28+
background: url('../img/logger.png') center/cover no-repeat, #e0f2ff;
2929
border-bottom: 1px solid rgba(148, 163, 184, 0.35);
3030
}
3131

resources/logger/main.png

-119 KB
Binary file not shown.

resources/plugins/index.css

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
* {
2+
margin: 0;
3+
padding: 0;
4+
box-sizing: border-box;
5+
}
6+
7+
body {
8+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif, 'Microsoft YaHei';
9+
background: radial-gradient(circle at 20% 50%, rgba(120, 200, 255, 0.3) 0%, transparent 50%),
10+
radial-gradient(circle at 80% 80%, rgba(180, 220, 255, 0.3) 0%, transparent 50%),
11+
radial-gradient(circle at 40% 20%, rgba(200, 230, 255, 0.2) 0%, transparent 50%),
12+
linear-gradient(135deg, #e3f2fd 0%, #ffffff 50%, #f0f7ff 100%);
13+
padding: 16px;
14+
}
15+
16+
.container {
17+
max-width: 1400px;
18+
margin: 0 auto;
19+
background: rgba(255, 255, 255, 0.96);
20+
border-radius: 18px;
21+
box-shadow: 0 18px 45px rgba(100, 150, 200, 0.35);
22+
overflow: hidden;
23+
}
24+
25+
.header {
26+
position: relative;
27+
padding: 30px;
28+
color: #fff;
29+
background: url('../img/plugin.png') center/cover no-repeat,
30+
linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
31+
border-bottom: 1px solid rgba(255, 255, 255, 0.2);
32+
}
33+
34+
.header h1 {
35+
font-size: 32px;
36+
margin-bottom: 15px;
37+
font-weight: 600;
38+
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
39+
}
40+
41+
.info {
42+
display: flex;
43+
gap: 20px;
44+
font-size: 14px;
45+
opacity: 0.95;
46+
}
47+
48+
.info span {
49+
background: rgba(255, 255, 255, 0.2);
50+
padding: 6px 12px;
51+
border-radius: 6px;
52+
backdrop-filter: blur(10px);
53+
}
54+
55+
.plugins-container {
56+
padding: 20px;
57+
display: grid;
58+
grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
59+
gap: 20px;
60+
}
61+
62+
.plugin-card {
63+
background: #fff;
64+
border-radius: 12px;
65+
padding: 20px;
66+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
67+
border: 2px solid #e3f2fd;
68+
display: flex;
69+
flex-direction: column;
70+
position: relative;
71+
}
72+
73+
.plugin-header {
74+
margin-bottom: 15px;
75+
}
76+
77+
.plugin-name-row {
78+
display: flex;
79+
align-items: center;
80+
justify-content: space-between;
81+
gap: 10px;
82+
margin-bottom: 8px;
83+
}
84+
85+
.plugin-name {
86+
font-size: 18px;
87+
font-weight: 600;
88+
color: #1a202c;
89+
word-break: break-word;
90+
flex: 1;
91+
line-height: 1.4;
92+
}
93+
94+
.platform-badge {
95+
display: inline-flex;
96+
align-items: center;
97+
gap: 4px;
98+
padding: 4px 10px;
99+
border-radius: 6px;
100+
font-size: 11px;
101+
font-weight: 600;
102+
text-transform: uppercase;
103+
white-space: nowrap;
104+
flex-shrink: 0;
105+
}
106+
107+
.platform-icon {
108+
font-size: 14px;
109+
}
110+
111+
.platform-npm {
112+
background: linear-gradient(135deg, #cb3837 0%, #d63031 100%);
113+
color: white;
114+
}
115+
116+
.platform-git {
117+
background: linear-gradient(135deg, #f05032 0%, #ff6b35 100%);
118+
color: white;
119+
}
120+
121+
.platform-app {
122+
background: linear-gradient(135deg, #66bb6a 0%, #43a047 100%);
123+
color: white;
124+
}
125+
126+
.plugin-version {
127+
display: inline-block;
128+
padding: 3px 8px;
129+
background: #e2e8f0;
130+
color: #4a5568;
131+
border-radius: 4px;
132+
font-size: 12px;
133+
font-weight: 500;
134+
}
135+
136+
.plugin-body {
137+
flex: 1;
138+
display: flex;
139+
flex-direction: column;
140+
gap: 12px;
141+
}
142+
143+
.plugin-description {
144+
font-size: 14px;
145+
line-height: 1.6;
146+
color: #4a5568;
147+
word-break: break-word;
148+
flex: 1;
149+
}
150+
151+
.no-description {
152+
color: #a0aec0;
153+
font-style: italic;
154+
}
155+
156+
.plugin-meta {
157+
display: flex;
158+
flex-direction: column;
159+
gap: 8px;
160+
padding-top: 10px;
161+
border-top: 1px solid #e2e8f0;
162+
}
163+
164+
.meta-item {
165+
display: flex;
166+
align-items: flex-start;
167+
gap: 8px;
168+
font-size: 13px;
169+
}
170+
171+
.meta-label {
172+
color: #718096;
173+
font-weight: 500;
174+
white-space: nowrap;
175+
}
176+
177+
.meta-value {
178+
color: #2d3748;
179+
word-break: break-all;
180+
flex: 1;
181+
}
182+
183+
.plugin-path {
184+
font-family: 'Consolas', 'Monaco', monospace;
185+
font-size: 11px;
186+
color: #42a5f5;
187+
}
188+
189+
.plugin-footer {
190+
margin-top: 12px;
191+
padding-top: 12px;
192+
border-top: 1px solid #e2e8f0;
193+
display: flex;
194+
justify-content: flex-end;
195+
}
196+
197+
.plugin-index {
198+
font-size: 12px;
199+
color: #a0aec0;
200+
font-weight: 600;
201+
}
202+
203+
.footer {
204+
background: #f8f9fa;
205+
padding: 15px 30px;
206+
text-align: center;
207+
color: #6c757d;
208+
font-size: 12px;
209+
border-top: 1px solid #dee2e6;
210+
}

resources/plugins/index.html

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<!DOCTYPE html>
2+
<html lang="zh-CN">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>插件列表</title>
8+
<link rel="stylesheet" href="{{pluResPath}}plugins/index.css">
9+
</head>
10+
11+
<body>
12+
<div class="container">
13+
<div class="header">
14+
<h1>🔌 插件列表</h1>
15+
<div class="info">
16+
<span class="date">{{date}}</span>
17+
<span class="count">共 {{total}} 个插件</span>
18+
</div>
19+
</div>
20+
21+
<div class="plugins-container">
22+
{{each plugins}}
23+
<div class="plugin-card">
24+
<div class="plugin-header">
25+
<div class="plugin-name-row">
26+
<h3 class="plugin-name">{{$value.name}}</h3>
27+
<span class="platform-badge platform-{{$value.type}}">
28+
<span class="platform-icon">{{$value.typeIcon}}</span>
29+
{{$value.type}}
30+
</span>
31+
</div>
32+
{{if $value.version}}
33+
<span class="plugin-version">v{{$value.version}}</span>
34+
{{/if}}
35+
</div>
36+
37+
<div class="plugin-body">
38+
{{if $value.description}}
39+
<p class="plugin-description">{{$value.description}}</p>
40+
{{else}}
41+
<p class="plugin-description no-description">暂无描述</p>
42+
{{/if}}
43+
44+
<div class="plugin-meta">
45+
{{if $value.author}}
46+
<div class="meta-item">
47+
<span class="meta-label">👤 作者:</span>
48+
<span class="meta-value">{{$value.author}}</span>
49+
</div>
50+
{{/if}}
51+
<div class="meta-item">
52+
<span class="meta-label">📁 路径:</span>
53+
<span class="meta-value plugin-path">{{$value.dir}}</span>
54+
</div>
55+
</div>
56+
</div>
57+
58+
<div class="plugin-footer">
59+
<span class="plugin-index">#{{$value.index}}</span>
60+
</div>
61+
</div>
62+
{{/each}}
63+
</div>
64+
65+
<div class="footer">
66+
<p>{{sys.copyright}}</p>
67+
</div>
68+
</div>
69+
</body>
70+
71+
</html>

src/apps/login.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { config } from '@/utils/config'
1+
import { cfg } from '@/config'
22
import karin, { common, contactFriend, logger, segment } from 'node-karin'
33
import axios from 'node-karin/axios'
44
import os from 'node:os'
@@ -7,7 +7,7 @@ const url = { IPv4: ['https://4.ipw.cn'], IPv6: ['https://6.ipw.cn'] }
77

88
export const login = karin.command(/#?(|web)$/i, async (e) => {
99
const net = os.networkInterfaces()
10-
const cfg = config()
10+
const config = cfg.get()
1111
const IP: { lan: { ipv4: null | string, ipv6: null | string }, net: { ipv4: null | string, ipv6: null | string } } =
1212
{ lan: { ipv4: null, ipv6: null }, net: { ipv4: null, ipv6: null } }
1313
for (const i in net) {
@@ -35,7 +35,7 @@ export const login = karin.command(/#?(面板|web)登录$/i, async (e) => {
3535
const port = process.env.HTTP_PORT
3636
const token = process.env.HTTP_AUTH_KEY
3737
const msg = [segment.text('面板登录地址:')]
38-
if (cfg.domain) msg.push(segment.text(`- 自定义域名: ${cfg.domain}/web/login?token=${token}`))
38+
if (config.domain) msg.push(segment.text(`- 自定义域名: ${config.domain}/web/login?token=${token}`))
3939
msg.push(segment.text(`- 内网地址: ${IP.lan.ipv4 ? `http://${IP.lan.ipv4}:${port}/web/login?token=${token}` : `http://${IP.lan.ipv4}:${port}/web/login?token=${token}`}`))
4040
if (IP.net.ipv4) msg.push(segment.text(`- 外网IPv4地址: http://${IP.net.ipv4}:${port}/web/login?token=${token}`))
4141
if (IP.net.ipv6) msg.push(segment.text(`- 外网IPv6地址: http://${IP.net.ipv6}:${port}/web/login?token=${token}`))

0 commit comments

Comments
 (0)