// 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);
}