Skip to content
Snippets Groups Projects
Commit e68ed4b8 authored by nicolas.paschoud's avatar nicolas.paschoud
Browse files

Merge conflict in sql-request.js

parents 8943f25f 6ef37880
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..
......@@ -263,7 +263,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).")
}
})
/**
......
......@@ -167,6 +167,25 @@ async function addSharing(login, to_user, file_id){
}
}
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);
});
}
function createPath(path, user, callback) {
let parent = path.split("/");
parent.pop();
......@@ -185,3 +204,4 @@ exports.addPath = addPath;
exports.addSharing = addSharing;
exports.changeDirectory = changeDirectory;
exports.createPath = createPath;
exports.verifyFileID = verifyFileID;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment