Skip to content

Commit

Permalink
Update capture.php
Browse files Browse the repository at this point in the history
  • Loading branch information
andi34 authored Dec 5, 2023
1 parent b977a03 commit 74f63d3
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions api/capture.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,25 @@
$logger->debug(basename($_SERVER['PHP_SELF']));

try {
if (!isset($_POST['style'])) {
$rawInput = file_get_contents('php://input');
$postData = json_decode($rawInput, true);

if (!isset($postData['style'])) {
throw new Exception('No style provided');
}

if (!empty($_POST['file']) && (preg_match('/^[a-z0-9_]+\.jpg$/', $_POST['file']) || preg_match('/^[a-z0-9_]+\.(mp4)$/', $_POST['file']))) {
$file = $_POST['file'];
if (!empty($$postData['file']) && (preg_match('/^[a-z0-9_]+\.jpg$/', $postData['file']) || preg_match('/^[a-z0-9_]+\.(mp4)$/', $postData['file']))) {
$file = $postData['file'];
} else {
$file = $_POST['style'] === 'video' ? Image::createNewFilename($config['picture']['naming'], '.mp4') : Image::createNewFilename($config['picture']['naming']);
$file = $postData['style'] === 'video' ? Image::createNewFilename($config['picture']['naming'], '.mp4') : Image::createNewFilename($config['picture']['naming']);
if ($config['database']['file'] != 'db') {
$file = $config['database']['file'] . '_' . $file;
}
}

$filename_tmp = $config['foldersAbs']['tmp'] . DIRECTORY_SEPARATOR . $file;
if (file_exists($filename_tmp)) {
$random = $_POST['style'] === 'video' ? Image::createNewFilename('random', '.mp4') : Image::createNewFilename('random');
$random = $postData['style'] === 'video' ? Image::createNewFilename('random', '.mp4') : Image::createNewFilename('random');
$filename_random = $config['foldersAbs']['tmp'] . DIRECTORY_SEPARATOR . $random;
rename($filename_tmp, $filename_random);
}
Expand All @@ -37,16 +40,16 @@
$captureHandler->fileName = $file;
$captureHandler->tmpFile = $filename_tmp;

switch ($_POST['style']) {
switch ($postData['style']) {
case 'photo':
$captureHandler->style = 'image';
break;
case 'collage':
if (!is_numeric($_POST['collageNumber'])) {
if (!is_numeric($postData['collageNumber'])) {
throw new Exception('No or invalid collage number provided.');
}

$number = $_POST['collageNumber'] + 0;
$number = $postData['collageNumber'] + 0;

if ($number > $config['collage']['limit']) {
throw new Exception('Collage consists only of ' . $config['collage']['limit'] . ' pictures');
Expand All @@ -72,16 +75,16 @@
break;
}

if ($_POST['style'] === 'video') {
if ($postData['style'] === 'video') {
$captureHandler->captureCmd = $config['take_video']['cmd'];
$captureHandler->captureWithCmd();
} elseif ($config['dev']['demo_images']) {
$captureHandler->captureDemo();
} elseif ($config['preview']['mode'] === 'device_cam' && $config['preview']['camTakesPic']) {
$captureHandler->flipImage = $config['preview']['flip'];
$captureHandler->captureCanvas($_POST['canvasimg']);
$captureHandler->captureCanvas($postData['canvasimg']);
} else {
if ($_POST['style'] === 'custom') {
if ($postData['style'] === 'custom') {
$captureHandler->captureCmd = $config['take_custom']['cmd'];
} else {
$captureHandler->captureCmd = $config['take_picture']['cmd'];
Expand Down

0 comments on commit 74f63d3

Please sign in to comment.