forked from zotan/webmusic
Fix plain view, beautify m3u support
This commit is contained in:
parent
6b061eceef
commit
928dec02e4
|
@ -3,16 +3,31 @@
|
|||
@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
|
||||
{
|
||||
<h2>@Model.displaypath <span id="state"></span> <span id="flags"></span></h2>
|
||||
<a class="action-muted">[..]</a>
|
||||
<a href="?@Model.path_oneup" class="entry-muted cfont"> Go back</a><br/>
|
||||
<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)
|
||||
{
|
||||
<a class="action" href="#">[--]</a>
|
||||
|
@ -29,3 +44,4 @@
|
|||
<a href="#" onclick="playSong('@Html.Raw(jsfile)')"> @file</a>
|
||||
<br/>
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
@model IndexModel
|
||||
@{
|
||||
Layout = null;
|
||||
Response.ContentType = "text/plain";
|
||||
}
|
||||
@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