-
Notifications
You must be signed in to change notification settings - Fork 577
Expand file tree
/
Copy pathFileManagerRepository.cs
More file actions
70 lines (58 loc) · 2.2 KB
/
Copy pathFileManagerRepository.cs
File metadata and controls
70 lines (58 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using BlogEngine.Core.Data.Contracts;
using BlogEngine.Core.FileSystem;
using BlogEngine.Core.Providers;
using System;
using System.Collections.Generic;
namespace BlogEngine.Core.Data
{
public class FileManagerRepository : IFileManagerRepository
{
public IEnumerable<FileInstance> Find(int take = 10, int skip = 0, string path = "", string order = "")
{
if (!Security.IsAuthorizedTo(Rights.EditOwnPosts))
throw new UnauthorizedAccessException();
var list = new List<FileInstance>();
var rwr = Utils.RelativeWebRoot;
var responsePath = "root";
path = path.SanitizePath();
if(string.IsNullOrEmpty(path))
path = Blog.CurrentInstance.StorageLocation + Utils.FilesFolder;
var directory = BlogService.GetDirectory(path);
if (!directory.IsRoot)
{
list.Add(new FileInstance()
{
FileSize = "",
FileType = FileType.Directory,
Created = DateTime.Now.ToString(),
FullPath = directory.Parent.FullPath,
Name = "..."
});
responsePath = "root" + directory.FullPath;
}
foreach (var dir in directory.Directories)
list.Add(new FileInstance()
{
FileSize = "",
FileType = FileType.Directory,
Created = dir.DateCreated.ToString(),
FullPath = dir.FullPath,
Name = dir.Name.Replace("/", "")
});
foreach (var file in directory.Files)
list.Add(new FileInstance()
{
FileSize = file.FileSizeFormat,
Created = file.DateCreated.ToString(),
FileType = file.IsImage ? FileType.Image : FileType.File,
FullPath = file.FilePath,
Name = file.Name
});
for (int i = 0; i < list.Count; i++)
{
list[i].SortOrder = i;
}
return list;
}
}
}