magic-metadata: rename
This commit is contained in:
parent
a71af7d1d5
commit
81eeeb7aeb
8 changed files with 32 additions and 33 deletions
|
@ -6,7 +6,7 @@ import 'package:path_provider/path_provider.dart';
|
|||
import 'package:photos/models/backup_status.dart';
|
||||
import 'package:photos/models/file.dart';
|
||||
import 'package:photos/models/file_load_result.dart';
|
||||
import 'package:photos/models/file_magic_metadata.dart';
|
||||
import 'package:photos/models/magic_metadata.dart';
|
||||
import 'package:photos/models/file_type.dart';
|
||||
import 'package:photos/models/location.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
|
@ -241,7 +241,7 @@ class FilesDB {
|
|||
static List<String> addMagicMetadataColumns() {
|
||||
return [
|
||||
'''
|
||||
ALTER TABLE $table ADD COLUMN $columnMMdEncodedJson Text DEFAULT '{}';
|
||||
ALTER TABLE $table ADD COLUMN $columnMMdEncodedJson TEXT DEFAULT '{}';
|
||||
''',
|
||||
'''
|
||||
ALTER TABLE $table ADD COLUMN $columnMMdVersion INTEGER DEFAULT 0;
|
||||
|
@ -914,7 +914,7 @@ class FilesDB {
|
|||
row[columnMMdVersion] = file.mMdVersion ?? 0;
|
||||
row[columnMMdEncodedJson] = file.mMdEncodedJson ?? '{}';
|
||||
row[columnMMdVisibility] =
|
||||
file.fileMagicMetadata?.visibility ?? kVisibilityVisible;
|
||||
file.magicMetadata?.visibility ?? kVisibilityVisible;
|
||||
return row;
|
||||
}
|
||||
|
||||
|
@ -945,7 +945,7 @@ class FilesDB {
|
|||
row[columnMMdVersion] = file.mMdVersion ?? 0;
|
||||
row[columnMMdEncodedJson] == file.mMdEncodedJson ?? '{}';
|
||||
row[columnMMdVisibility] =
|
||||
file.fileMagicMetadata?.visibility ?? kVisibilityVisible;
|
||||
file.magicMetadata?.visibility ?? kVisibilityVisible;
|
||||
return row;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import 'package:path/path.dart';
|
|||
import 'package:photo_manager/photo_manager.dart';
|
||||
import 'package:photos/core/configuration.dart';
|
||||
import 'package:photos/core/constants.dart';
|
||||
import 'package:photos/models/file_magic_metadata.dart';
|
||||
import 'package:photos/models/magic_metadata.dart';
|
||||
import 'package:photos/models/file_type.dart';
|
||||
import 'package:photos/models/location.dart';
|
||||
import 'package:photos/services/feature_flag_service.dart';
|
||||
|
@ -38,10 +38,10 @@ class File {
|
|||
|
||||
String mMdEncodedJson;
|
||||
int mMdVersion = 0;
|
||||
FileMagicMetadata _fileMMd;
|
||||
FileMagicMetadata get fileMagicMetadata =>
|
||||
_fileMMd ?? FileMagicMetadata.fromEncodedJson(mMdEncodedJson ?? '{}');
|
||||
set fileMagicMetadata (val) => _fileMMd = val;
|
||||
MagicMetadata _mmd;
|
||||
MagicMetadata get magicMetadata =>
|
||||
_mmd ?? MagicMetadata.fromEncodedJson(mMdEncodedJson ?? '{}');
|
||||
set magicMetadata (val) => _mmd = val;
|
||||
|
||||
static const kCurrentMetadataVersion = 1;
|
||||
|
||||
|
|
|
@ -5,29 +5,29 @@ const kVisibilityArchive = 1;
|
|||
|
||||
const kMagicKeyVisibility = 'visibility';
|
||||
|
||||
class FileMagicMetadata {
|
||||
class MagicMetadata {
|
||||
// 0 -> visible
|
||||
// 1 -> archived
|
||||
// 2 -> hidden etc?
|
||||
int visibility;
|
||||
|
||||
FileMagicMetadata({this.visibility});
|
||||
MagicMetadata({this.visibility});
|
||||
|
||||
factory FileMagicMetadata.fromEncodedJson(String encodedJson) =>
|
||||
FileMagicMetadata.fromJson(jsonDecode(encodedJson));
|
||||
factory MagicMetadata.fromEncodedJson(String encodedJson) =>
|
||||
MagicMetadata.fromJson(jsonDecode(encodedJson));
|
||||
|
||||
factory FileMagicMetadata.fromJson(dynamic json) =>
|
||||
FileMagicMetadata.fromMap(json);
|
||||
factory MagicMetadata.fromJson(dynamic json) =>
|
||||
MagicMetadata.fromMap(json);
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
var map = <String, dynamic>{};
|
||||
final map = <String, dynamic>{};
|
||||
map[kMagicKeyVisibility] = visibility;
|
||||
return map;
|
||||
}
|
||||
|
||||
factory FileMagicMetadata.fromMap(Map<String, dynamic> map) {
|
||||
factory MagicMetadata.fromMap(Map<String, dynamic> map) {
|
||||
if (map == null) return null;
|
||||
return FileMagicMetadata(
|
||||
return MagicMetadata(
|
||||
visibility: map[kMagicKeyVisibility] ?? kVisibilityVisible,
|
||||
);
|
||||
}
|
|
@ -9,7 +9,7 @@ import 'package:photos/db/files_db.dart';
|
|||
import 'package:photos/events/files_updated_event.dart';
|
||||
import 'package:photos/models/file.dart';
|
||||
import 'package:photos/core/configuration.dart';
|
||||
import 'package:photos/models/file_magic_metadata.dart';
|
||||
import 'package:photos/models/magic_metadata.dart';
|
||||
import 'package:photos/services/remote_sync_service.dart';
|
||||
|
||||
import '../utils/crypto_util.dart';
|
||||
|
@ -38,14 +38,14 @@ class FileMagicService {
|
|||
List<File> files, Map<String, dynamic> newMetadataUpdate) async {
|
||||
final params = <String, dynamic>{};
|
||||
params['metadataList'] = [];
|
||||
int ownerID = Configuration.instance.getUserID();
|
||||
final int ownerID = Configuration.instance.getUserID();
|
||||
try {
|
||||
for (final file in files) {
|
||||
if (file.uploadedFileID == null) {
|
||||
throw AssertionError(
|
||||
"operation is only supported on backed up files");
|
||||
} else if (file.ownerID != ownerID) {
|
||||
throw AssertionError("can not modify memories not owned by you");
|
||||
throw AssertionError("cannot modify memories not owned by you");
|
||||
}
|
||||
// read the existing magic metadata and apply new updates to existing data
|
||||
// current update is simple replace. This will be enhanced in the future,
|
||||
|
@ -57,7 +57,7 @@ class FileMagicService {
|
|||
|
||||
// update the local information so that it's reflected on UI
|
||||
file.mMdEncodedJson = jsonEncode(jsonToUpdate);
|
||||
file.fileMagicMetadata = FileMagicMetadata.fromJson(jsonToUpdate);
|
||||
file.magicMetadata = MagicMetadata.fromJson(jsonToUpdate);
|
||||
|
||||
final fileKey = decryptFileKey(file);
|
||||
final encryptedMMd = await CryptoUtil.encryptChaCha(
|
||||
|
@ -110,7 +110,7 @@ class UpdateMagicMetadata {
|
|||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
var map = <String, dynamic>{};
|
||||
final map = <String, dynamic>{};
|
||||
map['id'] = id;
|
||||
if (magicMetadata != null) {
|
||||
map['magicMetadata'] = magicMetadata.toJson();
|
||||
|
|
|
@ -6,7 +6,7 @@ import 'package:photos/core/configuration.dart';
|
|||
import 'package:photos/core/event_bus.dart';
|
||||
import 'package:photos/db/files_db.dart';
|
||||
import 'package:photos/events/files_updated_event.dart';
|
||||
import 'package:photos/models/file_magic_metadata.dart';
|
||||
import 'package:photos/models/magic_metadata.dart';
|
||||
import 'package:photos/models/selected_files.dart';
|
||||
|
||||
import 'gallery.dart';
|
||||
|
@ -19,7 +19,7 @@ class ArchivePage extends StatelessWidget {
|
|||
|
||||
ArchivePage(
|
||||
{this.tagPrefix = "archived_page",
|
||||
this.appBarType = GalleryAppBarType.archivedPage,
|
||||
this.appBarType = GalleryAppBarType.archive,
|
||||
Key key})
|
||||
: super(key: key);
|
||||
|
||||
|
|
|
@ -23,8 +23,7 @@ import 'package:photos/ui/thumbnail_widget.dart';
|
|||
import 'package:photos/utils/local_settings.dart';
|
||||
import 'package:photos/utils/navigation_util.dart';
|
||||
import 'package:photos/utils/toast_util.dart';
|
||||
|
||||
import 'archive_page.dart';
|
||||
import 'package:photos/ui/archive_page.dart';
|
||||
|
||||
class CollectionsGalleryWidget extends StatefulWidget {
|
||||
const CollectionsGalleryWidget({Key key}) : super(key: key);
|
||||
|
|
|
@ -10,7 +10,7 @@ import 'package:photos/core/configuration.dart';
|
|||
import 'package:photos/core/event_bus.dart';
|
||||
import 'package:photos/events/subscription_purchased_event.dart';
|
||||
import 'package:photos/models/collection.dart';
|
||||
import 'package:photos/models/file_magic_metadata.dart';
|
||||
import 'package:photos/models/magic_metadata.dart';
|
||||
import 'package:photos/models/selected_files.dart';
|
||||
import 'package:photos/services/collections_service.dart';
|
||||
import 'package:photos/ui/create_collection_page.dart';
|
||||
|
@ -23,7 +23,7 @@ import 'package:photos/utils/toast_util.dart';
|
|||
|
||||
enum GalleryAppBarType {
|
||||
homepage,
|
||||
archivedPage,
|
||||
archive,
|
||||
local_folder,
|
||||
// indicator for gallery view of collections shared with the user
|
||||
shared_collection,
|
||||
|
@ -213,7 +213,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
|
|||
},
|
||||
));
|
||||
if (widget.type == GalleryAppBarType.homepage ||
|
||||
widget.type == GalleryAppBarType.archivedPage ||
|
||||
widget.type == GalleryAppBarType.archive ||
|
||||
widget.type == GalleryAppBarType.local_folder) {
|
||||
actions.add(IconButton(
|
||||
icon: Icon(
|
||||
|
@ -243,7 +243,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
|
|||
}
|
||||
|
||||
if (widget.type == GalleryAppBarType.homepage ||
|
||||
widget.type == GalleryAppBarType.archivedPage) {
|
||||
widget.type == GalleryAppBarType.archive) {
|
||||
bool showArchive = widget.type == GalleryAppBarType.homepage;
|
||||
actions.add(PopupMenuButton(
|
||||
itemBuilder: (context) {
|
||||
|
|
|
@ -11,7 +11,7 @@ import 'package:photos/events/collection_updated_event.dart';
|
|||
import 'package:photos/events/local_photos_updated_event.dart';
|
||||
import 'package:photos/events/remote_sync_event.dart';
|
||||
import 'package:photos/models/file.dart';
|
||||
import 'package:photos/models/file_magic_metadata.dart';
|
||||
import 'package:photos/models/magic_metadata.dart';
|
||||
import 'package:photos/utils/crypto_util.dart';
|
||||
import 'package:photos/utils/file_download_util.dart';
|
||||
|
||||
|
@ -88,7 +88,7 @@ class DiffFetcher {
|
|||
Sodium.base642bin(item['magicMetadata']['header']));
|
||||
file.mMdEncodedJson = utf8.decode(utfEncodedMmd);
|
||||
file.mMdVersion = item['magicMetadata']['version'];
|
||||
file.fileMagicMetadata = FileMagicMetadata.fromEncodedJson(file.mMdEncodedJson);
|
||||
file.magicMetadata = MagicMetadata.fromEncodedJson(file.mMdEncodedJson);
|
||||
}
|
||||
files.add(file);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue