修复问题

This commit is contained in:
ZhuoQinghui 2024-09-27 15:18:40 +08:00
parent 9870300952
commit 30a04ece2b
2 changed files with 2 additions and 2 deletions

View File

@ -20,7 +20,7 @@
const data = JSON.parse(event.data);
if (data.type === 'file') {
// 处理文件消息,例如显示文件下载链接
const fileUrl = data.url;
const fileUrl = window.location.origin + data.url;
const fileLink = document.createElement('a');
fileLink.href = fileUrl;
fileLink.target = '_blank';

View File

@ -29,7 +29,7 @@ app.use(express.static(path.join(__dirname, 'public')));
// 处理文件上传
app.post('/upload', upload.single('file'), (req, res) => {
const fileUrl = `http://localhost:3000/uploads/${req.file.filename}`;
const fileUrl = `/uploads/${req.file.filename}`;
wss.clients.forEach(function each(client) {
if (client.readyState === WebSocket.OPEN) {
client.send(JSON.stringify({ type: 'file', url: fileUrl }));