Skip to content
Snippets Groups Projects
Commit 6ef37880 authored by noe.fleury's avatar noe.fleury :computer:
Browse files

Possibility to download files / Added files for example

parent f371d40e
No related branches found
No related tags found
No related merge requests found
......@@ -68,8 +68,8 @@ VALUES
("@dfsg", "trois", "/c/test", 46.2054, 6.1459),
("gbvaf", "quatre", "/b", 46.2054, 6.1459),
("dsfgh", "cinq", "/d", 46.2054, 6.1459),
("sdfa", "six", "/e", 46.2054, 6.1459),
("liblb", "myfile", "/n", 46.2054, 6.1459);
("sdfa", "six.txt", "/e", 46.2054, 6.1459),
("liblb", "myfile.txt", "/n", 46.2054, 6.1459);
INSERT INTO Shares
VALUES
......
coucou nicolas
nothing to see here..
......@@ -281,7 +281,28 @@ app.get('/upload/', (req, res) => {
})
app.get('/download/:file_id', (req, res) => {
res.send(`Request for a download (${req.params['file_id']})`)
// res.send(`Request for a download (${req.params['file_id']})`)
token = req.query["token"]
file_id = req.params["file_id"]
user = verify_token(token);
if (user){
sql.verifyFileID(user, file_id, (filename) => {
console.log(filename)
if (filename){
res.download("files/" + file_id, filename);
}
else{
res.send("Can't download (not your file).")
}
})
}
else{
res.send("Can't download (please be connected).")
}
})
/**
......
......@@ -193,7 +193,25 @@ async function addSharing(login, to_user, file_id){
else{
return "Unable to share, this is not your file.";
}
}
async function verifyFileID(login, file_id, callback){
let q = `SELECT (file_name) FROM Files as F LEFT JOIN Paths as P ON F.paths = P.paths WHERE F.file_id = '${file_id}' AND P.login = '${login}';`
con.query(q, (err, res) => {
if (err) {
console.log("Error while verifying file_id");
return callback(false);
}
console.log(res)
if (res.length > 0)
filename = res[0].file_name;
else
filename = false;
return callback(filename);
});
}
......@@ -202,3 +220,4 @@ exports.addUser = addUser;
exports.addPath = addPath;
exports.addSharing = addSharing;
exports.changeDirectory = changeDirectory;
exports.verifyFileID = verifyFileID;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment