88API88API
使用指南AI 應用API 文件幫助支援
介面模組使用指南

使用者模組

功能說明

介面字首統一為 http(s)://<your-domain>

生產環境應使用 HTTPS 以保證認證令牌。 HTTP 僅建議用於開發環境。

核心使用者管理系統,實現四級許可權體系(公開/使用者/管理員/Root)和完整的使用者生命週期管理 。包含註冊登入、個人資料、Token 管理、充值支付、推廣系統等功能。支援 2FA、郵箱驗證和多種 OAuth 登入方式。

賬號註冊/登入

🔐 無需鑑權

註冊新賬號

  • 介面名稱:註冊新賬號
  • HTTP 方法:POST
  • 路徑/api/user/register
  • 鑑權要求:公開
  • 功能簡介:建立新使用者賬戶,支援郵箱驗證和推薦碼功能

💡 請求示例:

const response = await fetch('/api/user/register', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    username: "newuser",
    password: "password123",
    email: "user@example.com",
    verification_code: "123456",
    aff_code: "INVITE123"
  })
});
const data = await response.json();

✅ 成功響應示例:

{
  "success": true,
  "message": "使用者註冊成功"
}

❗ 失敗響應示例:

{
  "success": false,
  "message": "管理員關閉了新使用者註冊"
}

🧾 欄位說明:

  • username (字串): 使用者名稱,必填
  • password (字串): 密碼,必填
  • email (字串): 郵箱地址,當啟用郵箱驗證時必填
  • verification_code (字串): 郵箱驗證碼,當啟用郵箱驗證時必填
  • aff_code (字串): 推薦碼,可選

使用者登入

  • 介面名稱:使用者登入
  • HTTP 方法:POST
  • 路徑/api/user/login
  • 鑑權要求:公開
  • 功能簡介:使用者賬戶登入,支援兩步驗證(2FA)

💡 請求示例:

const response = await fetch('/api/user/login', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    username: "testuser",
    password: "password123"
  })
});
const data = await response.json();

✅ 成功響應示例(無 2FA):

{
  "success": true,
  "message": "登入成功",
  "data": {
    "token": "user_access_token",
    "user": {
      "id": 1,
      "username": "testuser",
      "role": 1,
      "quota": 1000000
    }
  }
}

✅ 成功響應示例(需要 2FA):

{
  "success": true,
  "message": "請輸入兩步驗證碼",
  "data": {
    "require_2fa": true
  }
}

❗ 失敗響應示例:

{
  "success": false,
  "message": "管理員關閉了密碼登入"
}

🧾 欄位說明:

  • username (字串): 使用者名稱,必填
  • password (字串): 密碼,必填
  • require_2fa (布林型): 是否需要兩步驗證

Epay 支付回撥

  • 介面名稱:Epay 支付回撥
  • HTTP 方法:GET
  • 路徑/api/user/epay/notify
  • 鑑權要求:公開
  • 功能簡介:處理易支付系統的支付回撥通知

💡 請求示例:

_// 通常由支付系統自動回撥,前端無需主動呼叫  _
_// 示例URL: /api/user/epay/notify?trade_no=USR1NO123456&money=10.00&trade_status=TRADE_SUCCESS_

✅ 成功響應示例:

{
  "success": true,
  "message": "支付成功"
}

❗ 失敗響應示例:

{
  "success": false,
  "message": "訂單不存在或已處理"
}

🧾 欄位說明:

  • trade_no (字串): 交易訂單號
  • money (字串): 支付金額
  • trade_status (字串): 交易狀態
  • sign (字串): 簽名驗證

列出所有分組(無鑑權版)

  • 介面名稱:列出所有分組
  • HTTP 方法:GET
  • 路徑/api/user/groups
  • 鑑權要求:公開
  • 功能簡介:獲取系統中所有使用者分組資訊,無需登入即可訪問

💡 請求示例:

const response = await fetch('/api/user/groups', {
  method: 'GET',
  headers: {
    'Content-Type': 'application/json'
  }
});
const data = await response.json();

✅ 成功響應示例:

{
  "success": true,
  "message": "",
  "data": {
    "default": {
      "ratio": 1.0,
      "desc": "預設分組"
    },
    "vip": {
      "ratio": 0.8,
      "desc": "VIP分組"
    },
    "auto": {
      "ratio": "自動",
      "desc": "自動選擇最優分組"
    }
  }
}

