45 lines
1.7 KiB
PHP
45 lines
1.7 KiB
PHP
<?php
|
|
// Claude Sync Endpoint — receives transcripts + documents from Claude sessions
|
|
header("Content-Type: application/json");
|
|
$action = $_GET['action'] ?? '';
|
|
$dest = "/var/www/weval/claude-sync/";
|
|
|
|
if ($action === 'upload') {
|
|
$type = $_GET['type'] ?? 'outputs'; // transcripts|outputs|uploads
|
|
$name = basename($_GET['name'] ?? 'file_'.time());
|
|
$dir = $dest . ($type === 'transcripts' ? 'transcripts/' : ($type === 'uploads' ? 'uploads/' : 'outputs/'));
|
|
@mkdir($dir, 0755, true);
|
|
$raw = file_get_contents("php://input");
|
|
if (strlen($raw) > 10) {
|
|
file_put_contents($dir . $name, $raw, FILE_APPEND);
|
|
echo json_encode(["ok"=>true, "file"=>$name, "size"=>filesize($dir.$name)]);
|
|
} else {
|
|
echo json_encode(["error"=>"no data"]);
|
|
}
|
|
} elseif ($action === 'clear') {
|
|
$name = basename($_GET['name'] ?? '');
|
|
$type = $_GET['type'] ?? 'outputs';
|
|
$dir = $dest . ($type === 'transcripts' ? 'transcripts/' : 'outputs/');
|
|
@unlink($dir . $name);
|
|
echo json_encode(["ok"=>true, "cleared"=>$name]);
|
|
} elseif ($action === 'list') {
|
|
$result = [];
|
|
foreach(['transcripts','outputs','uploads'] as $sub) {
|
|
$dir = $dest . $sub . '/';
|
|
$files = [];
|
|
if (is_dir($dir)) {
|
|
foreach(scandir($dir) as $f) {
|
|
if ($f[0] !== '.') $files[] = ["name"=>$f, "size"=>filesize($dir.$f), "modified"=>filemtime($dir.$f)];
|
|
}
|
|
}
|
|
$result[$sub] = $files;
|
|
}
|
|
echo json_encode($result, JSON_PRETTY_PRINT);
|
|
} else {
|
|
echo json_encode(["endpoints"=>[
|
|
"?action=list" => "List all synced files",
|
|
"?action=upload&type=transcripts&name=xxx" => "Upload file (POST body)",
|
|
"?action=clear&type=outputs&name=xxx" => "Delete file"
|
|
]]);
|
|
}
|