Sunday 4 March 2012

Slow weekend

So I created a blog. Setting it up a took like 3 minutes total (including searching for a recommended one)... For the rest of the weekend I was fighting with permissions and attachments in the application. A few problems came out, which was unsurprising really.

What was surprising, is the fact these were not technical difficulties. I set CanCan (and learnt a lot about it... again) up, then I got Paperclip working with an AWS-S3 account. It was a first time I did something like this and it worked like a charm. Thank god for smart people writing smart software. Even made it possible to limit the uploads and downloads via the usage of HTTPS, rather than standard HTTP. It was all so deliciously simple:

A User with a proper UserRole can create a Project. A Project is defined by a Game it's designed for (Doom, Doom2, Heretic...) and an Engine (source port) it uses. The User can then proceed to create Maps for it. Each map has a Name (a "display" name), a Lump (the name of the lump it's supposed to be located with in the WAD) and a Wadfile, which actually is a zip archive, oh well. Of course the file name and location has to be automatically determined upon upload, so that it can be both downloaded or removed later with ease. This means the file name has to be static...

Then it struck me - what if the map author wanted to rename it?
It's not unheard of - people had done it a few times during the course of DTWiD development. The fact, that I wanted the filenames to be pretty and actually include a slug based on the Map's "display" Name didn't really help. Paperclip can't do this for me. Not on S3.

I started deliberating what would be better - to store the files with an id-only based names (which would  mean that when downloading people would get files named like so: 2-5-12.zip), or to include additional functionality to change file's name directly in the S3 repository. The first solution was ugly, the second one was resource heavy. Things like that would probably require dedicated worker processes to pull it off and I can't really have those on a shared web hosting.

Then it struck me again - leaving me barely alive.
I got it all wrong. Not to mention neither solution would really be reliable enough.
I just have to separate the Map entity from a Wadfile entity. A single Map will be able to have a couple of related Wadfile class objects, each one of them named automatically, or manually (User's choice) and each of them managed independently, with only create and delete actions to chose from. This means changing the name of the Map will not bother the file at all. The author would then have to decide if he wants to reupload the file with a new name or leave it as is.

The beauty of it is that it's so much easier to do and it allows a Map to have a couple of files, like different versions of work in progress.
...but I should probably limit it to like 5 or 10 files per Map.

No comments:

Post a Comment