❗ 失敗響應示例:

{
  "success": false,
  "message": "獲取分組資訊失敗"
}

🧾 欄位說明:

data (物件): 分組資訊對映

  • 鍵 (字串): 分組名稱
  • ratio (數字/字串): 分組倍率,"自動"表示自動選擇
  • desc (字串): 分組描述

🔐 使用者鑑權

退出登入

  • 介面名稱:退出登入
  • HTTP 方法:GET
  • 路徑/api/user/logout
  • 鑑權要求:使用者
  • 功能簡介:清除使用者會話,退出登入狀態

💡 請求示例:

const response = await fetch('/api/user/logout', {
  method: 'GET',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'your_user_id'
  }
});
const data = await response.json();

✅ 成功響應示例:

{
  "success": true,
  "message": ""
}

❗ 失敗響應示例:

{
  "success": false,
  "message": "會話清除失敗"
}

🧾 欄位說明:

無請求引數

使用者自身操作

🔐 使用者鑑權

獲取自己所在分組

  • 介面名稱:獲取自己所在分組
  • HTTP 方法:GET
  • 路徑/api/user/self/groups
  • 鑑權要求:使用者
  • 功能簡介:獲取當前登入使用者可使用的分組資訊,包含分組倍率和描述

💡 請求示例:

const response = await fetch('/api/user/self/groups', {
  method: 'GET',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'your_user_id'
  }
});
const data = await response.json();

✅ 成功響應示例:

{
  "success": true,
  "message": "",
  "data": {
    "default": {
      "ratio": 1.0,
      "desc": "預設分組"
    },
    "vip": {
      "ratio": 0.8,
      "desc": "VIP分組"
    },
    "auto": {
      "ratio": "自動",
      "desc": "自動選擇最優分組"
    }
  }
}

❗ 失敗響應示例:

{
  "success": false,
  "message": "獲取分組資訊失敗"
}

🧾 欄位說明:

data (物件): 使用者可用分組資訊對映 group.go:25-48

  • 鍵 (字串): 分組名稱
  • ratio (數字/字串): 分組倍率,"自動"表示自動選擇最優分組
  • desc (字串): 分組描述

獲取個人資料

  • 介面名稱:獲取個人資料
  • HTTP 方法:GET
  • 路徑/api/user/self
  • 鑑權要求:使用者
  • 功能簡介:獲取當前使用者的詳細資訊,包含許可權、配額、設定等

💡 請求示例:

const response = await fetch('/api/user/self', {
  method: 'GET',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'your_user_id'
  }
});
const data = await response.json();

✅ 成功響應示例:

{
  "success": true,
  "message": "",
  "data": {
    "id": 1,
    "username": "testuser",
    "display_name": "Test User",
    "role": 1,
    "status": 1,
    "email": "user@example.com",
    "group": "default",
    "quota": 1000000,
    "used_quota": 50000,
    "request_count": 100,
    "aff_code": "ABC123",
    "aff_count": 5,
    "aff_quota": 10000,
    "aff_history_quota": 50000,
    "inviter_id": 0,
    "linux_do_id": "",
    "setting": "{}",
    "stripe_customer": "",
    "sidebar_modules": "{\"chat\":{\"enabled\":true}}",
    "permissions": {
      "can_view_logs": true,
      "can_manage_tokens": true
    }
  }
}

❗ 失敗響應示例:

{
  "success": false,
  "message": "獲取使用者資訊失敗"
}

🧾 欄位說明:

  • id (數字): 使用者 ID
  • username (字串): 使用者名稱
  • display_name (字串): 顯示名稱
  • role (數字): 使用者角色,1=普通使用者,10=管理員,100=Root 使用者
  • status (數字): 使用者狀態,1=正常,2=禁用
  • email (字串): 郵箱地址
  • group (字串): 所屬分組
  • quota (數字): 總配額
  • used_quota (數字): 已使用配額
  • request_count (數字): 請求次數
  • aff_code (字串): 推薦碼
  • aff_count (數字): 推薦人數
  • aff_quota (數字): 推薦獎勵配額
  • aff_history_quota (數字): 歷史推薦配額
  • inviter_id (數字): 邀請人 ID
  • linux_do_id (字串): LinuxDo 賬戶 ID
  • setting (字串): 使用者設定 JSON 字串
  • stripe_customer (字串): Stripe 客戶 ID
  • sidebar_modules (字串): 側邊欄模組配置 JSON 字串
  • permissions (物件): 使用者許可權資訊

