diff --git a/src/HGO.ASPNetCore.FileManager/CommandsProcessor/FileManagerCommandsProcessor.cs b/src/HGO.ASPNetCore.FileManager/CommandsProcessor/FileManagerCommandsProcessor.cs index e634130..1aedde0 100644 --- a/src/HGO.ASPNetCore.FileManager/CommandsProcessor/FileManagerCommandsProcessor.cs +++ b/src/HGO.ASPNetCore.FileManager/CommandsProcessor/FileManagerCommandsProcessor.cs @@ -612,14 +612,14 @@ private IActionResult Download(string id, string filePath, bool view) }; } - if (view) - { - return new FileStreamResult(File.OpenRead(physicalPath), Utils.GetMimeTypeForFileExtension(physicalPath)); - } + //if (view) + //{ + // return new FileStreamResult(File.OpenRead(physicalPath), Utils.GetMimeTypeForFileExtension(physicalPath)); + //} return new PhysicalFileResult(physicalPath, Utils.GetMimeTypeForFileExtension(physicalPath)) { - FileDownloadName = Path.GetFileName(physicalPath), + FileDownloadName = view ? null : Path.GetFileName(physicalPath), EnableRangeProcessing = true }; } @@ -825,6 +825,7 @@ private IActionResult FilePreview(string id, string filePath) }; } + var basePath = _httpContextAccessor.HttpContext?.Request.PathBase.Value?.TrimEnd('/') ?? ""; switch (Path.GetExtension(physicalPath).ToLower().Trim()) { case ".png" or ".jpg" or ".webp" or ".gif" or ".svg" or ".jpeg" or ".apng" or ".avif" or ".ico" or ".bmp" or ".tif" or ".tiff": @@ -834,31 +835,31 @@ private IActionResult FilePreview(string id, string filePath) EnableRangeProcessing = true }; case ".zip" or ".rar" or ".tar" or ".7z" or ".gzip" or ".7zip": - return new RedirectResult("/hgofilemanager/images/zip.png") { Permanent = true }; + return new RedirectResult(basePath + "/hgofilemanager/images/zip.png") { Permanent = true }; case ".js" or ".jsx": - return new RedirectResult("/hgofilemanager/images/js.png") { Permanent = true }; + return new RedirectResult(basePath + "/hgofilemanager/images/js.png") { Permanent = true }; case ".php": - return new RedirectResult("/hgofilemanager/images/php.png") { Permanent = true }; + return new RedirectResult(basePath + "/hgofilemanager/images/php.png") { Permanent = true }; case ".html" or ".htm" or ".cshtml": - return new RedirectResult("/hgofilemanager/images/html.png") { Permanent = true }; + return new RedirectResult(basePath + "/hgofilemanager/images/html.png") { Permanent = true }; case ".css": - return new RedirectResult("/hgofilemanager/images/css.png") { Permanent = true }; + return new RedirectResult(basePath + "/hgofilemanager/images/css.png") { Permanent = true }; case ".json": - return new RedirectResult("/hgofilemanager/images/json.png") { Permanent = true }; + return new RedirectResult(basePath + "/hgofilemanager/images/json.png") { Permanent = true }; case ".txt": - return new RedirectResult("/hgofilemanager/images/txt.png") { Permanent = true }; + return new RedirectResult(basePath + "/hgofilemanager/images/txt.png") { Permanent = true }; case ".pdf": - return new RedirectResult("/hgofilemanager/images/pdf.png") { Permanent = true }; + return new RedirectResult(basePath + "/hgofilemanager/images/pdf.png") { Permanent = true }; case ".mp4": - return new RedirectResult("/hgofilemanager/images/mp4.png") { Permanent = true }; + return new RedirectResult(basePath + "/hgofilemanager/images/mp4.png") { Permanent = true }; case ".mp3": - return new RedirectResult("/hgofilemanager/images/mp3.png") { Permanent = true }; + return new RedirectResult(basePath + "/hgofilemanager/images/mp3.png") { Permanent = true }; case ".exe": - return new RedirectResult("/hgofilemanager/images/exe.png") { Permanent = true }; + return new RedirectResult(basePath + "/hgofilemanager/images/exe.png") { Permanent = true }; case ".dll": - return new RedirectResult("/hgofilemanager/images/dll.png") { Permanent = true }; + return new RedirectResult(basePath + "/hgofilemanager/images/dll.png") { Permanent = true }; default: - return new RedirectResult("/hgofilemanager/images/file.png") { Permanent = true }; + return new RedirectResult(basePath + "/hgofilemanager/images/file.png") { Permanent = true }; } } } \ No newline at end of file diff --git a/src/HGO.ASPNetCore.FileManager/Extensions.cs b/src/HGO.ASPNetCore.FileManager/Extensions.cs index efcaef2..384d6a4 100644 --- a/src/HGO.ASPNetCore.FileManager/Extensions.cs +++ b/src/HGO.ASPNetCore.FileManager/Extensions.cs @@ -14,7 +14,7 @@ public static class Extensions { public static void AddHgoFileManager(this IServiceCollection services) { - services.AddControllersWithViews().AddRazorRuntimeCompilation(c=> c.FileProviders.Add(new EmbeddedFileProvider(typeof(FileManagerComponent) + services.AddControllersWithViews().AddRazorRuntimeCompilation(c => c.FileProviders.Add(new EmbeddedFileProvider(typeof(FileManagerComponent) .GetTypeInfo().Assembly, "HGO.ASPNetCore.FileManager"))); services.AddSession(); services.AddSingleton(); @@ -42,54 +42,48 @@ public static HtmlString RenderHgoFileManagerJavaScripts(this RazorPageBase razo excludelist.AddRange(exclude); } + var basePath = razorPage.ViewContext.HttpContext.Request.PathBase.HasValue + ? razorPage.ViewContext.HttpContext.Request.PathBase.Value.TrimEnd('/') + : ""; var scripts = ""; if (!excludelist.Any(p => p.ToLower() == "js.cookie")) { - scripts += - "\r\n"; + scripts += $"\r\n"; } if (!excludelist.Any(p => p.ToLower() == "fontawesome")) { - scripts += - "\r\n"; + scripts += $"\r\n"; } if (!excludelist.Any(p => p.ToLower() == "lozad.js")) { - scripts += - "\r\n"; + scripts += $"\r\n"; } if (!excludelist.Any(p => p.ToLower() == "jsTree")) { - scripts += - "\r\n"; + scripts += $"\r\n"; } if (!excludelist.Any(p => p.ToLower() == "viselect")) { - scripts += - "\r\n"; + scripts += $"\r\n"; } if (!excludelist.Any(p => p.ToLower() == "split.js")) { - scripts += - "\r\n"; + scripts += $"\r\n"; } if (!excludelist.Any(p => p.ToLower() == "dropzone")) { - scripts += - "\r\n"; + scripts += $"\r\n"; } if (!excludelist.Any(p => p.ToLower() == "context-js")) { - scripts += - "\r\n"; + scripts += $"\r\n"; } if (!excludelist.Any(p => p.ToLower() == "toastify")) { - scripts += - "\r\n"; + scripts += $"\r\n"; } - scripts += "\r\n"; + scripts += $"\r\n"; return new HtmlString(scripts); } @@ -101,46 +95,43 @@ public static HtmlString RenderHgoFileManagerCss(this RazorPageBase razorPage, b excludelist.AddRange(exclude); } - var styles = ""; + var basePath = razorPage.ViewContext.HttpContext.Request.PathBase.HasValue + ? razorPage.ViewContext.HttpContext.Request.PathBase.Value.TrimEnd('/') + : ""; + var styles = $"\r\n"; if (!excludelist.Any(p => p.ToLower() == "jsTree")) { - styles += - "\r\n"; + styles += $"\r\n"; } if (!excludelist.Any(p => p.ToLower() == "dropzone")) { - styles += - "\r\n"; + styles += $"\r\n"; } if (!excludelist.Any(p => p.ToLower() == "fontawesome")) { - styles += - "\r\n"; + styles += $"\r\n"; } if (!excludelist.Any(p => p.ToLower() == "context-js")) { if (darkMode) { - styles += - "\r\n"; + styles += $"\r\n"; } else { - styles += - "\r\n"; + styles += $"\r\n"; } } if (!excludelist.Any(p => p.ToLower() == "toastify")) { - styles += - "\r\n"; + styles += $"\r\n"; } - styles += "\r\n"; + styles += $"\r\n"; if (darkMode) { - styles += "\r\n"; + styles += $"\r\n"; razorPage.ViewContext.HttpContext.Session.SetString("HgoFileManagerTheme", "Dark"); } diff --git a/src/HGO.ASPNetCore.FileManager/hgofilemanager/HgoFileManager.css b/src/HGO.ASPNetCore.FileManager/hgofilemanager/HgoFileManager.css index c5ce19d..7ca8f6f 100644 --- a/src/HGO.ASPNetCore.FileManager/hgofilemanager/HgoFileManager.css +++ b/src/HGO.ASPNetCore.FileManager/hgofilemanager/HgoFileManager.css @@ -128,67 +128,67 @@ } } - .hgo-fm-menu .button-continer { - display: flex; - flex-direction: row; - justify-content: flex-start; - flex-wrap: wrap; - align-content: center; - align-items: center; - } +.hgo-fm-menu .button-continer { + display: flex; + flex-direction: row; + justify-content: flex-start; + flex-wrap: wrap; + align-content: center; + align-items: center; +} - .hgo-fm-menu .input-continer { - display: flex; - flex-grow: 1; - flex-direction: row; - align-items: center; - flex-wrap: wrap; - justify-content: space-between; - align-content: center; - } +.hgo-fm-menu .input-continer { + display: flex; + flex-grow: 1; + flex-direction: row; + align-items: center; + flex-wrap: wrap; + justify-content: space-between; + align-content: center; +} + +.hgo-fm-menu input { + border-radius: 30px; + box-shadow: 0 3px 20px 0 rgba(0,0,0,.07); + border: solid 1px #fff; + background-color: #fff; + padding: 3px 10px; + color: #727272; + flex: auto; + transition: all .25s linear; + margin: 3px; +} - .hgo-fm-menu input { - border-radius: 30px; - box-shadow: 0 3px 20px 0 rgba(0,0,0,.07); - border: solid 1px #fff; - background-color: #fff; - padding: 3px 10px; - color: #727272; - flex: auto; + .hgo-fm-menu input:focus-visible { + border: solid 1px #aab9ff; transition: all .25s linear; - margin: 3px; + outline: none; } - .hgo-fm-menu input:focus-visible { - border: solid 1px #aab9ff; - transition: all .25s linear; - outline: none; - } +.hgo-fm-menu hr { + height: 12px; + width: 1px; + margin: 0px 3px; +} - .hgo-fm-menu hr { - height: 12px; - width: 1px; - margin: 0px 3px; - } +.hgo-fm-menu button { + border-radius: 5px; + border: solid 1px #d1d1d1; + margin: 3px; + transition: all .25s linear; + color: #3e5a70; + font-size: 16px; +} - .hgo-fm-menu button { - border-radius: 5px; - border: solid 1px #d1d1d1; - margin: 3px; + .hgo-fm-menu button:hover:enabled { + background: rgba(46, 115, 252, 0.11); + border: 1px solid rgb(0 93 255 / 36%); transition: all .25s linear; - color: #3e5a70; - font-size: 16px; } - .hgo-fm-menu button:hover:enabled { - background: rgba(46, 115, 252, 0.11); - border: 1px solid rgb(0 93 255 / 36%); - transition: all .25s linear; - } - - .hgo-fm-menu button:disabled { - color: #cdcdcd; - } + .hgo-fm-menu button:disabled { + color: #cdcdcd; + } /*---- Menu/Nav Bar end ----------------------*/ /*---- footer breadcrumb start ----------------------*/ @@ -272,7 +272,7 @@ .hgo-fm-tree .jstree-icon.jstree-themeicon { background-size: cover; - background-image: url(/hgofilemanager/images/folder.png); + background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQMAAACQp+OdAAAABlBMVEUAAAD/yigfXxocAAAAAXRSTlMAQObYZgAAAEBJREFUeF7t0LENwCAQxdBDFFmb0W6UG4GSzhFffGUDqrh6teNGMIQGKXQoYwoPrANlMIw0auNHR+WH5mOBigu9rcsJrN38ucEAAAAASUVORK5CYII='); background-position: center; } diff --git a/src/HGO.ASPNetCore.FileManager/hgofilemanager/HgoFileManager.js b/src/HGO.ASPNetCore.FileManager/hgofilemanager/HgoFileManager.js index f43f67a..c367c97 100644 --- a/src/HGO.ASPNetCore.FileManager/hgofilemanager/HgoFileManager.js +++ b/src/HGO.ASPNetCore.FileManager/hgofilemanager/HgoFileManager.js @@ -73,9 +73,9 @@ this.addButtonToMenu(); } - if (!disabledFunctions.includes('copy')) + if (!disabledFunctions.includes('copy')) this.addButtonToMenu('', (e) => this.copyItems()).setAttribute('title', 'Copy'); - if (!disabledFunctions.includes('cut')) + if (!disabledFunctions.includes('cut')) this.addButtonToMenu('', (e) => this.cutItems()).setAttribute('title', 'Cut'); if (!(disabledFunctions.includes('copy') && disabledFunctions.includes('cut'))) { this.pasteButton = this.addButtonToMenu('', (e) => this.pasteItems()); @@ -85,45 +85,45 @@ this.addButtonToMenu(); } - if (!disabledFunctions.includes('rename')) + if (!disabledFunctions.includes('rename')) this.addButtonToMenu('', (e) => this.renameSelectedItems()).setAttribute('title', 'Rename'); - if (!disabledFunctions.includes('getfilecontent')) + if (!disabledFunctions.includes('getfilecontent')) this.addButtonToMenu('', (e) => this.getFileContent()).setAttribute('title', 'Edit'); - if (!disabledFunctions.includes('delete')) + if (!disabledFunctions.includes('delete')) this.addButtonToMenu('', (e) => this.deleteSelectedItems()).setAttribute('title', 'Delete'); - if (!(disabledFunctions.includes('rename') && disabledFunctions.includes('getfilecontent') && disabledFunctions.includes('delete'))) + if (!(disabledFunctions.includes('rename') && disabledFunctions.includes('getfilecontent') && disabledFunctions.includes('delete'))) this.addButtonToMenu(); if (!disabledFunctions.includes('createnewfolder')) this.addButtonToMenu('', (e) => this.createNewFolder()).setAttribute('title', 'New Folder'); if (!disabledFunctions.includes('createnewfile')) this.addButtonToMenu('', (e) => this.createNewFile()).setAttribute('title', 'New File'); - if (!(disabledFunctions.includes('createnewfolder') && disabledFunctions.includes('createnewfile'))) + if (!(disabledFunctions.includes('createnewfolder') && disabledFunctions.includes('createnewfile'))) this.addButtonToMenu(); if (!disabledFunctions.includes('view')) this.addButtonToMenu('', (e) => this.viewFile()).setAttribute('title', 'View'); - if (!disabledFunctions.includes('download')) + if (!disabledFunctions.includes('download')) this.addButtonToMenu('', (e) => this.downloadFile()).setAttribute('title', 'Download'); - if (!disabledFunctions.includes('upload')) + if (!disabledFunctions.includes('upload')) this.addButtonToMenu('', (e) => this.showUploadPanel()).setAttribute('title', 'Upload'); - if (!(disabledFunctions.includes('download') && disabledFunctions.includes('upload') && disabledFunctions.includes('view'))) + if (!(disabledFunctions.includes('download') && disabledFunctions.includes('upload') && disabledFunctions.includes('view'))) this.addButtonToMenu(); - if (!disabledFunctions.includes('zip')) + if (!disabledFunctions.includes('zip')) this.addButtonToMenu('', (e) => this.zipSelectedItems()).setAttribute('title', 'Zip'); - if (!disabledFunctions.includes('unzip')) + if (!disabledFunctions.includes('unzip')) this.addButtonToMenu('', (e) => this.extractSelectedItems()).setAttribute('title', 'UnZip'); - if (!(disabledFunctions.includes('unzip') && disabledFunctions.includes('zip'))) + if (!(disabledFunctions.includes('unzip') && disabledFunctions.includes('zip'))) this.addButtonToMenu(); - if (!disabledFunctions.includes('toggleview')) + if (!disabledFunctions.includes('toggleview')) this.addButtonToMenu('', (e) => this.toggleFilesListView()).setAttribute('title', 'Toggle View'); if (!disabledFunctions.includes('search')) this.addInputToMenu('Search ...', (e) => { if (e.keyCode == 13) this.search(e.currentTarget.value); }, 'search-box'); - if (disabledFunctions.includes('menubar')) + if (disabledFunctions.includes('menubar')) menuContinerDiv.style.display = 'none'; } @@ -132,16 +132,16 @@ let self = this; let menuItems = []; - if (!disabledFunctions.includes('browse')) + if (!disabledFunctions.includes('browse')) menuItems.push({ text: ' Up', onclick: function (e) { self.goUpFolder(); } }); - if (!disabledFunctions.includes('reload')) + if (!disabledFunctions.includes('reload')) menuItems.push({ text: ' Reload', onclick: function (e) { self.getFolderContent(); } }); - if (!(disabledFunctions.includes('browse') && disabledFunctions.includes('reload'))) + if (!(disabledFunctions.includes('browse') && disabledFunctions.includes('reload'))) menuItems.push(null); - if (!disabledFunctions.includes('copy')) + if (!disabledFunctions.includes('copy')) menuItems.push({ text: ' Copy', onclick: function (e) { self.copyItems(); } }); - if (!disabledFunctions.includes('cut')) + if (!disabledFunctions.includes('cut')) menuItems.push({ text: ' Cut', onclick: function (e) { self.cutItems(); } }); if (!(disabledFunctions.includes('copy') && disabledFunctions.includes('cut'))) { menuItems.push({ text: ' Paste', onclick: function (e) { self.pasteItems(); }, disabled: true }); @@ -155,27 +155,27 @@ if (!(disabledFunctions.includes('createnewfolder') && disabledFunctions.includes('createnewfile'))) menuItems.push(null); - if (!disabledFunctions.includes('rename')) + if (!disabledFunctions.includes('rename')) menuItems.push({ text: ' Rename', onclick: function (e) { self.renameSelectedItems(); } }); if (!disabledFunctions.includes('getfilecontent')) menuItems.push({ text: ' Edit', onclick: function (e) { self.getFileContent(); } }); - if (!disabledFunctions.includes('delete')) + if (!disabledFunctions.includes('delete')) menuItems.push({ text: ' Delete', onclick: function (e) { self.deleteSelectedItems(); } }); - if (!(disabledFunctions.includes('rename') && disabledFunctions.includes('getfilecontent') && disabledFunctions.includes('delete'))) + if (!(disabledFunctions.includes('rename') && disabledFunctions.includes('getfilecontent') && disabledFunctions.includes('delete'))) menuItems.push(null); - if (!disabledFunctions.includes('zip')) + if (!disabledFunctions.includes('zip')) menuItems.push({ text: ' Zip', onclick: function (e) { self.zipSelectedItems(); } }); - if (!disabledFunctions.includes('unzip')) + if (!disabledFunctions.includes('unzip')) menuItems.push({ text: ' UnZip', onclick: function (e) { self.extractSelectedItems(); } }); - if (!(disabledFunctions.includes('unzip') && disabledFunctions.includes('zip'))) + if (!(disabledFunctions.includes('unzip') && disabledFunctions.includes('zip'))) menuItems.push(null); if (!disabledFunctions.includes('view')) menuItems.push({ text: ' View', onclick: function (e) { self.viewFile(); } }); - if (!disabledFunctions.includes('download')) + if (!disabledFunctions.includes('download')) menuItems.push({ text: ' Download', onclick: function (e) { self.downloadFile(); } }); - if (!disabledFunctions.includes('upload')) + if (!disabledFunctions.includes('upload')) menuItems.push({ text: ' Upload', onclick: function (e) { self.showUploadPanel(); } }); @@ -207,7 +207,7 @@ this.jsSelectContinerDiv.classList.add('hgo-fm-fsitems'); if (Cookies.get('hgo-fm-current-view-' + this.thisId)) this.jsSelectContinerDiv.classList.add(Cookies.get('hgo-fm-current-view-' + this.thisId)); - if (!disabledFunctions.includes('browse')) + if (!disabledFunctions.includes('browse')) this.jsSelectContinerDiv.addEventListener('dblclick', (e) => { e.stopPropagation(); this.goUpFolder(); @@ -245,7 +245,7 @@ "keep_selected_style": false }, "plugins": [] - }).on("select_node.jstree", (!disabledFunctions.includes('browse')) ? + }).on("select_node.jstree", (!disabledFunctions.includes('browse')) ? function (evt, data) { if (data.event.type === 'click') { if (data.node.parent === "#") { @@ -257,7 +257,7 @@ self.getFolderContent(self.getCurrentPath() + "\\" + data.node.text); } } - } + } : null ); this.jsTree = $(jsTreeDiv).jstree(true); @@ -286,7 +286,7 @@ for (const el of removed) { el.classList.remove('selected'); } - + }).on('beforedrag', ({ store, event }) => { if (!event.ctrlKey && !event.metaKey) { this.jsSelect.clearSelection(); @@ -386,10 +386,11 @@ self.getFolderContent(path); }); + let basePath = window.HGOFM_BASEPATH || ''; let fsItemImg = document.createElement('img'); fsItemImg.classList.add('lozad'); - fsItemImg.src = '/hgofilemanager/images/loading.gif'; - fsItemImg.setAttribute('data-src', '/hgofilemanager/images/folder.png'); + fsItemImg.src = basePath + '/hgofilemanager/images/loading.gif'; + fsItemImg.setAttribute('data-src', basePath + '/hgofilemanager/images/folder.png'); fsItemDiv.appendChild(fsItemImg); let fsItemSpan = document.createElement('span'); @@ -407,19 +408,20 @@ fsItemDiv.setAttribute('item-type', 'file'); fsItemDiv.classList.add('fsitem'); - if (!disabledFunctions.includes('view')) + if (!disabledFunctions.includes('view')) fsItemDiv.addEventListener('dblclick', (e) => { e.stopPropagation(); self.viewFile(); }); + let basePath = window.HGOFM_BASEPATH || ''; let fsItemImg = document.createElement('img'); fsItemImg.classList.add('lozad'); - fsItemImg.src = '/hgofilemanager/images/loading.gif'; + fsItemImg.src = basePath + '/hgofilemanager/images/loading.gif'; if (!disabledFunctions.includes('filepreview')) { fsItemImg.setAttribute('data-src', this.apiUrl + `?id=${this.thisId}&command=filePreview¶meters=${file.VirtualPath}`); } else { - fsItemImg.setAttribute('data-src', '/hgofilemanager/images/file.png'); + fsItemImg.setAttribute('data-src', basePath + '/hgofilemanager/images/file.png'); } fsItemDiv.appendChild(fsItemImg); @@ -475,7 +477,7 @@ return ""; } - showToastify = function(text, type = 'error') { + showToastify = function (text, type = 'error') { let bgColor = 'linear-gradient(to right, #b6ff8a, #238f00);'; if (type === 'error') { bgColor = "linear-gradient(to right, #ff8a8a, #ff6565)"; @@ -862,8 +864,8 @@ parallelUploads: (typeof this.config.parallelUploads != "undefined" ? this.config.parallelUploads : 1), chunking: (typeof this.config.chunking != "undefined" ? this.config.chunking : true), chunkSize: (typeof this.config.chunkSizeByte != "undefined" ? this.config.chunkSizeByte : 10000000), // bytes - retryChunks: (typeof this.config.retryChunks != "undefined" ? this.config.retryChunks : true), - retryChunksLimit: (typeof this.config.retryChunksLimit != "undefined" ? this.config.retryChunksLimit : 3), + retryChunks: (typeof this.config.retryChunks != "undefined" ? this.config.retryChunks : true), + retryChunksLimit: (typeof this.config.retryChunksLimit != "undefined" ? this.config.retryChunksLimit : 3), maxFilesize: (typeof this.config.maxFileSizeToUploadMByte != "undefined" ? this.config.maxFileSizeToUploadMByte : 256), // mega bytes acceptedFiles: (typeof this.config.acceptedFiles != "undefined" ? this.config.acceptedFiles : ''), //'.png,.pdf' paramName: 'file',