webserver up and running for http/https, logger timestamp format change

This commit is contained in:
Maximilian Wagner
2025-12-25 23:31:48 +01:00
parent a54c4cf9ff
commit aa76d9c721
12 changed files with 190 additions and 62 deletions

View File

@@ -1,13 +1,15 @@
package backend
import (
"encoding/json"
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"encoding/json"
"errors"
"git.noctra.dev/noctra/servtex/globals"
"time"
"git.noctra.dev/noctra/servtex/globals"
)
// Returns the current time in the timezone specified in the config file
@@ -21,13 +23,19 @@ func GetLocalTimeRFC() string {
return GetLocalTime().Format(time.RFC3339)
}
func GetLocalTimeLog() string {
return GetLocalTime().Format("2006/01/02 15:04:05")
}
// Returns the current localtime in custom pretty print format
func GetLocalTimePretty() string {
return GetLocalTime().Format("02.01.2006 15:04")
}
// Writes to log and prints to screen
func LogLine(message string) {
logline := "\n" + GetLocalTimeRFC() + " - " + message
logline := GetLocalTimeLog() + " ServTeX: " + message + "\n"
fmt.Print(logline)
globals.LogFile.WriteString(logline)
}
@@ -37,8 +45,7 @@ func LogLine(message string) {
func configReaderParse(filePath string, configOptionStorage *globals.Config) error {
jsonData, err := os.ReadFile(filePath)
if err == nil {
err = json.Unmarshal(jsonData, &configOptionStorage)
if err != nil {
if err = json.Unmarshal(jsonData, &configOptionStorage); err != nil {
return errors.New("Config file could not be read")
}
} else {
@@ -89,10 +96,13 @@ func ChangeWatch(path string, callOnChange func()) {
// Intended to be run as goroutine
func LatexCompile(config globals.Config, execution *globals.LatexExecution) error {
if !execution.ExecutionLock.TryLock() {
if execution.ExecutionLock.TryLock() {
defer execution.ExecutionLock.Unlock()
} else {
LogLine("LaTeX execution already underway")
return errors.New("Execution already in progress")
}
LogLine("LaTeX execution started")
execution.ExecutionState = "Started"
@@ -109,7 +119,6 @@ func LatexCompile(config globals.Config, execution *globals.LatexExecution) erro
execution.ExecutionState = "Unknown Latex Engine"
execution.Output = []byte{}
execution.Timestamp = GetLocalTimePretty()
execution.ExecutionLock.Unlock()
return errors.New("Unknown Latex Engine")
}
@@ -123,7 +132,6 @@ func LatexCompile(config globals.Config, execution *globals.LatexExecution) erro
execution.Output = stdout
execution.Timestamp = GetLocalTimePretty()
execution.ExecutionState = "Done"
execution.ExecutionLock.Unlock()
return nil
}