Jason Staten 4 weeks ago
parent e8b15338a6
commit 134980cc98
  1. 30
      database.go
  2. 3
      flake.nix
  3. 10
      preflight.sh
  4. 45
      web.go

@ -1091,6 +1091,30 @@ func cleanupdb(arg string) {
}
}
func getusercount() int {
row := stmtGetUserCount.QueryRow()
var count int
row.Scan(&count)
return count
}
func getactiveusercount(monthsago int) int {
origin := time.Now().AddDate(0, -monthsago, 0).UTC().Format(dbtimeformat)
row := stmtGetActiveUserCount.QueryRow(origin)
var count int
row.Scan(&count)
return count
}
func getlocalhonkcount() int {
row := stmtGetLocalHonkCount.QueryRow()
var count int
row.Scan(&count)
return count
}
var stmtHonkers, stmtDubbers, stmtNamedDubbers, stmtSaveHonker, stmtUpdateFlavor, stmtUpdateHonker *sql.Stmt
var stmtDeleteHonker *sql.Stmt
var stmtAnyXonk, stmtOneXonk, stmtPublicHonks, stmtUserHonks, stmtHonksByCombo, stmtHonksByConvoy *sql.Stmt
@ -1109,6 +1133,9 @@ var stmtSaveMeta, stmtDeleteAllMeta, stmtDeleteOneMeta, stmtDeleteSomeMeta, stmt
var stmtHonksISaved, stmtGetFilters, stmtSaveFilter, stmtDeleteFilter *sql.Stmt
var stmtGetTracks *sql.Stmt
var stmtSaveChonk, stmtLoadChonks, stmtGetChatters *sql.Stmt
var stmtGetUserCount *sql.Stmt
var stmtGetActiveUserCount *sql.Stmt
var stmtGetLocalHonkCount *sql.Stmt
func preparetodie(db *sql.DB, s string) *sql.Stmt {
stmt, err := db.Prepare(s)
@ -1194,4 +1221,7 @@ func prepareStatements(db *sql.DB) {
stmtSaveChonk = preparetodie(db, "insert into chonks (userid, xid, who, target, dt, noise, format) values (?, ?, ?, ?, ?, ?, ?)")
stmtLoadChonks = preparetodie(db, "select chonkid, userid, xid, who, target, dt, noise, format from chonks where userid = ? and dt > ? order by chonkid asc")
stmtGetChatters = preparetodie(db, "select distinct(target) from chonks where userid = ?")
stmtGetUserCount = preparetodie(db, "select count(*) from users where userid > 0")
stmtGetActiveUserCount = preparetodie(db, "select count(distinct honker) from honks where whofore = 2 and dt > ?")
stmtGetLocalHonkCount = preparetodie(db, "select count(*) from honks where whofore = 2")
}

@ -24,7 +24,8 @@
in {
devShell = pkgs.mkShell {
buildInputs = with pkgs; [ go gopls gotools go-tools golangci-lint];
CFLAGS="-I${pkgs.sqlite.dev}/include";
buildInputs = with pkgs; [ go gopls gotools go-tools golangci-lint sqlite];
};
defaultPackage = pkgs.buildGoModule {

@ -9,11 +9,11 @@ if [ "$v" \< "go1.16" ] ; then
false
fi
if [ \! \( -e /usr/include/sqlite3.h -o -e /usr/local/include/sqlite3.h \) ] ; then
echo unable to find sqlite3.h header
echo please install libsqlite3 dev package
false
fi
# if [ \! \( -e /usr/include/sqlite3.h -o -e /usr/local/include/sqlite3.h \) ] ; then
# echo unable to find sqlite3.h header
# echo please install libsqlite3 dev package
# false
# fi
touch .preflightcheck

@ -2098,6 +2098,49 @@ func fingerlicker(w http.ResponseWriter, r *http.Request) {
j.Write(w)
}
func knowninformation(w http.ResponseWriter, r *http.Request) {
j := junk.New()
l := junk.New()
l["type"] = `http://nodeinfo.diaspora.software/ns/schema/2.0`
l["href"] = fmt.Sprintf("https://%s/nodeinfo/2.0", serverName)
j["links"] = []junk.Junk{l}
w.Header().Set("Content-Type", "application/json")
j.Write(w)
}
func actualinformation(w http.ResponseWriter, r *http.Request) {
j := junk.New()
soft := junk.New()
soft["name"] = "honk"
soft["version"] = softwareVersion
services := junk.New()
services["inbound"] = []string{}
services["outbound"] = []string{"rss2.0"}
users := junk.New()
users["total"] = getusercount()
users["activeHalfyear"] = getactiveusercount(6)
users["activeMonth"] = getactiveusercount(1)
usage := junk.New()
usage["users"] = users
usage["localPosts"] = getlocalhonkcount()
j["version"] = "2.0"
j["protocols"] = []string{"activitypub"}
j["software"] = soft
j["services"] = services
j["openRegistrations"] = false
j["usage"] = usage
w.Header().Set("Content-Type", "application/json")
j.Write(w)
}
func somedays() string {
secs := 432000 + notrand.Int63n(432000)
return fmt.Sprintf("%d", secs)
@ -2498,6 +2541,8 @@ func serve() {
getters.HandleFunc("/emu/{emu:[^.]*[^/]+}", serveemu)
getters.HandleFunc("/meme/{meme:[^.]*[^/]+}", servememe)
getters.HandleFunc("/.well-known/webfinger", fingerlicker)
getters.HandleFunc("/.well-known/nodeinfo", knowninformation)
getters.HandleFunc("/nodeinfo/2.0", actualinformation)
getters.HandleFunc("/flag/{code:.+}", showflag)

Loading…
Cancel
Save