0

The question arises from this note:

Someone here suggested using div's. The HTML requirement is very skeletal. The 3D display is basically canvas, but it requires seven three.js files, ten js files of my own making to exchange parameters and other variables with the global variable and .dae collada files for each of the 3D models you can see. If they could be linked in like jQuery that might be the solution but I wonder about conflicts.

on Questions on extending GAS spreadsheet usefulness

principally, if they can be linked like jQuery part

The files to be linked are on myDrive. The thinking is that if I can copy the files into GAS editor, it seems as secure and more flexible to bring them into the html directly.

code.gs

function sendUrls(){   
   var folder = DriveApp.getFoldersByName("___Blazer").next();
   var sub = folder.getFoldersByName("assembler").next();
   var contents = sub.getFiles();
   var file;
   var data = []
    while(contents.hasNext()) {
       file = contents.next();
       type = file.getName().split(".")[1];
       url = file.getUrl();
       data.push([type,url]);
     }
     return data;
}

html

google.script.run.withSuccessHandler(function (files) {
    $.each(files,function(i,v){
       if(v[0] === "js"){
           $.get(v[1])
       }
    })
})
.sendUrls();

console

The first url opens the proper script file but the origin file is not recognisable to me.

TheMaster
  • 45,448
  • 6
  • 62
  • 85
Chris Glasier
  • 791
  • 2
  • 10
  • 21
  • Why not get it directly from server and pass the blob to client? – TheMaster Jun 06 '19 at 11:36
  • 1
    @TheMaster In the current stage, the blob cannot be directly passed from Google side to HTML using ``google.script.run()``. So if the data is the binary data and text data, pass the base64 encoded data and the string data, respectively. Or directly retrieves the data from client side using ``fetch()``. At that time, for example, you can use OAuth2, Service Account and API key. And also, if you use ``google.script.run``, the access token can be also retrieved from the server side. – Tanaike Jun 06 '19 at 11:55

1 Answers1

0

I am not sure that this is a proper answer as it relies on cors-anywhere, viz:

function importFile(name){
  var myUrl = 'http://glasier.hk/cors/tba.html';
  var proxy = 'https://cors-anywhere.herokuapp.com/';
  var finalURL = proxy + myUrl;
  $.get(finalURL,function(data) {
     $("body").append(data);
     importNset();
  })
}

function importNset(){
  google.script.run
  .withSuccessHandler(function (code) {
    path = "https://api.myjson.com/bins/"+code;
    $.get(path)
    .done((data, textStatus, jqXHR) => {
      nset = data;
      cfig = nset.cfig;
      start();
      })
    })
  .sendCode();
}

var nset,cfig;
$(document).ready(function(){
  importFile();
});

but it works, albeit on my machine, using my own website as the resource.

I used the Gas function in gas Shop to make the eight previously tested js files into the single tba.html script only file. I swapped the workshop specific script files for those needed for google.script.run but otherwise that was it. If I could find out how to cors-enable my site, I think I might be able to demonstrate how scripts might be imported to generate different views from the same TBA and spreadsheet interfaces.

Chris Glasier
  • 791
  • 2
  • 10
  • 21