fix: image stream data error

This commit is contained in:
jialin
2025-01-16 21:51:22 +08:00
parent b14c01f9f7
commit 214c5998c6
7 changed files with 44 additions and 20 deletions
@@ -60,6 +60,8 @@ const METAKEYS = [
'negative_prompt'
];
const ODD_STRING = 'AAAABJRU5ErkJgg===';
const advancedFieldsDefaultValus = {
seed: null,
sample_method: 'euler_a',
@@ -135,6 +137,10 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
};
});
const removeBase64Suffix = (str: string, suffix: string) => {
return str.endsWith(suffix) ? str.slice(0, -suffix.length) : str;
};
const getNewImageSizeOptions = useCallback((metaData: any) => {
const { max_height, max_width } = metaData || {};
if (!max_height || !max_width) {
@@ -350,12 +356,12 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
chunk?.data?.forEach((item: any) => {
const imgItem = newImageList[item.index];
if (item.b64_json && stream_options.chunk_results) {
imgItem.dataUrl += item.b64_json;
imgItem.dataUrl += removeBase64Suffix(item.b64_json, ODD_STRING);
} else if (item.b64_json) {
console.log('item.b64_json:', item.b64_json, item.index);
imgItem.dataUrl = `data:image/png;base64,${item.b64_json}`;
imgItem.dataUrl = `data:image/png;base64,${removeBase64Suffix(item.b64_json, ODD_STRING)}`;
}
const progress = _.round(item.progress, 0);
const progress = item.progress;
newImageList[item.index] = {
dataUrl: imgItem.dataUrl,
height: imgSize[1],
+11 -4
View File
@@ -62,6 +62,8 @@ const METAKEYS = [
'strength'
];
const ODD_STRING = 'AAAABJRU5ErkJgg===';
const advancedFieldsDefaultValus = {
seed: null,
sample_method: 'euler_a',
@@ -150,6 +152,10 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
};
});
const removeBase64Suffix = (str: string, suffix: string) => {
return str.endsWith(suffix) ? str.slice(0, -suffix.length) : str;
};
const updateCacheFormData = (values: Record<string, any>) => {
cacheFormData.current = {
...cacheFormData.current,
@@ -383,11 +389,11 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
chunk?.data?.forEach((item: any) => {
const imgItem = newImageList[item.index];
if (item.b64_json && params.stream_options_chunk_result) {
imgItem.dataUrl += item.b64_json;
imgItem.dataUrl += removeBase64Suffix(item.b64_json, ODD_STRING);
} else if (item.b64_json) {
imgItem.dataUrl = `data:image/png;base64,${item.b64_json}`;
imgItem.dataUrl = `data:image/png;base64,${removeBase64Suffix(item.b64_json, ODD_STRING)}`;
}
const progress = _.round(item.progress, 0);
const progress = item.progress;
newImageList[item.index] = {
dataUrl: imgItem.dataUrl,
@@ -832,7 +838,8 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
style={{
height: 125,
maxWidth: 125,
maxHeight: 125
maxHeight: 125,
overflow: 'hidden'
}}
key={item.uid}
>