Fixed Code

This commit is contained in:
Falko Victor Habel 2024-06-21 10:30:22 +02:00
parent dbd9060591
commit 166c95b7bb
1 changed files with 2 additions and 7 deletions

View File

@ -73,7 +73,7 @@ func streamResponse(w http.ResponseWriter, messages <-chan string) {
} }
for msg := range messages { for msg := range messages {
formattedMessage := createStreamResponse(msg) formattedMessage := createStreamResponse("fromLanguage", "toLanguage", msg) // Adjust as needed
fmt.Fprintf(w, " %s\n\n", formattedMessage) fmt.Fprintf(w, " %s\n\n", formattedMessage)
flusher.Flush() flusher.Flush()
} }
@ -83,7 +83,7 @@ func downloadPackages(w http.ResponseWriter, fromLanguage, toLanguage string) {
messages := make(chan string) messages := make(chan string)
defer close(messages) defer close(messages)
go streamResponse(w, fromLanguage, toLanguage, messages) go streamResponse(w, messages)
cmd := exec.Command(linux, "translator/download.py", fromLanguage, toLanguage) cmd := exec.Command(linux, "translator/download.py", fromLanguage, toLanguage)
output, err := cmd.StdoutPipe() output, err := cmd.StdoutPipe()
@ -193,11 +193,6 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
return return
} }
// Convert byte slices to strings
msg.Message = string(body)
msg.From = string(msg.From)
msg.To = string(msg.To)
if len(msg.From) > 2 || len(msg.To) > 2 { if len(msg.From) > 2 || len(msg.To) > 2 {
http.Error(w, "From and To fields should not be longer than 2 letters.", http.StatusBadRequest) http.Error(w, "From and To fields should not be longer than 2 letters.", http.StatusBadRequest)
return return