Compare commits
10
Commits
233d3ef369
...
6e701376df
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6e701376df | ||
|
|
41f220d145 | ||
|
|
c3b9b3e43a | ||
|
|
8a66b8b7e9 | ||
|
|
7e08427539 | ||
|
|
b26767e126 | ||
|
|
83b907988b | ||
|
|
dd23ed4f64 | ||
|
|
330a3958f3 | ||
|
|
d85dbcfdf7 |
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.FileProviders;
|
using Microsoft.Extensions.FileProviders;
|
||||||
@@ -11,7 +12,8 @@ using xStorageService.Models;
|
|||||||
|
|
||||||
namespace xStorageService.Interfaces
|
namespace xStorageService.Interfaces
|
||||||
{
|
{
|
||||||
public partial interface IXStorageProvider {
|
public partial interface IXStorageProvider
|
||||||
|
{
|
||||||
XStorageConfiguration Configuration { get; }
|
XStorageConfiguration Configuration { get; }
|
||||||
XStorageHelper StorageHelper { get; }
|
XStorageHelper StorageHelper { get; }
|
||||||
IFileProvider FileProvider { get; }
|
IFileProvider FileProvider { get; }
|
||||||
@@ -29,6 +31,7 @@ namespace xStorageService.Interfaces
|
|||||||
string GetVideoFolderPath();
|
string GetVideoFolderPath();
|
||||||
string GetDocumentFolderPath();
|
string GetDocumentFolderPath();
|
||||||
string FilePathResolver(string fullPath);
|
string FilePathResolver(string fullPath);
|
||||||
|
string ConvertToFileUrl(string fullPath);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -79,7 +82,8 @@ namespace xStorageService.Interfaces
|
|||||||
Task<string> SaveFileAsync(
|
Task<string> SaveFileAsync(
|
||||||
IFormFile file,
|
IFormFile file,
|
||||||
bool isTemp = false,
|
bool isTemp = false,
|
||||||
bool isWidget = false
|
bool isWidget = false,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
void DeleteFile(
|
void DeleteFile(
|
||||||
string fileFullPath,
|
string fileFullPath,
|
||||||
@@ -92,11 +96,26 @@ namespace xStorageService.Interfaces
|
|||||||
Exception exception = null
|
Exception exception = null
|
||||||
);
|
);
|
||||||
// Task CreateThumbnail (XFile file);
|
// Task CreateThumbnail (XFile file);
|
||||||
Task CreateThumbnail (XFileDto file);
|
Task CreateThumbnail(
|
||||||
Task CreateThumbnail (string fileName);
|
XFileDto file,
|
||||||
Task<XFileResult> HandleProfileImageSave (IFormFile file);
|
CancellationToken cancellationToken = default
|
||||||
Task<XFileResult> HandleFileSave (IFormFile file);
|
);
|
||||||
Task<IEnumerable<XFileResult>> HandleFilesSave (IFormFileCollection files);
|
Task CreateThumbnail(
|
||||||
|
string fileName,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
Task<XFileResult> HandleProfileImageSave(
|
||||||
|
IFormFile file,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
Task<XFileResult> HandleFileSave(
|
||||||
|
IFormFile file,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
Task<IEnumerable<XFileResult>> HandleFilesSave(
|
||||||
|
IFormFileCollection files,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+257
-115
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.FileProviders;
|
using Microsoft.Extensions.FileProviders;
|
||||||
@@ -15,8 +16,10 @@ using xStorageService.Helpers;
|
|||||||
using xStorageService.Interfaces;
|
using xStorageService.Interfaces;
|
||||||
using xStorageService.Models;
|
using xStorageService.Models;
|
||||||
|
|
||||||
namespace xStorageService.Providers {
|
namespace xStorageService.Providers
|
||||||
public partial class XStorageProvider : IXStorageProvider {
|
{
|
||||||
|
public partial class XStorageProvider : IXStorageProvider
|
||||||
|
{
|
||||||
|
|
||||||
public readonly string BasePath;
|
public readonly string BasePath;
|
||||||
private readonly XFileType[] ThumbSupprtedTypes = new XFileType[] {
|
private readonly XFileType[] ThumbSupprtedTypes = new XFileType[] {
|
||||||
@@ -33,7 +36,8 @@ namespace xStorageService.Providers {
|
|||||||
XStorageHelper storageHelper,
|
XStorageHelper storageHelper,
|
||||||
IXThumbnailProvider thumbnailProvider,
|
IXThumbnailProvider thumbnailProvider,
|
||||||
XStorageConfiguration configuration
|
XStorageConfiguration configuration
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
FileProvider = fileProvider;
|
FileProvider = fileProvider;
|
||||||
Configuration = configuration;
|
Configuration = configuration;
|
||||||
@@ -52,7 +56,8 @@ namespace xStorageService.Providers {
|
|||||||
/// Get Storage Folder Path
|
/// Get Storage Folder Path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string GetStorageFolderPath () {
|
public string GetStorageFolderPath()
|
||||||
|
{
|
||||||
return Path.Combine(BasePath, Configuration.Storage);
|
return Path.Combine(BasePath, Configuration.Storage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +65,8 @@ namespace xStorageService.Providers {
|
|||||||
/// Get Temp Folder Path
|
/// Get Temp Folder Path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string GetTempFolderPath () {
|
public string GetTempFolderPath()
|
||||||
|
{
|
||||||
return Path.Combine(GetStorageFolderPath(), Configuration.Temp);
|
return Path.Combine(GetStorageFolderPath(), Configuration.Temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +74,8 @@ namespace xStorageService.Providers {
|
|||||||
/// Get Uploads Folder Path
|
/// Get Uploads Folder Path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string GetUploadsFolderPath () {
|
public string GetUploadsFolderPath()
|
||||||
|
{
|
||||||
return Path.Combine(GetStorageFolderPath(), Configuration.Uploads);
|
return Path.Combine(GetStorageFolderPath(), Configuration.Uploads);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +83,8 @@ namespace xStorageService.Providers {
|
|||||||
/// Get Widgets Folder Path
|
/// Get Widgets Folder Path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string GetWidgetsFolderPath () {
|
public string GetWidgetsFolderPath()
|
||||||
|
{
|
||||||
return Path.Combine(GetStorageFolderPath(), Configuration.Widgets);
|
return Path.Combine(GetStorageFolderPath(), Configuration.Widgets);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +92,8 @@ namespace xStorageService.Providers {
|
|||||||
/// Get Thumb Folder Path
|
/// Get Thumb Folder Path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string GetThumbFolderPath () {
|
public string GetThumbFolderPath()
|
||||||
|
{
|
||||||
return Path.Combine(GetUploadsFolderPath(), Configuration.Thumb);
|
return Path.Combine(GetUploadsFolderPath(), Configuration.Thumb);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +101,8 @@ namespace xStorageService.Providers {
|
|||||||
/// Get Images Folder Path
|
/// Get Images Folder Path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string GetImageFolderPath () {
|
public string GetImageFolderPath()
|
||||||
|
{
|
||||||
return Path.Combine(GetUploadsFolderPath(), Configuration.Image);
|
return Path.Combine(GetUploadsFolderPath(), Configuration.Image);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +110,8 @@ namespace xStorageService.Providers {
|
|||||||
/// Get Audios Folder Path
|
/// Get Audios Folder Path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string GetAudioFolderPath () {
|
public string GetAudioFolderPath()
|
||||||
|
{
|
||||||
return Path.Combine(GetUploadsFolderPath(), Configuration.Audio);
|
return Path.Combine(GetUploadsFolderPath(), Configuration.Audio);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +119,8 @@ namespace xStorageService.Providers {
|
|||||||
/// Get Videos Folder Path
|
/// Get Videos Folder Path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string GetVideoFolderPath () {
|
public string GetVideoFolderPath()
|
||||||
|
{
|
||||||
return Path.Combine(GetUploadsFolderPath(), Configuration.Video);
|
return Path.Combine(GetUploadsFolderPath(), Configuration.Video);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +128,8 @@ namespace xStorageService.Providers {
|
|||||||
/// Get Documents Folder Path
|
/// Get Documents Folder Path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string GetDocumentFolderPath () {
|
public string GetDocumentFolderPath()
|
||||||
|
{
|
||||||
return Path.Combine(GetUploadsFolderPath(), Configuration.Document);
|
return Path.Combine(GetUploadsFolderPath(), Configuration.Document);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +138,8 @@ namespace xStorageService.Providers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fullPath"></param>
|
/// <param name="fullPath"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string FilePathResolver (string fullPath) {
|
public string FilePathResolver(string fullPath)
|
||||||
|
{
|
||||||
return fullPath.Replace(BasePath, "");
|
return fullPath.Replace(BasePath, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,7 +148,8 @@ namespace xStorageService.Providers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fullPath"></param>
|
/// <param name="fullPath"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string ConvertToProfileImageUrl (string fullPath) {
|
public string ConvertToProfileImageUrl(string fullPath)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var authority = !Configuration.IdentityAuthority.IsNullOrEmpty() &&
|
var authority = !Configuration.IdentityAuthority.IsNullOrEmpty() &&
|
||||||
Configuration.IdentityAuthority.EndsWith("/") ?
|
Configuration.IdentityAuthority.EndsWith("/") ?
|
||||||
@@ -150,7 +165,8 @@ namespace xStorageService.Providers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fullPath"></param>
|
/// <param name="fullPath"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string ConvertToFileUrl (string fullPath) {
|
public string ConvertToFileUrl(string fullPath)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var authority = !Configuration.Authority.IsNullOrEmpty() &&
|
var authority = !Configuration.Authority.IsNullOrEmpty() &&
|
||||||
Configuration.Authority.EndsWith("/") ?
|
Configuration.Authority.EndsWith("/") ?
|
||||||
@@ -168,63 +184,76 @@ namespace xStorageService.Providers {
|
|||||||
/// Check Folder Structure of Storage Area
|
/// Check Folder Structure of Storage Area
|
||||||
/// and Create them if not Exists
|
/// and Create them if not Exists
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Prepare () {
|
public void Prepare()
|
||||||
|
{
|
||||||
//
|
//
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
//
|
//
|
||||||
// Storage Folder Path Check ...
|
// Storage Folder Path Check ...
|
||||||
if (!IsFolderExists (GetStorageFolderPath ())) {
|
if (!IsFolderExists(GetStorageFolderPath()))
|
||||||
|
{
|
||||||
Directory.CreateDirectory(GetStorageFolderPath());
|
Directory.CreateDirectory(GetStorageFolderPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Temp Folder Path Check ...
|
// Temp Folder Path Check ...
|
||||||
if (!IsFolderExists (GetTempFolderPath ())) {
|
if (!IsFolderExists(GetTempFolderPath()))
|
||||||
|
{
|
||||||
Directory.CreateDirectory(GetTempFolderPath());
|
Directory.CreateDirectory(GetTempFolderPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Temp Folder Path Check ...
|
// Temp Folder Path Check ...
|
||||||
if (!IsFolderExists (GetThumbFolderPath ())) {
|
if (!IsFolderExists(GetThumbFolderPath()))
|
||||||
|
{
|
||||||
Directory.CreateDirectory(GetThumbFolderPath());
|
Directory.CreateDirectory(GetThumbFolderPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Widgets Folder Path Chekc ...
|
// Widgets Folder Path Chekc ...
|
||||||
if (!IsFolderExists (GetWidgetsFolderPath ())) {
|
if (!IsFolderExists(GetWidgetsFolderPath()))
|
||||||
|
{
|
||||||
Directory.CreateDirectory(GetWidgetsFolderPath());
|
Directory.CreateDirectory(GetWidgetsFolderPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Uploads Folder Path Chekc ...
|
// Uploads Folder Path Chekc ...
|
||||||
if (!IsFolderExists (GetUploadsFolderPath ())) {
|
if (!IsFolderExists(GetUploadsFolderPath()))
|
||||||
|
{
|
||||||
Directory.CreateDirectory(GetUploadsFolderPath());
|
Directory.CreateDirectory(GetUploadsFolderPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Image Folder Path Chekc ...
|
// Image Folder Path Chekc ...
|
||||||
if (!IsFolderExists (GetImageFolderPath ())) {
|
if (!IsFolderExists(GetImageFolderPath()))
|
||||||
|
{
|
||||||
Directory.CreateDirectory(GetImageFolderPath());
|
Directory.CreateDirectory(GetImageFolderPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Music Folder Path Chekc ...
|
// Music Folder Path Chekc ...
|
||||||
if (!IsFolderExists (GetAudioFolderPath ())) {
|
if (!IsFolderExists(GetAudioFolderPath()))
|
||||||
|
{
|
||||||
Directory.CreateDirectory(GetAudioFolderPath());
|
Directory.CreateDirectory(GetAudioFolderPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Video Folder Path Chekc ...
|
// Video Folder Path Chekc ...
|
||||||
if (!IsFolderExists (GetVideoFolderPath ())) {
|
if (!IsFolderExists(GetVideoFolderPath()))
|
||||||
|
{
|
||||||
Directory.CreateDirectory(GetVideoFolderPath());
|
Directory.CreateDirectory(GetVideoFolderPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Document Folder Path Chekc ...
|
// Document Folder Path Chekc ...
|
||||||
if (!IsFolderExists (GetDocumentFolderPath ())) {
|
if (!IsFolderExists(GetDocumentFolderPath()))
|
||||||
|
{
|
||||||
Directory.CreateDirectory(GetDocumentFolderPath());
|
Directory.CreateDirectory(GetDocumentFolderPath());
|
||||||
}
|
}
|
||||||
} catch {
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
XException.StorageServiceInitialFailed.Throw();
|
XException.StorageServiceInitialFailed.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,7 +270,8 @@ namespace xStorageService.Providers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path"></param>
|
/// <param name="path"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool IsFolderExists (string path) {
|
public bool IsFolderExists(string path)
|
||||||
|
{
|
||||||
return Directory.Exists(path);
|
return Directory.Exists(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,7 +280,8 @@ namespace xStorageService.Providers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filePath"></param>
|
/// <param name="filePath"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool IsFileExists (string filePath) {
|
public bool IsFileExists(string filePath)
|
||||||
|
{
|
||||||
return File.Exists(filePath);
|
return File.Exists(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,9 +290,11 @@ namespace xStorageService.Providers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fileName"></param>
|
/// <param name="fileName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool IsSupportThumb (string fileName) {
|
public bool IsSupportThumb(string fileName)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
if (!fileName.StartsWith (Configuration.FilePrefix)) {
|
if (!fileName.StartsWith(Configuration.FilePrefix))
|
||||||
|
{
|
||||||
XException.InavlidFile.Throw();
|
XException.InavlidFile.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,7 +308,8 @@ namespace xStorageService.Providers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="type"></param>
|
/// <param name="type"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool IsSupportThumb (XFileType type) {
|
public bool IsSupportThumb(XFileType type)
|
||||||
|
{
|
||||||
return ThumbSupprtedTypes.Contains(type);
|
return ThumbSupprtedTypes.Contains(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,9 +317,11 @@ namespace xStorageService.Providers {
|
|||||||
/// Validate a File Exists or not
|
/// Validate a File Exists or not
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filePath"></param>
|
/// <param name="filePath"></param>
|
||||||
public void ValidateFileExists (string filePath) {
|
public void ValidateFileExists(string filePath)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
if (!IsFileExists (filePath)) {
|
if (!IsFileExists(filePath))
|
||||||
|
{
|
||||||
XException.NotFound.Throw();
|
XException.NotFound.Throw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -294,24 +330,28 @@ namespace xStorageService.Providers {
|
|||||||
/// Validate a File Model with it's Related Physical File
|
/// Validate a File Model with it's Related Physical File
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="file"></param>
|
/// <param name="file"></param>
|
||||||
public void ValidateFileModel (XFileDto file) {
|
public void ValidateFileModel(XFileDto file)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
// Validate Args ...
|
// Validate Args ...
|
||||||
if (file == null) {
|
if (file == null)
|
||||||
|
{
|
||||||
XException.InvalidArgs.Throw();
|
XException.InvalidArgs.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Retrieve Full File Path ...
|
// Retrieve Full File Path ...
|
||||||
var fileFullPath = file.Path;
|
var fileFullPath = file.Path;
|
||||||
if (fileFullPath.IsNullOrEmpty ()) {
|
if (fileFullPath.IsNullOrEmpty())
|
||||||
|
{
|
||||||
XException.InavlidFile.Throw();
|
XException.InavlidFile.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Retrieve is File Exists or not ...
|
// Retrieve is File Exists or not ...
|
||||||
var isPhysicalFileExists = IsFileExists(file.Path);
|
var isPhysicalFileExists = IsFileExists(file.Path);
|
||||||
if (!isPhysicalFileExists) {
|
if (!isPhysicalFileExists)
|
||||||
|
{
|
||||||
XException.NotFound.Throw();
|
XException.NotFound.Throw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -320,22 +360,26 @@ namespace xStorageService.Providers {
|
|||||||
/// Validate File for Upload
|
/// Validate File for Upload
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="file"></param>
|
/// <param name="file"></param>
|
||||||
public void ValidateFile (IFormFile file) {
|
public void ValidateFile(IFormFile file)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
// Validate Args ...
|
// Validate Args ...
|
||||||
if (file == null) {
|
if (file == null)
|
||||||
|
{
|
||||||
XException.InvalidArgs.Throw();
|
XException.InvalidArgs.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Check File Size not Zero ...
|
// Check File Size not Zero ...
|
||||||
if (file.Length == 0) {
|
if (file.Length == 0)
|
||||||
|
{
|
||||||
XException.EmptyFile.Throw();
|
XException.EmptyFile.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Check File Max Size ...
|
// Check File Max Size ...
|
||||||
if (file.Length > Configuration.MaxFileSize) {
|
if (file.Length > Configuration.MaxFileSize)
|
||||||
|
{
|
||||||
XException.MaxFileSizeExceeded.Throw();
|
XException.MaxFileSizeExceeded.Throw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -344,10 +388,12 @@ namespace xStorageService.Providers {
|
|||||||
/// Validate a Collection of IFormFile
|
/// Validate a Collection of IFormFile
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="files"></param>
|
/// <param name="files"></param>
|
||||||
public void ValidateFiles (IFormFileCollection files) {
|
public void ValidateFiles(IFormFileCollection files)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
// Validate Args ...
|
// Validate Args ...
|
||||||
if (!files.HasChild ()) {
|
if (!files.HasChild())
|
||||||
|
{
|
||||||
XException.InvalidArgs.Throw();
|
XException.InvalidArgs.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,7 +406,8 @@ namespace xStorageService.Providers {
|
|||||||
/// Validate File for Profile Image
|
/// Validate File for Profile Image
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="file"></param>
|
/// <param name="file"></param>
|
||||||
public void ValidateProfileImage (IFormFile file) {
|
public void ValidateProfileImage(IFormFile file)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
// Check File Validation ...
|
// Check File Validation ...
|
||||||
// since Args Checked in File Validation, there is no need to
|
// since Args Checked in File Validation, there is no need to
|
||||||
@@ -370,7 +417,8 @@ namespace xStorageService.Providers {
|
|||||||
//
|
//
|
||||||
// Check File Type ...
|
// Check File Type ...
|
||||||
var fileType = GetFileType(file.FileName);
|
var fileType = GetFileType(file.FileName);
|
||||||
if (fileType != XFileType.Image) {
|
if (fileType != XFileType.Image)
|
||||||
|
{
|
||||||
XException.UnsupportedFileType.Throw();
|
XException.UnsupportedFileType.Throw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -382,7 +430,8 @@ namespace xStorageService.Providers {
|
|||||||
/// Generate New File
|
/// Generate New File
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string NewFileName () {
|
public string NewFileName()
|
||||||
|
{
|
||||||
return Configuration.FilePrefix + Guid.NewGuid().ToString().ToLower();
|
return Configuration.FilePrefix + Guid.NewGuid().ToString().ToLower();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -391,9 +440,11 @@ namespace xStorageService.Providers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fileName"></param>
|
/// <param name="fileName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string GenerateThumbName (string fileName) {
|
public string GenerateThumbName(string fileName)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
if (!IsSupportThumb (fileName)) {
|
if (!IsSupportThumb(fileName))
|
||||||
|
{
|
||||||
XException.UnsupportedFileType.Throw();
|
XException.UnsupportedFileType.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -406,10 +457,12 @@ namespace xStorageService.Providers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fileName"></param>
|
/// <param name="fileName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string GetNewFileName (string fileName) {
|
public string GetNewFileName(string fileName)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
// Validate Args ...
|
// Validate Args ...
|
||||||
if (fileName.IsNullOrEmpty ()) {
|
if (fileName.IsNullOrEmpty())
|
||||||
|
{
|
||||||
XException.InvalidArgs.Throw();
|
XException.InvalidArgs.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -433,10 +486,12 @@ namespace xStorageService.Providers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fileName"></param>
|
/// <param name="fileName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string GetFileExtension (string fileName) {
|
public string GetFileExtension(string fileName)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var result = StorageHelper.GetFileExtension(fileName);
|
var result = StorageHelper.GetFileExtension(fileName);
|
||||||
if (result.IsNullOrEmpty ()) {
|
if (result.IsNullOrEmpty())
|
||||||
|
{
|
||||||
XException.InvalidArgs.Throw();
|
XException.InvalidArgs.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -449,10 +504,12 @@ namespace xStorageService.Providers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fileName"></param>
|
/// <param name="fileName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string GetFileNameWithoutExtension (string fileName) {
|
public string GetFileNameWithoutExtension(string fileName)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var result = StorageHelper.GetFileNameWithoutExtension(fileName);
|
var result = StorageHelper.GetFileNameWithoutExtension(fileName);
|
||||||
if (result.IsNullOrEmpty ()) {
|
if (result.IsNullOrEmpty())
|
||||||
|
{
|
||||||
XException.InvalidArgs.Throw();
|
XException.InvalidArgs.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -465,16 +522,19 @@ namespace xStorageService.Providers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fileName"></param>
|
/// <param name="fileName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public FileExtensions GetFileExtensionType (string fileName) {
|
public FileExtensions GetFileExtensionType(string fileName)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var fileExt = GetFileExtension(fileName);
|
var fileExt = GetFileExtension(fileName);
|
||||||
if (fileExt.IsNullOrEmpty ()) {
|
if (fileExt.IsNullOrEmpty())
|
||||||
|
{
|
||||||
XException.InvalidData.Throw();
|
XException.InvalidData.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
var result = StorageHelper.GetExtensionType(fileExt);
|
var result = StorageHelper.GetExtensionType(fileExt);
|
||||||
if (result == -1) {
|
if (result == -1)
|
||||||
|
{
|
||||||
XException.UnsupportedFileType.Throw();
|
XException.UnsupportedFileType.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -487,7 +547,8 @@ namespace xStorageService.Providers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fileName"></param>
|
/// <param name="fileName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public XFileType GetFileType (string fileName) {
|
public XFileType GetFileType(string fileName)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var fileExtension = GetFileExtensionType(fileName);
|
var fileExtension = GetFileExtensionType(fileName);
|
||||||
return GetFileType(fileExtension);
|
return GetFileType(fileExtension);
|
||||||
@@ -498,7 +559,8 @@ namespace xStorageService.Providers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fileExtension"></param>
|
/// <param name="fileExtension"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public XFileType GetFileType (FileExtensions fileExtension) {
|
public XFileType GetFileType(FileExtensions fileExtension)
|
||||||
|
{
|
||||||
return StorageHelper.GetType((int)fileExtension);
|
return StorageHelper.GetType((int)fileExtension);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -507,9 +569,11 @@ namespace xStorageService.Providers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="thumFileName"></param>
|
/// <param name="thumFileName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string GetThumbnailFileFullPath (string thumFileName) {
|
public string GetThumbnailFileFullPath(string thumFileName)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
if (!thumFileName.StartsWith (Configuration.ThumbPrefix)) {
|
if (!thumFileName.StartsWith(Configuration.ThumbPrefix))
|
||||||
|
{
|
||||||
XException.InavlidFile.Throw();
|
XException.InavlidFile.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -522,7 +586,8 @@ namespace xStorageService.Providers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fileName"></param>
|
/// <param name="fileName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string GetRelatedThumbnailFullPath (string fileName) {
|
public string GetRelatedThumbnailFullPath(string fileName)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var thumbName = GenerateThumbName(fileName);
|
var thumbName = GenerateThumbName(fileName);
|
||||||
return GetThumbnailFileFullPath(thumbName);
|
return GetThumbnailFileFullPath(thumbName);
|
||||||
@@ -533,10 +598,12 @@ namespace xStorageService.Providers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="type"></param>
|
/// <param name="type"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string GetFileTypeFolderPath (XFileType type) {
|
public string GetFileTypeFolderPath(XFileType type)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
// Retrieve Folder Path Based on file ...
|
// Retrieve Folder Path Based on file ...
|
||||||
switch (type) {
|
switch (type)
|
||||||
|
{
|
||||||
case XFileType.Image:
|
case XFileType.Image:
|
||||||
case XFileType.CoverImage:
|
case XFileType.CoverImage:
|
||||||
case XFileType.ProfileImasge:
|
case XFileType.ProfileImasge:
|
||||||
@@ -564,10 +631,13 @@ namespace xStorageService.Providers {
|
|||||||
public string GetFileFolderPath(
|
public string GetFileFolderPath(
|
||||||
string fileName,
|
string fileName,
|
||||||
bool isTemp = false,
|
bool isTemp = false,
|
||||||
bool isWidget = false) {
|
bool isWidget = false
|
||||||
|
)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
// Validate Args ...
|
// Validate Args ...
|
||||||
if (fileName.IsNullOrEmpty ()) {
|
if (fileName.IsNullOrEmpty())
|
||||||
|
{
|
||||||
XException.InvalidArgs.Throw();
|
XException.InvalidArgs.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -580,14 +650,16 @@ namespace xStorageService.Providers {
|
|||||||
//
|
//
|
||||||
// if isTemp equals true
|
// if isTemp equals true
|
||||||
// ignore file type and return Temp Folder ...
|
// ignore file type and return Temp Folder ...
|
||||||
if (isTemp) {
|
if (isTemp)
|
||||||
|
{
|
||||||
folderPath = GetTempFolderPath();
|
folderPath = GetTempFolderPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// if isWidget equals true and isTemp equals false
|
// if isWidget equals true and isTemp equals false
|
||||||
// ignore file type and return Widget's Folder ...
|
// ignore file type and return Widget's Folder ...
|
||||||
if (isWidget && !isTemp) {
|
if (isWidget && !isTemp)
|
||||||
|
{
|
||||||
folderPath = GetWidgetsFolderPath();
|
folderPath = GetWidgetsFolderPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -595,13 +667,15 @@ namespace xStorageService.Providers {
|
|||||||
// if both isTemp and isWidget equals false
|
// if both isTemp and isWidget equals false
|
||||||
// which is the default state, retrieve proper folder path
|
// which is the default state, retrieve proper folder path
|
||||||
// based on file type and return it ...
|
// based on file type and return it ...
|
||||||
if (!isTemp && !isWidget) {
|
if (!isTemp && !isWidget)
|
||||||
|
{
|
||||||
folderPath = GetFileTypeFolderPath(fileType);
|
folderPath = GetFileTypeFolderPath(fileType);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Check folderPath restrict to have Value ...
|
// Check folderPath restrict to have Value ...
|
||||||
if (folderPath.IsNullOrEmpty ()) {
|
if (folderPath.IsNullOrEmpty())
|
||||||
|
{
|
||||||
XException.InvalidData.Throw();
|
XException.InvalidData.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -621,7 +695,8 @@ namespace xStorageService.Providers {
|
|||||||
string fileName,
|
string fileName,
|
||||||
bool isTemp = false,
|
bool isTemp = false,
|
||||||
bool isWidget = false
|
bool isWidget = false
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var folderPath = GetFileFolderPath(
|
var folderPath = GetFileFolderPath(
|
||||||
fileName,
|
fileName,
|
||||||
@@ -630,7 +705,8 @@ namespace xStorageService.Providers {
|
|||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
if (folderPath.IsNullOrEmpty ()) {
|
if (folderPath.IsNullOrEmpty())
|
||||||
|
{
|
||||||
XException.ActionFailed.Throw();
|
XException.ActionFailed.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -642,11 +718,17 @@ namespace xStorageService.Providers {
|
|||||||
/// Save a File into Storage Based on it's Type
|
/// Save a File into Storage Based on it's Type
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="file"></param>
|
/// <param name="file"></param>
|
||||||
|
/// <param name="isTemp"></param>
|
||||||
|
/// <param name="isWidget"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<string> SaveFileAsync(
|
public async Task<string> SaveFileAsync(
|
||||||
IFormFile file,
|
IFormFile file,
|
||||||
bool isTemp = false,
|
bool isTemp = false,
|
||||||
bool isWidget = false) {
|
bool isWidget = false,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
// Validate Args ...
|
// Validate Args ...
|
||||||
ValidateFile(file);
|
ValidateFile(file);
|
||||||
@@ -659,8 +741,13 @@ namespace xStorageService.Providers {
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Save File ...
|
// Save File ...
|
||||||
using (var stream = new FileStream (fileFullPath, FileMode.Create)) {
|
using (var stream = new FileStream(fileFullPath, FileMode.Create))
|
||||||
await file.CopyToAsync (stream);
|
{
|
||||||
|
//
|
||||||
|
await file.CopyToAsync(
|
||||||
|
stream,
|
||||||
|
cancellationToken
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -674,20 +761,26 @@ namespace xStorageService.Providers {
|
|||||||
/// Delete a Physical File by Validate it's Exists
|
/// Delete a Physical File by Validate it's Exists
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fileFullPath"></param>
|
/// <param name="fileFullPath"></param>
|
||||||
|
/// <param name="forceFileExists"></param>
|
||||||
|
/// <param name="exception"></param>
|
||||||
public void DeleteFile(
|
public void DeleteFile(
|
||||||
string fileFullPath,
|
string fileFullPath,
|
||||||
bool forceFileExists = true,
|
bool forceFileExists = true,
|
||||||
Exception exception = null) {
|
Exception exception = null
|
||||||
|
)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
// Validate Args ...
|
// Validate Args ...
|
||||||
if (!forceFileExists &&
|
if (!forceFileExists &&
|
||||||
fileFullPath.IsNullOrEmpty ()) {
|
fileFullPath.IsNullOrEmpty())
|
||||||
|
{
|
||||||
XException.InvalidArgs.Throw();
|
XException.InvalidArgs.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Prepare Default Exception ...
|
// Prepare Default Exception ...
|
||||||
if (exception == null) {
|
if (exception == null)
|
||||||
|
{
|
||||||
exception = XException.NotFound.ToException();
|
exception = XException.NotFound.ToException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -695,7 +788,8 @@ namespace xStorageService.Providers {
|
|||||||
// Check File Exists ...
|
// Check File Exists ...
|
||||||
var isFileExists = File.Exists(fileFullPath);
|
var isFileExists = File.Exists(fileFullPath);
|
||||||
if (forceFileExists &&
|
if (forceFileExists &&
|
||||||
!isFileExists) {
|
!isFileExists)
|
||||||
|
{
|
||||||
XException.NotFound.Throw();
|
XException.NotFound.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -703,7 +797,8 @@ namespace xStorageService.Providers {
|
|||||||
// Handle Prevent Error when forceFileExists false
|
// Handle Prevent Error when forceFileExists false
|
||||||
// and File doesn't Exists ...
|
// and File doesn't Exists ...
|
||||||
if (!forceFileExists &&
|
if (!forceFileExists &&
|
||||||
!isFileExists) {
|
!isFileExists)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -723,21 +818,25 @@ namespace xStorageService.Providers {
|
|||||||
ICollection<string> fileFullPaths,
|
ICollection<string> fileFullPaths,
|
||||||
bool forceFileExists = true,
|
bool forceFileExists = true,
|
||||||
Exception exception = null
|
Exception exception = null
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
if (exception.IsNull ()) {
|
if (exception.IsNull())
|
||||||
|
{
|
||||||
exception = XException.NotFound.ToException();
|
exception = XException.NotFound.ToException();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
var result = fileFullPaths.Where(f => !IsFileExists(GetFileFullPath(f))).ToList();
|
var result = fileFullPaths.Where(f => !IsFileExists(GetFileFullPath(f))).ToList();
|
||||||
if (forceFileExists && result.HasChild ()) {
|
if (forceFileExists && result.HasChild())
|
||||||
|
{
|
||||||
throw exception;
|
throw exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
var existsFile = fileFullPaths.Where(f => IsFileExists(f)).ToList();
|
var existsFile = fileFullPaths.Where(f => IsFileExists(f)).ToList();
|
||||||
existsFile.ForEach (f => {
|
existsFile.ForEach(f =>
|
||||||
|
{
|
||||||
DeleteFile(
|
DeleteFile(
|
||||||
f,
|
f,
|
||||||
forceFileExists: forceFileExists,
|
forceFileExists: forceFileExists,
|
||||||
@@ -753,18 +852,26 @@ namespace xStorageService.Providers {
|
|||||||
/// Create Thumbnail based on FileName.Ext
|
/// Create Thumbnail based on FileName.Ext
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fileName"></param>
|
/// <param name="fileName"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task CreateThumbnail (string fileName) {
|
public async Task CreateThumbnail(
|
||||||
|
string fileName,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
if (fileName.IsNullOrEmpty ()) {
|
if (fileName.IsNullOrEmpty())
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
await Task.Run (() => {
|
await Task.Run(() =>
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var fileFullPath = GetFileFullPath(fileName);
|
var fileFullPath = GetFileFullPath(fileName);
|
||||||
if (!IsFileExists (fileFullPath)) {
|
if (!IsFileExists(fileFullPath))
|
||||||
|
{
|
||||||
XException.NotFound.Throw();
|
XException.NotFound.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -779,40 +886,48 @@ namespace xStorageService.Providers {
|
|||||||
Configuration.ThumbSize,
|
Configuration.ThumbSize,
|
||||||
Configuration.ThumbQuality
|
Configuration.ThumbQuality
|
||||||
);
|
);
|
||||||
});
|
}, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create Thumbnail based on XFile model
|
/// Create Thumbnail based on XFile model
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="file"></param>
|
/// <param name="file"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task CreateThumbnail (XFileDto file) {
|
public async Task CreateThumbnail(
|
||||||
|
XFileDto file,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
await CreateThumbnail (file.Name);
|
await CreateThumbnail(
|
||||||
|
file.Name,
|
||||||
|
cancellationToken
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// /// <summary>
|
|
||||||
// /// Create Thumbnail based on XFile model
|
|
||||||
// /// </summary>
|
|
||||||
// /// <param name="file"></param>
|
|
||||||
// /// <returns></returns>
|
|
||||||
// public async Task CreateThumbnail (XFile file) {
|
|
||||||
// //
|
|
||||||
// await CreateThumbnail (file.Name);
|
|
||||||
// }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Save and Create a Thumbnail For Profile Image
|
/// Save and Create a Thumbnail For Profile Image
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="file"></param>
|
/// <param name="file"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<XFileResult> HandleProfileImageSave (IFormFile file) {
|
public async Task<XFileResult> HandleProfileImageSave(
|
||||||
|
IFormFile file,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
ValidateProfileImage(file);
|
ValidateProfileImage(file);
|
||||||
|
|
||||||
//
|
//
|
||||||
var savedFileName = await SaveFileAsync (file, isTemp : false, isWidget : false);
|
var savedFileName = await SaveFileAsync(
|
||||||
|
file,
|
||||||
|
isTemp: false,
|
||||||
|
isWidget: false,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
var thumbFileName = GenerateThumbName(savedFileName);
|
var thumbFileName = GenerateThumbName(savedFileName);
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -820,10 +935,14 @@ namespace xStorageService.Providers {
|
|||||||
var thumbFullPath = GetThumbnailFileFullPath(thumbFileName);
|
var thumbFullPath = GetThumbnailFileFullPath(thumbFileName);
|
||||||
|
|
||||||
//
|
//
|
||||||
await CreateThumbnail (savedFileName);
|
await CreateThumbnail(
|
||||||
|
savedFileName,
|
||||||
|
cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
return new XFileResult {
|
return new XFileResult
|
||||||
|
{
|
||||||
Name = file.Name,
|
Name = file.Name,
|
||||||
FileName = savedFileName,
|
FileName = savedFileName,
|
||||||
FilePath = ConvertToProfileImageUrl(savedFileFullPath),
|
FilePath = ConvertToProfileImageUrl(savedFileFullPath),
|
||||||
@@ -836,8 +955,13 @@ namespace xStorageService.Providers {
|
|||||||
/// Handle File Upload with Support of Thumbnails ...
|
/// Handle File Upload with Support of Thumbnails ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="file"></param>
|
/// <param name="file"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<XFileResult> HandleFileSave (IFormFile file) {
|
public async Task<XFileResult> HandleFileSave(
|
||||||
|
IFormFile file,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
ValidateFile(file);
|
ValidateFile(file);
|
||||||
|
|
||||||
@@ -851,7 +975,8 @@ namespace xStorageService.Providers {
|
|||||||
var thumbFileName = "";
|
var thumbFileName = "";
|
||||||
var thumbFullPath = "";
|
var thumbFullPath = "";
|
||||||
var fileType = GetFileType(savedFileName);
|
var fileType = GetFileType(savedFileName);
|
||||||
if (fileType.IsImageKind ()) {
|
if (fileType.IsImageKind())
|
||||||
|
{
|
||||||
//
|
//
|
||||||
thumbFileName = GenerateThumbName(savedFileName);
|
thumbFileName = GenerateThumbName(savedFileName);
|
||||||
thumbFullPath = GetThumbnailFileFullPath(thumbFileName);
|
thumbFullPath = GetThumbnailFileFullPath(thumbFileName);
|
||||||
@@ -862,7 +987,8 @@ namespace xStorageService.Providers {
|
|||||||
|
|
||||||
//
|
//
|
||||||
var result =
|
var result =
|
||||||
new XFileResult {
|
new XFileResult
|
||||||
|
{
|
||||||
Name = file.FileName,
|
Name = file.FileName,
|
||||||
FileName = savedFileName,
|
FileName = savedFileName,
|
||||||
FilePath = ConvertToFileUrl(savedFileFullPath),
|
FilePath = ConvertToFileUrl(savedFileFullPath),
|
||||||
@@ -878,16 +1004,27 @@ namespace xStorageService.Providers {
|
|||||||
/// Handle File Upload with Support of Thumbnails ...
|
/// Handle File Upload with Support of Thumbnails ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="files"></param>
|
/// <param name="files"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<IEnumerable<XFileResult>> HandleFilesSave (IFormFileCollection files) {
|
public async Task<IEnumerable<XFileResult>> HandleFilesSave(
|
||||||
|
IFormFileCollection files,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
ValidateFiles(files);
|
ValidateFiles(files);
|
||||||
|
|
||||||
//
|
//
|
||||||
var result = new Collection<XFileResult>();
|
var result = new Collection<XFileResult>();
|
||||||
foreach (var file in files) {
|
foreach (var file in files)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var savedFileName = await SaveFileAsync (file, isTemp : false, isWidget : false);
|
var savedFileName = await SaveFileAsync(
|
||||||
|
file,
|
||||||
|
isTemp: false,
|
||||||
|
isWidget: false,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
var savedFileFullPath = GetFileFullPath(savedFileName);
|
var savedFileFullPath = GetFileFullPath(savedFileName);
|
||||||
@@ -896,18 +1033,23 @@ namespace xStorageService.Providers {
|
|||||||
var thumbFileName = "";
|
var thumbFileName = "";
|
||||||
var thumbFullPath = "";
|
var thumbFullPath = "";
|
||||||
var fileType = GetFileType(savedFileName);
|
var fileType = GetFileType(savedFileName);
|
||||||
if (fileType.IsImageKind ()) {
|
if (fileType.IsImageKind())
|
||||||
|
{
|
||||||
//
|
//
|
||||||
thumbFileName = GenerateThumbName(savedFileName);
|
thumbFileName = GenerateThumbName(savedFileName);
|
||||||
thumbFullPath = GetThumbnailFileFullPath(thumbFileName);
|
thumbFullPath = GetThumbnailFileFullPath(thumbFileName);
|
||||||
|
|
||||||
//
|
//
|
||||||
await CreateThumbnail (savedFileName);
|
await CreateThumbnail(
|
||||||
|
savedFileName,
|
||||||
|
cancellationToken
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
result.Add(
|
result.Add(
|
||||||
new XFileResult {
|
new XFileResult
|
||||||
|
{
|
||||||
Name = file.FileName,
|
Name = file.FileName,
|
||||||
FileName = savedFileName,
|
FileName = savedFileName,
|
||||||
FilePath = ConvertToFileUrl(savedFileFullPath),
|
FilePath = ConvertToFileUrl(savedFileFullPath),
|
||||||
|
|||||||
+2
-1
@@ -1,7 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<packageSources>
|
<packageSources>
|
||||||
|
<!-- <add key="megan" value="https://hub.megan.ir/nuget/index.json" /> -->
|
||||||
<add key="nuget" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
<add key="nuget" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||||
<add key="liget" value="https://nuget.saherelmhub.ir/v3/index.json" protocolVersion="3" />
|
<add key="baget" value="https://nuget.saherelmhub.ir/v3/index.json" protocolVersion="3" disableTLSCertificateValidation="true" />
|
||||||
</packageSources>
|
</packageSources>
|
||||||
</configuration>
|
</configuration>
|
||||||
+19
-6
@@ -2,11 +2,13 @@
|
|||||||
|
|
||||||
<!-- Runtime Definition -->
|
<!-- Runtime Definition -->
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
|
||||||
<PackageId>xDashboard.xStorageService</PackageId>
|
|
||||||
<Version>1.0.0</Version>
|
<Version>1.0.0</Version>
|
||||||
|
<LangVersion>12.0</LangVersion>
|
||||||
<Authors>Hadi Khazaee Asl</Authors>
|
<Authors>Hadi Khazaee Asl</Authors>
|
||||||
<Company>SaherElm IT Center</Company>
|
<Company>SaherElm IT Center</Company>
|
||||||
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
|
<PackageId>xDashboard.xStorageService</PackageId>
|
||||||
|
|
||||||
<Description>
|
<Description>
|
||||||
provide File Storage/Validating/Handling and etc tools to xDashboard project.
|
provide File Storage/Validating/Handling and etc tools to xDashboard project.
|
||||||
</Description>
|
</Description>
|
||||||
@@ -17,19 +19,30 @@
|
|||||||
|
|
||||||
<!-- Icon Handling -->
|
<!-- Icon Handling -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="../../Resources/Images/favicon.png" Link="icon.png" Pack="true" PackagePath="\icon.png" />
|
<None Include="../../Resources/Images/favicon.png" Link="icon.png" Pack="true"
|
||||||
|
PackagePath="\icon.png" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<!-- Local Modules -->
|
<!-- Local Modules -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="xDashboard.xModels" Version="1.0.0" />
|
</ItemGroup>
|
||||||
<!-- <ProjectReference Include="../xModels/xModels.csproj" /> -->
|
|
||||||
|
<!-- Local Dependencies -->
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="../xModels/xModels.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<!-- Dependencies -->
|
<!-- Dependencies -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Magick.NET-Q8-AnyCPU" Version="7.23.1" />
|
<PackageReference Include="Magick.NET-Q8-AnyCPU" Version="7.23.1" />
|
||||||
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="5.0.0" />
|
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="3.1.32.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<!-- For XML Documentation Support -->
|
||||||
|
<PropertyGroup>
|
||||||
|
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||||
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
|
<NoWarn>$(NoWarn);1591</NoWarn>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
Reference in New Issue
Block a user