.
This commit is contained in:
@@ -4,15 +4,13 @@ import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gemini-grc/logging"
|
||||
"strings"
|
||||
|
||||
"github.com/guregu/null/v5"
|
||||
)
|
||||
|
||||
type LinkList []GeminiUrl
|
||||
type LinkList []URL
|
||||
|
||||
func (l LinkList) Value() (driver.Value, error) {
|
||||
func (l *LinkList) Value() (driver.Value, error) {
|
||||
return json.Marshal(l)
|
||||
}
|
||||
|
||||
@@ -31,7 +29,7 @@ func (l *LinkList) Scan(value interface{}) error {
|
||||
type Snapshot struct {
|
||||
ID int `db:"id" json:"id,omitempty"`
|
||||
UID string `db:"uid" json:"uid,omitempty"`
|
||||
URL GeminiUrl `db:"url" json:"url,omitempty"`
|
||||
URL URL `db:"url" json:"url,omitempty"`
|
||||
Host string `db:"host" json:"host,omitempty"`
|
||||
Timestamp null.Time `db:"timestamp" json:"timestamp,omitempty"`
|
||||
MimeType null.String `db:"mimetype" json:"mimetype,omitempty"`
|
||||
@@ -43,32 +41,32 @@ type Snapshot struct {
|
||||
Error null.String `db:"error" json:"error,omitempty"` // On network errors only
|
||||
}
|
||||
|
||||
func SnapshotToJSON(g Snapshot) string {
|
||||
// Serialize the Person struct to JSON
|
||||
jsonData, err := json.MarshalIndent(g, "", "\t")
|
||||
if err != nil {
|
||||
logging.LogError("Error serializing to JSON: %w", err)
|
||||
}
|
||||
return string(jsonData)
|
||||
}
|
||||
|
||||
func SnapshotFromJSON(input string) Snapshot {
|
||||
var snapshot Snapshot
|
||||
err := json.Unmarshal([]byte(input), &snapshot)
|
||||
if err != nil {
|
||||
logging.LogError("Error deserializing from JSON: %w", err)
|
||||
}
|
||||
return snapshot
|
||||
}
|
||||
|
||||
func ShouldPersistSnapshot(result *Snapshot) bool {
|
||||
if !result.MimeType.Valid {
|
||||
return false
|
||||
}
|
||||
if result.MimeType.String == "text/gemini" ||
|
||||
strings.HasPrefix(result.MimeType.String, "image/") ||
|
||||
strings.HasPrefix(result.MimeType.String, "text/") {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
//func SnapshotToJSON(g Snapshot) string {
|
||||
// // Serialize the Person struct to JSON
|
||||
// jsonData, err := json.MarshalIndent(g, "", "\t")
|
||||
// if err != nil {
|
||||
// logging.LogError("Error serializing to JSON: %w", err)
|
||||
// }
|
||||
// return string(jsonData)
|
||||
//}
|
||||
//
|
||||
//func SnapshotFromJSON(input string) Snapshot {
|
||||
// var snapshot Snapshot
|
||||
// err := json.Unmarshal([]byte(input), &snapshot)
|
||||
// if err != nil {
|
||||
// logging.LogError("Error deserializing from JSON: %w", err)
|
||||
// }
|
||||
// return snapshot
|
||||
//}
|
||||
//
|
||||
//func ShouldPersistSnapshot(result *Snapshot) bool {
|
||||
// if !result.MimeType.Valid {
|
||||
// return false
|
||||
// }
|
||||
// if result.MimeType.String == "text/gemini" ||
|
||||
// strings.HasPrefix(result.MimeType.String, "image/") ||
|
||||
// strings.HasPrefix(result.MimeType.String, "text/") {
|
||||
// return true
|
||||
// }
|
||||
// return false
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user