forked from Tubaleviao/file-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio.js
25 lines (23 loc) · 766 Bytes
/
io.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const {existsSync, mkdirSync, readdir} = require('fs')
const upio = require('up.io')
const path = require('path')
module.exports.con = (init) => async socket => {
var uploader = new upio()
if (!existsSync(init)) mkdirSync(init, { recursive: true })
uploader.dir = init;
uploader.listen(socket)
console.log("connected")
socket.on('path', async location => {
const files = []
uploader.dir = path.join(uploader.dir, path.relative(uploader.dir, location))
let parent = path.parse(location).dir
readdir(location, {withFileTypes: true}, (err, dir) => {
for (const f of dir) files.push({
name: f.name,
path: path.join(location, f.name),
isFile: f.isFile(),
})
socket.emit('files', {files, location, parent})
})
})
}