Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

feat(mobile): open saved items in webview

daniel31x13b7c0cef8deab
diff --git a/apps/mobile/app/links/[id].tsx b/apps/mobile/app/links/[id].tsx
index 7b5572ea..b9fb3aad 100644
--- a/apps/mobile/app/links/[id].tsx
+++ b/apps/mobile/app/links/[id].tsx
@@ -1,17 +1,11 @@
-import {
- View,
- StyleSheet,
- ActivityIndicator,
- Text,
- // Platform,
-} from "react-native";
+import { View, StyleSheet, ActivityIndicator, Text } from "react-native";
import { WebView } from "react-native-webview";
import useAuthStore from "@/store/auth";
import { useLocalSearchParams } from "expo-router";
import { useGetLink } from "@linkwarden/router/links";
import { useUser } from "@linkwarden/router/user";
import { useEffect, useState } from "react";
-// import { generateLinkHref } from "@linkwarden/lib/generateLinkHref";
+import { generateLinkHref } from "@linkwarden/lib/generateLinkHref";
export default function HomeScreen() {
const { auth } = useAuthStore();
@@ -24,8 +18,9 @@ export default function HomeScreen() {
useEffect(() => {
async function fetchLinkData() {
const link = await getLink.mutateAsync({ id: Number(id) });
- if (link && link.url) {
- setUrl(link.url);
+
+ if (link) {
+ setUrl(generateLinkHref(link, user[0], auth.instance, true));
}
}
@@ -47,7 +42,10 @@ export default function HomeScreen() {
flex: 1,
}),
}}
- source={{ uri: url }}
+ source={{
+ uri: url,
+ headers: { Authorization: `Bearer ${auth.session}` },
+ }}
onLoadEnd={() => setIsLoading(false)}
/>
)}
diff --git a/packages/lib/generateLinkHref.ts b/packages/lib/generateLinkHref.ts
index acefbf68..af4ace86 100644
--- a/packages/lib/generateLinkHref.ts
+++ b/packages/lib/generateLinkHref.ts
@@ -9,16 +9,23 @@ import { formatAvailable } from "@linkwarden/lib/formatStats";
export const generateLinkHref = (
link: LinkIncludingShortenedCollectionAndTags,
account: AccountSettings,
- instanceURL: string | null = ""
+ instanceURL: string | null = "",
+ apiEndpoint: boolean = false
): string => {
// Return the links href based on the account's preference
// If the user's preference is not available, return the original link
+
+ let endpoint = "/preserved";
+ if (apiEndpoint) {
+ endpoint = "/api/v1/archives";
+ }
+
if (account.linksRouteTo === LinksRouteTo.ORIGINAL && link.type === "url") {
return link.url || "";
} else if (account.linksRouteTo === LinksRouteTo.PDF || link.type === "pdf") {
if (!formatAvailable(link, "pdf")) return link.url || "";
- return instanceURL + `/preserved/${link?.id}?format=${ArchivedFormat.pdf}`;
+ return instanceURL + `${endpoint}/${link?.id}?format=${ArchivedFormat.pdf}`;
} else if (
account.linksRouteTo === LinksRouteTo.READABLE &&
link.type === "url"
@@ -27,7 +34,7 @@ export const generateLinkHref = (
return (
instanceURL +
- `/preserved/${link?.id}?format=${ArchivedFormat.readability}`
+ `${endpoint}/${link?.id}?format=${ArchivedFormat.readability}`
);
} else if (
account.linksRouteTo === LinksRouteTo.SCREENSHOT ||
@@ -37,7 +44,7 @@ export const generateLinkHref = (
return (
instanceURL +
- `/preserved/${link?.id}?format=${
+ `${endpoint}/${link?.id}?format=${
link?.image?.endsWith("png") ? ArchivedFormat.png : ArchivedFormat.jpeg
}`
);
@@ -45,7 +52,7 @@ export const generateLinkHref = (
if (!formatAvailable(link, "monolith")) return link.url || "";
return (
- instanceURL + `/preserved/${link?.id}?format=${ArchivedFormat.monolith}`
+ instanceURL + `${endpoint}/${link?.id}?format=${ArchivedFormat.monolith}`
);
} else {
return link.url || "";