From 02e55a4636dc010766d84ef95988e15e0169e620 Mon Sep 17 00:00:00 2001 From: Chris Coutinho Date: Fri, 16 May 2025 08:19:01 +0200 Subject: [PATCH] Remove scripts --- attach_and_embed_image.py | 70 --------------------- attach_image.py | 40 ------------ check_updated_note.py | 26 -------- retrieved_image.png | Bin 1565 -> 0 bytes sample_image.png | Bin 1565 -> 0 bytes sample_image.py | 11 ---- test_delete_note_with_attachment.py | 82 ------------------------- update_content_with_image_reference.py | 53 ---------------- update_image_reference.py | 55 ----------------- update_webdav_auth.py | 77 ----------------------- verify_image_attachment.py | 44 ------------- 11 files changed, 458 deletions(-) delete mode 100644 attach_and_embed_image.py delete mode 100644 attach_image.py delete mode 100644 check_updated_note.py delete mode 100644 retrieved_image.png delete mode 100644 sample_image.png delete mode 100644 sample_image.py delete mode 100644 test_delete_note_with_attachment.py delete mode 100644 update_content_with_image_reference.py delete mode 100644 update_image_reference.py delete mode 100644 update_webdav_auth.py delete mode 100644 verify_image_attachment.py diff --git a/attach_and_embed_image.py b/attach_and_embed_image.py deleted file mode 100644 index 930b900..0000000 --- a/attach_and_embed_image.py +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env python -import os -import sys -from nextcloud_mcp_server.client import NextcloudClient - -def main(): - note_id = 487 # ID of the note we just created - - # Create client - client = NextcloudClient.from_env() - - # Check if image exists - image_path = 'sample_image.png' - if not os.path.exists(image_path): - print(f"Error: Image file '{image_path}' not found") - return 1 - - # Read the image - with open(image_path, 'rb') as f: - image_content = f.read() - - print(f"Attaching image to note {note_id}...") - try: - # Attach the image to the note - upload_response = client.add_note_attachment( - note_id=note_id, - filename="sample_image.png", - content=image_content, - mime_type="image/png" - ) - - print(f"Image attached successfully (Status: {upload_response['status_code']}).") - - # Now get the current note to get its etag - note = client.notes_get_note(note_id=note_id) - etag = note["etag"] - - # Update the note content to include the image references - updated_content = f"""# Note with Visible Image Demo - -This note demonstrates how to properly embed an image in Nextcloud Notes so it's visible in the browser interface. - -We'll include the sample red square image we created earlier using both Markdown and HTML methods. - -## Method 1: Markdown Image Syntax -![Sample Red Square Image](.attachments.{note_id}/sample_image.png) - -## Method 2: HTML Image Tag -Sample Red Square Image - -## Image Path Details -The image is stored at: `/Notes/.attachments.{note_id}/sample_image.png` -""" - - # Update the note with the references to the image - updated_note = client.notes_update_note( - note_id=note_id, - etag=etag, - content=updated_content - ) - - print(f"Note updated with image references. You can now view it in the browser.") - print(f"Note URL: /index.php/apps/notes/#/note/{note_id}") - return 0 - except Exception as e: - print(f"Error: {e}") - return 1 - -if __name__ == "__main__": - sys.exit(main()) diff --git a/attach_image.py b/attach_image.py deleted file mode 100644 index f9d766c..0000000 --- a/attach_image.py +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env python -import os -import sys -from nextcloud_mcp_server.client import NextcloudClient - -def main(): - note_id = 420 # ID of the note we created earlier - - # Create client - client = NextcloudClient.from_env() - - # Check if image exists - image_path = 'sample_image.png' - if not os.path.exists(image_path): - print(f"Error: Image file '{image_path}' not found") - return 1 - - # Read the image - with open(image_path, 'rb') as f: - image_content = f.read() - - print(f"Attaching image to note {note_id}...") - try: - # Attach the image to the note - upload_response = client.add_note_attachment( - note_id=note_id, - filename="sample_image.png", - content=image_content, - mime_type="image/png" - ) - - print(f"Image attached successfully (Status: {upload_response['status_code']}).") - print(f"Note URL: /index.php/apps/notes/#/note/{note_id}") - return 0 - except Exception as e: - print(f"Error attaching image: {e}") - return 1 - -if __name__ == "__main__": - sys.exit(main()) diff --git a/check_updated_note.py b/check_updated_note.py deleted file mode 100644 index bcba688..0000000 --- a/check_updated_note.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env python -import sys -from nextcloud_mcp_server.client import NextcloudClient - -def main(): - note_id = 420 # ID of the note with the image attachment - - # Create client - client = NextcloudClient.from_env() - - # Get the note again to see the updated content - try: - note = client.notes_get_note(note_id=note_id) - print(f"Retrieved note: {note['title']}") - print("\nCURRENT NOTE CONTENT:") - print("-" * 50) - print(note['content']) - print("-" * 50) - - return 0 - except Exception as e: - print(f"Error retrieving note: {e}") - return 1 - -if __name__ == "__main__": - sys.exit(main()) diff --git a/retrieved_image.png b/retrieved_image.png deleted file mode 100644 index fd67dba665e8a12681ca538e9d780d4038bd108f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1565 zcmeAS@N?(olHy`uVBq!ia0vp^CqS5k2}mkgS)OEIV1450;uumf=k4v&-XXOz$3ON@ zpX6{#Y1hPwthu``9Bax*H22`Rlo8nBlJMVQ%Lxu8ja9W0F5ODeR}Q&O5ngo8qHJN) zyWFm@yJZUQg%oK|uEeGhlHlGB0vVKFbb4}5Wn z*r1>jAt0v1!7bLp%6+JbHSu86h6G1^!c+XR$^tLO@8av8r>fFnFIiN9IN3*Ib>GZTe50`pxEKK&;m=kGJEf%B`E9F1mt+aGW&|^Z%=>85ta!uU;i(WV{J|ds|%HuSLYY|JXd+ zlT-NR7p-|SeZ5mx?(IdJH-E@Jb0uQqGKUCL(}`!F@!#Ly@1u6}-ag+v&vyRf%l!jG zO|u@g^BWeYc?1Rt6+e4&+`i6-OGCT6U;cR8*RR>1baoz}GVR#*{N(jn_x8Ma%d2T+ zmGtdR%CG0=AGezt2+Z{P^5w|c*&Ayr9|q5mN}MWIb##i6BrkvV>uXOoYzeV0&&u#P zdi2(w$is&xg~Y9sw-1T4%S!U>?CMgE~xpmZL|t^sX&-zqL1d(yUn}&wT#nyxj8b-P9#}tEZmy z2&&&7wtm`@Ha1s}OMic#yz}c<;h{+-&-?u5hoz_2Em`Wi+;8O?pGn`|dY66BZrv~X zY}>kZ5;8oRTH4A}yXMV%@v2Ky+o|i_yBk|HmtQg%oK|uEeGhlHlGB0vVKFbb4}5Wn z*r1>jAt0v1!7bLp%6+JbHSu86h6G1^!c+XR$^tLO@8av8r>fFnFIiN9IN3*Ib>GZTe50`pxEKK&;m=kGJEf%B`E9F1mt+aGW&|^Z%=>85ta!uU;i(WV{J|ds|%HuSLYY|JXd+ zlT-NR7p-|SeZ5mx?(IdJH-E@Jb0uQqGKUCL(}`!F@!#Ly@1u6}-ag+v&vyRf%l!jG zO|u@g^BWeYc?1Rt6+e4&+`i6-OGCT6U;cR8*RR>1baoz}GVR#*{N(jn_x8Ma%d2T+ zmGtdR%CG0=AGezt2+Z{P^5w|c*&Ayr9|q5mN}MWIb##i6BrkvV>uXOoYzeV0&&u#P zdi2(w$is&xg~Y9sw-1T4%S!U>?CMgE~xpmZL|t^sX&-zqL1d(yUn}&wT#nyxj8b-P9#}tEZmy z2&&&7wtm`@Ha1s}OMic#yz}c<;h{+-&-?u5hoz_2Em`Wi+;8O?pGn`|dY66BZrv~X zY}>kZ5;8oRTH4A}yXMV%@v2Ky+o|i_yBk|Hmt - -## Image Path Details -The image is stored at: `/Notes/.attachments.{note_id}/sample_image.png` - -## Note on Image Embedding -In Nextcloud Notes, images must be referenced with a period at the beginning of the path. The correct format is: -`.attachments.{note_id}/filename.png` - -Without the leading period, the image won't display correctly. -""" - - # Update the note with the corrected image references - updated_note = client.notes_update_note( - note_id=note_id, - etag=etag, - content=updated_content - ) - - print(f"Note updated with corrected image references.") - print(f"Note URL: /index.php/apps/notes/#/note/{note_id}") - return 0 - except Exception as e: - print(f"Error: {e}") - return 1 - -if __name__ == "__main__": - sys.exit(main()) diff --git a/update_webdav_auth.py b/update_webdav_auth.py deleted file mode 100644 index 9a3210f..0000000 --- a/update_webdav_auth.py +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env python -import sys -import os -import base64 -from nextcloud_mcp_server.client import NextcloudClient, HTTPStatusError -import logging -import time - -logging.basicConfig(level=logging.INFO) -logger = logging.getLogger(__name__) - -def test_webdav_auth_with_attachment(): - """ - Test function to verify WebDAV authentication by attempting to use add_note_attachment. - """ - client = NextcloudClient.from_env() - print("Client authentication type:", type(client._client.auth).__name__) - - username = os.environ["NEXTCLOUD_USERNAME"] - webdav_base = client._get_webdav_base_path() - notes_path = f"{webdav_base}/Notes" - print(f"Target WebDAV Notes path for PROPFIND check: {notes_path}") - - temp_note_id = None - try: - # 1. Create a temporary note to get a note_id - print("\nCreating a temporary note...") - temp_note_title = f"Temp Note for WebDAV Test - {int(time.time())}" - created_note = client.notes_create_note(title=temp_note_title, content="Test content") - temp_note_id = created_note.get("id") - if not temp_note_id: - print("Error: Failed to create temporary note.") - return 1 - print(f"Temporary note created with ID: {temp_note_id}") - - # 2. Attempt to add an attachment (this will trigger the internal PROPFIND) - print(f"\nTest: Attempting add_note_attachment for note_id {temp_note_id} (uses client's BasicAuth)") - dummy_content = b"This is a test attachment." - dummy_filename = "test_attachment.txt" - - # The add_note_attachment method itself contains the PROPFIND check - # and will log details if it fails. - response_data = client.add_note_attachment( - note_id=temp_note_id, - filename=dummy_filename, - content=dummy_content, - mime_type="text/plain" - ) - print(f"add_note_attachment response: {response_data}") - if response_data and response_data.get("status_code") in [201, 204]: - print("Success! add_note_attachment (and its internal PROPFIND) worked.") - else: - print("Failure or unexpected response from add_note_attachment.") - # The client.py logs should show details of the PROPFIND if it failed. - - except HTTPStatusError as e: - print(f"HTTPStatusError during add_note_attachment: {e.response.status_code} - {e.response.text}") - if e.response.status_code == 401: - print("Reproduced 401 Unauthorized during add_note_attachment's PROPFIND check!") - else: - print("An HTTP error other than 401 occurred.") - except Exception as e: - print(f"An unexpected error occurred: {str(e)}") - finally: - # 3. Clean up: Delete the temporary note - if temp_note_id: - print(f"\nCleaning up: Deleting temporary note ID {temp_note_id}...") - try: - client.notes_delete_note(note_id=temp_note_id) - print(f"Successfully deleted temporary note ID {temp_note_id}.") - except Exception as e_del: - print(f"Error deleting temporary note ID {temp_note_id}: {str(e_del)}") - - return 0 - -if __name__ == "__main__": - sys.exit(test_webdav_auth_with_attachment()) diff --git a/verify_image_attachment.py b/verify_image_attachment.py deleted file mode 100644 index 281f1b2..0000000 --- a/verify_image_attachment.py +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env python -import sys -from nextcloud_mcp_server.client import NextcloudClient - -def main(): - note_id = 420 # ID of the note we created earlier - - # Create client - client = NextcloudClient.from_env() - - # First verify the note exists - print(f"Retrieving note {note_id}...") - try: - note = client.notes_get_note(note_id=note_id) - print(f"Note retrieved: {note['title']}") - except Exception as e: - print(f"Error retrieving note: {e}") - return 1 - - # Now try to get the image attachment - attachment_filename = "sample_image.png" - print(f"Retrieving attachment '{attachment_filename}' from note {note_id}...") - try: - content, mime_type = client.get_note_attachment( - note_id=note_id, - filename=attachment_filename - ) - print(f"Attachment retrieved successfully!") - print(f"MIME type: {mime_type}") - print(f"Content size: {len(content)} bytes") - - # Save the retrieved image to verify it's the same - output_path = "retrieved_image.png" - with open(output_path, 'wb') as f: - f.write(content) - print(f"Saved retrieved image to: {output_path}") - - return 0 - except Exception as e: - print(f"Error retrieving attachment: {e}") - return 1 - -if __name__ == "__main__": - sys.exit(main())