獲取模型可見性

  • 介面名稱:獲取模型可見性
  • HTTP 方法:GET
  • 路徑/api/user/models
  • 鑑權要求:使用者
  • 功能簡介:獲取當前使用者可訪問的 AI 模型列表

💡 請求示例:

const response = await fetch('/api/user/models', {
  method: 'GET',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'your_user_id'
  }
});
const data = await response.json();

✅ 成功響應示例:

{
  "success": true,
  "message": "",
  "data": [
    "gpt-3.5-turbo",
    "gpt-4",
    "claude-3-sonnet",
    "claude-3-haiku"
  ]
}

❗ 失敗響應示例:

{
  "success": false,
  "message": "獲取模型列表失敗"
}

🧾 欄位說明:

data (陣列): 使用者可訪問的模型名稱列表

修改個人資料

  • 介面名稱:修改個人資料
  • HTTP 方法:PUT
  • 路徑/api/user/self
  • 鑑權要求:使用者
  • 功能簡介:更新使用者個人資訊或側邊欄設定

💡 請求示例(更新個人資訊):

const response = await fetch('/api/user/self', {
  method: 'PUT',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'your_user_id'
  },
  body: JSON.stringify({
    display_name: "New Display Name",
    email: "newemail@example.com"
  })
});
const data = await response.json();

💡 請求示例(更新側邊欄設定):

const response = await fetch('/api/user/self', {
  method: 'PUT',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'your_user_id'
  },
  body: JSON.stringify({
    sidebar_modules: JSON.stringify({
      chat: { enabled: true, playground: true },
      console: { enabled: true, token: true }
    })
  })
});
const data = await response.json();

✅ 成功響應示例:

{
  "success": true,
  "message": "更新成功"
}

❗ 失敗響應示例:

{
  "success": false,
  "message": "輸入不合法"
}

🧾 欄位說明:

  • display_name (字串): 顯示名稱,可選
  • email (字串): 郵箱地址,可選
  • password (字串): 新密碼,可選
  • sidebar_modules (字串): 側邊欄模組配置 JSON 字串,可選

登出賬號

  • 介面名稱:登出賬號
  • HTTP 方法:DELETE
  • 路徑/api/user/self
  • 鑑權要求:使用者
  • 功能簡介:刪除當前使用者賬戶,Root 使用者不可刪除

💡 請求示例:

const response = await fetch('/api/user/self', {
  method: 'DELETE',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'your_user_id'
  }
});
const data = await response.json();

✅ 成功響應示例:

{
  "success": true,
  "message": ""
}

❗ 失敗響應示例:

{
  "success": false,
  "message": "不能刪除超級管理員賬戶"
}

🧾 欄位說明:

無請求引數

生成使用者級別 Access Token

  • 介面名稱:生成使用者級別 Access Token
  • HTTP 方法:GET
  • 路徑/api/user/token
  • 鑑權要求:使用者
  • 功能簡介:為當前使用者生成新的訪問令牌,用於 API 呼叫

💡 請求示例:

const response = await fetch('/api/user/token', {
  method: 'GET',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'your_user_id'
  }
});
const data = await response.json();

✅ 成功響應示例:

{
  "success": true,
  "message": "",
  "data": "`<YOUR_API_KEY>`"
}

❗ 失敗響應示例:

{
  "success": false,
  "message": "生成令牌失敗"
}

🧾 欄位說明:

data (字串): 生成的訪問令牌

獲取推廣碼資訊

  • 介面名稱:獲取推廣碼資訊
  • HTTP 方法:GET
  • 路徑/api/user/aff
  • 鑑權要求:使用者
  • 功能簡介:獲取或生成使用者的推廣碼,用於邀請新使用者註冊

💡 請求示例:

const response = await fetch('/api/user/aff', {
  method: 'GET',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'your_user_id'
  }
});
const data = await response.json();

✅ 成功響應示例:

