Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
bebf217b
authored
Jul 27, 2026
by
Xianquan
Committed by
GitHub
Jul 27, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: avoid double-encoding avatar URLs (#7388)
parent
b678010e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
4 deletions
+54
-4
pro
+1
-1
projects/app/src/pages/api/system/img/[...id].ts
+1
-3
projects/app/test/api/system/img.test.ts
+52
-0
No files found.
pro
@
d92a0660
Subproject commit
7027ac732193b6997eac387f556f23eb2e3bab22
Subproject commit
d92a06602209c4495e13370178b163bbc9058eb9
projects/app/src/pages/api/system/img/[...id].ts
View file @
bebf217b
...
...
@@ -22,10 +22,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
return
;
}
// Encode URL to handle special characters (e.g., Chinese characters)
const
publicUrl
=
getS3AvatarSource
().
createPublicUrl
(
joined
);
const
encodedUrl
=
encodeURI
(
publicUrl
);
res
.
redirect
(
301
,
encodedUrl
);
res
.
redirect
(
301
,
publicUrl
);
}
catch
(
error
)
{
jsonRes
(
res
,
{
code
:
500
,
...
...
projects/app/test/api/system/img.test.ts
0 → 100644
View file @
bebf217b
import
{
beforeEach
,
describe
,
expect
,
it
,
vi
}
from
'vitest'
;
import
handler
from
'@/pages/api/system/img/[...id]'
;
const
mocks
=
vi
.
hoisted
(()
=>
({
createPublicUrl
:
vi
.
fn
(),
isObjectIdValid
:
vi
.
fn
(()
=>
false
)
}));
vi
.
mock
(
'@fastgpt/service/common/s3/sources/avatar'
,
()
=>
({
getS3AvatarSource
:
vi
.
fn
(()
=>
({
createPublicUrl
:
mocks
.
createPublicUrl
}))
}));
vi
.
mock
(
'@fastgpt/service/common/file/image/controller'
,
()
=>
({
readMongoImg
:
vi
.
fn
()
}));
vi
.
mock
(
'@fastgpt/service/common/mongo'
,
()
=>
({
Types
:
{
ObjectId
:
{
isValid
:
mocks
.
isObjectIdValid
}
}
}));
describe
(
'system image redirect'
,
()
=>
{
const
key
=
'avatar/team-id/g0A71O-人事咨询小助手.png'
;
const
encodedPublicUrl
=
'https://cdn.example.com/avatar/team-id/g0A71O-%E4%BA%BA%E4%BA%8B%E5%92%A8%E8%AF%A2%E5%B0%8F%E5%8A%A9%E6%89%8B.png'
;
beforeEach
(()
=>
{
vi
.
clearAllMocks
();
mocks
.
createPublicUrl
.
mockReturnValue
(
encodedPublicUrl
);
});
it
(
'does not double-encode an already encoded object URL'
,
async
()
=>
{
const
req
=
{
query
:
{
id
:
key
.
split
(
'/'
)
}
}
as
any
;
const
res
=
{
redirect
:
vi
.
fn
()
}
as
any
;
await
handler
(
req
,
res
);
expect
(
mocks
.
createPublicUrl
).
toHaveBeenCalledWith
(
key
);
expect
(
res
.
redirect
).
toHaveBeenCalledWith
(
301
,
encodedPublicUrl
);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment