Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate name for StorageFile based on its mime type (#726) #756

Merged
merged 54 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
216c414
Add interface of filename generation to PlatformUtilsImpl
Dec 19, 2023
0dc0118
Export public method [extensionFromMime] from mime library
Dec 20, 2023
2faece4
Move [generateFilename] to separate [GenerateNameExt] on [StorageFile]
Dec 20, 2023
da677de
Use generated filename for avatar image
Dec 20, 2023
f83b763
Add proxy function returns default extension
Dec 20, 2023
4cd5687
Refactor generateFilename
Dec 20, 2023
b929b9a
Remove any changes in platform utils
Dec 20, 2023
7de32ff
Improve documentation comments
Dec 20, 2023
9dd3d15
Refactor - fix import to relative
Dec 20, 2023
19f8b7c
Move filename generation method inside [StorageFile]
Dec 20, 2023
b86a2fb
Prevent loading file by checking if it exist in cache
Alienjob Dec 20, 2023
14ef912
Improve [MimeResolver] documentation
Alienjob Dec 21, 2023
c31b0d6
Add [mime] field to [CacheEntry]
Alienjob Dec 21, 2023
607ba8e
Move [defaultExtension] to static const
Alienjob Dec 21, 2023
f8c834a
Add checking filename extension to [PlatformUtils.saveToGallery]
Alienjob Dec 21, 2023
b9d7875
Add TODO about caching mime-type from http response
Alienjob Dec 21, 2023
5377736
Fix fmt
Alienjob Dec 21, 2023
a3a9584
Change [generateFilename] to [defaultFilename]
Alienjob Dec 21, 2023
f37ee95
Remove resolving mime of file by content
Alienjob Dec 21, 2023
4bb9564
Fix call sync method async
Alienjob Dec 21, 2023
f2276f3
Improve formatting and documentation
Alienjob Dec 21, 2023
049a7e8
Implement [urlExtension] method
Alienjob Dec 21, 2023
0848fc7
Improve documentation
Alienjob Dec 21, 2023
2889659
Merge branch 'main' into 726-fix-extension-on-saved-avatar-image-file
Alienjob Dec 21, 2023
95f20e0
Refactor [MediaType] resolving
Alienjob Dec 22, 2023
4b76290
Fix imports
Alienjob Dec 22, 2023
6161245
Improve documentation
Alienjob Dec 22, 2023
176652a
Improve documantation
Alienjob Dec 22, 2023
7b01df7
Remove extension resolving from [StorageFile] name getter
Alienjob Dec 22, 2023
06b20a3
Test analysis options
Alienjob Dec 25, 2023
2f249ab
Fix test analysis options issue
Alienjob Dec 25, 2023
ca50acf
Remove comment in analysis_options
Alienjob Dec 25, 2023
c1ce661
Merge branch 'main' into 726-fix-extension-on-saved-avatar-image-file
Alienjob Dec 25, 2023
f8b95a5
Add TODO: about remove temp fix
Alienjob Dec 25, 2023
09ddc66
Remove [StorageFile] name length limit
Alienjob Dec 25, 2023
8ff8dee
Improve documentation
Alienjob Dec 25, 2023
a2560eb
Merge branch '726-fix-extension-on-saved-avatar-image-file' of github…
Alienjob Dec 25, 2023
6a07278
Fix caching [MediaType] of [CacheEntry]
Alienjob Dec 25, 2023
14bbebd
Improve documentation
Alienjob Dec 25, 2023
d2e8569
Fix [_resolveType] flow
Alienjob Dec 25, 2023
3b62224
Merge remote-tracking branch 'origin/main' into 726-fix-extension-on-…
Alienjob Dec 25, 2023
78ad910
Corrections
SleepySquash Dec 26, 2023
11abaa6
Fix retrieve extension from MediaType
Alienjob Dec 26, 2023
81e74e1
Add extension resolving at platform_utils downloading
Alienjob Dec 26, 2023
11b3fde
Add extension resolving at GalleryPopup.saveAs dialog
Alienjob Dec 26, 2023
80dd7aa
Add parsing the [url] of [StorageFile] for extension
Alienjob Dec 27, 2023
0eb3dac
Remove changes at _downloadAs
Alienjob Dec 27, 2023
e0437aa
Remove changes from platform utils
Alienjob Dec 28, 2023
8a4d16f
Remove changes from cache and mime
Alienjob Dec 28, 2023
cf4f9cf
Mark problem with image saving on web
Alienjob Dec 28, 2023
f708d35
Improve documentation
Alienjob Dec 28, 2023
49a6305
Merge remote-tracking branch 'origin/main' into 726-fix-extension-on-…
SleepySquash Dec 29, 2023
4c6a953
Corrections
SleepySquash Dec 29, 2023
fe882f7
Add CHANGELOG entry
SleepySquash Dec 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ All user visible changes to this project will be documented in this file. This p
- Restore button displaying under mobile navigation bar. ([#763, #758])
- Contacts tab:
- Restore button displaying under mobile navigation bar. ([#763, #758])
- User page:
- Downloaded avatar missing its extension on desktop. ([#756, #726])

[#718]: /../../issues/718
[#726]: /../../issues/726
[#750]: /../../pull/750
[#756]: /../../pull/756
[#758]: /../../issues/758
[#763]: /../../pull/763

Expand Down
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ linter:
# https://dart-lang.github.io/linter/lints/index.html
rules:
prefer_single_quotes: true
prefer_relative_imports: true
31 changes: 31 additions & 0 deletions lib/domain/model/file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// along with this program. If not, see
// <https://www.gnu.org/licenses/agpl-3.0.html>.

import 'package:intl/intl.dart';
import 'package:hive/hive.dart';

import '../model_type_id.dart';
Expand Down Expand Up @@ -70,6 +71,36 @@ abstract class StorageFile extends HiveObject {

/// Returns an absolute URL to this [StorageFile] on a file storage.
String get url => '${Config.files}$relativeRef';

/// Returns the name of this [StorageFile].
String get name {
Alienjob marked this conversation as resolved.
Show resolved Hide resolved
final basename = DateFormat('yyyy_MM_dd_H_m_s').format(DateTime.now());
return [basename, _extension].nonNulls.join('.');
}

/// Returns the extension parsed from the [relativeRef], excluding the dot, if
/// any.
///
/// ```dart
/// var file = StorageFile(relativeRef: 'http://site/.jpg');
/// print(file._extension); // => 'jpg'
///
/// var file = StorageFile(relativeRef: 'http://site/noExtension');
/// print(file._extension); // => 'null'
/// ```
String? get _extension {
final index = url.lastIndexOf('.');
if (index < 0 || index + 1 >= url.length) {
return null;
}

final result = url.substring(index + 1).toLowerCase();
if (result.contains('/')) {
return null;
}

return result;
}
}

/// Plain-[StorageFile] on a file storage.
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/page/home/widget/big_avatar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class _BigAvatarWidgetState extends State<BigAvatarWidget> {
children: [
GalleryItem.image(
avatar!.original.url,
avatar.original.checksum ?? DateTime.now().toString(),
avatar.original.name,
Alienjob marked this conversation as resolved.
Show resolved Hide resolved
width: avatar.original.width,
height: avatar.original.height,
checksum: avatar.original.checksum,
Expand Down
10 changes: 9 additions & 1 deletion lib/ui/page/home/widget/gallery_popup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,15 @@ class _GalleryPopupState extends State<GalleryPopup>
constraints:
const BoxConstraints(minWidth: 1, minHeight: 1),
child: PlatformUtils.isWeb
? WebImage(e.link, onForbidden: e.onError)
? WebImage(
e.link,
onForbidden: e.onError,

// TODO: Wait for HTML to support specifying
// download name:
// https://github.com/whatwg/html/issues/2722
// name: e.name,
)
: RetryImage(
e.link,
width: e.width?.toDouble(),
Expand Down
Loading