@namespace Oqtane.Modules.Admin.Files @using System.IO @inherits ModuleBase @inject NavigationManager NavigationManager @inject IFileService FileService @inject IFolderService FolderService @inject IStringLocalizer Localizer
@Localizer["Cancel"]
@if (_folders != null) {
@Localizer["Cancel"] }
@code { private string url = string.Empty; private List _folders; private int _folderId = -1; public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; protected override async Task OnInitializedAsync() { _folders = await FolderService.GetFoldersAsync(ModuleState.SiteId); if (PageState.QueryString.ContainsKey("id")) { _folderId = int.Parse(PageState.QueryString["id"]); } } private async Task Download() { if (url == string.Empty || _folderId == -1) { AddModuleMessage(Localizer["You Must Enter A Url And Select A Folder"], MessageType.Warning); return; } var filename = url.Substring(url.LastIndexOf("/", StringComparison.Ordinal) + 1); if (!Constants.UploadableFiles.Split(',') .Contains(Path.GetExtension(filename).ToLower().Replace(".", ""))) { AddModuleMessage(Localizer["File Could Not Be Downloaded From Url Due To Its File Extension"], MessageType.Warning); return; } if (!filename.IsPathOrFileValid()) { AddModuleMessage(Localizer["You Must Enter A Url With A Valid File Name"], MessageType.Warning); return; } try { await FileService.UploadFileAsync(url, _folderId); await logger.LogInformation("File Downloaded Successfully From Url {Url}", url); AddModuleMessage(Localizer["File Downloaded Successfully From Url"], MessageType.Success); } catch (Exception ex) { await logger.LogError(ex, "Error Downloading File From Url {Url} {Error}", url, ex.Message); AddModuleMessage(Localizer["Error Downloading File From Url. Please Verify That The Url Is Valid."], MessageType.Error); } } }