Files: added new interface

This commit is contained in:
pavelbannov 2020-02-28 14:32:11 +03:00
parent 697b03ab6f
commit 8e06c42740
5 changed files with 539 additions and 1 deletions

View File

@ -279,7 +279,12 @@ namespace ASC.Api.Documents
public FolderContentWrapper GetFolder(string folderId, Guid userIdOrGroupId, FilterType filterType)
{
return ToFolderContentWrapper(folderId, userIdOrGroupId, filterType).NotFoundIfNull();
}
[Read("{folderId:int}", order: int.MaxValue)]
public FolderContentWrapper GetFolder(int folderId, Guid userIdOrGroupId, FilterType filterType)
{
return ToFolderContentWrapper(folderId, userIdOrGroupId, filterType).NotFoundIfNull();
}
/// <summary>
@ -822,6 +827,19 @@ namespace ASC.Api.Documents
return FileWrapperHelper.Get(file);
}
/// <summary>
/// Returns a detailed information about the file with the ID specified in the request
/// </summary>
/// <short>File information</short>
/// <category>Files</category>
/// <returns>File info</returns>
[Read("file/{fileId:int}")]
public FileWrapper GetFileInfo(int fileId, int version = -1)
{
var file = FileStorageService.GetFile(fileId, version).NotFoundIfNull("File not found");
return FileWrapperHelper.Get(file);
}
/// <summary>
/// Updates the information of the selected file with the parameters specified in the request
/// </summary>

View File

