Browse Source

add stub for server-side query formatting

master
cinnaboot 7 years ago
parent
commit
974ef0378d
  1. 29
      admin.php
  2. 17
      static/admin.js

29
admin.php

@ -21,7 +21,8 @@ declare(strict_types=1);
require_once('include/getJsonErrorString.php'); 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; const MAX_RECURSE_DEPTH = 5;
$g_errors = []; $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 function main() : void
{ {
switch (@$_GET['action']) { switch (@$_GET['action']) {
@ -156,6 +180,9 @@ function main() : void
case 'file_map'; case 'file_map';
// //
break; break;
case 'verify':
verifyChanges();
break;
} }
} }

17
static/admin.js

@ -159,7 +159,7 @@ function onScanSubmit(e)
let errors = document.querySelector('#errors'); let errors = document.querySelector('#errors');
let error_count = 0; let error_count = 0;
div = document.querySelector('#main_container div'); let div = document.querySelector('#main_container div');
let json = createJSONFromDOM(div); let json = createJSONFromDOM(div);
for (let node of div.children) { for (let node of div.children) {
@ -176,14 +176,21 @@ function onScanSubmit(e)
if (error_count == 0) { if (error_count == 0) {
console.log('valid json, uploading'); 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 { } else {
console.log('failed upload, errors in json'); console.log('failed upload, errors in json');
} }
console.log(json);
} }
function scanFolderResponse(data) function scanFolderResponse(data)

Loading…
Cancel
Save