Add sample display logs from server.WIP
This commit is contained in:
parent
cc3e146cc2
commit
b2ab74434f
3 changed files with 55 additions and 19 deletions
|
|
@ -1,9 +1,10 @@
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<div class="flex-1 bg-slate-400 h-screen p-8">
|
<div class="flex-1 flex-wrap bg-stone-200 p-8" id="log-disp">
|
||||||
<p> Display log here !</p>
|
<div id="log-dl"></div>
|
||||||
|
<p class="flex flex-wrap" id="log-disp-texts"> Display log here !</p>
|
||||||
</div>
|
</div>
|
||||||
<!-- Temporary remove log -->
|
<!-- Temporary remove log -->
|
||||||
<div class="flex-3 bg-slate-700 h-screen justify-centers items-center">
|
<div class="flex-3 sticky top-0 bg-slate-700 h-screen justify-centers items-center">
|
||||||
<app-merge></app-merge>
|
<app-merge></app-merge>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ import { CommonModule } from '@angular/common';
|
||||||
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
|
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
|
||||||
import { MergeServiceService } from './merge-service.service';
|
import { MergeServiceService } from './merge-service.service';
|
||||||
import { HttpClient } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
import { environment } from 'src/environments/environment.development';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-merge',
|
selector: 'app-merge',
|
||||||
|
|
@ -12,7 +14,7 @@ import { HttpClient } from '@angular/common/http';
|
||||||
templateUrl: './merge.component.html',
|
templateUrl: './merge.component.html',
|
||||||
styleUrls: ['./merge.component.css']
|
styleUrls: ['./merge.component.css']
|
||||||
})
|
})
|
||||||
export class MergeComponent {
|
export class MergeComponent<T> {
|
||||||
|
|
||||||
exceptionValues = [0, null, undefined]
|
exceptionValues = [0, null, undefined]
|
||||||
|
|
||||||
|
|
@ -45,7 +47,7 @@ export class MergeComponent {
|
||||||
|
|
||||||
// TODO: Fetch merge. Modify this to websocket
|
// TODO: Fetch merge. Modify this to websocket
|
||||||
|
|
||||||
this.httpClient.post("http://localhost:8080/merge", {
|
this.httpClient.post<T>(environment.api+"/merge", {
|
||||||
master: this.targets.master_version,
|
master: this.targets.master_version,
|
||||||
dev: this.targets.dev_version,
|
dev: this.targets.dev_version,
|
||||||
output: this.targets.output_path,
|
output: this.targets.output_path,
|
||||||
|
|
@ -53,8 +55,15 @@ export class MergeComponent {
|
||||||
}, {
|
}, {
|
||||||
withCredentials: true
|
withCredentials: true
|
||||||
}).subscribe({
|
}).subscribe({
|
||||||
next(value) {
|
next: (value: T) => {
|
||||||
console.log(value)
|
console.log(value)
|
||||||
|
if(typeof value === "object" && value !== null){
|
||||||
|
if("message" in value){
|
||||||
|
console.log(value.message)
|
||||||
|
// alert(value.message + " \n Fetching logs ...")
|
||||||
|
this.downloadLogs("");
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -66,20 +75,30 @@ export class MergeComponent {
|
||||||
} else {
|
} else {
|
||||||
additionalParams = ""
|
additionalParams = ""
|
||||||
}
|
}
|
||||||
this.httpClient.get("http://localhost:8080/dllog"+additionalParams, { responseType: 'blob' }).subscribe(
|
this.httpClient.get(environment.api+"/dllog"+additionalParams, {
|
||||||
(data) => {
|
responseType: 'blob',
|
||||||
const blob = new Blob([data], { type: 'application/octet-stream' });
|
withCredentials: true,
|
||||||
|
}).subscribe(
|
||||||
|
{
|
||||||
|
next: (value) => {
|
||||||
|
const blob = new Blob([value], { type: 'application/octet-stream' });
|
||||||
|
const url = window.URL.createObjectURL(blob);
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.href = url;
|
||||||
|
a.download = 'logfile.log';
|
||||||
|
a.innerText = "download log";
|
||||||
|
console.log("Blob: ",blob.text())
|
||||||
|
// document.body.appendChild(a);
|
||||||
|
document.getElementById("log-dl")?.appendChild(a);
|
||||||
|
document.getElementById("log-dl")!.className = "bg-yellow-500 rounded p-2";
|
||||||
|
blob.text().then(v => document.getElementById("log-disp-texts")!.innerHTML = v);
|
||||||
|
// a.click();
|
||||||
|
|
||||||
const url = window.URL.createObjectURL(blob);
|
// window.URL.revokeObjectURL(url);
|
||||||
const a = document.createElement('a');
|
},
|
||||||
a.href = url;
|
error: (err) => {
|
||||||
a.download = 'logfile.log';
|
console.error('Error downloading log file: ',err);
|
||||||
document.body.appendChild(a);
|
}
|
||||||
a.click();
|
|
||||||
window.URL.revokeObjectURL(url);
|
|
||||||
},
|
|
||||||
(error) => {
|
|
||||||
console.error('Error downloading log file: ',error);
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
@ -191,7 +192,22 @@ func (s *Server) createHandler() {
|
||||||
})
|
})
|
||||||
|
|
||||||
r.Get("/dllog", func(w http.ResponseWriter, r *http.Request) {
|
r.Get("/dllog", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
changelog_path := "cofffeemachineConfig/changelog/testlog.html"
|
||||||
|
logFile, err := os.Open(changelog_path)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer logFile.Close()
|
||||||
|
|
||||||
|
w.Header().Set("Content-Disposition", "attachment; filename=logfile.html")
|
||||||
|
w.Header().Set("Content-Type", "application/octet-stream")
|
||||||
|
|
||||||
|
_, err = io.Copy(w, logFile)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
})
|
})
|
||||||
// Recipe Router
|
// Recipe Router
|
||||||
rr := routers.NewRecipeRouter(database)
|
rr := routers.NewRecipeRouter(database)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue