Skip to content

Commit 44a2e58

Browse files
committed
web wip
1 parent f31a1b9 commit 44a2e58

40 files changed

+7762
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/build/
2+
/dist/
23
*.d
34
*.o
45
/strfry

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
BIN ?= strfry
2-
APPS ?= dbutils relay mesh
2+
APPS ?= dbutils relay mesh web
33
OPT ?= -O3 -g
44

55
include golpe/rules.mk

golpe

pkg/build.pl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env perl
2+
3+
use strict;
4+
5+
use lib 'golpe/';
6+
use BuildLib;
7+
8+
9+
my $version = `git describe --tags 2>/dev/null` || die "couldn't get version";
10+
11+
12+
BuildLib::fpm({
13+
types => [qw/ deb /],
14+
name => 'strfry',
15+
version => $version,
16+
description => 'strfry',
17+
files => {
18+
'strfry' => '/usr/local/bin/strfry',
19+
},
20+
dirs => {
21+
},
22+
config_files => [
23+
],
24+
# -dev packages so we don't have to hard-code ABI versions
25+
deps => [qw/
26+
zlib1g
27+
libssl-dev
28+
liblmdb-dev
29+
libflatbuffers-dev
30+
libsecp256k1-dev
31+
libzstd-dev
32+
libre2-dev
33+
systemd-coredump
34+
/],
35+
});

src/apps/web/HTTP.h

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#pragma once
2+
3+
#include <zlib.h>
4+
#include <openssl/sha.h>
5+
6+
#include <mutex>
7+
8+
9+
10+
struct HTTPRequest : NonCopyable {
11+
uint64_t connId;
12+
uWS::HttpResponse *res;
13+
14+
std::string ipAddr;
15+
std::string url;
16+
uWS::HttpMethod method = uWS::HttpMethod::METHOD_INVALID;
17+
bool acceptGzip = false;
18+
19+
std::string body;
20+
21+
HTTPRequest(uint64_t connId, uWS::HttpResponse *res, uWS::HttpRequest req) : connId(connId), res(res) {
22+
res->hasHead = true; // We'll be sending our own headers
23+
24+
ipAddr = res->httpSocket->getAddressBytes();
25+
method = req.getMethod();
26+
url = req.getUrl().toString();
27+
acceptGzip = req.getHeader("accept-encoding").toStringView().find("gzip") != std::string::npos;
28+
}
29+
};
30+
31+
32+
struct HTTPResponse : NonCopyable {
33+
std::string_view code = "200 OK";
34+
std::string_view contentType = "text/html; charset=utf-8";
35+
std::string extraHeaders;
36+
std::string body;
37+
bool noCompress = false;
38+
39+
std::string getETag() {
40+
unsigned char hash[SHA256_DIGEST_LENGTH];
41+
SHA256(reinterpret_cast<unsigned char*>(body.data()), body.size(), hash);
42+
return to_hex(std::string_view(reinterpret_cast<char*>(hash), SHA256_DIGEST_LENGTH/2));
43+
}
44+
45+
std::string encode(bool doCompress) {
46+
std::string eTag = getETag();
47+
48+
std::string compressed;
49+
bool didCompress = false;
50+
51+
if (!noCompress && doCompress) {
52+
compressed.resize(body.size());
53+
54+
z_stream zs;
55+
zs.zalloc = Z_NULL;
56+
zs.zfree = Z_NULL;
57+
zs.opaque = Z_NULL;
58+
zs.avail_in = body.size();
59+
zs.next_in = (Bytef*)body.data();
60+
zs.avail_out = compressed.size();
61+
zs.next_out = (Bytef*)compressed.data();
62+
63+
deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 15 + 16, 8, Z_DEFAULT_STRATEGY);
64+
auto ret1 = deflate(&zs, Z_FINISH);
65+
auto ret2 = deflateEnd(&zs);
66+
67+
if (ret1 == Z_STREAM_END && ret2 == Z_OK) {
68+
compressed.resize(zs.total_out);
69+
didCompress = true;
70+
}
71+
}
72+
73+
auto bodySize = didCompress ? compressed.size() : body.size();
74+
75+
std::string output;
76+
output.reserve(bodySize + 1024);
77+
78+
output += "HTTP/1.1 ";
79+
output += code;
80+
output += "\r\nContent-Length: ";
81+
output += std::to_string(bodySize);
82+
output += "\r\nContent-Type: ";
83+
output += contentType;
84+
output += "\r\nETag: \"";
85+
output += eTag;
86+
output += "\"\r\n";
87+
if (didCompress) output += "Content-Encoding: gzip\r\nVary: Accept-Encoding\r\n";
88+
output += extraHeaders;
89+
output += "Connection: Keep-Alive\r\n\r\n";
90+
output += didCompress ? compressed : body;
91+
92+
return output;
93+
}
94+
};

src/apps/web/README

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
no:
2+
* slow loading
3+
* burning client CPU
4+
* wasting bandwidth
5+
* images
6+
* cookie warning crap
7+
* pop-ups that come up when you scroll half way down
8+
* re-rendering, re-flowing, bouncing around of the page after you started reading
9+
* breaking back button
10+
* messing with scrolling
11+
* breaking when JS disabled

src/apps/web/TODO

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
release
2+
- whitelabeling of website, merge to master
3+
- docs
4+
- flag/moderation support
5+
- improve homepage algo
6+
- if nostr:npub1... appears in note content when users is posting, add it as p-tag "mention"
7+
- same with #tags
8+
9+
read
10+
- search field: enter anything, pubkey (hex or npub), eventId, etc. maybe even full-text search?
11+
- click on up/down vote counts to see who voted
12+
- nip-05 checkmarks
13+
14+
styling
15+
! user comments aren't sorted in timestamp descending?
16+
! make login/upvote/etc buttons do something when not logged in/no nostr plugin installed
17+
? slightly grey out visited links
18+
? limit name length: http://localhost:8080/u/npub1e44hczvjqvnp5shx9tmapmw5w6q9x98wdrd2lxhmwfsdmuf5gp9qwvpk6g
19+
? smarter truncation/abbrev (try to cut at a sentence, or word boundary, don't cut URLs)
20+
? abbrev comments should be smaller? non-pre tag?
21+
? slightly grey out visited links
22+
23+
write
24+
? edit your profile (or maybe just send them to https://metadata.nostr.com/)

0 commit comments

Comments
 (0)