Repository: sissbruecker/linkding
Pull request #655 (2024-03-17 08:49:31)

Include web archive link in /api/bookmarks/
Closes https://github.com/sissbruecker/linkding/issues/573


Patch:
diff --git a/bookmarks/api/serializers.py b/bookmarks/api/serializers.py
index 6fd437a..6e82e33 100644
--- a/bookmarks/api/serializers.py
+++ b/bookmarks/api/serializers.py
@@ -30,6 +30,7 @@ class BookmarkSerializer(serializers.ModelSerializer):
             "notes",
             "website_title",
             "website_description",
+            "web_archive_snapshot_url",
             "is_archived",
             "unread",
             "shared",
@@ -40,6 +41,7 @@ class BookmarkSerializer(serializers.ModelSerializer):
         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 533cf43..8099f51 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 069be5f..b0db26e 100644
--- a/bookmarks/tests/helpers.py
+++ b/bookmarks/tests/helpers.py
@@ -84,6 +84,7 @@ class BookmarkFactoryMixin:
         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 @@ class BookmarkFactoryMixin:
             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 @@ class BookmarkFactoryMixin:
                 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 d3d0b6c..dae6754 100644
--- a/bookmarks/tests/test_bookmarks_api.py
+++ b/bookmarks/tests/test_bookmarks_api.py
@@ -35,6 +35,7 @@ class BookmarksApiTestCase(LinkdingApiTestCase, BookmarkFactoryMixin):
             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 @@ class BookmarksApiTestCase(LinkdingApiTestCase, BookmarkFactoryMixin):
         )
         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 @@ class BookmarksApiTestCase(LinkdingApiTestCase, BookmarkFactoryMixin):
         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()