> ## Documentation Index
> Fetch the complete documentation index at: https://docs.2024921.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# 媒体资源

> 图片上传与管理接口

## 获取媒体列表

```http theme={null}
GET /api/media
Authorization: Bearer <token>
```

**响应：**

```json theme={null}
{
  "ok": true,
  "media": [
    {
      "id": "媒体ID",
      "name": "图片名称",
      "url": "data:image/png;base64,...",
      "type": "image/png",
      "size": 123456,
      "created_at": "2025-01-01T00:00:00Z"
    }
  ]
}
```

## 上传媒体

```http theme={null}
POST /api/media
Authorization: Bearer <token>
```

**请求体：**

```json theme={null}
{
  "name": "图片名称",
  "url": "data:image/png;base64,...",
  "type": "image/png",
  "size": 123456
}
```

<Info>
  图片以 base64 格式存储在 D1 数据库中。适合个人博客小规模图片。
  大量图片建议使用外部图床。
</Info>

## 删除媒体

```http theme={null}
DELETE /api/media/:id
Authorization: Bearer <token>
```

## 表结构

```sql theme={null}
CREATE TABLE media (
  id         TEXT PRIMARY KEY,
  name       TEXT NOT NULL,
  url        TEXT NOT NULL,       -- data URL 或外链
  type       TEXT DEFAULT '',     -- MIME 类型
  size       INTEGER DEFAULT 0,   -- 字节
  created_at TEXT DEFAULT ''
);
```
