From 5d981f6bdb29606ff099d0dd0bada8eb329d0c0f Mon Sep 17 00:00:00 2001 From: BrightDV <92821484+BrightDV@users.noreply.github.com> Date: Fri, 19 Jul 2024 11:45:34 +0200 Subject: [PATCH] [server] update new bbs routes --- lib/Screens/racehub.dart | 6 ++-- lib/api/event_tracker.dart | 10 +++++-- lib/api/formula1.dart | 56 +++++++++++++++++++++++++---------- lib/api/formulae.dart | 24 +++++++-------- lib/api/videos.dart | 14 +++++++-- lib/helpers/download.dart | 4 ++- lib/scraping/fia.dart | 2 +- lib/scraping/formula_one.dart | 14 ++++----- lib/scraping/formulae.dart | 10 ++++++- 9 files changed, 94 insertions(+), 46 deletions(-) diff --git a/lib/Screens/racehub.dart b/lib/Screens/racehub.dart index 26f88bd..0de9f73 100644 --- a/lib/Screens/racehub.dart +++ b/lib/Screens/racehub.dart @@ -689,7 +689,8 @@ class SessionItem extends StatelessWidget { children: [ Text( sessionsAbbreviations[ - session.sessionsAbbreviation], + session.sessionsAbbreviation] ?? + session.sessionsAbbreviation, style: TextStyle( fontSize: 20, ), @@ -770,7 +771,8 @@ class SessionItem extends StatelessWidget { context, MaterialPageRoute( builder: (context) => SessionScreen( - sessionsAbbreviations[session.sessionsAbbreviation], + sessionsAbbreviations[session.sessionsAbbreviation] ?? + session.sessionsAbbreviation, session, meetingCountryName, meetingOfficialName, diff --git a/lib/api/event_tracker.dart b/lib/api/event_tracker.dart index 2c1fbee..fec9435 100644 --- a/lib/api/event_tracker.dart +++ b/lib/api/event_tracker.dart @@ -94,7 +94,9 @@ class EventTracker { if (championship == 'Formula 1') { Uri uri = Uri.parse( - '$endpoint/v1/event-tracker', + endpoint != defaultEndpoint + ? '$endpoint/f1/v1/event-tracker' + : '$endpoint/v1/event-tracker', ); Response res = await get( uri, @@ -136,7 +138,7 @@ class EventTracker { Response res = await get( Uri.parse( endpoint != defaultEndpoint - ? '$endpoint/formula-e/v1/races/$raceId' + ? '$endpoint/fe/formula-e/v1/races/$raceId' : '$feEndpoint/formula-e/v1/races/$raceId', ), headers: { @@ -313,7 +315,9 @@ class EventTracker { .get('useOfficialDataSoure', defaultValue: false) as bool; Uri uri = Uri.parse( - '$endpoint/v1/event-tracker/meeting/$formulaOneCircuitId', + endpoint != defaultEndpoint + ? '$endpoint/f1/v1/event-tracker/meeting/$formulaOneCircuitId' + : '$endpoint/v1/event-tracker/meeting/$formulaOneCircuitId', ); Response res = await get( diff --git a/lib/api/formula1.dart b/lib/api/formula1.dart index 8fa7f98..4663ee0 100644 --- a/lib/api/formula1.dart +++ b/lib/api/formula1.dart @@ -85,13 +85,22 @@ class Formula1 { .get('server', defaultValue: defaultEndpoint) as String; if (tagId != null) { url = Uri.parse( - '$endpoint/v1/editorial/articles?limit=16&offset=$offset&tags=$tagId'); + endpoint != defaultEndpoint + ? '$endpoint/f1/v1/editorial/articles?limit=16&offset=$offset&tags=$tagId' + : '$endpoint/v1/editorial/articles?limit=16&offset=$offset&tags=$tagId', + ); } else if (articleType != null) { url = Uri.parse( - '$endpoint/v1/editorial/articles?limit=16&offset=$offset&articleTypes=$articleType'); + endpoint != defaultEndpoint + ? '$endpoint/f1/v1/editorial/articles?limit=16&offset=$offset&articleTypes=$articleType' + : '$endpoint/v1/editorial/articles?limit=16&offset=$offset&articleTypes=$articleType', + ); } else { - url = - Uri.parse('$endpoint/v1/editorial/articles?limit=16&offset=$offset'); + url = Uri.parse( + endpoint != defaultEndpoint + ? '$endpoint/f1/v1/editorial/articles?limit=16&offset=$offset' + : '$endpoint/v1/editorial/articles?limit=16&offset=$offset', + ); } var response = await http.get( url, @@ -124,11 +133,16 @@ class Formula1 { .get('server', defaultValue: defaultEndpoint) as String; if (articleType != null) { url = Uri.parse( - '$endpoint/v1/editorial/articles?limit=16&tags=${tags.join(',')}&articleTypes=$articleType', + endpoint != defaultEndpoint + ? '$endpoint/f1/v1/editorial/articles?limit=16&tags=${tags.join(',')}&articleTypes=$articleType' + : '$endpoint/v1/editorial/articles?limit=16&tags=${tags.join(',')}&articleTypes=$articleType', ); } else { url = Uri.parse( - '$endpoint/v1/editorial/articles?limit=16&tags=${tags.join(',')}'); + endpoint != defaultEndpoint + ? '$endpoint/f1/v1/editorial/articles?limit=16&tags=${tags.join(',')}' + : '$endpoint/v1/editorial/articles?limit=16&tags=${tags.join(',')}', + ); } var response = await http.get( url, @@ -151,7 +165,11 @@ class Formula1 { Future
getArticleData(String articleId) async { String endpoint = Hive.box('settings') .get('server', defaultValue: defaultEndpoint) as String; - Uri url = Uri.parse('$endpoint/v1/editorial/articles/$articleId'); + Uri url = Uri.parse( + endpoint != defaultEndpoint + ? '$endpoint/f1/v1/editorial/articles/$articleId' + : '$endpoint/v1/editorial/articles/$articleId', + ); var response = await http.get( url, headers: endpoint != defaultEndpoint @@ -329,7 +347,7 @@ class Formula1 { .get('server', defaultValue: defaultEndpoint) as String; Uri url = Uri.parse( endpoint != defaultEndpoint - ? '$endpoint/v1/fom-results/race/meeting=$meetingId' + ? '$endpoint/f1/v1/fom-results/race/meeting=$meetingId' : '$endpoint/v1/fom-results/race?meeting=$meetingId', ); var response = await http.get( @@ -364,7 +382,7 @@ class Formula1 { .get('server', defaultValue: defaultEndpoint) as String; Uri url = Uri.parse( endpoint != defaultEndpoint - ? '$endpoint/v1/fom-results/qualifying/meeting=$meetingId' + ? '$endpoint/f1/v1/fom-results/qualifying/meeting=$meetingId' : '$endpoint/v1/fom-results/qualifying?meeting=$meetingId', ); var response = await http.get( @@ -422,7 +440,7 @@ class Formula1 { .get('server', defaultValue: defaultEndpoint) as String; Uri url = Uri.parse( endpoint != defaultEndpoint - ? '$endpoint/v1/fom-results/practice/meeting=$meetingId&session=$session' + ? '$endpoint/f1/v1/fom-results/practice/meeting=$meetingId&session=$session' : '$endpoint/v1/fom-results/practice?meeting=$meetingId&session=$session', ); var response = await http.get( @@ -484,7 +502,7 @@ class Formula1 { .get('server', defaultValue: defaultEndpoint) as String; Uri url = Uri.parse( endpoint != defaultEndpoint - ? '$endpoint/v1/fom-results/sprint-shootout/meeting=$meetingId' + ? '$endpoint/f1/v1/fom-results/sprint-shootout/meeting=$meetingId' : '$endpoint/v1/fom-results/sprint-shootout?meeting=$meetingId', ); var response = await http.get( @@ -543,7 +561,7 @@ class Formula1 { .get('server', defaultValue: defaultEndpoint) as String; Uri url = Uri.parse( endpoint != defaultEndpoint - ? '$endpoint/v1/fom-results/sprint/meeting=$meetingId' + ? '$endpoint/f1/v1/fom-results/sprint/meeting=$meetingId' : '$endpoint/v1/fom-results/sprint?meeting=$meetingId', ); var response = await http.get( @@ -667,7 +685,9 @@ class Formula1 { String endpoint = Hive.box('settings') .get('server', defaultValue: defaultEndpoint) as String; var url = Uri.parse( - '$endpoint/v1/editorial-driverlisting/listing', + endpoint != defaultEndpoint + ? '$endpoint/f1/v1/editorial-driverlisting/listing' + : '$endpoint/v1/editorial-driverlisting/listing', ); var response = await http.get( url, @@ -740,7 +760,9 @@ class Formula1 { String endpoint = Hive.box('settings') .get('server', defaultValue: defaultEndpoint) as String; Uri url = Uri.parse( - '$endpoint/v1/editorial-constructorlisting/listing', + endpoint != defaultEndpoint + ? '$endpoint/f1/v1/editorial-constructorlisting/listing' + : '$endpoint/v1/editorial-constructorlisting/listing', ); var response = await http.get( url, @@ -879,7 +901,9 @@ class Formula1 { String endpoint = Hive.box('settings') .get('server', defaultValue: defaultEndpoint) as String; Uri url = Uri.parse( - '$endpoint/v1/editorial-eventlisting/events', + endpoint != defaultEndpoint + ? '$endpoint/f1/v1/editorial-eventlisting/events' + : '$endpoint/v1/editorial-eventlisting/events', ); var response = await http.get( url, @@ -909,7 +933,7 @@ class Formula1 { .get('server', defaultValue: defaultEndpoint) as String; Uri url = Uri.parse( endpoint != defaultEndpoint - ? '$endpoint/v1/fom-results/starting-grid/meeting=$meetingId' + ? '$endpoint/f1/v1/fom-results/starting-grid/meeting=$meetingId' : '$endpoint/v1/fom-results/starting-grid?meeting=$meetingId', ); var response = await http.get( diff --git a/lib/api/formulae.dart b/lib/api/formulae.dart index 6930059..8b4910b 100644 --- a/lib/api/formulae.dart +++ b/lib/api/formulae.dart @@ -43,7 +43,7 @@ class FormulaE { .get('server', defaultValue: defaultF1Endpoint) as String; Uri url = Uri.parse( endpoint != defaultF1Endpoint - ? '$endpoint/content/formula-e/text/EN/$articleId' + ? '$endpoint/fe/content/formula-e/text/EN/$articleId' : '$defaultEndpoint/content/formula-e/text/EN/$articleId', ); @@ -118,8 +118,8 @@ class FormulaE { .get('server', defaultValue: defaultF1Endpoint) as String; Uri url = Uri.parse( endpoint != defaultF1Endpoint - ? '$endpoint/content/formula-e/text/EN/page=$page&pageSize=16&tagNames=content-type%3Anews&tagExpression=&playlistTypeRestriction=&playlistId=&detail=&size=16&championshipId=&sort=' - : '$defaultEndpoint/content/formula-e/text/EN/?page=$page&pageSize=16&tagNames=content-type%3Anews&tagExpression=&playlistTypeRestriction=&playlistId=&detail=&size=16&championshipId=&sort=', + ? '$endpoint/fe/content/formula-e/text/EN/page=$page&pageSize=16&tagNames=content-type:news&tagExpression=&playlistTypeRestriction=&playlistId=&detail=&size=16&championshipId=&sort=' + : '$defaultEndpoint/content/formula-e/text/EN/?page=$page&pageSize=16&tagNames=content-type:news&tagExpression=&playlistTypeRestriction=&playlistId=&detail=&size=16&championshipId=&sort=', ); var response = await http.get( @@ -180,7 +180,7 @@ class FormulaE { .get('server', defaultValue: defaultF1Endpoint) as String; Uri url = Uri.parse( endpoint != defaultF1Endpoint - ? '$endpoint/content/formula-e/playlist/EN/15/page=$page&pageSize=$limit&detail=DETAILED&size=$limit' + ? '$endpoint/fe/content/formula-e/playlist/EN/15/page=$page&pageSize=$limit&detail=DETAILED&size=$limit' : '$defaultEndpoint/content/formula-e/playlist/EN/15?page=$page&pageSize=$limit&detail=DETAILED&size=$limit', ); @@ -239,7 +239,7 @@ class FormulaE { .get('server', defaultValue: defaultF1Endpoint) as String; Uri url = Uri.parse( endpoint != defaultF1Endpoint - ? '$endpoint/formula-e/v1/standings/drivers/championshipId=$championshipId' + ? '$endpoint/fe/formula-e/v1/standings/drivers/championshipId=$championshipId' : '$defaultEndpoint/formula-e/v1/standings/drivers?championshipId=$championshipId', ); var response = await http.get( @@ -297,7 +297,7 @@ class FormulaE { .get('server', defaultValue: defaultF1Endpoint) as String; Uri url = Uri.parse( endpoint != defaultF1Endpoint - ? '$endpoint/formula-e/v1/standings/teams/championshipId=$championshipId' + ? '$endpoint/fe/formula-e/v1/standings/teams/championshipId=$championshipId' : '$defaultEndpoint/formula-e/v1/standings/teams?championshipId=$championshipId', ); var response = await http.get( @@ -398,7 +398,7 @@ class FormulaE { .get('server', defaultValue: defaultF1Endpoint) as String; Uri url = Uri.parse( endpoint != defaultF1Endpoint - ? '$endpoint/formula-e/v1/races/championshipId=$championshipId' + ? '$endpoint/fe/formula-e/v1/races/championshipId=$championshipId' : '$defaultEndpoint/formula-e/v1/races?championshipId=$championshipId', ); var response = await http.get( @@ -425,7 +425,7 @@ class FormulaE { .get('server', defaultValue: defaultF1Endpoint) as String; Uri url = Uri.parse( endpoint != defaultF1Endpoint - ? '$endpoint/formula-e/v1/races/$raceId/sessions' + ? '$endpoint/fe/formula-e/v1/races/$raceId/sessions' : '$defaultEndpoint/formula-e/v1/races/$raceId/sessions', ); var response = await http.get( @@ -563,7 +563,7 @@ class FormulaE { .get('server', defaultValue: defaultF1Endpoint) as String; Uri url = Uri.parse( endpoint != defaultF1Endpoint - ? '$endpoint/content/formula-e/EN/contentTypes=video&contentTypes=news&page=0&pageSize=10&references=FORMULA_E_RACE:${race.meetingId}&onlyRestrictedContent=false&detail=DETAILED' + ? '$endpoint/fe/content/formula-e/EN/contentTypes=video&contentTypes=news&page=0&pageSize=10&references=FORMULA_E_RACE:${race.meetingId}&onlyRestrictedContent=false&detail=DETAILED' : '$defaultEndpoint/content/formula-e/EN?contentTypes=video&contentTypes=news&page=0&pageSize=10&references=FORMULA_E_RACE:${race.meetingId}&onlyRestrictedContent=false&detail=DETAILED', ); http.Response response = await http.get( @@ -648,7 +648,7 @@ class FormulaE { .get('server', defaultValue: defaultF1Endpoint) as String; Uri url = Uri.parse( endpoint != defaultF1Endpoint - ? '$endpoint/formula-e/v1/races/$raceId/sessions/$sessionId/results' + ? '$endpoint/fe/formula-e/v1/races/$raceId/sessions/$sessionId/results' : '$defaultEndpoint/formula-e/v1/races/$raceId/sessions/$sessionId/results', ); var response = await http.get( @@ -861,7 +861,7 @@ class FormulaE { .get('server', defaultValue: defaultF1Endpoint) as String; Uri url = Uri.parse( endpoint != defaultF1Endpoint - ? '$endpoint/content/formula-e/photo/en/references=FORMULA_E_RACE:$raceId&tagNames=race:bg-image' + ? '$endpoint/fe/content/formula-e/photo/en/references=FORMULA_E_RACE:$raceId&tagNames=race:bg-image' : '$defaultEndpoint/content/formula-e/photo/en/?references=FORMULA_E_RACE:$raceId&tagNames=race:bg-image', ); var response = await http.get( @@ -882,7 +882,7 @@ class FormulaE { .get('server', defaultValue: defaultF1Endpoint) as String; Uri url = Uri.parse( endpoint != defaultF1Endpoint - ? '$endpoint/formula-e/v1/championships/latest' + ? '$endpoint/fe/formula-e/v1/championships/latest' : '$defaultEndpoint/formula-e/v1/championships/latest', ); var response = await http.get( diff --git a/lib/api/videos.dart b/lib/api/videos.dart index 58c4b6a..4e948f3 100644 --- a/lib/api/videos.dart +++ b/lib/api/videos.dart @@ -68,10 +68,16 @@ class F1VideosFetcher { Uri url; if (tag != '') { url = Uri.parse( - '$endpoint/v1/video-assets/videos?limit=$limit&tag=$tag&offset=$offset'); + endpoint != defaultEndpoint + ? '$endpoint/f1/v1/video-assets/videos?limit=$limit&tag=$tag&offset=$offset' + : '$endpoint/v1/video-assets/videos?limit=$limit&tag=$tag&offset=$offset', + ); } else { url = Uri.parse( - '$endpoint/v1/video-assets/videos?limit=$limit&offset=$offset'); + endpoint != defaultEndpoint + ? '$endpoint/f1/v1/video-assets/videos?limit=$limit&offset=$offset' + : '$endpoint/v1/video-assets/videos?limit=$limit&offset=$offset', + ); } var response = await http.get( url, @@ -96,7 +102,9 @@ class F1VideosFetcher { String endpoint = Hive.box('settings') .get('server', defaultValue: defaultEndpoint) as String; Uri url = Uri.parse( - "$endpoint/v1/video-assets/videos/$videoId", + endpoint != defaultEndpoint + ? "$endpoint/f1/v1/video-assets/videos/$videoId" + : "$endpoint/v1/video-assets/videos/$videoId", ); var response = await http.get( url, diff --git a/lib/helpers/download.dart b/lib/helpers/download.dart index 723ff3d..3d2dea5 100644 --- a/lib/helpers/download.dart +++ b/lib/helpers/download.dart @@ -201,7 +201,9 @@ class DownloadUtils { final task = DownloadTask( taskId: taskId, - url: '$endpoint/v1/editorial/articles/$articleId', + url: endpoint != f1Endpoint + ? '$endpoint/f1/v1/editorial/articles/$articleId' + : '$endpoint/v1/editorial/articles/$articleId', filename: '$taskId.json', displayName: articleTitle, headers: endpoint != f1Endpoint diff --git a/lib/scraping/fia.dart b/lib/scraping/fia.dart index 2be464a..10ab683 100644 --- a/lib/scraping/fia.dart +++ b/lib/scraping/fia.dart @@ -39,7 +39,7 @@ class FIAScraper { .get('server', defaultValue: defaultEndpoint) as String; if (endpoint != defaultEndpoint) { latestDocumentsUrl = Uri.parse( - '$endpoint/documents', + '$endpoint/f1/documents', ); } else { latestDocumentsUrl = Uri.parse( diff --git a/lib/scraping/formula_one.dart b/lib/scraping/formula_one.dart index b28e0c4..45500e7 100644 --- a/lib/scraping/formula_one.dart +++ b/lib/scraping/formula_one.dart @@ -70,7 +70,7 @@ class FormulaOneScraper { } if (endpoint != defaultEndpoint) { resultsUrl = Uri.parse( - '$endpoint/results/${DateTime.now().year}/races/$circuitId/$circuitName/$sessionName.html', + '$endpoint/f1/results/${DateTime.now().year}/races/$circuitId/$circuitName/$sessionName.html', ); } else { resultsUrl = Uri.parse( @@ -135,7 +135,7 @@ class FormulaOneScraper { 'https://www.formula1.com', endpoint, ) ?? - '$endpoint/en/results.html/${DateTime.now().year}/races/$circuitId/$circuitName/$sessionName.html', + '$endpoint/f1/en/results.html/${DateTime.now().year}/races/$circuitId/$circuitName/$sessionName.html', ); } else if (qualifyingResultsUrl == null) { resultsUrl = Uri.parse( @@ -239,7 +239,7 @@ class FormulaOneScraper { if (endpoint != defaultEndpoint) { resultsUrl = Uri.parse( - '$endpoint/en/results.html/${DateTime.now().year}/races/$circuitId/$circuitName/$sessionName.html', + '$endpoint/f1/en/results.html/${DateTime.now().year}/races/$circuitId/$circuitName/$sessionName.html', ); } else { resultsUrl = Uri.parse( @@ -347,7 +347,7 @@ class FormulaOneScraper { String endpoint = Hive.box('settings') .get('server', defaultValue: defaultEndpoint) as String; if (endpoint != defaultEndpoint) { - driverDetailsUrl = Uri.parse("$endpoint/en/drivers/${driverId}.html"); + driverDetailsUrl = Uri.parse("$endpoint/f1/en/drivers/${driverId}.html"); } else { driverDetailsUrl = Uri.parse( "https://www.formula1.com/en/drivers/$driverId", @@ -423,7 +423,7 @@ class FormulaOneScraper { String endpoint = Hive.box('settings') .get('server', defaultValue: defaultEndpoint) as String; if (endpoint != defaultEndpoint) { - teamDetailsUrl = Uri.parse("$endpoint/en/teams/$teamId.html"); + teamDetailsUrl = Uri.parse("$endpoint/f1/en/teams/$teamId.html"); } else { teamDetailsUrl = Uri.parse( "https://www.formula1.com/en/teams/$teamId.html", @@ -527,7 +527,7 @@ class FormulaOneScraper { .get('server', defaultValue: defaultEndpoint) as String; if (endpoint != defaultEndpoint) { resultsUrl = Uri.parse( - '$endpoint/en/results.html/${DateTime.now().year}/races/$circuitId/$circuitName.html', + '$endpoint/f1/en/results.html/${DateTime.now().year}/races/$circuitId/$circuitName.html', ); } else { resultsUrl = Uri.parse( @@ -640,7 +640,7 @@ class FormulaOneScraper { .get('server', defaultValue: defaultEndpoint) as String; if (endpoint != defaultEndpoint) { formulaOneCircuitPageUrl = Uri.parse( - '$endpoint/en/racing/${DateTime.now().year}/$formulaOneCircuitName/Circuit.html', + '$endpoint/f1/en/racing/${DateTime.now().year}/$formulaOneCircuitName/Circuit.html', ); } else { formulaOneCircuitPageUrl = Uri.parse( diff --git a/lib/scraping/formulae.dart b/lib/scraping/formulae.dart index 732933a..e57454a 100644 --- a/lib/scraping/formulae.dart +++ b/lib/scraping/formulae.dart @@ -21,6 +21,8 @@ import 'dart:convert'; import 'package:boxbox/api/formula1.dart'; import 'package:boxbox/api/formulae.dart'; +import 'package:boxbox/helpers/constants.dart'; +import 'package:hive_flutter/hive_flutter.dart'; import 'package:html/parser.dart' as parser; import 'package:html/dom.dart' as dom; import 'package:html2md/html2md.dart' as html2md; @@ -28,6 +30,7 @@ import 'package:http/http.dart' as http; class FormulaEScraper { final String defaultEndpoint = "https://www.fiaformulae.com"; + final String defaultF1Endpoint = Constants().F1_API_URL; List rules = [ html2md.Rule( @@ -47,8 +50,13 @@ class FormulaEScraper { ]; Future
getArticleData(News? item, String articleId) async { + String endpoint = Hive.box('settings') + .get('server', defaultValue: defaultF1Endpoint) as String; + Uri url = Uri.parse(endpoint != defaultF1Endpoint + ? '$endpoint/fe/en/news/$articleId' + : '$defaultEndpoint/en/news/$articleId'); http.Response response = await http.get( - Uri.parse('$defaultEndpoint/en/news/$articleId'), + url, headers: { 'Accept': 'application/json', 'User-Agent':