mirror of
https://code.dumpstack.io/tools/wi.git
synced 2024-11-14 14:29:19 +02:00
Implements follow link from history
This commit is contained in:
parent
159907723b
commit
fd1e14128e
|
@ -126,8 +126,17 @@ func Get(db *sql.DB, url string) {
|
||||||
fmt.Println(text)
|
fmt.Println(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Link(db *sql.DB, linkID int64) {
|
func Link(db *sql.DB, linkID int64, fromHistory bool) {
|
||||||
url, err := storage.GetLink(db, linkID)
|
|
||||||
|
var url string
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if fromHistory {
|
||||||
|
url, err = storage.GetHistoryUrl(db, linkID)
|
||||||
|
} else {
|
||||||
|
url, err = storage.GetLink(db, linkID)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
3
main.go
3
main.go
|
@ -21,6 +21,7 @@ var (
|
||||||
|
|
||||||
link = kingpin.Command("link", "Get link")
|
link = kingpin.Command("link", "Get link")
|
||||||
linkNo = link.Arg("no", "Number").Required().Int64()
|
linkNo = link.Arg("no", "Number").Required().Int64()
|
||||||
|
linkFromHistory = link.Flag("history", "Item from history").Bool()
|
||||||
|
|
||||||
historyList = kingpin.Command("history", "List history")
|
historyList = kingpin.Command("history", "List history")
|
||||||
historyListItems = historyList.Arg("items", "Amount of items").Int64()
|
historyListItems = historyList.Arg("items", "Amount of items").Int64()
|
||||||
|
@ -38,7 +39,7 @@ func main() {
|
||||||
case "get":
|
case "get":
|
||||||
commands.Get(db, *getUrl)
|
commands.Get(db, *getUrl)
|
||||||
case "link":
|
case "link":
|
||||||
commands.Link(db, *linkNo)
|
commands.Link(db, *linkNo, *linkFromHistory)
|
||||||
case "history":
|
case "history":
|
||||||
commands.History(db, *historyListItems, 20, *historyListAll)
|
commands.History(db, *historyListItems, 20, *historyListAll)
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,3 +109,15 @@ func GetHistory(db *sql.DB) (history []HistoryItem, err error) {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetHistoryUrl(db *sql.DB, historyID int64) (url string, err error) {
|
||||||
|
stmt, err := db.Prepare("SELECT `url` FROM `history` WHERE id=$1;")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer stmt.Close()
|
||||||
|
|
||||||
|
err = stmt.QueryRow(historyID).Scan(&url)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue