|
|
|
@ -1,7 +1,9 @@
|
|
|
|
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
|
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { timeout } from 'rxjs/operators'
|
|
|
|
|
|
|
|
|
|
const URL = "https://compiler.sensebox.de"
|
|
|
|
|
// const URL = "https://compiler.sensebox.de"
|
|
|
|
|
const URL = "http://compiler.snsbx.nroo.de"
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class CompilerProvider {
|
|
|
|
@ -10,23 +12,28 @@ export class CompilerProvider {
|
|
|
|
|
console.log('Hello CompilerProvider Provider');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async callcompiler(sketch : string): Promise<any> {
|
|
|
|
|
async callcompiler(sketch : string): Promise<ArrayBuffer> {
|
|
|
|
|
const headers = new HttpHeaders({'Content-Type': 'application/json'} );
|
|
|
|
|
const data = { board: 'sensebox-mcu', sketch }
|
|
|
|
|
|
|
|
|
|
// send compilation request, returning a job ID
|
|
|
|
|
return this.http.post(`${URL}/compile`, data, { headers }).toPromise()
|
|
|
|
|
return this.http.post(`${URL}/compile`, data, { headers })
|
|
|
|
|
.pipe(timeout(4000))
|
|
|
|
|
.toPromise()
|
|
|
|
|
.catch(err => {
|
|
|
|
|
let msg = ''
|
|
|
|
|
try { msg = JSON.parse(err.error.message).process } catch (err) {}
|
|
|
|
|
throw new Error(msg || err)
|
|
|
|
|
let msg = 'unable to contact web compiler. are you online?'
|
|
|
|
|
try {
|
|
|
|
|
// attempt to extract the compilation error message and clean it up
|
|
|
|
|
msg = JSON.parse(err.error.message).process
|
|
|
|
|
msg = `compilation error: ${msg.substr(msg.indexOf(' ') + 14)}`
|
|
|
|
|
msg = msg.substr(0, msg.indexOf('^'))
|
|
|
|
|
} catch (err) {}
|
|
|
|
|
throw Error(msg)
|
|
|
|
|
})
|
|
|
|
|
.then((response:any) =>{
|
|
|
|
|
// download the resulting sketch binary
|
|
|
|
|
return this.http.get(`${URL}/download?id=${response.data.id}&board=sensebox-mcu`, {
|
|
|
|
|
responseType: 'text',
|
|
|
|
|
}).toPromise()
|
|
|
|
|
|
|
|
|
|
.then((response: any) => {
|
|
|
|
|
const url = `${URL}/download?id=${response.data.id}&board=sensebox-mcu`
|
|
|
|
|
return this.http.get(url, { responseType: 'arraybuffer' }).toPromise()
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|