V3 接口参考
raw.pub API 文档
接口固定使用 https://api.raw.pub。令牌直接确定用户,路径中不填写用户名。
规则
| 项目 | 说明 |
|---|---|
| 个人空间 | 发送 Authorization: Bearer {token},服务端通过令牌反查用户。 |
| 公共空间 | 不发送 Authorization;不支持别名,有效期仅支持 1d、7d、30d。 |
| code | 只代表链接身份。相同内容可以创建多个 code,各自独立管理。 |
| Content | 相同内容只保存一份;contentReused 表示内容复用,不表示 code 复用。 |
| 编辑 | 传读取到的 version;并发版本冲突返回 409。 |
Link 字段
| 字段 | 类型 | 说明 |
|---|---|---|
id | number | 记录 ID。 |
owner | string | 个人用户名;公共空间为空。 |
code/alias | string | 链接 code 和个人别名。 |
kind | string | text、url、file、directory。 |
value | string | 内容摘要。 |
fileName/contentType | string | 文件名和媒体类型。 |
sizeBytes | number | 内容字节数。 |
hash | string | 内容摘要。 |
tags | string[] | normal、attachment,可同时存在。 |
version | number | 可编辑 Head 版本。 |
deadline | string|null | RFC 3339 失效时间;null 为长期。 |
createTime/modifyTime | string | RFC 3339 时间。 |
link | string | 分享地址;有别名时使用别名。 |
contentReused | boolean | 是否复用了已有 Content。 |
expired/recoverable | boolean | 失效和 30 天恢复期状态。 |
创建
创建文本、网址或引用已有文件
https://api.raw.pub/api/v1/links请求字段
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
origin | string | 文本/网址必填 | 文本或 HTTP/HTTPS 网址。 |
kind | string | 否 | text、url、file。 |
fileCode | string | file 必填 | 引用同空间已有文件。 |
fileName | string | 否 | 引用文件的新名称。 |
alias | string | 否 | 个人别名。 |
deadline | string | 否 | RFC 3339。 |
请求示例
curl --request POST 'https://api.raw.pub/api/v1/links' \
--header 'Authorization: Bearer {token}' --header 'Content-Type: application/json' \
--data '{"origin":"hello raw.pub","kind":"text"}'
响应
201 Created,返回完整 Link。内容重复仍创建新 code。
{"code":"AbCd2345","kind":"text","value":"hello raw.pub","version":1,"contentReused":true,"link":"https://raw.pub/{user}/AbCd2345"}小文件上传
https://api.raw.pub/api/v1/links请求字段
file | binary,必填。 |
alias | 个人别名。 |
expiry | 有效时长。 |
tag | normal 或 attachment。 |
请求示例
curl --request POST 'https://api.raw.pub/api/v1/links' --header 'Authorization: Bearer {token}' --form 'file=@./report.pdf'
响应
201 Created,返回 file Link。
{"code":"BcDe3456","kind":"file","fileName":"report.pdf","sizeBytes":12345,"version":1,"contentReused":false}大文件直传
申请上传地址
https://api.raw.pub/api/v1/uploads请求字段
fileName/contentType | 文件名和媒体类型,必填。 |
sizeBytes | 字节数,必填。 |
contentHash | MD5 十六进制拼 SHA-256 十六进制,必填。 |
contentMD5 | MD5 Base64,必填。 |
tag | normal 或 attachment。 |
请求示例
curl --request POST 'https://api.raw.pub/api/v1/uploads' --header 'Authorization: Bearer {token}' --header 'Content-Type: application/json' --data '{"fileName":"video.mp4","contentType":"video/mp4","sizeBytes":123456,"contentHash":"{md5}{sha256}","contentMD5":"{base64}"}'
响应字段
intentId | 任务 ID。 |
upload.method/url/headers | 直接上传参数。 |
completeUrl | 完成确认接口。 |
link | 内容已存在时直接返回新 Link。 |
响应示例
{"intentId":"{intentId}","upload":{"method":"PUT","url":"{signedUrl}","headers":{"Content-MD5":"{base64}"}},"completeUrl":"/api/v1/uploads/{intentId}/complete"}确认上传完成
https://api.raw.pub/api/v1/uploads/{intentId}/complete请求字段
路径 intentId 必填,请求体为空,使用申请时相同令牌。
请求示例
curl --request POST 'https://api.raw.pub/api/v1/uploads/{intentId}/complete' --header 'Authorization: Bearer {token}'
响应
200 OK,校验大小、摘要和媒体信息后返回 file Link。
{"code":"CdEf4567","kind":"file","fileName":"video.mp4","storage":"oss","contentReused":false,"version":1}目录
创建完整目录树
https://api.raw.pub/api/v1/directories请求字段
directoryName | 根名;/ 表示虚拟根。 |
children | 完整有序树。 |
children[].name | 同级不可重名。 |
children[].code | 引用文件或已有目录时填写;网址也可以只截取最后的 code 或 alias。 |
children[].children | 普通子目录填写;与 code 二选一。 |
请求示例
curl --request POST 'https://api.raw.pub/api/v1/directories' --header 'Authorization: Bearer {token}' --header 'Content-Type: application/json' --data '{"directoryName":"project","children":[{"name":"src","children":[{"name":"main.go","code":"AbCd2345"}]},{"name":"shared","code":"DirEf678"}]}'
响应
201 Created。普通子目录没有 code;引用目录是实时挂载,目标更新后会在这里同步显示。递归或重复挂载返回 409。
{"code":"DeFg5678","kind":"directory","version":1,"tree":{"name":"project","children":[{"name":"src","kind":"directory","code":"","children":[{"name":"main.go","kind":"file","code":"AbCd2345"}]},{"name":"shared","kind":"directory","code":"DirEf678","mounted":true}]}}更新目录或目录切面
https://api.raw.pub/api/v1/directories/{code}请求字段
directoryName、children 是当前 code 可见的完整树;version 是读取到的版本。
请求示例
curl --request PUT 'https://api.raw.pub/api/v1/directories/{code}' --header 'Authorization: Bearer {token}' --header 'Content-Type: application/json' --data '{"directoryName":"src-new","version":3,"children":[{"name":"main.go","code":"AbCd2345"}]}'
响应
200 OK;根和共享 Head 的切面同步变化,版本冲突返回 409。
{"code":"{code}","kind":"directory","version":4,"tree":{"name":"src-new","children":[{"name":"main.go","code":"AbCd2345"}]}}为子目录生成切面链接
https://api.raw.pub/api/v1/links/{code}/slices请求字段
path | 子目录路径,必填。 |
alias | 可选个人别名。 |
请求示例
curl --request POST 'https://api.raw.pub/api/v1/links/{code}/slices' --header 'Authorization: Bearer {token}' --header 'Content-Type: application/json' --data '{"path":"/src"}'
响应
201 Created;同一 Head 的同一路径只能创建一次。
{"code":"EfGh6789","kind":"directory","fileName":"src","version":3,"link":"https://raw.pub/{user}/EfGh6789"}一行上传本地目录
https://api.raw.pub/upd请求字段
{目录} | 本地目录路径,必填。 |
{token} | 个人 API 令牌;省略则上传到公共空间。 |
{有效期} | 可选,例如 7d。 |
请求示例
curl -fsSL 'https://api.raw.pub/upd' | bash -s -- '{目录}' '{token}' '{有效期}'
响应
脚本按文件顺序上传,1KB 以下的文本走服务器,其余文件直传存储;随后提交完整目录树。标准输出仅返回最终目录链接,进度写入标准错误。
https://raw.pub/{user}/{code}链接管理
滚动加载链接列表
https://api.raw.pub/api/v1/links请求字段
page/size | 页码和数量,size 最大 100。 |
status | active、expired、all。 |
tag | normal、attachment、all;默认 all。 |
请求示例
curl 'https://api.raw.pub/api/v1/links?page=1&size=20&status=active&tag=normal' --header 'Authorization: Bearer {token}'
响应字段
list | Link[];directory 额外包含 tree。 |
total/page/size/hasMore | 滚动加载状态。 |
响应示例
{"list":[{"code":"DeFg5678","kind":"directory","tags":["normal"],"version":2,"tree":{"name":"project","children":[]}}],"total":1,"page":1,"size":20,"hasMore":false}按内容摘要检查是否存在
https://api.raw.pub/api/v1/links?hash={hash}请求字段
hash | 内容摘要,必填。 |
请求示例
curl 'https://api.raw.pub/api/v1/links?hash={hash}' --header 'Authorization: Bearer {token}'
响应字段
exists | 是否存在可用 Content。 |
sameSpace | 是否已有当前空间 Link。 |
link | sameSpace 为 true 时返回已有链接。 |
响应示例
{"exists":true,"sameSpace":true,"link":"https://raw.pub/{user}/{code}"}替换文本、网址或文件内容
https://api.raw.pub/api/v1/links/{code}请求字段
kind | text、url、file。 |
origin | text/url 内容。 |
fileCode | file 来源 code。 |
fileName/contentType | 可选文件元数据。 |
version | 当前版本。 |
请求示例
curl --request PUT 'https://api.raw.pub/api/v1/links/{code}' --header 'Authorization: Bearer {token}' --header 'Content-Type: application/json' --data '{"kind":"text","origin":"new text","version":2}'
响应
200 OK,code 不变、version 增加。
{"code":"{code}","kind":"text","value":"new text","version":3,"contentReused":false}修改别名或有效期
https://api.raw.pub/api/v1/links/{code}请求字段
alias | string|null;空值清除。 |
deadline | RFC 3339|null;null 改为长期。 |
请求示例
curl --request PATCH 'https://api.raw.pub/api/v1/links/{code}' --header 'Authorization: Bearer {token}' --header 'Content-Type: application/json' --data '{"alias":"report","deadline":null}'
响应
200 OK。
{"code":"{code}","alias":"report","deadline":null,"link":"https://raw.pub/{user}/report"}另存为独立链接
https://api.raw.pub/api/v1/links/{code}/save-as请求字段
可选 alias、deadline、expiry,允许内容完全不变。
请求示例
curl --request POST 'https://api.raw.pub/api/v1/links/{code}/save-as' --header 'Authorization: Bearer {token}' --header 'Content-Type: application/json' --data '{}'
响应
201 Created,新 code 使用独立 Head,初始共享 Content。
{"code":"FgHi789A","kind":"text","version":1,"contentReused":true}删除链接
https://api.raw.pub/api/v1/links/{code}请求字段
路径 code 必填,无请求体,必须使用所属用户令牌。
请求示例
curl --request DELETE 'https://api.raw.pub/api/v1/links/{code}' --header 'Authorization: Bearer {token}'
响应
204 No Content,响应体为空。仍被其他 code 或目录引用的 Content 不会删除。
HTTP/1.1 204 No Content读取
读取元数据
https://api.raw.pub/api/v1/links/{code}/meta请求字段
路径 code 或 alias 必填,无请求体。
请求示例
curl 'https://api.raw.pub/api/v1/links/{code}/meta'响应字段与示例
返回 type、contentType、contentLength、fileName、value、code、link、version;目录增加 tree,远端文件增加 rawUrl。
{"type":"file","contentType":"image/png","contentLength":1234,"fileName":"image.png","code":"{code}","link":"https://raw.pub/{user}/{code}","version":1,"rawUrl":"https://1.raw.pub/{contentId}"}读取原始内容
https://api.raw.pub/api/v1/links/{code}/raw请求字段
路径 code 必填,无请求体。
请求示例
curl 'https://api.raw.pub/api/v1/links/{code}/raw'响应
text/file 返回原始字节;远端文件返回 307;directory 返回当前切面 manifest;url 返回 400。
HTTP/1.1 200 OK · Content-Type: text/plain; charset=utf-8 · hello raw.pub触发下载
https://api.raw.pub/api/v1/links/{code}/download请求字段
路径 code 必填,无请求体。
请求示例
curl --remote-header-name --remote-name 'https://api.raw.pub/api/v1/links/{code}/download'响应
本地内容返回 200 和 attachment;远端文件返回 307 到带下载文件名的短期地址。
HTTP/1.1 307 Temporary Redirect · Location: {downloadUrl}错误响应
{"status":409,"error":"link changed since it was loaded"}
| 状态 | 说明 |
|---|---|
| 400 | 字段、内容、目录树或摘要无效。 |
| 401 | 令牌无效。 |
| 403 | 空间无权限。 |
| 404 | 链接、切面或上传任务不存在。 |
| 409 | 别名、切面或版本冲突。 |
| 413 | 超过大小上限。 |
| 503 | 远端存储不可用。 |