From 37c4b479b831e6f3fa4d73e7139419d2f22b9c70 Mon Sep 17 00:00:00 2001 From: nkan-aot2 <156717133+nkan-aot2@users.noreply.github.com> Date: Wed, 29 Jan 2025 14:40:23 -0800 Subject: [PATCH] re commit mp3 fix; remove test code --- .../ZippingServices/services/zipperservice.py | 37 ++++++------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/computingservices/ZippingServices/services/zipperservice.py b/computingservices/ZippingServices/services/zipperservice.py index ca89d040..d032feb9 100644 --- a/computingservices/ZippingServices/services/zipperservice.py +++ b/computingservices/ZippingServices/services/zipperservice.py @@ -115,16 +115,17 @@ def __zipfilesandupload(_message, s3credentials): _docbytes = __getdocumentbytearray(fileobj, s3credentials) _formattedbytes = None _filename, extension = path.splitext(fileobj["s3uripath"]) - - try: - _formattedbytes = __removesensitivecontent(_docbytes) - if _formattedbytes is not None: - print("_formattedbytes length is {0}".format(len(_formattedbytes))) - else: - print("_formattedbytes is none") - except Exception: - print("error happened while removing sensitive content of {0} ".format(filename)) - print(traceback.format_exc()) + + if extension.lower() == '.pdf': + try: + _formattedbytes = __removesensitivecontent(_docbytes) + if _formattedbytes is not None: + print("_formattedbytes length is {0}".format(len(_formattedbytes))) + else: + print("_formattedbytes is none") + except Exception: + print("error happened while removing sensitive content of {0} ".format(filename)) + print(traceback.format_exc()) #added a space to try out code merge on git. 18-Sept-2024 zip.writestr( filename, _docbytes if _formattedbytes is None else _formattedbytes @@ -176,19 +177,3 @@ def __getzipfilepath(foldername, filename): else filename + ".zip" ) - -def __removesensitivecontent(documentbytes): - # clear metadata - reader2 = PyPDF2.PdfReader(BytesIO(documentbytes)) - # Check if metadata exists. - if reader2.metadata is not None: - # Create a new PDF file without metadata. - writer = PyPDF2.PdfWriter() - # Copy pages from the original PDF to the new PDF. - for page_num in range(len(reader2.pages)): - page = reader2.pages[page_num] - writer.add_page(page) - #writer.remove_links() # to remove comments. - buffer = BytesIO() - writer.write(buffer) - return buffer.getvalue()