2018-03-15 10:07:04 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2020-04-03 10:09:08 +02:00
|
|
|
|
using System.IO;
|
2018-03-15 10:02:20 +01:00
|
|
|
|
using System.Linq;
|
2020-09-17 11:35:29 +02:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2020-05-19 09:52:58 +02:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2020-08-21 14:52:47 +01:00
|
|
|
|
using Microsoft.Extensions.Options;
|
2020-06-09 13:01:05 +10:00
|
|
|
|
using Umbraco.Core;
|
2019-11-19 07:52:40 +01:00
|
|
|
|
using Umbraco.Core.Configuration;
|
2020-08-21 14:52:47 +01:00
|
|
|
|
using Umbraco.Core.Configuration.Models;
|
2020-06-05 11:36:59 +02:00
|
|
|
|
using Umbraco.Core.Hosting;
|
2018-03-15 10:02:20 +01:00
|
|
|
|
using Umbraco.Core.IO;
|
2020-05-19 09:52:58 +02:00
|
|
|
|
using Umbraco.Web.Common.Attributes;
|
2018-03-15 10:02:20 +01:00
|
|
|
|
|
2020-06-03 17:17:30 +02:00
|
|
|
|
namespace Umbraco.Web.BackOffice.Controllers
|
2018-03-15 10:02:20 +01:00
|
|
|
|
{
|
2020-06-09 13:01:05 +10:00
|
|
|
|
[PluginController(Constants.Web.Mvc.BackOfficeApiArea)]
|
2018-03-15 10:02:20 +01:00
|
|
|
|
public class BackOfficeAssetsController : UmbracoAuthorizedJsonController
|
|
|
|
|
|
{
|
2019-11-19 07:52:40 +01:00
|
|
|
|
private readonly IFileSystem _jsLibFileSystem;
|
|
|
|
|
|
|
2020-09-18 12:53:06 +02:00
|
|
|
|
public BackOfficeAssetsController(IIOHelper ioHelper, IHostingEnvironment hostingEnvironment, ILoggerFactory loggerFactory, IOptions<GlobalSettings> globalSettings)
|
2019-11-19 07:52:40 +01:00
|
|
|
|
{
|
2020-09-18 12:53:06 +02:00
|
|
|
|
_jsLibFileSystem = new PhysicalFileSystem(ioHelper, hostingEnvironment, loggerFactory.CreateLogger<PhysicalFileSystem>(), globalSettings.Value.UmbracoPath + Path.DirectorySeparatorChar + "lib");
|
2019-11-19 07:52:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-15 10:02:20 +01:00
|
|
|
|
[HttpGet]
|
2019-01-23 22:56:00 +01:00
|
|
|
|
public object GetSupportedLocales()
|
2018-03-15 10:02:20 +01:00
|
|
|
|
{
|
2018-03-15 10:07:04 +01:00
|
|
|
|
const string momentLocaleFolder = "moment";
|
2019-01-23 22:56:00 +01:00
|
|
|
|
const string flatpickrLocaleFolder = "flatpickr/l10n";
|
|
|
|
|
|
|
|
|
|
|
|
return new
|
|
|
|
|
|
{
|
|
|
|
|
|
moment = GetLocales(momentLocaleFolder),
|
|
|
|
|
|
flatpickr = GetLocales(flatpickrLocaleFolder)
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private IEnumerable<string> GetLocales(string path)
|
|
|
|
|
|
{
|
|
|
|
|
|
var cultures = _jsLibFileSystem.GetFiles(path, "*.js").ToList();
|
2018-03-15 10:07:04 +01:00
|
|
|
|
for (var i = 0; i < cultures.Count; i++)
|
2018-03-15 10:02:20 +01:00
|
|
|
|
{
|
|
|
|
|
|
cultures[i] = cultures[i]
|
2019-01-23 22:56:00 +01:00
|
|
|
|
.Substring(cultures[i].IndexOf(path, StringComparison.Ordinal) + path.Length + 1);
|
2018-03-15 10:02:20 +01:00
|
|
|
|
}
|
|
|
|
|
|
return cultures;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|