Word Docx Formatting Repair Helper
帮助知识工作者自动化处理Word文档格式、查找替换与样式调整任务。
通过 Maton API 接入 OneDrive,实现文件上传、下载与共享操作。
openclaw skills install @byungkyu/one-drive命令、参数、文件名以原文为准
通过 Microsoft Graph 实现受管理的 OAuth 认证,访问 OneDrive API。支持对文件、文件夹、驱动器及共享功能的完整增删改查操作。
CLI:
maton one-drive item listmaton api '/one-drive/v1.0/me/drive/root/children'Python:
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://api.maton.ai/one-drive/v1.0/me/drive/root/children')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOFhttps://api.maton.ai/one-drive/v1.0/{resource}Maton 将请求代理至 graph.microsoft.com,并自动注入您的 OAuth 访问令牌。
NPM:
npm install -g @maton/cliHomebrew:
brew install maton-ai/cli/matonCLI:
maton login # 打开浏览器获取 API 密钥
maton login --interactive # 跳过浏览器,手动粘贴 API 密钥
maton whoami # 查看当前认证状态手动方式:
MATON_API_KEY:export MATON_API_KEY="YOUR_API_KEY"在 https://api.maton.ai 管理您的 OneDrive OAuth 连接。
CLI:
maton connection list one-drive --status ACTIVEmaton api -X GET /connections -f app=one-drive -f status=ACTIVEPython:
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://api.maton.ai/connections?app=one-drive&status=ACTIVE')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOFCLI:
maton connection create one-drivematon api /connections -f app=one-drivePython:
python <<'EOF'
import urllib.request, os, json
data = json.dumps({'app': 'one-drive'}).encode()
req = urllib.request.Request('https://api.maton.ai/connections', data=data, method='POST')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Content-Type', 'application/json')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOFCLI:
maton connection view {connection_id}maton api /connections/{connection_id}Python:
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://api.maton.ai/connections/{connection_id}')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF响应示例:
{
"connection": {
"connection_id": "{connection_id}",
"status": "ACTIVE",
"creation_time": "2026-02-07T08:23:30.317909Z",
"last_updated_time": "2026-02-07T08:24:04.925298Z",
"url": "https://connect.maton.ai/?session_token=...",
"app": "one-drive",
"metadata": {}
}
}在浏览器中打开返回的 url 完成 OAuth 授权流程。
CLI:
maton connection delete {connection_id}maton api -X DELETE /connections/{connection_id}Python:
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://api.maton.ai/connections/{connection_id}', method='DELETE')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF若您拥有多个 OneDrive 连接,需明确指定使用哪一个:
CLI:
maton one-drive item list --connection {connection_id}maton api /one-drive/v1.0/me/drive/root/children --connection {connection_id}Python:
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://api.maton.ai/one-drive/v1.0/me/drive')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Maton-Connection', '{connection_id}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF若存在多个连接,请始终指定具体连接以确保请求发送至正确的账户。
GET /one-drive/v1.0/me/drive示例:
maton one-drive whoamiGET /one-drive/v1.0/me/drives示例:
maton one-drive drive listGET /one-drive/v1.0/drives/{drive-id}示例:
maton one-drive drive view {drive-id}GET /one-drive/v1.0/me/drive/root示例:
maton one-drive item view rootGET /one-drive/v1.0/me/drive/root/children示例:
maton one-drive item listGET /one-drive/v1.0/me/drive/items/{item-id}示例:
maton one-drive item view {item-id}使用冒号(:)语法通过路径访问项目:
GET /one-drive/v1.0/me/drive/root:/Documents/report.pdf示例:
maton one-drive item view-by-path Documents/report.pdfGET /one-drive/v1.0/me/drive/root:/Documents:/children示例:
maton one-drive item list DocumentsGET /one-drive/v1.0/me/drive/items/{item-id}/children示例:
maton one-drive item view {item-id} --expand children通过名称访问已知特殊文件夹:
GET /one-drive/v1.0/me/drive/special/documents
GET /one-drive/v1.0/me/drive/special/photos
GET /one-drive/v1.0/me/drive/special/music
GET /one-drive/v1.0/me/drive/special/approot示例:
maton one-drive item view --special documentsGET /one-drive/v1.0/me/drive/recent示例:
maton one-drive drive recentGET /one-drive/v1.0/me/drive/sharedWithMe示例:
maton one-drive drive sharedGET /one-drive/v1.0/me/drive/root/search(q='budget')示例:
maton one-drive drive search 'budget'POST /one-drive/v1.0/me/drive/root:/Documents:/children
Content-Type: application/json
{
"name": "Reports",
"folder": {},
"@microsoft.graph.conflictBehavior": "rename"
}示例:
maton one-drive item create-folder Reports --path Documents在指定父文件夹内创建文件夹:
POST /one-drive/v1.0/me/drive/items/{parent-id}/children
Content-Type: application/json
{
"name": "Reports",
"folder": {}
}示例:
maton one-drive item create-folder Reports --parent-id {parent-id}PUT /one-drive/v1.0/me/drive/root:/Documents/report.pdf:/content
Content-Type: application/pdf
{report.pdf 二进制内容}示例:
maton one-drive item upload ./report.pdf --path Documents/report.pdf对于超过 4MB 的文件,使用可恢复上传机制:
步骤 1:创建上传会话
POST /one-drive/v1.0/me/drive/root:/large-report.pdf:/createUploadSession
Content-Type: application/json
{
"item": {
"@microsoft.graph.conflictBehavior": "rename"
}
}示例:
maton one-drive item upload ./large-report.pdf --path large-report.pdf --conflict rename大于 4 MiB 的文件将自动启用可恢复上传会话。
响应示例:
{
"uploadUrl": "https://sn3302.up.1drv.com/up/...",
"expirationDateTime": "2024-02-08T10:00:00Z"
}**步骤 2:向 uploadUrl 上传数据块**
获取文件元数据以获取下载链接:
GET /one-drive/v1.0/me/drive/items/{item-id}示例:
maton one-drive item view {item-id}响应中包含 @microsoft.graph.downloadUrl —— 一个预认证的临时链接:
{
"id": "...",
"name": "document.pdf",
"@microsoft.graph.downloadUrl": "https://public-sn3302.files.1drv.com/..."
}可直接使用该链接下载文件内容(无需携带认证头)。
PATCH /one-drive/v1.0/me/drive/items/{item-id}
Content-Type: application/json
{
"name": "new-name.txt"
}示例:
maton one-drive item update {item-id} --name new-name.txt移动到其他文件夹:
PATCH /one-drive/v1.0/me/drive/items/{item-id}
Content-Type: application/json
{
"parentReference": {
"id": "{new-parent-id}"
}
}示例:
maton one-drive item move {item-id} --dest-id {new-parent-id}POST /one-drive/v1.0/me/drive/items/{item-id}/copy
Content-Type: application/json
{
"parentReference": {
"id": "{destination-folder-id}"
},
"name": "copied-file.txt"
}示例:
maton one-drive item copy {item-id} --dest-id {destination-folder-id} --name copied-file.txt返回 202 Accepted,并附带 Location 头用于监控复制进度。
DELETE /one-drive/v1.0/me/drive/items/{item-id}示例:
maton one-drive item delete {item-id}成功后返回 204 No Content。
POST /one-drive/v1.0/me/drive/items/01ABCDEF/createLink
Content-Type: application/json
{
"type": "view",
"scope": "anonymous"
}链接类型:
view:只读访问edit:读写访问embed:可嵌入链接作用范围:
anonymous:任何持有链接的人organization:您所在组织内的任何人示例:
maton one-drive item share 01ABCDEF --type view --scope anonymousPOST /one-drive/v1.0/me/drive/items/{item-id}/invite
Content-Type: application/json
{
"recipients": [
{"email": "user@example.com"}
],
"roles": ["read"],
"sendInvitation": true,
"message": "Check out this file!"
}示例:
maton one-drive item invite {item-id} --emails user@example.com --roles read --message 'Check out this file!'通过 OData 查询参数自定义响应:
$select:选择特定字段:?$select=id,name,size$expand:包含关联资源:?$expand=children$filter:过滤结果:?$filter=file ne null(仅文件)$orderby:排序结果:?$orderby=name asc$top:限制返回数量:?$top=10示例:
GET /one-drive/v1.0/me/drive/root/children?$select=id,name,size&$top=20&$orderby=name%20ascmaton one-drive item list --select id,name,size --top 20 --orderby 'name asc'OneDrive 使用基于游标的分页机制。CLI 会自动处理分页,使用 --paginate 参数。
示例:
maton one-drive item list --paginate# 搜索文件
maton one-drive drive search 'budget'
# 共享文件
maton one-drive item share 01ABCDEF --type view --scope anonymous
# 使用 --jq 提取特定字段(需配合 --json)
maton one-drive item view root --json --jq '.name'// 列出根目录文件
const response = await fetch(
'https://api.maton.ai/one-drive/v1.0/me/drive/root/children',
{
headers: {
'Authorization': `Bearer ${process.env.MATON_API_KEY}`
}
}
);
const data = await response.json();
// 上传文件
const uploadResponse = await fetch(
'https://api.maton.ai/one-drive/v1.0/me/drive/root:/myfile.txt:/content',
{
method: 'PUT',
headers: {
'Authorization': `Bearer ${process.env.MATON_API_KEY}`,
'Content-Type': 'text/plain'
},
body: 'Hello, OneDrive!'
}
);import os
import requests
# 列出根目录文件
response = requests.get(
'https://api.maton.ai/one-drive/v1.0/me/drive/root/children',
headers={'Authorization': f'Bearer {os.environ["MATON_API_KEY"]}'}
)
files = response.json()
# 上传文件
upload_response = requests.put(
'https://api.maton.ai/one-drive/v1.0/me/drive/root:/myfile.txt:/content',
headers={
'Authorization': f'Bearer {os.environ["MATON_API_KEY"]}',
'Content-Type': 'text/plain'
},
data='Hello, OneDrive!'
)graph.microsoft.com):)语法进行路径定位:/root:/path/to/file@microsoft.graph.downloadUrl 返回的下载链接为预认证且有效期短暂fail、replace、renamewhoami 返回的用户自身驱动器 ID 可直接访问。drive list 中出现的 b!... 前缀 ID 在直接调用时会返回 HTTP 400 错误。应使用 me/drive 替代。curl -g 以禁用通配符解析jq 或其他命令时,某些 shell 环境中环境变量如 $MATON_API_KEY 可能无法正确展开| 状态码 | 含义 |
|---|---|
| 400 | 缺少 OneDrive 连接或请求无效 |
| 401 | 无效或缺失的 Maton API 密钥 |
| 403 | 权限不足 |
| 404 | 项目未找到 |
| 409 | 冲突(例如项目已存在) |
| 429 | 请求频率超限(请检查 Retry-After 头) |
| 4xx/5xx | 透传自 Microsoft Graph API 的错误 |
{
"error": {
"code": "itemNotFound",
"message": "The resource could not be found."
}
}CLI:
maton whoamimaton connection list手动方式:
MATON_API_KEY 环境变量已设置:echo $MATON_API_KEYpython <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://api.maton.ai/connections')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOFone-drive 开头。例如:https://api.maton.ai/one-drive/v1.0/me/drive/root/childrenhttps://api.maton.ai/v1.0/me/drive/root/children已收录 2 个 Skill