mirror of
https://github.com/miniflux/v2.git
synced 2025-09-15 18:57:04 +00:00
feat(integration): add integration with archive.org
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 $ ```
This commit is contained in:
parent
87e65f800e
commit
3fba5801f3
8 changed files with 87 additions and 5 deletions
|
@ -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
|
||||
},
|
||||
}
|
||||
|
|
43
internal/integration/archiveorg/archiveorg.go
Normal file
43
internal/integration/archiveorg/archiveorg.go
Normal file
|
@ -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)
|
||||
}
|
|
@ -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 != "" {
|
||||
|
|
|
@ -123,4 +123,5 @@ type Integration struct {
|
|||
PushoverToken string
|
||||
PushoverDevice string
|
||||
PushoverPrefix string
|
||||
ArchiveorgEnabled bool
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -15,6 +15,18 @@
|
|||
<div role="alert" class="alert alert-error">{{ .errorMessage }}</div>
|
||||
{{ end }}
|
||||
|
||||
<details {{ if .form.ArchiveorgEnabled }}open{{ end }}>
|
||||
<summary>Archive.org</summary>
|
||||
<div class="form-section">
|
||||
<label>
|
||||
<input type="checkbox" name="archiveorg_enabled" value="1" {{ if .form.ArchiveorgEnabled }}checked{{ end }}> {{ t "form.integration.archiveorg_activate" }}
|
||||
</label>
|
||||
<div class="buttons">
|
||||
<button type="submit" class="button button-primary" data-label-loading="{{ t "form.submit.saving" }}">{{ t "action.update" }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<details {{ if .form.AppriseEnabled }}open{{ end }}>
|
||||
<summary>Apprise</summary>
|
||||
<div class="form-section">
|
||||
|
|
|
@ -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",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue