Document deduplication

I think we can merge this. Uploading, downloading and deletion work as they should.

The document export script seems to have problems with duplicate documents and I’m not sure if we need to take a closer look but I don’t think there’s anything fundamentally wrong with the implementation.