@ -32,6 +32,268 @@ using ASC.Web.Files.Services.DocumentService;
namespace ASC.Files.Core
{
public interface IFileDao<T>
{
/// <summary>
/// Clear the application cache for the specific file
/// </summary>
void InvalidateCache(T fileId);
/// <summary>
/// Receive file
/// </summary>
/// <param name="fileId">file id</param>
/// <returns></returns>
File<T> GetFile(T fileId);
/// <summary>
/// Receive file
/// </summary>
/// <param name="fileId">file id</param>
/// <param name="fileVersion">file version</param>
/// <returns></returns>
File<T> GetFile(T fileId, int fileVersion);
/// <summary>
/// Receive file
/// </summary>
/// <param name="parentId">folder id</param>
/// <param name="title">file name</param>
/// <returns>
/// file
/// </returns>
File<T> GetFile(T parentId, string title);
/// <summary>
/// Receive last file without forcesave
/// </summary>
/// <param name="fileId">file id</param>
/// <param name="fileVersion"></param>
/// <returns></returns>
File<T> GetFileStable(T fileId, int fileVersion = -1);
/// <summary>
/// Returns all versions of the file
/// </summary>
/// <param name="fileId"></param>
/// <returns></returns>
List<File<T>> GetFileHistory(T fileId);
/// <summary>
/// Gets the file (s) by ID (s)
/// </summary>
/// <param name="fileIds">id file</param>
/// <returns></returns>
List<File<T>> GetFiles(T[] fileIds);
/// <summary>
/// Gets the file (s) by ID (s) for share
/// </summary>
/// <param name="fileIds">id file</param>
/// <param name="filterType"></param>
/// <param name="subjectGroup"></param>
/// <param name="subjectID"></param>
/// <param name="searchText"></param>
/// <param name="searchInContent"></param>
/// <returns></returns>
List<File<T>> GetFilesForShare(T[] fileIds, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool searchInContent);
/// <summary>
///
/// </summary>
/// <param name="parentId"></param>
/// <returns></returns>
List<object> GetFiles(T parentId);
/// <summary>
/// Get files in folder
/// </summary>
/// <param name="parentId">folder id</param>
/// <param name="orderBy"></param>
/// <param name="filterType">filterType type</param>
/// <param name="subjectGroup"></param>
/// <param name="subjectID"></param>
/// <param name="searchText"> </param>
/// <param name="searchInContent"></param>
/// <param name="withSubfolders"> </param>
/// <returns>list of files</returns>
/// <remarks>
/// Return only the latest versions of files of a folder
/// </remarks>
List<File<T>> GetFiles(T parentId, OrderBy orderBy, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool searchInContent, bool withSubfolders = false);
/// <summary>
/// Get stream of file
/// </summary>
/// <param name="file"></param>
/// <returns>Stream</returns>
Stream GetFileStream(File<T> file);
/// <summary>
/// Get stream of file
/// </summary>
/// <param name="file"></param>
/// <param name="offset"></param>
/// <returns>Stream</returns>
Stream GetFileStream(File<T> file, long offset);
/// <summary>
/// Get presigned uri
/// </summary>
/// <param name="file"></param>
/// <param name="expires"></param>
/// <returns>Stream uri</returns>
Uri GetPreSignedUri(File<T> file, TimeSpan expires);
/// <summary>
/// Check is supported PreSignedUri
/// </summary>
/// <param name="file"></param>
/// <returns>Stream uri</returns>
bool IsSupportedPreSignedUri(File<T> file);
/// <summary>
/// Saves / updates the version of the file
/// and save stream of file
/// </summary>
/// <param name="file"></param>
/// <param name="fileStream"> </param>
/// <returns></returns>
/// <remarks>
/// Updates the file if:
/// - The file comes with the given id
/// - The file with that name in the folder / container exists
///
/// Save in all other cases
/// </remarks>
File<T> SaveFile(File<T> file, Stream fileStream);
/// <summary>
///
/// </summary>
/// <param name="file"></param>
/// <param name="fileStream"></param>
/// <returns></returns>
File<T> ReplaceFileVersion(File<T> file, Stream fileStream);
/// <summary>
/// Deletes a file including all previous versions
/// </summary>
/// <param name="fileId">file id</param>
void DeleteFile(T fileId);
/// <summary>
/// Checks whether or not file
/// </summary>
/// <param name="title">file name</param>
/// <param name="folderId">folder id</param>
/// <returns>Returns true if the file exists, otherwise false</returns>
bool IsExist(string title, T folderId);
/// <summary>
/// Moves a file or set of files in a folder
/// </summary>
/// <param name="fileId">file id</param>
/// <param name="toFolderId">The ID of the destination folder</param>
object MoveFile(T fileId, T toFolderId);
/// <summary>
/// Copy the files in a folder
/// </summary>
/// <param name="fileId">file id</param>
/// <param name="toFolderId">The ID of the destination folder</param>
File<T> CopyFile(T fileId, T toFolderId);
/// <summary>
/// Rename file
/// </summary>
/// <param name="file"></param>
/// <param name="newTitle">new name</param>
object FileRename(File<T> file, string newTitle);
/// <summary>
/// Update comment file
/// </summary>
/// <param name="fileId">file id</param>
/// <param name="fileVersion">file version</param>
/// <param name="comment">new comment</param>
string UpdateComment(T fileId, int fileVersion, string comment);
/// <summary>
/// Complete file version
/// </summary>
/// <param name="fileId">file id</param>
/// <param name="fileVersion">file version</param>
void CompleteVersion(T fileId, int fileVersion);
/// <summary>
/// Continue file version
/// </summary>
/// <param name="fileId">file id</param>
/// <param name="fileVersion">file version</param>
void ContinueVersion(T fileId, int fileVersion);
/// <summary>
/// Check the need to use the trash before removing
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
bool UseTrashForRemove(File<T> file);
#region chunking
ChunkedUploadSession CreateUploadSession(File<T> file, long contentLength);
#endregion
#region Only in TMFileDao
/// <summary>
/// Set created by
/// </summary>
/// <param name="fileIds"></param>
/// <param name="newOwnerId"></param>
void ReassignFiles(T[] fileIds, Guid newOwnerId);
/// <summary>
/// Search files in SharedWithMe & Projects
/// </summary>
/// <param name="parentIds"></param>
/// <param name="filterType"></param>
/// <param name="subjectGroup"></param>
/// <param name="subjectID"></param>
/// <param name="searchText"></param>
/// <param name="searchInContent"></param>
/// <returns></returns>
List<File<T>> GetFiles(T[] parentIds, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool searchInContent);
/// <summary>
/// Search the list of files containing text
/// Only in TMFileDao
/// </summary>
/// <param name="text">search text</param>
/// <param name="bunch"></param>
/// <returns>list of files</returns>
IEnumerable<File<T>> Search(string text, bool bunch = false);
/// <summary>
/// Checks whether file exists on storage
/// </summary>
/// <param name="file">file</param>
/// <returns></returns>
bool IsExistOnStorage(File<T> file);
void SaveEditHistory(File<T> file, string changes, Stream differenceStream);
List<EditHistory> GetEditHistory(DocumentServiceHelper documentServiceHelper, T fileId, int fileVersion = 0);
Stream GetDifferenceStream(File<T> file);
bool ContainChanges(T fileId, int fileVersion);
#endregion
}
/// <summary>
/// Interface encapsulates access toFolderId files
/// </summary>

View File

@ -51,7 +51,7 @@ using Microsoft.Extensions.DependencyInjection;
namespace ASC.Files.Core.Data
{
public class FileDao : AbstractDao, IFileDao
public class FileDao : AbstractDao, IFileDao, IFileDao<int>
{
private static readonly object syncRoot = new object();
public FactoryIndexer<FilesWrapper> FactoryIndexer { get; }
@ -106,12 +106,22 @@ namespace ASC.Files.Core.Data
{
}
public void InvalidateCache(int fileId)
{
}
public File GetFile(object fileId)
{
var query = GetFileQuery(r => r.Id.ToString() == fileId.ToString() && r.CurrentVersion);
return FromQueryWithShared(query).SingleOrDefault();
}
public File<int> GetFile(int fileId)
{
var query = GetFileQuery(r => r.Id == fileId && r.CurrentVersion);
return FromQueryWithSharedInt(query).SingleOrDefault();
}
public File GetFile(object fileId, int fileVersion)
{
var query = GetFileQuery(r => r.Id.ToString() == fileId.ToString() && r.Version == fileVersion);
@ -1200,6 +1210,31 @@ namespace ASC.Files.Core.Data
.ToList();
}
protected List<File<int>> FromQueryWithSharedInt(IQueryable<DbFile> dbFiles)
{
return dbFiles
.Select(r => new DbFileQuery
{
file = r,
root =
FilesDbContext.Folders
.Join(FilesDbContext.Tree, a => a.Id, b => b.ParentId, (folder, tree) => new { folder, tree })
.Where(x => x.folder.TenantId == r.TenantId)
.Where(x => x.tree.FolderId == r.FolderId)
.OrderByDescending(r => r.tree.Level)
.Select(r => r.folder)
.FirstOrDefault(),
shared =
FilesDbContext.Security
.Where(x => x.EntryType == FileEntryType.File)
.Where(x => x.EntryId == r.Id.ToString())
.Any()
})
.ToList()
.Select(ToFileInt)
.ToList();
}
protected List<File> FromQuery(IQueryable<DbFile> dbFiles)
{
return dbFiles
@ -1243,6 +1278,193 @@ namespace ASC.Files.Core.Data
file.Forcesave = r.file.Forcesave;
return file;
}
public File<int> ToFileInt(DbFileQuery r)
{
var file = ServiceProvider.GetService<File<int>>();
file.ID = r.file.Id;
file.Title = r.file.Title;
file.FolderID = r.file.FolderId;
file.CreateOn = TenantUtil.DateTimeFromUtc(r.file.CreateOn);
file.CreateBy = r.file.CreateBy;
file.Version = r.file.Version;
file.VersionGroup = r.file.VersionGroup;
file.ContentLength = r.file.ContentLength;
file.ModifiedOn = TenantUtil.DateTimeFromUtc(r.file.ModifiedOn);
file.ModifiedBy = r.file.ModifiedBy;
file.RootFolderType = r.root?.FolderType ?? default;
file.RootFolderCreator = r.root?.CreateBy ?? default;
file.RootFolderId = r.root?.Id ?? default;
file.Shared = r.shared;
file.ConvertedType = r.file.ConvertedType;
file.Comment = r.file.Comment;
file.Encrypted = r.file.Encrypted;
file.Forcesave = r.file.Forcesave;
return file;
}
///test:test
public File<int> GetFile(int fileId, int fileVersion)
{
throw new NotImplementedException();
}
public File<int> GetFile(int parentId, string title)
{
throw new NotImplementedException();
}
public File<int> GetFileStable(int fileId, int fileVersion = -1)
{
throw new NotImplementedException();
}
public List<File<int>> GetFileHistory(int fileId)
{
throw new NotImplementedException();
}
public List<File<int>> GetFiles(int[] fileIds)
{
throw new NotImplementedException();
}
public List<File<int>> GetFilesForShare(int[] fileIds, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool searchInContent)
{
throw new NotImplementedException();
}
public List<object> GetFiles(int parentId)
{
throw new NotImplementedException();
}
public List<File<int>> GetFiles(int parentId, OrderBy orderBy, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool searchInContent, bool withSubfolders = false)
{
throw new NotImplementedException();
}
public Stream GetFileStream(File<int> file)
{
throw new NotImplementedException();
}
public Stream GetFileStream(File<int> file, long offset)
{
throw new NotImplementedException();
}
public Uri GetPreSignedUri(File<int> file, TimeSpan expires)
{
throw new NotImplementedException();
}
public bool IsSupportedPreSignedUri(File<int> file)
{
throw new NotImplementedException();
}
public File<int> SaveFile(File<int> file, Stream fileStream)
{
throw new NotImplementedException();
}
public File<int> ReplaceFileVersion(File<int> file, Stream fileStream)
{
throw new NotImplementedException();
}
public void DeleteFile(int fileId)
{
throw new NotImplementedException();
}
public bool IsExist(string title, int folderId)
{
throw new NotImplementedException();
}
public object MoveFile(int fileId, int toFolderId)
{
throw new NotImplementedException();
}
public File<int> CopyFile(int fileId, int toFolderId)
{
throw new NotImplementedException();
}
public object FileRename(File<int> file, string newTitle)
{
throw new NotImplementedException();
}
public string UpdateComment(int fileId, int fileVersion, string comment)
{
throw new NotImplementedException();
}
public void CompleteVersion(int fileId, int fileVersion)
{
throw new NotImplementedException();
}
public void ContinueVersion(int fileId, int fileVersion)
{
throw new NotImplementedException();
}
public bool UseTrashForRemove(File<int> file)
{
throw new NotImplementedException();
}
public ChunkedUploadSession CreateUploadSession(File<int> file, long contentLength)
{
throw new NotImplementedException();
}
public void ReassignFiles(int[] fileIds, Guid newOwnerId)
{
throw new NotImplementedException();
}
public List<File<int>> GetFiles(int[] parentIds, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool searchInContent)
{
throw new NotImplementedException();
}
IEnumerable<File<int>> IFileDao<int>.Search(string text, bool bunch)
{
throw new NotImplementedException();
}
public bool IsExistOnStorage(File<int> file)
{
throw new NotImplementedException();
}
public void SaveEditHistory(File<int> file, string changes, Stream differenceStream)
{
throw new NotImplementedException();
}
public List<EditHistory> GetEditHistory(DocumentServiceHelper documentServiceHelper, int fileId, int fileVersion = 0)
{
throw new NotImplementedException();
}
public Stream GetDifferenceStream(File<int> file)
{
throw new NotImplementedException();
}
public bool ContainChanges(int fileId, int fileVersion)
{
throw new NotImplementedException();
}
}
public class DbFileQuery
@ -1257,7 +1479,9 @@ namespace ASC.Files.Core.Data
public static DIHelper AddFileDaoService(this DIHelper services)
{
services.TryAddScoped<IFileDao, FileDao>();
services.TryAddScoped<IFileDao<int>, FileDao>();
services.TryAddTransient<File>();
services.TryAddTransient<File<int>>();
return services
.AddFilesDbContextService()

View File

@ -54,6 +54,16 @@ namespace ASC.Files.Core
[EnumMember] IsEditingAlone = 0x10
}
public class File<T> : File
{
[DataMember(Name = "id")]
public new T ID { get; set; }
public File(Global global, FilesLinkUtility filesLinkUtility, FileUtility fileUtility, FileConverter fileConverter) : base(global, filesLinkUtility, fileUtility, fileConverter)
{
}
}
[Serializable]
[DataContract(Name = "file", Namespace = "")]
[DebuggerDisplay("{Title} ({ID} v{Version})")]

View File

@ -445,6 +445,30 @@ namespace ASC.Web.Files.Services.WCFService
return file;
}
public File<int> GetFile(int fileId, int version)
{
var fileDao = GetFileDao() as IFileDao<int>;
fileDao.InvalidateCache(fileId);
var file = version > 0
? fileDao.GetFile(fileId, version)
: fileDao.GetFile(fileId);
ErrorIf(file == null, FilesCommonResource.ErrorMassage_FileNotFound);
ErrorIf(!FileSecurity.CanRead(file), FilesCommonResource.ErrorMassage_SecurityException_ReadFile);
EntryManager.SetFileStatus(file);
if (file.RootFolderType == FolderType.USER
&& !Equals(file.RootFolderCreator, AuthContext.CurrentAccount.ID))
{
var folderDao = GetFolderDao();
if (!FileSecurity.CanRead(folderDao.GetFolder(file.FolderID)))
file.FolderIdDisplay = GlobalFolderHelper.FolderShare;
}
return file;
}
public ItemList<File> GetSiblingsFile(string fileId, string parentId, FilterType filter, bool subjectGroup, string subjectID, string search, bool searchInContent, bool withSubfolders, OrderBy orderBy)
{
var subjectId = string.IsNullOrEmpty(subjectID) ? Guid.Empty : new Guid(subjectID);