Browse Source

Fixed uploads 'saveKey' not being the be-all for saving key to server

tags/2.0.3
Teknikode 4 years ago
parent
commit
ebc61c218a

+ 3
- 3
Teknik/Areas/Upload/Controllers/UploadController.cs View File

@@ -42,7 +42,7 @@ namespace Teknik.Areas.Upload.Controllers
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Upload(string fileType, string fileExt, string iv, int keySize, int blockSize, bool encrypt, HttpPostedFileWrapper data, string key = null)
public ActionResult Upload(string fileType, string fileExt, string iv, int keySize, int blockSize, bool encrypt, bool saveKey, HttpPostedFileWrapper data, string key = null)
{
if (Config.UploadConfig.UploadEnabled)
{
@@ -70,7 +70,7 @@ namespace Teknik.Areas.Upload.Controllers
return Json(new { error = new { message = "Unable to encrypt file" } });
}
}
Models.Upload upload = Uploader.SaveFile(fileData, fileType, contentLength, fileExt, iv, key, keySize, blockSize);
Models.Upload upload = Uploader.SaveFile(fileData, fileType, contentLength, fileExt, iv, (saveKey) ? key : null, keySize, blockSize);
if (upload != null)
{
if (User.Identity.IsAuthenticated)
@@ -83,7 +83,7 @@ namespace Teknik.Areas.Upload.Controllers
db.SaveChanges();
}
}
return Json(new { result = new { name = upload.Url, url = Url.SubRouteUrl("upload", "Upload.Download", new { file = upload.Url }) } }, "text/plain");
return Json(new { result = new { name = upload.Url, url = Url.SubRouteUrl("upload", "Upload.Download", new { file = upload.Url }), key = key } }, "text/plain");
}
return Json(new { error = "Unable to upload file" });
}

+ 5
- 7
Teknik/Areas/Upload/Scripts/Upload.js View File

@@ -243,6 +243,7 @@ function uploadFile(data, key, iv, filetype, fileExt, fileID, saveKey, serverSid
fd.append('keySize', keySize);
fd.append('blockSize', blockSize);
fd.append('data', blob);
fd.append('saveKey', saveKey);
fd.append('encrypt', serverSideEncrypt);
fd.append('__RequestVerificationToken', $('#__AjaxAntiForgeryForm input[name=__RequestVerificationToken]').val());

@@ -267,7 +268,9 @@ function uploadComplete(fileID, key, saveKey, serverSideEncrypt, evt) {
obj = JSON.parse(evt.target.responseText);
var name = obj.result.name;
var fullName = obj.result.url;
if (!saveKey && !serverSideEncrypt) {
if (obj.result.key != null)
key = obj.result.key;
if (!saveKey) {
fullName = fullName + '#' + key;
}
$('#progress-' + fileID).children('.progress-bar').css('width', '100%');
@@ -281,9 +284,6 @@ function uploadComplete(fileID, key, saveKey, serverSideEncrypt, evt) {
<button type="button" class="btn btn-default btn-sm" id="remove-key-link-' + fileID + '">Remove Key From Server</button> \
</div>';
}
if (!saveKey && serverSideEncrypt) {
keyBtn = '';
}
$('#link-footer-' + fileID).html(' \
<div class="row"> \
' + keyBtn + ' \
@@ -299,9 +299,7 @@ function uploadComplete(fileID, key, saveKey, serverSideEncrypt, evt) {
linkRemoveKey('#remove-key-link-' + fileID + '', name, key, fileID);
}
else {
if (!serverSideEncrypt) {
linkSaveKey('#save-key-link-' + fileID + '', name, key, fileID);
}
linkSaveKey('#save-key-link-' + fileID + '', name, key, fileID);
}
linkUploadDelete('#generate-delete-link-' + fileID + '', name);
linkRemove('#remove-link-' + fileID + '', fileID);

Loading…
Cancel
Save