show last time item was refreshed
This commit is contained in:
5
main.go
5
main.go
@@ -136,6 +136,11 @@ func main() {
|
||||
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)
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package model
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (m *Model) GetItems() ([]*Item, error) {
|
||||
rows, err := m.db.Queryx("SELECT * FROM items")
|
||||
@@ -19,3 +22,14 @@ func (m *Model) GetItems() ([]*Item, error) {
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ type Item struct {
|
||||
Category int `json:"category" db:"category"`
|
||||
CreatedAt time.Time `json:"createdAt" db:"created_at"`
|
||||
Torrents []Torrent `json:"torrents,omitempty"`
|
||||
RefreshedAt *time.Time `json:"refreshedAt" db:"refreshed_at"`
|
||||
}
|
||||
|
||||
func (m *Model) Init() {
|
||||
@@ -59,6 +60,8 @@ func (m *Model) Init() {
|
||||
item_id integer not null,
|
||||
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 {
|
||||
|
||||
@@ -4,6 +4,7 @@ export type ItemDetails = {
|
||||
id: number;
|
||||
query: string;
|
||||
createdAt: string;
|
||||
refreshedAt: string | null;
|
||||
};
|
||||
|
||||
export const useItemsQuery = () => {
|
||||
|
||||
@@ -12,9 +12,12 @@ import { useDownloadTorrentMutation } from "../api/useDownloadTorrentMutation";
|
||||
import { useDeleteItemMutation } from "../api/useDeleteItemMutation";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import dayjs from "dayjs";
|
||||
import relativeTime from "dayjs/plugin/relativeTime";
|
||||
import { humanFileSize } from "../utils/humanFileSize";
|
||||
import { useDeleteTorrentMutation } from "../api/useDeleteTorrentMutation";
|
||||
|
||||
dayjs.extend(relativeTime);
|
||||
|
||||
export type ItemProps = {
|
||||
item: ItemDetails;
|
||||
};
|
||||
@@ -79,7 +82,16 @@ export const Item = ({ item }: ItemProps) => {
|
||||
</div>
|
||||
{open && (
|
||||
<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
|
||||
className="cursor-pointer flex items-center gap-1 text-[#b00420]"
|
||||
onClick={handleDelete}
|
||||
|
||||
Reference in New Issue
Block a user