Make Bookmarks scrapable from web UI
This commit is contained in:
parent
c52960759e
commit
7244bf51e9
@ -5,11 +5,31 @@ import (
|
||||
"net/http"
|
||||
|
||||
"gitlab.com/offline-twitter/twitter_offline_engine/pkg/persistence"
|
||||
"gitlab.com/offline-twitter/twitter_offline_engine/pkg/scraper"
|
||||
)
|
||||
|
||||
func (app *Application) Bookmarks(w http.ResponseWriter, r *http.Request) {
|
||||
app.traceLog.Printf("'Bookmarks' handler (path: %q)", r.URL.Path)
|
||||
|
||||
// Run a scrape if needed
|
||||
if r.URL.Query().Has("scrape") {
|
||||
if app.IsScrapingDisabled {
|
||||
app.InfoLog.Printf("Would have scraped: %s", r.URL.Path)
|
||||
http.Error(w, "Scraping is disabled (are you logged in?)", 401)
|
||||
return
|
||||
}
|
||||
|
||||
// Run scraper
|
||||
trove, err := scraper.GetBookmarks(300) // TODO: parameterizable
|
||||
if err != nil && !errors.Is(err, scraper.END_OF_FEED) {
|
||||
app.ErrorLog.Print(err)
|
||||
panic(err) // Return a toast
|
||||
}
|
||||
|
||||
app.Profile.SaveTweetTrove(trove, false)
|
||||
go app.Profile.SaveTweetTrove(trove, true)
|
||||
}
|
||||
|
||||
c := persistence.NewUserFeedBookmarksCursor(app.ActiveUser.Handle)
|
||||
err := parse_cursor_value(&c, r)
|
||||
if err != nil {
|
||||
|
@ -104,7 +104,7 @@ func (app *Application) Search(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Run scraper
|
||||
trove, err := scraper.Search(search_text, 1) // TODO: parameterizable
|
||||
if err != nil {
|
||||
if err != nil && !errors.Is(err, scraper.END_OF_FEED) {
|
||||
app.ErrorLog.Print(err)
|
||||
// TOOD: show error in UI
|
||||
}
|
||||
|
@ -2,7 +2,24 @@
|
||||
|
||||
{{define "main"}}
|
||||
<div class="bookmarks-feed-header">
|
||||
<h1>Bookmarks</h1>
|
||||
<div class="row row--spread">
|
||||
<div class="dummy"></div> {{/* Extra div to take up a slot in the `row` */}}
|
||||
<h1>Bookmarks</h1>
|
||||
<div class="row">
|
||||
<a class="button" target="_blank" href="https://twitter.com/i/bookmarks" title="Open on twitter.com">
|
||||
<img class="svg-icon" src="/static/icons/external-link.svg" width="24" height="24" />
|
||||
</a>
|
||||
<a class="button" hx-get="?scrape" hx-target="body" hx-indicator=".bookmarks-feed-header" title="Refresh">
|
||||
<img class="svg-icon" src="/static/icons/refresh.svg" width="24" height="24" />
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="htmx-spinner">
|
||||
<div class="htmx-spinner__fullscreen-forcer">
|
||||
<div class="htmx-spinner__background"></div>
|
||||
<img class="svg-icon htmx-spinner__icon" src="/static/icons/spinner.svg" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="timeline">
|
||||
{{template "timeline" .Feed}}
|
||||
|
@ -24,8 +24,10 @@
|
||||
</a>
|
||||
</div>
|
||||
<div class="htmx-spinner">
|
||||
<div class="htmx-spinner__background"></div>
|
||||
<img class="svg-icon htmx-spinner__icon" src="/static/icons/spinner.svg" />
|
||||
<div class="htmx-spinner__fullscreen-forcer">
|
||||
<div class="htmx-spinner__background"></div>
|
||||
<img class="svg-icon htmx-spinner__icon" src="/static/icons/spinner.svg" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{if .IsUsersSearch}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user