Skip to content

Commit

Permalink
Merge pull request #443 from ardriveapp/1.12.1-release
Browse files Browse the repository at this point in the history
PE-1297: Release v1.12.1
  • Loading branch information
Karl Prieb authored Apr 11, 2022
2 parents 2aef356 + d14da81 commit 7ceef4b
Show file tree
Hide file tree
Showing 22 changed files with 1,485 additions and 140 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/deploy-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
flutter pub run build_runner build
flutter config --enable-web
flutter build web --profile
- name: main.dart.js cache invalidation
run: |
sed -i 's/main.dart.js/main.dart.js?version='"$GITHUB_SHA"'/' build/web/index.html
- uses: JamesIves/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/deploy-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
flutter pub run build_runner build
flutter config --enable-web
flutter build web
- name: main.dart.js cache invalidation
run: |
sed -i 's/main.dart.js/main.dart.js?version='"$GITHUB_SHA"'/' build/web/index.html
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
Expand Down
18 changes: 3 additions & 15 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,6 @@ on:
- gh-pages
- master
jobs:
# test:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# with:
# persist-credentials: false
# - uses: subosito/flutter-action@v1
# with:
# channel: 'stable'
# - name: Prepare app
# run: |
# flutter pub get
# flutter pub run build_runner build
# - name: Run tests
# run: flutter test
deploy-preview:
runs-on: ubuntu-latest
steps:
Expand All @@ -35,6 +20,9 @@ jobs:
flutter pub run build_runner build
flutter config --enable-web
flutter build web --profile
- name: main.dart.js cache invalidation
run: |
sed -i 's/main.dart.js/main.dart.js?version='"$GITHUB_SHA"'/' build/web/index.html
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
Expand Down
11 changes: 5 additions & 6 deletions lib/blocs/folder_create/folder_create_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,11 @@ class FolderCreateCubit extends Cubit<FolderCreateState> {
AbstractControl<dynamic> control) async {
final String folderName = control.value;

// Check that the parent folder does not already have a folder with the input name.
final foldersWithName = await _driveDao
.foldersInFolderWithName(
driveId: driveId, parentFolderId: parentFolderId, name: folderName)
.get();
final nameAlreadyExists = foldersWithName.isNotEmpty;
final nameAlreadyExists = await _driveDao.doesEntityWithNameExist(
name: folderName,
driveId: driveId,
parentFolderId: parentFolderId,
);

if (nameAlreadyExists) {
control.markAsTouched();
Expand Down
31 changes: 12 additions & 19 deletions lib/blocs/fs_entry_move/fs_entry_move_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,6 @@ class FsEntryMoveCubit extends Cubit<FsEntryMoveState> {
);
}

Future<bool> entityNameExists({
required String name,
required String parentFolderId,
}) async {
final foldersWithName = await _driveDao
.foldersInFolderWithName(
driveId: driveId, parentFolderId: parentFolderId, name: name)
.get();
final filesWithName = await _driveDao
.filesInFolderWithName(
driveId: driveId, parentFolderId: parentFolderId, name: name)
.get();
return foldersWithName.isNotEmpty || filesWithName.isNotEmpty;
}

Future<void> submit() async {
try {
final state = this.state as FsEntryMoveFolderLoadSuccess;
Expand All @@ -100,10 +85,14 @@ class FsEntryMoveCubit extends Cubit<FsEntryMoveState> {
.folderById(driveId: driveId, folderId: folderId!)
.getSingle();

if (await entityNameExists(
final entityWithSameNameExists =
await _driveDao.doesEntityWithNameExist(
name: folder.name,
driveId: driveId,
parentFolderId: parentFolder.id,
)) {
);

if (entityWithSameNameExists) {
emit(FsEntryMoveNameConflict(name: folder.name));
return;
}
Expand Down Expand Up @@ -140,10 +129,14 @@ class FsEntryMoveCubit extends Cubit<FsEntryMoveState> {
path: '${parentFolder.path}/${file.name}',
lastUpdated: DateTime.now());

if (await entityNameExists(
final entityWithSameNameExists =
await _driveDao.doesEntityWithNameExist(
name: file.name,
driveId: driveId,
parentFolderId: parentFolder.id,
)) {
);

if (entityWithSameNameExists) {
emit(FsEntryMoveNameConflict(name: file.name));
return;
}
Expand Down
33 changes: 14 additions & 19 deletions lib/blocs/fs_entry_rename/fs_entry_rename_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,14 @@ class FsEntryRenameCubit extends Cubit<FsEntryRenameState> {
return {AppValidationMessage.fsEntryNameUnchanged: true};
}

// Check that the current folder does not already have a folder with the target file name.
final foldersWithName = await _driveDao
.foldersInFolderWithName(
driveId: driveId,
parentFolderId: folder.parentFolderId,
name: newFolderName)
.get();
final nameAlreadyExists = foldersWithName.isNotEmpty;

if (nameAlreadyExists) {
final entityWithSameNameExists = await _driveDao.doesEntityWithNameExist(
name: newFolderName,
driveId: driveId,
// Will never be null since you can't rename root folder
parentFolderId: folder.parentFolderId!,
);

if (entityWithSameNameExists) {
control.markAsTouched();
return {AppValidationMessage.fsEntryNameAlreadyPresent: true};
}
Expand All @@ -182,16 +180,13 @@ class FsEntryRenameCubit extends Cubit<FsEntryRenameState> {
return {AppValidationMessage.fsEntryNameUnchanged: true};
}

// Check that the current folder does not already have a file with the target file name.
final filesWithName = await _driveDao
.filesInFolderWithName(
driveId: driveId,
parentFolderId: file.parentFolderId,
name: newFileName)
.get();
final nameAlreadyExists = filesWithName.isNotEmpty;
final entityWithSameNameExists = await _driveDao.doesEntityWithNameExist(
name: newFileName,
driveId: driveId,
parentFolderId: file.parentFolderId,
);

if (nameAlreadyExists) {
if (entityWithSameNameExists) {
control.markAsTouched();
return {AppValidationMessage.fsEntryNameAlreadyPresent: true};
}
Expand Down
94 changes: 71 additions & 23 deletions lib/blocs/upload/upload_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,20 @@ class UploadCubit extends Cubit<UploadState> {

/// Map of conflicting file ids keyed by their file names.
final Map<String, String> conflictingFiles = {};
final List<String> conflictingFolders = [];

bool fileSizeWithinBundleLimits(int size) => size < bundleSizeLimit;

UploadCubit(
{required this.driveId,
required this.folderId,
required this.files,
required ProfileCubit profileCubit,
required DriveDao driveDao,
required ArweaveService arweave,
required PstService pst,
required UploadPlanUtils uploadPlanUtils})
: _profileCubit = profileCubit,
UploadCubit({
required this.driveId,
required this.folderId,
required this.files,
required ProfileCubit profileCubit,
required DriveDao driveDao,
required ArweaveService arweave,
required PstService pst,
required UploadPlanUtils uploadPlanUtils,
}) : _profileCubit = profileCubit,
_driveDao = driveDao,
_arweave = arweave,
_pst = pst,
Expand All @@ -69,9 +70,43 @@ class UploadCubit extends Cubit<UploadState> {
///
/// If there's one, prompt the user to upload the file as a version of the existing one.
/// If there isn't one, prepare to upload the file.
Future<void> checkConflictingFolders() async {
emit(UploadPreparationInProgress());

for (final file in files) {
final fileName = file.name;
final existingFolderName = await _driveDao
.foldersInFolderWithName(
driveId: _targetDrive.id,
parentFolderId: _targetFolder.id,
name: fileName,
)
.map((f) => f.name)
.getSingleOrNull();

if (existingFolderName != null) {
conflictingFolders.add(existingFolderName);
}
}

if (conflictingFolders.isNotEmpty) {
emit(
UploadFolderNameConflict(
areAllFilesConflicting: conflictingFolders.length == files.length,
conflictingFileNames: conflictingFolders,
),
);
} else {
await checkConflictingFiles();
}
}

Future<void> checkConflictingFiles() async {
emit(UploadPreparationInProgress());

_removeFilesWithFolderNameConflicts();

for (final file in files) {
final fileName = file.name;
final existingFileId = await _driveDao
Expand All @@ -89,17 +124,21 @@ class UploadCubit extends Cubit<UploadState> {
}

if (conflictingFiles.isNotEmpty) {
emit(UploadFileConflict(
isAllFilesConflicting: conflictingFiles.length == files.length,
conflictingFileNames: conflictingFiles.keys.toList()));
emit(
UploadFileConflict(
areAllFilesConflicting: conflictingFiles.length == files.length,
conflictingFileNames: conflictingFiles.keys.toList(),
),
);
} else {
await prepareUploadPlanAndCostEstimates();
}
}

/// If `conflictingFileAction` is null, means that had no conflict.
Future<void> prepareUploadPlanAndCostEstimates(
{ConflictingFileActions? conflictingFileAction}) async {
Future<void> prepareUploadPlanAndCostEstimates({
ConflictingFileActions? conflictingFileAction,
}) async {
final profile = _profileCubit.state as ProfileLoggedIn;

if (await _profileCubit.checkIfWalletMismatch()) {
Expand All @@ -116,7 +155,7 @@ class UploadCubit extends Cubit<UploadState> {
_targetDrive.isPrivate ? privateFileSizeLimit : publicFileSizeLimit;

if (conflictingFileAction == ConflictingFileActions.Skip) {
_removeConflictingFiles();
_removeFilesWithFileNameConflicts();
}

final tooLargeFiles = [
Expand All @@ -131,23 +170,28 @@ class UploadCubit extends Cubit<UploadState> {
));
return;
}

final uploadPlan = await _uploadPlanUtils.xfilesToUploadPlan(
folderEntry: _targetFolder,
targetDrive: _targetDrive,
files: files,
cipherKey: profile.cipherKey,
wallet: profile.wallet,
conflictingFiles: conflictingFiles);
folderEntry: _targetFolder,
targetDrive: _targetDrive,
files: files,
cipherKey: profile.cipherKey,
wallet: profile.wallet,
conflictingFiles: conflictingFiles,
);

final costEstimate = await CostEstimate.create(
uploadPlan: uploadPlan,
arweaveService: _arweave,
pstService: _pst,
wallet: profile.wallet,
);

if (await _profileCubit.checkIfWalletMismatch()) {
emit(UploadWalletMismatch());
return;
}

emit(
UploadReady(
costEstimate: costEstimate,
Expand Down Expand Up @@ -220,10 +264,14 @@ class UploadCubit extends Cubit<UploadState> {
emit(UploadComplete());
}

void _removeConflictingFiles() {
void _removeFilesWithFileNameConflicts() {
files.removeWhere((element) => conflictingFiles.containsKey(element.name));
}

void _removeFilesWithFolderNameConflicts() {
files.removeWhere((element) => conflictingFolders.contains(element.name));
}

@override
void onError(Object error, StackTrace stackTrace) {
emit(UploadFailure());
Expand Down
14 changes: 12 additions & 2 deletions lib/blocs/upload/upload_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,27 @@ class UploadSigningInProgress extends UploadState {

class UploadFileConflict extends UploadState {
final List<String> conflictingFileNames;
final bool isAllFilesConflicting;
final bool areAllFilesConflicting;

UploadFileConflict({
required this.conflictingFileNames,
required this.isAllFilesConflicting,
required this.areAllFilesConflicting,
});

@override
List<Object> get props => [conflictingFileNames];
}

class UploadFolderNameConflict extends UploadFileConflict {
UploadFolderNameConflict({
required List<String> conflictingFileNames,
required bool areAllFilesConflicting,
}) : super(
conflictingFileNames: conflictingFileNames,
areAllFilesConflicting: areAllFilesConflicting,
);
}

class UploadFileTooLarge extends UploadState {
final List<String> tooLargeFileNames;
final bool isPrivate;
Expand Down
5 changes: 3 additions & 2 deletions lib/components/app_drawer/app_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ class AppDrawer extends StatelessWidget {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'Version ${snapshot.data!.version}',
appLocalizationsOf(context)
.appVersion(snapshot.data!.version),
style: Theme.of(context)
.textTheme
.caption!
Expand Down Expand Up @@ -291,7 +292,7 @@ class AppDrawer extends StatelessWidget {
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
R.insufficientARWarning,
appLocalizationsOf(context).insufficientARWarning,
style: Theme.of(context)
.textTheme
.caption!
Expand Down
Loading

0 comments on commit 7ceef4b

Please sign in to comment.