feat: fix db and recode judge
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user