mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
opt: view pgc from dynamic
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:PiliPlus/http/init.dart';
|
||||
import 'package:PiliPlus/utils/download.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
@@ -362,7 +363,7 @@ class _InteractiveviewerGalleryState extends State<InteractiveviewerGallery>
|
||||
// 图片分享
|
||||
void onShareImg(String imgUrl) async {
|
||||
SmartDialog.showLoading();
|
||||
var response = await Dio()
|
||||
var response = await Request()
|
||||
.get(imgUrl, options: Options(responseType: ResponseType.bytes));
|
||||
final temp = await getTemporaryDirectory();
|
||||
SmartDialog.dismiss();
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:PiliPlus/http/follow.dart';
|
||||
import 'package:PiliPlus/pages/dynamics/tab/controller.dart';
|
||||
import 'package:PiliPlus/pages/dynamics/tab/view.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/url_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -89,6 +90,20 @@ class DynamicsController extends GetxController
|
||||
arguments: {'item': item, 'floor': floor});
|
||||
break;
|
||||
case 'DYNAMIC_TYPE_AV':
|
||||
if (item.modules.moduleDynamic.major.archive.type == 2) {
|
||||
if (item.modules.moduleDynamic.major.archive.jumpUrl
|
||||
.startsWith('//')) {
|
||||
item.modules.moduleDynamic.major.archive.jumpUrl =
|
||||
'https:${item.modules.moduleDynamic.major.archive.jumpUrl}';
|
||||
}
|
||||
String? redirectUrl = await UrlUtils.parseRedirectUrl(
|
||||
item.modules.moduleDynamic.major.archive.jumpUrl);
|
||||
if (redirectUrl != null) {
|
||||
Utils.viewPgcFromUri(redirectUrl);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String bvid = item.modules.moduleDynamic.major.archive.bvid;
|
||||
String cover = item.modules.moduleDynamic.major.archive.cover;
|
||||
try {
|
||||
|
||||
@@ -790,7 +790,8 @@ class ReplyItem extends StatelessWidget {
|
||||
});
|
||||
} else {
|
||||
final String redirectUrl =
|
||||
await UrlUtils.parseRedirectUrl(matchStr);
|
||||
(await UrlUtils.parseRedirectUrl(matchStr)) ??
|
||||
matchStr;
|
||||
// if (redirectUrl == matchStr) {
|
||||
// Clipboard.setData(ClipboardData(text: matchStr));
|
||||
// SmartDialog.showToast('地址可能有误');
|
||||
@@ -824,7 +825,8 @@ class ReplyItem extends StatelessWidget {
|
||||
parameters: {'keyword': title});
|
||||
} else if (matchStr.startsWith('https://b23.tv')) {
|
||||
final String redirectUrl =
|
||||
await UrlUtils.parseRedirectUrl(matchStr);
|
||||
(await UrlUtils.parseRedirectUrl(matchStr)) ??
|
||||
matchStr;
|
||||
final String pathSegment =
|
||||
Uri.parse(redirectUrl).path;
|
||||
final String lastPathSegment =
|
||||
|
||||
@@ -822,7 +822,8 @@ class ReplyItemGrpc extends StatelessWidget {
|
||||
});
|
||||
} else {
|
||||
final String redirectUrl =
|
||||
await UrlUtils.parseRedirectUrl(matchStr);
|
||||
(await UrlUtils.parseRedirectUrl(matchStr)) ??
|
||||
matchStr;
|
||||
// if (redirectUrl == matchStr) {
|
||||
// Clipboard.setData(ClipboardData(text: matchStr));
|
||||
// SmartDialog.showToast('地址可能有误');
|
||||
@@ -856,7 +857,8 @@ class ReplyItemGrpc extends StatelessWidget {
|
||||
parameters: {'keyword': title});
|
||||
} else if (matchStr.startsWith('https://b23.tv')) {
|
||||
final String redirectUrl =
|
||||
await UrlUtils.parseRedirectUrl(matchStr);
|
||||
(await UrlUtils.parseRedirectUrl(matchStr)) ??
|
||||
matchStr;
|
||||
final String pathSegment =
|
||||
Uri.parse(redirectUrl).path;
|
||||
final String lastPathSegment =
|
||||
|
||||
@@ -318,7 +318,8 @@ class PiliScheme {
|
||||
return;
|
||||
} else if (host == 'b23.tv') {
|
||||
final String fullPath = 'https://$host$path';
|
||||
final String redirectUrl = await UrlUtils.parseRedirectUrl(fullPath);
|
||||
final String redirectUrl =
|
||||
(await UrlUtils.parseRedirectUrl(fullPath)) ?? fullPath;
|
||||
final String pathSegment = Uri.parse(redirectUrl).path;
|
||||
final String lastPathSegment = pathSegment.split('/').last;
|
||||
final RegExp avRegex = RegExp(r'^[aA][vV]\d+', caseSensitive: false);
|
||||
|
||||
@@ -1,35 +1,31 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../http/init.dart';
|
||||
import '../http/search.dart';
|
||||
import 'id_utils.dart';
|
||||
import 'utils.dart';
|
||||
|
||||
class UrlUtils {
|
||||
// 302重定向路由截取
|
||||
static Future<String> parseRedirectUrl(String url) async {
|
||||
late String redirectUrl;
|
||||
final dio = Dio();
|
||||
dio.options.followRedirects = false;
|
||||
dio.options.validateStatus = (status) {
|
||||
return status == 200 || status == 301 || status == 302;
|
||||
};
|
||||
static Future<String?> parseRedirectUrl(String url) async {
|
||||
try {
|
||||
final response = await dio.get(url);
|
||||
if (response.statusCode == 302) {
|
||||
redirectUrl = response.headers['location']?.first as String;
|
||||
if (redirectUrl.endsWith('/')) {
|
||||
redirectUrl = redirectUrl.substring(0, redirectUrl.length - 1);
|
||||
}
|
||||
final response = await Request().get(
|
||||
url,
|
||||
options: Options(
|
||||
followRedirects: false,
|
||||
validateStatus: (status) {
|
||||
return status == 200 || status == 301 || status == 302;
|
||||
},
|
||||
),
|
||||
);
|
||||
if (response.statusCode == 302 || response.statusCode == 301) {
|
||||
return response.headers['location']?.first;
|
||||
} else {
|
||||
if (url.endsWith('/')) {
|
||||
url = url.substring(0, url.length - 1);
|
||||
}
|
||||
return url;
|
||||
return null;
|
||||
}
|
||||
return redirectUrl;
|
||||
} catch (err) {
|
||||
return url;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user