forked from SoDOff-Project/sodoff
add UseAnyURLPrefix setting
This commit is contained in:
parent
9d89a6b6da
commit
9e934c3925
@ -4,6 +4,7 @@ public class AssetServerConfig {
|
|||||||
public string ListenIP { get; set; } = string.Empty;
|
public string ListenIP { get; set; } = string.Empty;
|
||||||
public int Port { get; set; } = 5001;
|
public int Port { get; set; } = 5001;
|
||||||
public string URLPrefix { get; set; } = string.Empty;
|
public string URLPrefix { get; set; } = string.Empty;
|
||||||
|
public bool UseAnyURLPrefix { get; set; } = true;
|
||||||
public AssetServerMode Mode { get; set; }
|
public AssetServerMode Mode { get; set; }
|
||||||
public string ProviderURL { get; set; } = string.Empty;
|
public string ProviderURL { get; set; } = string.Empty;
|
||||||
public string AutoEncryptRegexp { get; set; } = string.Empty;
|
public string AutoEncryptRegexp { get; set; } = string.Empty;
|
||||||
|
@ -34,12 +34,27 @@ public class AssetMiddleware
|
|||||||
{
|
{
|
||||||
string path = context.Request.Path;
|
string path = context.Request.Path;
|
||||||
|
|
||||||
if (path is null || !string.IsNullOrEmpty(config.Value.URLPrefix) && !path.StartsWith("/" + config.Value.URLPrefix) || config.Value.Mode == AssetServerMode.None) {
|
if (path is null || config.Value.Mode == AssetServerMode.None) {
|
||||||
context.Response.StatusCode = 400;
|
context.Response.StatusCode = 400;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string assetPath = path.Remove(0, config.Value.URLPrefix.Length + 1);
|
string assetPath;
|
||||||
|
if (config.Value.UseAnyURLPrefix) {
|
||||||
|
int firstSlash = path.IndexOf('/', 1);
|
||||||
|
if (firstSlash < 0) {
|
||||||
|
context.Response.StatusCode = 400;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
assetPath = path.Remove(0, firstSlash + 1);
|
||||||
|
} else {
|
||||||
|
if (!string.IsNullOrEmpty(config.Value.URLPrefix) && !path.StartsWith("/" + config.Value.URLPrefix)) {
|
||||||
|
context.Response.StatusCode = 400;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
assetPath = path.Remove(0, config.Value.URLPrefix.Length + 1);
|
||||||
|
}
|
||||||
|
|
||||||
string localPath = GetLocalPath("assets/" + assetPath);
|
string localPath = GetLocalPath("assets/" + assetPath);
|
||||||
|
|
||||||
if (localPath == string.Empty && config.Value.Mode == AssetServerMode.Partial && config.Value.UseCache)
|
if (localPath == string.Empty && config.Value.Mode == AssetServerMode.Partial && config.Value.UseCache)
|
||||||
|
@ -17,9 +17,15 @@
|
|||||||
"// Port": "Listening port number for the asset server. Should be different than for the server API",
|
"// Port": "Listening port number for the asset server. Should be different than for the server API",
|
||||||
"Port": 5001,
|
"Port": 5001,
|
||||||
|
|
||||||
"// URLPrefix": "Extra prefix in the URL; omitted while retrieving the path from the requested URL. For example, if set to '.com', then a request to http://localhost/.com/abc will return the 'abc' file from the assets folder",
|
"// URLPrefix (1)": "Extra prefix in the URL; omitted while retrieving the path from the requested URL. See also: UseAnyURLPrefix setting.",
|
||||||
|
"// URLPrefix (2)": "For example, if set to '.com', then a request to 'http://localhost/.com/abc' will return the 'abc' file from the assets folder.",
|
||||||
"URLPrefix": ".com",
|
"URLPrefix": ".com",
|
||||||
|
|
||||||
|
"// UseAnyURLPrefix (1)": "Extended version of URLPrefix (if set to true, then URLPrefix setting will be ignored).",
|
||||||
|
"// UseAnyURLPrefix (2)": "When true requires that requested URL contained extra prefix (one directory at path start), that will be omitted while retrieving the path from the requested URL.",
|
||||||
|
"// UseAnyURLPrefix (3)": "If set to true, then (for example) a request to 'http://localhost/any.com/abc' will return the 'abc' file from the assets folder ('any.com' will be omitted).",
|
||||||
|
"UseAnyURLPrefix": true,
|
||||||
|
|
||||||
"// Mode": "Two modes: full - everything is local, partial - downloads assets from ProviderURL if not found locally",
|
"// Mode": "Two modes: full - everything is local, partial - downloads assets from ProviderURL if not found locally",
|
||||||
"Mode": "partial",
|
"Mode": "partial",
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user