修复问题
This commit is contained in:
parent
9870300952
commit
30a04ece2b
|
@ -20,7 +20,7 @@
|
||||||
const data = JSON.parse(event.data);
|
const data = JSON.parse(event.data);
|
||||||
if (data.type === 'file') {
|
if (data.type === 'file') {
|
||||||
// 处理文件消息,例如显示文件下载链接
|
// 处理文件消息,例如显示文件下载链接
|
||||||
const fileUrl = data.url;
|
const fileUrl = window.location.origin + data.url;
|
||||||
const fileLink = document.createElement('a');
|
const fileLink = document.createElement('a');
|
||||||
fileLink.href = fileUrl;
|
fileLink.href = fileUrl;
|
||||||
fileLink.target = '_blank';
|
fileLink.target = '_blank';
|
||||||
|
|
|
@ -29,7 +29,7 @@ app.use(express.static(path.join(__dirname, 'public')));
|
||||||
|
|
||||||
// 处理文件上传
|
// 处理文件上传
|
||||||
app.post('/upload', upload.single('file'), (req, res) => {
|
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) {
|
wss.clients.forEach(function each(client) {
|
||||||
if (client.readyState === WebSocket.OPEN) {
|
if (client.readyState === WebSocket.OPEN) {
|
||||||
client.send(JSON.stringify({ type: 'file', url: fileUrl }));
|
client.send(JSON.stringify({ type: 'file', url: fileUrl }));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user