/// <summary> /// Get picture (thumb) physical path /// </summary> /// <param name="thumbFileName">Filename</param> /// <returns>Local picture physical path</returns> protected virtual async Task <string> GetThumbPhysicalPath(string thumbFileName) { var thumbFile = _mediaFileStore.Combine(_thumbPath, thumbFileName); var fileInfo = await _mediaFileStore.GetFileInfo(thumbFile); return(fileInfo?.PhysicalPath); }
public async Task <IActionResult> CustomCss() { var model = new Editor(); var pathFile = _mediaFileStore.Combine("assets", "custom", "style.css"); var file = await _mediaFileStore.GetFileInfo(pathFile); if (file != null) { model.Content = await _mediaFileStore.ReadAllText(pathFile); } if (string.IsNullOrEmpty(model.Content)) { model.Content = "/* my custom style */"; } return(View(model)); }
public virtual async Task <IActionResult> Index(string fileName) { if (!_commonSettings.AllowToReadLetsEncryptFile) { return(Content("")); } if (fileName == null) { return(Content("")); } var filepath = _mediaFileStore.Combine("assets", "acme", Path.GetFileName(fileName)); var fileInfo = await _mediaFileStore.GetFileInfo(filepath); if (fileInfo != null) { return(File(await _mediaFileStore.ReadAllText(filepath), "text/plain")); } return(Content("")); }
private async Task <string> PrepareRobotsTextFile() { var sb = new StringBuilder(); //if robots.txt exists, use it var robotsFile = await _mediaFileStore.GetFileInfo("robots.custom.txt"); if (robotsFile != null) { //the robots.txt file exists string robotsFileContent = await _mediaFileStore.ReadAllText(robotsFile.Name); sb.Append(robotsFileContent); } else { //doesn't exist. generate var disallowPaths = new List <string> { "/admin", "/bin/", "/assets/files/", "/assets/files/exportimport/", "/country/getstatesbycountryid", "/install", "/setproductreviewhelpfulness", }; var localizableDisallowPaths = new List <string> { "/addproducttocart/catalog/", "/addproducttocart/details/", "/outofstocksubscriptions/manage", "/cart", "/changelanguage/*", "/checkout", "/checkout/billingaddress", "/checkout/completed", "/checkout/confirm", "/checkout/shippingaddress", "/checkout/shippingmethod", "/checkout/paymentinfo", "/checkout/paymentmethod", "/clearcomparelist", "/compareproducts", "/compareproducts/add/*", "/account/activation", "/account/addresses", "/account/changepassword", "/account/checkusernameavailability", "/account/downloadableproducts", "/account/info", "/account/auctions", "/common/customeractioneventurl", "/common/getactivepopup", "/common/removepopup", "/deletepm", "/emailwishlist", "/login/*", "/newsletter/subscriptionactivation", "/checkout", "/order/history", "/orderdetails", "/passwordrecovery/confirm", "/popupinteractiveform", "/register/*", "/merchandisereturn", "/merchandisereturn/history", "/loyaltypoints/history", "/search?", "/shoppingcart/*", "/storeclosed", "/subscribenewsletter", "/subscribenewsletter/SaveCategories", "/page/authenticate", "/uploadfileproductattribute", "/uploadfilecheckoutattribute", "/wishlist", }; const string newLine = "\r\n"; //Environment.NewLine sb.Append("User-agent: *"); sb.Append(newLine); //sitemaps if (_config.SeoFriendlyUrlsForLanguagesEnabled) { //URLs are localizable. Append SEO code foreach (var language in await _languageService.GetAllLanguages(storeId: _workContext.CurrentStore.Id)) { sb.AppendFormat("Sitemap: {0}{1}/sitemap.xml", _workContext.CurrentStore.Url, language.UniqueSeoCode); sb.Append(newLine); } } else { //localizable paths (without SEO code) sb.AppendFormat("Sitemap: {0}sitemap.xml", _workContext.CurrentStore.Url); sb.Append(newLine); } //host var storeLocation = _workContext.CurrentStore.SslEnabled ? _workContext.CurrentStore.SecureUrl.TrimEnd('/') : _workContext.CurrentStore.Url.TrimEnd('/'); sb.AppendFormat("Host: {0}", storeLocation); sb.Append(newLine); //usual paths foreach (var path in disallowPaths) { sb.AppendFormat("Disallow: {0}", path); sb.Append(newLine); } //localizable paths (without SEO code) foreach (var path in localizableDisallowPaths) { sb.AppendFormat("Disallow: {0}", path); sb.Append(newLine); } if (_config.SeoFriendlyUrlsForLanguagesEnabled) { //URLs are localizable. Append SEO code foreach (var language in await _languageService.GetAllLanguages(storeId: _workContext.CurrentStore.Id)) { foreach (var path in localizableDisallowPaths) { sb.AppendFormat("Disallow: /{0}{1}", language.UniqueSeoCode, path); sb.Append(newLine); } } } //load and add robots.txt additions to the end of file. var robotsAdditionsFile = await _mediaFileStore.GetFileInfo("robots.additions.txt"); if (robotsAdditionsFile != null) { string robotsFileContent = await _mediaFileStore.ReadAllText(robotsAdditionsFile.Name); sb.Append(robotsFileContent); } } return(sb.ToString()); }
public virtual async Task <IActionResult> AsyncLogoUpload() { if (!await _permissionService.Authorize(StandardPermission.ManageSettings)) { return(Content("Access denied")); } var form = await HttpContext.Request.ReadFormAsync(); var httpPostedFile = form.Files.FirstOrDefault(); if (httpPostedFile == null) { return(Json(new { success = false, message = "No file uploaded", })); } var qqFileNameParameter = "qqfilename"; var fileName = httpPostedFile.FileName; if (String.IsNullOrEmpty(fileName) && form.ContainsKey(qqFileNameParameter)) { fileName = form[qqFileNameParameter].ToString(); } fileName = Path.GetFileName(fileName); var contentType = httpPostedFile.ContentType; var fileExtension = Path.GetExtension(fileName); if (!String.IsNullOrEmpty(fileExtension)) { fileExtension = fileExtension.ToLowerInvariant(); } if (!GetAllowedFileTypes().Contains(fileExtension)) { return(Json(new { success = false, message = "File no allowed" })); } //contentType is not always available //that's why we manually update it here //http://www.sfsu.edu/training/mimetype.htm if (String.IsNullOrEmpty(contentType)) { switch (fileExtension) { case ".bmp": contentType = "image/bmp"; break; case ".gif": contentType = "image/gif"; break; case ".jpeg": case ".jpg": case ".jpe": case ".jfif": case ".pjpeg": case ".pjp": contentType = "image/jpeg"; break; case ".png": contentType = "image/png"; break; case ".tiff": case ".tif": contentType = "image/tiff"; break; default: break; } } if (String.IsNullOrEmpty(contentType)) { return(Json(new { success = false, message = "Unknown content type" })); } fileName = fileName.Replace(" ", ""); var fileInfo = await _mediaFileStore.GetFileInfo(fileName); if (fileInfo == null) { try { var filepath = _mediaFileStore.GetDirectoryInfo(""); if (filepath != null) { using (var stream = new FileStream(_mediaFileStore.Combine(filepath.PhysicalPath, fileName), FileMode.OpenOrCreate)) { httpPostedFile.CopyTo(stream); } return(Json(new { success = true, imageUrl = fileName })); } else { return(Json(new { success = false, message = "Physical path not exist" })); } } catch (Exception ex) { return(Json(new { success = false, message = ex.Message })); } } return(Json(new { success = false, message = "This filename exists" })); }