Repository: sissbruecker/linkding

Issue:
Include Web Archive Link In /api/bookmarks/
It could be useful if `/api/bookmarks` would return results that included the web archive link. I haven't checked the codebase, but I assume it would be reasonably easy to add a new field. What do you think? I personally backup my bookmarks via the API and it'd be great to also have the Web Archive link.


Discussion:

Patch:
diff --git a/bookmarks/api/serializers.py b/bookmarks/api/serializers.py
index 6fd437a5..6e82e339 100644
--- a/bookmarks/api/serializers.py
+++ b/bookmarks/api/serializers.py
@@ -30,6 +30,7 @@ class Meta:
             "notes",
             "website_title",
             "website_description",
+            "web_archive_snapshot_url",
             "is_archived",
             "unread",
             "shared",
@@ -40,6 +41,7 @@ class Meta:
         read_only_fields = [
             "website_title",
             "website_description",
+            "web_archive_snapshot_url",
             "date_added",
             "date_modified",
         ]
diff --git a/docs/API.md b/docs/API.md
index 533cf43a..8099f519 100644
--- a/docs/API.md
+++ b/docs/API.md
@@ -48,6 +48,7 @@ Example response:
       "notes": "Example notes",
       "website_title": "Website title",
       "website_description": "Website description",
+      "web_archive_snapshot_url": "https://web.archive.org/web/20200926094623/https://example.com",
       "is_archived": false,
       "unread": false,
       "shared": false,


Test patch:
diff --git a/bookmarks/tests/helpers.py b/bookmarks/tests/helpers.py
index 069be5fc..b0db26e1 100644
--- a/bookmarks/tests/helpers.py
+++ b/bookmarks/tests/helpers.py
@@ -84,6 +84,7 @@ def setup_numbered_bookmarks(
         unread: bool = False,
         shared: bool = False,
         with_tags: bool = False,
+        with_web_archive_snapshot_url: bool = False,
         user: User = None,
     ):
         user = user or self.get_or_create_test_user()
@@ -112,6 +113,9 @@ def setup_numbered_bookmarks(
             if with_tags:
                 tag_name = f"{tag_prefix} {i}{suffix}"
                 tags = [self.setup_tag(name=tag_name, user=user)]
+            web_archive_snapshot_url = ""
+            if with_web_archive_snapshot_url:
+                web_archive_snapshot_url = f"https://web.archive.org/web/{i}"
             bookmark = self.setup_bookmark(
                 url=url,
                 title=title,
@@ -119,6 +123,7 @@ def setup_numbered_bookmarks(
                 unread=unread,
                 shared=shared,
                 tags=tags,
+                web_archive_snapshot_url=web_archive_snapshot_url,
                 user=user,
             )
             bookmarks.append(bookmark)
diff --git a/bookmarks/tests/test_bookmarks_api.py b/bookmarks/tests/test_bookmarks_api.py
index d3d0b6cd..dae67548 100644
--- a/bookmarks/tests/test_bookmarks_api.py
+++ b/bookmarks/tests/test_bookmarks_api.py
@@ -35,6 +35,7 @@ def assertBookmarkListEqual(self, data_list, bookmarks):
             expectation["notes"] = bookmark.notes
             expectation["website_title"] = bookmark.website_title
             expectation["website_description"] = bookmark.website_description
+            expectation["web_archive_snapshot_url"] = bookmark.web_archive_snapshot_url
             expectation["is_archived"] = bookmark.is_archived
             expectation["unread"] = bookmark.unread
             expectation["shared"] = bookmark.shared
@@ -61,6 +62,17 @@ def test_list_bookmarks(self):
         )
         self.assertBookmarkListEqual(response.data["results"], bookmarks)
 
+    def test_list_bookmarks_with_more_details(self):
+        self.authenticate()
+        bookmarks = self.setup_numbered_bookmarks(
+            5, with_tags=True, with_web_archive_snapshot_url=True
+        )
+
+        response = self.get(
+            reverse("bookmarks:bookmark-list"), expected_status_code=status.HTTP_200_OK
+        )
+        self.assertBookmarkListEqual(response.data["results"], bookmarks)
+
     def test_list_bookmarks_does_not_return_archived_bookmarks(self):
         self.authenticate()
         bookmarks = self.setup_numbered_bookmarks(5)
@@ -436,6 +448,18 @@ def test_get_bookmark(self):
         response = self.get(url, expected_status_code=status.HTTP_200_OK)
         self.assertBookmarkListEqual([response.data], [bookmark])
 
+    def test_get_bookmark_with_more_details(self):
+        self.authenticate()
+        tag1 = self.setup_tag()
+        bookmark = self.setup_bookmark(
+            web_archive_snapshot_url="https://web.archive.org/web/1/",
+            tags=[tag1],
+        )
+
+        url = reverse("bookmarks:bookmark-detail", args=[bookmark.id])
+        response = self.get(url, expected_status_code=status.HTTP_200_OK)
+        self.assertBookmarkListEqual([response.data], [bookmark])
+
     def test_update_bookmark(self):
         self.authenticate()
         bookmark = self.setup_bookmark()