mirror of
https://github.com/hoytech/strfry.git
synced 2025-06-18 17:27:11 +00:00
allow writePolicy plugins to filter events downloaded via sync
This commit is contained in:
@ -9,7 +9,6 @@
|
||||
#include "Subscription.h"
|
||||
#include "WSConnection.h"
|
||||
#include "events.h"
|
||||
|
||||
#include "PluginWritePolicy.h"
|
||||
|
||||
|
||||
@ -76,7 +75,6 @@ void cmd_stream(const std::vector<std::string> &subArgs) {
|
||||
} else {
|
||||
LI << "[" << ws.remoteAddr << "] write policy blocked event " << evJson.at("id").get_string() << ": " << okMsg;
|
||||
}
|
||||
|
||||
} else {
|
||||
LW << "Unexpected EVENT";
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "DBQuery.h"
|
||||
#include "filters.h"
|
||||
#include "events.h"
|
||||
#include "PluginWritePolicy.h"
|
||||
|
||||
|
||||
static const char USAGE[] =
|
||||
@ -73,6 +74,9 @@ void cmd_sync(const std::vector<std::string> &subArgs) {
|
||||
|
||||
WriterPipeline writer;
|
||||
WSConnection ws(url);
|
||||
PluginWritePolicy writePolicy;
|
||||
|
||||
|
||||
ws.reconnect = false;
|
||||
|
||||
ws.onConnect = [&]{
|
||||
@ -128,7 +132,16 @@ void cmd_sync(const std::vector<std::string> &subArgs) {
|
||||
LW << "Unable to upload event " << msg.at(1).get_string() << ": " << msg.at(3).get_string();
|
||||
}
|
||||
} else if (msg.at(0) == "EVENT") {
|
||||
writer.write({ std::move(msg.at(2)), EventSourceType::Sync, url });
|
||||
if (msg.get_array().size() < 3) throw herr("array too short");
|
||||
auto &evJson = msg.at(2);
|
||||
|
||||
std::string okMsg;
|
||||
auto res = writePolicy.acceptEvent(evJson, hoytech::curr_time_s(), EventSourceType::Sync, ws.remoteAddr, okMsg);
|
||||
if (res == WritePolicyResult::Accept) {
|
||||
writer.write({ std::move(evJson), EventSourceType::Sync, url });
|
||||
} else {
|
||||
LI << "[" << ws.remoteAddr << "] write policy blocked event " << evJson.at("id").get_string() << ": " << okMsg;
|
||||
}
|
||||
} else if (msg.at(0) == "EOSE") {
|
||||
inFlightDown = false;
|
||||
writer.wait();
|
||||
|
Reference in New Issue
Block a user