up some deprecated fixes
Build / Build (push) Successful in 10s

This commit is contained in:
wt committed 2026-03-19 14:54:33 +07:00
1 parent fca32c2233
commit 7f0e5b7b10
8 files changed
+21 -105

No files matched your search

-11
View File
@@ -16,7 +16,6 @@ import (
func ExtlinuxWrite(w http.ResponseWriter, r *http.Request) {
var MOUNT_POINT = os.Getenv("MOUNT_POINT")
var EXTLINUX_FILE = os.Getenv("EXTLINUX_FILE")
// Ограничиваем размер тела, чтобы избежать слишком больших запросов (аналог 4096 в C)
r.Body = http.MaxBytesReader(w, r.Body, 4096)
body, err := io.ReadAll(r.Body)
if err != nil {
@@ -24,7 +23,6 @@ func ExtlinuxWrite(w http.ResponseWriter, r *http.Request) {
return
}
// Парсим JSON
var requestData struct {
Content string `json:"content"`
}
@@ -35,7 +33,6 @@ func ExtlinuxWrite(w http.ResponseWriter, r *http.Request) {
return
}
// Проверяем наличие поля content
if requestData.Content == "" {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusBadRequest)
@@ -45,14 +42,12 @@ func ExtlinuxWrite(w http.ResponseWriter, r *http.Request) {
timestamp := r.URL.Query().Get("timestamp")
if timestamp != "" {
// Полное URL-декодирование (в C декодировался только %3A, но здесь используем стандартный способ)
decoded, err := url.QueryUnescape(timestamp)
if err == nil {
timestamp = decoded
}
}
// Монтируем устройство
if utils.MountDevice() < 0 {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusInternalServerError)
@@ -60,11 +55,9 @@ func ExtlinuxWrite(w http.ResponseWriter, r *http.Request) {
return
}
// Формируем полный путь к файлу
filePath := filepath.Join(MOUNT_POINT, EXTLINUX_FILE)
fmt.Println(filePath)
// Открываем файл на запись (создаём/перезаписываем)
f, err := os.Create(filePath)
if err != nil {
w.Header().Set("Content-Type", "application/json")
@@ -74,7 +67,6 @@ func ExtlinuxWrite(w http.ResponseWriter, r *http.Request) {
}
defer f.Close()
// Записываем содержимое
if _, err := f.WriteString(requestData.Content); err != nil {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusInternalServerError)
@@ -86,7 +78,6 @@ func ExtlinuxWrite(w http.ResponseWriter, r *http.Request) {
versionPath := filepath.Join(MOUNT_POINT, EXTLINUX_FILE+".version")
vf, err := os.Create(versionPath)
if err == nil {
// Форматируем ISO 8601 в человекочитаемый вид (как в C)
var readableDate string
if len(timestamp) >= 19 {
readableDate = timestamp[:10] + " " + timestamp[11:19] // "YYYY-MM-DD HH:MM:SS"
@@ -99,10 +90,8 @@ func ExtlinuxWrite(w http.ResponseWriter, r *http.Request) {
}
}
// Принудительно сбрасываем файловые буферы на диск (аналог sync())
syscall.Sync()
// Успешный ответ
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"status":"success","message":"extlinux.conf updated"}`))