diff --git a/admin.php b/admin.php index b856268..d8b1eb3 100644 --- a/admin.php +++ b/admin.php @@ -21,7 +21,8 @@ declare(strict_types=1); require_once('include/getJsonErrorString.php'); -const FOLDER_PATH = '../video/unwatched'; +//const FOLDER_PATH = '../video/unwatched'; +const FOLDER_PATH = '../video/tv.shows/Archer'; const MAX_RECURSE_DEPTH = 5; $g_errors = []; @@ -147,6 +148,29 @@ function getUnsavedMetadata() : void } } +function verifyChanges() : void +{ + header('Content-Type: text/json'); + $input = file_get_contents('php://input'); + + if ($input) { + $json = json_decode($input); + + if ($json) { + // TODO: recursively check that each path entry maps to a file on disk + // and has a valid media type set + // TODO: sanitize file names for TMDB queries + // TODO: make queries to TMDB for sanitized titles + // NOTE: this will be much easier for movies because TV shows will require + // additional queries for seasons and episodes + echo '{"errors": null, "message": "successfully decoded"}'; + } else { + echo '{"errors":"' . __FUNCTION__ . ', error decoding json: ' + . getJsonErrorString(json_last_error()) . '"}'; + } + } +} + function main() : void { switch (@$_GET['action']) { @@ -156,6 +180,9 @@ function main() : void case 'file_map'; // break; + case 'verify': + verifyChanges(); + break; } } diff --git a/static/admin.js b/static/admin.js index d56a6b6..5eb1776 100644 --- a/static/admin.js +++ b/static/admin.js @@ -159,7 +159,7 @@ function onScanSubmit(e) let errors = document.querySelector('#errors'); let error_count = 0; - div = document.querySelector('#main_container div'); + let div = document.querySelector('#main_container div'); let json = createJSONFromDOM(div); for (let node of div.children) { @@ -176,14 +176,21 @@ function onScanSubmit(e) if (error_count == 0) { console.log('valid json, uploading'); - fetchPOSTJSON(VERIFY_URL, json, function() { - // ?? + + fetchPOSTJSON(VERIFY_URL, {body: json}, function(response) { + let main_container = document.querySelector("#main_container"); + resetContainers(main_container); + + if (response.errors) + errors.appendChild(document.createTextNode(response.message)); + else + main_container.appendChild(document.createTextNode(response.message)); + + console.log(response); }); } else { console.log('failed upload, errors in json'); } - - console.log(json); } function scanFolderResponse(data)