add google and onedrive

This commit is contained in:
Anton Suhorukov 2022-06-06 17:28:51 +03:00
parent a0729a8084
commit 720121f56e
11 changed files with 80 additions and 20 deletions

View File

@ -273,6 +273,12 @@ internal abstract class BoxDaoBase : ThirdPartyProviderDao<BoxProviderInfo>
return items;
}
protected Task<Stream> GetThumbnailAsync(string fileId)
{
var boxFileId = MakeBoxId(fileId);
return ProviderInfo.GetThumbnailAsync(boxFileId);
}
protected sealed class ErrorFolder : BoxFolder
{
public string Error { get; set; }

View File

@ -545,6 +545,11 @@ internal class BoxFileDao : BoxDaoBase, IFileDao<string>
return false;
}
public Task<Stream> GetThumbnailAsync(File<string> file)
{
return GetThumbnailAsync(_boxDaoSelector.ConvertId(file.Id));
}
#region chunking
private File<string> RestoreIds(File<string> file)
@ -629,10 +634,5 @@ internal class BoxFileDao : BoxDaoBase, IFileDao<string>
return Task.CompletedTask;
}
public Task<Stream> GetThumbnailAsync(File<string> file)
{
throw new NotImplementedException();
}
#endregion
}

View File

@ -145,6 +145,12 @@ internal class BoxProviderInfo : IProviderInfo
{
return _boxProviderInfoHelper.CacheResetAsync(BoxRootId, ID, boxPath, isFile);
}
internal async Task<Stream> GetThumbnailAsync(string boxFileId)
{
var storage = await StorageAsync;
return await _boxProviderInfoHelper.GetThumbnailAsync(storage, boxFileId);
}
}
[Scope]
@ -330,4 +336,9 @@ public class BoxProviderInfoHelper
await _cacheNotify.PublishAsync(new BoxCacheItem { IsFile = isFile ?? false, IsFileExists = isFile.HasValue, Key = key }, CacheNotifyAction.Remove).ConfigureAwait(false);
}
}
internal async Task<Stream> GetThumbnailAsync(BoxStorage storage, string boxFileId)
{
return await storage.GetThumbnailAsync(boxFileId).ConfigureAwait(false);
}
}

View File

@ -270,4 +270,9 @@ internal class BoxStorage
//todo: without chunked uploader:
return Math.Min(max, MaxChunkedUploadFileSize);
}
public Task<Stream> GetThumbnailAsync(string fileId)
{
return _boxClient.FilesManager.GetThumbnailAsync(fileId, 320, 320, 320, 320, extension: "jpg");
}
}

View File

@ -141,7 +141,9 @@ internal class DropboxStorage : IDisposable
public async Task<Stream> GetThumbnailsAsync(string filePath)
{
var path = new PathOrLink.Path(filePath);
var arg = new ThumbnailV2Arg(path);
var size = ThumbnailSize.W256h256.Instance;
var arg = new ThumbnailV2Arg(path, size: size);
var responce = await _dropboxClient.Files.GetThumbnailV2Async(arg);
return await responce.GetContentAsStreamAsync();
}

View File

@ -547,6 +547,11 @@ internal class GoogleDriveFileDao : GoogleDriveDaoBase, IFileDao<string>
return false;
}
public async Task<Stream> GetThumbnailAsync(File<string> file)
{
return await ProviderInfo.GetThumbnail(MakeDriveId(_googleDriveDaoSelector.ConvertId(file.Id)));
}
#region chunking
private File<string> RestoreIds(File<string> file)
@ -702,9 +707,5 @@ internal class GoogleDriveFileDao : GoogleDriveDaoBase, IFileDao<string>
return Task.CompletedTask;
}
public async Task<Stream> GetThumbnailAsync(File<string> file)
{
return await ProviderInfo.GetThumbnail(MakeDriveId(_googleDriveDaoSelector.ConvertId(file.Id)));
}
#endregion
}

View File

@ -344,6 +344,12 @@ internal abstract class OneDriveDaoBase : ThirdPartyProviderDao<OneDriveProvider
return requestTitle;
}
protected Task<Stream> GetThumbnailAsync(string fileId)
{
var oneDriveId = MakeOneDriveId(fileId);
return ProviderInfo.GetThumbnailAsync(oneDriveId);
}
private string MatchEvaluator(Match match)
{
var index = Convert.ToInt32(match.Groups[2].Value);

View File

@ -556,6 +556,11 @@ internal class OneDriveFileDao : OneDriveDaoBase, IFileDao<string>
return false;
}
public Task<Stream> GetThumbnailAsync(File<string> file)
{
return GetThumbnailAsync(_oneDriveDaoSelector.ConvertId(file.Id));
}
#region chunking
private File<string> RestoreIds(File<string> file)
@ -701,10 +706,5 @@ internal class OneDriveFileDao : OneDriveDaoBase, IFileDao<string>
System.IO.File.Delete(uploadSession.GetItemOrDefault<string>("TempPath"));
}
}
public Task<Stream> GetThumbnailAsync(File<string> file)
{
throw new NotImplementedException();
}
#endregion
}

View File

@ -121,6 +121,12 @@ internal class OneDriveProviderInfo : IProviderInfo
{
return _oneDriveProviderInfoHelper.CacheResetAsync(ID, onedriveId);
}
internal async Task<Stream> GetThumbnailAsync(string onedriveId)
{
var storage = await StorageAsync;
return await _oneDriveProviderInfoHelper.GetThumbnailAsync(storage, onedriveId);
}
}
[Scope(Additional = typeof(OneDriveProviderInfoExtention))]
@ -264,6 +270,11 @@ public class OneDriveProviderInfoHelper
await _cacheNotify.PublishAsync(new OneDriveCacheItem { Key = key }, CacheNotifyAction.Remove).ConfigureAwait(false);
}
}
internal async Task<Stream> GetThumbnailAsync(OneDriveStorage storage, string onedriveId)
{
return await storage.GetThumbnailAsync(onedriveId).ConfigureAwait(false);
}
}
public static class OneDriveProviderInfoExtention
{

View File

@ -24,6 +24,8 @@
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
using System.Net.Sockets;
using Folder = Microsoft.OneDrive.Sdk.Folder;
namespace ASC.Files.Thirdparty.OneDrive;
@ -354,6 +356,22 @@ internal class OneDriveStorage
var httpClient = _clientFactory.CreateClient();
using var response = await httpClient.SendAsync(request);
}
public async Task<Stream> GetThumbnailAsync(string fileId)
{
var thumbnails = await OnedriveClient.Drive.Items[fileId].Thumbnails.Request().GetAsync();
var request = new HttpRequestMessage
{
RequestUri = new Uri(thumbnails[0].Medium.Url),
Method = HttpMethod.Get
};
var httpClient = _clientFactory.CreateClient();
using var response = await httpClient.SendAsync(request);
var bytes = await response.Content.ReadAsByteArrayAsync();
var mem = new MemoryStream(bytes);
return new MemoryStream(bytes);
}
}

View File

@ -561,6 +561,11 @@ internal class SharpBoxFileDao : SharpBoxDaoBase, IFileDao<string>
return false;
}
public Task<Stream> GetThumbnailAsync(File<string> file)
{
throw new NotImplementedException();
}
#region chunking
public async Task<ChunkedUploadSession<string>> CreateUploadSessionAsync(File<string> file, long contentLength)
@ -706,10 +711,5 @@ internal class SharpBoxFileDao : SharpBoxDaoBase, IFileDao<string>
return file;
}
public Task<Stream> GetThumbnailAsync(File<string> file)
{
throw new NotImplementedException();
}
#endregion
}