|
|
|
@@ -114,8 +114,9 @@ public class SimApiStorage
|
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
|
public string FullUrl(string path)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(path)) return path;
|
|
|
|
|
if(path.StartsWith("http://") || path.StartsWith("https://")) return path;
|
|
|
|
|
if (!(path.StartsWith('/') || path.StartsWith("~/"))) throw new Exception("path must start with / or ~/");
|
|
|
|
|
if (!(path.StartsWith('/') || path.StartsWith("~/"))) return path;
|
|
|
|
|
var httpRequest = HttpContextAccessor.HttpContext?.Request;
|
|
|
|
|
var url = $"{httpRequest?.Scheme}://{httpRequest?.Host}";
|
|
|
|
|
if (string.IsNullOrEmpty(path))
|
|
|
|
@@ -126,6 +127,27 @@ public class SimApiStorage
|
|
|
|
|
return path.StartsWith('~') ? string.Concat(url, path.AsSpan(1, path.Length - 1)) : $"{ServeUrl}{path}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取一个Path得访问URL
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="path"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public string? GetUrl(string? path)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(path)) return path;
|
|
|
|
|
if (path.StartsWith("~/"))
|
|
|
|
|
{
|
|
|
|
|
var httpRequest = HttpContextAccessor.HttpContext?.Request;
|
|
|
|
|
var url = $"{httpRequest?.Scheme}://{httpRequest?.Host}";
|
|
|
|
|
return string.Concat(url, path.AsSpan(1, path.Length - 1));
|
|
|
|
|
}
|
|
|
|
|
if (path.StartsWith('/'))
|
|
|
|
|
{
|
|
|
|
|
return $"{ServeUrl}{path}";
|
|
|
|
|
}
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 从URL中获取相对路径 (如果url不是当前服务器的url,则原样返回)
|
|
|
|
|
/// </summary>
|
|
|
|
@@ -133,7 +155,7 @@ public class SimApiStorage
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public string? GetPath(string? url)
|
|
|
|
|
{
|
|
|
|
|
return url?.Replace($"{Endpoint}/{Bucket}", string.Empty);
|
|
|
|
|
return url?.Replace($"{Endpoint}/{Bucket}", string.Empty).Replace(ServeUrl,string.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckPath(string path)
|
|
|
|
|