diff --git a/src/api/config.js b/src/api/config.js index 636367a..90b7d7e 100644 --- a/src/api/config.js +++ b/src/api/config.js @@ -11,10 +11,11 @@ export default class Config { return fetch(`${this.api}config/all`, { method: 'GET' }).then(parseFetch); } set(data) { - return fetch(`${this.api}config`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(data) - }).then(parseFetch); + const body = new URLSearchParams(); + for (const key in data) { + body.append(key, data[key]); + } + + return fetch(`${this.api}config`, { method: 'POST', body }).then(parseFetch); } } diff --git a/src/api/network.js b/src/api/network.js index ec5e2ff..15742de 100644 --- a/src/api/network.js +++ b/src/api/network.js @@ -14,34 +14,30 @@ export default class Network { return fecth(`${this.api}network/status`, { method: 'GET' }).then(parseFetch); } assosiate(ssid, phrase, recreate = false) { - return fetch(`${this.api}network/associate`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ ssid, phrase, recreate }) - }).then(parseFetch); + const body = new URLSearchParams(); + body.append('ssid', ssid); + body.append('phrase', phrase); + body.append('recreate', recreate); + + return fetch(`${this.api}network/associate`, { method: 'POST', body }).then(parseFetch); } disassociate() { //not tested - return fetch(`${this.api}network/disassociate`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({}) - }).then(parseFetch); + const body = new URLSearchParams(); + + return fetch(`${this.api}network/disassociate`, { method: 'POST', body }).then(parseFetch); } openAccesPoint() { //not tested - return fetch(`${this.api}network/openap`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({}) - }).then(parseFetch); + const body = new URLSearchParams(); + + return fetch(`${this.api}network/openap`, { method: 'POST', body }).then(parseFetch); } remove(ssid) { - return fetch(`${this.api}network/remove`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ ssid }) - }).then(parseFetch); + const body = new URLSearchParams(); + body.append('ssid', ssid); + + return fetch(`${this.api}network/remove`, { method: 'POST', body }).then(parseFetch); } signin() { return fecth(`${this.api}network/signin`, { method: 'GET' }).then(parseFetch); diff --git a/src/api/printer.js b/src/api/printer.js index 63fbb5a..3149f2d 100644 --- a/src/api/printer.js +++ b/src/api/printer.js @@ -17,25 +17,32 @@ export default class Printer { return fetch(`${this.api}printer/listall`, { method: 'GET' }).then(parseFetch); } heatup() { - return fetch(`${this.api}printer/heatup`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({}) - }).then(parseFetch); + const body = new URLSearchParams(); + + return fetch(`${this.api}printer/heatup`, { method: 'POST', body }).then(parseFetch); + } + fetch(id, startCode = 'g28', endCode = 'g28') { + const body = new URLSearchParams(); + body.append('id', id); + body.append('start_code', startCode); + body.append('end_code', endCode); + + return fetch(`${this.api}printer/fetch`, { method: 'POST', body }).then(parseFetch); } print(gcode = '', first = false, start = false, last) { - return fetch(`${this.api}printer/print`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ gcode, first, start, last }) - }).then(parseFetch); + const body = new URLSearchParams(); + body.append('gcode', gcode); + body.append('first', first); + body.append('start', start); + body.append('last', last); + + return fetch(`${this.api}printer/print`, { method: 'POST', body }).then(parseFetch); } stop(gcode = '') { - return fetch(`${this.api}printer/stop`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ gcode, first, start, last }) - }).then(parseFetch); + const body = new URLSearchParams(); + body.append('gcode', gcode); + + return fetch(`${this.api}printer/stop`, { method: 'POST', body }).then(parseFetch); } async _sendBatch(gcode, start, index) { try { diff --git a/src/api/sketch.js b/src/api/sketch.js index 8b6c94b..4213b52 100644 --- a/src/api/sketch.js +++ b/src/api/sketch.js @@ -8,20 +8,17 @@ export default class Sketch { return fetch(`${this.api}sketch/?id=${id}`, { method: 'GET' }).then(parseFetch); } set(data = '') { - return fetch(`${this.api}sketch`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ data }) - }).then(parseFetch); + const body = new URLSearchParams(); + body.append('data', data); + + return fetch(`${this.api}sketch`, { method: 'POST', body }).then(parseFetch); } status() { return fetch(`${this.api}sketch/status`, { method: 'GET' }).then(parseFetch); } clear() { - return fetch(`${this.api}sketch/clear`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({}) - }).then(parseFetch); + const body = new URLSearchParams(); + + return fetch(`${this.api}sketch/clear`, { method: 'POST', body }).then(parseFetch); } } diff --git a/src/api/update.js b/src/api/update.js index 513dc5e..0573a31 100644 --- a/src/api/update.js +++ b/src/api/update.js @@ -9,26 +9,20 @@ export default class Update { } download() { //not tested - return fetch(`${this.api}update/download`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({}) - }).then(parseFetch); + const body = new URLSearchParams(); + + return fetch(`${this.api}update/download`, { method: 'POST', body }).then(parseFetch); } install() { //not tested - return fetch(`${this.api}update/install`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({}) - }).then(parseFetch); + const body = new URLSearchParams(); + + return fetch(`${this.api}update/install`, { method: 'POST', body }).then(parseFetch); } clear() { //not tested - return fetch(`${this.api}update/clear`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({}) - }).then(parseFetch); + const body = new URLSearchParams(); + + return fetch(`${this.api}update/clear`, { method: 'POST', body }).then(parseFetch); } }