Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions internal/integration/archiveorg/archiveorg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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=5d"

type Client struct{}

func NewClient() *Client {
return &Client{}
}

func (c *Client) SendURL(entryURL, title string) error {
// We're using a goroutine here as submissions to archive.org might take a long time,
// and thus trigger a timeout on miniflux' side.
go func(entryURL string) {
slog.Debug("Sending entry to archive.org",
slog.String("title", title))

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))
}
defer res.Body.Close()
if res.StatusCode > 299 {
slog.Error("archiveorg: failed with status code", slog.Int("code", res.StatusCode))
}
}(entryURL)

return nil
}
19 changes: 19 additions & 0 deletions internal/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -37,6 +38,24 @@ import (

// SendEntry sends the entry to third-party providers when the user click on "Save".
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),
)

err := archiveorg.NewClient().SendURL(entry.URL, entry.Title)
if err != nil {
slog.Error("Unable to send entry to archive.org",
slog.Int64("user_id", userIntegrations.UserID),
slog.Int64("entry_id", entry.ID),
slog.String("entry_url", entry.URL),
slog.Any("error", err),
)
}
}

if userIntegrations.BetulaEnabled {
slog.Debug("Sending entry to Betula",
slog.Int64("user_id", userIntegrations.UserID),
Expand Down
1 change: 1 addition & 0 deletions internal/model/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,5 @@ type Integration struct {
PushoverToken string
PushoverDevice string
PushoverPrefix string
ArchiveorgEnabled bool
}
11 changes: 8 additions & 3 deletions internal/storage/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ func (s *Storage) Integration(userID int64) (*model.Integration, error) {
karakeep_enabled,
karakeep_api_key,
karakeep_url
archiveorg_enabled,
FROM
integrations
WHERE
Expand Down Expand Up @@ -340,6 +341,7 @@ func (s *Storage) Integration(userID int64) (*model.Integration, error) {
&integration.KarakeepEnabled,
&integration.KarakeepAPIKey,
&integration.KarakeepURL,
&integration.ArchiveorgEnabled,
)
switch {
case err == sql.ErrNoRows:
Expand Down Expand Up @@ -467,9 +469,10 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error {
rssbridge_token=$108,
karakeep_enabled=$109,
karakeep_api_key=$110,
karakeep_url=$111
karakeep_url=$111,
archiveorg_enabled=$112
WHERE
user_id=$112
user_id=$113
`
_, err := s.db.Exec(
query,
Expand Down Expand Up @@ -584,6 +587,7 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error {
integration.KarakeepEnabled,
integration.KarakeepAPIKey,
integration.KarakeepURL,
integration.ArchiveorgEnabled,
integration.UserID,
)

Expand Down Expand Up @@ -626,7 +630,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 {
Expand Down
12 changes: 12 additions & 0 deletions internal/template/templates/views/integrations.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ <h1 id="page-header-title">{{ t "page.integrations.title" }}</h1>
<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">
Expand Down
2 changes: 2 additions & 0 deletions internal/ui/form/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ type IntegrationForm struct {
PushoverToken string
PushoverDevice string
PushoverPrefix string
ArchiveorgEnabled bool
}

// Merge copy form values to the model.
Expand Down Expand Up @@ -350,6 +351,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",
}
}

Expand Down
1 change: 1 addition & 0 deletions internal/ui/integration_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,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))
Expand Down
Loading