jeawin-astro 5.0.7 → 5.0.8
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/package.json +1 -1
- package/src/components/chatbot.astro +2 -2
- package/src/scripts/cms.js +0 -61
package/package.json
CHANGED
|
@@ -31,7 +31,7 @@ try{
|
|
|
31
31
|
<link rel="stylesheet" crossorigin href="https://img.jeawincdn.com/resource/web-chatbot-ui/dist/index.css" />
|
|
32
32
|
<script is:inline type="module" crossorigin="true" src="https://img.jeawincdn.com/resource/web-chatbot-ui/dist/index.js"></script>
|
|
33
33
|
<script define:vars={{
|
|
34
|
-
|
|
34
|
+
site_id: siteinfo.id,
|
|
35
35
|
jeawin_form_api_domain:jeawin_form_api_domain,
|
|
36
36
|
assistant_name: assistant_name,
|
|
37
37
|
assistant_avatar: assistant_avatar,
|
|
@@ -48,7 +48,7 @@ try{
|
|
|
48
48
|
// @ts-ignore
|
|
49
49
|
window.CHATBOT_CONFIG = {
|
|
50
50
|
title: title,
|
|
51
|
-
endpoint: `${jeawin_form_api_domain}/api.php?c=chatbot&m=chat&site_id=${
|
|
51
|
+
endpoint: `${jeawin_form_api_domain}/api.php?c=chatbot&m=chat&site_id=${site_id}`, // 可以替换为 https://{your-fc-http-trigger-domain}/chat
|
|
52
52
|
displayByDefault: false, // 默认不展示 AI 助手聊天框
|
|
53
53
|
aiChatOptions: { // aiChatOptions 中 options 会传递 aiChat 组件,自定义取值参考:https://docs.nlkit.com/nlux/reference/ui/ai-chat
|
|
54
54
|
conversationOptions: { // 自定义取值参考:https://docs.nlkit.com/nlux/reference/ui/ai-chat#conversation-options
|
package/src/scripts/cms.js
CHANGED
|
@@ -18,70 +18,15 @@ import { render_value } from './util.js';
|
|
|
18
18
|
|
|
19
19
|
let fetchCacheDuration = '1d';
|
|
20
20
|
let fetchVerbose = true;
|
|
21
|
-
const MAX_CACHE_SIZE = 500 * 1024 * 1024;
|
|
22
21
|
|
|
23
22
|
const isProd = import.meta.env?.PROD || false;
|
|
24
23
|
if (isProd) {
|
|
25
24
|
fetchCacheDuration = '1d';
|
|
26
25
|
fetchVerbose = false;
|
|
27
26
|
}
|
|
28
|
-
|
|
29
|
-
async function cleanupCache(cachePath) {
|
|
30
|
-
try {
|
|
31
|
-
const ls = await cacache.ls(cachePath);
|
|
32
|
-
let totalSize = 0;
|
|
33
|
-
const entries = [];
|
|
34
|
-
const now = Date.now();
|
|
35
|
-
|
|
36
|
-
for (const [key, info] of Object.entries(ls)) {
|
|
37
|
-
totalSize += info.size;
|
|
38
|
-
const isExpired = info.time && (now - info.time) > getDurationMs(fetchCacheDuration);
|
|
39
|
-
entries.push({ key, ...info, isExpired });
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const expiredEntries = entries.filter(e => e.isExpired);
|
|
43
|
-
if (expiredEntries.length > 0) {
|
|
44
|
-
await Promise.all(expiredEntries.map(e => cacache.rm.entry(cachePath, e.key).catch(() => {})));
|
|
45
|
-
totalSize -= expiredEntries.reduce((sum, e) => sum + e.size, 0);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (totalSize > MAX_CACHE_SIZE) {
|
|
49
|
-
entries.sort((a, b) => a.time - b.time);
|
|
50
|
-
const targetSize = MAX_CACHE_SIZE * 0.7;
|
|
51
|
-
let removedSize = 0;
|
|
52
|
-
|
|
53
|
-
for (const entry of entries) {
|
|
54
|
-
if (totalSize - removedSize <= targetSize) break;
|
|
55
|
-
await cacache.rm.entry(cachePath, entry.key).catch(() => {});
|
|
56
|
-
removedSize += entry.size;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
} catch (e) {}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async function cleanupAllCaches() {
|
|
63
|
-
const cacheBase = '.cache';
|
|
64
|
-
const subDirs = ['site', 'nodes', 'node'];
|
|
65
|
-
|
|
66
|
-
for (const subDir of subDirs) {
|
|
67
|
-
const basePath = `${cacheBase}/${subDir}`;
|
|
68
|
-
await cleanupCache(basePath);
|
|
69
|
-
|
|
70
|
-
try {
|
|
71
|
-
const fs = await import('node:fs');
|
|
72
|
-
const entries = fs.readdirSync(basePath, { withFileTypes: true });
|
|
73
|
-
for (const entry of entries) {
|
|
74
|
-
if (entry.isDirectory()) {
|
|
75
|
-
await cleanupCache(`${basePath}/${entry.name}`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
} catch (e) {}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
27
|
// consolelog(fetchCacheDuration);
|
|
82
28
|
|
|
83
29
|
function consolelog(...items) {
|
|
84
|
-
return;
|
|
85
30
|
if (!isProd) {
|
|
86
31
|
console.log(dayjs().format('YYYY-MM-DD HH:mm:ss SSS'), ...items)
|
|
87
32
|
}
|
|
@@ -226,9 +171,6 @@ export default class JeawinApi {
|
|
|
226
171
|
consolelog(`[JeawinCache] 缓存已过期: ${url}`);
|
|
227
172
|
} else {
|
|
228
173
|
const data = JSON.parse(res);
|
|
229
|
-
if (Math.random() < 0.05) {
|
|
230
|
-
cleanupCache(cachePath).catch(() => {});
|
|
231
|
-
}
|
|
232
174
|
consolelog(`[JeawinCache] 从缓存中获取数据: ${url}`);
|
|
233
175
|
return Promise.resolve(data);
|
|
234
176
|
}
|
|
@@ -290,9 +232,6 @@ export default class JeawinApi {
|
|
|
290
232
|
try {
|
|
291
233
|
await cacache.put(cachePath, key, cachedData);
|
|
292
234
|
consolelog(`[JeawinCache] 数据已缓存: ${url}`);
|
|
293
|
-
if (Math.random() < 0.1) {
|
|
294
|
-
cleanupAllCaches().catch(() => {});
|
|
295
|
-
}
|
|
296
235
|
} catch (e) {
|
|
297
236
|
if (!isProd) {
|
|
298
237
|
console.error('Cache put error:', e);
|