@@ -114,4 +120,12 @@
}
StateHasChanged();
}
+
+ public async Task CloseFileManager()
+ {
+ filemanagervisible = false;
+ message = "";
+ StateHasChanged();
+ }
+
}
\ No newline at end of file
diff --git a/Oqtane.Server/Controllers/FileController.cs b/Oqtane.Server/Controllers/FileController.cs
index cf99306d..26a83c80 100644
--- a/Oqtane.Server/Controllers/FileController.cs
+++ b/Oqtane.Server/Controllers/FileController.cs
@@ -13,6 +13,7 @@ using System.Threading;
using System.Threading.Tasks;
using Oqtane.Security;
using System.Linq;
+using System.Drawing;
namespace Oqtane.Controllers
{
@@ -25,7 +26,6 @@ namespace Oqtane.Controllers
private readonly IUserPermissions UserPermissions;
private readonly ITenantResolver Tenants;
private readonly ILogManager logger;
- private readonly string WhiteList = "jpg,jpeg,jpe,gif,bmp,png,mov,wmv,avi,mp4,mp3,doc,docx,xls,xlsx,ppt,pptx,pdf,txt,zip,nupkg";
public FileController(IWebHostEnvironment environment, IFileRepository Files, IFolderRepository Folders, IUserPermissions UserPermissions, ITenantResolver Tenants, ILogManager logger)
{
@@ -139,16 +139,23 @@ namespace Oqtane.Controllers
string folderpath = GetFolderPath(folder);
CreateDirectory(folderpath);
string filename = url.Substring(url.LastIndexOf("/") + 1);
- try
+ // check for allowable file extensions
+ if (Constants.UploadableFiles.Contains(Path.GetExtension(filename).Replace(".", "")))
{
- var client = new System.Net.WebClient();
- client.DownloadFile(url, folderpath + filename);
- FileInfo fileinfo = new FileInfo(folderpath + filename);
- file = Files.AddFile(new Models.File { Name = filename, FolderId = folder.FolderId, Extension = fileinfo.Extension.Replace(".",""), Size = (int)fileinfo.Length });
+ try
+ {
+ var client = new System.Net.WebClient();
+ client.DownloadFile(url, folderpath + filename);
+ Files.AddFile(CreateFile(filename, folder.FolderId, folderpath + filename));
+ }
+ catch
+ {
+ logger.Log(LogLevel.Error, this, LogFunction.Create, "File Could Not Be Downloaded From Url {Url}", url);
+ }
}
- catch
+ else
{
- logger.Log(LogLevel.Error, this, LogFunction.Create, "File Could Not Be Downloaded From Url {Url}", url);
+ logger.Log(LogLevel.Error, this, LogFunction.Create, "File Could Not Be Downloaded From Url Due To Its File Extension {Url}", url);
}
}
else
@@ -193,8 +200,7 @@ namespace Oqtane.Controllers
string upload = await MergeFile(folderpath, file.FileName);
if (upload != "" && folderid != -1)
{
- FileInfo fileinfo = new FileInfo(folderpath + upload);
- Files.AddFile(new Models.File { Name = upload, FolderId = folderid, Extension = fileinfo.Extension.Replace(".", ""), Size = (int)fileinfo.Length });
+ Files.AddFile(CreateFile(upload, folderid, folderpath + upload));
}
}
else
@@ -248,7 +254,7 @@ namespace Oqtane.Controllers
}
// check for allowable file extensions
- if (!WhiteList.Contains(Path.GetExtension(filename).Replace(".", "")))
+ if (!Constants.UploadableFiles.Contains(Path.GetExtension(filename).Replace(".", "")))
{
System.IO.File.Delete(Path.Combine(folder, filename + ".tmp"));
}
@@ -357,5 +363,31 @@ namespace Oqtane.Controllers
}
}
}
+
+ private Models.File CreateFile(string filename, int folderid, string filepath)
+ {
+ Models.File file = new Models.File();
+ file.Name = filename;
+ file.FolderId = folderid;
+
+ FileInfo fileinfo = new FileInfo(filepath);
+ file.Extension = fileinfo.Extension.ToLower().Replace(".", "");
+ file.Size = (int)fileinfo.Length;
+ file.ImageHeight = 0;
+ file.ImageWidth = 0;
+
+ if (Constants.ImageFiles.Contains(file.Extension))
+ {
+ FileStream stream = new FileStream(filepath, FileMode.Open, FileAccess.Read);
+ using (var image = Image.FromStream(stream))
+ {
+ file.ImageHeight = image.Height;
+ file.ImageWidth = image.Width;
+ }
+ stream.Close();
+ }
+
+ return file;
+ }
}
}
\ No newline at end of file
diff --git a/Oqtane.Server/Oqtane.Server.csproj b/Oqtane.Server/Oqtane.Server.csproj
index b9c304de..bdf1e2b9 100644
--- a/Oqtane.Server/Oqtane.Server.csproj
+++ b/Oqtane.Server/Oqtane.Server.csproj
@@ -44,6 +44,7 @@
+
diff --git a/Oqtane.Server/Repository/SiteRepository.cs b/Oqtane.Server/Repository/SiteRepository.cs
index d206c763..495930ba 100644
--- a/Oqtane.Server/Repository/SiteRepository.cs
+++ b/Oqtane.Server/Repository/SiteRepository.cs
@@ -176,7 +176,7 @@ namespace Oqtane.Repository
FolderRepository.AddFolder(new Folder { SiteId = site.SiteId, ParentId = folder.FolderId, Name = "Users", Path = "Users\\", Order = 1, IsSystem = true, Permissions = "[{\"PermissionName\":\"Browse\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]" });
if (site.Name == "Default Site")
{
- File file = FileRepository.AddFile(new File { FolderId = folder.FolderId, Name = "logo.png", Extension = "png", Size = 8192 });
+ File file = FileRepository.AddFile(new File { FolderId = folder.FolderId, Name = "logo.png", Extension = "png", Size = 8192, ImageHeight = 80, ImageWidth = 250 });
site.LogoFileId = file.FileId;
UpdateSite(site);
}
diff --git a/Oqtane.Server/Scripts/00.00.00.sql b/Oqtane.Server/Scripts/00.00.00.sql
index 29637d45..e43b1e76 100644
--- a/Oqtane.Server/Scripts/00.00.00.sql
+++ b/Oqtane.Server/Scripts/00.00.00.sql
@@ -285,6 +285,8 @@ CREATE TABLE [dbo].[File](
[Name] [nvarchar](250) NOT NULL,
[Extension] [nvarchar](50) NOT NULL,
[Size] [int] NOT NULL,
+ [ImageHeight] [int] NOT NULL,
+ [ImageWidth] [int] NOT NULL,
[CreatedBy] [nvarchar](256) NOT NULL,
[CreatedOn] [datetime] NOT NULL,
[ModifiedBy] [nvarchar](256) NOT NULL,
diff --git a/Oqtane.Shared/Models/File.cs b/Oqtane.Shared/Models/File.cs
index 44acbcbd..ae20fa11 100644
--- a/Oqtane.Shared/Models/File.cs
+++ b/Oqtane.Shared/Models/File.cs
@@ -9,6 +9,8 @@ namespace Oqtane.Models
public string Name { get; set; }
public string Extension { get; set; }
public int Size { get; set; }
+ public int ImageHeight { get; set; }
+ public int ImageWidth { get; set; }
public string CreatedBy { get; set; }
public DateTime CreatedOn { get; set; }
diff --git a/Oqtane.Shared/Models/Site.cs b/Oqtane.Shared/Models/Site.cs
index 439f5131..bcb358df 100644
--- a/Oqtane.Shared/Models/Site.cs
+++ b/Oqtane.Shared/Models/Site.cs
@@ -1,5 +1,4 @@
using System;
-using System.ComponentModel.DataAnnotations.Schema;
namespace Oqtane.Models
{
@@ -21,23 +20,5 @@ namespace Oqtane.Models
public string DeletedBy { get; set; }
public DateTime? DeletedOn { get; set; }
public bool IsDeleted { get; set; }
-
- [NotMapped]
- public string TenantRootPath
- {
- get
- {
- return "Tenants/" + TenantId.ToString() + "/";
- }
- }
-
- [NotMapped]
- public string SiteRootPath
- {
- get
- {
- return "Tenants/" + TenantId.ToString() + "/Sites/" + SiteId.ToString() + "/";
- }
- }
}
}
diff --git a/Oqtane.Shared/Shared/Constants.cs b/Oqtane.Shared/Shared/Constants.cs
index e6c2fcca..fe4a12dd 100644
--- a/Oqtane.Shared/Shared/Constants.cs
+++ b/Oqtane.Shared/Shared/Constants.cs
@@ -31,5 +31,8 @@
public const string HostRole = "Host Users";
public const string AdminRole = "Administrators";
public const string RegisteredRole = "Registered Users";
+
+ public const string ImageFiles = "jpg,jpeg,jpe,gif,bmp,png";
+ public const string UploadableFiles = "jpg,jpeg,jpe,gif,bmp,png,mov,wmv,avi,mp4,mp3,doc,docx,xls,xlsx,ppt,pptx,pdf,txt,zip,nupkg";
}
}