public override async Task <bool> DeleteAsync(FileProviderDeleteArgs args) { var configuration = args.Configuration.GetFastDFSConfiguration(); ConfigurationFactory.AddIfNotContains(configuration); var fileId = FileNameCalculator.Calculate(args); var containerName = GetContainerName(configuration, args); return(await Client.RemoveFileAsync(containerName, fileId, configuration.ClusterName)); }
public override async Task <string> SaveAsync(FileProviderSaveArgs args) { var configuration = args.Configuration.GetFastDFSConfiguration(); ConfigurationFactory.AddIfNotContains(configuration); var containerName = GetContainerName(configuration, args); var storageNode = await Client.GetStorageNodeAsync(containerName, configuration.ClusterName); var fileId = await Client.UploadFileAsync(storageNode, args.FileStream, args.FileExt, configuration.ClusterName); return(fileId); }
public override async Task <bool> ExistsAsync(FileProviderExistsArgs args) { var configuration = args.Configuration.GetFastDFSConfiguration(); ConfigurationFactory.AddIfNotContains(configuration); var fileId = FileNameCalculator.Calculate(args); var containerName = GetContainerName(configuration, args); var storageNode = await Client.GetStorageNodeAsync(containerName, configuration.ClusterName); var fileInfo = await Client.GetFileInfo(storageNode, fileId, configuration.ClusterName); return(fileInfo != null); }
public override Task <string> GetAccessUrlAsync(FileProviderAccessArgs args) { if (!args.Configuration.HttpAccess) { return(Task.FromResult(string.Empty)); } var configuration = args.Configuration.GetFastDFSConfiguration(); ConfigurationFactory.AddIfNotContains(configuration); var fileId = FileNameCalculator.Calculate(args); var containerName = GetContainerName(configuration, args); var accessUrl = BuildAccessUrl(configuration, containerName, fileId); return(Task.FromResult(accessUrl)); }
public override async Task <bool> DownloadAsync(FileProviderDownloadArgs args) { var configuration = args.Configuration.GetFastDFSConfiguration(); ConfigurationFactory.AddIfNotContains(configuration); var fileId = FileNameCalculator.Calculate(args); var containerName = GetContainerName(configuration, args); var storageNode = await Client.GetStorageNodeAsync(containerName, configuration.ClusterName); try { await Client.DownloadFileEx(storageNode, fileId, args.Path, configuration.ClusterName); return(true); } catch (Exception ex) { Logger.LogException(ex, LogLevel.Error); return(false); } }
public override async Task <Stream> GetOrNullAsync(FileProviderGetArgs args) { var configuration = args.Configuration.GetFastDFSConfiguration(); ConfigurationFactory.AddIfNotContains(configuration); var fileId = FileNameCalculator.Calculate(args); var containerName = GetContainerName(configuration, args); var storageNode = await Client.GetStorageNodeAsync(containerName, configuration.ClusterName); try { var content = await Client.DownloadFileAsync(storageNode, fileId, configuration.ClusterName); return(new MemoryStream(content)); } catch (Exception ex) { Logger.LogException(ex, LogLevel.Error); return(null); } }