V3 接口参考

raw.pub API 文档

接口固定使用 https://api.raw.pub。令牌直接确定用户,路径中不填写用户名。

规则

项目说明
个人空间发送 Authorization: Bearer {token},服务端通过令牌反查用户。
公共空间不发送 Authorization;不支持别名,有效期仅支持 1d7d30d
code只代表链接身份。相同内容可以创建多个 code,各自独立管理。
Content相同内容只保存一份;contentReused 表示内容复用,不表示 code 复用。
编辑传读取到的 version;并发版本冲突返回 409。

Link 字段

字段类型说明
idnumber记录 ID。
ownerstring个人用户名;公共空间为空。
code/aliasstring链接 code 和个人别名。
kindstringtext、url、file、directory。
valuestring内容摘要。
fileName/contentTypestring文件名和媒体类型。
sizeBytesnumber内容字节数。
hashstring内容摘要。
tagsstring[]normal、attachment,可同时存在。
versionnumber可编辑 Head 版本。
deadlinestring|nullRFC 3339 失效时间;null 为长期。
createTime/modifyTimestringRFC 3339 时间。
linkstring分享地址;有别名时使用别名。
contentReusedboolean是否复用了已有 Content。
expired/recoverableboolean失效和 30 天恢复期状态。

创建

创建文本、网址或引用已有文件

POSThttps://api.raw.pub/api/v1/links

请求字段

字段类型必填说明
originstring文本/网址必填文本或 HTTP/HTTPS 网址。
kindstringtext、url、file。
fileCodestringfile 必填引用同空间已有文件。
fileNamestring引用文件的新名称。
aliasstring个人别名。
deadlinestringRFC 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"}

小文件上传

POSThttps://api.raw.pub/api/v1/links

请求字段

filebinary,必填。
alias个人别名。
expiry有效时长。
tagnormal 或 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}

大文件直传

申请上传地址

POSThttps://api.raw.pub/api/v1/uploads

请求字段

fileName/contentType文件名和媒体类型,必填。
sizeBytes字节数,必填。
contentHashMD5 十六进制拼 SHA-256 十六进制,必填。
contentMD5MD5 Base64,必填。
tagnormal 或 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"}

确认上传完成

POSThttps://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}

目录

创建完整目录树

POSThttps://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}]}}

更新目录或目录切面

PUThttps://api.raw.pub/api/v1/directories/{code}

请求字段

directoryNamechildren 是当前 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"}]}}

为子目录生成切面链接

POSThttps://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"}

一行上传本地目录

GEThttps://api.raw.pub/upd

请求字段

{目录}本地目录路径,必填。
{token}个人 API 令牌;省略则上传到公共空间。
{有效期}可选,例如 7d。

请求示例

curl -fsSL 'https://api.raw.pub/upd' | bash -s -- '{目录}' '{token}' '{有效期}'

响应

脚本按文件顺序上传,1KB 以下的文本走服务器,其余文件直传存储;随后提交完整目录树。标准输出仅返回最终目录链接,进度写入标准错误。

https://raw.pub/{user}/{code}

链接管理

滚动加载链接列表

GEThttps://api.raw.pub/api/v1/links

请求字段

page/size页码和数量,size 最大 100。
statusactive、expired、all。
tagnormal、attachment、all;默认 all。

请求示例

curl 'https://api.raw.pub/api/v1/links?page=1&size=20&status=active&tag=normal' --header 'Authorization: Bearer {token}'

响应字段

listLink[];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}

按内容摘要检查是否存在

GEThttps://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。
linksameSpace 为 true 时返回已有链接。

响应示例

{"exists":true,"sameSpace":true,"link":"https://raw.pub/{user}/{code}"}

替换文本、网址或文件内容

PUThttps://api.raw.pub/api/v1/links/{code}

请求字段

kindtext、url、file。
origintext/url 内容。
fileCodefile 来源 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}

修改别名或有效期

PATCHhttps://api.raw.pub/api/v1/links/{code}

请求字段

aliasstring|null;空值清除。
deadlineRFC 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"}

另存为独立链接

POSThttps://api.raw.pub/api/v1/links/{code}/save-as

请求字段

可选 aliasdeadlineexpiry,允许内容完全不变。

请求示例

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}

删除链接

DELETEhttps://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

读取

读取元数据

GEThttps://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}"}

读取原始内容

GEThttps://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

触发下载

GEThttps://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远端存储不可用。