Skip to content

Commit

Permalink
publish metadata note on create and live urls
Browse files Browse the repository at this point in the history
  • Loading branch information
trinidz committed Nov 20, 2024
1 parent bf19f06 commit 0ade936
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 51 deletions.
9 changes: 3 additions & 6 deletions feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,9 @@ func parseFeedForPubkey(pubKey string, deleteFailingFeeds bool) (*gofeed.Feed, E

func createMetadataNote(pubkey string, privkey string, feed *gofeed.Feed, defaultProfilePictureUrl string) error {

if _, evt_meta, _ := getLocalMetadataEvent(pubkey); evt_meta.ID != "" {
if time.Now().Unix()-evt_meta.CreatedAt.Time().Unix() > int64(s.FeedMetadataRefreshDays*86400) {
log.Printf("[DEBUG] updating old metadata for event ID %s", evt_meta.ID)
} else {
log.Printf("[DEBUG] recent metadata exists at event ID %s created at: %v", evt_meta.ID, evt_meta.CreatedAt.Time().Unix())
if _, feedMetadata, _ := getLocalMetadataEvent(pubkey); feedMetadata.ID != "" {
if time.Now().Unix()-feedMetadata.CreatedAt.Time().Unix() < int64(s.FeedMetadataRefreshDays*86400) {
//log.Printf("[DEBUG] recent metadata exists at event ID %s created at: %v", feedMetadata.ID, feedMetadata.CreatedAt.Time().Unix())
return nil
}
}
Expand Down Expand Up @@ -197,7 +195,6 @@ func createMetadataNote(pubkey string, privkey string, feed *gofeed.Feed, defaul
}

log.Printf("[DEBUG] metadata note for %s created with ID %s with createdat %d", feed.Link, evt.ID, evt.CreatedAt.Time().Unix())

return nil
}

Expand Down
40 changes: 24 additions & 16 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,24 @@ func createFeed(r *http.Request, secret *string) *GUIEntry {
guientry.BookmarkEntity.ImageURL = parsedFeed.Image.URL
}

go func() {
if err := createMetadataNote(publicKey, sk, parsedFeed, s.DefaultProfilePicUrl); err != nil {
log.Printf("[ERROR] creating metadata note %s", err)
}
if err := createMetadataNote(publicKey, sk, parsedFeed, s.DefaultProfilePicUrl); err != nil {
log.Printf("[ERROR] creating metadata note %s", err)
}

latestCreatedAt := initFeed(publicKey, sk, feedUrl, parsedFeed)
if _, metadataEvent, _ := getLocalMetadataEvent(publicKey); metadataEvent.ID != "" {
publishNostrEventCh <- metadataEvent
}

if err := addEntityToBookmarkEvent([]Entity{
{PubKey: publicKey,
PrivateKey: sk,
URL: feedUrl,
ImageURL: guientry.BookmarkEntity.ImageURL,
LastUpdate: latestCreatedAt}}); err != nil {
log.Printf("[ERROR] feed entity %s not added to bookmark", feedUrl)
}
}()
latestCreatedAt := initFeed(publicKey, sk, feedUrl, parsedFeed)

if err := addEntityToBookmarkEvent([]Entity{
{PubKey: publicKey,
PrivateKey: sk,
URL: feedUrl,
ImageURL: guientry.BookmarkEntity.ImageURL,
LastUpdate: latestCreatedAt}}); err != nil {
log.Printf("[ERROR] feed entity %s not added to bookmark", feedUrl)
}

if err := qrcode.WriteFile(fmt.Sprintf("nostr:%s", guientry.NPubKey), qrcode.Low, 128, fmt.Sprintf("%s/%s.png", s.QRCodePath, guientry.NPubKey)); err != nil {
log.Print("[ERROR]", err)
Expand Down Expand Up @@ -367,8 +369,6 @@ func importFeeds(opmlUrls []opml.Outline, secret *string) []*GUIEntry {
Error: false,
ErrorCode: 0,
}
importedEntries = append(importedEntries, &guiEntry)
importProgressCh <- ImportProgressStruct{entryIndex: urlIndex, totalEntries: len(opmlUrls)}

if err := qrcode.WriteFile(fmt.Sprintf("nostr:%s", guiEntry.NPubKey), qrcode.Low, 128, fmt.Sprintf("%s/%s.png", s.QRCodePath, guiEntry.NPubKey)); err != nil {
log.Print("[ERROR] ", err)
Expand All @@ -385,6 +385,9 @@ func importFeeds(opmlUrls []opml.Outline, secret *string) []*GUIEntry {

latestCreatedAt := initFeed(publicKey, sk, feedUrl, parsedFeed)
bookmarkEntities = append(bookmarkEntities, Entity{PubKey: publicKey, PrivateKey: sk, URL: feedUrl, ImageURL: localImageURL, LastUpdate: latestCreatedAt})

importedEntries = append(importedEntries, &guiEntry)
importProgressCh <- ImportProgressStruct{entryIndex: urlIndex, totalEntries: len(opmlUrls)}
}

if err := addEntityToBookmarkEvent(bookmarkEntities); err != nil {
Expand Down Expand Up @@ -578,12 +581,17 @@ func updateRssNotesState() {
select {
case followAction := <-followManagmentCh:
updateFollowListEvent(followAction)
case nostrEvent := <-publishNostrEventCh:
go func() {
blastEvent(&nostrEvent)
}()
case <-tickerUpdateFeeds.C:
updateAllFeeds()
case <-tickerDeleteOldNotes.C:
deleteOldEvents()
case <-quitChannel:
tickerUpdateFeeds.Stop()
tickerDeleteOldNotes.Stop()
return
}
}
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Settings struct {
RelayIcon string `envconfig:"RELAY_ICON" default:"https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons/png/commafeed.png"`
RandomSecret string `envconfig:"RANDOM_SECRET" required:"true"`
OwnerPubkey string `envconfig:"OWNER_PUBKEY"`
Version string `envconfig:"VERSION" default:"0.0.4"`
Version string `envconfig:"VERSION" default:"0.0.7"`

LogLevel string `envconfig:"LOG_LEVEL" default:"WARN"`
Port string `envconfig:"PORT" default:"3334"`
Expand All @@ -53,12 +53,12 @@ type Settings struct {
}

var (
s Settings
//db = lmdb.LMDBBackend{}
s Settings
db = badger.BadgerBackend{}
relay = khatru.NewRelay()
followManagmentCh = make(chan FollowManagment)
importProgressCh = make(chan ImportProgressStruct)
publishNostrEventCh = make(chan nostr.Event)
pool *nostr.SimplePool
seedRelays []string
tickerUpdateFeeds *time.Ticker
Expand Down
1 change: 1 addition & 0 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ RELAY_NAME="my-rssnotes-relay"
#RELAY_CONTACT="[email protected]"
#RELAY_ICON="https://i.imgur.com/MaceU96.png"
#PORT="3334"
#DEFAULT_PROFILE_PICTURE_URL="https://i.imgur.com/MaceU96.png"
#MAX_NOTE_AGE_DAYS="90" #notes older than this many days will be deleted, disabled by default or if set to "0"
21 changes: 1 addition & 20 deletions sample.seedrelays.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,7 @@
"nos.lol",
"relay.nostr.band",
"relay.snort.social",
"nostr.land",
"nostr.mom",
"relay.nos.social",
"relay.primal.net",
"relay.nostr.bg",
"nostr21.com",
"nostrue.com",
"relay.siamstr.com",
"wot.utxo.one",
"nostrelites.org",
"wot.nostr.party",
"wot.sovbit.host",
"wot.girino.org",
"relay.lnau.net",
"wot.siamstr.com",
"relay.otherstuff.fyi",
"relay.lexingtonbitcoin.org",
"wot.azzamo.net",
"wot.swarmstr.com",
"zap.watch",
"satsage.xyz",
"wons.calva.dev"
"nostrelites.org"
]
7 changes: 4 additions & 3 deletions web/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,12 @@ <h2 class="subtitle">Existing feeds:</h2>
<tr>
<td><img src="{{.BookmarkEntity.ImageURL}}" alt="feed icon" width="128" height="128"></td>
<td><a href="{{.BookmarkEntity.URL}}" style="word-break: break-all;">{{.BookmarkEntity.URL}}</a></td>
<td><span>{{.NPubKey}}</span>
<td>
<a href="https://njump.me/{{.NPubKey}}" style="word-break: break-all;">{{.NPubKey}}</a>
<p>---</p>
<span>{{.BookmarkEntity.PubKey}}</span>
<td><img src="/assets/qrcodes/{{.NPubKey}}.png" alt="npub qrcode" width="128" height="128">
<a href="https://njump.me/{{.NPubKey}}" style="word-break: break-all;">{{.BookmarkEntity.PubKey}}</a>
</td>
<td><img src="/assets/qrcodes/{{.NPubKey}}.png" alt="npub qrcode" width="128" height="128"></td>
<td>
<div class="buttons">
<a href="/delete?pubkey={{.BookmarkEntity.PubKey}}" target="_self" class="button is-small is-link is-light">Delete</a>
Expand Down
8 changes: 5 additions & 3 deletions web/templates/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,13 @@ <h2 class="subtitle">Found feeds (showing a maximum of 50, refine your query if
<td><img src="{{.BookmarkEntity.ImageURL}}" alt="feed icon" width="128" height="128"></td>
<td><a href="{{.BookmarkEntity.URL}}" style="word-break: break-all;">{{.BookmarkEntity.URL}}</a></td>
<td>
<span>{{.NPubKey}}</span>
<a href="https://njump.me/{{.NPubKey}}" style="word-break: break-all;">{{.NPubKey}}</a>
<p>---</p>
<span>{{.BookmarkEntity.PubKey}}</span>
<td><img src="/assets/qrcodes/{{.NPubKey}}.png" alt="npub qrcode" width="128" height="128">
<a href="https://njump.me/{{.NPubKey}}" style="word-break: break-all;">{{.BookmarkEntity.PubKey}}</a>
</td>

<td><img src="/assets/qrcodes/{{.NPubKey}}.png" alt="npub qrcode" width="128" height="128"></td>

<td>
<div class="buttons">
<a href="/delete?pubkey={{.BookmarkEntity.PubKey}}" target="_self" class="button is-small is-link is-light">Delete</a>
Expand Down

0 comments on commit 0ade936

Please sign in to comment.