diff --git a/artifacts/postiz-mobile/app/(tabs)/compose.tsx b/artifacts/postiz-mobile/app/(tabs)/compose.tsx index f774cc2..ff359cf 100644 --- a/artifacts/postiz-mobile/app/(tabs)/compose.tsx +++ b/artifacts/postiz-mobile/app/(tabs)/compose.tsx @@ -767,6 +767,7 @@ export default function ComposeScreen() { workspaces={workspaces} maxSelect={MAX_IMAGES - mediaItems.length} onClose={() => setShowMediaLibrary(false)} + onPickFromDevice={() => { setShowMediaLibrary(false); pickImage(); }} onSelect={(items: LibraryMediaItem[]) => { setMediaItems((prev) => [ diff --git a/artifacts/postiz-mobile/components/MediaLibraryModal.tsx b/artifacts/postiz-mobile/components/MediaLibraryModal.tsx index aaa61df..ae6987d 100644 --- a/artifacts/postiz-mobile/components/MediaLibraryModal.tsx +++ b/artifacts/postiz-mobile/components/MediaLibraryModal.tsx @@ -35,6 +35,7 @@ interface Props { maxSelect: number; onClose: () => void; onSelect: (items: LibraryMediaItem[]) => void; + onPickFromDevice?: () => void; } function resolveUrl(path: string, baseUrl: string): string { @@ -43,7 +44,7 @@ function resolveUrl(path: string, baseUrl: string): string { return `${origin}/${path.replace(/^\//, "")}`; } -export function MediaLibraryModal({ visible, workspaces, defaultWorkspaceId, maxSelect, onClose, onSelect }: Props) { +export function MediaLibraryModal({ visible, workspaces, defaultWorkspaceId, maxSelect, onClose, onSelect, onPickFromDevice }: Props) { const colors = useColors(); const insets = useSafeAreaInsets(); const [activeId, setActiveId] = useState(""); @@ -66,17 +67,19 @@ export function MediaLibraryModal({ visible, workspaces, defaultWorkspaceId, max if (!activeWorkspace) return; setLoading(true); setError(null); - const url = `${activeWorkspace.baseUrl}/media`; + const apiBase = activeWorkspace.baseUrl.replace(/\/public\/v1$/, ""); + const url = `${apiBase}/media?page=0&search=`; try { // eslint-disable-next-line no-undef const res = await globalThis.fetch(url, { headers: { Authorization: activeWorkspace.apiKey }, }); if (!res.ok) { + if (res.status === 401 || res.status === 403) { + throw new Error("SESSION_REQUIRED"); + } if (res.status === 404) { - throw new Error( - `Media listing endpoint not found (404).\nURL tried: ${url}\n\nThis feature requires Postiz to expose GET /media in its public API. Your version may not support it yet.` - ); + throw new Error("ENDPOINT_NOT_FOUND"); } throw new Error(`HTTP ${res.status} — ${url}`); } @@ -171,6 +174,29 @@ export function MediaLibraryModal({ visible, workspaces, defaultWorkspaceId, max + ) : error === "SESSION_REQUIRED" ? ( + + + + {"Media library requires a web session.\nAPI key access is not supported by Postiz."} + + {onPickFromDevice && ( + { onClose(); onPickFromDevice(); }} + style={[styles.retryBtn, { backgroundColor: colors.primary }]} + activeOpacity={0.8} + > + Use device gallery + + )} + + ) : error === "ENDPOINT_NOT_FOUND" ? ( + + + + {"Media library endpoint not found on this server."} + + ) : error ? (