Levertine

Please login or register.

Author Topic: Approval & Duplicate Filename Questions  (Read 2381 times)

Steve

  • Full Member
  • ***
  • Posts: 101
  • Alcohol is the liquid version of Photoshop.

Approval & Duplicate Filename Questions
« on: January 07, 2015, 01:06:02 AM »
Why do my images need approval? Is that a permission based thing?

Also, how does the gallery handle the uploading of images with filenames that are duplicates of ones already uploaded?

:)

Arantor

  • Levertine Developer
  • Full Member
  • *
  • Posts: 248

Re: Approval & Duplicate Filename Questions
« Reply #1 on: January 07, 2015, 01:21:36 AM »
Here? Because I set them to require approval (yes, it's a permission thing). This is because in case people try out things and upload stuff that requires approval (because it's not really legal to upload or not suitable for general consumption) and I can remove it instead of approving.

As for duplicate filenames, the gallery really doesn't care what the filename is - there is only one time the original filename is actually properly used, and that's if you hit the download link, whereupon the prompt for download includes the original name. It is also used as a default name if you don't give it one while uploading a file (and a default for bulk uploading) but it's massaged a bit.

Internally a completely different filename is attached to the file. It's kind of complicated and there's good reason for it so let's dive in.

The first thing that happens during an upload is that a hash is created of the file. This is a 40 character code that is generated mathematically from the file. I don't want to get into how but that's what happens. Anyway, this is used as the seed of a filename.

Let's say I upload a JPG file and it obtains the hash 12345, and it's file id 1. This will internally end up with a filename of 1_12345_jpg.dat. The dat part means FileZilla won't mangle it thinking it is a non-binary file, while the real extension is visible if people need to rename it back for any reason.

Now, the really clever part. There is the lgal_items folder where everything goes and inside is a folder for files (there's also one for album thumbnails but that's not so interesting). Inside that folder could be up to 16 folders, and inside each of those could be another 16 folders. This sounds weird, but bear with me.

So, our file's hash was 12345. This will mean that the file will be lgal_items/files/1/12/1_12345_jpg.dat. We end up with the files/ folder containing 16 folders (0-9 plus a-f) based on the first digit of the hash, and each of those folders ends up with a set of folders comprising of the first two digits of the hash.

This seems insane and ordinarily I'd agree, but there's a reason for it. This means we have potentially 256 folders that the system will distribute between - and more importantly will do so reasonably evenly, since the hash itself is generated in such a way that the distribution between the first two digits is approximately even given the source data. So instead of running into the usual FTP limits of a thousand files or a couple of thousand files per folder, LevGal will automatically attempt to distribute files between 256 folders - meaning you need to be hitting 300,000 files or more before you start running into problems. Sure, there's things like previews and thumbnails which come out of this count but either way you're still talking 5 or 6 digit counts of images before you start running into FTP limitations. And since this is all managed by LevGal, all you ever need to do to back it up is just get your FTP client doing the lgal_items folder (and all good FTP clients should go through all the folders automatically)

Steve

  • Full Member
  • ***
  • Posts: 101
  • Alcohol is the liquid version of Photoshop.

Re: Approval & Duplicate Filename Questions
« Reply #2 on: January 07, 2015, 01:48:24 AM »
Awesome. Explained very well and understandably.

As for the approval thing, I forgot you don't know me well enough to know that I wouldn't do that and even if you did, I don't blame you for being cautious with what people upload. So it's something I really shouldn't even have asked. Sorry about that.

Arantor

  • Levertine Developer
  • Full Member
  • *
  • Posts: 248

Re: Approval & Duplicate Filename Questions
« Reply #3 on: January 07, 2015, 12:39:27 PM »
Please don't take it personally - it's applied to everyone here (except me because admins have automatic approval) ;)

Permissions in LevGal are very coarse for a reason - one of the headaches I found with the other galleries is how complicated permissions get, especially when you start applying permissions to individual albums. So I don't do any of that in LevGal and definitely not here. There's the add-item permissions (add to own album, add to any album) and by nature these are add-without-approving, plus there's the permission for approving items, and a toggle for users to be able to approve items in their own albums without them being able to approve generally.

I'm definitely of the mentality about keeping it simple - which is why there's only one extra member group here at present, for LevGal customers (since that's needed for helpdesk and download album access), and I don't really plan on making any more except for any other mods I do (which also means everyone has to wait for item approval). Can't have it all ways, I guess.

Steve

  • Full Member
  • ***
  • Posts: 101
  • Alcohol is the liquid version of Photoshop.

Re: Approval & Duplicate Filename Questions
« Reply #4 on: January 07, 2015, 01:29:34 PM »
It's all good. I didn't take it personal. I should have thought of it myself is all. :)
 

SMF 2.0.9 | SMF © 2014, Simple Machines
BlueLight design by Bloc