Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: randomise filenames #2

Open
johngoggs opened this issue Dec 2, 2019 · 3 comments
Open

Request: randomise filenames #2

johngoggs opened this issue Dec 2, 2019 · 3 comments

Comments

@johngoggs
Copy link

Hi Mike,

Coming from Wordpress earlier this year, I had a GCS addon that would randomise filenames to ensure filenames are not the same. Renaming filenames exist, but it will amend a 1 on the end of the filename, and I don't want to see the original filenames in each request.

I understand that I could randomise the filenames myself, but I would end up losing track of each file.

FYI - great addon :)

Thanks.

@mikenikles
Copy link
Collaborator

Hi,

Could you share the link to that Wordpress GCS add-on? I'd like to understand what the benefits are of randomizing file names. What is your motivation to randomize file names? You said you don't want to see the original file names in each request - why is that?

From my experience with Ghost so far, each file upload results in a unique (although not random) file name which is likely to make sure old versions of the same file are not cached.

@johngoggs
Copy link
Author

Hi Mike,

Sorry for the long delay. I took a few weeks off work, and I forgot about this request.

Wordpress Plugin: https://en-gb.wordpress.org/plugins/wp-stateless/

For me, the benefit of randomising filenames is to keep the filename pattern consistent and tidy. For example, if you upload a file called screenshot.png, the next time you upload the same file or a file with the same file name during the same month, it will add a number onto the end of the filename, i.e. screenshot-1.png.

During a post, I may upload the same file, or an overwrite of the same filename multiple times, this means I end up with a lot of images that I need to clean up manually.

This request is less so about unique filenames, as they are already unique. It's more about my workflow and keeping filenames consistent during each upload.

@mikenikles
Copy link
Collaborator

A few weeks off sounds good and not replying here is the right thing to do when you're off work ;-).

I fully agree with you and look at that as two separate issues:

1) File names and their naming conventions
I'd prefer to keep this GCS storage adapter as basic as possible. Having said that, my preference would be for authors to make sure file names follow a good naming convention. For example, you could prefix files you upload with the blog post's slug to keep them nicely tied to individual posts.

2) Delete unused files from storage
From what I can tell, Ghost doesn't support this at the moment. Here's a question from last May.
If you really wanted to automate this, here's a thought:

  • Write a Google Cloud Function that triggers when a new object is added to your Ghost storage bucket.
  • If the object name ends in *-1, do nothing.
  • Iny any other case, check if an object with the same name, but a lower index exists. For example, if a *-2 file is uploaded, check if a *-1 object exists. If it does, check the Ghost database to make sure *-1 is not used (for a different blog post for example as you mentioned). If it's not used, delete the file.
    It takes some coding, but if you upload a lot of files you eventually don't need, it may be worth investigating that solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants