Skip to content

Commit

Permalink
.Net Core Framework connector enhancement
Browse files Browse the repository at this point in the history
Added Recursive Searching support
Added GetInfo() function for completeness
Fixes psolom#308 - NaN shown instead of Create and Modify Datetime 
Fixed bug psolom#314, [Object:Object] instead of cannot find file/dir messages, etc
Reduced the overhead of the Summarize() function

** Image height and width information is not returned.
  • Loading branch information
JoeyWasHere authored Apr 23, 2018
1 parent c0383b7 commit 216266b
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions connectors/asp/FileManagerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
using Microsoft.AspNetCore.Cors;
using Microsoft.Azure.KeyVault.Models;

// using MetadataExtractor;

namespace API.NetCore.Controllers
{
[Route("[controller]")]

public class FileManagerController : Controller
{
private readonly string _webRootPath;
Expand Down Expand Up @@ -94,8 +93,9 @@ public IActionResult Index(string mode, string path, string name, List<IFormFile
catch (Exception e)
{
// returns all unhandeled exceptions and returns them in JSON format with 500.
// Issue #314, Cannot find file/dir message, etc
return new JsonResult(e.Message) {
// Issue #314
return new JsonResult(e.Message)
{
StatusCode = StatusCodes.Status500InternalServerError,
ContentType = "application/json"
};
Expand Down Expand Up @@ -144,11 +144,8 @@ private dynamic SeekFolder(string path, string search)
var searchPath = Path.Combine(_webRootPath, path);
var data = new List<dynamic>();

foreach (FileInfo file in new DirectoryInfo(searchPath).GetFiles( "*" + search + "*", SearchOption.AllDirectories))
foreach (FileInfo file in new DirectoryInfo(searchPath).GetFiles("*" + search + "*", SearchOption.AllDirectories))
{
IEnumerable<MetadataExtractor.Directory> md = MetadataExtractor.ImageMetadataReader.ReadMetadata(new FileStream(file.FullName, FileMode.Open));

// we could clean up this section by calling GetInfo(path)
var item = new
{
Id = MakeWebPath(Path.Combine(Path.GetRelativePath(_webRootPath, file.DirectoryName), file.Name), true),
Expand All @@ -163,7 +160,7 @@ private dynamic SeekFolder(string path, string search)
Modified = GetUnixTimestamp(file.LastWriteTimeUtc),
Size = file.Length,
Extension = file.Extension.TrimStart('.'),
// Insert Height and Width logic for images
// Insert Height and Width logic for images
Timestamp = DateTime.Now.Subtract(file.LastWriteTime).TotalSeconds
}
};
Expand Down Expand Up @@ -203,7 +200,6 @@ private dynamic GetInfo(string path)

var filePath = Path.Combine(_webRootPath, path);
FileInfo file = new FileInfo(path);
IEnumerable<MetadataExtractor.Directory> md = MetadataExtractor.ImageMetadataReader.ReadMetadata(new FileStream(filePath, FileMode.Open));

return new
{
Expand All @@ -221,12 +217,10 @@ private dynamic GetInfo(string path)
Modified = GetUnixTimestamp(file.LastWriteTimeUtc),
Size = file.Length,
Extension = file.Extension.TrimStart('.'),
// Insert Height and Width logic for images
Timestamp = DateTime.Now.Subtract(file.LastWriteTime).TotalSeconds
}
}
};

}

private dynamic ReadFolder(string path)
Expand Down Expand Up @@ -904,6 +898,7 @@ private dynamic Summarize()
}



private static void DirectoryCopy(string sourceDirName, string destDirName)
{
// Get the subdirectories for the specified directory.
Expand Down

0 comments on commit 216266b

Please sign in to comment.