Compare commits

...

2 Commits

5 changed files with 43 additions and 8 deletions

View File

@@ -136,9 +136,14 @@ func main() {
continue continue
} }
} }
if err := m.UpdateRefreshedAt(item.ID, time.Now()); err != nil {
log.Printf("couldn't update refreshed_at for %d: %v\n", item.ID, err)
continue
}
} }
time.Sleep(10 * time.Second) time.Sleep(1 * time.Hour)
} }
}(m) }(m)

View File

@@ -1,6 +1,9 @@
package model package model
import "fmt" import (
"fmt"
"time"
)
func (m *Model) GetItems() ([]*Item, error) { func (m *Model) GetItems() ([]*Item, error) {
rows, err := m.db.Queryx("SELECT * FROM items") rows, err := m.db.Queryx("SELECT * FROM items")
@@ -19,3 +22,14 @@ func (m *Model) GetItems() ([]*Item, error) {
return items, nil return items, nil
} }
func (m *Model) UpdateRefreshedAt(itemId int64, refreshedAt time.Time) error {
if _, err := m.db.NamedExec("UPDATE items SET refreshed_at = :refreshed_at WHERE id = :item_id", map[string]any{
"refreshed_at": refreshedAt,
"item_id": itemId,
}); err != nil {
return fmt.Errorf("failed to update refreshed_at field: %v", err)
}
return nil
}

View File

@@ -28,11 +28,12 @@ type Torrent struct {
} }
type Item struct { type Item struct {
ID int64 `json:"id" db:"id"` ID int64 `json:"id" db:"id"`
Query string `json:"query" db:"query"` Query string `json:"query" db:"query"`
Category int `json:"category" db:"category"` Category int `json:"category" db:"category"`
CreatedAt time.Time `json:"createdAt" db:"created_at"` CreatedAt time.Time `json:"createdAt" db:"created_at"`
Torrents []Torrent `json:"torrents,omitempty"` Torrents []Torrent `json:"torrents,omitempty"`
RefreshedAt *time.Time `json:"refreshedAt" db:"refreshed_at"`
} }
func (m *Model) Init() { func (m *Model) Init() {
@@ -59,6 +60,8 @@ func (m *Model) Init() {
item_id integer not null, item_id integer not null,
FOREIGN KEY (item_id) REFERENCES users(id) FOREIGN KEY (item_id) REFERENCES users(id)
)`) )`)
m.db.Exec(`ALTER TABLE items ADD COLUMN refreshed_at datetime default null`)
} }
func New(db *sqlx.DB) *Model { func New(db *sqlx.DB) *Model {

View File

@@ -4,6 +4,7 @@ export type ItemDetails = {
id: number; id: number;
query: string; query: string;
createdAt: string; createdAt: string;
refreshedAt: string | null;
}; };
export const useItemsQuery = () => { export const useItemsQuery = () => {

View File

@@ -12,9 +12,12 @@ import { useDownloadTorrentMutation } from "../api/useDownloadTorrentMutation";
import { useDeleteItemMutation } from "../api/useDeleteItemMutation"; import { useDeleteItemMutation } from "../api/useDeleteItemMutation";
import { useQueryClient } from "@tanstack/react-query"; import { useQueryClient } from "@tanstack/react-query";
import dayjs from "dayjs"; import dayjs from "dayjs";
import relativeTime from "dayjs/plugin/relativeTime";
import { humanFileSize } from "../utils/humanFileSize"; import { humanFileSize } from "../utils/humanFileSize";
import { useDeleteTorrentMutation } from "../api/useDeleteTorrentMutation"; import { useDeleteTorrentMutation } from "../api/useDeleteTorrentMutation";
dayjs.extend(relativeTime);
export type ItemProps = { export type ItemProps = {
item: ItemDetails; item: ItemDetails;
}; };
@@ -79,7 +82,16 @@ export const Item = ({ item }: ItemProps) => {
</div> </div>
{open && ( {open && (
<div> <div>
<div className="flex mb-2"> <div className="flex items-center gap-2 mb-2">
<div>
Last Refresh:{" "}
{item.refreshedAt
? dayjs(item.refreshedAt).format("DD.MM.YYYY HH:mm")
: "never"}
{item.refreshedAt
? " (" + dayjs(item.refreshedAt).from(dayjs()) + ")"
: null}
</div>
<button <button
className="cursor-pointer flex items-center gap-1 text-[#b00420]" className="cursor-pointer flex items-center gap-1 text-[#b00420]"
onClick={handleDelete} onClick={handleDelete}