mirror of
https://github.com/hoytech/strfry.git
synced 2025-06-19 17:37:43 +00:00
wip
This commit is contained in:
44
src/apps/web/FeedReader.h
Normal file
44
src/apps/web/FeedReader.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
struct FeedReader {
|
||||||
|
struct EventInfo {
|
||||||
|
uint64_t comments = 0;
|
||||||
|
double score = 0.0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FeedEvent {
|
||||||
|
uint64_t levId;
|
||||||
|
std::string id;
|
||||||
|
|
||||||
|
EventInfo info;
|
||||||
|
};
|
||||||
|
|
||||||
|
tao::json::value feedJson;
|
||||||
|
|
||||||
|
FeedReader(lmdb::txn &txn, const std::string &feedId) {
|
||||||
|
size_t pos = feedId.find(".");
|
||||||
|
if (pos == std::string_view::npos) throw herr("bad feedId");
|
||||||
|
std::string pubkey = FeedId.substr(0, pos);
|
||||||
|
std::string adminTopic = feedId.substr(pos + 1);
|
||||||
|
|
||||||
|
tao::json::value filter = tao::json::value({
|
||||||
|
{ "authors", tao::json::value::array({ to_hex(authorPubkey) }) },
|
||||||
|
{ "kinds", tao::json::value::array({ uint64_t(33800) }) },
|
||||||
|
{ "#d", tao::json::value::array({ adminTopic }) },
|
||||||
|
});
|
||||||
|
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
|
foreachByFilter(txn, filter, [&](uint64_t levId){
|
||||||
|
feedJson = tao::json::from_string(getEventJson(txn, decomp, levId));
|
||||||
|
found = true;
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!found) throw herr("unable to lookup feedId: ", feedId);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<FeedEvent> getEvents(lmdb::txn &txn, Decompressor &decomp) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
};
|
@ -94,9 +94,9 @@ void doSearch(lmdb::txn &txn, Decompressor &decomp, std::string_view search, std
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
TemplarResult renderCommunityEvents(lmdb::txn &txn, Decompressor &decomp, UserCache &userCache, const CommunitySpec &communitySpec) {
|
TemplarResult renderFeed(lmdb::txn &txn, Decompressor &decomp, UserCache &userCache, const std::string &feedId) {
|
||||||
AlgoScanner a(txn, communitySpec.algo);
|
FeedReader feedReader(txn, feedId);
|
||||||
auto events = a.getEvents(txn, decomp, 60);
|
auto events = feedReader.getEvents(txn, decomp);
|
||||||
|
|
||||||
std::vector<TemplarResult> rendered;
|
std::vector<TemplarResult> rendered;
|
||||||
auto now = hoytech::curr_time_s();
|
auto now = hoytech::curr_time_s();
|
||||||
@ -120,11 +120,11 @@ TemplarResult renderCommunityEvents(lmdb::txn &txn, Decompressor &decomp, UserCa
|
|||||||
fe.info,
|
fe.info,
|
||||||
};
|
};
|
||||||
|
|
||||||
rendered.emplace_back(tmpl::community::item(ctx));
|
rendered.emplace_back(tmpl::feed::item(ctx));
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return tmpl::community::list(rendered);
|
return tmpl::feed::list(rendered);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -148,32 +148,16 @@ HTTPResponse WebServer::generateReadResponse(lmdb::txn &txn, Decompressor &decom
|
|||||||
// Normal frame:
|
// Normal frame:
|
||||||
|
|
||||||
std::optional<TemplarResult> body;
|
std::optional<TemplarResult> body;
|
||||||
std::optional<CommunitySpec> communitySpec;
|
|
||||||
std::string title;
|
std::string title;
|
||||||
|
|
||||||
// Or, raw:
|
// Or, raw:
|
||||||
|
|
||||||
std::optional<std::string> rawBody;
|
std::optional<std::string> rawBody;
|
||||||
|
|
||||||
if (u.path.size() == 0 || u.path[0] == "algo") {
|
|
||||||
communitySpec = lookupCommunitySpec(txn, decomp, userCache, cfg().web__homepageCommunity);
|
|
||||||
httpResp.extraHeaders += "Cache-Control: max-age=600\r\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (u.path.size() == 0) {
|
if (u.path.size() == 0) {
|
||||||
body = renderCommunityEvents(txn, decomp, userCache, *communitySpec);
|
body = renderFeed(txn, decomp, userCache, cfg().web__homepageFeedId);
|
||||||
} else if (u.path[0] == "algo") {
|
|
||||||
struct {
|
|
||||||
std::string community;
|
|
||||||
const CommunitySpec &communitySpec;
|
|
||||||
std::string_view descriptor;
|
|
||||||
} ctx = {
|
|
||||||
"homepage",
|
|
||||||
*communitySpec,
|
|
||||||
cfg().web__homepageCommunity,
|
|
||||||
};
|
|
||||||
|
|
||||||
body = tmpl::community::communityInfo(ctx);
|
httpResp.extraHeaders += "Cache-Control: max-age=600\r\n";
|
||||||
} else if (u.path[0] == "e") {
|
} else if (u.path[0] == "e") {
|
||||||
if (u.path.size() == 2) {
|
if (u.path.size() == 2) {
|
||||||
EventThread et(txn, decomp, decodeBech32Simple(u.path[1]));
|
EventThread et(txn, decomp, decodeBech32Simple(u.path[1]));
|
||||||
@ -320,7 +304,6 @@ HTTPResponse WebServer::generateReadResponse(lmdb::txn &txn, Decompressor &decom
|
|||||||
|
|
||||||
struct {
|
struct {
|
||||||
const TemplarResult &body;
|
const TemplarResult &body;
|
||||||
const std::optional<CommunitySpec> &communitySpec;
|
|
||||||
std::string_view title;
|
std::string_view title;
|
||||||
std::string staticFilesPrefix;
|
std::string staticFilesPrefix;
|
||||||
std::string_view staticOddbeanCssHash;
|
std::string_view staticOddbeanCssHash;
|
||||||
@ -328,7 +311,6 @@ HTTPResponse WebServer::generateReadResponse(lmdb::txn &txn, Decompressor &decom
|
|||||||
std::string_view staticOddbeanSvgHash;
|
std::string_view staticOddbeanSvgHash;
|
||||||
} ctx = {
|
} ctx = {
|
||||||
*body,
|
*body,
|
||||||
communitySpec,
|
|
||||||
title,
|
title,
|
||||||
cfg().web__staticFilesPrefix.size() ? cfg().web__staticFilesPrefix : "/static",
|
cfg().web__staticFilesPrefix.size() ? cfg().web__staticFilesPrefix : "/static",
|
||||||
oddbeanStatic__oddbean_css__hash().substr(0, 16),
|
oddbeanStatic__oddbean_css__hash().substr(0, 16),
|
||||||
|
@ -7,8 +7,8 @@ config:
|
|||||||
desc: "Port to open for the http protocol"
|
desc: "Port to open for the http protocol"
|
||||||
default: 8080
|
default: 8080
|
||||||
noReload: true
|
noReload: true
|
||||||
- name: web__homepageCommunity
|
- name: web__homepageFeedId
|
||||||
desc: "Community descriptor for homepage"
|
desc: "Homepage Feed ID (pubkey/feedName)"
|
||||||
default: ""
|
default: ""
|
||||||
- name: web__staticFilesPrefix
|
- name: web__staticFilesPrefix
|
||||||
desc: "URL or relative path prefix to use for static files (empty string to use versions embedded in binary)"
|
desc: "URL or relative path prefix to use for static files (empty string to use versions embedded in binary)"
|
||||||
|
Reference in New Issue
Block a user