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

99
LINES

< > BotCompany Repo | #1023660 // agi.blue source (backup from when it was still 99 lines!)

JavaX module (desktop) [tags: use-pretranspiled]

Download Jar. Libraryless. Click here for Pure Java version (13128L/91K).

1  
!7
2  
3  
concept Page { S url; long modified = now(); void change { modified = now(); super.change(); } }
4  
concept Entry { new Ref<Page> page; int count; S key, value; S ip; }
5  
6  
static int lines;
7  
sbool allowMultipleCasesInValues = true;
8  
9  
p {
10  
  dbIndexingCI(Page, 'url, Entry, 'key, Entry, 'value);
11  
  //for (Page p) if (!isAGIDomain(dropAfterSlash(p.url))) p.delete();
12  
  lines = countLines(mySource());
13  
}
14  
15  
sS getValue(Page page, S key) {
16  
  ret getString value(highestByField count(objectsWhereIC(findBackRefs(page, Entry), +key)));
17  
}
18  
sS pageDisplayName(Page page) {
19  
  S name = getValue(page, "read as");
20  
  bool unnaturalName = nempty(name) && !eq(makeAGIDomain(name), page.url);
21  
  ret unnaturalName ? name + " " + squareBracketed(page.url) : or2(name, unpackAGIDomainOpt(page.url));
22  
}
23  
24  
set flag NoNanoHTTPD. html {
25  
  S q = params.get('q);
26  
  S domain = or2(params.get('domain), domain());
27  
  if (nempty(q)) {
28  
    domain = makeAGIDomain(q);
29  
    if (l(domain) > maximumDomainPartLength()) // escape with "domain="
30  
      ret hrefresh("http://agi.blue/" + hquery(+domain, key := "read as", value := q));
31  
    ret hrefresh("http://" + domain + (eq(q, domain) ? "" : "/" +  hquery(key := "read as", value := q)));
32  
    //uri = "/"; replaceMapWithParams(params, key := "read as", value := q);
33  
  }
34  
  S url = domain + dropTrailingSlash(uri);
35  
  Page page, bool newPage = unpair uniqCI2_sync(Page, +url);
36  
37  
  S top = p(ahref("http://agi.blue", hsnippetimg(#1101682, width := 565/5, height := 800/5, title := "Robot by Peerro @ DeviantArt")))
38  
      + p(small(b(ahref("http://agi.blue", "agi.blue"))
39  
      + " | " + targetBlank(progLink(), "source code") + " of this web site (" + nLines(lines) + ") | " + targetBlank("https://gitter.im/agi-blue/community", "sponsor https?") + " | by " + targetBlank("https://BotCompany.de", "BC") + " | " + targetBlank("http://fiverr.tinybrain.de/", "Fiverr") + " | " + targetBlank("https://discordapp.com/invite/SEAjPqk", "Discord")));
40  
  
41  
  if (eqicOneOf(url, "agi.blue", "www.agi.blue"))
42  
    ret hhtml(hhead_title("agi.blue Overview") // HOME PAGE
43  
      + hbody_fullcenter(top
44  
        + hform(b("GIVE ME INPUT:") + "<br><br>" + htextinput('q) + " " + hsubmit("Ask"))
45  
        + h1("agi.blue has " + nPages(countConcepts(Page)))
46  
        + p(nlToBr(nemptyLines(map(func(Page p) -> S {
47  
          ahref(fixAGILink("http://" + p.url), htmlEncode2(pageDisplayName(p)))
48  
        }, sortedByFieldDesc modified(list(Page))))))
49  
      ));
50  
      
51  
  S key = trim(params.get('key)), value = trim(params.get('value));
52  
  L<Entry> entries = withDBLock(func -> L<Entry> {
53  
    L<Entry> entries = findBackRefs(page, Entry);
54  
    print("Entries: " + l(entries));
55  
    if (nempty(key) && nempty(value)) {
56  
      S ip = subBot_clientIP();
57  
      if (!any(e -> eqic(e.key, key) && eq_icIf(!allowMultipleCasesInValues, e.value, value) && eq(e.ip, ip), entries)) {
58  
        print("SAVING");
59  
        entries.add(cnew Entry(+page, +key, +value, +ip, count := l(entries) + 1));
60  
      }
61  
    }
62  
    ret entries;
63  
  });
64  
65  
  sortByFieldInPlace created(entries);
66  
  numberEntriesInConceptField count(entries);
67  
  
68  
  S get = params.get('get);
69  
  if (nempty(get))
70  
    ret serveText(jsonEncode(collect value(llNotNulls(firstWhereIC(entries, key := get)))));
71  
  
72  
  S key2 = key, value2 = value; if (nempty(key) && nempty(value)) key2 = value2 = ""; // input reset
73  
74  
  bool withHidden = eq(params.get('withHidden), "1");
75  
  new Set<Int> hide;
76  
  if (!withHidden) for (Entry e : entries) if (eqic(e.key, 'hide) && isSquareBracketedInt(e.value)) addAll(hide, e.count, parseInt(unSquareBracket(e.value)));
77  
  new MultiMap<Int, S> mmMeta;
78  
  for (Entry e : entries) if (isSquareBracketedInt(e.key)) mmMeta.put(parseInt(unSquareBracket(e.key)), e.value);
79  
  new MultiMap<S> mm;
80  
  for (Entry e : entries) mm.put(e.key, e.value);
81  
  
82  
  S name = or2(/* ouch */ last(mm.get("read as")), /* end ouch */ unpackAGIDomain(page.url), page.url);
83  
  
84  
  ret hhtml(hhead_title(pageDisplayName(page)) + hbody(hfullcenterAndTopRight(
85  
      top + h1(ahref_unstyled("http://" + url, htmlEncode2(name)) + (newPage ? " [huh????]" : ""))
86  
    + p(nlToBr(nemptyLines(map(entries, func(Entry e) -> S {
87  
      !withHidden && (hide.contains(e.count) || eqic(e.key, "read as") && eqic(e.value, name)) ? "" : "[" + e.count + "] " +
88  
      htmlencode2(e.key) + ": " + b(
89  
        isURL(e.value)
90  
        || cic(mmMeta.get(e.count), "is a URL")
91  
        || isAGIDomain(e.value)
92  
          ? ahref(fixAGILink(absoluteURL(e.value)), htmlencode2(e.value))
93  
          : ahref(agiBlue_linkForPhrase(e.value), htmlencode2(e.value))
94  
      ) }))))
95  
    + hpostform(h3("Add an entry")
96  
      + "Key: " + hinputfield(key := key2) + " Value: " + hinputfield(value := value2) + "<br><br>" + hsubmit("Add")
97  
      )
98  
    , hform(b("GIVE ME INPUT:") + " " + htextinput('q) + " " + hsubmit("Ask")))));
99  
}

Author comment

Began life as a copy of #1023558

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1023660
Snippet name: agi.blue source (backup from when it was still 99 lines!)
Eternal ID of this version: #1023660/1
Text MD5: c740bba8b05f2901e788eb89848786d3
Transpilation MD5: 7ac374b63d5d3550d849a93a0363ded6
Author: stefan
Category: javax / html
Type: JavaX module (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-07-01 13:01:10
Source code size: 4891 bytes / 99 lines
Pitched / IR pitched: No / No
Views / Downloads: 348 / 1771
Referenced in: [show references]