public async Task <IActionResult> DeleteFile(DeleteFileAddressModel model) { var(folders, fileName) = _folderLocator.SplitToFoldersAndFile(model.FolderNames); var folder = await _folderLocator.LocateSiteAndFolder(model.AccessToken, model.SiteName, folders); if (folder == null) { return(this.Protocol(ErrorType.NotFound, "Locate folder failed!")); } var file = folder.Files.SingleOrDefault(t => t.FileName == fileName); if (file == null) { return(this.Protocol(ErrorType.NotFound, "The file cannot be found. Maybe it has been deleted.")); } await _folderCleaner.DeleteFile(file); await _dbContext.SaveChangesAsync(); return(this.Protocol(ErrorType.Success, $"Successfully deleted the file '{file.FileName}'")); }
public async Task <IActionResult> Open(OpenAddressModel model) { var site = await _dbContext .Sites .Include(t => t.Root) .SingleOrDefaultAsync(t => t.SiteName.ToLower() == model.SiteName); if (site == null) { return(NotFound()); } if (!site.OpenToDownload) { _tokenEnsurer.Ensure(model.PBToken, "Download", model.SiteName, model.FolderNames); } var(folders, fileName) = _folderLocator.SplitToFoldersAndFile(model.FolderNames); try { var folder = await _folderLocator.LocateAsync(folders, site.Root, false); if (folder == null) { return(NotFound()); } var file = folder.Files.SingleOrDefault(t => t.FileName == fileName); if (file == null) { return(NotFound()); } var path = _storageProvider.GetFilePath(file.HardwareId); var extension = _storageProvider.GetExtension(file.FileName); if (ControllerContext.ActionDescriptor.AttributeRouteInfo.Name == "File") { return(this.WebFile(path, "do-not-open")); } else if (file.FileName.IsStaticImage() && Image.DetectFormat(path) != null) { return(await FileWithImageCompressor(path, extension)); } else { return(this.WebFile(path, extension)); } } catch (AiurAPIModelException e) when(e.Code == ErrorType.NotFound) { return(NotFound()); } }