diff --git a/Pages/Index.cshtml b/Pages/Index.cshtml
index fafb3e5..c060f16 100644
--- a/Pages/Index.cshtml
+++ b/Pages/Index.cshtml
@@ -3,29 +3,45 @@
@model IndexModel
@{
ViewData["Title"] = "webmusic";
+ var path = HttpUtility.UrlDecode(Request.QueryString.Value.TrimStart('?'));
+ if (path.EndsWith(".m3u"))
+ {
+ Layout = null;
+ Response.ContentType = "text/plain";
+ }
}
@if (Model.path.Contains(".."))
{
return;
}
+@if (path.EndsWith(".m3u"))
+{
+ @foreach (var file in Model.files)
+ {
+ @Html.Raw(Request.Scheme + "://" + Request.Host + "/" + Model.fullpath + "/" + file+"\n")
+ }
+}
+else
+{
@Model.displaypath
[..]
Go back
[--]
- Download m3u
-@foreach (var dir in Model.dirs)
-{
- [--]
- @dir
-
-}
-@foreach (var file in Model.files)
-{
- var jspath = Model.Encode(Model.fullpath);
- var jsfile = jspath + "/" + Model.Encode(file);
-
-
- [DL]
- @file
-
+ Download m3u
+ @foreach (var dir in Model.dirs)
+ {
+ [--]
+ @dir
+
+ }
+ @foreach (var file in Model.files)
+ {
+ var jspath = Model.Encode(Model.fullpath);
+ var jsfile = jspath + "/" + Model.Encode(file);
+
+
+ [DL]
+ @file
+
+ }
}
\ No newline at end of file
diff --git a/Pages/Index.cshtml.cs b/Pages/Index.cshtml.cs
index 1fbc2e4..e52d400 100644
--- a/Pages/Index.cshtml.cs
+++ b/Pages/Index.cshtml.cs
@@ -22,6 +22,8 @@ namespace webmusic.Pages
{
if (Request.QueryString.HasValue)
path = HttpUtility.UrlDecode(Request.QueryString.Value.Remove(0,1));
+ if (path.EndsWith(".m3u"))
+ path = path.Substring(0, path.Length - 4);
if (path.Contains(".."))
{
Response.Redirect("/Error");
diff --git a/Pages/plain.cshtml b/Pages/plain.cshtml
index 1eb63a6..0e75614 100644
--- a/Pages/plain.cshtml
+++ b/Pages/plain.cshtml
@@ -3,6 +3,7 @@
@model IndexModel
@{
Layout = null;
+ Response.ContentType = "text/plain";
}
@if (Model.path.Contains(".."))
{
diff --git a/Pages/plain.cshtml.cs b/Pages/plain.cshtml.cs
deleted file mode 100644
index 01589af..0000000
--- a/Pages/plain.cshtml.cs
+++ /dev/null
@@ -1,61 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text.RegularExpressions;
-using System.Web;
-using Microsoft.AspNetCore.Mvc.RazorPages;
-
-
-namespace webmusic.Pages
-{
- public class PlainModel : PageModel
- {
- public static string root = "music";
- public string path = "";
- public string displaypath = "";
- public string path_oneup = "";
- public string fullpath = "";
- public List dirs = new List();
- public List files = new List();
- public void OnGet()
- {
- if (Request.QueryString.HasValue)
- path = HttpUtility.UrlDecode(Request.QueryString.Value.Remove(0,1));
- if (path.Contains(".."))
- {
- Response.Redirect("/Error");
- return;
- }
- path_oneup = Regex.Match(path, @".*(?=\/)").Value;
- fullpath = root + path;
- displaypath = string.IsNullOrWhiteSpace(path) ? "/" : path;
- dirs = Directory.GetDirectories(fullpath).Select(Path.GetFileName).ToList();
- dirs.Sort();
- files = Directory.GetFiles(fullpath).Select(Path.GetFileName).ToList();
- files.RemoveAll(p => p.EndsWith(".m3u"));
- files.Sort(new NumericComparer());
- }
-
- public class NumericComparer : IComparer
- {
- public int Compare(string x, string y)
- {
- var regex = new Regex(@"^\d+");
-
- // run the regex on both strings
- var xRegexResult = regex.Match(x);
- var yRegexResult = regex.Match(y);
-
- // check if they are both numbers
- if (xRegexResult.Success && yRegexResult.Success)
- {
- return int.Parse(xRegexResult.Value).CompareTo(int.Parse(yRegexResult.Value));
- }
-
- // otherwise return as string comparison
- return string.Compare(x, y, StringComparison.Ordinal);
- }
- }
- }
-}
\ No newline at end of file