{
  "success": true,
  "message": "",
  "data": "ABC123"
}

❗ 失敗響應示例:

{
  "success": false,
  "message": "獲取推廣碼失敗"
}

🧾 欄位說明:

data (字串): 使用者的推廣碼,如果不存在會自動生成 4 位隨機字串

餘額直充

  • 介面名稱:餘額直充
  • HTTP 方法:POST
  • 路徑/api/user/topup
  • 鑑權要求:使用者
  • 功能簡介:使用兌換碼為賬戶充值配額

💡 請求示例:

const response = await fetch('/api/user/topup', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'your_user_id'
  },
  body: JSON.stringify({
    key: "REDEEM123456"
  })
});
const data = await response.json();

✅ 成功響應示例:

{
  "success": true,
  "message": "兌換成功",
  "data": 100000
}

❗ 失敗響應示例:

{
  "success": false,
  "message": "兌換碼無效或已使用"
}

🧾 欄位說明:

  • key (字串): 兌換碼,必填
  • data (數字): 成功時返回兌換的配額數量

提交支付訂單

  • 介面名稱:提交支付訂單
  • HTTP 方法:POST
  • 路徑/api/user/pay
  • 鑑權要求:使用者
  • 功能簡介:建立線上支付訂單,支援多種支付方式

💡 請求示例:

const response = await fetch('/api/user/pay', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'your_user_id'
  },
  body: JSON.stringify({
    amount: 10000,
    payment_method: "alipay",
    top_up_code: ""
  })
});
const data = await response.json();

✅ 成功響應示例:

{
  "success": true,
  "message": "success",
  "data": {
    "pid": "12345",
    "type": "alipay",
    "out_trade_no": "USR1NO123456",
    "notify_url": "https://example.com/notify",
    "return_url": "https://example.com/return",
    "name": "TUC10000",
    "money": "10.00",
    "sign": "abc123def456"
  },
  "url": "https://pay.example.com/submit"
}

❗ 失敗響應示例:

{
  "success": false,
  "message": "充值數量不能小於 1000"
}

🧾 欄位說明:

  • amount (數字): 充值數量,必須大於等於最小充值額度 topup.go:133-136
  • payment_method (字串): 支付方式,如"alipay"、"wxpay"等
  • top_up_code (字串): 充值碼,可選
  • data (物件): 支付表單引數
  • url (字串): 支付提交地址

餘額支付

  • 介面名稱:餘額支付
  • HTTP 方法:POST
  • 路徑/api/user/amount
  • 鑑權要求:使用者
  • 功能簡介:計算指定充值數量對應的實際支付金額

💡 請求示例:

const response = await fetch('/api/user/amount', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'your_user_id'
  },
  body: JSON.stringify({
    amount: 10000,
    top_up_code: ""
  })
});
const data = await response.json();

✅ 成功響應示例:

{
  "success": true,
  "message": "success",
  "data": "10.00"
}

❗ 失敗響應示例:

{
  "success": false,
  "message": "充值數量不能小於 1000"
}

🧾 欄位說明:

  • amount (數字): 充值數量,必須大於等於最小充值額度
  • top_up_code (字串): 充值碼,可選
  • data (字串): 實際需要支付的金額(元)

推廣額度轉賬

  • 介面名稱:推廣額度轉賬
  • HTTP 方法:POST
  • 路徑/api/user/aff_transfer
  • 鑑權要求:使用者
  • 功能簡介:將推廣獎勵額度轉換為可用配額

💡 請求示例:

const response = await fetch('/api/user/aff_transfer', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'your_user_id'
  },
  body: JSON.stringify({
    quota: 50000
  })
});
const data = await response.json();

✅ 成功響應示例:

{
  "success": true,
  "message": "劃轉成功"
}

❗ 失敗響應示例:

{
  "success": false,
  "message": "邀請額度不足!"
}

🧾 欄位說明:

quota (數字): 要轉換的額度數量,必須大於等於最小單位額度

更新使用者設定

  • 介面名稱:更新使用者設定
  • HTTP 方法:PUT
  • 路徑/api/user/setting
  • 鑑權要求:使用者
  • 功能簡介:更新使用者的個人設定配置

💡 請求示例:

