Additional inputs for Describe functionality
This commit is contained in:
parent
efaa5c4306
commit
ad184d778d
5 changed files with 239 additions and 38 deletions
66
lib/describe_prompt.php
Normal file
66
lib/describe_prompt.php
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
require __DIR__ . '/../auth.php';
|
||||
mvlog_require_login();
|
||||
|
||||
$MVLOG_ROOT = dirname(__DIR__);
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
$id = strtolower(trim((string)($_POST['id'] ?? $_GET['id'] ?? '')));
|
||||
$job = trim((string)($_POST['job'] ?? $_GET['job'] ?? ''));
|
||||
|
||||
function mvlog_article_id_is_valid(string $id): bool {
|
||||
return (bool)preg_match('/^[0-9]{14}[a-f0-9]{16}$/', $id);
|
||||
}
|
||||
|
||||
function mvlog_legacy_job_is_valid(string $job): bool {
|
||||
return (bool)preg_match('/^[0-9]{8}[-_][A-Za-z0-9._-]+$/', $job);
|
||||
}
|
||||
|
||||
function mvlog_read_article_id(string $jobdir): string {
|
||||
$path = $jobdir . '/.mvlog-id';
|
||||
if (!is_file($path)) return '';
|
||||
$value = strtolower(trim((string)@file_get_contents($path)));
|
||||
return mvlog_article_id_is_valid($value) ? $value : '';
|
||||
}
|
||||
|
||||
function mvlog_find_jobdir_by_id(string $mvlogRoot, string $articleId): ?string {
|
||||
if (!mvlog_article_id_is_valid($articleId)) return null;
|
||||
|
||||
$cacheFile = $mvlogRoot . '/cache/articles-index.json';
|
||||
if (is_file($cacheFile)) {
|
||||
$cache = json_decode((string)@file_get_contents($cacheFile), true);
|
||||
if (is_array($cache) && is_array($cache['by_id'] ?? null)) {
|
||||
$name = (string)($cache['by_id'][$articleId] ?? '');
|
||||
if ($name !== '') {
|
||||
$candidate = $mvlogRoot . '/in-dir/' . basename($name);
|
||||
if (is_dir($candidate)) return $candidate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (glob($mvlogRoot . '/in-dir/*', GLOB_ONLYDIR) ?: [] as $dir) {
|
||||
if (mvlog_read_article_id($dir) === $articleId) return $dir;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$jobdir = null;
|
||||
if ($id !== '' && mvlog_article_id_is_valid($id)) {
|
||||
$jobdir = mvlog_find_jobdir_by_id($MVLOG_ROOT, $id);
|
||||
}
|
||||
if ($jobdir === null && $job !== '' && mvlog_legacy_job_is_valid($job)) {
|
||||
$candidate = $MVLOG_ROOT . '/in-dir/' . basename($job);
|
||||
if (is_dir($candidate)) $jobdir = $candidate;
|
||||
}
|
||||
|
||||
if ($jobdir === null || !is_dir($jobdir)) {
|
||||
http_response_code(404);
|
||||
echo json_encode(['status' => 'error', 'message' => 'job not found']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$path = $jobdir . '/.mvlog-describe-prompt.txt';
|
||||
$prompt = is_file($path) ? trim((string)@file_get_contents($path)) : '';
|
||||
|
||||
echo json_encode(['status' => 'ok', 'additional_prompt' => $prompt], JSON_UNESCAPED_UNICODE);
|
||||
|
|
@ -9,6 +9,7 @@ header('Content-Type: application/json; charset=utf-8');
|
|||
|
||||
$job = $_POST['job'] ?? '';
|
||||
$max_frames = isset($_POST['max_frames']) ? intval($_POST['max_frames']) : 16;
|
||||
$additional_prompt = trim((string)($_POST['additional_prompt'] ?? ''));
|
||||
|
||||
if (!preg_match('/^[0-9]{8}[-_][A-Za-z0-9._-]+$/', $job)) {
|
||||
http_response_code(400);
|
||||
|
|
@ -23,6 +24,14 @@ if (!is_dir($jobdir)) {
|
|||
exit;
|
||||
}
|
||||
|
||||
$describe_prompt_file = $jobdir . '/.mvlog-describe-prompt.txt';
|
||||
if ($additional_prompt !== '') {
|
||||
@file_put_contents($describe_prompt_file, $additional_prompt . PHP_EOL);
|
||||
@chmod($describe_prompt_file, 0664);
|
||||
@chown($describe_prompt_file, 'www-data');
|
||||
@chgrp($describe_prompt_file, 'www-data');
|
||||
}
|
||||
|
||||
// Read existing data.txt for Title and Location (case-insensitive aliases)
|
||||
$data_file = $jobdir . '/data.txt';
|
||||
$title = '';
|
||||
|
|
@ -135,7 +144,11 @@ if (!is_file($script)) {
|
|||
|
||||
$log = $jobdir . '/generate_data.log';
|
||||
$bash = '/bin/bash';
|
||||
$cmd = escapeshellcmd($bash) . ' ' . escapeshellarg($script) . ' ' . escapeshellarg($jobdir) . ' ' . escapeshellarg($title) . ' ' . escapeshellarg($location) . ' ' . escapeshellarg((string)$max_frames) . ' >> ' . escapeshellarg($log) . ' 2>&1 & echo $!';
|
||||
if ($additional_prompt !== '') {
|
||||
$cmd = escapeshellcmd($bash) . ' ' . escapeshellarg($script) . ' ' . escapeshellarg($jobdir) . ' ' . escapeshellarg($title) . ' ' . escapeshellarg($location) . ' ' . escapeshellarg((string)$max_frames) . ' ' . escapeshellarg($additional_prompt) . ' >> ' . escapeshellarg($log) . ' 2>&1 & echo $!';
|
||||
} else {
|
||||
$cmd = escapeshellcmd($bash) . ' ' . escapeshellarg($script) . ' ' . escapeshellarg($jobdir) . ' ' . escapeshellarg($title) . ' ' . escapeshellarg($location) . ' ' . escapeshellarg((string)$max_frames) . ' ' . escapeshellarg('no-append') . ' >> ' . escapeshellarg($log) . ' 2>&1 & echo $!';
|
||||
}
|
||||
|
||||
$pid = trim(@shell_exec($cmd));
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ header('Content-Type: application/json; charset=utf-8');
|
|||
$id = strtolower(trim((string)($_POST['id'] ?? '')));
|
||||
$job = trim((string)($_POST['job'] ?? ''));
|
||||
$max_frames = isset($_POST['max_frames']) ? intval($_POST['max_frames']) : 16;
|
||||
$additional_prompt = trim((string)($_POST['additional_prompt'] ?? ''));
|
||||
|
||||
function mvlog_article_id_is_valid(string $id): bool {
|
||||
return (bool)preg_match('/^[0-9]{14}[a-f0-9]{16}$/', $id);
|
||||
|
|
@ -63,6 +64,14 @@ if ($jobdir === null || !is_dir($jobdir)) {
|
|||
exit;
|
||||
}
|
||||
|
||||
$describe_prompt_file = $jobdir . '/.mvlog-describe-prompt.txt';
|
||||
if ($additional_prompt !== '') {
|
||||
@file_put_contents($describe_prompt_file, $additional_prompt . PHP_EOL);
|
||||
@chmod($describe_prompt_file, 0664);
|
||||
@chown($describe_prompt_file, 'www-data');
|
||||
@chgrp($describe_prompt_file, 'www-data');
|
||||
}
|
||||
|
||||
// Read existing data.txt for Title and Location (case-insensitive aliases)
|
||||
$data_file = $jobdir . '/data.txt';
|
||||
$title = '';
|
||||
|
|
@ -101,8 +110,12 @@ if (!is_file($script)) {
|
|||
exit;
|
||||
}
|
||||
|
||||
// Build command and execute. Use no-append flag as last argument.
|
||||
$cmd = escapeshellcmd($script) . ' ' . escapeshellarg($jobdir) . ' ' . escapeshellarg($title) . ' ' . escapeshellarg($location) . ' ' . escapeshellarg((string)$max_frames) . ' ' . escapeshellarg('no-append') . ' 2>&1';
|
||||
// Build command and execute. Pass optional additional prompt as the last argument.
|
||||
if ($additional_prompt !== '') {
|
||||
$cmd = escapeshellcmd($script) . ' ' . escapeshellarg($jobdir) . ' ' . escapeshellarg($title) . ' ' . escapeshellarg($location) . ' ' . escapeshellarg((string)$max_frames) . ' ' . escapeshellarg($additional_prompt) . ' 2>&1';
|
||||
} else {
|
||||
$cmd = escapeshellcmd($script) . ' ' . escapeshellarg($jobdir) . ' ' . escapeshellarg($title) . ' ' . escapeshellarg($location) . ' ' . escapeshellarg((string)$max_frames) . ' ' . escapeshellarg('no-append') . ' 2>&1';
|
||||
}
|
||||
|
||||
// Allow long-running
|
||||
@set_time_limit(0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue