From d9ab4bf953f199374fa9d71a369f32fe6cb83108 Mon Sep 17 00:00:00 2001 From: yssk22 Date: Wed, 20 Aug 2025 05:38:36 +0000 Subject: [PATCH] [expo] update UserAgent and add fallback when Ameblo optimization doesn't work. **Summary** ^^ **Test** - expo **Issue** - N/A --- expo/app.config.default.js | 1 + .../internals/FeedItemAmebloOptimizedView.tsx | 37 +++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/expo/app.config.default.js b/expo/app.config.default.js index 892f9053..19a27d47 100644 --- a/expo/app.config.default.js +++ b/expo/app.config.default.js @@ -42,6 +42,7 @@ module.exports = { usesNonExemptEncryption: false }, infoPlist: { + ITSAppUsesNonExemptEncryption: false, CFBundleAllowMixedLocalizations: true, NSAppTransportSecurity: { NSExceptionDomains: { diff --git a/expo/features/feed/internals/FeedItemAmebloOptimizedView.tsx b/expo/features/feed/internals/FeedItemAmebloOptimizedView.tsx index 9f2fb751..ff2cdfe2 100644 --- a/expo/features/feed/internals/FeedItemAmebloOptimizedView.tsx +++ b/expo/features/feed/internals/FeedItemAmebloOptimizedView.tsx @@ -16,28 +16,43 @@ export default function FeedItemAmebloOptimizedView({ url }: FeedItemAmebloOptim // TODO: Use the optimized content for web return
Post content here
; } + if (state.data?.optimizedHtml) { + return ( + <> + + + ); + } + // fallback return ( <> - + ); } const UserAgent = - 'Mozilla/5.0 (Linux; Android 11; Pixel 5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.91 Mobile Safari/537.36'; + 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1'; const AmebloEntryIDUrlRegExp = /\/([^/]+)\/entry-(\d+)\.html/; const AmebloInitDataRegExp = /\s*window\.INIT_DATA\s*=\s*(\{.*\});\s*window\.RESOURCE_BASE_URL/; // /(?s)window\.INIT_DATA\s*=\s*(\{.*\});\s*window\.RESOURCE_BASE_URL/; -async function getAmebloOptimizedContent(url: string): Promise { +type AmebloContent = { + originalHtml: string; + optimizedHtml?: string; +}; + +async function getAmebloOptimizedContent(url: string): Promise { const matched = url.match(AmebloEntryIDUrlRegExp); if (matched == null || matched.length < 3) { - return ''; + throw new Error('invalid URL'); } const id = matched[2]; const { html } = await fetchContent(url); - const entryText = extractEntryText(html, id); - return ` - + try { + const entryText = extractEntryText(html, id); + return { + originalHtml: html, + optimizedHtml: ` @@ -65,7 +80,13 @@ async function getAmebloOptimizedContent(url: string): Promise { - `; + ` + }; + } catch { + return { + originalHtml: html + }; + } } function extractEntryText(html: string, id: string) {