Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Move discover json to local assets

laurenspriemde4bd4c5e8b9
diff --git a/mobile/apps/photos/assets/discover.json b/mobile/apps/photos/assets/discover.json
new file mode 100644
index 0000000000..e84c642d4f
--- /dev/null
+++ b/mobile/apps/photos/assets/discover.json
@@ -0,0 +1,116 @@
+{
+ "prompts": [
+ {
+ "query": "identity documents and cards",
+ "title": "Identity",
+ "minScore": 0.20,
+ "minSize": 0.0,
+ "showVideo" : false
+ },
+ {
+ "query": "screenshots",
+ "title": "Screenshots",
+ "minScore": 0.18,
+ "minSize": 0.0,
+ "recentFirst" : true,
+ "showVideo" : false
+ },
+ {
+ "query": "image containing a black and white QR code",
+ "title": "QR Codes",
+ "minScore": 0.20,
+ "minSize": 0.0,
+ "recentFirst" : true,
+ "showVideo" : false
+ },
+ {
+ "query": "receipts, bills and invoices",
+ "title": "Receipts",
+ "minScore": 0.20,
+ "minSize": 0.0,
+ "recentFirst" : true
+ },
+ {
+ "query": "screenshots of digital notes, photos of notebook and whiteboards",
+ "title": "Notes",
+ "minScore": 0.20,
+ "minSize": 0.0,
+ "recentFirst" : true
+ },
+ {
+ "query": "memes",
+ "title": "Memes",
+ "minScore": 0.18,
+ "minSize": 0.0,
+ "recentFirst" : true
+ },
+ {
+ "query": "business card",
+ "title": "Visiting Cards",
+ "minScore": 0.20,
+ "minSize": 0.0,
+ "recentFirst" : true,
+ "showVideo" : false
+ },
+ {
+ "query": "photo of toddler",
+ "title": "Babies",
+ "minScore": 0.20,
+ "minSize": 0.0,
+ "recentFirst" : true
+ },
+ {
+ "query": "photos of pets",
+ "title": "Pets",
+ "minScore": 0.20,
+ "minSize": 0.0,
+ "recentFirst" : true
+ },
+ {
+ "query": "selfie",
+ "title": "Selfies",
+ "minScore": 0.18,
+ "minSize": 0.0,
+ "recentFirst" : true
+ },
+ {
+ "query": "high resolution hd wallpaper",
+ "title": "Wallpapers",
+ "minScore": 0.18,
+ "minSize": 0.0,
+ "showVideo" : false
+ },
+ {
+ "query": "photo of food",
+ "title": "Food",
+ "minScore": 0.20,
+ "minSize": 0.0,
+ "recentFirst" : true
+ },
+ {
+ "query": "celebration with friends",
+ "title": "Celebrations",
+ "minScore": 0.20,
+ "minSize": 0.0,
+ "recentFirst" : true
+ },
+ {
+ "query": "photo of setting sun",
+ "title": "Sunset",
+ "minScore": 0.20,
+ "minSize": 0.0
+ },
+ {
+ "query": "photo of mountains or hills",
+ "title": "Hills",
+ "minScore": 0.20,
+ "minSize": 0.0
+ },
+ {
+ "query": "outdoor photo of trees, leaves, flowers",
+ "title": "Greenery",
+ "minScore": 0.20,
+ "minSize": 0.0
+ }
+ ]
+}
diff --git a/mobile/apps/photos/lib/models/ml/discover/prompt.dart b/mobile/apps/photos/lib/models/ml/discover/prompt.dart
index fdc1bd93f7..3e9c94c942 100644
--- a/mobile/apps/photos/lib/models/ml/discover/prompt.dart
+++ b/mobile/apps/photos/lib/models/ml/discover/prompt.dart
@@ -1,4 +1,4 @@
-// https://discover.ente.io/v3.json
+// Loaded from assets/discover.json
class Prompt {
final String id;
final int position;
diff --git a/mobile/apps/photos/lib/services/magic_cache_service.dart b/mobile/apps/photos/lib/services/magic_cache_service.dart
index 1885f58bc2..9f032c7308 100644
--- a/mobile/apps/photos/lib/services/magic_cache_service.dart
+++ b/mobile/apps/photos/lib/services/magic_cache_service.dart
@@ -2,9 +2,9 @@ import "dart:async";
import "dart:convert";
import "dart:io";
-import "package:computer/computer.dart";
import "package:ente_pure_utils/ente_pure_utils.dart";
import "package:flutter/foundation.dart";
+import "package:flutter/services.dart";
import "package:flutter/widgets.dart";
import "package:logging/logging.dart";
import "package:path_provider/path_provider.dart";
@@ -22,7 +22,6 @@ import "package:photos/models/search/hierarchical/magic_filter.dart";
import "package:photos/models/search/search_types.dart";
import "package:photos/service_locator.dart";
import "package:photos/services/machine_learning/semantic_search/semantic_search_service.dart";
-import "package:photos/services/remote_assets_service.dart";
import "package:photos/services/search_service.dart";
import "package:photos/ui/viewer/search/result/magic_result_screen.dart";
import "package:photos/utils/cache_util.dart";
@@ -228,7 +227,7 @@ GenericSearchResult? toGenericSearchResult(
class MagicCacheService {
static const _lastMagicCacheUpdateTime = "last_magic_cache_update_time";
- static const _kMagicPromptsDataUrl = "https://discover.ente.io/v3.json";
+ static const _kPromptsAssetPath = "assets/discover.json";
/// Delay is for cache update to be done not during app init, during which a
/// lot of other things are happening.
@@ -281,11 +280,7 @@ class MagicCacheService {
if (!enableDiscover) {
return;
}
- final updatedJSONFile = await RemoteAssetsService.instance
- .getAssetIfUpdated(_kMagicPromptsDataUrl);
- if (updatedJSONFile != null) {
- queueUpdate("Prompts data updated");
- } else if (lastMagicCacheUpdateTime <
+ if (lastMagicCacheUpdateTime <
DateTime.now()
.subtract(const Duration(hours: 12))
.millisecondsSinceEpoch) {
@@ -346,7 +341,7 @@ class MagicCacheService {
return;
}
try {
- final prompts = await _readPromptFromDiskOrNetwork();
+ final prompts = await _readPromptsFromAssets();
final magicCaches = await _readResultFromDisk();
_promptFuture = Future.value(prompts);
_magicCacheFuture = Future.value(magicCaches);
@@ -360,7 +355,7 @@ class MagicCacheService {
if (_promptFuture != null) {
return _promptFuture!;
}
- _promptFuture = _readPromptFromDiskOrNetwork();
+ _promptFuture = _readPromptsFromAssets();
return _promptFuture!;
}
@@ -372,15 +367,13 @@ class MagicCacheService {
return _magicCacheFuture!;
}
- Future<List<Prompt>> _readPromptFromDiskOrNetwork() async {
- final String path =
- await RemoteAssetsService.instance.getAssetPath(_kMagicPromptsDataUrl);
- return Computer.shared().compute(
- _loadMagicPrompts,
- param: <String, dynamic>{
- "path": path,
- },
- );
+ Future<List<Prompt>> _readPromptsFromAssets() async {
+ final String contents = await rootBundle.loadString(_kPromptsAssetPath);
+ final Map<String, dynamic> promptsJson = jsonDecode(contents);
+ final List<dynamic> promptData = promptsJson['prompts'];
+ return promptData
+ .map<Prompt>((jsonItem) => Prompt.fromJson(jsonItem))
+ .toList();
}
Future<List<MagicCache>> _readResultFromDisk() async {
@@ -529,19 +522,6 @@ class MagicCacheService {
}
}
- static Future<List<Prompt>> _loadMagicPrompts(
- Map<String, dynamic> args,
- ) async {
- final String path = args["path"] as String;
- final File file = File(path);
- final String contents = await file.readAsString();
- final Map<String, dynamic> promptsJson = jsonDecode(contents);
- final List<dynamic> promptData = promptsJson['prompts'];
- return promptData
- .map<Prompt>((jsonItem) => Prompt.fromJson(jsonItem))
- .toList();
- }
-
///Returns non-empty magic results from magicPromptsData
///Length is number of prompts, can be less if there are not enough non-empty
///results