MineSkin / api.mineskin.org

Source of the MineSkin API
https://api.mineskin.org
MIT License
50 stars 5 forks source link

Support base64-encoded image in either generate route #389

Open mergu opened 9 months ago

mergu commented 9 months ago

Is your feature request related to a problem? Please describe. I'm attempting to make use of this API in a semi-restrictive environment, and only have reliable access to the base64-encoded image. When trying to pass the decoded image to mineskin, I receive generation failures. Confirmed the image is ok by uploading through the mineskin UI manually. I assume the problem here is utf-8 encoding done to my payload, which is out of my control.

I have also tried to use the generate/url route using a Data URL https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs, but one of the checks before pulling the texture fails and I receive {"success":false,"errorType":"GeneratorError","errorCode":"invalid_image_url","error":"Failed to find image from url","nextRequest":1703510085.607,"delayInfo":{"seconds":6,"millis":6000}}.

The data url was {"url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAABAklEQVR4Xu3VMQ7CMAyF4VyBgZmBialsrIiFC3RmRuycH3CFJeu1SZlKUv2fZAFJg+xHJFKa8bx2r1I9zsdi6fc1RwfW0oG19PuaUxqytEcABEAA6wng8zJZBLCGAPRvzSsOcU+70fC21nf70Tkte6ZP2+H5WLZ2Ox3+H5A3as3E0nUbJH2Hnxpcz8eqOgBtVgOIA9rgdiPivp7TGm5BzQH4NdfGfT2G4AHEtV/OVx2ANpyrOHAcfK5KAdie9rM4bdhLg/Hrru/1OT1/SZtsALan/SxubgAf2H91WysF4J+bCcCH08b1yucCyJ1vJgAAAAAAAAAAAAAAAAAAAAAAALA6b27DnSK0ejouAAAAAElFTkSuQmCC"}

Describe the solution you'd like I'd like either of the routes to support base64-encoded images. This is generally a more http-friendly format of data, compatible with any client. The easiest fix I believe would be supporting a data url in here - https://github.com/MineSkin/api.mineskin.org/blob/master/src/generator/Generator.ts#L864

Describe alternatives you've considered I have considered uploading to another API, most support base64-encoded images such as the imgur api, and using the url. I would prefer not doing the extra hop.

mergu commented 9 months ago

An update on this, I've been able to successfully upload the png using some reflection hackery. Have also reported it to the plugin I'm using to make generic web requests with. Still think a base64 option would be handy but not necessary for myself anymore