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

API POST requests ignore updated previews #343

Open
mathrick opened this issue Oct 10, 2024 · 1 comment
Open

API POST requests ignore updated previews #343

mathrick opened this issue Oct 10, 2024 · 1 comment

Comments

@mathrick
Copy link

Given the current asset payload for 3133:

GET https://godotengine.org/asset-library/api/asset/3133
{
  "asset_id": "3133",
  "type": "addon",
  "title": "Quick layout changer",
  "author": "mathrick",
  "author_id": "15665",
  "version": "8",
  "version_string": "1.3.0",
  "category": "Tools",
  "category_id": "5",
  "godot_version": "4.2",
  "rating": "0",
  "cost": "MIT",
  "description": "This is a simple Godot 4 editor plugin to change editor layouts\ndirectly from the toolbar, without going through the\nEditor->Layouts->... menu.\n\nChanges:\n* Version 1.3.0\n  - Add partial translations for the short string (\"Layout\") used by\n    the toolbar dropdown when no layout is selected\n\n* Version 1.2.1\n  - Restore compatibility with 4.2\n\n* Version 1.2.0\n  - Add non-English localisation support on 4.3+\n\n\nSince version 1.3.0, the quick layout menu itself is localised in\nseveral languages (if running on Godot 4.3+).\n\n\n**WARNING**: This plugin is very hacky and relies on a lot of\ninternal details of how the editor works, since there's no official\nAPI that would allow access to saved layouts. According to my testing\nit _should_ be compatible with:\n\n* Godot 4.2, should work for any language\n* Godot 4.3, should work with any language supported by\n  4.3.stable. As it currently requires manual syncing of\n  translations, any changed or added translations in\n  subsequent Godot releases will not be picked up\n  automatically and will need a new release of the plugin\n\nIf you run into any problems, please open an issue, and I'll do my best to fix it.\n",
  "support_level": "community",
  "download_provider": "GitHub",
  "download_commit": "be6cd9fd9865a27528541e383f6d3254e2e77d64",
  "browse_url": "https://github.com/mathrick/godot-quick-layout-changer",
  "issues_url": "https://github.com/mathrick/godot-quick-layout-changer/issues",
  "icon_url": "https://raw.githubusercontent.com/mathrick/godot-quick-layout-changer/main/icon.png",
  "searchable": "1",
  "modify_date": "2024-10-04 14:04:41",
  "download_url": "https://github.com/mathrick/godot-quick-layout-changer/archive/be6cd9fd9865a27528541e383f6d3254e2e77d64.zip",
  "previews": [
    {
      "preview_id": "3719",
      "type": "image",
      "link": "https://raw.githubusercontent.com/mathrick/godot-quick-layout-changer/main/screenshots/screenshot.png",
      "thumbnail": "https://raw.githubusercontent.com/mathrick/godot-quick-layout-changer/main/screenshots/screenshot.png"
    }
  ],
  "download_hash": ""
}

And the following edit:

POST https://godotengine.org/asset-library/api/asset/3133
{
    "token": "...",
    "asset_id": "3133",
    "previews": [
        {
            "enabled": true,
            "operation": "update",
            "edit_preview_id": "3719",
            "type": "image",
            "link": "https://raw.githubusercontent.com/mathrick/godot-quick-layout-changer/be6cd9fd9865a27528541e383f6d3254e2e77d64/screenshots/screenshot.png",
            "thumbnail": "https://raw.githubusercontent.com/mathrick/godot-quick-layout-changer/be6cd9fd9865a27528541e383f6d3254e2e77d64/screenshots/screenshot.png"
        },
        {
            "enabled": true,
            "operation": "insert",
            "type": "image",
            "link": "https://raw.githubusercontent.com/mathrick/godot-quick-layout-changer/be6cd9fd9865a27528541e383f6d3254e2e77d64/screenshots/localisation.png",
            "thumbnail": "https://raw.githubusercontent.com/mathrick/godot-quick-layout-changer/be6cd9fd9865a27528541e383f6d3254e2e77d64/screenshots/localisation.png"
        }
    ]
}

This is the resulting edit:

GET https://godotengine.org/asset-library/api/asset/edit/14191
{
  "edit_id": "14191",
  "asset_id": "3133",
  "user_id": "15665",
  "title": null,
  "description": null,
  "category_id": null,
  "godot_version": null,
  "version_string": null,
  "cost": null,
  "download_provider": null,
  "download_commit": null,
  "browse_url": null,
  "issues_url": null,
  "icon_url": null,
  "status": "new",
  "reason": "",
  "author": "mathrick",
  "previews": [
    {
      "edit_preview_id": "6106",
      "preview_id": null,
      "type": "image",
      "link": "https://raw.githubusercontent.com/mathrick/godot-quick-layout-changer/be6cd9fd9865a27528541e383f6d3254e2e77d64/screenshots/localisation.png",
      "thumbnail": "https://raw.githubusercontent.com/mathrick/godot-quick-layout-changer/be6cd9fd9865a27528541e383f6d3254e2e77d64/screenshots/localisation.png",
      "operation": "insert"
    },
    {
      "preview_id": "3719",
      "type": "image",
      "link": "https://raw.githubusercontent.com/mathrick/godot-quick-layout-changer/main/screenshots/screenshot.png",
      "thumbnail": ""
    }
  ],
  "original": {...},
  "download_url": null
}

Notice that only the inserted preview actually got applied, the update had no effect. Resending the same request results in Error 400: Creating edits without changes is not allowed. If I send a request which only has the update, it does get accepted for some reason:

POST https://godotengine.org/asset-library/api/asset/3133
{
    "token": "...",
    "asset_id": "3133",
    "previews": [
        {
            "enabled": true,
            "operation": "update",
            "edit_preview_id": "3719",
            "type": "image",
            "link": "https://raw.githubusercontent.com/mathrick/godot-quick-layout-changer/be6cd9fd9865a27528541e383f6d3254e2e77d64/screenshots/screenshot.png",
            "thumbnail": "https://raw.githubusercontent.com/mathrick/godot-quick-layout-changer/be6cd9fd9865a27528541e383f6d3254e2e77d64/screenshots/screenshot.png"
        }
    ]
}

But the preview is not updated:

GET https://godotengine.org/asset-library/api/asset/edit/14194
{
  "edit_id": "14194",
  "asset_id": "3133",
  "user_id": "15665",
  "title": null,
  "description": null,
  "category_id": null,
  "godot_version": null,
  "version_string": null,
  "cost": null,
  "download_provider": null,
  "download_commit": null,
  "browse_url": null,
  "issues_url": null,
  "icon_url": null,
  "status": "new",
  "reason": "",
  "type": null,
  "link": null,
  "thumbnail": null,
  "operation": null,
  "author": "mathrick",
  "previews": [
    {
      "preview_id": "3719",
      "type": "image",
      "link": "https://raw.githubusercontent.com/mathrick/godot-quick-layout-changer/main/screenshots/screenshot.png",
      "thumbnail": ""
    }
  ],
  "original": {...},
  "download_url": null
}

I can resend it as many times as I want, and it results in a new "edit" every time, so 14194, 14195, and 14196 are identical. It seems that the code is blind to preview updates, and doesn't actually process them in any way. I can't tell whether the improper rejection of edits as empty is just a consequence of that, or a different, but similar flaw in the validation logic.

@mathrick
Copy link
Author

Also possibly related: new assets created through the API don't get any previews whatsoever. I tested against latest master in a docker container, with the following payload:

POST http://localhost:8080/asset-library/api/asset/
{
    "title": "Quick layout changer",
    "description": "This is a simple Godot 4 editor plugin to change editor layouts\ndirectly from the toolbar, without going through the\nEditor->Layouts->... menu.\n\nChanges:\n* Version 1.3.0\n  - Add partial translations for the short string (\"Layout\") used by\n    the toolbar dropdown when no layout is selected\n\n* Version 1.2.1\n  - Restore compatibility with 4.2\n\n* Version 1.2.0\n  - Add non-English localisation support on 4.3+\n\n\nSince version 1.3.0, the quick layout menu itself is localised in\nseveral languages (if running on Godot 4.3+).\n\n\n**WARNING**: This plugin is very hacky and relies on a lot of\ninternal details of how the editor works, since there's no official\nAPI that would allow access to saved layouts. According to my testing\nit _should_ be compatible with:\n\n* Godot 4.2, should work for any language\n* Godot 4.3, should work with any language supported by\n  4.3.stable. As it currently requires manual syncing of\n  translations, any changed or added translations in\n  subsequent Godot releases will not be picked up\n  automatically and will need a new release of the plugin\n\nIf you run into any problems, please open an issue, and I'll do my best to fix it.\n",
    "godot_version": "4.2",
    "category_id": 5,
    "version_string": "1.3.0",
    "cost": "MIT",
    "download_provider": "GitHub",
    "download_commit": "be6cd9fd9865a27528541e383f6d3254e2e77d64",
    "browse_url": "https://github.com/mathrick/godot-quick-layout-changer",
    "issues_url": "https://github.com/mathrick/godot-quick-layout-changer/issues",
    "icon_url": "https://raw.githubusercontent.com/mathrick/godot-quick-layout-changer/main/icon.png",
    "download_url": "https://github.com/mathrick/godot-quick-layout-changer/archive/be6cd9fd9865a27528541e383f6d3254e2e77d64.zip",
    "previews": [
        {
            "enabled": true,
            "operation": "insert",
            "type": "image",
            "link": "https://raw.githubusercontent.com/mathrick/godot-quick-layout-changer/be6cd9fd9865a27528541e383f6d3254e2e77d64/screenshots/screenshot.png",
            "thumbnail": "https://raw.githubusercontent.com/mathrick/godot-quick-layout-changer/be6cd9fd9865a27528541e383f6d3254e2e77d64/screenshots/screenshot.png"
        },
        {
            "enabled": true,
            "operation": "insert",
            "type": "image",
            "link": "https://raw.githubusercontent.com/mathrick/godot-quick-layout-changer/be6cd9fd9865a27528541e383f6d3254e2e77d64/screenshots/localisation.png",
            "thumbnail": "https://raw.githubusercontent.com/mathrick/godot-quick-layout-changer/be6cd9fd9865a27528541e383f6d3254e2e77d64/screenshots/localisation.png"
        }
    ]
}

This is the result:

GET http://localhost:8080/asset-library/api/asset/edit/3
{
  "edit_id": "3",
  "asset_id": "-1",
  "user_id": "1",
  "title": "Quick layout changer",
  "description": "This is a simple Godot 4 editor plugin to change editor layouts\ndirectly from the toolbar, without going through the\nEditor-\u003ELayouts-\u003E... menu.\n\nChanges:\n* Version 1.3.0\n  - Add partial translations for the short string (\"Layout\") used by\n    the toolbar dropdown when no layout is selected\n\n* Version 1.2.1\n  - Restore compatibility with 4.2\n\n* Version 1.2.0\n  - Add non-English localisation support on 4.3+\n\n\nSince version 1.3.0, the quick layout menu itself is localised in\nseveral languages (if running on Godot 4.3+).\n\n\n**WARNING**: This plugin is very hacky and relies on a lot of\ninternal details of how the editor works, since there's no official\nAPI that would allow access to saved layouts. According to my testing\nit _should_ be compatible with:\n\n* Godot 4.2, should work for any language\n* Godot 4.3, should work with any language supported by\n  4.3.stable. As it currently requires manual syncing of\n  translations, any changed or added translations in\n  subsequent Godot releases will not be picked up\n  automatically and will need a new release of the plugin\n\nIf you run into any problems, please open an issue, and I'll do my best to fix it.\n",
  "category_id": "5",
  "godot_version": "4.2",
  "version_string": "1.3.0",
  "cost": "MIT",
  "download_provider": "GitHub",
  "download_commit": "be6cd9fd9865a27528541e383f6d3254e2e77d64",
  "browse_url": "https://github.com/mathrick/godot-quick-layout-changer",
  "issues_url": "https://github.com/mathrick/godot-quick-layout-changer/issues",
  "icon_url": "https://raw.githubusercontent.com/mathrick/godot-quick-layout-changer/main/icon.png",
  "status": "new",
  "reason": "",
  "type": null,
  "link": null,
  "thumbnail": null,
  "operation": null,
  "unedited_preview_id": null,
  "unedited_type": null,
  "unedited_link": null,
  "unedited_thumbnail": null,
  "author": "mathrick",
  "previews": [],
  "download_url": "https://github.com/mathrick/godot-quick-layout-changer/archive/be6cd9fd9865a27528541e383f6d3254e2e77d64.zip"
}

Once again, the previews are completely dropped. Submitting them through the browser form however seems to work properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants