Skip to content
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

Support for array of attachments #11

Open
pomarec opened this issue Feb 6, 2025 · 14 comments
Open

Support for array of attachments #11

pomarec opened this issue Feb 6, 2025 · 14 comments

Comments

@pomarec
Copy link

pomarec commented Feb 6, 2025

Hi,

Thanks for the work on this package.

Is it planned to support attachmentS ?

class User extends compose(BaseModel, Attachmentable) {
  @attachments()
  declare avatar: Attachment[]
}

Best

@batosai
Copy link
Owner

batosai commented Feb 7, 2025

Not at the moment, but I keep the idea to think about it.

Thanks

@corentinclichy
Copy link

First thanks a lot for the lib! This is really cool!
Just comment to follow this. I am really interested by multi file uploads

@batosai
Copy link
Owner

batosai commented Feb 28, 2025

Hello,

The development is in progress :)

@batosai
Copy link
Owner

batosai commented Mar 6, 2025

Hello,

I just released a beta version with this feature.

npm i @jrmc/adonis-attachment@beta
  @attachments({
    disk: 'minio',
    folder: 'users',
    variants: ['thumbnail']
  })
  declare files: Attachment[] | null
async update({ request, response }: HttpContext) {
    const user = await User.first()

    const avatar = request.file('avatar')
    const files = request.files('files')

    if (user) {
      if (avatar) {
        user.avatar = await attachmentManager.createFromFile(avatar)
      }

      if (files.length) {
        user.files = await attachmentManager.createFromFiles(files)
      }

      await user.save()
    }

    response.redirect().toRoute('home')
  }

Thank you in advance for your feedback

@pomarec
Copy link
Author

pomarec commented Mar 10, 2025

Thank for this improvement !

I have only one pending problem :

Record.#getDirtyAttributeNamesOfAttachment() consider as valid an array of strings changing from ['bla'] to [] because isDirtyAttachment is true

Proposed solution :

          const isDirtyAttachment =
        dirtyValue instanceof Attachment ||
        (Array.isArray(dirtyValue) && dirtyValue.every((item) => item instanceof Attachment) && dirtyValue.length)  

Same for originalValue.

What do you think ?

@batosai
Copy link
Owner

batosai commented Mar 10, 2025

Yes I missed it, I will change that.

Thanks

@batosai
Copy link
Owner

batosai commented Mar 10, 2025

@pomarec After analyzing, in which case do you find yourself with [] ?

@batosai
Copy link
Owner

batosai commented Mar 10, 2025

I created a new beta version.

@pomarec
Copy link
Author

pomarec commented Mar 11, 2025

export enum NotificationType {
  notif1 = 'name_of_notif_1',
   ...
}

class User {
  declare enabledNotificationsEmail: NotificationType[]
}

@pomarec
Copy link
Author

pomarec commented Mar 11, 2025

LGTM

@pomarec
Copy link
Author

pomarec commented Mar 28, 2025

@batosai Do you mind fixing what I mentionned above for isDirtyAttachment and isOriginalAttachment and publish a new beta ?
Thanks in advance

@batosai
Copy link
Owner

batosai commented Mar 28, 2025

This has been done and you have confirmed it to me 🧐

@pomarec
Copy link
Author

pomarec commented Mar 28, 2025

I might be wrong but it seems the fix is not done for isOriginalAttachment

@batosai
Copy link
Owner

batosai commented Mar 28, 2025

Ok, I’ll watch this as soon as possible

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

No branches or pull requests

3 participants