skills/pastebin/references/api.md

75 lines
1.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 底層 API
## 上傳
```
POST https://bin.xlion.tw
Content-Type: application/json
{"text": "...", "expires": 31536000, "extension": "md"}
```
Response: `{"path": "/XXXXXX"}`
→ URL: `https://bin.xlion.tw{path}`
## 讀取已上傳的內容
```
https://bin.xlion.tw/raw/{path}
```
Example:
```bash
curl https://bin.xlion.tw/raw/JqLLXBmJb4p | head
```
## Markdown 渲染
```
https://bin.xlion.tw/md/{path}.md
```
`.md` 或 `.markdown` 副檔名的 paste 可透過 `/md/` 路徑取得渲染後的 HTML。
## Shell Functions
可複製到 `~/.zshrc`(或 shell 設定檔)中使用:
### clipboard_bin — 剪貼簿上傳
```bash
function clipboard_bin() {
local EXT="$1"
local URL=$(
jq -n --arg t "$(xclip -selection clipboard -o)" \
--arg e "${EXT:-txt}" \
'{text: $t, extension: $e, expires: 31536000}' |
curl -s -H 'Content-Type: application/json' --data-binary @- https://bin.xlion.tw |
jq -r '. | "https://bin.xlion.tw\(.path)"')
xdg-open $URL
}
```
讀取剪貼簿內容,上傳後自動開啟瀏覽器。第一個參數為副檔名(選填,預設 `txt`)。
### stdin_bin — stdin 上傳
```bash
function stdin_bin() {
local EXT="$1"
local URL=$(jq -Rns --arg e "${EXT:-txt}" \
'{text: inputs, extension: $e, expires: 31536000}' |
curl -s -H 'Content-Type: application/json' --data-binary @- https://bin.xlion.tw |
jq -r '. | "https://bin.xlion.tw\(.path)"')
echo $URL
xdg-open $URL
}
```
從 stdin 讀取文字,上傳後自動開啟瀏覽器。第一個參數為副檔名(選填,預設 `txt`)。
(使用方式:輸入完後 `Ctrl+D` 或 pipe)
## 注意事項
- `expires` 為秒數,`31536000` = 1 年
- 若上傳得到 403,檢查網路連線是否正常