From f15ce89d78f374f2349f4980b63ce0362abd78d5 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Fri, 10 Feb 2017 22:42:51 +0800 Subject: [PATCH] follow up spec --- DOCUMENT.md | 2 +- api.php | 13 +++++++------ player.js | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/DOCUMENT.md b/DOCUMENT.md index 95aba69..9e4c750 100644 --- a/DOCUMENT.md +++ b/DOCUMENT.md @@ -16,7 +16,7 @@ * POST: + 'do' = "getplaylist" - + 'folder' = folder name + + 'folder' = folder name (optional, default value = "") * RETURN: json with the following struct. (if folder exist) diff --git a/api.php b/api.php index 3e192ff..731470e 100644 --- a/api.php +++ b/api.php @@ -43,23 +43,24 @@ function fire($status, $message, $result = null) { switch($command) { case "getplaylist": - if(!isset($_POST['folder'])) fire(400, "Illegal request!"); + $requestFolderStr = ""; + if(isset($_POST['folder'])) $requestFolderStr = $_POST['folder']; $actualSongFolder = null; - if(is_dir($songFolderPath."/".urldecode($_POST['folder']))) { - $actualSongFolder = $songFolderPath."/".urldecode($_POST['folder']); + if(is_dir($songFolderPath."/".urldecode($requestFolderStr))) { + $actualSongFolder = $songFolderPath."/".urldecode($requestFolderStr); } else { // Solve problem if using weird charset. // This will cause problem if given path is not a single folder. // eg. "Folder/Subfolder/". $folderList = scandir($songFolderPath); foreach($folderList as $oneFolderName) { - if (GIVEMETHEFUCKINGUTF8($oneFolderName)."/"==urldecode($_POST['folder'])) { + if (GIVEMETHEFUCKINGUTF8($oneFolderName)."/"==urldecode($requestFolderStr)) { $actualSongFolder="{$songFolderPath}/{$oneFolderName}"; break; } } } - if($actualSongFolder == null) fire(404, "Folder \"{$_POST['folder']}\" not exist!"); + if($actualSongFolder == null) fire(404, "Folder \"{$requestFolderStr}\" not exist!"); $fileList = scandir($actualSongFolder); $musicList = array(); $subFolderList = array(); @@ -68,7 +69,7 @@ function fire($status, $message, $result = null) { $utf8FileName = GIVEMETHEFUCKINGUTF8($oneFileName); $curFilePath = "{$actualSongFolder}/{$oneFileName}"; if (is_dir($curFilePath)) { - array_push($subFolderList, $_POST['folder'].rawurlencode($utf8FileName)); + array_push($subFolderList, $requestFolderStr.rawurlencode($utf8FileName)); continue; } if (in_array(getFileExtension($utf8FileName),$allowedExts)) { diff --git a/player.js b/player.js index 5915fb3..5e9b9cd 100644 --- a/player.js +++ b/player.js @@ -105,7 +105,7 @@ function formatTime(t) { } typeof callback === 'function' && callback(); } - xhr.send("do=getplaylist&folder="); + xhr.send("do=getplaylist"); }, fetchData: function() {