老九网盘资源数据库 - API文档

公开API接口文档,支持资源添加、搜索和热门剧获取等功能

API认证说明

认证方式:所有API都需要提供API Token进行认证

请求头方式:X-API-Token: your_token

查询参数方式:?api_token=your_token

获取Token:请联系管理员在系统配置中设置API Token

批量添加资源

批量添加多个资源到待处理列表,每个资源可包含多个链接(url为数组),标题和url为必填项

请求信息

方法:POST

路径:/api/public/resources/batch-add

认证:必需(X-API-Token)

请求参数

title 和 url 是必填项,其他字段均为选填

{
  "resources": [
    {
      "title": "资源1",
      "description": "描述1",
      "url": ["链接1", "链接2"],
      "category": "分类",
      "tags": "标签1,标签2",
      "img": "图片链接",
      "source": "数据来源",
      "extra": "额外信息"
    },
    {
      "title": "资源2",
      "url": ["链接3"],
      "description": "描述2"
    }
  ]
}

响应示例

{
  "success": true,
  "message": "批量添加成功",
  "data": {
    "created_count": 2,
    "created_ids": [123, 124]
  },
  "code": 200
}

资源搜索

搜索资源,支持关键词、标签、分类过滤

请求信息

方法:GET

路径:/api/public/resources/search

认证:必需

查询参数

keyword - 搜索关键词

tag - 标签过滤

category - 分类过滤

page - 页码(默认1)

page_size - 每页数量(默认20,最大100)

响应示例

{
  "success": true,
  "message": "搜索成功",
  "data": {
    "resources": [
      {
        "id": 1,
        "title": "资源标题",
        "url": "资源链接",
        "description": "资源描述",
        "view_count": 100,
        "created_at": "2024-12-19 10:00:00",
        "updated_at": "2024-12-19 10:00:00"
      }
    ],
    "total": 50,
    "page": 1,
    "page_size": 20
  },
  "code": 200
}

热门剧列表

获取热门剧列表,支持分页

请求信息

方法:GET

路径:/api/public/hot-dramas

认证:必需

查询参数

page - 页码(默认1)

page_size - 每页数量(默认20,最大100)

响应示例

{
  "success": true,
  "message": "获取热门剧成功",
  "data": {
    "hot_dramas": [
      {
        "id": 1,
        "title": "剧名",
        "description": "剧集描述",
        "img": "封面图片",
        "url": "详情链接",
        "rating": 8.5,
        "year": "2024",
        "region": "中国大陆",
        "genres": "剧情,悬疑",
        "category": "电视剧",
        "created_at": "2024-12-19 10:00:00",
        "updated_at": "2024-12-19 10:00:00"
      }
    ],
    "total": 20,
    "page": 1,
    "page_size": 20
  },
  "code": 200
}

错误码说明

HTTP状态码

200 - 请求成功

400 - 请求参数错误

401 - 认证失败(Token无效或缺失)

500 - 服务器内部错误

503 - 系统维护中或API Token未配置

响应格式

{
  "success": true/false,
  "message": "响应消息",
  "data": {}, // 响应数据
  "code": 200 // 状态码
}

使用示例

cURL示例

# 设置API Token
API_TOKEN="your_api_token_here"

# 批量添加资源
curl -X POST "http://localhost:8080/api/public/resources/batch-add" \
  -H "Content-Type: application/json" \
  -H "X-API-Token: $API_TOKEN" \
  -d '{
    "resources": [
      { "title": "测试资源1", "url": ["https://example.com/resource1"], "description": "描述1" },
      { "title": "测试资源2", "url": ["https://example.com/resource2", "https://example.com/resource3"], "description": "描述2" }
    ]
  }'

# 搜索资源
curl -X GET "http://localhost:8080/api/public/resources/search?keyword=测试" \
  -H "X-API-Token: $API_TOKEN"

# 获取热门剧
curl -X GET "http://localhost:8080/api/public/hot-dramas?page=1&page_size=5" \
  -H "X-API-Token: $API_TOKEN"

前端 fetch 示例


// 资源搜索
fetch('/api/public/resources/search?q=测试', { headers: { 'X-API-Token': 'your_token' } })
  .then(res => res.json())
  .then(res => {
    if (res.success) {
      const list = res.data.list // 资源列表
      const total = res.data.total
    } else {
      alert(res.message)
    }
  })
// 批量添加资源
fetch('/api/public/resources/batch-add', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json', 'X-API-Token': 'your_token' },
  body: JSON.stringify({
    resources: [
      { title: 'xxx', url: ['xxx'], description: 'xxx' },
      { title: 'yyy', url: ['yyy', 'zzz'], description: 'yyy' }
    ]
  })
})
  .then(res => res.json())
  .then(res => {
    if (res.success) {
      alert('添加成功,ID: ' + res.data.created_ids.join(', '))
    } else {
      alert(res.message)
    }
  })