Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

62
LINES

< > BotCompany Repo | #1028676 - Snippet Transpiler Web Bot [Dyn Module]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (10129L/58K).

!7

// uses its own transpiler so it can set options

cmodule SnippetTranspiler {
  switchable int refreshDelay = 1; // seconds
  switchable S authModuleID;

  virtual WebResponse html(WebRequest req) {
    SS params = req.params;
    
    // check auth module if set
    if (nempty(authModuleID))
      try object dm_call_assertModuleExists(authModuleID, 'webAuthCheck, req.uri, params);
      
    ret dm_evalInQ(() -> {
      if (eq("1", params.get('medium))) {
        veryQuickJava_mediumRefresh();
        print("Medium-refreshed transpiler.");
      }
      
      if (eq("1", params.get('fresh))) {
        refreshTranspiler();
        print("Refreshed transpiler.");
      }
      
      S uri = dropPrefixSlash(req.uri);
      if (isSnippetID(uri)) params.put(snippetID := uri);
      
      if (empty(params.get('snippetID))) ret "OK";
      
      sendToSnippetUpdatesBot("/transpiling/" + params.get('snippetID));
      
      final bool compile = eq("1", params.get('compile));
      
      final new Flag ok;
      print_byThread = new InheritableThreadLocal;
      S text = hijackPrint_tee(r {
        S snippetID = fsI(params.get('snippetID));
        pcall {
          bool isInclude = getSnippetType(snippetID) == snippetType_JavaXInclude();
          transpileRaw_translator();
          set(transpileRaw_trans, +print_byThread);
          print("Set print_byThread (" + print_byThread! + ") in " + systemHashCode(transpileRaw_trans));
          temp tempSetTL(transpileForServer_compile, compile);
          temp tempSetTL(transpileRaw_asInclude, isInclude);
          transpileForServer(snippetID);
          ok.raise();
        }
      });
      
      S redirect = params.get('redirect);
      
      /*sendToSnippetUpdatesBot("/transpile" + (ok.isUp() ? "OK" : "Fail") 
        + "/" + psI(params.get('snippetID)));*/
      
      ret hhtml(hhead(htitle((ok.isUp() ? "OK" : "Failed") + " Transpilation")
        + (ok.isUp() && nempty(redirect) ? hrefresh(refreshDelay, redirect) : ""))
        + hbody(hsourcecode(text)));
    });
  }
}

Author comment

Began life as a copy of #1018308

download  show line numbers  debug dex   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, xrpafgyirdlv

No comments. add comment

Snippet ID: #1028676
Snippet name: Snippet Transpiler Web Bot [Dyn Module]
Eternal ID of this version: #1028676/8
Text MD5: 6be11ed2cb7c684aaa82a83ef1028ada
Transpilation MD5: 33d88752355682fadd7cb5572aa9797d
Author: stefan
Category: javax / web
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-08-11 15:22:15
Source code size: 2125 bytes / 62 lines
Pitched / IR pitched: No / No
Views / Downloads: 71 / 131
Version history: 7 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1028676 & http://1028676.tinybrain.de