Lint fixes.
This commit is contained in:
@@ -1,20 +1,29 @@
|
||||
// func PopulateDB(db *sqlx.DB) {
|
||||
// // Delete all rows in the snapshots table
|
||||
// db.MustExec("TRUNCATE snapshots;")
|
||||
package main
|
||||
|
||||
// // Prepare the query for inserting a snapshot with uid, url, and timestamp
|
||||
// query := `INSERT INTO snapshots(uid, url, timestamp)
|
||||
// VALUES ($1, $2, $3)`
|
||||
import (
|
||||
"gemini-grc/uid"
|
||||
"time"
|
||||
|
||||
// // Calculate the timestamp for 2 days ago
|
||||
// timestamp := time.Now().Add(-48 * time.Hour)
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
// db.MustExec(query, uid.UID(), "gemini://geminiprotocol.net/", timestamp)
|
||||
// db.MustExec(query, uid.UID(), "gemini://warmedal.se/~antenna", timestamp)
|
||||
// db.MustExec(query, uid.UID(), "gemini://skyjake.fi/~Cosmos/", timestamp)
|
||||
// db.MustExec(query, uid.UID(), "gemini://gemini.circumlunar.space/capcom/", timestamp)
|
||||
// db.MustExec(query, uid.UID(), "gemini://auragem.letz.dev/", timestamp)
|
||||
// db.MustExec(query, uid.UID(), "gemini://gemplex.space/", timestamp)
|
||||
// db.MustExec(query, uid.UID(), "gemini://kennedy.gemi.dev/", timestamp)
|
||||
// db.MustExec(query, uid.UID(), "gemini://tlgs.one/", timestamp)
|
||||
// }
|
||||
func PopulateDB(db *sqlx.DB) {
|
||||
// Delete all rows in the snapshots table
|
||||
db.MustExec("TRUNCATE snapshots;")
|
||||
|
||||
// Prepare the query for inserting a snapshot with uid, url, and timestamp
|
||||
query := `INSERT INTO snapshots(uid, url, timestamp)
|
||||
VALUES ($1, $2, $3)`
|
||||
|
||||
// Calculate the timestamp for 2 days ago
|
||||
timestamp := time.Now().Add(-48 * time.Hour)
|
||||
|
||||
db.MustExec(query, uid.UID(), "gemini://geminiprotocol.net/", timestamp)
|
||||
db.MustExec(query, uid.UID(), "gemini://warmedal.se/~antenna", timestamp)
|
||||
db.MustExec(query, uid.UID(), "gemini://skyjake.fi/~Cosmos/", timestamp)
|
||||
db.MustExec(query, uid.UID(), "gemini://gemini.circumlunar.space/capcom/", timestamp)
|
||||
db.MustExec(query, uid.UID(), "gemini://auragem.letz.dev/", timestamp)
|
||||
db.MustExec(query, uid.UID(), "gemini://gemplex.space/", timestamp)
|
||||
db.MustExec(query, uid.UID(), "gemini://kennedy.gemi.dev/", timestamp)
|
||||
db.MustExec(query, uid.UID(), "gemini://tlgs.one/", timestamp)
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ func SaveToFile(rootPath string, s *Snapshot, done chan struct{}) {
|
||||
urlPath := s.URL.Path
|
||||
// If path is empty, add `index.gmi` as the file to save
|
||||
if urlPath == "" || urlPath == "." {
|
||||
urlPath = fmt.Sprintf("index.gmi")
|
||||
urlPath = "index.gmi"
|
||||
}
|
||||
// If path ends with '/' then add index.gmi for the
|
||||
// directory to be created.
|
||||
|
||||
@@ -5,32 +5,10 @@ import (
|
||||
"fmt"
|
||||
"gemini-grc/logging"
|
||||
"net/url"
|
||||
gourl "net/url"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func isGeminiURL(url string) bool {
|
||||
_, err := gourl.Parse(url)
|
||||
if err != nil {
|
||||
logging.LogWarn("[%s] Invalid URL: %v", url, err)
|
||||
return false
|
||||
}
|
||||
return strings.HasPrefix(url, "gemini://")
|
||||
}
|
||||
|
||||
func parseLinks(s Snapshot, queue chan string) {
|
||||
for _, link := range *s.Links {
|
||||
if strings.HasPrefix(link.Full, "gemini://") {
|
||||
go func(link GeminiUrl) {
|
||||
// fmt.Printf("LINK: %s\n", link)
|
||||
queue <- link.Full
|
||||
}(link)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func checkGeminiStatusCode(code int) error {
|
||||
switch {
|
||||
case code == 20:
|
||||
|
||||
@@ -62,10 +62,9 @@ func ConnectAndGetData(url string) ([]byte, error) {
|
||||
}
|
||||
// Make sure we always close the connection.
|
||||
defer func() {
|
||||
err := conn.Close()
|
||||
if err != nil {
|
||||
// Do nothing! Connection will timeout eventually if still open somehow.
|
||||
}
|
||||
// No need to handle error:
|
||||
// Connection will timeout eventually if still open somehow.
|
||||
conn.Close()
|
||||
}()
|
||||
|
||||
// Set read and write timeouts on the TCP connection.
|
||||
@@ -141,7 +140,6 @@ func Visit(s *Snapshot) {
|
||||
if pageData.Data != nil {
|
||||
s.Data = null.ValueFrom(pageData.Data)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Update given snapshot with the
|
||||
|
||||
@@ -20,6 +20,7 @@ func EnsureValidUTF8(input []byte) (string, error) {
|
||||
charmap.Windows1252.NewDecoder(), // Then try Windows-1252, etc
|
||||
// TODO: Try more encodings?
|
||||
}
|
||||
// First successful conversion wins
|
||||
for _, encoding := range encodings {
|
||||
reader := transform.NewReader(bytes.NewReader(inputNoNull), encoding)
|
||||
result, err := io.ReadAll(reader)
|
||||
|
||||
@@ -57,7 +57,7 @@ func RobotMatch(s *Snapshot) bool {
|
||||
logging.LogDebug("Checking robots.txt cache for %s", s.URL.String())
|
||||
key := fmt.Sprintf("%s:%d", s.Host, s.URL.Port)
|
||||
v, ok := RobotsCache.Load(key)
|
||||
if ok == false {
|
||||
if !ok {
|
||||
// First time check, populate robot cache
|
||||
logging.LogDebug("No robots.txt entry, populating cache for %s", s.URL.String())
|
||||
disallowedURLs := populateBlacklist(key)
|
||||
|
||||
@@ -58,11 +58,11 @@ func runWorker(id int, db *sqlx.DB) {
|
||||
logging.LogInfo("[%d] Starting %d/%d %s", id, i+1, total, s.URL)
|
||||
err = workOnSnapshot(id, tx, &s)
|
||||
if err != nil {
|
||||
logging.LogError("[%d] [%s] Error %w", id, s.URL, err)
|
||||
logging.LogError("[%d] [%s] Unexpected Error %w", id, s.URL, err)
|
||||
util.PrintStackAndPanic(err)
|
||||
}
|
||||
if s.Error.Valid {
|
||||
logging.LogWarn("[%d] [%s] Error: %v", id, s.URL, fmt.Errorf(s.Error.String))
|
||||
logging.LogWarn("[%d] [%s] Worker Error: %v", id, s.URL, s.Error.String)
|
||||
}
|
||||
logging.LogDebug("[%d] Done %d/%d.", id, i, total)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user