From 3fba5801f3dc0787512d98b86bb60817113f1331 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Fri, 4 Jul 2025 17:18:28 +0200 Subject: [PATCH] feat(integration): add integration with archive.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tested locally: ```console $ Tue 26 Aug 17:34:05 CEST 2025 $ go build && ./miniflux.app -c ./config.ini -debug level=DEBUG msg="Starting daemon..." level=DEBUG msg="Starting background scheduler..." level=DEBUG msg="Worker started" worker_id=15 level=DEBUG msg="Worker started" worker_id=0 […] level=DEBUG msg="Incoming request" client_ip=127.0.0.1 request.method=POST request.uri=/entry/save/29773 request.protocol=HTTP/1.1 request.execution_time=5.57385ms level=DEBUG msg="Sending entry to archive.org" user_id=1 entry_id=29773 entry_url=https://sumnerevans.com/portfolio/ level=DEBUG msg="Sending entry to archive.org" title=Portfolio url=https://sumnerevans.com/portfolio/ ^C $ curl -I -H "User-Agent: Mozilla" https://web.archive.org/web/20250826153413/https://sumnerevans.com/portfolio/ | grep orig-date x-archive-orig-date: Tue, 26 Aug 2025 15:34:13 GMT $ ``` --- internal/database/migrations.go | 7 +++ internal/integration/archiveorg/archiveorg.go | 43 +++++++++++++++++++ internal/integration/integration.go | 12 +++++- internal/model/integration.go | 1 + internal/storage/integration.go | 13 ++++-- .../templates/views/integrations.html | 12 ++++++ internal/ui/form/integration.go | 3 ++ internal/ui/integration_show.go | 1 + 8 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 internal/integration/archiveorg/archiveorg.go diff --git a/internal/database/migrations.go b/internal/database/migrations.go index 2f6eaa35..f6f92956 100644 --- a/internal/database/migrations.go +++ b/internal/database/migrations.go @@ -1341,4 +1341,11 @@ var migrations = [...]func(tx *sql.Tx) error{ return nil }, + func(tx *sql.Tx) (err error) { + sql := ` + ALTER TABLE integrations ADD COLUMN archiveorg_enabled bool default 'f' + ` + _, err = tx.Exec(sql) + return err + }, } diff --git a/internal/integration/archiveorg/archiveorg.go b/internal/integration/archiveorg/archiveorg.go new file mode 100644 index 00000000..f86a37ec --- /dev/null +++ b/internal/integration/archiveorg/archiveorg.go @@ -0,0 +1,43 @@ +// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +package archiveorg + +import ( + "log/slog" + "net/http" + "net/url" +) + +// See https://docs.google.com/document/d/1Nsv52MvSjbLb2PCpHlat0gkzw0EvtSgpKHu4mk0MnrA/edit?tab=t.0 +const options = "delay_wb_availability=1&if_not_archived_within=15d" + +type Client struct{} + +func NewClient() *Client { + return &Client{} +} + +func (c *Client) SendURL(entryURL, title string) { + // We're using a goroutine here as submissions to archive.org might take a long time + // and trigger a timeout on miniflux' side. + go func(entryURL string) { + res, err := http.Get("https://web.archive.org/save/" + url.QueryEscape(entryURL) + "?" + options) + if err != nil { + slog.Error("archiveorg: unable to send request: %v", + slog.Any("err", err), + slog.String("title", title), + slog.String("url", entryURL), + ) + return + } + if res.StatusCode > 299 { + slog.Error("archiveorg: failed with status code", + slog.String("title", title), + slog.String("url", entryURL), + slog.Int("code", res.StatusCode), + ) + } + res.Body.Close() + }(entryURL) +} diff --git a/internal/integration/integration.go b/internal/integration/integration.go index bec8b436..1f24ba3d 100644 --- a/internal/integration/integration.go +++ b/internal/integration/integration.go @@ -7,6 +7,7 @@ import ( "log/slog" "miniflux.app/v2/internal/integration/apprise" + "miniflux.app/v2/internal/integration/archiveorg" "miniflux.app/v2/internal/integration/betula" "miniflux.app/v2/internal/integration/cubox" "miniflux.app/v2/internal/integration/discord" @@ -398,6 +399,16 @@ func SendEntry(entry *model.Entry, userIntegrations *model.Integration) { } } + if userIntegrations.ArchiveorgEnabled { + slog.Debug("Sending entry to archive.org", + slog.Int64("user_id", userIntegrations.UserID), + slog.Int64("entry_id", entry.ID), + slog.String("entry_url", entry.URL), + ) + + archiveorg.NewClient().SendURL(entry.URL, entry.Title) + } + if userIntegrations.WebhookEnabled { var webhookURL string if entry.Feed != nil && entry.Feed.WebhookURL != "" { @@ -506,7 +517,6 @@ func PushEntries(feed *model.Feed, entries model.Entries, userIntegrations *mode ) } } - if userIntegrations.WebhookEnabled { var webhookURL string if feed.WebhookURL != "" { diff --git a/internal/model/integration.go b/internal/model/integration.go index bff86357..e18c5794 100644 --- a/internal/model/integration.go +++ b/internal/model/integration.go @@ -123,4 +123,5 @@ type Integration struct { PushoverToken string PushoverDevice string PushoverPrefix string + ArchiveorgEnabled bool } diff --git a/internal/storage/integration.go b/internal/storage/integration.go index 761a8dd8..da89fc4b 100644 --- a/internal/storage/integration.go +++ b/internal/storage/integration.go @@ -226,7 +226,8 @@ func (s *Storage) Integration(userID int64) (*model.Integration, error) { linktaco_api_token, linktaco_org_slug, linktaco_tags, - linktaco_visibility + linktaco_visibility, + archiveorg_enabled FROM integrations WHERE @@ -352,6 +353,7 @@ func (s *Storage) Integration(userID int64) (*model.Integration, error) { &integration.LinktacoOrgSlug, &integration.LinktacoTags, &integration.LinktacoVisibility, + &integration.ArchiveorgEnabled, ) switch { case err == sql.ErrNoRows: @@ -485,9 +487,10 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error { linktaco_api_token=$114, linktaco_org_slug=$115, linktaco_tags=$116, - linktaco_visibility=$117 + linktaco_visibility=$117, + archiveorg_enabled=$118 WHERE - user_id=$118 + user_id=$119 ` _, err := s.db.Exec( query, @@ -608,6 +611,7 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error { integration.LinktacoOrgSlug, integration.LinktacoTags, integration.LinktacoVisibility, + integration.ArchiveorgEnabled, integration.UserID, ) @@ -651,7 +655,8 @@ func (s *Storage) HasSaveEntry(userID int64) (result bool) { betula_enabled='t' OR cubox_enabled='t' OR discord_enabled='t' OR - slack_enabled='t' + slack_enabled='t' OR + archiveorg_enabled='t' ) ` if err := s.db.QueryRow(query, userID).Scan(&result); err != nil { diff --git a/internal/template/templates/views/integrations.html b/internal/template/templates/views/integrations.html index 8ce2b933..0bb72204 100644 --- a/internal/template/templates/views/integrations.html +++ b/internal/template/templates/views/integrations.html @@ -15,6 +15,18 @@ {{ end }} +
+ Archive.org +
+ +
+ +
+
+
+
Apprise
diff --git a/internal/ui/form/integration.go b/internal/ui/form/integration.go index a5b03c18..04ba208d 100644 --- a/internal/ui/form/integration.go +++ b/internal/ui/form/integration.go @@ -129,6 +129,7 @@ type IntegrationForm struct { PushoverToken string PushoverDevice string PushoverPrefix string + ArchiveorgEnabled bool } // Merge copy form values to the model. @@ -247,6 +248,7 @@ func (i IntegrationForm) Merge(integration *model.Integration) { integration.PushoverToken = i.PushoverToken integration.PushoverDevice = i.PushoverDevice integration.PushoverPrefix = i.PushoverPrefix + integration.ArchiveorgEnabled = i.ArchiveorgEnabled } // NewIntegrationForm returns a new IntegrationForm. @@ -368,6 +370,7 @@ func NewIntegrationForm(r *http.Request) *IntegrationForm { PushoverToken: r.FormValue("pushover_token"), PushoverDevice: r.FormValue("pushover_device"), PushoverPrefix: r.FormValue("pushover_prefix"), + ArchiveorgEnabled: r.FormValue("archiveorg_enabled") == "1", } } diff --git a/internal/ui/integration_show.go b/internal/ui/integration_show.go index 13cc18d3..6a7af48f 100644 --- a/internal/ui/integration_show.go +++ b/internal/ui/integration_show.go @@ -142,6 +142,7 @@ func (h *handler) showIntegrationPage(w http.ResponseWriter, r *http.Request) { PushoverToken: integration.PushoverToken, PushoverDevice: integration.PushoverDevice, PushoverPrefix: integration.PushoverPrefix, + ArchiveorgEnabled: integration.ArchiveorgEnabled, } sess := session.New(h.store, request.SessionID(r))