|
|
|
@ -16,7 +16,8 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const SCAN_URL = '/video_metadata/admin.php?action=scan'; |
|
|
|
const SCAN_URL = 'admin.php?action=scan'; |
|
|
|
|
|
|
|
const VERIFY_URL = 'admin.php?action=verify'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function copyJSONtoDOMData(node, path_info) |
|
|
|
function copyJSONtoDOMData(node, path_info) |
|
|
|
@ -104,8 +105,11 @@ function buildDirectoryTreeWithData(path_info) |
|
|
|
if (path_info.depth > 0) { |
|
|
|
if (path_info.depth > 0) { |
|
|
|
sub_list.addEventListener('click', function(e) { |
|
|
|
sub_list.addEventListener('click', function(e) { |
|
|
|
e.stopPropagation(); |
|
|
|
e.stopPropagation(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (e.target.nodeName != 'INPUT') { |
|
|
|
for (let div of sub_list.querySelectorAll('div')) |
|
|
|
for (let div of sub_list.querySelectorAll('div')) |
|
|
|
div.classList.toggle('hidden'); |
|
|
|
div.classList.toggle('hidden'); |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -115,12 +119,71 @@ function buildDirectoryTreeWithData(path_info) |
|
|
|
return clone; |
|
|
|
return clone; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function createJSONFromDOM(node) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
let json = {}; |
|
|
|
|
|
|
|
json.base_name = node.dataset.baseName; |
|
|
|
|
|
|
|
json.content_size = node.dataset.contentSize; |
|
|
|
|
|
|
|
json.depth = node.dataset.depth; |
|
|
|
|
|
|
|
json.path_extension = node.dataset.fileExtension; |
|
|
|
|
|
|
|
json.full_path = node.dataset.fullPath; |
|
|
|
|
|
|
|
json.media_type = node.dataset.mediaType; |
|
|
|
|
|
|
|
json.path_type = node.dataset.pathType; |
|
|
|
|
|
|
|
json.contents = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return json; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function buildJSONFromNode(node) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
let json = createJSONFromDOM(node); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (json.media_type == "unknown" || json.media_type == "") { |
|
|
|
|
|
|
|
throw new Error('unknown media type, ' + json.base_name + ', at depth: ' + json.depth + '.\n'); |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (node.childNodes.length > 1) { |
|
|
|
|
|
|
|
for (let child of node.children) { |
|
|
|
|
|
|
|
if (child.nodeName == 'DIV') |
|
|
|
|
|
|
|
json.contents.push(buildJSONFromNode(child)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return json; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function onScanSubmit(e) |
|
|
|
function onScanSubmit(e) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// TODO: need to walk the dom tree and build a json object out of the data attributes
|
|
|
|
console.log('onScanSubmit'); |
|
|
|
// TODO: verify there are no 'unkown' media types, or fail with warning
|
|
|
|
|
|
|
|
// TODO: send json back to admin.php for tmdb_queries
|
|
|
|
let errors = document.querySelector('#errors'); |
|
|
|
|
|
|
|
let error_count = 0; |
|
|
|
|
|
|
|
div = document.querySelector('#main_container div'); |
|
|
|
|
|
|
|
let json = createJSONFromDOM(div); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (let node of div.children) { |
|
|
|
|
|
|
|
if (node.nodeName == 'DIV') { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
json.contents.push(buildJSONFromNode(node)); |
|
|
|
|
|
|
|
} catch(e) { |
|
|
|
console.log(e); |
|
|
|
console.log(e); |
|
|
|
|
|
|
|
errors.appendChild(document.createTextNode(e.message)); |
|
|
|
|
|
|
|
error_count++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (error_count == 0) { |
|
|
|
|
|
|
|
console.log('valid json, uploading'); |
|
|
|
|
|
|
|
fetchPOSTJSON(VERIFY_URL, json, function() { |
|
|
|
|
|
|
|
// ??
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
console.log('failed upload, errors in json'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(json); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function scanFolderResponse(data) |
|
|
|
function scanFolderResponse(data) |
|
|
|
@ -144,7 +207,6 @@ function scanFolderResponse(data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (data.path_info) { |
|
|
|
if (data.path_info) { |
|
|
|
//console.log(data.path_info);
|
|
|
|
|
|
|
|
let b = document.createElement('button'); |
|
|
|
let b = document.createElement('button'); |
|
|
|
b.textContent = 'Upload'; |
|
|
|
b.textContent = 'Upload'; |
|
|
|
b.addEventListener('click', onScanSubmit); |
|
|
|
b.addEventListener('click', onScanSubmit); |
|
|
|
@ -164,6 +226,7 @@ window.onload = function () { |
|
|
|
|
|
|
|
|
|
|
|
scan_button.addEventListener('click', function(e) { |
|
|
|
scan_button.addEventListener('click', function(e) { |
|
|
|
let info_container = document.querySelector('#info pre'); |
|
|
|
let info_container = document.querySelector('#info pre'); |
|
|
|
|
|
|
|
resetContainers(info_container); |
|
|
|
info_container.appendChild(document.createTextNode('waiting for response...')); |
|
|
|
info_container.appendChild(document.createTextNode('waiting for response...')); |
|
|
|
fetchJSON(SCAN_URL, scanFolderResponse); |
|
|
|
fetchJSON(SCAN_URL, scanFolderResponse); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|