koishi-plugin-group-analysis-mx 1.5.0 → 1.5.1
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/lib/service/renderer.js
CHANGED
|
@@ -201,6 +201,30 @@ class RendererService extends koishi_1.Service {
|
|
|
201
201
|
if (!this.ctx.puppeteer) {
|
|
202
202
|
throw new Error('Puppeteer service is not available.');
|
|
203
203
|
}
|
|
204
|
+
// 头像转 base64 内联:避免部分用户头像 URL 加载失败导致空白;失败用默认头像兜底
|
|
205
|
+
const DEFAULT_AVATAR = 'data:image/svg+xml;base64,' + Buffer.from('<svg xmlns="http://www.w3.org/2000/svg" width="80" height="80"><rect width="80" height="80" fill="#d9dee5"/><circle cx="40" cy="31" r="15" fill="#aab3bf"/><path d="M10 76c4-17 16-26 30-26s26 9 30 26z" fill="#aab3bf"/></svg>').toString('base64');
|
|
206
|
+
const avatarCache = new Map();
|
|
207
|
+
const inlineAvatar = async (obj) => {
|
|
208
|
+
if (!obj)
|
|
209
|
+
return obj;
|
|
210
|
+
const url = obj.avatar;
|
|
211
|
+
if (!url)
|
|
212
|
+
return { ...obj, avatar: DEFAULT_AVATAR };
|
|
213
|
+
if (!avatarCache.has(url)) {
|
|
214
|
+
let b64 = '';
|
|
215
|
+
try {
|
|
216
|
+
b64 = await this.imageToBase64(url);
|
|
217
|
+
}
|
|
218
|
+
catch (e) { }
|
|
219
|
+
avatarCache.set(url, b64 || DEFAULT_AVATAR);
|
|
220
|
+
}
|
|
221
|
+
return { ...obj, avatar: avatarCache.get(url) };
|
|
222
|
+
};
|
|
223
|
+
data = {
|
|
224
|
+
...data,
|
|
225
|
+
userStats: await Promise.all((data.userStats || []).map(inlineAvatar)),
|
|
226
|
+
userTitles: await Promise.all((data.userTitles || []).map(inlineAvatar)),
|
|
227
|
+
};
|
|
204
228
|
const templatePath = this.getSkinPath('template_group.html');
|
|
205
229
|
const randomId = Math.random().toString(36).substring(2, 15);
|
|
206
230
|
const skin = this.config.skin || 'md3';
|
package/package.json
CHANGED
|
@@ -91,8 +91,7 @@
|
|
|
91
91
|
${activeHoursChart}
|
|
92
92
|
|
|
93
93
|
<div class="footer">
|
|
94
|
-
|
|
95
|
-
</div>
|
|
94
|
+
由《剑灵》怀旧服机器人-若汐生成</div>
|
|
96
95
|
</div>
|
|
97
96
|
</div>
|
|
98
97
|
|
|
@@ -105,4 +104,4 @@
|
|
|
105
104
|
}
|
|
106
105
|
</script>
|
|
107
106
|
</body>
|
|
108
|
-
</html>
|
|
107
|
+
</html>
|