You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.0 KiB

<?php
header('Content-Type: application/json');
require_once __DIR__ . '/default.php';
require_once __DIR__ . '/auth.php';
$action = $_GET['action'] ?? '';
switch ($action) {
case 'load':
echo json_encode(readConfig());
exit;
case 'save':
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
echo json_encode(['error' => 'POST required.']);
exit;
}
$input = json_decode(file_get_contents('php://input'), true);
if (!is_array($input)) {
echo json_encode(['error' => 'Invalid JSON.']);
exit;
}
$config = readConfig();
$config['defaultModel'] = isset($input['defaultModel']) ? (string) $input['defaultModel'] : '';
if (!writeConfig($config)) {
echo json_encode(['error' => 'Unable to save config.']);
exit;
}
echo json_encode(['success' => true, 'defaultModel' => $config['defaultModel']]);
exit;
default:
echo json_encode(['error' => 'Unknown action.']);
exit;
}