File size: 1,584 Bytes
37ac66f
 
 
 
 
 
 
 
 
80709f1
 
 
 
 
 
 
 
 
 
 
37ac66f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?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));
}