const response = await fetch('/api/user/setting', {
  method: 'PUT',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your_user_token',
    'New-Api-User': 'your_user_id'
  },
  body: JSON.stringify({
    theme: "dark",
    language: "zh-CN",
    notifications: {
      email: true,
      browser: false
    }
  })
});
const data = await response.json();

✅ 成功響應示例:

{
  "success": true,
  "message": "設定更新成功"
}

❗ 失敗響應示例:

{
  "success": false,
  "message": "設定格式錯誤"
}

🧾 欄位說明:

  • 請求體可包含任意使用者設定欄位,以 JSON 格式提交
  • 具體欄位根據前端設定頁面的需求而定

管理員使用者管理

🔐 管理員鑑權

獲取全部使用者列表

  • 介面名稱:獲取全部使用者列表
  • HTTP 方法:GET
  • 路徑/api/user/
  • 鑑權要求:管理員
  • 功能簡介:分頁獲取系統中所有使用者的列表資訊

💡 請求示例:

const response = await fetch('/api/user/?p=1&page_size=20', {
  method: 'GET',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your_admin_token',
    'New-Api-User': 'your_user_id'
  }
});
const data = await response.json();

✅ 成功響應示例:

{
  "success": true,
  "message": "",
  "data": {
    "items": [
      {
        "id": 1,
        "username": "testuser",
        "display_name": "Test User",
        "role": 1,
        "status": 1,
        "email": "user@example.com",
        "group": "default",
        "quota": 1000000,
        "used_quota": 50000,
        "request_count": 100
      }
    ],
    "total": 50,
    "page": 1,
    "page_size": 20
  }
}

❗ 失敗響應示例:

{
  "success": false,
  "message": "獲取使用者列表失敗"
}

🧾 欄位說明:

  • p (數字): 頁碼,預設為 1
  • page_size (數字): 每頁數量,預設為 20
  • items (陣列): 使用者資訊列表
  • total (數字): 使用者總數
  • page (數字): 當前頁碼
  • page_size (數字): 每頁數量

搜尋使用者

  • 介面名稱:搜尋使用者
  • HTTP 方法:GET
  • 路徑/api/user/search
  • 鑑權要求:管理員
  • 功能簡介:根據關鍵詞和分組搜尋使用者

💡 請求示例:

const response = await fetch('/api/user/search?keyword=test&group=default&p=1&page_size=20', {
  method: 'GET',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your_admin_token',
    'New-Api-User': 'your_user_id'
  }
});
const data = await response.json();

✅ 成功響應示例:

{
  "success": true,
  "message": "",
  "data": {
    "items": [
      {
        "id": 1,
        "username": "testuser",
        "display_name": "Test User",
        "role": 1,
        "status": 1,
        "email": "test@example.com",
        "group": "default"
      }
    ],
    "total": 1,
    "page": 1,
    "page_size": 20
  }
}

❗ 失敗響應示例:

{
  "success": false,
  "message": "搜尋使用者失敗"
}

🧾 欄位說明:

  • keyword (字串): 搜尋關鍵詞,可匹配使用者名稱、顯示名、郵箱
  • group (字串): 使用者分組過濾條件
  • p (數字): 頁碼,預設為 1
  • page_size (數字): 每頁數量,預設為 20

獲取單個使用者資訊

  • 介面名稱:獲取單個使用者資訊
  • HTTP 方法:GET
  • 路徑/api/user/:id
  • 鑑權要求:管理員
  • 功能簡介:獲取指定使用者的詳細資訊,包含許可權檢查

💡 請求示例:

const response = await fetch('/api/user/123', {
  method: 'GET',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your_admin_token',
    'New-Api-User': 'your_user_id'
  }
});
const data = await response.json();

✅ 成功響應示例:

{
  "success": true,
  "message": "",
  "data": {
    "id": 123,
    "username": "targetuser",
    "display_name": "Target User",
    "role": 1,
    "status": 1,
    "email": "target@example.com",
    "group": "default",
    "quota": 1000000,
    "used_quota": 50000,
    "request_count": 100,
    "aff_code": "ABC123",
    "aff_count": 5
  }
}

❗ 失敗響應示例:

{
  "success": false,
  "message": "無權獲取同級或更高等級使用者的資訊"
}

