43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
|
// Obsidian Vault Sync Receiver - S204
|
|
// Receives .md files from Razer Blade Obsidian vault
|
|
|
|
header('Content-Type: application/json');
|
|
$data = json_decode(file_get_contents('php://input'), true);
|
|
|
|
if (!$data || ($data['action'] ?? '') !== 'obsidian_sync') {
|
|
echo json_encode(['status' => 'ignored']);
|
|
exit;
|
|
}
|
|
|
|
$base = '/var/www/weval/wevia-ia/wevialife-data/obsidian';
|
|
if (!is_dir($base)) mkdir($base, 0755, true);
|
|
|
|
$path = $data['path'] ?? '';
|
|
$content = $data['content'] ?? '';
|
|
|
|
if (!$path || !$content) {
|
|
echo json_encode(['error' => 'missing path or content']);
|
|
exit;
|
|
}
|
|
|
|
// Security: only allow .md files, no path traversal
|
|
$path = str_replace('..', '', $path);
|
|
if (!preg_match('/\.md$/', $path)) {
|
|
echo json_encode(['error' => 'only .md files']);
|
|
exit;
|
|
}
|
|
|
|
$fullPath = $base . $path;
|
|
$dir = dirname($fullPath);
|
|
if (!is_dir($dir)) mkdir($dir, 0755, true);
|
|
|
|
$decoded = base64_decode($content);
|
|
if ($decoded === false) {
|
|
echo json_encode(['error' => 'base64 decode failed']);
|
|
exit;
|
|
}
|
|
|
|
file_put_contents($fullPath, $decoded);
|
|
echo json_encode(['status' => 'ok', 'path' => $path, 'size' => strlen($decoded)]);
|