Skip to content

Commit

Permalink
Use sha checksum for assets
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Nov 27, 2024
1 parent e20c04e commit 2335bdb
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 173 deletions.
2 changes: 1 addition & 1 deletion api/lib/src/converter/xopp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ String _exportColor(int value) {
case 'image':
final imageData = UriData.parse(element.innerText);
String path;
(data, path) = data.addImage(imageData.contentAsBytes(), 'png');
(data, path) = data.importImage(imageData.contentAsBytes(), 'png');
final left = double.parse(element.getAttribute('x')!);
final top = double.parse(element.getAttribute('y')!);
final right = double.parse(element.getAttribute('right')!);
Expand Down
12 changes: 7 additions & 5 deletions api/lib/src/models/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:typed_data';

import 'package:archive/archive.dart';
import 'package:collection/collection.dart';
import 'package:crypto/crypto.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:lw_file_system_api/archive.dart';

Expand Down Expand Up @@ -58,8 +59,10 @@ final class NoteData extends ArchiveData<NoteData> {
NoteData updateState(ArchiveState state) => NoteData(archive, state: state);

@useResult
(NoteData, String) addAsset(String path, Uint8List data, String fileExtension,
[String name = '']) {
(NoteData, String) importAsset(
String path, Uint8List data, String fileExtension) {
final hash = sha512256.convert(data);
final name = base64Encode(hash.bytes);
final newPath = '$path/${findUniqueName(path, fileExtension, name)}';
return (setAsset(newPath, data), newPath);
}
Expand Down Expand Up @@ -287,9 +290,8 @@ final class NoteData extends ArchiveData<NoteData> {
return setAsset(kInfoArchiveFile, utf8.encode(content));
}

(NoteData, String) addImage(Uint8List data, String fileExtension,
[String name = '']) =>
addAsset(kImagesArchiveDirectory, data, fileExtension, name);
(NoteData, String) importImage(Uint8List data, String fileExtension) =>
importAsset(kImagesArchiveDirectory, data, fileExtension);

@useResult
Uint8List? getFont(String fontName) =>
Expand Down
3 changes: 2 additions & 1 deletion app/lib/bloc/document_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ class DocumentBloc extends ReplayBloc<DocumentEvent, DocumentState> {
}
return source;
}
final result = data.addImage(uriData.contentAsBytes(), fileExtension);
final result =
data.importImage(uriData.contentAsBytes(), fileExtension);
data = result.$1;
return Uri.file(result.$2, windows: false).toString();
}
Expand Down
22 changes: 11 additions & 11 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ packages:
source: hosted
version: "0.3.4+2"
crypto:
dependency: transitive
dependency: "direct main"
description:
name: crypto
sha256: "1e445881f28f22d6140f181e07737b22f1e099a5e1ff94b0af2f9e4a463f4855"
Expand Down Expand Up @@ -434,10 +434,10 @@ packages:
dependency: transitive
description:
name: file_selector_linux
sha256: b2b91daf8a68ecfa4a01b778a6f52edef9b14ecd506e771488ea0f2e0784198b
sha256: "54cbbd957e1156d29548c7d9b9ec0c0ebb6de0a90452198683a7d23aed617a33"
url: "https://pub.dev"
source: hosted
version: "0.9.3+1"
version: "0.9.3+2"
file_selector_macos:
dependency: transitive
description:
Expand Down Expand Up @@ -602,10 +602,10 @@ packages:
dependency: "direct main"
description:
name: flutter_svg
sha256: "936d9c1c010d3e234d1672574636f3352b4941ca3decaddd3cafaeb9ad49c471"
sha256: "54900a1a1243f3c4a5506d853a2b5c2dbc38d5f27e52a52618a8054401431123"
url: "https://pub.dev"
source: hosted
version: "2.0.15"
version: "2.0.16"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -996,10 +996,10 @@ packages:
dependency: transitive
description:
name: path_provider_android
sha256: c464428172cb986b758c6d1724c603097febb8fb855aa265aeecc9280c294d4a
sha256: "8c4967f8b7cb46dc914e178daa29813d83ae502e0529d7b0478330616a691ef7"
url: "https://pub.dev"
source: hosted
version: "2.2.12"
version: "2.2.14"
path_provider_foundation:
dependency: transitive
description:
Expand Down Expand Up @@ -1229,10 +1229,10 @@ packages:
dependency: transitive
description:
name: sembast
sha256: "61f893e50fe2fa7d14529d275d45ac31871d7ad2ae3a745f9aa3afc0b447d75b"
sha256: b20afd98c44bfc272d57a82cb191fbb728875c95e06c973149666f27d81d6afd
url: "https://pub.dev"
source: hosted
version: "3.7.5+2"
version: "3.8.0"
share_plus:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1562,10 +1562,10 @@ packages:
dependency: transitive
description:
name: vector_graphics_compiler
sha256: ab9ff38fc771e9ee1139320adbe3d18a60327370c218c60752068ebee4b49ab1
sha256: "1b4b9e706a10294258727674a340ae0d6e64a7231980f9f9a3d12e4b42407aad"
url: "https://pub.dev"
source: hosted
version: "1.1.15"
version: "1.1.16"
vector_math:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ dependencies:
one_dollar_unistroke_recognizer: ^1.2.0
super_clipboard: ^0.9.0-dev.4
web: ^1.0.0
crypto: ^3.0.6
dev_dependencies:
flutter_native_splash: ^2.4.0
flutter_lints: ^5.0.0
Expand Down
6 changes: 3 additions & 3 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
},
"dependencies": {
"@astrojs/check": "^0.9.4",
"@astrojs/react": "^3.6.2",
"@astrojs/react": "^3.6.3",
"@astrojs/starlight": "^0.29.2",
"@phosphor-icons/react": "^2.1.7",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"astro": "^4.16.13",
"astro": "^4.16.16",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"remark-gemoji": "^8.0.0",
"remark-heading-id": "^1.0.1",
"sharp": "^0.33.5",
"typescript": "^5.6.3"
"typescript": "^5.7.2"
},
"packageManager": "[email protected]",
"devDependencies": {
Expand Down
Loading

0 comments on commit 2335bdb

Please sign in to comment.