jeffalo / scratch-image-uploader

Use Scratch project thumbnails to upload images to be used on the forums.
10 stars 3 forks source link

Adding SVG support? #21

Open BoomerScratch opened 4 years ago

BoomerScratch commented 4 years ago

Currently, if you upload an SVG image, the image will not appear and a 500 error occurs. We should convert the SVG to PNG. This is easy: you can create a canvas element, render the SVG on it, and finally grab a picture of the canvas using canvas.toDataURL. The harder part is that it doesn't work if the canvas is offscreen. To fix that, we can use @canvg. Create a file called canvg.js with these contents, and also add it to the content scripts in manifest.json. We first need to merge #20 before I can start working on it.

BoomerScratch commented 4 years ago

Okay, this is kinda hard to do 😅

easrng commented 4 years ago

or, y'know, OffscreenCanvas

BoomerScratch commented 4 years ago

@easrng Yes, that is what I tried. I noticed some days ago that canvg isn't needed; it's built-in in most browsers.

NoobTracker commented 4 years ago

Currently, the thumbnails don't support SVG. But there's a way of still doing it: Using assets.scratch.mit.edu.

BoomerScratch commented 4 years ago

@NoobTracker assets.scratch.mit.edu is not whitelisted.

NoobTracker commented 4 years ago

Ohhh it's possible. I found an exploit that makes that possible. Look at this, someone either copied my idea or discovered it too. And it is technically whitelisted.

BoomerScratch commented 4 years ago

@NoobTracker Oh, that's interesting.

NoobTracker commented 4 years ago

Indeed. You need to use get_image/ or something like that (y'know, one of the whitelisted paths) and then you need to get one directory higher by using ../, but since .. is blacklisted in URLs, you need to use %2E%2E/.

BoomerScratch commented 4 years ago

Ping @JeffaloBob, assets are possible.

NoobTracker commented 4 years ago

I already told Jeffalo, he tried it.