Files
html/api/blade-task-create.php
2026-04-21 03:00:04 +02:00

52 lines
1.9 KiB
PHP

<?php
/**
* V111 - Blade Task Creator - WEVIA chat pilote Blade via tasks
* POST /api/blade-task-create.php with key=WEVADS2026 and action+params
* Writes /var/www/html/api/blade-tasks/task_<ts>.json for blade-poll
*/
header('Content-Type: application/json');
$k = $_POST['k'] ?? $_GET['k'] ?? '';
if ($k !== 'WEVADS2026') { http_response_code(403); die(json_encode(['error'=>'auth'])); }
$action = $_POST['action'] ?? $_GET['action'] ?? '';
$DIR = '/var/www/html/api/blade-tasks';
if (!is_dir($DIR)) @mkdir($DIR, 0755, true);
if ($action === 'list') {
$files = glob("$DIR/task_*.json");
sort($files);
$out = [];
foreach ($files as $f) {
$d = @json_decode(@file_get_contents($f), true);
if ($d) $out[] = ['file'=>basename($f),'status'=>$d['status']??'?','goal'=>$d['goal']??'?','created'=>$d['created']??'?'];
}
echo json_encode(['tasks'=>$out,'count'=>count($out)]);
exit;
}
if ($action === 'create') {
$goal = $_POST['goal'] ?? $_GET['goal'] ?? '';
$params = $_POST['params'] ?? $_GET['params'] ?? '{}';
$priority = $_POST['priority'] ?? 'normal';
if (!$goal) { http_response_code(400); die(json_encode(['error'=>'missing goal'])); }
$ts = date('Ymd-His');
$id = 'blade_'.$ts.'_'.substr(md5($goal.mt_rand()),0,6);
$task = [
'id'=>$id,
'goal'=>$goal,
'params'=>json_decode($params,true) ?: [],
'priority'=>$priority,
'status'=>'pending',
'created'=>date('c'),
'source'=>'wevia-master-chat'
];
$file = "$DIR/task_$id.json";
$ok = @file_put_contents($file, json_encode($task, JSON_PRETTY_PRINT));
if ($ok === false) { http_response_code(500); die(json_encode(['error'=>'write failed'])); }
echo json_encode(['ok'=>true,'id'=>$id,'file'=>basename($file),'task'=>$task]);
exit;
}
echo json_encode(['error'=>'unknown action','available'=>['list','create']]);