mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-06-03 01:28:17 +08:00
@@ -117,27 +117,25 @@ Future<void> importFromClipBoard<T>(
|
||||
Future<void> importFromLocalFile<T>({
|
||||
required FutureOr<void> Function(T json) onImport,
|
||||
}) async {
|
||||
final result = await FilePicker.pickFiles(
|
||||
final result = await FilePicker.pickFile(
|
||||
type: .custom,
|
||||
allowedExtensions: const ['json', 'txt'],
|
||||
);
|
||||
if (result != null) {
|
||||
final path = result.files.first.path;
|
||||
if (path != null) {
|
||||
final data = await File(path).readAsString();
|
||||
final T json;
|
||||
try {
|
||||
json = jsonDecode(data);
|
||||
} catch (e) {
|
||||
SmartDialog.showToast('解析json失败:$e');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await onImport(json);
|
||||
SmartDialog.showToast('导入成功');
|
||||
} catch (e) {
|
||||
SmartDialog.showToast('导入失败:$e');
|
||||
}
|
||||
final path = result.xFile.path;
|
||||
final data = await File(path).readAsString();
|
||||
final T json;
|
||||
try {
|
||||
json = jsonDecode(data);
|
||||
} catch (e) {
|
||||
SmartDialog.showToast('解析json失败:$e');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await onImport(json);
|
||||
SmartDialog.showToast('导入成功');
|
||||
} catch (e) {
|
||||
SmartDialog.showToast('导入失败:$e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -668,51 +668,49 @@ class HeaderControlState extends State<HeaderControl>
|
||||
onTap: () async {
|
||||
Get.back();
|
||||
try {
|
||||
final result = await FilePicker.pickFiles(
|
||||
final result = await FilePicker.pickFile(
|
||||
type: .custom,
|
||||
allowedExtensions: const ['json', 'vtt', 'srt', 'ass'],
|
||||
);
|
||||
if (result != null) {
|
||||
final file = result.files.single;
|
||||
final file = result.xFile;
|
||||
final path = file.path;
|
||||
if (path != null) {
|
||||
final name = file.name;
|
||||
final length = videoDetailCtr.subtitles.length;
|
||||
if (name.endsWith('.json')) {
|
||||
final file = File(path);
|
||||
final stream = file.openRead().transform(
|
||||
utf8.decoder,
|
||||
);
|
||||
final buffer = StringBuffer();
|
||||
await for (final chunk in stream) {
|
||||
if (!mounted) return;
|
||||
buffer.write(chunk);
|
||||
}
|
||||
if (!mounted) return;
|
||||
String sub = buffer.toString();
|
||||
sub = await compute<List, String>(
|
||||
VideoHttp.processList,
|
||||
jsonDecode(sub)['body'],
|
||||
);
|
||||
if (!mounted) return;
|
||||
videoDetailCtr.vttSubtitles[length] = (
|
||||
isData: true,
|
||||
id: sub,
|
||||
);
|
||||
} else {
|
||||
videoDetailCtr.vttSubtitles[length] = (
|
||||
isData: false,
|
||||
id: path,
|
||||
);
|
||||
}
|
||||
videoDetailCtr.subtitles.add(
|
||||
Subtitle(
|
||||
lan: '',
|
||||
lanDoc: name.split('.').firstOrNull ?? name,
|
||||
),
|
||||
final name = file.name;
|
||||
final length = videoDetailCtr.subtitles.length;
|
||||
if (name.endsWith('.json')) {
|
||||
final file = File(path);
|
||||
final stream = file.openRead().transform(
|
||||
utf8.decoder,
|
||||
);
|
||||
final buffer = StringBuffer();
|
||||
await for (final chunk in stream) {
|
||||
if (!mounted) return;
|
||||
buffer.write(chunk);
|
||||
}
|
||||
if (!mounted) return;
|
||||
String sub = buffer.toString();
|
||||
sub = await compute<List, String>(
|
||||
VideoHttp.processList,
|
||||
jsonDecode(sub)['body'],
|
||||
);
|
||||
if (!mounted) return;
|
||||
videoDetailCtr.vttSubtitles[length] = (
|
||||
isData: true,
|
||||
id: sub,
|
||||
);
|
||||
} else {
|
||||
videoDetailCtr.vttSubtitles[length] = (
|
||||
isData: false,
|
||||
id: path,
|
||||
);
|
||||
await videoDetailCtr.setSubtitle(length + 1);
|
||||
}
|
||||
videoDetailCtr.subtitles.add(
|
||||
Subtitle(
|
||||
lan: '',
|
||||
lanDoc: name.split('.').firstOrNull ?? name,
|
||||
),
|
||||
);
|
||||
await videoDetailCtr.setSubtitle(length + 1);
|
||||
}
|
||||
} catch (e) {
|
||||
SmartDialog.showToast('加载失败: $e');
|
||||
|
||||
@@ -316,6 +316,7 @@ abstract final class ImageUtils {
|
||||
final savePath = await FilePicker.saveFile(
|
||||
type: FileType.image,
|
||||
fileName: fileName,
|
||||
bytes: Uint8List(0),
|
||||
);
|
||||
if (savePath == null) {
|
||||
SmartDialog.showToast("取消保存");
|
||||
@@ -353,6 +354,7 @@ abstract final class ImageUtils {
|
||||
final savePath = await FilePicker.saveFile(
|
||||
type: type,
|
||||
fileName: fileName,
|
||||
bytes: Uint8List(0),
|
||||
);
|
||||
if (savePath == null) {
|
||||
SmartDialog.showToast("取消保存");
|
||||
|
||||
@@ -17,7 +17,7 @@ abstract final class StorageUtils {
|
||||
allowedExtensions: allowedExtensions,
|
||||
type: type,
|
||||
fileName: name,
|
||||
bytes: PlatformUtils.isDesktop ? null : bytes,
|
||||
bytes: PlatformUtils.isDesktop ? Uint8List(0) : bytes,
|
||||
);
|
||||
if (path == null) {
|
||||
SmartDialog.showToast("取消保存");
|
||||
|
||||
Reference in New Issue
Block a user