Skip to content

Commit

Permalink
follow up spec
Browse files Browse the repository at this point in the history
  • Loading branch information
BLumia committed Feb 10, 2017
1 parent 2f74951 commit f15ce89
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DOCUMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 7 additions & 6 deletions api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion player.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function formatTime(t) {
}
typeof callback === 'function' && callback();
}
xhr.send("do=getplaylist&folder=");
xhr.send("do=getplaylist");
},

fetchData: function() {
Expand Down

0 comments on commit f15ce89

Please sign in to comment.