Source Code
feishu_file_fetch
Quick start
Create or update the reference implementation at scripts/feishu_file_fetch.py. It should:
- Accept JSON input:
{ message_id, file_key, type="file", outdir="/root/clawd/uploads", max_bytes=104857600 } - Output JSON:
{ ok, path, filename, bytes, sha256, error? } - Use
FEISHU_APP_ID/FEISHU_APP_SECRETto fetch and cachetenant_access_token(refresh 2 minutes before expiry). - Download via
GET https://open.feishu.cn/open-apis/im/v1/messages/{message_id}/resources/{file_key}?type={type}withAuthorization: Bearer <token>. - Stream to
outdir/yyyyMMdd/, parse filename fromContent-Disposition, fallback tofile_key.bin. - Compute sha256 while streaming; enforce
max_bytesstrictly (terminate and delete temp file if exceeded). - Prevent path traversal by ensuring final path stays within
outdir. - Never log tokens or secrets.
Runtime notes
- Use only stdlib to avoid dependency installs.
- If
Content-Lengthexceedsmax_bytes, fail early. - Use a temp file in the target directory and
os.replaceon success.
Example usage
echo '{"message_id":"om_xxx","file_key":"file_xxx"}' | python scripts/feishu_file_fetch.py
Additional resources
- For API details and error handling notes, see reference.md