note-connector 0.2.12 → 0.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/py/pyproject.toml +1 -1
- package/py/src/note_mcp/api/images.py +0 -58
- package/py/src/note_mcp/server.py +0 -37
package/package.json
CHANGED
package/py/pyproject.toml
CHANGED
|
@@ -677,64 +677,6 @@ def _validate_image_bytes(data: bytes, mime_type: str) -> None:
|
|
|
677
677
|
)
|
|
678
678
|
|
|
679
679
|
|
|
680
|
-
async def upload_eyecatch_base64(
|
|
681
|
-
session: Session,
|
|
682
|
-
note_id: str,
|
|
683
|
-
mime_type: str,
|
|
684
|
-
image_base64: str,
|
|
685
|
-
) -> Image:
|
|
686
|
-
"""Upload an eyecatch image from base64-encoded data.
|
|
687
|
-
|
|
688
|
-
Decodes base64 image data, validates it, writes to a temporary file,
|
|
689
|
-
and uploads via the standard image upload flow. The temporary file is
|
|
690
|
-
cleaned up after upload (success or failure).
|
|
691
|
-
|
|
692
|
-
Args:
|
|
693
|
-
session: Authenticated session
|
|
694
|
-
note_id: The note ID to associate the image with (numeric or key format)
|
|
695
|
-
mime_type: MIME type of the image (e.g., "image/png")
|
|
696
|
-
image_base64: Base64-encoded image data (with or without data URL prefix)
|
|
697
|
-
|
|
698
|
-
Returns:
|
|
699
|
-
Image object with upload result
|
|
700
|
-
|
|
701
|
-
Raises:
|
|
702
|
-
NoteAPIError: If validation fails or API request fails
|
|
703
|
-
"""
|
|
704
|
-
# Step 1: Validate MIME type
|
|
705
|
-
_validate_mime_type(mime_type)
|
|
706
|
-
|
|
707
|
-
# Step 2: Decode base64
|
|
708
|
-
image_bytes = _decode_base64_image(image_base64)
|
|
709
|
-
|
|
710
|
-
# Step 3: Validate image bytes
|
|
711
|
-
_validate_image_bytes(image_bytes, mime_type)
|
|
712
|
-
|
|
713
|
-
# Step 4: Determine file extension
|
|
714
|
-
extension = MIME_TO_EXTENSION.get(mime_type, ".bin")
|
|
715
|
-
|
|
716
|
-
# Step 5: Write to temp file and upload
|
|
717
|
-
tmp_path: str | None = None
|
|
718
|
-
try:
|
|
719
|
-
fd, tmp_path = tempfile.mkstemp(suffix=extension)
|
|
720
|
-
os.close(fd)
|
|
721
|
-
|
|
722
|
-
with open(tmp_path, "wb") as f:
|
|
723
|
-
f.write(image_bytes)
|
|
724
|
-
|
|
725
|
-
image = await _upload_image_internal(
|
|
726
|
-
session=session,
|
|
727
|
-
file_path=tmp_path,
|
|
728
|
-
note_id=note_id,
|
|
729
|
-
image_type=ImageType.EYECATCH,
|
|
730
|
-
)
|
|
731
|
-
return image
|
|
732
|
-
finally:
|
|
733
|
-
if tmp_path is not None:
|
|
734
|
-
with contextlib.suppress(OSError):
|
|
735
|
-
os.unlink(tmp_path)
|
|
736
|
-
|
|
737
|
-
|
|
738
680
|
# =============================================================================
|
|
739
681
|
# Chunked Base64 Image Upload
|
|
740
682
|
# =============================================================================
|
|
@@ -25,7 +25,6 @@ from note_mcp.api.articles import (
|
|
|
25
25
|
from note_mcp.api.images import (
|
|
26
26
|
insert_image_via_api,
|
|
27
27
|
upload_body_image,
|
|
28
|
-
upload_eyecatch_base64,
|
|
29
28
|
upload_eyecatch_chunked,
|
|
30
29
|
upload_eyecatch_image,
|
|
31
30
|
)
|
|
@@ -291,42 +290,6 @@ async def note_upload_eyecatch(
|
|
|
291
290
|
return "アイキャッチ画像をアップロードしました。"
|
|
292
291
|
|
|
293
292
|
|
|
294
|
-
@mcp.tool()
|
|
295
|
-
@require_session
|
|
296
|
-
@handle_api_error
|
|
297
|
-
async def note_set_eyecatch_base64(
|
|
298
|
-
session: Session,
|
|
299
|
-
note_id: Annotated[str, "アイキャッチ画像を設定する記事のID(数値IDまたは記事キー n... 形式)"],
|
|
300
|
-
mime_type: Annotated[str, "画像のMIMEタイプ(image/png, image/jpeg, image/webp など)"],
|
|
301
|
-
image_base64: Annotated[str, "base64エンコードされた画像データ(data:image/...;base64, 形式も可)"],
|
|
302
|
-
) -> str:
|
|
303
|
-
"""base64画像データから記事のアイキャッチ画像を設定します。
|
|
304
|
-
|
|
305
|
-
ChatGPTなどで生成した画像をbase64形式で直接渡すことで、
|
|
306
|
-
ファイルパスを必要とせずにnote記事のサムネイル/見出し画像を設定できます。
|
|
307
|
-
|
|
308
|
-
対応形式: PNG, JPEG, WebP, GIF
|
|
309
|
-
最大サイズ: 10MB
|
|
310
|
-
|
|
311
|
-
Args:
|
|
312
|
-
note_id: アイキャッチ画像を設定する記事のID(数値IDまたは記事キー n... 形式)
|
|
313
|
-
mime_type: 画像のMIMEタイプ
|
|
314
|
-
image_base64: base64エンコードされた画像データ
|
|
315
|
-
|
|
316
|
-
Returns:
|
|
317
|
-
設定結果(画像URLを含む)
|
|
318
|
-
"""
|
|
319
|
-
image = await upload_eyecatch_base64(
|
|
320
|
-
session=session,
|
|
321
|
-
note_id=note_id,
|
|
322
|
-
mime_type=mime_type,
|
|
323
|
-
image_base64=image_base64,
|
|
324
|
-
)
|
|
325
|
-
if image.url:
|
|
326
|
-
return f"アイキャッチ画像を設定しました。URL: {image.url}"
|
|
327
|
-
return "アイキャッチ画像を設定しました。"
|
|
328
|
-
|
|
329
|
-
|
|
330
293
|
@mcp.tool()
|
|
331
294
|
@require_session
|
|
332
295
|
@handle_api_error
|