app/lib/api/rss.dart

32 lines
1003 B
Dart
Raw Normal View History

import 'dart:io';
import 'package:dart_rss/dart_rss.dart';
import 'package:dio/dio.dart';
2024-01-29 20:44:00 +08:00
import 'package:starcitizen_doctor/common/conf/url_conf.dart';
class RSSApi {
static final _dio = Dio(BaseOptions(
connectTimeout: const Duration(seconds: 10),
responseType: ResponseType.plain));
static Future<List<RssItem>> getRssVideo() async {
2024-01-29 20:44:00 +08:00
final r = await _dio.get(URLConf.rssVideoUrl);
final f = RssFeed.parse(r.data);
return f.items.sublist(0, 8);
}
static Future<List<RssItem>> getRssText() async {
2024-01-29 20:44:00 +08:00
final r1 = await _dio.get(URLConf.rssTextUrl1);
final r1f = RssFeed.parse(r1.data);
2024-01-29 20:44:00 +08:00
final r2 = await _dio.get(URLConf.rssTextUrl2);
final r2f = RssFeed.parse(r2.data);
final items = r1f.items..addAll(r2f.items);
items.sort((a, b) {
final aDate = HttpDate.parse(a.pubDate ?? "").millisecondsSinceEpoch;
final bDate = HttpDate.parse(b.pubDate ?? "").millisecondsSinceEpoch;
return bDate - aDate;
});
return items;
}
}