Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] 导出的消息包含图片时,预览可以显示图片,但是导出的文件里面图片是空白 #200

Open
3 tasks done
zpng opened this issue Feb 20, 2024 · 11 comments

Comments

@zpng
Copy link

zpng commented Feb 20, 2024

为了提高交流效率,我们设立了官方 QQ 群和 QQ 频道,如果你在使用或者搭建过程中遇到了任何问题,请先第一时间加群或者频道咨询解决,除非是可以稳定复现的 Bug 或者较为有创意的功能建议,否则请不要随意往 Issue 区发送低质无意义帖子。

点击加入官方群聊

反馈须知

⚠️ 注意:不遵循此模板的任何帖子都会被立即关闭,如果没有提供下方的信息,我们无法定位你的问题。

请在下方中括号内输入 x 来表示你已经知晓相关内容。

  • 我确认已经在 常见问题 中搜索了此次反馈的问题,没有找到解答;
  • 我确认已经在 Issues 列表(包括已经 Close 的)中搜索了此次反馈的问题,没有找到解答。
  • 我确认已经在 Vercel 使用教程 中搜索了此次反馈的问题,没有找到解答。

描述问题
导出的消息包含图片时,预览可以显示图片,但是导出的文件里面图片是空白

请求修复fetch报错

## 用户:
return fetch(midJourneyAPIPath, {
headers: {
"Content-Type": "application/json",
token: token,
},
cache: "no-store",
method: req.method,
body: req.body,
})
上述代码报错为,
[Midjourney]  [TypeError: RequestInit: duplex option is required when sending a body.]
请帮我修改代码以修复错误


## ChatGPT:
错误提示表示在发送请求体时,需要一个双向(duplex)选项。这可能是因为你的请求需要同时读取和写入数据。在JavaScript的`fetch` API中,没有直接的`duplex`选项,但你可以使用`ReadableStream`来创建一个双向流。

然而,通常情况下,你不需要在使用`fetch`发送JSON数据时设置双向流。这可能是由于你的`req.body`已经是一个流,你需要首先将其转换为JSON。这里是一个可能的解决方案,你可以试试看:

