Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function() {
  2.     //getDirectoryContents('/var/www/html/jukebox/api');
  3.     //showBaseDirectories();
  4.  
  5.     login();
  6.    
  7. });
  8.  
  9. function login() {
  10.     $.ajax({
  11.         url: 'http://localhost/api/v1/login',
  12.         data: {username : "user", password: "pass"},
  13.         type: 'POST',
  14.         success: function(data) {
  15.             console.log(data);
  16.             //var json = $.parseJSON(data);
  17.             //console.log(json);
  18.             showBaseDirectories();
  19.         }
  20.     });
  21. }
  22.  
  23. function showBaseDirectories() {
  24.     $.ajax({
  25.         url: 'http://localhost/api/v1/fs',
  26.         data: {},
  27.         type: 'GET',
  28.         success: function(data) {
  29.             console.log(data);
  30.             //var json = $.parseJSON(data);
  31.             //console.log(json);
  32.             showDirContents(data);
  33.         }
  34.     });
  35. }
  36.  
  37. function getDirectoryContents(path) {
  38.     var mpath = {
  39.         path: path
  40.     };
  41.  
  42.     $.ajax({
  43.         url: 'http://localhost/api/v1/fs',
  44.         data: JSON.stringify(mpath),
  45.         dataType: "json",
  46.         contentType: 'application/json',
  47.         type: 'POST',
  48.         success: function(data) {
  49.             //var json = $.parseJSON(data);
  50.             console.log(JSON.stringify(data));
  51.             showDirContents(data);
  52.         }
  53.     });
  54. }
  55.  
  56. function showDirContents(data) {
  57.     $('#files').empty();
  58.     $.each(data, function(i, item) {
  59.         showSingleFile(item, i)
  60.     })
  61. }
  62.  
  63. function showSingleFile(file, i) {
  64.     var type = "song";
  65.     if (file.isDir) type = "directory"
  66.  
  67.     $('#files').append(
  68.         "<div id='file_"+i+"' class='file " + type +"'" + ">"
  69.         + unescape(file.file) + " : " + file.duration + "<br />"
  70.         + file.artist + " : " + file.song
  71.         + "</div>"
  72.     );
  73.  
  74.     $('#file_'+i).on( "click", function() {
  75.         console.log(file.file);
  76.         if (file.isDir)
  77.             getDirectoryContents(file.path);
  78.         else
  79.             processAudioFileClick(file.path);
  80.     });
  81. }
  82.  
  83. function processAudioFileClick(path) {
  84.     var mpath = {
  85.         path: path
  86.     };
  87.     $.ajax({
  88.         url: 'http://localhost:8008/api/v1/playlist/save',
  89.         data: JSON.stringify(mpath),
  90.         dataType: "json",
  91.         contentType: 'application/json',
  92.         type: 'POST',
  93.         success: function(data) {
  94.             var json = $.parseJSON(data);
  95.             alert(json.message);
  96.         }
  97.     });
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement