del cache

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-11-01 17:26:21 +08:00
parent 77dd939172
commit 737be8dcac
12 changed files with 105 additions and 68 deletions

View File

@@ -18,7 +18,6 @@ import 'package:PiliPlus/utils/page_utils.dart';
import 'package:PiliPlus/utils/storage.dart';
import 'package:PiliPlus/utils/update.dart';
import 'package:PiliPlus/utils/utils.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart' hide ListTile;
import 'package:flutter/services.dart' show Clipboard, ClipboardData;
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
@@ -339,30 +338,17 @@ Future<void> showInportExportDialog<T>(
ListTile(
dense: true,
title: const Text('导出文件至本地', style: style),
onTap: () async {
onTap: () {
Get.back();
final res = utf8.encode(toJson());
final name =
'piliplus_${label}_${context.isTablet ? 'pad' : 'phone'}_'
'${DateFormat('yyyyMMddHHmmss').format(DateTime.now())}.json';
try {
final path = await FilePicker.platform.saveFile(
allowedExtensions: ['json'],
type: FileType.custom,
fileName: name,
bytes: Utils.isDesktop ? null : res,
);
if (path == null) {
SmartDialog.showToast("取消保存");
return;
}
if (Utils.isDesktop) {
await File(path).writeAsBytes(res);
}
SmartDialog.showToast("已保存");
} catch (e) {
SmartDialog.showToast("保存失败: $e");
}
Utils.saveBytes2File(
name: name,
bytes: res,
allowedExtensions: const ['json'],
);
},
),
ListTile(

View File

@@ -82,7 +82,10 @@ abstract class CommonRichTextPubPageState<T extends CommonRichTextPubPage>
).colorScheme.secondaryContainer.withValues(alpha: 0.5);
void onClear() {
pathList.removeAt(index);
final path = pathList.removeAt(index);
if (Utils.isMobile) {
File(path).tryDel();
}
if (pathList.isEmpty && editController.rawText.trim().isEmpty) {
enablePublish.value = false;
}
@@ -148,8 +151,9 @@ abstract class CommonRichTextPubPageState<T extends CommonRichTextPubPage>
Future<void> onCropImage(int index) async {
late final colorScheme = ColorScheme.of(context);
CroppedFile? croppedFile = await ImageCropper.platform.cropImage(
sourcePath: pathList[index],
final sourcePath = pathList[index];
final croppedFile = await ImageCropper.platform.cropImage(
sourcePath: sourcePath,
uiSettings: [
AndroidUiSettings(
toolbarTitle: '裁剪',
@@ -161,6 +165,7 @@ abstract class CommonRichTextPubPageState<T extends CommonRichTextPubPage>
],
);
if (croppedFile != null) {
File(sourcePath).tryDel();
pathList[index] = croppedFile.path;
}
}

View File

@@ -7,7 +7,6 @@ import 'package:PiliPlus/utils/accounts.dart';
import 'package:PiliPlus/utils/utils.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';
class CreateVoteController extends GetxController {
CreateVoteController(this.voteId);
@@ -109,9 +108,9 @@ class CreateVoteController extends GetxController {
}
}
Future<void> onUpload(int index, XFile pickedFile) async {
Future<void> onUpload(int index, String path) async {
var res = await MsgHttp.uploadBfs(
path: pickedFile.path,
path: path,
category: 'daily',
biz: 'vote',
);

View File

@@ -1,8 +1,11 @@
import 'dart:io' show File;
import 'package:PiliPlus/common/widgets/button/icon_button.dart';
import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
import 'package:PiliPlus/models/dynamics/vote_model.dart';
import 'package:PiliPlus/pages/dynamics_create_vote/controller.dart';
import 'package:PiliPlus/utils/date_utils.dart';
import 'package:PiliPlus/utils/extension.dart';
import 'package:PiliPlus/utils/utils.dart';
import 'package:easy_debounce/easy_throttle.dart';
import 'package:flutter/material.dart';
@@ -414,7 +417,12 @@ class _CreateVotePageState extends State<CreateVotePage> {
source: ImageSource.gallery,
);
if (pickedFile != null) {
_controller.onUpload(index, pickedFile);
final path = pickedFile.path;
_controller.onUpload(index, path).whenComplete(() {
if (Utils.isMobile) {
File(path).tryDel();
}
});
}
} catch (e) {
SmartDialog.showToast(e.toString());

View File

@@ -1,3 +1,5 @@
import 'dart:io' show File;
import 'package:PiliPlus/common/widgets/loading_widget/loading_widget.dart';
import 'package:PiliPlus/http/fav.dart';
import 'package:PiliPlus/http/msg.dart';
@@ -118,8 +120,8 @@ class _CreateFavPageState extends State<CreateFavPage> {
if (pickedFile != null && mounted) {
String imgPath = pickedFile.path;
if (Utils.isMobile) {
CroppedFile? croppedFile = await ImageCropper.platform.cropImage(
sourcePath: pickedFile.path,
final croppedFile = await ImageCropper.platform.cropImage(
sourcePath: imgPath,
uiSettings: [
AndroidUiSettings(
toolbarTitle: '裁剪',
@@ -141,6 +143,7 @@ class _CreateFavPageState extends State<CreateFavPage> {
],
);
if (croppedFile != null) {
File(imgPath).tryDel();
imgPath = croppedFile.path;
}
}
@@ -157,6 +160,9 @@ class _CreateFavPageState extends State<CreateFavPage> {
SmartDialog.showToast(res['msg']);
}
}
if (Utils.isMobile) {
File(imgPath).tryDel();
}
});
}
} catch (e) {

View File

@@ -1,3 +1,5 @@
import 'dart:io' show File;
import 'package:PiliPlus/common/constants.dart';
import 'package:PiliPlus/common/widgets/loading_widget/loading_widget.dart';
import 'package:PiliPlus/http/constants.dart';
@@ -488,10 +490,10 @@ class _EditProfilePageState extends State<EditProfilePage> {
SmartDialog.showToast('不能选GIF');
return;
}
String? imagePath;
String? imagePath = pickedFile.path;
if (Utils.isMobile) {
CroppedFile? croppedFile = await ImageCropper.platform.cropImage(
sourcePath: pickedFile.path,
final croppedFile = await ImageCropper.platform.cropImage(
sourcePath: imagePath,
uiSettings: [
AndroidUiSettings(
toolbarTitle: '裁剪',
@@ -514,11 +516,8 @@ class _EditProfilePageState extends State<EditProfilePage> {
),
],
);
if (croppedFile != null) {
imagePath = croppedFile.path;
}
} else {
imagePath = pickedFile.path;
File(imagePath).tryDel();
imagePath = croppedFile?.path;
}
if (imagePath != null) {
Request()
@@ -536,10 +535,17 @@ class _EditProfilePageState extends State<EditProfilePage> {
.then((res) {
if (res.data['code'] == 0) {
SmartDialog.showToast('修改成功');
Future.delayed(const Duration(milliseconds: 500), _getInfo);
Future.delayed(const Duration(milliseconds: 500), () {
if (mounted) {
_getInfo();
}
});
} else {
SmartDialog.showToast(res.data['message']);
}
if (Utils.isMobile && imagePath != null) {
File(imagePath).tryDel();
}
});
}
}

View File

@@ -42,7 +42,6 @@ import 'package:PiliPlus/utils/utils.dart';
import 'package:PiliPlus/utils/video_utils.dart';
import 'package:canvas_danmaku/canvas_danmaku.dart';
import 'package:dio/dio.dart';
import 'package:file_picker/file_picker.dart';
import 'package:floating/floating.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
@@ -1058,20 +1057,11 @@ class HeaderControlState extends State<HeaderControl> {
);
final name =
'${introController.videoDetail.value.title}-${videoDetailCtr.bvid}-${videoDetailCtr.cid.value}-${item.lanDoc}.json';
final path = await FilePicker.platform.saveFile(
Utils.saveBytes2File(
name: name,
bytes: bytes,
allowedExtensions: const ['json'],
type: FileType.custom,
fileName: name,
bytes: Utils.isDesktop ? null : bytes,
);
if (path == null) {
SmartDialog.showToast("取消保存");
return;
}
if (Utils.isDesktop) {
await File(path).writeAsBytes(bytes);
}
SmartDialog.showToast("已保存");
}
} catch (e) {
if (kDebugMode) rethrow;

View File

@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:io' show File;
import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
import 'package:PiliPlus/common/widgets/loading_widget/loading_widget.dart';
@@ -303,21 +304,20 @@ class _WhisperDetailPageState
);
} else {
try {
XFile? pickedFile = await imagePicker.pickImage(
final XFile? pickedFile = await imagePicker.pickImage(
source: ImageSource.gallery,
imageQuality: 100,
);
if (pickedFile != null) {
final path = pickedFile.path;
SmartDialog.showLoading(msg: '正在上传图片');
final result = await MsgHttp.uploadBfs(
path: pickedFile.path,
path: path,
biz: 'im',
);
if (result['status']) {
String mimeType =
lookupMimeType(
pickedFile.path,
)?.split('/').getOrNull(1) ??
lookupMimeType(path)?.split('/').getOrNull(1) ??
'jpg';
UploadBfsResData data = result['data'];
Map picMsg = {
@@ -329,10 +329,16 @@ class _WhisperDetailPageState
'size': data.imgSize,
};
SmartDialog.showLoading(msg: '正在发送');
await _whisperDetailController.sendMsg(
picMsg: picMsg,
onClearText: editController.clear,
);
await _whisperDetailController
.sendMsg(
picMsg: picMsg,
onClearText: editController.clear,
)
.whenComplete(() {
if (Utils.isMobile) {
File(path).tryDel();
}
});
} else {
SmartDialog.dismiss();
SmartDialog.showToast(result['msg']);

View File

@@ -18,9 +18,8 @@ abstract class CacheManage {
final dir = Directory('${tempDirectory.path}/libCachedImageData');
if (dir.existsSync()) {
return await getTotalSizeOfFilesInDir(dir, maxSize);
} else {
return 0;
}
return 0;
}
if (tempDirectory.existsSync()) {

View File

@@ -6,6 +6,7 @@ import 'dart:math';
import 'package:PiliPlus/common/constants.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/services.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
@@ -25,6 +26,32 @@ abstract class Utils {
static final bool isDesktop =
Platform.isWindows || Platform.isMacOS || Platform.isLinux;
static Future<void> saveBytes2File({
required String name,
required Uint8List bytes,
required List<String> allowedExtensions,
FileType type = FileType.custom,
}) async {
try {
final path = await FilePicker.platform.saveFile(
allowedExtensions: allowedExtensions,
type: type,
fileName: name,
bytes: Utils.isDesktop ? null : bytes,
);
if (path == null) {
SmartDialog.showToast("取消保存");
return;
}
if (Utils.isDesktop) {
await File(path).writeAsBytes(bytes);
}
SmartDialog.showToast("已保存");
} catch (e) {
SmartDialog.showToast("保存失败: $e");
}
}
static int? safeToInt(dynamic value) => switch (value) {
int e => e,
String e => int.tryParse(e),

View File

@@ -504,11 +504,12 @@ packages:
file_picker:
dependency: "direct main"
description:
name: file_picker
sha256: f2d9f173c2c14635cc0e9b14c143c49ef30b4934e8d1d274d6206fcb0086a06f
url: "https://pub.dev"
source: hosted
version: "10.3.3"
path: "."
ref: mod
resolved-ref: "4b7dd4b85328f9ed0b369cc77c5c8e87957a9d18"
url: "https://github.com/bggRGjQaUbCoE/flutter_file_picker.git"
source: git
version: "10.3.5"
file_selector_linux:
dependency: transitive
description:

View File

@@ -211,7 +211,11 @@ dependencies:
path: packages/window_manager
ref: main
tray_manager: ^0.5.1
file_picker: ^10.3.3
# file_picker: ^10.3.3
file_picker:
git:
url: https://github.com/bggRGjQaUbCoE/flutter_file_picker.git
ref: mod
super_sliver_list:
git:
url: https://github.com/bggRGjQaUbCoE/super_sliver_list.git