openapi: 3.1.0
info:
  title: FufuLinks API
  version: 1.0.0
  description: 基于 FFLink 的公共友链读取和申请提交接口。
servers:
  - url: http://127.0.0.1:8080
    description: 本机开发
  - url: https://links.furina.blog
    description: 约定的正式公共入口
paths:
  /api/v1/links:
    get:
      operationId: listPublishedLinks
      summary: 分页读取已发布友链
      parameters:
        - name: category
          in: query
          description: 按 FFLink tags 中的任一标签编码筛选，区分大小写。
          schema:
            $ref: '#/components/schemas/CategoryCode'
        - name: cursor
          in: query
          description: 上一页的 X-Next-Cursor 响应头值。
          schema:
            $ref: '#/components/schemas/Id'
        - name: limit
          in: query
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 20
      responses:
        '200':
          description: 按友链 ID 倒序分发 FFLink 数组。空页返回空数组。
          headers:
            X-Next-Cursor:
              description: 下一页的游标。到达最后一页时省略此响应头。
              schema:
                type: string
                pattern: '^[1-9][0-9]*$'
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/FFLink'
        '400':
          $ref: '#/components/responses/BadRequest'
  /api/v1/links/{id}:
    get:
      operationId: getPublishedLink
      summary: 读取指定的已发布友链
      parameters:
        - name: id
          in: path
          required: true
          schema:
            $ref: '#/components/schemas/Id'
      responses:
        '200':
          description: 已发布友链的 FFLink 表示。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FFLink'
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          description: 无已发布友链对应此 ID。
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
  /api/v1/categories:
    get:
      operationId: listCategories
      summary: 读取预设标签
      responses:
        '200':
          description: 标签按编码升序排列。
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Category'
  /api/v1/stats:
    get:
      operationId: getPublicStats
      summary: 读取公共库统计
      responses:
        '200':
          description: 当前已发布友链数量。
          content:
            application/json:
              schema:
                type: object
                required: [publishedLinks]
                properties:
                  publishedLinks:
                    type: integer
                    format: int64
                    minimum: 0
  /api/v1/applications:
    post:
      operationId: submitLinkApplication
      summary: 提交友链申请
      description: 提交 FFLink 字段及选填的联系邮箱。标签可省略，提供时最多 10 个且须为已登记编码。名称和简介须含非空白字符。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ApplicationRequest'
            example:
              title: 独立博客
              imgurl: https://blog.example.org/avatar.png
              desc: 记录技术与生活。
              siteurl: https://blog.example.org/
              tags: [technology, lifestyle]
      responses:
        '201':
          description: 已保存并进入待审核队列。
          content:
            application/json:
              schema:
                type: object
                required: [id, status]
                properties:
                  id:
                    $ref: '#/components/schemas/Id'
                  status:
                    const: PENDING
        '400':
          $ref: '#/components/responses/BadRequest'
        '409':
          description: 该站点已有待审核申请或已登记。
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '429':
          description: 启用 AI 审核且已达到本分钟的申请接收上限。
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
components:
  responses:
    BadRequest:
      description: 请求格式或字段不符合要求。
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
  schemas:
    Id:
      type: integer
      format: int64
      minimum: 1
    CategoryCode:
      type: string
      maxLength: 48
      pattern: '^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$'
    Category:
      type: object
      required: [code, name]
      properties:
        code:
          $ref: '#/components/schemas/CategoryCode'
        name:
          type: string
    FFLink:
      $ref: '../schema/fflink.schema.json'
    ApplicationRequest:
      type: object
      required: [title, imgurl, desc, siteurl]
      additionalProperties: false
      properties:
        title:
          $ref: '../schema/fflink.schema.json#/properties/title'
        imgurl:
          $ref: '../schema/fflink.schema.json#/properties/imgurl'
        desc:
          $ref: '../schema/fflink.schema.json#/properties/desc'
        siteurl:
          $ref: '../schema/fflink.schema.json#/properties/siteurl'
        tags:
          $ref: '../schema/fflink.schema.json#/properties/tags'
        email:
          description: 选填，仅保存于申请记录。提交时会裁去首尾空白，空白值视为未填写。
          anyOf:
            - type: string
              format: email
              maxLength: 254
            - type: string
              pattern: '^\s*$'
            - type: 'null'
    Problem:
      type: object
      required: [status, detail]
      properties:
        type:
          type: string
        title:
          type: string
        status:
          type: integer
        detail:
          type: string
        instance:
          type: string
