Powtóreczka
This commit is contained in:
1 parent
e80734527f
commit
c1348ef991
648 files changed
+66782
No files matched your search
@@ -0,0 +1,52 @@
|
||||
const express = require("express")
|
||||
const app = express()
|
||||
const PORT = 3000
|
||||
|
||||
const path = require('path')
|
||||
const formidable = require('formidable')
|
||||
const fs = require('fs')
|
||||
|
||||
app.use(express.json())
|
||||
|
||||
app.use(express.urlencoded({
|
||||
extended: true
|
||||
}));
|
||||
|
||||
app.post('/handleUpload', function(req, res) {
|
||||
let form = formidable({})
|
||||
|
||||
form.keepExtensions = true
|
||||
|
||||
form.uploadDir = __dirname + '/rzeczy/upload/'
|
||||
|
||||
form.parse(req, function(err, fields, files) {
|
||||
// tu dopiszemy rzeczy
|
||||
const sciezka = files.file.path
|
||||
const nazwa_pliku_dla_klienta = "/upload" + sciezka.substr(sciezka.lastIndexOf("/"), sciezka.length - sciezka.lastIndexOf("/"))
|
||||
|
||||
if (files.file.type.substr(0, 5) == "image") {
|
||||
const odpowiedz = {
|
||||
nazwa_pliku: nazwa_pliku_dla_klienta,
|
||||
typ: "obrazek"
|
||||
}
|
||||
|
||||
res.send(JSON.stringify(odpowiedz))
|
||||
} else {
|
||||
fs.readFile(files.file.path, function(err, data) {
|
||||
const odpowiedz = {
|
||||
nazwa_pliku: nazwa_pliku_dla_klienta,
|
||||
typ: "tekst",
|
||||
tresc: data.toString()
|
||||
}
|
||||
|
||||
res.send(JSON.stringify(odpowiedz))
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
app.use(express.static('rzeczy'))
|
||||
|
||||
app.listen(PORT, function () {
|
||||
console.log("start serwera na porcie " + PORT )
|
||||
})
|
||||
Reference in new issue
Block a user