@waterplus-ai/waterbuddy 0.1.10 → 0.1.12
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/host/index.js +9 -7
- package/package.json +1 -1
package/lib/host/index.js
CHANGED
|
@@ -38,13 +38,17 @@ function clearPersistedAuth() {
|
|
|
38
38
|
try { fs.rmSync(authFile, { force: true }) } catch {}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
function isSupportedAvatarUrl(url) {
|
|
42
|
+
return (url.protocol === 'http:' || url.protocol === 'https:') && !url.username && !url.password
|
|
43
|
+
}
|
|
44
|
+
|
|
41
45
|
function normalizeAvatar(value) {
|
|
42
46
|
if (typeof value !== 'string' || !value) return undefined
|
|
43
47
|
if (value.startsWith('data:')) return value
|
|
44
48
|
try {
|
|
45
49
|
const url = new URL(value, AI_URL)
|
|
46
|
-
if (url
|
|
47
|
-
return
|
|
50
|
+
if (!isSupportedAvatarUrl(url)) return undefined
|
|
51
|
+
return url.href
|
|
48
52
|
} catch { return undefined }
|
|
49
53
|
}
|
|
50
54
|
|
|
@@ -143,15 +147,13 @@ async function proxyAvatar(req, res) {
|
|
|
143
147
|
const value = new URL(req.url, 'http://127.0.0.1').searchParams.get('url')
|
|
144
148
|
let target
|
|
145
149
|
try { target = new URL(value) } catch { return json(res, 400, { error: 'invalid-avatar-url' }) }
|
|
146
|
-
if (target
|
|
147
|
-
|
|
148
|
-
if (!response.ok || !response.body) return json(res, response.status || 502, { error: 'avatar-fetch-failed' })
|
|
149
|
-
res.writeHead(response.status, { 'content-type': response.headers.get('content-type') || 'image/jpeg', 'cache-control': 'private, max-age=3600' })
|
|
150
|
-
for await (const chunk of response.body) res.write(chunk)
|
|
150
|
+
if (!isSupportedAvatarUrl(target)) return json(res, 400, { error: 'avatar-url-not-supported' })
|
|
151
|
+
res.writeHead(302, { location: target.href, 'cache-control': 'private, max-age=3600' })
|
|
151
152
|
res.end()
|
|
152
153
|
}
|
|
153
154
|
|
|
154
155
|
export const inject = ['webServer', 'systemPrompt']
|
|
156
|
+
export { normalizeAvatar }
|
|
155
157
|
|
|
156
158
|
export function apply(ctx) {
|
|
157
159
|
readPersistedAuth()
|