Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Archive bookmarks #153

Open
TomCasavant opened this issue Oct 17, 2023 · 2 comments
Open

Archive bookmarks #153

TomCasavant opened this issue Oct 17, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@TomCasavant
Copy link
Contributor

TomCasavant commented Oct 17, 2023

It might be a little outside of the scope for now or it might make more sense to handle this outside of the server using a future but just throwing this out there as a potential feature, I setup this function on my instance that I tied into the /bookmark/new endpoint so when a new bookmark is created it should archive the url on the internet archive wayback machine.

export async function archiveUrlOnInternetArchive(url) {
  const access = process.env.ARCHIVE_ACCESS
  const secret = process.env.ARCHIVE_SECRET
  if (access && secret) {
      try {
        const apiUrl = 'https://web.archive.org/save/';
        const data = `url=${url}&capture_all=1&delay_wb_availability=1&skip_first_archive=1`;

        const response = await axios.post(apiUrl, data, {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Authorization': `LOW ${access}:${secret}`,
            'Accept': 'application/json',
          },
        });

        if (response.status === 200) {
          // Handle success
          console.log(response)
          console.log('URL archived successfully!');
        } else {
          console.error('Failed to archive URL. HTTP Status:', response.status);
        }
      } catch (error) {
        console.error('Error archiving URL:', error.message);
      }
  } else {
    console.error("No Archive access")
  }

I haven't figured out how to test if it works yet because I'm not entirely certain how often the archive's webcrawlers run after making a request It works now, this new function requires an API key from the internet archive though. But it might be useful to store the archived url alongside the actual url in case your bookmark gets removed years from now. Obviously if this does get implemented later on I would think we'd need to make it an optional thing in the settings, but I have ran into issues where a blog post I've saved disappears or moves after awhile and then I've lost it so hopefully this resolves that problem.

Edit: updated the function to one that works more effectively (explained here https://github.com/TomCasavant/tom-postmarks#features if someone needs it)

@ckolderup
Copy link
Owner

That's neat! I have some vague desire to support some kind of plugin system for things like this, though I haven't really thought about how we'd support it architecturally. I'd like to avoid having a preferences screen a mile long, and it seems like everyone having their own install of Postmarks lends nicely to supporting a way to bring in external packages on a per-install basis. This would be a great candidate for that kind of thing, imo.

(The other thought I had at an earlier point was to support webhooks as a kind of complement to the simple API (#61), so the API would be responsible for handling data coming into Postmarks, and webhooks would be responsible for handling data going out. But being a good webhooks provider would involve a significant increase in architectural needs, since we'd need to queue the calls asynchronously and manage retries, etc. So I think that's probably out of scope.)

@ckolderup ckolderup added the enhancement New feature or request label Oct 17, 2023
@andypiper
Copy link
Collaborator

Just dropped by to say that I ❤️ this idea - will definitely be looking at adding the same hook into my fork at some stage. Thanks for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants