- WebFinger: detect when to use http or https, better function naming - RequestPool: add user agent
111 lines
2.0 KiB
D
111 lines
2.0 KiB
D
module main;
|
|
|
|
import std.json;
|
|
|
|
import requests;
|
|
import slf4d;
|
|
import slf4d.default_provider;
|
|
|
|
import config;
|
|
import singletons;
|
|
import db.db;
|
|
import net.request_pool;
|
|
import webfinger;
|
|
import ap.actor;
|
|
import ap.util;
|
|
import std.math.remainder;
|
|
import util;
|
|
|
|
void commonInit() {
|
|
auto provider = new DefaultProvider(true, Levels.DEBUG);
|
|
configureLoggingProvider(provider);
|
|
|
|
Config cfg = loadConfig();
|
|
initRequestPool(cfg);
|
|
initDatabase(cfg);
|
|
}
|
|
|
|
Config loadConfig() {
|
|
Config cfg = new Config();
|
|
cfg.load();
|
|
return cfg;
|
|
}
|
|
|
|
void initRequestPool(Config cfg) {
|
|
Rp = new RequestPool();
|
|
Rp.startBackground();
|
|
}
|
|
|
|
void initDatabase(Config cfg) {
|
|
Db = new DB(DBSettings.fromJson(cfg.v["db"]));
|
|
Db.connect();
|
|
}
|
|
|
|
void main() {
|
|
commonInit();
|
|
|
|
scope (exit) {
|
|
Db.close();
|
|
Rp.stop();
|
|
}
|
|
|
|
generateRSA();
|
|
return;
|
|
|
|
Actor marisa = apResolveRemoteUsername("@admin@localhost:8080");
|
|
infoF!"Actor type: %s"(marisa.type);
|
|
infoF!"Actor preferredUsername: %s"(marisa.preferredUsername);
|
|
infoF!"Actor sharedInbox: %s"(marisa.endpoints.sharedInbox);
|
|
|
|
PRequest followers = PRequest();
|
|
|
|
with (followers) {
|
|
url = marisa.followers;
|
|
headers["Accept"] = "application/activity+json";
|
|
}
|
|
|
|
Response rs = Rp.request(followers, true);
|
|
infoF!"followers: %s"(rs.responseBody);
|
|
}
|
|
|
|
//int main() {
|
|
// auto provider = new DefaultProvider(true, Levels.DEBUG);
|
|
// configureLoggingProvider(provider);
|
|
//
|
|
// Config cfg = new Config();
|
|
//
|
|
// try {
|
|
// cfg.load();
|
|
// } catch (Exception e) {
|
|
// error(e);
|
|
// return 21;
|
|
// }
|
|
//
|
|
// DBSettings dbSettings;
|
|
// auto dbCfg = cfg.v["db"];
|
|
// with (dbSettings) {
|
|
// host = dbCfg["host"].str;
|
|
// port = cast(ushort) dbCfg["port"].integer;
|
|
// username = dbCfg["username"].str;
|
|
// password = dbCfg["password"].str;
|
|
// dbname = dbCfg["dbName"].str;
|
|
//
|
|
// switch (dbCfg["connector"].str) {
|
|
// case "postgresql":
|
|
// connector = DBConnector.DB_PGSQL;
|
|
// break;
|
|
// default:
|
|
// break;
|
|
// }
|
|
// }
|
|
//
|
|
// Db = new DB(dbSettings);
|
|
// Db.connect();
|
|
//
|
|
// scope (exit)
|
|
// Db.close();
|
|
//
|
|
// return 0;
|
|
//}
|
|
//
|