mirror of
https://git.teknik.io/Teknikode/Teknik.git
synced 2023-08-02 14:16:22 +02:00
Fixed paste and upload file deletion
This commit is contained in:
parent
94546b1881
commit
372997f995
@ -57,19 +57,7 @@ namespace Teknik.Areas.Paste.Controllers
|
|||||||
// Check Expiration
|
// Check Expiration
|
||||||
if (PasteHelper.CheckExpiration(paste))
|
if (PasteHelper.CheckExpiration(paste))
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(paste.FileName))
|
DeleteFile(paste);
|
||||||
{
|
|
||||||
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);
|
return new StatusCodeResult(StatusCodes.Status404NotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,20 +219,7 @@ namespace Teknik.Areas.Paste.Controllers
|
|||||||
// Check Expiration
|
// Check Expiration
|
||||||
if (PasteHelper.CheckExpiration(paste))
|
if (PasteHelper.CheckExpiration(paste))
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(paste.FileName))
|
DeleteFile(paste);
|
||||||
{
|
|
||||||
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);
|
return new StatusCodeResult(StatusCodes.Status404NotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,17 +383,7 @@ namespace Teknik.Areas.Paste.Controllers
|
|||||||
{
|
{
|
||||||
if (foundPaste.User.Username == User.Identity.Name)
|
if (foundPaste.User.Username == User.Identity.Name)
|
||||||
{
|
{
|
||||||
string subDir = foundPaste.FileName[0].ToString();
|
DeleteFile(foundPaste);
|
||||||
string filePath = Path.Combine(_config.PasteConfig.PasteDirectory, subDir, foundPaste.FileName);
|
|
||||||
// Delete from the DB
|
|
||||||
_dbContext.Pastes.Remove(foundPaste);
|
|
||||||
_dbContext.SaveChanges();
|
|
||||||
|
|
||||||
// Delete the File
|
|
||||||
if (System.IO.File.Exists(filePath))
|
|
||||||
{
|
|
||||||
System.IO.File.Delete(filePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Json(new { result = true, redirect = Url.SubRouteUrl("p", "Paste.Index") });
|
return Json(new { result = true, redirect = Url.SubRouteUrl("p", "Paste.Index") });
|
||||||
}
|
}
|
||||||
@ -451,5 +416,24 @@ namespace Teknik.Areas.Paste.Controllers
|
|||||||
HttpContext.Session.Remove("PastePassword_" + url);
|
HttpContext.Session.Remove("PastePassword_" + url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void DeleteFile(Models.Paste 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -203,17 +203,7 @@ namespace Teknik.Areas.Upload.Controllers
|
|||||||
// Check Expiration
|
// Check Expiration
|
||||||
if (UploadHelper.CheckExpiration(upload))
|
if (UploadHelper.CheckExpiration(upload))
|
||||||
{
|
{
|
||||||
string subDir = upload.FileName[0].ToString();
|
DeleteFile(upload);
|
||||||
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);
|
return new StatusCodeResult(StatusCodes.Status404NotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -432,17 +422,7 @@ namespace Teknik.Areas.Upload.Controllers
|
|||||||
// Check Expiration
|
// Check Expiration
|
||||||
if (UploadHelper.CheckExpiration(upload))
|
if (UploadHelper.CheckExpiration(upload))
|
||||||
{
|
{
|
||||||
string delDir = upload.FileName[0].ToString();
|
DeleteFile(upload);
|
||||||
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" } });
|
return Json(new { error = new { message = "File Does Not Exist" } });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -500,17 +480,7 @@ namespace Teknik.Areas.Upload.Controllers
|
|||||||
model.File = file;
|
model.File = file;
|
||||||
if (!string.IsNullOrEmpty(upload.DeleteKey) && upload.DeleteKey == key)
|
if (!string.IsNullOrEmpty(upload.DeleteKey) && upload.DeleteKey == key)
|
||||||
{
|
{
|
||||||
string subDir = upload.FileName[0].ToString();
|
DeleteFile(upload);
|
||||||
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);
|
|
||||||
}
|
|
||||||
model.Deleted = true;
|
model.Deleted = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -550,23 +520,28 @@ namespace Teknik.Areas.Upload.Controllers
|
|||||||
{
|
{
|
||||||
if (foundUpload.User.Username == User.Identity.Name)
|
if (foundUpload.User.Username == User.Identity.Name)
|
||||||
{
|
{
|
||||||
string subDir = foundUpload.FileName[0].ToString();
|
DeleteFile(foundUpload);
|
||||||
string filePath = Path.Combine(_config.UploadConfig.UploadDirectory, subDir, foundUpload.FileName);
|
|
||||||
// Delete from the DB
|
|
||||||
_dbContext.Uploads.Remove(foundUpload);
|
|
||||||
_dbContext.SaveChanges();
|
|
||||||
|
|
||||||
// Delete the File
|
|
||||||
if (System.IO.File.Exists(filePath))
|
|
||||||
{
|
|
||||||
System.IO.File.Delete(filePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Json(new { result = true });
|
return Json(new { result = true });
|
||||||
}
|
}
|
||||||
return Json(new { error = new { message = "You do not have permission to edit this Paste" } });
|
return Json(new { error = new { message = "You do not have permission to edit this Paste" } });
|
||||||
}
|
}
|
||||||
return Json(new { error = new { message = "This Paste does not exist" } });
|
return Json(new { error = new { message = "This Upload does not exist" } });
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DeleteFile(Models.Upload upload)
|
||||||
|
{
|
||||||
|
string subDir = upload.FileName[0].ToString();
|
||||||
|
string filePath = Path.Combine(_config.UploadConfig.UploadDirectory, subDir, upload.FileName);
|
||||||
|
|
||||||
|
// Delete the File
|
||||||
|
if (System.IO.File.Exists(filePath))
|
||||||
|
{
|
||||||
|
System.IO.File.Delete(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete from the DB
|
||||||
|
_dbContext.Uploads.Remove(upload);
|
||||||
|
_dbContext.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user