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
|
||||
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();
|
||||
DeleteFile(paste);
|
||||
return new StatusCodeResult(StatusCodes.Status404NotFound);
|
||||
}
|
||||
|
||||
@ -231,20 +219,7 @@ 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();
|
||||
DeleteFile(paste);
|
||||
return new StatusCodeResult(StatusCodes.Status404NotFound);
|
||||
}
|
||||
|
||||
@ -408,17 +383,7 @@ namespace Teknik.Areas.Paste.Controllers
|
||||
{
|
||||
if (foundPaste.User.Username == User.Identity.Name)
|
||||
{
|
||||
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();
|
||||
|
||||
// Delete the File
|
||||
if (System.IO.File.Exists(filePath))
|
||||
{
|
||||
System.IO.File.Delete(filePath);
|
||||
}
|
||||
DeleteFile(foundPaste);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
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);
|
||||
}
|
||||
DeleteFile(upload);
|
||||
return new StatusCodeResult(StatusCodes.Status404NotFound);
|
||||
}
|
||||
|
||||
@ -432,17 +422,7 @@ 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);
|
||||
}
|
||||
DeleteFile(upload);
|
||||
return Json(new { error = new { message = "File Does Not Exist" } });
|
||||
}
|
||||
|
||||
@ -500,17 +480,7 @@ namespace Teknik.Areas.Upload.Controllers
|
||||
model.File = file;
|
||||
if (!string.IsNullOrEmpty(upload.DeleteKey) && upload.DeleteKey == key)
|
||||
{
|
||||
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);
|
||||
}
|
||||
DeleteFile(upload);
|
||||
model.Deleted = true;
|
||||
}
|
||||
else
|
||||
@ -550,23 +520,28 @@ namespace Teknik.Areas.Upload.Controllers
|
||||
{
|
||||
if (foundUpload.User.Username == User.Identity.Name)
|
||||
{
|
||||
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();
|
||||
|
||||
// Delete the File
|
||||
if (System.IO.File.Exists(filePath))
|
||||
{
|
||||
System.IO.File.Delete(filePath);
|
||||
}
|
||||
|
||||
DeleteFile(foundUpload);
|
||||
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 = "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