appwrite / sdk-for-cli

[READ-ONLY] Official Appwrite CLI >_
BSD 3-Clause "New" or "Revised" License
85 stars 29 forks source link

🐛 Bug Report: The avatars commands giving Error: Not Found #86

Open ra-jeev opened 12 months ago

ra-jeev commented 12 months ago

👟 Reproduction steps

appwrite avatars --verbose getFlag --code af --destination test.png

👍 Expected behavior

Should download the flag icon and create a new file at the destination path.

👎 Actual Behavior

Throws the below error:

AppwriteException [Error]: Not Found
    at Client.call (/usr/local/lib/node_modules/appwrite-cli/lib/client.js:209:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async avatarsGetFlag (/usr/local/lib/node_modules/appwrite-cli/lib/commands/avatars.js:144:22) {
  code: 404,
  response: [Object: null prototype] {
    message: 'Not Found',
    code: 404,
    type: 'general_route_not_found',
    version: '0.10.44'
  }
}

Error Not Found

🎲 Appwrite version

Appwrite CLI v2.0.2

💻 Operating system

macOS v12.6.7

🧱 Your Environment

Using the appwrite CLI v2.0.2 on macbook pro with zsh.

👀 Have you spent some time to check if this issue has been raised before?

🏢 Have you read the Code of Conduct?

stnguyen90 commented 11 months ago

@ra-jeev thanks for raising this issue! 🙏🏼 Looks like there are a few things wrong with how we handle images in the CLI:

  1. The endpoint is included in the path when it shouldn't be:

https://github.com/appwrite/sdk-for-cli/blob/b4619977eb95ca6650aa5291eb6a26d6bfa46eda/lib/commands/avatars.js#L142

  1. The content-type is set to application/json:

https://github.com/appwrite/sdk-for-cli/blob/b4619977eb95ca6650aa5291eb6a26d6bfa46eda/lib/commands/avatars.js#L145

  1. The transformResponse tries to parse the data when it shouldn't:

https://github.com/appwrite/sdk-for-cli/blob/b4619977eb95ca6650aa5291eb6a26d6bfa46eda/lib/client.js#L186

ra-jeev commented 11 months ago

@stnguyen90 Thanks a lot for acknowledging the issue. Glad I was able to notice this bug while playing around with the appwrite CLI (actually I was trying to connect Appwrite CLI to the 1Password CLI, and that is when I noticed it).

adarshjhaa100 commented 10 months ago

Hi, I can work on this if no one's working on this

stnguyen90 commented 9 months ago

@adarshjhaa100, are you still interested in working on this?

adarshjhaa100 commented 9 months ago

@stnguyen90 yes I am interested. Just confirming, need to raise PR to the SDK Generator repo right ?

stnguyen90 commented 7 months ago

@adarshjhaa100, assigned! Yes, the SDK Generator repo, please.

adarshjhaa100 commented 7 months ago

@stnguyen90 Looks like something's changed. The latest version gives a slightly different issue: image

The 1st and 3rd point you've mentioned seems a correct analysis of the issue. I made the change and am able to download the image: image

Would like to add something for the 2nd point here. This is a GET request, which has a null request body. So, it seems fair to omit the content-type from request header while fetching avatar. (I presume content-type here is the type of request body, correct me if im wrong)

Given the above analysis, just need to figure out how to handle for images.

Couple of solutions which I can think of: 1) Probably can use the response header content-type to identify and then apply appropriate transformResponse. But I don't see a way to pull responseHeader in the request config.

2) I see that responseType of 'arraybuffer' is used for avatars only. So, could use that to change the transformResponse.

Do let me know if either of these seem feasible. I'll raise a PR post that.