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
ef15ca89
authored
Mar 22, 2024
by
xiaotian
Committed by
GitHub
Mar 22, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: claude3 image type verification failed (#1038) (#1040)
parent
a63467d7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
3 deletions
+23
-3
packages/service/common/file/utils.ts
+18
-0
projects/app/src/pages/api/system/img/[id].ts
+5
-3
No files found.
packages/service/common/file/utils.ts
View file @
ef15ca89
...
@@ -9,3 +9,21 @@ export const removeFilesByPaths = (paths: string[]) => {
...
@@ -9,3 +9,21 @@ export const removeFilesByPaths = (paths: string[]) => {
});
});
});
});
};
};
const
imageTypeMap
:
Record
<
string
,
string
>
=
{
'/'
:
'image/jpeg'
,
i
:
'image/png'
,
R
:
'image/gif'
,
U
:
'image/webp'
,
Q
:
'image/bmp'
};
export
const
guessImageTypeFromBase64
=
(
str
:
string
)
=>
{
const
defaultType
=
'image/jpeg'
;
if
(
typeof
str
!==
'string'
||
str
.
length
===
0
)
{
return
defaultType
;
}
const
firstChar
=
str
.
charAt
(
0
);
return
imageTypeMap
[
firstChar
]
||
defaultType
;
};
projects/app/src/pages/api/system/img/[id].ts
View file @
ef15ca89
...
@@ -2,6 +2,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';
...
@@ -2,6 +2,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';
import
{
jsonRes
}
from
'@fastgpt/service/common/response'
;
import
{
jsonRes
}
from
'@fastgpt/service/common/response'
;
import
{
connectToDatabase
}
from
'@/service/mongo'
;
import
{
connectToDatabase
}
from
'@/service/mongo'
;
import
{
readMongoImg
}
from
'@fastgpt/service/common/file/image/controller'
;
import
{
readMongoImg
}
from
'@fastgpt/service/common/file/image/controller'
;
import
{
guessImageTypeFromBase64
}
from
'@fastgpt/service/common/file/utils'
;
// get the models available to the system
// get the models available to the system
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
)
{
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
)
{
...
@@ -9,9 +10,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -9,9 +10,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
await
connectToDatabase
();
await
connectToDatabase
();
const
{
id
}
=
req
.
query
as
{
id
:
string
};
const
{
id
}
=
req
.
query
as
{
id
:
string
};
res
.
setHeader
(
'Content-Type'
,
'image/jpeg'
);
const
binary
=
await
readMongoImg
({
id
});
const
imageType
=
guessImageTypeFromBase64
(
binary
.
toString
(
'base64'
));
res
.
send
(
await
readMongoImg
({
id
}));
res
.
setHeader
(
'Content-Type'
,
imageType
);
res
.
send
(
binary
);
}
catch
(
error
)
{
}
catch
(
error
)
{
jsonRes
(
res
,
{
jsonRes
(
res
,
{
code
:
500
,
code
:
500
,
...
...
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