Remove scripts
This commit is contained in:
@@ -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
|
|
||||||

|
|
||||||
|
|
||||||
## Method 2: HTML Image Tag
|
|
||||||
<img src=".attachments.{note_id}/sample_image.png" alt="Sample Red Square Image" width="300" />
|
|
||||||
|
|
||||||
## 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())
|
|
||||||
@@ -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())
|
|
||||||
@@ -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())
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.5 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.5 KiB |
@@ -1,11 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
from PIL import Image, ImageDraw
|
|
||||||
|
|
||||||
# Create a simple image (a red square with some text)
|
|
||||||
img = Image.new('RGB', (200, 200), color = (255, 255, 255))
|
|
||||||
draw = ImageDraw.Draw(img)
|
|
||||||
draw.rectangle([(20, 20), (180, 180)], fill=(255, 0, 0))
|
|
||||||
draw.text((40, 100), "Nextcloud MCP", fill=(255, 255, 255))
|
|
||||||
img.save('sample_image.png')
|
|
||||||
|
|
||||||
print("Image created successfully: sample_image.png")
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
from nextcloud_mcp_server.client import NextcloudClient
|
|
||||||
|
|
||||||
def main():
|
|
||||||
# Create client
|
|
||||||
client = NextcloudClient.from_env()
|
|
||||||
|
|
||||||
# 1. Create a new test note
|
|
||||||
test_title = "Test Note for Deletion with Attachment"
|
|
||||||
print(f"Creating test note: {test_title}...")
|
|
||||||
note = client.notes_create_note(
|
|
||||||
title=test_title,
|
|
||||||
content="This note will be deleted but its attachment should remain.",
|
|
||||||
category="Test"
|
|
||||||
)
|
|
||||||
note_id = note["id"]
|
|
||||||
print(f"Note created with ID: {note_id}")
|
|
||||||
|
|
||||||
# 2. Attach the existing image to the note
|
|
||||||
print(f"Attaching image to note {note_id}...")
|
|
||||||
with open("sample_image.png", 'rb') as f:
|
|
||||||
image_content = f.read()
|
|
||||||
|
|
||||||
upload_response = client.add_note_attachment(
|
|
||||||
note_id=note_id,
|
|
||||||
filename="deletion_test_image.png",
|
|
||||||
content=image_content,
|
|
||||||
mime_type="image/png"
|
|
||||||
)
|
|
||||||
print(f"Image attached successfully (Status: {upload_response['status_code']}).")
|
|
||||||
|
|
||||||
# 3. Verify the attachment exists
|
|
||||||
print(f"Verifying attachment exists...")
|
|
||||||
content, mime_type = client.get_note_attachment(
|
|
||||||
note_id=note_id,
|
|
||||||
filename="deletion_test_image.png"
|
|
||||||
)
|
|
||||||
print(f"Attachment verified (Size: {len(content)} bytes)")
|
|
||||||
|
|
||||||
# 4. Delete the note
|
|
||||||
print(f"\nDeleting note {note_id}...")
|
|
||||||
response = client.notes_delete_note(note_id=note_id)
|
|
||||||
print(f"Note deleted successfully.")
|
|
||||||
|
|
||||||
# Wait a moment for deletion to process
|
|
||||||
time.sleep(1)
|
|
||||||
|
|
||||||
# 5. Verify the note is gone
|
|
||||||
print("\nVerifying note is deleted...")
|
|
||||||
try:
|
|
||||||
client.notes_get_note(note_id=note_id)
|
|
||||||
print("ERROR: Note still exists!")
|
|
||||||
return 1
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Note confirmed deleted (404 Not Found expected): {e}")
|
|
||||||
|
|
||||||
# 6. Check if attachment still exists (expected behavior)
|
|
||||||
print("\nChecking if attachment still exists (orphaned)...")
|
|
||||||
try:
|
|
||||||
content, mime_type = client.get_note_attachment(
|
|
||||||
note_id=note_id,
|
|
||||||
filename="deletion_test_image.png"
|
|
||||||
)
|
|
||||||
print("EXPECTED BEHAVIOR: Attachment still exists after note deletion!")
|
|
||||||
print(f"Attachment size: {len(content)} bytes")
|
|
||||||
print(f"This matches the documented behavior of Nextcloud Notes.")
|
|
||||||
|
|
||||||
# Save the orphaned attachment to verify
|
|
||||||
output_path = "orphaned_attachment.png"
|
|
||||||
with open(output_path, 'wb') as f:
|
|
||||||
f.write(content)
|
|
||||||
print(f"Saved orphaned attachment to: {output_path}")
|
|
||||||
|
|
||||||
return 0
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Unexpected: Attachment was deleted with note: {e}")
|
|
||||||
return 1
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
sys.exit(main())
|
|
||||||
@@ -1,53 +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()
|
|
||||||
|
|
||||||
# First get the current note
|
|
||||||
try:
|
|
||||||
note = client.notes_get_note(note_id=note_id)
|
|
||||||
print(f"Retrieved note: {note['title']}")
|
|
||||||
|
|
||||||
# Update the note content to include a direct reference to the image
|
|
||||||
updated_content = f"""# Note with Image Attachment
|
|
||||||
|
|
||||||
This note demonstrates attaching images to Nextcloud Notes.
|
|
||||||
|
|
||||||
An image will be attached to this note as a demonstration.
|
|
||||||
|
|
||||||
## Image Reference
|
|
||||||
|
|
||||||
The image is attached but not displayed inline in the Notes UI.
|
|
||||||
Attachments in Nextcloud Notes exist as separate files in the .attachments.{note_id}
|
|
||||||
directory but aren't automatically embedded in the note content.
|
|
||||||
|
|
||||||
You can view the image by going to the Files app and navigating to:
|
|
||||||
/Notes/.attachments.{note_id}/sample_image.png
|
|
||||||
|
|
||||||
## Orphaned Attachments
|
|
||||||
|
|
||||||
When notes are deleted, their attachments remain in the system.
|
|
||||||
This is the expected behavior of the official Nextcloud Notes app.
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Update the note with the new content
|
|
||||||
updated_note = client.notes_update_note(
|
|
||||||
note_id=note_id,
|
|
||||||
etag=note['etag'],
|
|
||||||
content=updated_content
|
|
||||||
)
|
|
||||||
|
|
||||||
print(f"Note updated successfully with image reference information.")
|
|
||||||
return 0
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Error updating note: {e}")
|
|
||||||
return 1
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
sys.exit(main())
|
|
||||||
@@ -1,55 +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 with the issue
|
|
||||||
|
|
||||||
# Create client
|
|
||||||
client = NextcloudClient.from_env()
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Get the current note to get its etag
|
|
||||||
note = client.notes_get_note(note_id=note_id)
|
|
||||||
etag = note["etag"]
|
|
||||||
|
|
||||||
# Update the note content with correct image reference syntax
|
|
||||||
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
|
|
||||||

|
|
||||||
|
|
||||||
## Method 2: HTML Image Tag
|
|
||||||
<img src=".attachments.{note_id}/sample_image.png" alt="Sample Red Square Image" width="300" />
|
|
||||||
|
|
||||||
## 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())
|
|
||||||
@@ -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())
|
|
||||||
@@ -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())
|
|
||||||
Reference in New Issue
Block a user