老九网盘资源数据库 - 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": {
    "list": [
      {
        "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,
    "limit": 20
  },
  "code": 200
}
违禁词过滤说明

当搜索结果包含违禁词时,响应会包含额外的过滤信息:

{
  "success": true,
  "message": "操作成功",
  "data": {
    "list": [...],
    "total": 45,
    "page": 1,
    "limit": 20,
    "forbidden_words_filtered": true,
    "filtered_forbidden_words": ["违禁词1", "违禁词2"],
    "original_total": 50,
    "filtered_count": 5
  },
  "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"

JavaScript fetch 示例

// 资源搜索
fetch('/api/public/resources/search?keyword=测试', { 
  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
      console.log('搜索结果:', list)
    } else {
      console.error('搜索失败:', 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: '测试资源1', url: ['https://example.com/resource1'], description: '描述1' },
      { title: '测试资源2', url: ['https://example.com/resource2'], description: '描述2' }
    ]
  })
})
  .then(res => res.json())
  .then(res => {
    if (res.success) {
      console.log('添加成功,ID:', res.data.created_ids)
    } else {
      console.error('添加失败:', res.message)
    }
  })

// 获取热门剧
fetch('/api/public/hot-dramas?page=1&page_size=10', {
  headers: { 'X-API-Token': 'your_token' }
})
  .then(res => res.json())
  .then(res => {
    if (res.success) {
      const dramas = res.data.hot_dramas
      console.log('热门剧:', dramas)
    } else {
      console.error('获取失败:', res.message)
    }
  })

Python requests 示例

import requests

API_TOKEN = 'your_api_token_here'
BASE_URL = 'http://localhost:8080/api'

headers = {
    'X-API-Token': API_TOKEN,
    'Content-Type': 'application/json'
}

# 搜索资源
def search_resources(keyword, page=1, page_size=20):
    params = {
        'keyword': keyword,
        'page': page,
        'page_size': page_size
    }
    response = requests.get(
        f'{BASE_URL}/public/resources/search',
        headers={'X-API-Token': API_TOKEN},
        params=params
    )
    return response.json()

# 批量添加资源
def batch_add_resources(resources):
    data = {'resources': resources}
    response = requests.post(
        f'{BASE_URL}/public/resources/batch-add',
        headers=headers,
        json=data
    )
    return response.json()

# 获取热门剧
def get_hot_dramas(page=1, page_size=20):
    params = {
        'page': page,
        'page_size': page_size
    }
    response = requests.get(
        f'{BASE_URL}/public/hot-dramas',
        headers={'X-API-Token': API_TOKEN},
        params=params
    )
    return response.json()

# 使用示例
if __name__ == '__main__':
    # 搜索资源
    result = search_resources('测试')
    if result['success']:
        print('搜索结果:', result['data']['list'])
    
    # 批量添加资源
    resources = [
        {'title': '测试资源1', 'url': ['https://example.com/resource1']},
        {'title': '测试资源2', 'url': ['https://example.com/resource2']}
    ]
    result = batch_add_resources(resources)
    if result['success']:
        print('添加成功,ID:', result['data']['created_ids'])
    
    # 获取热门剧
    result = get_hot_dramas()
    if result['success']:
        print('热门剧:', result['data']['hot_dramas'])

本站内容由网络爬虫自动抓取。本站不储存、复制、传播任何文件,仅作个人公益学习,请在获取后24小内删除!!!

老九网盘链接管理系统| v 1.2.5