Fixed (hopefully) enabled render/preview on initial dir upload
This commit is contained in:
parent
cf00754e29
commit
04c9574a56
2 changed files with 133 additions and 85 deletions
|
|
@ -41,6 +41,54 @@ function mvlog_rm_rf(string $path): void {
|
|||
@rmdir($path);
|
||||
}
|
||||
|
||||
function mvlog_input_dir_state(string $dir): array {
|
||||
$stateFile = $dir . '/.movmaker-state.json';
|
||||
$state = is_file($stateFile) ? json_decode((string)@file_get_contents($stateFile), true) : [];
|
||||
return is_array($state) ? $state : [];
|
||||
}
|
||||
function mvlog_input_dir_preview(string $dir): bool {
|
||||
if (is_file($dir . '/.movmaker-preview')) return true;
|
||||
$state = mvlog_input_dir_state($dir);
|
||||
return !empty($state['preview']);
|
||||
}
|
||||
function mvlog_input_dir_enabled(string $dir): bool { return is_file($dir . '/.movmaker-enabled'); }
|
||||
function mvlog_input_dir_visible_marker(string $dir): bool { return !is_file($dir . '/.mvlog-hidden'); }
|
||||
function mvlog_set_input_dir_visible(string $dir, bool $visible): void {
|
||||
$path = $dir . '/.mvlog-hidden';
|
||||
if ($visible) { if (is_file($path)) @unlink($path); }
|
||||
else { @file_put_contents($path, "hidden
|
||||
"); @chmod($path, 0664); }
|
||||
}
|
||||
function mvlog_input_dir_permalink(string $dir): bool { return is_file($dir . '/.mvlog-permalink'); }
|
||||
function mvlog_input_dir_has_full_output(string $dir, array $config): bool {
|
||||
$state = mvlog_input_dir_state($dir);
|
||||
$output = basename((string)($state['output'] ?? ''));
|
||||
return $output !== '' && is_file($config['videos_dir'] . '/' . $output) && !preg_match('/_preview\.(mp4|webm|mov|m4v)$/i', $output);
|
||||
}
|
||||
function mvlog_input_dir_can_show(string $dir, array $config): bool { return mvlog_input_dir_has_full_output($dir, $config) && !mvlog_input_dir_preview($dir); }
|
||||
function mvlog_initialize_input_dir_defaults(string $dir, array $config): void {
|
||||
if (!is_file($dir . '/.mvlog-hidden') && !mvlog_input_dir_permalink($dir) && !mvlog_input_dir_has_full_output($dir, $config)) {
|
||||
mvlog_set_input_dir_visible($dir, false);
|
||||
}
|
||||
}
|
||||
function mvlog_input_dir_switch_payload(string $dir, array $config, string $articleId): array {
|
||||
$canShow = mvlog_input_dir_can_show($dir, $config);
|
||||
$visible = $canShow && mvlog_input_dir_visible_marker($dir);
|
||||
$permalink = mvlog_input_dir_permalink($dir);
|
||||
return [
|
||||
'dir' => basename($dir),
|
||||
'id' => $articleId,
|
||||
'enabled' => mvlog_input_dir_enabled($dir),
|
||||
'preview' => mvlog_input_dir_preview($dir),
|
||||
'visible' => $visible,
|
||||
'permalink' => $permalink,
|
||||
'can_show' => $canShow,
|
||||
'can_permalink' => $canShow,
|
||||
'public_locked' => $visible || $permalink,
|
||||
'map_hidden' => is_file($dir . '/.mvlog-hide-map'),
|
||||
];
|
||||
}
|
||||
|
||||
function mvlog_cleanup_stale_processing(string $dir, string $name, array $state, string $lockDir, bool $locked, string $status, string $articleId): array {
|
||||
$stateFile = $dir . '/.movmaker-state.json';
|
||||
$started = '';
|
||||
|
|
@ -74,11 +122,11 @@ $workerRunning = mvlog_worker_running();
|
|||
$dirs = glob($config['uploads_dir'] . '/*', GLOB_ONLYDIR) ?: [];
|
||||
foreach ($dirs as $dir) {
|
||||
$name = basename($dir);
|
||||
mvlog_initialize_input_dir_defaults($dir, $config);
|
||||
$stateFile = $dir . '/.movmaker-state.json';
|
||||
$lockDir = $dir . '/.movmaker-lock';
|
||||
$idFile = $dir . '/.mvlog-id';
|
||||
$state = is_file($stateFile) ? json_decode((string)file_get_contents($stateFile), true) : [];
|
||||
if (!is_array($state)) $state = [];
|
||||
$state = mvlog_input_dir_state($dir);
|
||||
$status = (string)($state['status'] ?? '');
|
||||
$articleId = strtolower((string)($state['article_id'] ?? ''));
|
||||
if ($articleId === '' && is_file($idFile)) $articleId = strtolower(trim((string)file_get_contents($idFile)));
|
||||
|
|
@ -92,12 +140,7 @@ foreach ($dirs as $dir) {
|
|||
$cleaned[] = ['dir' => $name, 'id' => $articleId, 'status' => $status];
|
||||
}
|
||||
|
||||
$switches[] = [
|
||||
'dir' => $name,
|
||||
'id' => $articleId,
|
||||
'enabled' => is_file($dir . '/.movmaker-enabled'),
|
||||
'preview' => is_file($dir . '/.movmaker-preview'),
|
||||
];
|
||||
$switches[] = mvlog_input_dir_switch_payload($dir, $config, $articleId);
|
||||
|
||||
if ($locked || $status === 'processing') {
|
||||
$started = '';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue