Compare commits
2 Commits
c34c1a2d38
...
9f12482b30
Author | SHA1 | Date | |
---|---|---|---|
9f12482b30 | |||
a81b7c0a37 |
@ -7,6 +7,6 @@ const FileshareSchema = new mongoose.Schema({
|
|||||||
filename: { type: String, require: true },
|
filename: { type: String, require: true },
|
||||||
password: { type: String, require: true },
|
password: { type: String, require: true },
|
||||||
downloads: { type: Number, default: 0 },
|
downloads: { type: Number, default: 0 },
|
||||||
timestamp: { type: Date, default: Date.now },
|
createdAt: { type: Date, default: Date.now },
|
||||||
})
|
})
|
||||||
module.exports = mongoose.model('Fileshare', FileshareSchema)
|
module.exports = mongoose.model('Fileshare', FileshareSchema)
|
||||||
|
12
server.js
12
server.js
@ -45,6 +45,18 @@ app.post('/upload', upload.single('file'), async (req, res) => {
|
|||||||
console.table(file)
|
console.table(file)
|
||||||
res.status(201).render('index', { file })
|
res.status(201).render('index', { file })
|
||||||
})
|
})
|
||||||
|
app.get('/file/:id', async (req, res) => {
|
||||||
|
const file = await Fileshare.findByIdAndUpdate(req.params.id, { $inc: { downloads: 1 } })
|
||||||
|
if (file) {
|
||||||
|
const file_path = path.join(SAVE_PATH, file.md5)
|
||||||
|
if (file.password == '') {
|
||||||
|
res.status(200).download(file_path, file.filename)
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
res.sendStatus(404)
|
||||||
|
}
|
||||||
|
})
|
||||||
const server = app.listen(SERVER_PORT, SERVER_HOST, () => {
|
const server = app.listen(SERVER_PORT, SERVER_HOST, () => {
|
||||||
console.info(`server is running at http://${SERVER_HOST}:${SERVER_PORT}`)
|
console.info(`server is running at http://${SERVER_HOST}:${SERVER_PORT}`)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user