videoapp-compiler / api /config.php
josephrw's picture
Upload api/config.php with huggingface_hub
80709f1 verified
Raw
History Blame Contribute Delete
1.58 kB
<?php
define('APP_ROOT', '/app');
define('STORAGE_ROOT', APP_ROOT . '/storage');
define('UPLOAD_DIR', STORAGE_ROOT . '/uploads');
define('RECEIPT_DIR', STORAGE_ROOT . '/receipts');
define('GENERATED_DIR', STORAGE_ROOT . '/generated');
define('DMG_DIR', STORAGE_ROOT . '/dmgs');
define('BIN_EXTRACT', APP_ROOT . '/videoextract');
// Load HF_TOKEN from env file if not in environment
if (!getenv('HF_TOKEN')) {
$envFile = APP_ROOT . '/.hf_token';
if (file_exists($envFile)) {
$token = trim(file_get_contents($envFile));
if ($token) {
putenv("HF_TOKEN=$token");
}
}
}
function json_response($data, $status = 200) {
http_response_code($status);
header('Content-Type: application/json');
echo json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
exit;
}
function fail_json($message, $status = 400, $extra = []) {
json_response(array_merge([
'ok' => false,
'error' => $message
], $extra), $status);
}
function ensure_dirs() {
foreach ([UPLOAD_DIR, RECEIPT_DIR, GENERATED_DIR, DMG_DIR] as $dir) {
if (!is_dir($dir)) {
mkdir($dir, 0775, true);
}
}
}
function safe_id() {
return bin2hex(random_bytes(8));
}
function shell_arg($s) {
return escapeshellarg($s);
}
function read_json_file($path) {
if (!file_exists($path)) return null;
$raw = file_get_contents($path);
return json_decode($raw, true);
}
function write_json_file($path, $data) {
file_put_contents($path, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
}