utilities/auto-blog-link-preserver#8: Submit links into LinkWarden



Issue Information

Issue Type: issue
Status: closed
Reported By: btasker
Assigned To: btasker

Milestone: v0.1
Created: 10-Aug-24 19:08



Description

We need to remove the ArchiveBox related code and then look at integrating against LinkWarden's API



Toggle State Changes

Activity


assigned to @btasker

So, as a quick example, when I use the browser UI (which just talks to the APIs) to add a link into a collection called "Sitelinks", it posts the following to /api/v1/links

{
"name":"",
"url":"https://www.bentasker.co.uk/posts/blog/house-stuff/removing-bamboo-from-our-garden.html",
"description":"",
"type":"url",
"tags":[],
"preview":"",
"image":"",
"pdf":"",
"readable":"",
"monolith":"",
"textContent":"",
"collection":{"id":2,"name":"Site Links","ownerId":1}
}

So, we probably just need to do similar (tomorrow, I want to look at whether we can auto-matically include tags too, that'd be really useful)

Decided not to wait til the morning.

Taking a quick look, submitting with tags looks like this

{
  "name":"",
  "url":"https://www.bentasker.co.uk/posts/blog/software-development/troubleshooting-file-upload-validation-errors-on-images.html",
  "description":"",
  "type":"url",
  "tags":[
      {"name":"PHP"},
      {"name":"Laravel"}
  ],
  "preview":"",
  "image":"",
  "pdf":"",
  "readable":"",
  "monolith":"",
  "textContent":"",
  "collection":{
     "id":2,
     "name":"Site Links",
     "ownerId":1
  }
}

So, lets grab a token and see if we can submit something with curl

curl \
-v \
-H "Authorization: Bearer $WARDEN_TOKEN" \
-H "Content-type: application/json" \
-d '{"name":"","url":"https://www.bentasker.co.uk/posts/documentation/linux/286-implementing-secure-password-storage-with-phpcredlocker-and-a-raspberry-pi.html","description":"","type":"url","tags":[{"name":"PHP"}, {"name":"SiteLinks"}],"preview":"","image":"","pdf":"","readable":"","monolith":"","textContent":"","collection":{"id":2,"name":"Site Links","ownerId":1}}' \
https://$DOMAIN/api/v1/links

That responded immediately with a 200 and the following response body

{"response":{"id":7,"name":"Implementing Secure Password Storage with PHPCredlocker and a Raspberry Pi | www.bentasker.co.uk","type":"url","description":"","collectionId":2,"url":"https://www.bentasker.co.uk/posts/documentation/linux/286-implementing-secure-password-storage-with-phpcredlocker-and-a-raspberry-pi.html","textContent":null,"preview":null,"image":null,"pdf":null,"readable":null,"monolith":null,"lastPreserved":null,"importDate":null,"createdAt":"2024-08-10T22:34:32.275Z","updatedAt":"2024-08-10T22:34:32.275Z","tags":[{"id":1,"name":"PHP","ownerId":1,"createdAt":"2024-08-10T22:27:39.758Z","updatedAt":"2024-08-10T22:27:39.758Z"},{"id":3,"name":"SiteLinks","ownerId":1,"createdAt":"2024-08-10T22:34:32.275Z","updatedAt":"2024-08-10T22:34:32.275Z"}],"collection":{"id":2,"name":"Site Links","description":"","color":"[#0](/issue/utilities/auto-blog-link-preserver/0.html)ea5e9","parentId":null,"isPublic":false,"ownerId":1,"createdAt":"2024-08-10T19:16:20.045Z","updatedAt":"2024-08-10T19:16:20.045Z"}}}

So, we just need to update the script to do that in python

verified

mentioned in commit 868eea5f0c3c9ddd63fd730a10b1fda3d7586087

Commit: 868eea5f0c3c9ddd63fd730a10b1fda3d7586087 
Author: B Tasker                            
                            
Date: 2024-08-10T23:37:13.000+01:00 

Message

chore: strip out the old ArchiveBox functions (utilities/auto-blog-link-preserver#8)

+5 -45 (50 lines changed)
verified

mentioned in commit cde543d9ee03d22c0bca67c8bd6900d7f2e3c6e8

Commit: cde543d9ee03d22c0bca67c8bd6900d7f2e3c6e8 
Author: B Tasker                            
                            
Date: 2024-08-10T23:46:26.000+01:00 

Message

feat: implement submission of links into LinkWarden (utilities/auto-blog-link-preserver#8)

+49 -6 (55 lines changed)

OK, submission is working - the script has just happily worked through my RSS feed extracting links from each of the posts and submitting them

Picture of LinkWarden dashboard

There wasn't a single failure in submission.

However, this ticket is not complete yet. The collection ID is currently hardcoded, we need to change that.

The options are

  • Have the operator (optionally) provide it (bit of a pain to lookup the details)
  • See if there's an API call we can make at startup to obtain the details

Looks like we can do a GET to /api/v1/collections

verified

mentioned in commit 5aba0a3e00f136945ef278372ff817f5ac530834

Commit: 5aba0a3e00f136945ef278372ff817f5ac530834 
Author: B Tasker                            
                            
Date: 2024-08-11T00:03:56.000+01:00 

Message

feat: allow submissions to be placed into a named collection (utilities/auto-blog-link-preserver#8)

+44 -6 (50 lines changed)

The script will now look up the collection name is one is defined. It can be defined with LINKWARDEN_COLLECTION_NAME.

So, to have links go into a collection called Site Links and tagged with SiteLinks and anti-link-rot you'd have

export LINKWARDEN_COLLECTION_NAME="Site Links"
export LINKWARDEN_TAGS="SiteLinks,anti-link-rot"
export LINKWARDEN_URL="https://mylinkwarden.invalid"
export LINKWARDEN_TOKEN="aaabbbcccdddeee"