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

Images should not be indexed on alt, but rather unique id #42

Closed
stanbar opened this issue Jan 11, 2024 · 6 comments
Closed

Images should not be indexed on alt, but rather unique id #42

stanbar opened this issue Jan 11, 2024 · 6 comments

Comments

@stanbar
Copy link

stanbar commented Jan 11, 2024

Hi,
I believe that storing images based on the alt is not an good idea and instead unique id should be used. The reason is that, uploading two images with the same filename (thus the same alts), replaces the previous image.

Instead of

const storageRef = ref(storage, `images/${userId}/${alt}`);

I would rather use

const storageRef = ref(storage, `images/${userId}/${id}`);
@Ketchupchh
Copy link
Contributor

Yeah, this should be fixed. In my testing it doesn't replace any images but just discards the new one and places the original in the tweet instead. I'll fix the issues you found in my PR as well, thank you. I'll contact ccrsxx about the username bug as well.

@stanbar
Copy link
Author

stanbar commented Jan 11, 2024

@Ketchupchh thank you!

@ccrsxx
Copy link
Owner

ccrsxx commented Jan 12, 2024

Yup, but that's by design.

I made it so that when we upload the same image with the same alt, it will return the old image instead of creating the new image. It won't replace the old image with the new image tho.

This is the code:

try {
src = await getDownloadURL(storageRef);
} catch {
await uploadBytesResumable(storageRef, file);
src = await getDownloadURL(storageRef);
}

I did it to reduce the bandwidth usage on the storage.

But yeah, that's bad if you upload a different picture with the same alt, it'll return the old one.

I see that the bandwidth usage isn't that much, so I think replacing the alt to id is good idea now.

@stanbar
Copy link
Author

stanbar commented Jan 12, 2024

@ccrsxx Well, if you want to do this kind of optimisation I think that the better option would be to calculate a hash (e.g. sha256) of a file's content, and use that instead of a filename. That way, the same images with different names, would be stored only once.

@ccrsxx
Copy link
Owner

ccrsxx commented Jan 17, 2024

Yup, that could be the solution. But for now, I''ll be using the randomly generated id.

@ccrsxx
Copy link
Owner

ccrsxx commented Mar 4, 2024

Fixed in #40

@ccrsxx ccrsxx closed this as completed Mar 4, 2024
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

3 participants