🧾 欄位說明:

  • id (數字): 使用者 ID,透過 URL 路徑傳遞
  • 返回完整的使用者資訊,但管理員無法檢視同級或更高許可權使用者的資訊

建立使用者

  • 介面名稱:建立使用者
  • HTTP 方法:POST
  • 路徑/api/user/
  • 鑑權要求:管理員
  • 功能簡介:建立新使用者賬戶,管理員不能建立許可權大於等於自己的使用者

💡 請求示例:

const response = await fetch('/api/user/', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your_admin_token',
    'New-Api-User': 'your_user_id'
  },
  body: JSON.stringify({
    username: "newuser",
    password: "password123",
    display_name: "New User",
    role: 1
  })
});
const data = await response.json();

✅ 成功響應示例:

{
  "success": true,
  "message": ""
}

❗ 失敗響應示例:

{
  "success": false,
  "message": "無法建立許可權大於等於自己的使用者"
}

🧾 欄位說明:

  • username (字串): 使用者名稱,必填
  • password (字串): 密碼,必填
  • display_name (字串): 顯示名稱,可選,預設為使用者名稱
  • role (數字): 使用者角色,必須小於當前管理員角色

凍結/重置等管理操作

  • 介面名稱:凍結/重置等管理操作
  • HTTP 方法:POST
  • 路徑/api/user/manage
  • 鑑權要求:管理員
  • 功能簡介:對使用者執行管理操作,包括啟用、禁用、刪除、提升、降級等

💡 請求示例:

const response = await fetch('/api/user/manage', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your_admin_token',
    'New-Api-User': 'your_user_id'
  },
  body: JSON.stringify({
    id: 123,
    action: "disable"
  })
});
const data = await response.json();

✅ 成功響應示例:

{
  "success": true,
  "message": ""
}

❗ 失敗響應示例:

{
  "success": false,
  "message": "無法禁用超級管理員使用者"
}

🧾 欄位說明:

  • id (數字): 目標使用者 ID,必填
  • action (字串): 操作型別,必填,可選值:
    • disable: 禁用使用者
    • enable: 啟用使用者
    • delete: 刪除使用者
    • promote: 提升為管理員(僅 Root 使用者可操作)
    • demote: 降級為普通使用者

更新使用者

  • 介面名稱:更新使用者
  • HTTP 方法:PUT
  • 路徑/api/user/
  • 鑑權要求:管理員
  • 功能簡介:更新使用者資訊,包含許可權檢查和配額變更記錄

💡 請求示例:

const response = await fetch('/api/user/', {
  method: 'PUT',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your_admin_token',
    'New-Api-User': 'your_user_id'
  },
  body: JSON.stringify({
    id: 123,
    username: "updateduser",
    display_name: "Updated User",
    email: "updated@example.com",
    quota: 2000000,
    role: 1,
    status: 1
  })
});
const data = await response.json();

✅ 成功響應示例:

{
  "success": true,
  "message": ""
}

❗ 失敗響應示例:

{
  "success": false,
  "message": "無權更新同許可權等級或更高許可權等級的使用者資訊"
}

🧾 欄位說明:

  • id (數字): 使用者 ID,必填
  • username (字串): 使用者名稱,可選
  • display_name (字串): 顯示名稱,可選
  • email (字串): 郵箱地址,可選
  • password (字串): 新密碼,可選,為空則不更新密碼
  • quota (數字): 使用者配額,可選
  • role (數字): 使用者角色,不能大於等於當前管理員角色
  • status (數字): 使用者狀態,可選

刪除使用者

  • 介面名稱:刪除使用者
  • HTTP 方法:DELETE
  • 路徑/api/user/:id
  • 鑑權要求:管理員
  • 功能簡介:硬刪除指定使用者,管理員不能刪除同級或更高許可權使用者

💡 請求示例:

const response = await fetch('/api/user/123', {
  method: 'DELETE',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your_admin_token',
    'New-Api-User': 'your_user_id'
  }
});
const data = await response.json();

✅ 成功響應示例:

{
  "success": true,
  "message": ""
}

❗ 失敗響應示例:

{
  "success": false,
  "message": "無權刪除同許可權等級或更高許可權等級的使用者"
}

🧾 欄位說明:

  • id (數字): 使用者 ID,透過 URL 路徑傳遞
  • 執行硬刪除操作,不可恢復