我需要将jPlayer目录设置为一个名为“/ Default / MediaGallery”而不是“/ MyFolder / CurrentMedia /”的文件夹。
请,任何人都可以帮我找到一种方法来更改jPlayer中的设置 - 版本:1.0.1
此致
答案 0 :(得分:2)
看起来像名称is hardcoded。没有办法摆脱路径的“/ Default”部分,因为jPlayer模块正在使用Orchard Media功能,该功能具有以每个租户命名的默认根文件夹(它是一个多租户友好的模块)。 您可以通过更改上面链接的文件的第12行中的名称( MediaGalleries )来仅更改该路径的以下部分。
答案 1 :(得分:1)
Name
中的字段Orchard.Web\App_Data\Sites\Default\Settings.txt
,路径在Orchard\FileSystems\Media\FileSystemStorageProvider.cs
中进行了硬编码。遗憾的是,没有办法用处理程序或其他东西来改变这个类的行为。现在有2个选项
IStorageProvider
的自定义实现,并在需要时(意味着媒体存储路径在Orchard目录结构之外),另外一个MVC控制器用于提供媒体文件。我使用第二个选项将媒体存储路径更改为\\<server>\Files$\<build_configuration>\Media
。
首先,这是IStorageProvider
的基本部分:
自定义IStorageProvider
实施
[Orchard.Environment.Extensions.OrchardSuppressDependency("Orchard.FileSystems.Media.FileSystemStorageProvider")] // adopted from AzureBlobStorageProvider.cs
public class FileSystemStorageProvider : Orchard.FileSystems.Media.IStorageProvider
{
private Orchard.FileSystems.Media.FileSystemStorageProvider mFileSystemStorageProvider;
public FileSystemStorageProvider(Orchard.Environment.Configuration.ShellSettings settings)
{
// use Orchard's default IStorageProvider for implementation
mFileSystemStorageProvider = new Orchard.FileSystems.Media.FileSystemStorageProvider(settings);
var lFileSystemStorageProviderType = mFileSystemStorageProvider.GetType();
// get media storage path, e.g. from configuration file
var lStoragePath = GetMediaStoragePath();
lStoragePath = System.IO.Path.Combine(lStoragePath, settings.Name);
// _storagePath is private read-only, so change it the hard way by using reflection
lFileSystemStorageProviderType
.GetField("_storagePath", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
.SetValue(mFileSystemStorageProvider, lStoragePath);
string lVirtualPath = "~/Files/" + settings.Name + "/";
lFileSystemStorageProviderType
.GetField("_virtualPath", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
.SetValue(mFileSystemStorageProvider, lVirtualPath);
string lPublicPath = mFileSystemStorageProvider.GetPublicUrl(null).Replace("/Media/" + settings.Name + "/", "/Files/" + settings.Name + "/");
lFileSystemStorageProviderType
.GetField("_publicPath", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
.SetValue(mFileSystemStorageProvider, lPublicPath);
}
#region Implementation of IStorageProvider
public bool FileExists(string aPath)
{
return mFileSystemStorageProvider.FileExists(aPath);
}
...
#endregion
}
此自定义实现映射
\\<server>\Files$\<build_configuration>\Media
的存储路径~/Files/Default/
/Files/Default/
的绝对路径现在有问题。 Orchard会将媒体URL呈现为www.mysite.de/Files/Default...
,但Orchard目录结构中没有名为Files的目录。现在,自定义路线发挥作用。
自定义路线
public class Routes : Orchard.Mvc.Routes.IRouteProvider
{
public System.Collections.Generic.IEnumerable<Orchard.Mvc.Routes.RouteDescriptor> GetRoutes()
{
Orchard.Mvc.Routes.RouteDescriptor[] lRoutes =
new Orchard.Mvc.Routes.RouteDescriptor[]
{
new Orchard.Mvc.Routes.RouteDescriptor()
{
Name = "Custom route for media files",
Priority = 10000,
Route = new System.Web.Routing.Route(
"Files/{*aRelativePath}",
new System.Web.Routing.RouteValueDictionary()
{
{"area", "MyModule"},
{"controller", "Media"},
{"action", "GetFile"}
},
new System.Web.Routing.RouteValueDictionary() {},
new System.Web.Routing.RouteValueDictionary() { {"area", "MyModule"} },
new System.Web.Mvc.MvcRouteHandler()
)
}
};
return lRoutes;
}
public void GetRoutes(System.Collections.Generic.ICollection<Orchard.Mvc.Routes.RouteDescriptor> arRoutes)
{
foreach (var lRouteDescriptor in GetRoutes())
arRoutes.Add(lRouteDescriptor);
}
}
此路由实现可确保将www.mysite.de/Files/Default...
重定向到特定的媒体控制器,如下所示:
媒体控制器
public class MediaController
{
public MediaController(Orchard.FileSystems.Media.IMimeTypeProvider aMimeTypeProvider)
{
mMimeTypeProvider = aMimeTypeProvider;
}
public System.Web.Mvc.ActionResult GetFile(string aRelativePath)
{
string lMediaStoragePath, lErrorMessage;
// get media storage path, e.g. from configuration file
if (GetMediaStoragePath(out lMediaStoragePath, out lErrorMessage))
{
string lFilename = System.IO.Path.Combine(lMediaStoragePath, aRelativePath);
string lMimeType = mMimeTypeProvider.GetMimeType(lFilename);
return File(lFilename, lMimeType);
}
else
return Content(lErrorMessage);
}
// private
private Orchard.FileSystems.Media.IMimeTypeProvider mMimeTypeProvider;
}