Skip to content

Commit

Permalink
跳转链接,多个文件符合时,取名字较短者,过滤掉 -composite-
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Oct 18, 2024
1 parent bdcb0c6 commit 925df9c
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions EasyWeb/Services/EntryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,14 @@ public FileEntry GetLink(FileEntry entry)
}

private FileEntry MatchLink(Int32 storageId, Int32 parentId, String[] matchs)
{
return MatchLinks(storageId, parentId, matchs)
.OrderByDescending(e => e.Version)
.ThenBy(e => e.Name.Length)
.FirstOrDefault();
}

private IList<FileEntry> MatchLinks(Int32 storageId, Int32 parentId, String[] matchs)
{
var m = matchs[0];
var flag = true;
Expand All @@ -301,7 +309,7 @@ private FileEntry MatchLink(Int32 storageId, Int32 parentId, String[] matchs)
else
childs = childs.Where(e => !e.IsDirectory && !m.IsMatch(e.Name)).ToList();

return childs.OrderByDescending(e => e.LastWrite).FirstOrDefault();
return childs;
}
else
{
Expand All @@ -312,17 +320,21 @@ private FileEntry MatchLink(Int32 storageId, Int32 parentId, String[] matchs)
if (childs.Count == 0) return null;

// 递归查找子目录,找到最新的文件
FileEntry fe = null;
var links = new List<FileEntry>();
foreach (var item in childs)
{
var rs = MatchLink(storageId, item.Id, matchs[1..]);
if (rs != null && (fe == null || rs.Version > fe.Version))
{
fe = rs;
}
var rs = MatchLinks(storageId, item.Id, matchs[1..]);
if (rs != null) links.AddRange(rs);
}

return fe;
//var fe = links.OrderByDescending(e => e.Version).FirstOrDefault();
//return fe;
if (links.Count > 0)
{
var max = links.Max(e => e.Version);
links = links.Where(e => e.Version == max).ToList();
}
return links;
}
}

Expand Down

0 comments on commit 925df9c

Please sign in to comment.