From b8b505b8f7596f2d8ea1e850dd2ae2798985290e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=B5=A9=E8=BF=9C?= Date: Sat, 26 Dec 2020 11:07:42 +0800 Subject: [PATCH] tweak inoreader behaviors --- .../settings/services/inoreader.tsx | 15 +++++++---- src/scripts/i18n/en-US.json | 1 + src/scripts/i18n/zh-CN.json | 1 + src/scripts/models/services/greader.ts | 25 +++++++++++-------- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/components/settings/services/inoreader.tsx b/src/components/settings/services/inoreader.tsx index 7858052..017ee73 100644 --- a/src/components/settings/services/inoreader.tsx +++ b/src/components/settings/services/inoreader.tsx @@ -3,9 +3,9 @@ import intl from "react-intl-universal" import { ServiceConfigsTabProps } from "../service" import { GReaderConfigs } from "../../../scripts/models/services/greader" import { SyncService } from "../../../schema-types" -import { Stack, Icon, Label, TextField, PrimaryButton, DefaultButton, Checkbox, MessageBar, MessageBarType, Dropdown, IDropdownOption } from "@fluentui/react" +import { Stack, Label, TextField, PrimaryButton, DefaultButton, Checkbox, + MessageBar, MessageBarType, Dropdown, IDropdownOption, MessageBarButton } from "@fluentui/react" import DangerButton from "../../utils/danger-button" -import { urlTest } from "../../../scripts/utils" type GReaderConfigsTabState = { existing: boolean @@ -22,6 +22,8 @@ const endpointOptions: IDropdownOption[] = [ "https://jp.inoreader.com" ].map(s => ({ key: s, text: s })) +const openSupport = () => window.utils.openExternal("https://github.com/yang991178/fluent-reader/wiki/Support#inoreader") + class InoreaderConfigsTab extends React.Component { constructor(props: ServiceConfigsTabProps) { super(props) @@ -41,8 +43,6 @@ class InoreaderConfigsTab extends React.Component { this.setState({ fetchLimit: option.key as number }) @@ -104,11 +104,16 @@ class InoreaderConfigsTab extends React.Component + }> + {intl.get("service.rateLimitWarning")} + {!this.state.existing && ( {intl.get("service.overwriteWarning")} )} - + diff --git a/src/scripts/i18n/en-US.json b/src/scripts/i18n/en-US.json index e226fe3..e7e5c0a 100644 --- a/src/scripts/i18n/en-US.json +++ b/src/scripts/i18n/en-US.json @@ -191,6 +191,7 @@ "suggest": "Suggest a new service", "overwriteWarning": "Local sources will be deleted if they exist in the service.", "groupsWarning": "Groups aren't automatically synced with the service.", + "rateLimitWarning": "If connection errors persist, the app may have been rate limited by the service.", "endpoint": "Endpoint", "username": "Username", "password": "Password", diff --git a/src/scripts/i18n/zh-CN.json b/src/scripts/i18n/zh-CN.json index 8fda473..97c7bb8 100644 --- a/src/scripts/i18n/zh-CN.json +++ b/src/scripts/i18n/zh-CN.json @@ -189,6 +189,7 @@ "suggest": "建议一项新服务", "overwriteWarning": "若本地与服务端存在URL相同的订阅源,则本地订阅源将被删除", "groupsWarning": "分组不会自动与服务端保持同步", + "rateLimitWarning": "若反复出现错误,则原因可能是应用被服务限流", "endpoint": "端点", "username": "用户名", "password": "密码", diff --git a/src/scripts/models/services/greader.ts b/src/scripts/models/services/greader.ts index d1c42cb..d3b4b8c 100644 --- a/src/scripts/models/services/greader.ts +++ b/src/scripts/models/services/greader.ts @@ -6,7 +6,7 @@ import { ServiceConfigs, SyncService } from "../../../schema-types" import { createSourceGroup } from "../group" import { RSSSource } from "../source" import { RSSItem } from "../item" -import { domParser } from "../../utils" +import { domParser, htmlDecode } from "../../utils" import { SourceRule } from "../rule" const ALL_TAG = "user/-/state/com.google/reading-list" @@ -156,7 +156,8 @@ export const gReaderServiceHooks: ServiceHooks = { let continuation: string do { try { - let params = "/reader/api/0/stream/contents?output=json&n=125" + const limit = Math.min(configs.fetchLimit - items.length, 1000) + let params = `/reader/api/0/stream/contents?output=json&n=${limit}` if (configs.lastFetched) params += `&ot=${configs.lastFetched}` if (continuation) params += `&c=${continuation}` const response = await fetchAPI(configs, params) @@ -164,7 +165,7 @@ export const gReaderServiceHooks: ServiceHooks = { fetchedItems = fetched.items for (let i of fetchedItems) { i.id = compactId(i.id, configs.useInt64) - if (i.id === configs.lastId) { + if (i.id === configs.lastId || items.length >= configs.fetchLimit) { break } else { items.push(i) @@ -174,11 +175,7 @@ export const gReaderServiceHooks: ServiceHooks = { } catch { break } - } while ( - continuation && - fetchedItems && fetchedItems.length >= 125 && - items.length < configs.fetchLimit - ) + } while (continuation && items.length < configs.fetchLimit) if (items.length > 0) { configs.lastId = items[0].id const fidMap = new Map() @@ -212,13 +209,21 @@ export const gReaderServiceHooks: ServiceHooks = { dom.head.append(baseEl) let img = dom.querySelector("img") if (img && img.src) item.thumb = img.src + if (configs.type == SyncService.Inoreader) item.title = htmlDecode(item.title) for (let c of i.categories) { if (!item.hasRead && c.endsWith("/state/com.google/read")) item.hasRead = true else if (!item.starred && c.endsWith("/state/com.google/starred")) item.starred = true } // Apply rules and sync back to the service - if (source.rules) SourceRule.applyAll(source.rules, item) - // TODO + if (source.rules) { + const hasRead = item.hasRead + const starred = item.starred + SourceRule.applyAll(source.rules, item) + if (item.hasRead !== hasRead) + editTag(configs, item.serviceRef, READ_TAG, item.hasRead) + if (item.starred !== starred) + editTag(configs, item.serviceRef, STAR_TAG, item.starred) + } parsedItems.push(item) }) if (parsedItems.length > 0) {