Merge pull request #222 from AlbertMN/patch-1

Add `headers` parameter for URL STL load
This commit is contained in:
Stewart Allen 2022-10-05 18:22:24 -04:00 • committed by GitHub
commit 3bccdb7a03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View file

@ -328,7 +328,7 @@ function platformLoad(url, onload) {
} }
} }
function platformLoadSTL(url, onload, formdata, credentials) { function platformLoadSTL(url, onload, formdata, credentials, headers) {
new load.STL().load(url, (vertices, filename) => { new load.STL().load(url, (vertices, filename) => {
if (vertices) { if (vertices) {
let widget = newWidget().loadVertices(vertices); let widget = newWidget().loadVertices(vertices);
@ -338,7 +338,7 @@ function platformLoadSTL(url, onload, formdata, credentials) {
onload(vertices, widget); onload(vertices, widget);
} }
} }
}, formdata, 1 / api.view.unit_scale(), credentials); }, formdata, 1 / api.view.unit_scale(), credentials, headers);
} }
function platformLoadURL(url, options = {}) { function platformLoadURL(url, options = {}) {

View file

@ -23,13 +23,14 @@ function STL() {
this.colors = null; this.colors = null;
} }
SP.load = function(url, callback, formdata, scale, credentials) { SP.load = function(url, callback, formdata, scale, credentials, headers) {
const stl = this; const stl = this;
fetch(url, { fetch(url, {
method: formdata ? 'POST' : 'GET', method: formdata ? 'POST' : 'GET',
credentials: credentials ? credentials : 'same-origin', credentials: credentials ? credentials : 'same-origin',
body: formdata body: formdata,
...(headers ? {headers: headers} : {})
}).then(response => { }).then(response => {
if (response.status === 200 || response.status === 0) { if (response.status === 200 || response.status === 0) {
response.arrayBuffer().then(buffer => { response.arrayBuffer().then(buffer => {