-
-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(admin): config editor #933
base: master
Are you sure you want to change the base?
Conversation
+шаг к инсталлеру, получается |
} else { | ||
$this->returnJson(["success" => false, "error" => tr("admin_tuning_cfg_write_fail")]); | ||
} | ||
} else { | ||
$this->returnJson(["success" => false, "error" => tr("admin_tuning_cfg_create_fail")]); | ||
} | ||
} else { | ||
$this->returnJson(["success" => false, "error" => tr("admin_tuning_cfg_create_fail")]); | ||
} | ||
} else { | ||
$this->returnJson(["success" => false, "error" => tr("admin_tuning_cfg_tmp_read_fail_yaml")]); | ||
} | ||
} else { | ||
$this->returnJson(["success" => false, "error" => tr("admin_tuning_cfg_tmp_read_fail")]); | ||
} | ||
} else { | ||
$this->returnJson(["success" => false, "error" => tr("admin_tuning_cfg_file_write_err")]); | ||
} | ||
} else { | ||
$this->returnJson(["success" => false, "error" => tr("admin_tuning_cfg_file_create_err")]); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
что это за порно
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Спросил ChatGPT, ответ убил:
function renderTuning(): void
{
$mode = in_array($this->queryParam("act"), ["cfg"]) ? $this->queryParam("act") : "cfg";
if ($_SERVER["REQUEST_METHOD"] !== "POST") {
$this->template->mode = $mode;
if ($mode === "cfg") {
$file_path = __DIR__ . "../../../openvk.yml";
if (file_exists($file_path)) {
$this->template->cfg = chandler_parse_yaml($file_path);
return;
}
$example_path = __DIR__ . "../../../openvk-example.yml";
if (file_exists($example_path)) {
$this->flash("warn", tr("admin_tuning_cfg_not_found"), tr("admin_tuning_cfg_not_found_description"));
$this->template->cfg = chandler_parse_yaml($example_path);
return;
}
$repo_file = file_get_contents("https://raw.githubusercontent.com/openvk/openvk/master/openvk-example.yml");
if (!$repo_file) {
$this->flash("err", tr("admin_tuning_cfg_file_not_found_in_repo"), tr("admin_tuning_cfg_error_description"));
return;
}
$file = fopen($file_path, "x");
if (!$file) {
$this->flash("err", tr("admin_tuning_cfg_file_create_err"), tr("admin_tuning_cfg_error_description"));
return;
}
if (!fwrite($file, $repo_file)) {
fclose($file);
$this->flash("err", tr("admin_tuning_cfg_file_write_err"), tr("admin_tuning_cfg_error_description"));
return;
}
fclose($file);
$this->template->cfg = chandler_parse_yaml($file_path);
}
return;
}
// POST Request
$this->assertNoCSRF();
if ($mode !== "cfg") {
return; // Or handle other modes if needed
}
$yaml = $this->postParam("yaml");
if (!$yaml) {
$this->notFound();
}
$temp_file_path = __DIR__ . "../../../openvk." . time() . ".yml";
$temp_file = fopen($temp_file_path, "x");
if (!$temp_file) {
$this->returnJson(["success" => false, "error" => tr("admin_tuning_cfg_file_create_err")]);
return;
}
if (!fwrite($temp_file, $yaml)) {
$this->returnJson(["success" => false, "error" => tr("admin_tuning_cfg_file_write_err")]);
return;
}
$temp_file_content = file_get_contents($temp_file_path);
if (!$temp_file_content) {
$this->returnJson(["success" => false, "error" => tr("admin_tuning_cfg_tmp_read_fail")]);
return;
}
if (!chandler_parse_yaml($temp_file_path)) {
$this->returnJson(["success" => false, "error" => tr("admin_tuning_cfg_tmp_read_fail_yaml")]);
return;
}
$cfg_file_path = __DIR__ . "../../../openvk.yml";
$backup_path = $cfg_file_path . ".tmp";
if (!rename($cfg_file_path, $backup_path)) {
$this->returnJson(["success" => false, "error" => tr("admin_tuning_cfg_create_fail")]);
return;
}
$cfg_file = fopen($cfg_file_path, "x");
if (!$cfg_file) {
$this->returnJson(["success" => false, "error" => tr("admin_tuning_cfg_create_fail")]);
return;
}
if (!file_put_contents($cfg_file_path, $temp_file_content)) {
$this->returnJson(["success" => false, "error" => tr("admin_tuning_cfg_write_fail")]);
return;
}
unlink($backup_path);
unlink($temp_file_path);
$this->returnJson(["success" => true]);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Советую решить конфликт слияния
Этот PR добавляет возможность редактировать конфиг (openvk.yml) через интерфейс админ-панели. Для более удобного редактирования названия ключей были переведены. Также, если файл с конфигом не существует, интерфейс попытается скопировать его из openvk-example.yml, или, если и он не найден, скачать из репозитория.
![image](https://github.com/openvk/openvk/assets/93197434/dbd31297-2f80-4a0d-948a-604669ebf4ab)