Fix plain view, beautify m3u support
This commit is contained in:
parent
6b061eceef
commit
928dec02e4
|
@ -3,29 +3,45 @@
|
||||||
@model IndexModel
|
@model IndexModel
|
||||||
@{
|
@{
|
||||||
ViewData["Title"] = "webmusic";
|
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(".."))
|
@if (Model.path.Contains(".."))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@if (path.EndsWith(".m3u"))
|
||||||
|
{
|
||||||
|
@foreach (var file in Model.files)
|
||||||
|
{
|
||||||
|
@Html.Raw(Request.Scheme + "://" + Request.Host + "/" + Model.fullpath + "/" + file+"\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
<h2>@Model.displaypath <span id="state"></span> <span id="flags"></span></h2>
|
<h2>@Model.displaypath <span id="state"></span> <span id="flags"></span></h2>
|
||||||
<a class="action-muted">[..]</a>
|
<a class="action-muted">[..]</a>
|
||||||
<a href="?@Model.path_oneup" class="entry-muted cfont"> Go back</a><br/>
|
<a href="?@Model.path_oneup" class="entry-muted cfont"> Go back</a><br/>
|
||||||
<a class="action-muted">[--]</a>
|
<a class="action-muted">[--]</a>
|
||||||
<a href="#" onclick="downloadm3u()" class="entry-muted cfont"> Download m3u</a><br/><br/>
|
<a href="/?@(Request.Query.FirstOrDefault().Key).m3u" class="entry-muted cfont"> Download m3u</a><br/><br/>
|
||||||
@foreach (var dir in Model.dirs)
|
@foreach (var dir in Model.dirs)
|
||||||
{
|
{
|
||||||
<a class="action" href="#">[--]</a>
|
<a class="action" href="#">[--]</a>
|
||||||
<a href="?@Model.path/@dir"> @dir</a>
|
<a href="?@Model.path/@dir"> @dir</a>
|
||||||
<br/>
|
<br/>
|
||||||
}
|
}
|
||||||
@foreach (var file in Model.files)
|
@foreach (var file in Model.files)
|
||||||
{
|
{
|
||||||
var jspath = Model.Encode(Model.fullpath);
|
var jspath = Model.Encode(Model.fullpath);
|
||||||
var jsfile = jspath + "/" + Model.Encode(file);
|
var jsfile = jspath + "/" + Model.Encode(file);
|
||||||
|
|
||||||
<script>queue.push('@Html.Raw(jsfile)')</script>
|
<script>queue.push('@Html.Raw(jsfile)')</script>
|
||||||
<a class="action" href="@Html.Raw(Model.Encode(Model.fullpath+"/"+file))" download>[DL]</a>
|
<a class="action" href="@Html.Raw(Model.Encode(Model.fullpath+"/"+file))" download>[DL]</a>
|
||||||
<a href="#" onclick="playSong('@Html.Raw(jsfile)')"> @file</a>
|
<a href="#" onclick="playSong('@Html.Raw(jsfile)')"> @file</a>
|
||||||
<br/>
|
<br/>
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -22,6 +22,8 @@ namespace webmusic.Pages
|
||||||
{
|
{
|
||||||
if (Request.QueryString.HasValue)
|
if (Request.QueryString.HasValue)
|
||||||
path = HttpUtility.UrlDecode(Request.QueryString.Value.Remove(0,1));
|
path = HttpUtility.UrlDecode(Request.QueryString.Value.Remove(0,1));
|
||||||
|
if (path.EndsWith(".m3u"))
|
||||||
|
path = path.Substring(0, path.Length - 4);
|
||||||
if (path.Contains(".."))
|
if (path.Contains(".."))
|
||||||
{
|
{
|
||||||
Response.Redirect("/Error");
|
Response.Redirect("/Error");
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
@model IndexModel
|
@model IndexModel
|
||||||
@{
|
@{
|
||||||
Layout = null;
|
Layout = null;
|
||||||
|
Response.ContentType = "text/plain";
|
||||||
}
|
}
|
||||||
@if (Model.path.Contains(".."))
|
@if (Model.path.Contains(".."))
|
||||||
{
|
{
|
||||||
|
|
|
@ -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<string> dirs = new List<string>();
|
|
||||||
public List<string> files = new List<string>();
|
|
||||||
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<string>
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue