Fixed issue with public downloads not working, because of wrong encryption key

This commit is contained in:
subnub
2020-03-05 16:43:52 -05:00
parent a5affd5e89
commit 4e9025f77c
+5 -2
View File
@@ -11,6 +11,7 @@ const NotFoundError = require("../../utils/NotFoundError");
const env = require("../../enviroment/env");
const jwt = require("jsonwebtoken");
const removeChunks = require("./utils/removeChunks");
const User = require("../../models/user");
const Folder = require("../../models/folder");
@@ -220,7 +221,7 @@ const FileService = function() {
return new Promise((resolve, reject) => {
dbUtilsFile.getPublicFile(ID).then((file) => {
dbUtilsFile.getPublicFile(ID).then(async(file) => {
if (!file || !file.metadata.link || file.metadata.link !== tempToken) {
reject({
@@ -230,11 +231,13 @@ const FileService = function() {
})
} else {
const user = await User.findById(file.metadata.owner);
const bucket = new mongoose.mongo.GridFSBucket(conn.db, {
chunkSizeBytes: 1024 * 255,
})
const password = env.key;
const password = user.getEncryptionKey();
const IV = file.metadata.IV.buffer
const readStream = bucket.openDownloadStream(ObjectID(ID))