diff --git a/.gitignore b/.gitignore index e07730e..c3ac906 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ ipfs.html about.html copyright.html torrent_dump_full.csv.gz -generate-top-torrents \ No newline at end of file +generate-top-torrents +api/api \ No newline at end of file diff --git a/api/README.md b/api/README.md new file mode 100644 index 0000000..8687ee5 --- /dev/null +++ b/api/README.md @@ -0,0 +1,29 @@ +Expecting a future where clickstream data are more and more important, because ranking will be moving from strict keyword based seeders sorted to fuzzy matching with machine learned sorting, I'll be adding limited anonymized telemetry to Torrent Paradise. + +## Telemetry collected after searching +- query +- session id + - required to find out if this is a followup query (after not being able to find results with a previous query) or a first + - pseudorandom identifier generated on each visit, not persisted across browser tabs +- action # + - needed to find the order of actions + +## Telemetry collected after clicking magnet link +- infohash +- query (once again) +- torrent name +- seeders +- leechers +- torrent size +- session id +- action # +- rank # +- screen resolution + - expected to be critical for ranking of video +- User Agent + - expected to be critical for ranking of software +- language + - could help for ranking video, might predict internet speed and thus required file size + + +Your IP address is never logged. Telemetry is always sent encrypted. HTTPS is terminated at the caddy web server. \ No newline at end of file diff --git a/api/api.service b/api/api.service new file mode 100644 index 0000000..13a799c --- /dev/null +++ b/api/api.service @@ -0,0 +1,13 @@ +[Unit] +Description=Torrent Paradise API service +Requires=postgresql + +[Service] +User=nextgen +WorkingDirectory=/home/nextgen +ExecStart=/home/nextgen/api +Restart=always +RestartSec=30 + +[Install] +WantedBy=multi-user.target diff --git a/api/main.go b/api/main.go new file mode 100644 index 0000000..38d2549 --- /dev/null +++ b/api/main.go @@ -0,0 +1,45 @@ +package main + +import ( + "database/sql" + "log" + "io/ioutil" + "net/http" + + _ "github.com/lib/pq" +) + +func initDb() *sql.DB { + connStr := "user=nextgen dbname=nextgen host=/var/run/postgresql" + db, err := sql.Open("postgres", connStr) + if err != nil { + log.Fatal(err) + } + + _, err = db.Exec(`CREATE TABLE IF NOT EXISTS telemetry ( + payload jsonb NOT NULL, + time timestamp DEFAULT current_timestamp + )`) + if err != nil { + log.Fatal(err) + } + return db +} + +func main() { + db := initDb() + + http.HandleFunc("/api/telemetry", func (w http.ResponseWriter, r *http.Request) { + body, err := ioutil.ReadAll(r.Body) + if err != nil{ + log.Print(err) + } + _, err = db.Exec("INSERT INTO telemetry (payload) VALUES ($1)", string(body)) + if err != nil { + log.Print(err) + w.WriteHeader(http.StatusInternalServerError) + } + w.WriteHeader(http.StatusOK) + }) + http.ListenAndServe(":8000", nil) +} \ No newline at end of file