Skip to content

Commit

Permalink
[Backport] Add option to disable image file size check (close #170) (#…
Browse files Browse the repository at this point in the history
…228)

This commit is backport from
[saveweb/wikiteam3](https://github.com/saveweb/wikiteam3) all credit
goes to the original author.

Close #170 
Fix size mismatch error when some wiki do server-side image
resizing/compression without re-upload/update data in wiki.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
sian1468 and pre-commit-ci[bot] authored Dec 18, 2023
1 parent 265855d commit eb6e38e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions wikiteam3/dumpgenerator/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ def getArgumentParser():
action="store_true",
help="Bypass CDN image compression. (CloudFlare Polish, etc.)",
)
groupDownload.add_argument(
"--disable-image-verify",
action="store_true",
help="Don't verify image size and hash while downloading. (useful for wikis with server-side image resizing)",
)
groupDownload.add_argument(
"--namespaces",
metavar="1,2,3",
Expand Down Expand Up @@ -469,6 +474,7 @@ def sleep(self, response=None):
"session": session,
"stdout_log_path": args.stdout_log_path,
"bypass_cdn_image_compression": args.bypass_cdn_image_compression,
"disable_image_verify": args.disable_image_verify,
}

# calculating path, if not defined by user with --path=
Expand Down
7 changes: 6 additions & 1 deletion wikiteam3/dumpgenerator/dump/image/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def generateImageDump(
c_savedImageDescs = 0

bypass_cdn_image_compression: bool = other["bypass_cdn_image_compression"]
disable_image_verify: bool = other["disable_image_verify"]

def modify_params(params: Optional[Dict] = None) -> Dict:
"""bypass Cloudflare Polish (image optimization)"""
Expand Down Expand Up @@ -130,7 +131,11 @@ def check_response(r: requests.Response) -> None:

if r.status_code == 200:
try:
if size == "False" or len(r.content) == int(size):
if (
size == "False"
or len(r.content) == int(size)
or disable_image_verify
):
# size == 'False' means size is unknown
with open(filename3, "wb") as imagefile:
imagefile.write(r.content)
Expand Down

0 comments on commit eb6e38e

Please sign in to comment.