#!/bin/env tclsh
package require logger
package require json
package require json::write
package require sqlite3
package require inifile
package require sha1
source src/config.tcl
source src/at.tcl
source src/ws.tcl
source src/jetstream.tcl
source src/httpd.tcl
source src/feed.tcl
source src/algos.tcl
set log [logger::init tclfeed]
${log}::info "tclfeed v0.0.1"
### DB STUFF ###
sqlite3 db [::ini::value $config database path]
foreach algo $::algos::list {
db eval {SELECT count(*) as n FROM sqlite_master WHERE name=$algo;} values {
if ![set values(n)] {
${log}::info "Creating table \"$algo\"!"
if [info exists ::algos::${algo}::cols] {
db eval "CREATE TABLE $algo (uri TEXT NOT NULL PRIMARY KEY, ord TEXT NOT NULL, [set ::algos::${algo}::cols]);"
} else {
db eval "CREATE TABLE $algo (uri TEXT NOT NULL PRIMARY KEY, ord TEXT NOT NULL);"
}
}
}
}
### JETSTREAM ###
jetstream::listen [::ini::value $config atproto jetstream_host] $::algos::list
### HTTPD ###
httpd::router main [list \
/xrpc/app.bsky.feed.getFeedSkeleton [list ::feed::serve_skeleton $::algos::list] \
]
httpd::listen main 3000
vwait nil