video loader bug fix for files in which diff is not fetched yet
This commit is contained in:
parent
52b1946b06
commit
0e3d6afc76
2 changed files with 50 additions and 0 deletions
37
lib/services/files_service.dart
Normal file
37
lib/services/files_service.dart
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
// ignore: import_of_legacy_library_into_null_safe
|
||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:logging/logging.dart';
|
||||||
|
import 'package:photos/core/configuration.dart';
|
||||||
|
import 'package:photos/core/network.dart';
|
||||||
|
|
||||||
|
class FilesService {
|
||||||
|
late Configuration _config;
|
||||||
|
late Dio _dio;
|
||||||
|
late Logger _logger;
|
||||||
|
FilesService._privateConstructor() {
|
||||||
|
_config = Configuration.instance;
|
||||||
|
_dio = Network.instance.getDio();
|
||||||
|
_logger = Logger("FilesService");
|
||||||
|
}
|
||||||
|
static final FilesService instance = FilesService._privateConstructor();
|
||||||
|
|
||||||
|
Future<int> getFileSize(int uploadedFileID) async {
|
||||||
|
try {
|
||||||
|
final response = await _dio.post(
|
||||||
|
Configuration.instance.getHttpEndpoint() + "/files/size",
|
||||||
|
options: Options(
|
||||||
|
headers: {
|
||||||
|
"X-Auth-Token": _config.getToken(),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
data: {
|
||||||
|
"fileIDs": [uploadedFileID],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return response.data["size"];
|
||||||
|
} catch (e) {
|
||||||
|
_logger.severe(e);
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:photos/core/constants.dart';
|
import 'package:photos/core/constants.dart';
|
||||||
import 'package:photos/models/file.dart';
|
import 'package:photos/models/file.dart';
|
||||||
|
import 'package:photos/services/files_service.dart';
|
||||||
import 'package:photos/ui/viewer/file/thumbnail_widget.dart';
|
import 'package:photos/ui/viewer/file/thumbnail_widget.dart';
|
||||||
import 'package:photos/ui/viewer/file/video_controls.dart';
|
import 'package:photos/ui/viewer/file/video_controls.dart';
|
||||||
import 'package:photos/utils/file_util.dart';
|
import 'package:photos/utils/file_util.dart';
|
||||||
|
@ -45,6 +46,7 @@ class _VideoWidgetState extends State<VideoWidget> {
|
||||||
super.initState();
|
super.initState();
|
||||||
if (widget.file.isRemoteFile) {
|
if (widget.file.isRemoteFile) {
|
||||||
_loadNetworkVideo();
|
_loadNetworkVideo();
|
||||||
|
_setFileSizeIfNull();
|
||||||
} else if (widget.file.isSharedMediaToAppSandbox) {
|
} else if (widget.file.isSharedMediaToAppSandbox) {
|
||||||
final localFile = io.File(getSharedMediaFilePath(widget.file));
|
final localFile = io.File(getSharedMediaFilePath(widget.file));
|
||||||
if (localFile.existsSync()) {
|
if (localFile.existsSync()) {
|
||||||
|
@ -68,6 +70,17 @@ class _VideoWidgetState extends State<VideoWidget> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _setFileSizeIfNull() {
|
||||||
|
if (widget.file.fileSize == null) {
|
||||||
|
FilesService.instance
|
||||||
|
.getFileSize(widget.file.uploadedFileID)
|
||||||
|
.then((value) {
|
||||||
|
widget.file.fileSize = value;
|
||||||
|
setState(() {});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _loadNetworkVideo() {
|
void _loadNetworkVideo() {
|
||||||
getFileFromServer(
|
getFileFromServer(
|
||||||
widget.file,
|
widget.file,
|
||||||
|
|
Loading…
Add table
Reference in a new issue