@@ -222,11 +222,36 @@ namespace Teknik.ServiceWorker | |||
// Process uploads | |||
List<Upload> uploads = db.Uploads.Where(u => u.ExpireDate != null && u.ExpireDate < curDate).ToList(); | |||
foreach (Upload upload in uploads) | |||
{ | |||
string subDir = upload.FileName[0].ToString(); | |||
string filePath = Path.Combine(config.UploadConfig.UploadDirectory, subDir, upload.FileName); | |||
// Delete the File | |||
if (File.Exists(filePath)) | |||
{ | |||
File.Delete(filePath); | |||
} | |||
} | |||
db.RemoveRange(uploads); | |||
db.SaveChanges(); | |||
// Process Pastes | |||
List<Paste> pastes = db.Pastes.Where(p => p.ExpireDate != null && p.ExpireDate < curDate).ToList(); | |||
foreach (Paste paste in pastes) | |||
{ | |||
string subDir = paste.FileName[0].ToString(); | |||
string filePath = Path.Combine(config.PasteConfig.PasteDirectory, subDir, paste.FileName); | |||
// Delete the File | |||
if (File.Exists(filePath)) | |||
{ | |||
File.Delete(filePath); | |||
} | |||
} | |||
db.RemoveRange(pastes); | |||
db.SaveChanges(); | |||
} |
@@ -57,6 +57,17 @@ namespace Teknik.Areas.Paste.Controllers | |||
// Check Expiration | |||
if (PasteHelper.CheckExpiration(paste)) | |||
{ | |||
if (!string.IsNullOrEmpty(paste.FileName)) | |||
{ | |||
string delSub = paste.FileName[0].ToString(); | |||
string delPath = Path.Combine(_config.PasteConfig.PasteDirectory, delSub, paste.FileName); | |||
// Delete the File | |||
if (System.IO.File.Exists(delPath)) | |||
{ | |||
System.IO.File.Delete(delPath); | |||
} | |||
} | |||
_dbContext.Pastes.Remove(paste); | |||
_dbContext.SaveChanges(); | |||
return new StatusCodeResult(StatusCodes.Status404NotFound); | |||
@@ -220,6 +231,18 @@ namespace Teknik.Areas.Paste.Controllers | |||
// Check Expiration | |||
if (PasteHelper.CheckExpiration(paste)) | |||
{ | |||
if (!string.IsNullOrEmpty(paste.FileName)) | |||
{ | |||
string delSub = paste.FileName[0].ToString(); | |||
string delPath = Path.Combine(_config.PasteConfig.PasteDirectory, delSub, paste.FileName); | |||
// Delete the File | |||
if (System.IO.File.Exists(delPath)) | |||
{ | |||
System.IO.File.Delete(delPath); | |||
} | |||
} | |||
// Delete from the DB | |||
_dbContext.Pastes.Remove(paste); | |||
_dbContext.SaveChanges(); | |||
return new StatusCodeResult(StatusCodes.Status404NotFound); | |||
@@ -377,6 +400,7 @@ namespace Teknik.Areas.Paste.Controllers | |||
} | |||
[HttpPost] | |||
[HttpOptions] | |||
public IActionResult Delete(string id) | |||
{ | |||
Models.Paste foundPaste = _dbContext.Pastes.Where(p => p.Url == id).FirstOrDefault(); | |||
@@ -384,7 +408,8 @@ namespace Teknik.Areas.Paste.Controllers | |||
{ | |||
if (foundPaste.User.Username == User.Identity.Name) | |||
{ | |||
string filePath = foundPaste.FileName; | |||
string subDir = foundPaste.FileName[0].ToString(); | |||
string filePath = Path.Combine(_config.PasteConfig.PasteDirectory, subDir, foundPaste.FileName); | |||
// Delete from the DB | |||
_dbContext.Pastes.Remove(foundPaste); | |||
_dbContext.SaveChanges(); |
@@ -79,6 +79,7 @@ namespace Teknik.Areas.Shortener.Controllers | |||
} | |||
[HttpPost] | |||
[HttpOptions] | |||
public IActionResult Delete(string id) | |||
{ | |||
ShortenedUrl shortenedUrl = _dbContext.ShortenedUrls.Where(s => s.ShortUrl == id).FirstOrDefault(); |
@@ -203,8 +203,17 @@ namespace Teknik.Areas.Upload.Controllers | |||
// Check Expiration | |||
if (UploadHelper.CheckExpiration(upload)) | |||
{ | |||
string subDir = upload.FileName[0].ToString(); | |||
string filePath = Path.Combine(_config.UploadConfig.UploadDirectory, subDir, upload.FileName); | |||
// Delete from the DB | |||
_dbContext.Uploads.Remove(upload); | |||
_dbContext.SaveChanges(); | |||
// Delete the File | |||
if (System.IO.File.Exists(filePath)) | |||
{ | |||
System.IO.File.Delete(filePath); | |||
} | |||
return new StatusCodeResult(StatusCodes.Status404NotFound); | |||
} | |||
@@ -423,8 +432,17 @@ namespace Teknik.Areas.Upload.Controllers | |||
// Check Expiration | |||
if (UploadHelper.CheckExpiration(upload)) | |||
{ | |||
string delDir = upload.FileName[0].ToString(); | |||
string delPath = Path.Combine(_config.UploadConfig.UploadDirectory, delDir, upload.FileName); | |||
// Delete from the DB | |||
_dbContext.Uploads.Remove(upload); | |||
_dbContext.SaveChanges(); | |||
// Delete the File | |||
if (System.IO.File.Exists(delPath)) | |||
{ | |||
System.IO.File.Delete(delPath); | |||
} | |||
return Json(new { error = new { message = "File Does Not Exist" } }); | |||
} | |||
@@ -482,7 +500,8 @@ namespace Teknik.Areas.Upload.Controllers | |||
model.File = file; | |||
if (!string.IsNullOrEmpty(upload.DeleteKey) && upload.DeleteKey == key) | |||
{ | |||
string filePath = upload.FileName; | |||
string subDir = upload.FileName[0].ToString(); | |||
string filePath = Path.Combine(_config.UploadConfig.UploadDirectory, subDir, upload.FileName); | |||
// Delete from the DB | |||
_dbContext.Uploads.Remove(upload); | |||
_dbContext.SaveChanges(); | |||
@@ -523,6 +542,7 @@ namespace Teknik.Areas.Upload.Controllers | |||
} | |||
[HttpPost] | |||
[HttpOptions] | |||
public IActionResult Delete(string id) | |||
{ | |||
Models.Upload foundUpload = _dbContext.Uploads.Where(u => u.Url == id).FirstOrDefault(); | |||
@@ -530,7 +550,8 @@ namespace Teknik.Areas.Upload.Controllers | |||
{ | |||
if (foundUpload.User.Username == User.Identity.Name) | |||
{ | |||
string filePath = foundUpload.FileName; | |||
string subDir = foundUpload.FileName[0].ToString(); | |||
string filePath = Path.Combine(_config.UploadConfig.UploadDirectory, subDir, foundUpload.FileName); | |||
// Delete from the DB | |||
_dbContext.Uploads.Remove(foundUpload); | |||
_dbContext.SaveChanges(); |
@@ -1396,5 +1396,36 @@ namespace Teknik.Areas.Users.Controllers | |||
return Json(new { error = ex.GetFullMessage(true) }); | |||
} | |||
} | |||
[HttpPost] | |||
[ValidateAntiForgeryToken] | |||
public IActionResult DeleteData(string type, string id) | |||
{ | |||
var context = new ControllerContext(); | |||
context.HttpContext = Request.HttpContext; | |||
context.RouteData = RouteData; | |||
context.ActionDescriptor = new Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor(); | |||
switch (type) | |||
{ | |||
case "upload": | |||
var uploadController = new Upload.Controllers.UploadController(_logger, _config, _dbContext); | |||
uploadController.ControllerContext = context; | |||
return uploadController.Delete(id); | |||
case "paste": | |||
var pasteController = new Paste.Controllers.PasteController(_logger, _config, _dbContext); | |||
pasteController.ControllerContext = context; | |||
return pasteController.Delete(id); | |||
case "shortenedUrl": | |||
var shortenController = new Shortener.Controllers.ShortenerController(_logger, _config, _dbContext); | |||
shortenController.ControllerContext = context; | |||
return shortenController.Delete(id); | |||
case "vault": | |||
var vaultController = new Vault.Controllers.VaultController(_logger, _config, _dbContext); | |||
vaultController.ControllerContext = context; | |||
return vaultController.Delete(id); | |||
} | |||
return Json(new { error = "Invalid Type" }); | |||
} | |||
} | |||
} |
@@ -1,10 +1,7 @@ | |||
@model Teknik.Areas.Users.ViewModels.ViewServiceDataViewModel | |||
<script> | |||
var deleteUploadURL = '@Url.SubRouteUrl("u", "Upload.Delete")'; | |||
var deletePasteURL = '@Url.SubRouteUrl("p", "Paste.Delete")'; | |||
var deleteShortenURL = '@Url.SubRouteUrl("s", "Shortener.Delete")'; | |||
var deleteVaultURL = '@Url.SubRouteUrl("v", "Vault.Delete")'; | |||
var deleteDataURL = '@Url.SubRouteUrl("account", "User.Action", new { action = "DeleteData" })'; | |||
</script> | |||
<div class="container"> |
@@ -428,6 +428,7 @@ namespace Teknik.Areas.Vault.Controllers | |||
} | |||
[HttpPost] | |||
[HttpOptions] | |||
public IActionResult Delete(string id) | |||
{ | |||
Vault.Models.Vault foundVault = _dbContext.Vaults.Where(v => v.Url == id).FirstOrDefault(); |
@@ -22,6 +22,7 @@ | |||
"importScripts": false, | |||
"CryptoJS": false, | |||
"Uint8Array": false, | |||
"Oidc": false, | |||
// Common.js Functions | |||
"deleteConfirm": false, | |||
@@ -46,6 +47,9 @@ | |||
"isValidURL": false, | |||
"pageloadTimerCount": false, | |||
"pageloadDoTimer": false, | |||
"pageloadStopTimer": false | |||
"pageloadStopTimer": false, | |||
// Common variables | |||
"oidcConfig": false | |||
} | |||
} |
@@ -1,27 +1,27 @@ | |||
/* globals deleteUploadURL, deletePasteURL, deleteShortenURL, deleteVaultURL */ | |||
/* globals deleteDataURL */ | |||
$(document).ready(function () { | |||
$('.delete-upload-button').click(function () { | |||
var id = $(this).data('upload-id'); | |||
var element = $('#uploads [id="' + id + '"'); | |||
deleteItem(deleteUploadURL, id, element, "Are you sure you want to delete this upload?"); | |||
deleteItem('upload', id, element, "Are you sure you want to delete this upload?"); | |||
}); | |||
$('.delete-paste-button').click(function () { | |||
var id = $(this).data('paste-id'); | |||
var element = $('#pastes [id="' + id + '"'); | |||
deleteItem(deletePasteURL, id, element, "Are you sure you want to delete this paste?"); | |||
deleteItem('paste', id, element, "Are you sure you want to delete this paste?"); | |||
}); | |||
$('.delete-shorten-button').click(function () { | |||
var id = $(this).data('shorten-id'); | |||
var element = $('#shortenedUrls [id="' + id + '"'); | |||
deleteItem(deleteShortenURL, id, element, "Are you sure you want to delete this shortened url?"); | |||
deleteItem('shortenedUrl', id, element, "Are you sure you want to delete this shortened url?"); | |||
}); | |||
$('.delete-vault-button').click(function () { | |||
var id = $(this).data('vault-id'); | |||
var element = $('#vaults [id="' + id + '"'); | |||
deleteItem(deleteVaultURL, id, element, "Are you sure you want to delete this vault?"); | |||
deleteItem('vault', id, element, "Are you sure you want to delete this vault?"); | |||
}); | |||
$('a[data-toggle="tab"]').on('shown.bs.tab', function () { | |||
@@ -36,14 +36,16 @@ $(document).ready(function () { | |||
} | |||
}); | |||
function deleteItem(url, id, element, confirmationMsg) { | |||
function deleteItem(type, id, element, confirmationMsg) { | |||
deleteConfirm(confirmationMsg, function (result) { | |||
if (result) { | |||
$.ajax({ | |||
type: "POST", | |||
url: url, | |||
data: { id: id }, | |||
headers: { 'X-Requested-With': 'XMLHttpRequest' }, | |||
url: deleteDataURL, | |||
data: AddAntiForgeryToken({ type: type, id: id }), | |||
headers: { | |||
'X-Requested-With': 'XMLHttpRequest' | |||
}, | |||
xhrFields: { | |||
withCredentials: true | |||
}, |
@@ -42,6 +42,7 @@ var assets = [ | |||
{ './node_modules/marked/lib/marked.js': 'lib/marked/js' }, | |||
{ './node_modules/sanitize-html/dist/sanitize-html.js': 'lib/sanitize-html/js' }, | |||
{ './node_modules/underscore/underscore.js': 'lib/underscore/js' }, | |||
{ './node_modules/oidc-client/dist/oidc-client.js': 'lib/oidc-client/js' }, | |||
// App JS Files | |||
{ './Scripts/**/*': 'js/app' }, |
@@ -16,6 +16,7 @@ | |||
"jquery": "^3.3.1", | |||
"jquery-validation": "^1.17.0", | |||
"marked": "^0.4.0", | |||
"oidc-client": "^1.6.1", | |||
"sanitize-html": "^1.18.2", | |||
"underscore": "^1.9.1" | |||
}, |