/* * This file is part of video_metadata. * * video_metadata is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * video_metadata is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with video_metadata. If not, see . */ const SCAN_URL = '/video_metadata/admin.php?action=scan'; function displayPathInfo(path_info) { const DEPTH_NAMES = ['depth_0', 'depth_1', 'depth_2', 'depth_3', 'depth_4', 'depth_5']; let frag = document.createDocumentFragment(); let line_item = document.createElement('li'); let sub_list = document.createElement('ul'); frag.appendChild(line_item.appendChild(sub_list)); if (path_info.path_type == 'directory') { sub_list.classList.add('directory'); } else if (path_info.path_type == 'file') { sub_list.classList.add('file'); sub_list.classList.add(((path_info.media_type == '') ? 'none' : path_info.media_type)); } if (path_info.media_type == 'unknown') sub_list.classList.add('unknown'); sub_list.classList.add(DEPTH_NAMES[path_info.depth]); let bn = document.createElement('li'); bn.textContent = 'base_name: ' + path_info.base_name; sub_list.appendChild(bn); let mt = document.createElement('li'); mt.textContent = 'media_type: ' + ((path_info.media_type == '') ? 'none' : path_info.media_type); sub_list.appendChild(mt); for (let node of path_info.contents) sub_list.appendChild(displayPathInfo(node)); return frag; } function scanFolderResponse(data) { let error_container = document.querySelector('#error_container'); let info_container = document.querySelector('#info pre'); let main_container = document.querySelector('#main_container ul'); resetContainers(error_container, info_container, main_container); if (data.errors) { for (let err of data.errors) { error_container.appendChild(document.createTextNode(err)); console.log(err); } } if (data.mem_usage) { info_container.appendChild(document.createTextNode( 'memory usage: ' + data.mem_usage + ' bytes') ); } if (data.path_info) { console.log(data.path_info); main_container.appendChild(displayPathInfo(data.path_info)); } } window.onload = function () { if (!('fetch' in window)) { console.log('no fetch API'); return; } let scan_button = document.querySelector('#scan_button'); scan_button.addEventListener('click', function(e) { fetchJSON(SCAN_URL, scanFolderResponse); }); }