mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-08-02 15:04:50 +08:00
Make default hash lib configurable without code changes via CLI argument (#3947)
* cli_args: Add --duplicate-check-hash-function. * server.py: compare_image_hash configurable hash function Uses an argument added in cli_args to specify the type of hashing to default to for duplicate hash checking. Uses an `eval()` to identify the specific hashlib class to utilize, but ultimately safely operates because we have specific options and only those options/choices in the arg parser. So we don't have any unsafe input there. * Add hasher() to node_helpers * hashlib selection moved to node_helpers * default-hashing-function instead of dupe checking hasher This makes a default-hashing-function option instead of previous selected option. * Use args.default_hashing_function * Use safer handling for node_helpers.hasher() Uses a safer handling method than `eval` to evaluate default hashing function. * Stray parentheses are evil. * Indentation fix. Somehow when I hit save I didn't notice I missed a space to make indentation work proper. Oops!
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
import hashlib
|
||||
|
||||
from comfy.cli_args import args
|
||||
|
||||
from PIL import ImageFile, UnidentifiedImageError
|
||||
|
||||
def conditioning_set_values(conditioning, values={}):
|
||||
@@ -22,3 +26,12 @@ def pillow(fn, arg):
|
||||
if prev_value is not None:
|
||||
ImageFile.LOAD_TRUNCATED_IMAGES = prev_value
|
||||
return x
|
||||
|
||||
def hasher():
|
||||
hashfuncs = {
|
||||
"md5": hashlib.md5,
|
||||
"sha1": hashlib.sha1,
|
||||
"sha256": hashlib.sha256,
|
||||
"sha512": hashlib.sha512
|
||||
}
|
||||
return hashfuncs[args.default_hashing_function]
|
||||
|
Reference in New Issue
Block a user