|
@@ -323,49 +323,47 @@ namespace FNZCM.ConHost
|
|
|
private static void ProcessRequest(HttpListenerContext context)
|
|
|
{
|
|
|
_lastRequestAccepted = DateTime.Now;
|
|
|
-
|
|
|
- var request = context.Request;
|
|
|
-
|
|
|
- var requestAbsPrefix = ConfigFile.Instance.M3uPrefix ?? $"{request.Url.Scheme + Uri.SchemeDelimiter + request.Url.Host + ":" + request.Url.Port}";
|
|
|
-
|
|
|
var num = Interlocked.Increment(ref _requestId);
|
|
|
+ var request = context.Request;
|
|
|
Console.WriteLine($"Request #{num:00000} from {request.RemoteEndPoint} {request.HttpMethod} {request.RawUrl}");
|
|
|
|
|
|
- if (false == string.IsNullOrEmpty(request.Headers["Origin"]))
|
|
|
+ try
|
|
|
{
|
|
|
- if (ConfigFile.Instance.AccessControlAllowOrigin?.Any(p => request.Headers["Origin"].StartsWith(p)) == true)
|
|
|
- context.Response.Headers["Access-Control-Allow-Origin"] = "*";
|
|
|
- }
|
|
|
+ var requestAbsPrefix = ConfigFile.Instance.M3uPrefix ?? $"{request.Url.Scheme + Uri.SchemeDelimiter + request.Url.Host + ":" + request.Url.Port}";
|
|
|
|
|
|
- // GET / show all libraries
|
|
|
+ if (request.Headers.AllKeys.Contains("Origin") && false == string.IsNullOrEmpty(request.Headers["Origin"]))
|
|
|
+ {
|
|
|
+ if (ConfigFile.Instance.AccessControlAllowOrigin?.Any(p => request.Headers["Origin"].StartsWith(p)) == true)
|
|
|
+ context.Response.Headers["Access-Control-Allow-Origin"] = "*";
|
|
|
+ }
|
|
|
|
|
|
- // foo=library bar=disc
|
|
|
- // GET /list/foo/ show all disc and cover with name, provide m3u path
|
|
|
- // GET /list/foo/bar/bk/ list all picture as grid
|
|
|
- // GET /list/foo/bar/tracks/ list all tracks as text list
|
|
|
+ // GET / show all libraries
|
|
|
|
|
|
- // GET /lib_list/foo/playlist.m3u8 auto gen
|
|
|
- // GET /lib_list/foo/aac_q1.00/playlist.m3u8 auto gen
|
|
|
+ // foo=library bar=disc
|
|
|
+ // GET /list/foo/ show all disc and cover with name, provide m3u path
|
|
|
+ // GET /list/foo/bar/bk/ list all picture as grid
|
|
|
+ // GET /list/foo/bar/tracks/ list all tracks as text list
|
|
|
|
|
|
- // GET /list/foo/bar/playlist.m3u8 auto gen
|
|
|
- // GET /list/foo/bar/aac_q1.00/playlist.m3u8 auto gen
|
|
|
+ // GET /lib_list/foo/playlist.m3u8 auto gen
|
|
|
+ // GET /lib_list/foo/aac_q1.00/playlist.m3u8 auto gen
|
|
|
|
|
|
- // media streaming HTTP Partial RANGE SUPPORT
|
|
|
- // GET /cover/foo/bar/cover.jpg image/<ext>
|
|
|
- // GET /media/foo/bar/01.%20foobar.flac audio/<ext>
|
|
|
- // GET /media/foo/bar/aac_q1.00/01.%20foobar.m4a audio/<ext>
|
|
|
- // GET /bk/foo/bar/foobar.jpg image/<ext>
|
|
|
+ // GET /list/foo/bar/playlist.m3u8 auto gen
|
|
|
+ // GET /list/foo/bar/aac_q1.00/playlist.m3u8 auto gen
|
|
|
|
|
|
- // metadata catalog
|
|
|
- // GET /metadata/progress.json
|
|
|
- // GET /metadata/file-set.json
|
|
|
- // GET /metadata/tag-dict.json
|
|
|
+ // media streaming HTTP Partial RANGE SUPPORT
|
|
|
+ // GET /cover/foo/bar/cover.jpg image/<ext>
|
|
|
+ // GET /media/foo/bar/01.%20foobar.flac audio/<ext>
|
|
|
+ // GET /media/foo/bar/aac_q1.00/01.%20foobar.m4a audio/<ext>
|
|
|
+ // GET /bk/foo/bar/foobar.jpg image/<ext>
|
|
|
|
|
|
- // loadable module
|
|
|
- // GET /module/<module-key>/<in-module-path>/
|
|
|
+ // metadata catalog
|
|
|
+ // GET /metadata/progress.json
|
|
|
+ // GET /metadata/file-set.json
|
|
|
+ // GET /metadata/tag-dict.json
|
|
|
+
|
|
|
+ // loadable module
|
|
|
+ // GET /module/<module-key>/<in-module-path>/
|
|
|
|
|
|
- try
|
|
|
- {
|
|
|
// ReSharper disable once PossibleNullReferenceException
|
|
|
var requestPath = request.Url.LocalPath.ToLower();
|
|
|
var pathParts = (IReadOnlyList<string>)requestPath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
|
|
@@ -427,7 +425,8 @@ namespace FNZCM.ConHost
|
|
|
var html = Encoding.UTF8.GetString(bin);
|
|
|
var r = html.Replace(module.HtmlBaseReplace, $"<base href=\"/modules/{moduleKey}/\" />");
|
|
|
bin = Encoding.UTF8.GetBytes(r);
|
|
|
- }else context.Response.ContentType = "application/octet-stream";
|
|
|
+ }
|
|
|
+ else context.Response.ContentType = "application/octet-stream";
|
|
|
|
|
|
context.Response.ContentLength64 = bin.Length;
|
|
|
context.Response.OutputStream.Write(bin, 0, bin.Length);
|
|
@@ -873,7 +872,6 @@ namespace FNZCM.ConHost
|
|
|
var sb = new StringBuilder();
|
|
|
sb.WriteM3U8Header();
|
|
|
|
|
|
-
|
|
|
foreach (var discKvp in lib.Discs.OrderByDescending(p => p.Key))
|
|
|
{
|
|
|
var disc = discKvp.Value;
|
|
@@ -1127,7 +1125,6 @@ namespace FNZCM.ConHost
|
|
|
context.WriteTextUtf8(_tagSetJson ?? "null", Const.ApplicationJson);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
else if (PathMapping.TryGetValue(requestPath, out var realPath))
|
|
|
{
|
|
|
var ext = requestPath.Split('.').LastOrDefault()?.ToLower();
|