note-connector 0.2.8 → 0.2.10
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 +29 -2
package/package.json
CHANGED
package/py/pyproject.toml
CHANGED
|
@@ -244,6 +244,17 @@ async def _upload_image_internal(
|
|
|
244
244
|
async with NoteAPIClient(session) as client:
|
|
245
245
|
response = await client.post(endpoint, files=files, data=data)
|
|
246
246
|
|
|
247
|
+
# Check for API-level error response
|
|
248
|
+
if "error" in response and not response.get("data"):
|
|
249
|
+
error_message = response.get("error", "unknown error")
|
|
250
|
+
if isinstance(error_message, dict):
|
|
251
|
+
error_message = error_message.get("message", str(error_message))
|
|
252
|
+
raise NoteAPIError(
|
|
253
|
+
code=ErrorCode.UPLOAD_FAILED,
|
|
254
|
+
message=f"画像アップロードに失敗しました: {error_message}",
|
|
255
|
+
details={"note_id": numeric_note_id, "response": response},
|
|
256
|
+
)
|
|
257
|
+
|
|
247
258
|
# Debug: log full API response for investigation
|
|
248
259
|
logger.debug(
|
|
249
260
|
"Image upload response for note_id=%s, endpoint=%s: %s",
|
|
@@ -570,14 +581,30 @@ def _decode_base64_image(image_base64: str) -> bytes:
|
|
|
570
581
|
"""
|
|
571
582
|
clean = _strip_data_url_prefix(image_base64)
|
|
572
583
|
|
|
573
|
-
|
|
584
|
+
# Strip whitespace and newlines (common in ChatGPT output)
|
|
585
|
+
clean = re.sub(r"\s+", "", clean)
|
|
586
|
+
|
|
587
|
+
if not clean:
|
|
574
588
|
raise NoteAPIError(
|
|
575
589
|
code=ErrorCode.INVALID_BASE64,
|
|
576
590
|
message="image_base64 が空です。",
|
|
577
591
|
)
|
|
578
592
|
|
|
593
|
+
# Fix missing padding: base64 length must be a multiple of 4
|
|
594
|
+
# ChatGPT sometimes drops trailing '=' padding chars
|
|
595
|
+
remainder = len(clean) % 4
|
|
596
|
+
if remainder:
|
|
597
|
+
clean += "=" * (4 - remainder)
|
|
598
|
+
|
|
579
599
|
try:
|
|
580
|
-
|
|
600
|
+
# validate=False: tolerate non-strict base64 (extra chars, minor format issues)
|
|
601
|
+
result = base64.b64decode(clean, validate=False)
|
|
602
|
+
if not result:
|
|
603
|
+
raise NoteAPIError(
|
|
604
|
+
code=ErrorCode.INVALID_BASE64,
|
|
605
|
+
message="image_base64 をデコードしましたが、データが空でした。",
|
|
606
|
+
)
|
|
607
|
+
return result
|
|
581
608
|
except (binascii.Error, ValueError) as e:
|
|
582
609
|
raise NoteAPIError(
|
|
583
610
|
code=ErrorCode.INVALID_BASE64,
|