Git Product home page Git Product logo

Comments (7)

evoactivity avatar evoactivity commented on July 25, 2024 1

This should not be closed, this was very confusing.

Based on this section of the docs
https://github.com/adonisjs/attachment-lite#pre-compute-on-demand

if (!this.options?.preComputeUrl) {

Having to replicate the options of the decorator with preComputeUrls set to true is not ideal.

I would consider adding another function meant for computing on demand where a forced flag or something can be passed to computeUrl so it ignores the value of preComputerUrls.

I can provide a patch if that sounds like an acceptable approach.

from attachment-lite.

ruanitto avatar ruanitto commented on July 25, 2024

Looking for test file, you use setOptions method:

attachment?.setOptions({ preComputeUrl: true })

If i set this on preCompute on demand methos, it works:

class User extends BaseModel {
  public static async preComputeUrls(models: User | User[]) {
    if (Array.isArray(models)) {
      await Promise.all(models.map((model) => this.preComputeUrls(model)))
      return
    }

    models.avatar?.setOptions({ disk: 'diskName', preComputeUrl: true }) // Only work if i replicate options of model, including preComputeUrl
    await models.avatar?.computeUrl()
    await models.coverImage?.computeUrl()
  }
}

from attachment-lite.

stale avatar stale commented on July 25, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from attachment-lite.

thetutlage avatar thetutlage commented on July 25, 2024

So far I am not sure what exactly this issue is about. Is it that preComputeUrl option not functioning as documented or something else?

from attachment-lite.

evoactivity avatar evoactivity commented on July 25, 2024

So following the docs it's recommened to not set preComputeUrls to true on the decorator.

class User extends BaseModel {
  @attachment({ preComputeUrl: false})
  public avatar: AttachmentContract
}
class User extends BaseModel {
  public static async preComputeUrls(models: User | User[]) {
    if (Array.isArray(models)) {
      await Promise.all(models.map((model) => this.preComputeUrls(model)))
      return
    }

    await models.avatar?.computeUrl()
    await models.coverImage?.computeUrl()
  }
}

This function does not work as described. computeUrl always returns early if preComputeUrl is false or undefined. No URL's are computed.

I do not think this is a documentation issue, I would expect computeUrl to always build the urls and having preComputeUrls on the decorator to false/undefined shouldn't affect running the function on demand.

from attachment-lite.

stale avatar stale commented on July 25, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from attachment-lite.

evoactivity avatar evoactivity commented on July 25, 2024

not stale

from attachment-lite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.