translated & built

This commit is contained in:
2022-10-11 17:15:48 +02:00
parent c49e074d59
commit 78b854103a
7 changed files with 676 additions and 25 deletions

View File

@@ -1,9 +1,3 @@
/*
1.前后端解决协议传送首部行替换问题(使用ws模块)
2.读文件列表
3.是文件夹则继续读文件列表 是文件则传输文件
4.前端显示图片或者保存文件(使用filesaver.js)
*/
function webServer() {
const fs = require('fs');
@@ -11,21 +5,21 @@ function webServer() {
const wss = new WebSocket.Server({
port: 8989
}, () => {
console.log('websocket服务器建立')
console.log('websocket server started!')
})
const path = require('path')
const pathPublic = path.join(__dirname, '../source')
let currentPath = pathPublic
wss.on('connection', function (ws) {
console.log('客户端连接')
console.log('Client Connection Accepted')
ws.on('close', (e) => {
console.log(e)
})
ws.on('message', (message) => {
console.log(message)
if (message == 'hello server') {
ws.send('连接成功')
ws.send('hello, connection success!')
}
if (message == 'getFile') {
fs.readdir(pathPublic, function (err, files) {
@@ -54,7 +48,7 @@ function webServer() {
if (stat.isFile()) {
fs.readFile(path.join(pathPublic, message), (err, data) => {
console.log(path.join(pathPublic, message))
console.log('文件发送')
console.log('Pushing file..')
ws.send(data)
})