Compare commits

..

3 Commits

Author SHA1 Message Date
Dirk Heilig 25470375b0 prettier 2024-04-20 17:26:31 +02:00
Dirk Heilig 89418701ed yoda style all the way 2024-04-20 17:25:50 +02:00
Dirk Heilig 0d033c11da add opcache 2024-04-20 17:25:36 +02:00
5 changed files with 65 additions and 72 deletions

View File

@ -1,6 +1,6 @@
FROM debian:12
RUN apt-get update && apt-get upgrade -y && apt-get clean
RUN apt-get install -y supervisor apache2 php libapache2-mod-php php-mbstring php-zip curl git openscad zip cmake build-essential
RUN apt-get install -y supervisor apache2 php libapache2-mod-php php-mbstring php-zip curl git openscad zip cmake build-essential php-opcache
RUN apt-get clean
RUN chown -R www-data:www-data /var/www
RUN curl https://files.openscad.org/snapshots/OpenSCAD-2024.03.28.ai18952-x86_64.AppImage > /tmp/openscad

2
devrun
View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash
set -e
docker build -t taggor .
docker run -p 8888:80 -v "$PWD/src:/var/www/src" --rm -it taggor "$@"
docker run -p 8888:80 -v "$PWD/src:/var/www/src" --rm -it taggor "$@"

View File

@ -1,55 +1,54 @@
<?php
if($_SERVER['REQUEST_METHOD'] === 'POST') {
$tags = explode("\n", $_POST['tags']);
$tags = array_map('trim', $tags);
$tags = array_filter($tags, function($tag) {
phpinfo();
exit();
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$tags = explode("\n", $_POST["tags"]);
$tags = array_map("trim", $tags);
$tags = array_filter($tags, function ($tag) {
return !empty($tag);
});
if(empty($tags)){
if (empty($tags)) {
header("Location: /?err=notags");
exit;
exit();
}
$jobId=microtime(1).'_'.uniqid();
$jobId = microtime(1) . "_" . uniqid();
#file_put_contents()
$queueDir=__DIR__.'/../queue';
$queueDir=realpath($queueDir);
$queueFile=$queueDir.'/'.$jobId.'.json';
$queueDir = __DIR__ . "/../queue";
$queueDir = realpath($queueDir);
$queueFile = $queueDir . "/" . $jobId . ".json";
file_put_contents($queueFile, json_encode($tags));
header('Location: /?jobid='.$jobId);
exit;
header("Location: /?jobid=" . $jobId);
exit();
}
if(isset($_GET['jobid'])){
$jobId=$_GET['jobid'];
$queueDir=__DIR__.'/../queue';
$queueDir=realpath($queueDir);
$queueFile=$queueDir.'/'.$jobId.'.json';
if (isset($_GET["jobid"])) {
$jobId = $_GET["jobid"];
$queueDir = __DIR__ . "/../queue";
$queueDir = realpath($queueDir);
$queueFile = $queueDir . "/" . $jobId . ".json";
$allJobs=glob($queueDir.'/*.json');
$allJobs = glob($queueDir . "/*.json");
sort($allJobs);
$myPositionInQueue=array_search($queueFile, $allJobs);
$myPositionInQueue = array_search($queueFile, $allJobs);
if (false === $myPositionInQueue) {
if (isset($_GET["download"]) && "1" == $_GET["download"]) {
$dlDir = __DIR__ . "/../html/dl";
$dlDir = realpath($dlDir);
$zipFile = $dlDir . "/" . $jobId . ".zip";
header("Content-Type: application/zip");
header(
'Content-Disposition: attachment; filename="' .
basename($zipFile) .
'"'
);
readfile($zipFile);
if(false === $myPositionInQueue) {
if(isset($_GET['download']) && $_GET['download'] == '1'){
$dlDir=__DIR__.'/../html/dl';
$dlDir=realpath($dlDir);
$zipFile=$dlDir.'/'.$jobId.'.zip';
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="'.basename($zipFile).'"');
readfile($zipFile);
exit;
}else{
echo <<<EOT
exit();
} else {
echo <<<EOT
<html>
<head>
<title>c3RE AuerBoxTag Generator (Download starting)</title>
@ -63,12 +62,9 @@ Your job $jobId is Finished.
</body>
</html>
EOT;
}
header('HTTP/1.1 404 Not Found');
exit;
header("HTTP/1.1 404 Not Found");
exit();
}
$myPositionInQueue++;
@ -85,15 +81,13 @@ Your job $jobId is $myPositionInQueue in the queue.
</body>
</html>
EOT;
exit;
exit();
}
$err='';
switch($_GET['err']){
case 'notags':
$err='Please provide at least one tag';
$err = "";
switch ($_GET["err"]) {
case "notags":
$err = "Please provide at least one tag";
break;
}
?>

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
cd "$( dirname "${BASH_SOURCE[0]}" )"
cd "$(dirname "${BASH_SOURCE[0]}")"
while :; do
sleep 5 &
./queueWorker
wait
done
done

View File

@ -1,36 +1,35 @@
#!/usr/bin/env php
<?php
$queueDir=__DIR__.'/../queue';
$queueDir=realpath($queueDir);
$queueItems=glob($queueDir.'/*.json');
$dlDir=__DIR__.'/../html/dl/';
if(!is_dir($dlDir)){
$queueDir = __DIR__ . "/../queue";
$queueDir = realpath($queueDir);
$queueItems = glob($queueDir . "/*.json");
$dlDir = __DIR__ . "/../html/dl/";
if (!is_dir($dlDir)) {
mkdir($dlDir);
}
if(empty($queueItems)){
if (empty($queueItems)) {
//clean up old files from dldir older than 24h
$oldFiles=glob($dlDir.'/*.zip');
foreach ($oldFiles as $oldFile){
if(filemtime($oldFile) < time()-24*60*60){
$oldFiles = glob($dlDir . "/*.zip");
foreach ($oldFiles as $oldFile) {
if (filemtime($oldFile) < time() - 24 * 60 * 60) {
unlink($oldFile);
}
}
exit;
exit();
}
sort($queueItems);
$jobFile=array_shift($queueItems);
$jobId=basename($jobFile, '.json');
$tags=json_decode(file_get_contents($jobFile), true);
$zipFile=$dlDir.$jobId.'.zip';
chdir(__DIR__.'/../AuerNameTag');
$shellArgs=array_map('escapeshellarg', $tags);
$jobFile = array_shift($queueItems);
$jobId = basename($jobFile, ".json");
$tags = json_decode(file_get_contents($jobFile), true);
$zipFile = $dlDir . $jobId . ".zip";
chdir(__DIR__ . "/../AuerNameTag");
$shellArgs = array_map("escapeshellarg", $tags);
system("rm -rf out");
system("git reset --hard");
system("./make.sh ". implode(' ', $shellArgs));
system("./make.sh " . implode(" ", $shellArgs));
chdir("out");
system("zip -r $zipFile .");
chdir('..');
chdir("..");
system("rm -rf out");
unlink($jobFile);