fix merge log json bug

This commit is contained in:
pakintada@gmail.com 2023-09-21 11:04:44 +07:00
parent 6b39392dfb
commit 17ad8486a6
3 changed files with 136 additions and 79 deletions

View file

@ -46,7 +46,7 @@ export class MergeComponent<T> {
this.targets.changelog_path = this.mergeForm.value.changelog_path!;
// TODO: Fetch merge. Modify this to websocket
let mergeLogs;
this.httpClient.post<T>(environment.api+"/merge", {
master: this.targets.master_version,
dev: this.targets.dev_version,
@ -60,16 +60,18 @@ export class MergeComponent<T> {
if(typeof value === "object" && value !== null){
if("message" in value){
// fetch html
this.fetchLogsToDisplay("", true);
this.fetchLogsToDisplay("", true, false);
// fetch log file
this.fetchLogsToDisplay("", false);
this.fetchLogsToDisplay("", false, false);
// fetch json
mergeLogs = this.fetchLogsToDisplay("", false, true);
}
}
},
})
}
fetchLogsToDisplay(query: string, isDisplayOnly: boolean){
fetchLogsToDisplay(query: string, isDisplayOnly: boolean, requestJson: boolean){
let additionalParams:string = "?query=";
if(query != ""){
additionalParams += query
@ -77,31 +79,52 @@ export class MergeComponent<T> {
additionalParams = ""
}
this.httpClient.post(environment.api+"/dllog"+additionalParams, {
htmlfile: isDisplayOnly,
},{
responseType: 'blob',
withCredentials: true,
}).subscribe(
{
let jsontarget;
if(requestJson){
this.httpClient.post(environment.api+"/dllog"+additionalParams, {
htmlfile: isDisplayOnly,
requestJson: requestJson
}, {
responseType: 'json',
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 = "Click here to download as `.log` file";
if(isDisplayOnly){
blob.text().then(v => document.getElementById("log-disp-texts")!.innerHTML = v);
} else {
document.getElementById("log-dl")?.appendChild(a);
document.getElementById("log-dl")!.className = "bg-yellow-500 rounded p-2 sticky top-0";
}
jsontarget = value;
},
error: (err) => {
console.error('Error downloading log file: ',err);
console.error('Error fetch json: ',err);
}
}
)
});
return jsontarget;
} else {
this.httpClient.post(environment.api+"/dllog"+additionalParams, {
htmlfile: isDisplayOnly,
requestJson: requestJson
},{
responseType: 'blob',
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 = "Click here to download as `.log` file";
if(isDisplayOnly){
blob.text().then(v => document.getElementById("log-disp-texts")!.innerHTML = v);
} else {
document.getElementById("log-dl")?.appendChild(a);
document.getElementById("log-dl")!.className = "bg-yellow-500 rounded p-2 sticky top-0";
}
},
error: (err) => {
console.error('Error downloading log file: ',err);
}
}
)
}
}
}