X-Git-Url: https://git.cweiske.de/stouyapi.git/blobdiff_plain/5060373c18331dbd58af36c81b930c1cdaf66961..4d2b9288d5403294fe6541358341986910e43c36:/www/api/v1/queued_downloads_delete.php diff --git a/www/api/v1/queued_downloads_delete.php b/www/api/v1/queued_downloads_delete.php new file mode 100644 index 0000000..3861f93 --- /dev/null +++ b/www/api/v1/queued_downloads_delete.php @@ -0,0 +1,53 @@ + + */ +$dbFile = __DIR__ . '/../../../data/push-to-my-ouya.sqlite3'; +$apiGameDir = __DIR__ . '/details-data/'; + +require_once __DIR__ . '/../../../src/push-to-my-ouya-helpers.php'; + +$ip = $_SERVER['REMOTE_ADDR']; +if ($ip == '' || strpos($ip, ':') !== false) { + //empty or IPv6 + header('HTTP/1.0 204 No Content'); + exit(1); +} +$ip = mapIp($ip); + +$game = $_GET['game']; +$cleanGame = preg_replace('#[^a-zA-Z0-9.]#', '', $game); +if ($game != $cleanGame || $game == '') { + header('HTTP/1.0 400 Bad Request'); + header('Content-type: text/plain'); + echo 'Invalid game' . "\n"; + exit(1); +} + +try { + $db = new SQLite3($dbFile, SQLITE3_OPEN_READWRITE); +} catch (Exception $e) { + //db file not found + header('HTTP/1.0 204 No Content'); + exit(1); +} + +$rowId = $db->querySingle( + 'SELECT id FROM pushes' + . ' WHERE ip = \'' . SQLite3::escapeString($ip) . '\'' + . ' AND game =\'' . SQLite3::escapeString($game) . '\'' +); +if ($rowId === null) { + header('HTTP/1.0 404 Not Found'); + header('Content-type: text/plain'); + echo 'Game not queued' . "\n"; + exit(1); +} + +$db->exec('DELETE FROM pushes WHERE id = ' . intval($rowId)); +header('HTTP/1.0 204 No Content'); +?>