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

36
LINES

< > BotCompany Repo | #1017992 // Static Pages Bot

JavaX source code (desktop) [tags: butter use-pretranspiled] - run with: x30.jar - homepage

Download Jar. Libraryless. Click here for Pure Java version (5344L/30K).

// hosts .html and .txt

!7

static File dir;

p { dir = javaxDataDir("Static Web Pages"); }

html {
  uri = dropSlashPrefix(uri);
  
  if (eq(uri, "upload")) {
    S text = params.get("text");
    S name;
    
    if (text != null) {
      name = uniqueFileNameUsingMD5_80_v2(text, md5(text)) + ".txt";
      saveTextFile(newFile(dir, name), text);
    } else {
      S html = params.get("html");
      S title = dropAllTags(html);
      name = uniqueFileNameUsingMD5_80_v2(title, md5(html)) + ".html";
      saveTextFile(newFile(dir, name), html);
    }
    ret "Saved as: " + ahref(rawSelfLink(urlencode(name)), name);
  }
  
  if (empty(uri)) ret "Static pages bot";
  
  S name = urldecode(uri);
  if (!isProperFileName_allowSpaces(name))
    ret subBot_serve404("Invalid file name");
    
  File f = newFile(dir, name);
  ret serveTextOrHTML(f);
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1017992
Snippet name: Static Pages Bot
Eternal ID of this version: #1017992/12
Text MD5: add15614bc0452d98a137994cdb63c0c
Transpilation MD5: aecbe9e0f4aea59af69019981a1af9bd
Author: stefan
Category: javax / web bots
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-09-23 00:18:32
Source code size: 888 bytes / 36 lines
Pitched / IR pitched: No / No
Views / Downloads: 496 / 1942
Version history: 11 change(s)
Referenced in: #1013896 - Eleutheria Main for butter.botcompany.de + Stefan's OS (LIVE)
#1017994 - uploadToStaticPagesBot - returns URL
#1024026 - Eleutheria Main for butter.botcompany.de (backup without Stefan's OS)
#1032567 - uploadText