feat: fix db and recode judge

This commit is contained in:
d3m0k1d
2026-01-13 21:03:10 +03:00
parent b2d03a4008
commit f0180b4bbe
5 changed files with 57 additions and 43 deletions

View File

@@ -49,3 +49,12 @@ func (d *DB) SearchUnViewed() (*sql.Rows, error) {
}
return rows, nil
}
func (d *DB) MarkAsViewed(id int) error {
_, err := d.db.Exec("UPDATE requests SET viewed = 1 WHERE id = ?", id)
if err != nil {
d.logger.Error("Failed to mark as viewed", "error", err)
return err
}
return nil
}

View File

@@ -1,19 +1,19 @@
package storage
type LogEntry struct {
ID int `db:"id"`
Service string `db:"service"`
IP string `db:"ip"`
Path *string `db:"path"`
Status *string `db:"status"`
Method *string `db:"method"`
IsViewed *bool `db:"viewed"`
CreatedAt string `db:"created_at"`
ID int `db:"id"`
Service string `db:"service"`
IP string `db:"ip"`
Path string `db:"path"`
Status string `db:"status"`
Method string `db:"method"`
IsViewed bool `db:"viewed"`
CreatedAt string `db:"created_at"`
}
type Ban struct {
ID int `db:"id"`
IP string `db:"ip"`
Reason *string `db:"reason"`
BannedAt string `db:"banned_at"`
ID int `db:"id"`
IP string `db:"ip"`
Reason string `db:"reason"`
BannedAt string `db:"banned_at"`
}

View File

@@ -6,28 +6,13 @@ import (
func Write(db *DB, resultCh <-chan *LogEntry) {
for result := range resultCh {
path := ""
if result.Path != nil {
path = *result.Path
}
status := ""
if result.Status != nil {
status = *result.Status
}
method := ""
if result.Method != nil {
method = *result.Method
}
_, err := db.db.Exec(
"INSERT INTO requests (service, ip, path, method, status, created_at) VALUES (?, ?, ?, ?, ?, ?)",
result.Service,
result.IP,
path,
method,
status,
result.Path,
result.Method,
result.Status,
time.Now().Format(time.RFC3339),
)
if err != nil {