```javascript
let bodyData;

if (req.body instanceof ReadableStream) {
  const reader = req.body.getReader();
  const result = await reader.read(); // Read from the stream
  const decoder = new TextDecoder();
  bodyData = decoder.decode(result.value); // Convert the Uint8Array to a string
} else {
  bodyData = JSON.stringify(req.body);
}

return fetch(midJourneyAPIPath, {
  headers: {
    "Content-Type": "application/json",
    token: token,
  },
  cache: "no-store",
  method: req.method,
  body: bodyData,
});

在这段代码中,我首先检查`req.body`是否是一个`ReadableStream`。如果是,我从流中读取数据,然后使用`TextDecoder`将其转换为字符串。如果`req.body`不是流,我直接将其转换为JSON。这样应该可以解决你的问题。

## 用户:
12332

## ChatGPT:
你输入了一串数字"12332",但没有提供更多的上下文信息。这让我很难理解你的需求。如果你需要进一步的帮助,请提供更多的详细信息。

## 用户:
/mj a mountain

## ChatGPT:
![a mountain](https://image.lingjingai3.com/attachments/1209160022710296627/1209325569829765120/barbara4602t_59231_a_mountain_2927e602-4a70-4f30-b71c-ddd71e28ce21.png?ex=65e68334&is=65d40e34&hm=f00f387a4d965f747ec66b39c5f076b5484c16437ffa65ab00c355580d7df9ee&)

如上所示的消息,预览为:
image
图片可以正常显示,
但是导出的图片为:
请求修复fetch报错

该图片不显示为空白。

一些必要的信息

  • System: [mac 13.6 (22G120)]
  • Browser: [chrome]
  • Version: [v2.10.1]
  • Deployment method: [zeabur deployment]
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Title: [Bug] When the exported message contains pictures, the preview can display the pictures, but the pictures in the exported file are blank.

@Hk-Gosuto
Copy link
Owner

这个应该是网络问题,最新的代码为了避免触发 cors 默认会将 markdown 中的图像链接处理为使用后端接口中转,如果网络情况不太好的话就会导致图片没办法正确渲染,可以多试几次,我在 vercel 的服务中试了一下是可以正确导出的。
image

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


This should be a network problem. In order to avoid triggering cors, the latest code will process the image link in markdown to use the backend interface for transfer by default. If the network condition is not good, the image will not be rendered correctly. You can try a few more times. , I tried it in vercel's service and it can be exported correctly.
image

@zpng
Copy link
Author

zpng commented Feb 20, 2024

这个应该是网络问题,最新的代码为了避免触发 cors 默认会将 markdown 中的图像链接处理为使用后端接口中转,如果网络情况不太好的话就会导致图片没办法正确渲染,可以多试几次,我在 vercel 的服务中试了一下是可以正确导出的。 image

@Hk-Gosuto 这个有办法在导出的时候控制图片出来之后再渲染导出吗,不然这样每次空白感觉也不大友好?而且我测试了好多遍都是空白

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


This should be a network problem. In order to avoid triggering cors, the latest code will process the image link in markdown to use the backend interface for transfer by default. If the network condition is not good, the image will not be rendered correctly. You can try a few more times. This time, I tried it in vercel's service and it could be exported correctly. ! [Image] (https://private- user-images.githubusercontent.com/14031260/306124667-fb322c84-6955e-8814b452.png?jwt=eyjhbgci Oijiuzi1niisini5CCI6IKPXVCJ9.EYJPC3MIOJNAXRODWIUY29TIIWIYXVKICMF3LMDPDGH1YNVZXJJW50LMNVBSIMTLETUILCJLEHAIOJE3 MDG0MDAXMJISIim5izii6MTCWODM5OTGYMIWICGF0ACI6II8XNDAZMC8ZMDYXMJCTZMIZMJJJK1NTVLTGTGTGTMMFJZMTRINDUYLNBUZZ9999999999999999 YLUFTEI1BBGDCML0AG09QVDTNC1ITUFDLVNIQTI1NIQTI1NIZYLUFTEI1DCMVKZW50FSPUFLSUFWQ09EWUXTQTUFFLNFPBJGMJALMKZ1LYXN0LTELM KZZMYUYRMF3CMVXDWVZDCZYLUFTEI1EYXRLPTIWMJIWVDAZMZAYMLOMWC1BBXHWAXJLCZMDAMWC1BXJLPTG0DXJLPTG0DXG1Y2ZMNZK 0y2rjmtg2nwywywzmvkzjgymtbkowuznznm2ytzkzjjjymm2M2I4ZDHKNWNWC1BBXOTU2LNBMVHzgvycz1JMFJM2LKPTAMA2V5X2LKPPP Tamcmvwb19pzd0in0.rlyxvmst8tiUppu-P1ABQK-JCJU6RNGTXBFB80p8_lg)

Is there a way to control the rendering and export of the image after it is exported? Otherwise, it will feel unfriendly every time it is blank? And I’ve tested it many times and it’s all blank.

@Hk-Gosuto
Copy link
Owner

导出图像时用的第三方包 html-to-image, 我看了一下该包的函数没提供类似的参数,网络本身不太好的话这个也不好处理。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


The third-party package html-to-image is used when exporting images. I checked that the function of this package does not provide similar parameters. If the network itself is not good, this will not be easy to handle.

@zpng
Copy link
Author

zpng commented Feb 20, 2024

导出图像时用的第三方包 html-to-image, 我看了一下该包的函数没提供类似的参数,网络本身不太好的话这个也不好处理。

没有其它办法了吗,这个地方下载的使用体验感觉不是很好

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


The third-party package html-to-image is used when exporting images. I checked that the function of this package does not provide similar parameters. If the network itself is not good, this will not be easy to handle.

Is there no other way? The experience of downloading from this place is not very good.

@Hk-Gosuto
Copy link
Owner

暂时没什么好办法,那个包的 issues 里也有相关的问题但并没有解决。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


There is no good solution for the moment. There are also related problems in the issues of that package but they have not been solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants