Skip to content

feat(attachments)!: cater for subdirectories in storage #78

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

Merged
merged 4 commits into from
May 2, 2024

Conversation

DominicGBauer
Copy link
Contributor

@DominicGBauer DominicGBauer commented Apr 23, 2024

Description

  • Allow subdirectories in storage to also be used in attachments queue
  • Rename methods to make them more general

Work Done

  • Allow subdirectories to be set on queue initializing which will create a subdirectory locally to match what is on remote storage
  • Renamed savePhoto and deletePhoto methods to saveFile and deleteFile - this introduces a BREAKING CHANGE

How to test

Using todolist demo:

  1. When initializing the queue in queue.dart add a subdirectory e.g. ['cover-images']
  PhotoAttachmentQueue(db, remoteStorage)
      : super(
            db: db,
            remoteStorage: remoteStorage,
            onDownloadError: onDownloadError,
            subdirectories: ['cover-images']);
  1. Update _takePhoto method in photo_capture_widget.dart to this (bold is what has been changed, the ID now captures the subdirectory):
  Future<void> _takePhoto(context) async {
    try {
      // Ensure the camera is initialized before taking a photo
      await _initializeControllerFuture;

      final XFile photo = await _cameraController.takePicture();
      // copy photo to new directory with ID as name
      String subdirectory = 'cover-images'; <--------
      String photoId = '$subdirectory/${powersync.uuid.v4()}'; <--------
      String storageDirectory = await attachmentQueue.getStorageDirectory();
      await attachmentQueue.localStorage
          .copyFile(photo.path, '$storageDirectory/$photoId.jpg');

      int photoSize = await photo.length();

      TodoItem.addPhoto(photoId, widget.todoId);
      attachmentQueue.saveFile(photoId, photoSize);
    } catch (e) {
      log.info('Error taking photo: $e');
    }

    // After taking the photo, navigate back to the previous screen
    Navigator.pop(context);
  }
  1. Load the app and take a photo after creating a todo
  2. You should see the image in a subfolder on supabase
  3. Load the app on another device and you should see the image download onto the device and display correctly

@DominicGBauer DominicGBauer requested a review from rkistner April 23, 2024 12:01
@DominicGBauer DominicGBauer self-assigned this Apr 23, 2024
@DominicGBauer DominicGBauer merged commit a0e74e6 into master May 2, 2024
@DominicGBauer DominicGBauer deleted the feat/add-subdirectories-to-attachments branch May 2, 2024 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants