Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

订阅源Web读取导入URL #219

Merged
merged 1 commit into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions entry/src/main/ets/componets/import/SubscriptionImport.ets
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ export default struct SubscriptionImport {
}
// 向当前group的list中添加BookSource对象
groupMap[title].list.push(item);
} else {
if (!groupMap['其他']) {
groupMap['其他'] = { title: '其他', list: [] };
}
groupMap['其他'].list.push(item);
}
for (let i = 0; i < this.localSourceList.length; i++) {
const localItem = this.localSourceList[i];
Expand Down
2 changes: 1 addition & 1 deletion entry/src/main/ets/database/entities/rssSources.ets
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const SUBSCRIPTION_GROUP_TYPE: Record<number, string> ={
0: '小说',
1: '漫画',
2: '影视',
3: '咨询',
3: '资讯',
4: '收藏夹'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* @datetime 2024/7/13 23:33
* @className: SubscriptionSearch
* 订阅搜索页面
* TODO 测试页面后续调整改为DB数据查询和数据读取
*/
import CommonConstants from '../../../../common/constants/CommonConstants';
import FontConstants from '../../../../common/constants/FontConstants';
Expand Down
47 changes: 32 additions & 15 deletions entry/src/main/ets/pages/view/Subscription/rssWebView.ets
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { webview } from '@kit.ArkWeb';
import { router } from '@kit.ArkUI';
import { showMessage } from '../../../componets/common/promptShow';
import { loginComponentManager } from '@kit.AccountKit';
import ImportCommon from '../../../componets/import/ImportCommon';
import { BookSource } from '../../../database/entities/BookSource';
import { getPasteDataSync, isNetworkUrl, sleep } from '../../../common/utils/utils';
import { isNetworkUrl, sleep } from '../../../common/utils/utils';
import axios, { AxiosResponse } from '@ohos/axios';
import SubscriptionImport from '../../../componets/import/SubscriptionImport';
import { rssListRule } from '../../../database/entities/rule/rssListRule';
import { rssSources } from '../../../database/entities/rssSources';

interface RouteParams {
Expand All @@ -23,6 +21,7 @@ struct RssWebView {
webviewController: webview.WebviewController = new webview.WebviewController();
regex:string = `/booksource/importonline\\?src=(http[s]?://[^/]+/[^\"']+)`;
regexRss:string = `/rsssource/importonline\\?src=(http[s]?://[^/]+/[^\"']+)`;
legadoRegex:string = `/import/auto\\?src=(http[s]?://[^/]+/[^\"']+)`
aboutToAppear(): void {
const params = router.getParams() as RouteParams;
this.sourcesUrl = params.url
Expand All @@ -44,15 +43,23 @@ struct RssWebView {
Column(){
Web({ src: this.sourcesUrl, controller: this.webviewController })
.onLoadIntercept((event) => {
let url = event.data.getRequestUrl()
let url = decodeURIComponent(event.data.getRequestUrl());
const match = url.match(this.regex);
if (match && match[1]) {
this.pasteAnalyzeBookSource(match[1])
let urlBook = decodeURIComponent(match[1]);
this.pasteAnalyzeBookSource(urlBook)
this.webviewController.loadUrl(this.sourcesUrl)
}
const matchRss = url.match(this.regexRss);
if (matchRss && matchRss[1]) {
this.pasteAnalyzeRssSource(matchRss[1])
let urlRss = decodeURIComponent(matchRss[1]);
this.pasteAnalyzeRssSource(urlRss)
this.webviewController.loadUrl(this.sourcesUrl)
}
const legadoMatch = url.match(this.legadoRegex);
if (legadoMatch && legadoMatch[1]) {
let urlLegado= decodeURIComponent(legadoMatch[1]);
showMessage(urlLegado) //todo 替换规则导入
this.webviewController.loadUrl(this.sourcesUrl)
}
return false
Expand Down Expand Up @@ -107,11 +114,16 @@ struct RssWebView {
showMessage('链接不正确')
return
}
const res: AxiosResponse = await axios
.get(url ?? 'https://node.wisdoms.xin/static/file/20240704/sy.json');
this.sourceList = res.data;
this.isShowImportBookSource = true;
const res: AxiosResponse = await axios.get(url ?? 'https://node.wisdoms.xin/static/file/20240704/sy.json');
if (res) {
console.log('res', JSON.stringify(res))
this.sourceList = res.data;
this.isShowImportBookSource = true;
} else {
showMessage('订阅源解析失败')
}
} catch (err) {
showMessage('订阅源解析失败')
console.error('错误 ' + err);
}
}
Expand All @@ -127,12 +139,17 @@ struct RssWebView {
showMessage('链接不正确')
return
}
const res: AxiosResponse = await axios
.get(url ?? 'http://yuedu.miaogongzi.net/shuyuan/miaogongziDY.json');
console.log('res', JSON.stringify(res))
this.subscriptionList = res.data;
this.isShowImportRssSources = true;
const res: AxiosResponse = await axios.get(url ?? 'http://yuedu.miaogongzi.net/shuyuan/miaogongziDY.json');
if (res) {
console.log('res', JSON.stringify(res))
this.subscriptionList = res.data;
this.isShowImportRssSources = true;
} else {
showMessage('订阅源解析失败')
}

} catch (err) {
showMessage('订阅源解析失败')
console.error('错误 ' + err);
}
}
Expand Down
2 changes: 1 addition & 1 deletion entry/src/main/ets/preferences/programDataPreferences.ets
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import CommonConstants from '../common/constants/CommonConstants'
import bookDataPreferences from '../common/utils/DataPreferencesUtils'

export class programDataPreferences {
readonly rssSourcesGroup: string[] = ['小说', '漫画', '影视', '咨询', '收藏夹']
readonly rssSourcesGroup: string[] = ['小说', '漫画', '影视', '资讯', '收藏夹']
initProgramDataPreferences = () => {
//内容数据持久化
//订阅源分组数据
Expand Down
Loading