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

register_tmp_file also for mtime #15012

Conversation

light-and-ray
Copy link
Contributor

@light-and-ray light-and-ray commented Feb 23, 2024

Description

I've found in my extension OutputPanel's save button doesn't work, because of timestamp in filename. I doubled register_tmp_file function inside save_pil_to_file also for filename with timestamp

Checklist:

@missionfloyd
Copy link
Collaborator

The timestamp is only added to keep the browser from displaying cached images. You can just cut it off.

filename.split("?")[0]

@light-and-ray
Copy link
Contributor Author

light-and-ray commented Feb 24, 2024

  1. filename can contain ? symbol, and also filename can be with no timestamp. So your method would be broken
  2. I need to remove this timestamp inside check_tmp function next to this function I changed, and this solution looks worse. Just add both variants in white list looks better

@missionfloyd
Copy link
Collaborator

Question marks are removed from filenames.

invalid_filename_chars = '<>:"/\\|?*\n\r\t'
invalid_filename_prefix = ' '
invalid_filename_postfix = ' .'
re_nonletters = re.compile(r'[\s' + string.punctuation + ']+')
re_pattern = re.compile(r"(.*?)(?:\[([^\[\]]+)\]|$)")
re_pattern_arg = re.compile(r"(.*)<([^>]*)>$")
max_filename_part_length = 128
NOTHING_AND_SKIP_PREVIOUS_TEXT = object()
def sanitize_filename_part(text, replace_spaces=True):
if text is None:
return None
if replace_spaces:
text = text.replace(' ', '_')
text = text.translate({ord(x): '_' for x in invalid_filename_chars})
text = text.lstrip(invalid_filename_prefix)[:max_filename_part_length]
text = text.rstrip(invalid_filename_postfix)
return text

If the timestamp is missing, split("?")[0] returns the whole string.

>>> filename = "image.png?123456789"
>>> filename.split("?")[0]
'image.png'
>>> filename = "image.png"
>>> filename.split("?")[0]
'image.png'

@AUTOMATIC1111
Copy link
Owner

register_tmp_file just adds the file to tmp_file_sets making it possible to retrieve that file via the frontend. I'm not sure what this change accomplishes.

@light-and-ray
Copy link
Contributor Author

I know it adds file into white list. I have a case when this tmp_file_set contains only file with no timestamp, and save image function (inside output panel) checks file with timestamp

@AUTOMATIC1111 AUTOMATIC1111 merged commit c8a5322 into AUTOMATIC1111:dev Feb 26, 2024
3 checks passed
@light-and-ray light-and-ray deleted the register_tmp_file-also-with-mtime branch February 26, 2024 09:53
AUTOMATIC1111 added a commit that referenced this pull request Mar 2, 2024
…ith-mtime

register_tmp_file also for mtime
ruchej pushed a commit to ruchej/stable-diffusion-webui that referenced this pull request Sep 30, 2024
…p_file-also-with-mtime

register_tmp_file also for mtime
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

Successfully merging this pull request may close these issues.

3 participants