mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-10-30 13:23:42 +08:00
Compare commits
8 Commits
v0.1.3
...
v0.1.4-alp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e7a809b082 | ||
|
|
4f8cbd643d | ||
|
|
1dd92a3f92 | ||
|
|
34a3329f5f | ||
|
|
4fb07b6d6d | ||
|
|
8be7c9ae80 | ||
|
|
4e8dc8d0cf | ||
|
|
1e46b9d135 |
29
.github/workflows/github-pages.yml
vendored
29
.github/workflows/github-pages.yml
vendored
@@ -1,29 +0,0 @@
|
||||
name: Build GitHub Pages
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
name:
|
||||
description: 'Reason'
|
||||
required: false
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout 🛎️
|
||||
uses: actions/checkout@v2 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly.
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Install and Build 🔧 # This example project is built using npm and outputs the result to the 'build' folder. Replace with the commands required to build your project, or remove this step entirely if your site is pre-built.
|
||||
env:
|
||||
CI: ""
|
||||
run: |
|
||||
cd web
|
||||
npm install
|
||||
npm run build
|
||||
|
||||
- name: Deploy 🚀
|
||||
uses: JamesIves/github-pages-deploy-action@releases/v3
|
||||
with:
|
||||
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
|
||||
BRANCH: gh-pages # The branch the action should deploy to.
|
||||
FOLDER: web/build # The folder the action should deploy.
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -3,4 +3,5 @@
|
||||
upload
|
||||
*.exe
|
||||
*.db
|
||||
build
|
||||
build
|
||||
*.db-journal
|
||||
@@ -24,7 +24,7 @@ RUN apk update \
|
||||
&& apk upgrade \
|
||||
&& apk add --no-cache ca-certificates tzdata \
|
||||
&& update-ca-certificates 2>/dev/null || true
|
||||
ENV PORT=3000
|
||||
|
||||
COPY --from=builder2 /build/one-api /
|
||||
EXPOSE 3000
|
||||
WORKDIR /data
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 JustSong
|
||||
Copyright (c) 2023 JustSong
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -87,7 +87,7 @@ server{
|
||||
}
|
||||
```
|
||||
|
||||
注意,为了 SSE 正常工作,需要关闭 Nginx 的代理缓存和缓冲。
|
||||
注意,为了 SSE 正常工作,需要关闭 Nginx 的代理缓冲。
|
||||
|
||||
之后使用 Let's Encrypt 的 certbot 配置 HTTPS:
|
||||
```bash
|
||||
@@ -138,6 +138,7 @@ sudo service nginx restart
|
||||
之后就可以使用你的令牌访问 One API 了,使用方式与 [OpenAI API](https://platform.openai.com/docs/api-reference/introduction) 一致。
|
||||
|
||||
可以通过在令牌后面添加渠道 ID 的方式指定使用哪一个渠道处理本次请求,例如:`Authorization: Bearer ONE_API_KEY-CHANNEL_ID`。
|
||||
注意,需要是管理员用户创建的令牌才能指定渠道 ID。
|
||||
|
||||
不加的话将会使用负载均衡的方式使用多个渠道。
|
||||
|
||||
|
||||
@@ -83,7 +83,18 @@ func TokenAuth() func(c *gin.Context) {
|
||||
c.Set("token_id", token.Id)
|
||||
c.Set("unlimited_times", token.UnlimitedTimes)
|
||||
if len(parts) > 1 {
|
||||
c.Set("channelId", parts[1])
|
||||
if model.IsAdmin(token.UserId) {
|
||||
c.Set("channelId", parts[1])
|
||||
} else {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"error": gin.H{
|
||||
"message": "普通用户不支持指定渠道",
|
||||
"type": "one_api_error",
|
||||
},
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
}
|
||||
c.Next()
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ import (
|
||||
|
||||
func CORS() gin.HandlerFunc {
|
||||
config := cors.DefaultConfig()
|
||||
config.AllowOrigins = []string{"https://one-api.vercel.app", "http://localhost:3000/"}
|
||||
config.AllowAllOrigins = true
|
||||
config.AllowCredentials = true
|
||||
config.AllowMethods = []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}
|
||||
config.AllowHeaders = []string{"Origin", "Content-Length", "Content-Type", "Authorization", "Accept", "Connection"}
|
||||
return cors.New(config)
|
||||
}
|
||||
|
||||
@@ -175,3 +175,16 @@ func ResetUserPasswordByEmail(email string, password string) error {
|
||||
err = DB.Model(&User{}).Where("email = ?", email).Update("password", hashedPassword).Error
|
||||
return err
|
||||
}
|
||||
|
||||
func IsAdmin(userId int) bool {
|
||||
if userId == 0 {
|
||||
return false
|
||||
}
|
||||
var user User
|
||||
err := DB.Where("id = ?", userId).Select("role").Find(&user).Error
|
||||
if err != nil {
|
||||
common.SysError("No such user " + err.Error())
|
||||
return false
|
||||
}
|
||||
return user.Role >= common.RoleAdminUser
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user