sdk-for-cli
sdk-for-cli copied to clipboard
🐛 Bug Report: The avatars commands giving Error: Not Found
👟 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?
- [X] I checked and didn't find similar issue
🏢 Have you read the Code of Conduct?
- [X] I have read the Code of Conduct
@ra-jeev thanks for raising this issue! 🙏🏼 Looks like there are a few things wrong with how we handle images in the CLI:
- 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
- The content-type is set to application/json:
https://github.com/appwrite/sdk-for-cli/blob/b4619977eb95ca6650aa5291eb6a26d6bfa46eda/lib/commands/avatars.js#L145
- The transformResponse tries to parse the data when it shouldn't:
https://github.com/appwrite/sdk-for-cli/blob/b4619977eb95ca6650aa5291eb6a26d6bfa46eda/lib/client.js#L186
@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).
Hi, I can work on this if no one's working on this
@adarshjhaa100, are you still interested in working on this?
@stnguyen90 yes I am interested. Just confirming, need to raise PR to the SDK Generator repo right ?
@adarshjhaa100, assigned! Yes, the SDK Generator repo, please.
@stnguyen90 Looks like something's changed. The latest version gives a slightly different issue:
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:
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:
-
Probably can use the response header
content-type
to identify and then apply appropriatetransformResponse
. But I don't see a way to pull responseHeader in the request config. -
I see that
responseType
of'arraybuffer'
is used for avatars only. So, could use that to change thetransformResponse
.
Do let me know if either of these seem feasible. I'll raise a PR post that.