FactorioMods icon indicating copy to clipboard operation
FactorioMods copied to clipboard

factoriomods uri is truncated.

Open Berserker66 opened this issue 10 years ago • 9 comments
trafficstars

As an example, for the galactic trade mod: this is the decoded string:

'{"id":52,"url":"http://www.factoriomods.com/mods/galactic-trade-mod","categories":["gameplay"],"author":"coopmaster","contact":"[email protected]","title":"Galactic Trade Mod","name":"GalacticTrade","description":"This mod adds the ability to buy and sell items in the game at market prices. You unlock the chest by researching market trading which comes after electronics.","homepage":"","releases":[{"id":279,"version":"0.6.5","released_at":"2015-09-22T00:00:00.000Z","game_versions":["0.12.x"],"dependencies":[],"files":[{"id":293,"name":"","mirror":null,"url":"https://drive.google.com/open?id=0B-yFva9bu-RVRDlCWEZ0ZmNkOVE"},{"id":292,"name":"","mirror":null,"url":"http://www.factorioforums.com/forum/download/file.php?id=6083"}]},{"id":274,"version":"0.6.4","released_at":"2015-09-20T00:00:00.000Z","game_versions":["0.12.x"],"dependencies":[],"files":[{"id":287,"name":"","mirror":null,"url":"http://www.factorioforums.com/forum/download/file.php?id=6024"},{"id":286,"name":"","mirror":null,"url":"https://drive.google.com/open?id=0B-yFva9bu-RVblJEU0FkM01MZUk"}]},{"id":270,"version":"0.6.2","released_at":"2015-09-15T00:00:00.000Z","game_versions":["0.12.x"],"dependencies":[],"files":[{"id":279,"name":"","mirror":null,"url":"https://drive.google.com/open?id=0B-yFva9bu-RVdWNXSGxjaWxyT2s"}]},{"id":266,"version":"0.6.1","released_at":"2015-09-10T00:00:00.000Z","game_versions":["0.12.x"],"dependencies":[],"files":[{"id":273,"name":"","mirror":null,"url":"https://drive.google.com/open?id=0B-yFva9bu-RVSDFpc0ZMZ3RiQmM"}]},{"id":69,"versi'

As you can see, it simply ends midway and does not yield a proper json object.

Instead of encoding all this information, I'd recommend just linking to an url on factoriomods.com, that then yields the json data.

Berserker66 avatar Sep 25 '15 15:09 Berserker66

I just checked the URL by decoding it manually with the browser atob and it's not truncated, it must be a limitation of the library you're using to parse the URL. IIRC @narrowtux was having the same issue using a Java library. Maybe he can explain how he solved it.

But yeah, it might be a good idea to just put the URL to the API there instead of the whole encoded mod.

Zequez avatar Sep 25 '15 16:09 Zequez

Yeah, that happens when you use the URI class wrongly.

This is how I'm decoding the string:

String json = new String(Base64.getDecoder().decode(uri.getRawSchemeSpecificPart().substring(2)));

narrowtux avatar Sep 25 '15 16:09 narrowtux

I'm using python's base64.b64decode() But when I try encoding and then decoding a large file(>100MB). it works. It only stumbles on the factoriomods uri, for some reason.

Berserker66 avatar Sep 25 '15 16:09 Berserker66

My point is that you're probably extracting the base64 part of the URI wrong.

Base64 is not the problem and evidently works. Check if your code puts the correct base64 encoded string into base64.b64decode().

narrowtux avatar Sep 25 '15 16:09 narrowtux

    mod = sys.argv[1].lstrip(r"factoriomods://")
    mod = base64.b64decode(mod)

I literally just strip the uri sheme identifier and pass the rest raw.

Berserker66 avatar Sep 25 '15 16:09 Berserker66

Investigated a bit more. The string gets truncated when the browser passes the uri to exe. For reference, Opera 12, Windows 7 64 Bit.

Berserker66 avatar Sep 25 '15 16:09 Berserker66

Ah that sucks then. Should make the URL smaller and just pass some id which then is used on the API.

narrowtux avatar Sep 25 '15 16:09 narrowtux

@Zequez you should somehow make your URL shorter because Windows apparently doesn't like long URLs.

narrowtux avatar Sep 25 '15 16:09 narrowtux

Well, I'll make them link to the API endpoint then.

On 25 September 2015 at 13:35, Moritz Schmale [email protected] wrote:

@Zequez https://github.com/Zequez you should somehow make your URL shorter because Windows apparently doesn't like long URLs.

— Reply to this email directly or view it on GitHub https://github.com/Zequez/FactorioMods/issues/10#issuecomment-143270871.

Zequez avatar Sep 25 '15 17:09 Zequez