Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function() {
- //getDirectoryContents('/var/www/html/jukebox/api');
- //showBaseDirectories();
- login();
- });
- function login() {
- $.ajax({
- url: 'http://localhost/api/v1/login',
- data: {username : "user", password: "pass"},
- type: 'POST',
- success: function(data) {
- console.log(data);
- //var json = $.parseJSON(data);
- //console.log(json);
- showBaseDirectories();
- }
- });
- }
- function showBaseDirectories() {
- $.ajax({
- url: 'http://localhost/api/v1/fs',
- data: {},
- type: 'GET',
- success: function(data) {
- console.log(data);
- //var json = $.parseJSON(data);
- //console.log(json);
- showDirContents(data);
- }
- });
- }
- function getDirectoryContents(path) {
- var mpath = {
- path: path
- };
- $.ajax({
- url: 'http://localhost/api/v1/fs',
- data: JSON.stringify(mpath),
- dataType: "json",
- contentType: 'application/json',
- type: 'POST',
- success: function(data) {
- //var json = $.parseJSON(data);
- console.log(JSON.stringify(data));
- showDirContents(data);
- }
- });
- }
- function showDirContents(data) {
- $('#files').empty();
- $.each(data, function(i, item) {
- showSingleFile(item, i)
- })
- }
- function showSingleFile(file, i) {
- var type = "song";
- if (file.isDir) type = "directory"
- $('#files').append(
- "<div id='file_"+i+"' class='file " + type +"'" + ">"
- + unescape(file.file) + " : " + file.duration + "<br />"
- + file.artist + " : " + file.song
- + "</div>"
- );
- $('#file_'+i).on( "click", function() {
- console.log(file.file);
- if (file.isDir)
- getDirectoryContents(file.path);
- else
- processAudioFileClick(file.path);
- });
- }
- function processAudioFileClick(path) {
- var mpath = {
- path: path
- };
- $.ajax({
- url: 'http://localhost:8008/api/v1/playlist/save',
- data: JSON.stringify(mpath),
- dataType: "json",
- contentType: 'application/json',
- type: 'POST',
- success: function(data) {
- var json = $.parseJSON(data);
- alert(json.message);
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement