mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-04-07 14:06:11 +08:00
csharp: improved GetFilesInfo
This commit is contained in:
@ -383,22 +383,22 @@ namespace OnlineEditorsExample
|
||||
return storedFiles;
|
||||
}
|
||||
|
||||
public static List<Dictionary<string, string>> GetFilesInfo(string idFile = null)
|
||||
public static List<Dictionary<string, object>> GetFilesInfo(string fileId = null)
|
||||
{
|
||||
var files = new List<Dictionary<string, string>>();
|
||||
var files = new List<Dictionary<string, object>>();
|
||||
|
||||
foreach (var file in GetStoredFiles())
|
||||
{
|
||||
var dictionary = new Dictionary<string, string>();
|
||||
dictionary.Add("version", GetFileVersion(file.Name, null).ToString());
|
||||
var dictionary = new Dictionary<string, object>();
|
||||
dictionary.Add("version", GetFileVersion(file.Name, null));
|
||||
dictionary.Add("id", ServiceConverter.GenerateRevisionId(_Default.CurUserHostAddress(null) + "/" + file.Name + "/" + File.GetLastWriteTime(_Default.StoragePath(file.Name, null)).GetHashCode()));
|
||||
dictionary.Add("contentLength", Math.Round(file.Length / 1024.0, 2) + " KB");
|
||||
dictionary.Add("pureContentLength", file.Length.ToString());
|
||||
dictionary.Add("pureContentLength", file.Length);
|
||||
dictionary.Add("title", file.Name);
|
||||
dictionary.Add("updated", file.LastWriteTime.ToString());
|
||||
if (idFile != null)
|
||||
if (fileId != null)
|
||||
{
|
||||
if (idFile.Equals(dictionary["id"]))
|
||||
if (fileId.Equals(dictionary["id"]))
|
||||
{
|
||||
files.Add(dictionary);
|
||||
break;
|
||||
|
||||
@ -240,23 +240,31 @@ namespace OnlineEditorsExample
|
||||
|
||||
private static void Files(HttpContext context)
|
||||
{
|
||||
List<Dictionary<string, string>> files = null;
|
||||
List<Dictionary<string, object>> files = null;
|
||||
|
||||
try
|
||||
{
|
||||
var idFile = context.Request["id"];
|
||||
if (idFile == null)
|
||||
context.Response.ContentType = "application/json";
|
||||
var jss = new JavaScriptSerializer();
|
||||
|
||||
if (context.Request["fileId"] == null)
|
||||
{
|
||||
files = _Default.GetFilesInfo();
|
||||
context.Response.Write(jss.Serialize(files));
|
||||
}
|
||||
else
|
||||
{
|
||||
files = _Default.GetFilesInfo(idFile);
|
||||
var fileId = context.Request["fileId"];
|
||||
files = _Default.GetFilesInfo(fileId);
|
||||
if (files.Count == 0)
|
||||
{
|
||||
context.Response.Write("\"File not found\"");
|
||||
}
|
||||
else
|
||||
{
|
||||
context.Response.Write(jss.Serialize(files));
|
||||
}
|
||||
}
|
||||
|
||||
context.Response.ContentType = "application/json";
|
||||
var jss = new JavaScriptSerializer();
|
||||
context.Response.Write(jss.Serialize(files));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user