master
Dirk Heilig 2024-04-20 17:26:31 +02:00
parent 89418701ed
commit 25470375b0
4 changed files with 63 additions and 72 deletions

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,57 +1,54 @@
<?php
phpinfo();
exit;
if($_SERVER['REQUEST_METHOD'] === 'POST') {
$tags = explode("\n", $_POST['tags']);
$tags = array_map('trim', $tags);
$tags = array_filter($tags, function($tag) {
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']) && '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);
exit;
}else{
echo <<<EOT
exit();
} else {
echo <<<EOT
<html>
<head>
<title>c3RE AuerBoxTag Generator (Download starting)</title>
@ -65,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++;
@ -87,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);