From d66290269d4709fe2d909284801f31669aa26f74 Mon Sep 17 00:00:00 2001 From: vnugent Date: Thu, 31 Aug 2023 22:17:50 -0400 Subject: pre tag updates --- back-end/src/Storage/FtpStorageManager.cs | 3 +- back-end/src/Storage/IStorageFacade.cs | 71 ------------------------------ back-end/src/Storage/ManagedStorage.cs | 10 ++--- back-end/src/Storage/MinioClientManager.cs | 5 +-- back-end/src/Storage/StorageBase.cs | 6 +-- 5 files changed, 11 insertions(+), 84 deletions(-) delete mode 100644 back-end/src/Storage/IStorageFacade.cs (limited to 'back-end/src/Storage') diff --git a/back-end/src/Storage/FtpStorageManager.cs b/back-end/src/Storage/FtpStorageManager.cs index abcf5e1..d64d4ea 100644 --- a/back-end/src/Storage/FtpStorageManager.cs +++ b/back-end/src/Storage/FtpStorageManager.cs @@ -29,7 +29,6 @@ using System.Collections.Generic; using FluentFTP; using FluentFTP.Exceptions; -using VNLib.Net.Http; using VNLib.Utils.Logging; using VNLib.Utils.Resources; using VNLib.Plugins; @@ -102,7 +101,7 @@ namespace Content.Publishing.Blog.Admin.Storage } /// - public override async Task SetFileAsync(string filePath, Stream data, ContentType ct, CancellationToken cancellation) + public override async Task WriteFileAsync(string filePath, Stream data, string ct, CancellationToken cancellation) { //Upload the file to the server FtpStatus status = await _client.UploadStream(data, GetExternalFilePath(filePath), FtpRemoteExists.Overwrite, true, token: cancellation); diff --git a/back-end/src/Storage/IStorageFacade.cs b/back-end/src/Storage/IStorageFacade.cs deleted file mode 100644 index 703394b..0000000 --- a/back-end/src/Storage/IStorageFacade.cs +++ /dev/null @@ -1,71 +0,0 @@ -/* -* Copyright (c) 2023 Vaughn Nugent -* -* Library: CMNext -* Package: Content.Publishing.Blog.Admin -* File: IStorageFacade.cs -* -* CMNext is free software: you can redistribute it and/or modify -* it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* CMNext is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU Affero General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with this program. If not, see https://www.gnu.org/licenses/. -*/ - -using System; -using System.IO; -using System.Threading; -using System.Threading.Tasks; - -using VNLib.Net.Http; - -namespace Content.Publishing.Blog.Admin.Storage -{ - /// - /// Represents an opaque storage interface that abstracts simple storage operations - /// ignorant of the underlying storage system. - /// - internal interface IStorageFacade - { - /// - /// Gets the full public file path for the given relative file path - /// - /// The relative file path of the item to get the full path for - /// The full relative file path - string GetExternalFilePath(string filePath); - - /// - /// Deletes a file from the storage system asynchronously - /// - /// The path to the file to delete - /// A token to cancel the operation - /// A task that represents and asynchronous work - Task DeleteFileAsync(string filePath, CancellationToken cancellation); - - /// - /// Writes a file from the stream to the given file location - /// - /// The path to the file to write to - /// The file data to stream - /// The content type of the file to write - /// A token to cancel the operation - /// A task that represents and asynchronous work - Task SetFileAsync(string filePath, Stream data, ContentType ct, CancellationToken cancellation); - - /// - /// Reads a file from the storage system at the given path asynchronously - /// - /// The file to read - /// The stream to write the file output to - /// A token to cancel the operation - /// The number of bytes read, -1 if the operation failed - Task ReadFileAsync(string filePath, Stream output, CancellationToken cancellation); - } -} diff --git a/back-end/src/Storage/ManagedStorage.cs b/back-end/src/Storage/ManagedStorage.cs index 654695f..19e208c 100644 --- a/back-end/src/Storage/ManagedStorage.cs +++ b/back-end/src/Storage/ManagedStorage.cs @@ -24,15 +24,15 @@ using System.IO; using System.Threading; using System.Threading.Tasks; -using VNLib.Net.Http; +using VNLib.Utils.IO; using VNLib.Plugins; using VNLib.Plugins.Extensions.Loading; namespace Content.Publishing.Blog.Admin.Storage { - internal sealed class ManagedStorage : IStorageFacade + internal sealed class ManagedStorage : ISimpleFilesystem { - private readonly IStorageFacade _backingStorage; + private readonly ISimpleFilesystem _backingStorage; public ManagedStorage(PluginBase plugin) { @@ -81,7 +81,7 @@ namespace Content.Publishing.Blog.Admin.Storage } /// - public Task SetFileAsync(string filePath, Stream data, ContentType ct, CancellationToken cancellation) + public Task WriteFileAsync(string filePath, Stream data, string ct, CancellationToken cancellation) { //Try to reset the stream if allowed if (data.CanSeek) @@ -90,7 +90,7 @@ namespace Content.Publishing.Blog.Admin.Storage data.Seek(0, SeekOrigin.Begin); } - return _backingStorage.SetFileAsync(filePath, data, ct, cancellation); + return _backingStorage.WriteFileAsync(filePath, data, ct, cancellation); } } } diff --git a/back-end/src/Storage/MinioClientManager.cs b/back-end/src/Storage/MinioClientManager.cs index e9f7c9a..6dd0f5c 100644 --- a/back-end/src/Storage/MinioClientManager.cs +++ b/back-end/src/Storage/MinioClientManager.cs @@ -26,7 +26,6 @@ using System.Threading.Tasks; using Minio; using Minio.DataModel; -using VNLib.Net.Http; using VNLib.Utils.Memory; using VNLib.Utils.Extensions; using VNLib.Plugins; @@ -94,11 +93,11 @@ namespace Content.Publishing.Blog.Admin.Storage } /// - public override Task SetFileAsync(string filePath, Stream data, ContentType ct, CancellationToken cancellation) + public override Task WriteFileAsync(string filePath, Stream data, string ct, CancellationToken cancellation) { PutObjectArgs args = new(); args.WithBucket(Config.BaseBucket) - .WithContentType(HttpHelpers.GetContentTypeString(ct)) + .WithContentType(ct) .WithObject(filePath) .WithObjectSize(data.Length) .WithStreamData(data); diff --git a/back-end/src/Storage/StorageBase.cs b/back-end/src/Storage/StorageBase.cs index b33d6f1..fe11c39 100644 --- a/back-end/src/Storage/StorageBase.cs +++ b/back-end/src/Storage/StorageBase.cs @@ -23,13 +23,13 @@ using System.IO; using System.Threading; using System.Threading.Tasks; -using VNLib.Net.Http; using VNLib.Plugins; +using VNLib.Utils.IO; using VNLib.Plugins.Extensions.Loading; namespace Content.Publishing.Blog.Admin.Storage { - internal abstract class StorageBase : IAsyncConfigurable, IStorageFacade + internal abstract class StorageBase : IAsyncConfigurable, ISimpleFilesystem { /// /// The base file path within the remote file system to use for external urls @@ -46,7 +46,7 @@ namespace Content.Publishing.Blog.Admin.Storage public abstract Task ReadFileAsync(string filePath, Stream output, CancellationToken cancellation); /// - public abstract Task SetFileAsync(string filePath, Stream data, ContentType ct, CancellationToken cancellation); + public abstract Task WriteFileAsync(string filePath, Stream data, string ct, CancellationToken cancellation); /// public virtual string GetExternalFilePath(string filePath) -- cgit