Upload 63 files
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +6 -0
- .github/ISSUE_TEMPLATE/bug_report.md +26 -0
- .github/ISSUE_TEMPLATE/config.yml +5 -0
- .github/ISSUE_TEMPLATE/feature_request.md +21 -0
- .github/close_issue.py +105 -0
- .github/workflows/CloseIssue.yml +24 -0
- .github/workflows/docker-image-amd64.yml +55 -0
- .github/workflows/docker-image-arm64.yml +63 -0
- .github/workflows/github-pages.yml +29 -0
- .github/workflows/linux-release.yml +46 -0
- .github/workflows/macos-release.yml +37 -0
- .github/workflows/windows-release.yml +40 -0
- .gitignore +6 -0
- Dockerfile +47 -0
- LICENSE +674 -0
- README.md +343 -5
- check/check.go +68 -0
- common/config/config.go +422 -0
- common/constants.go +66 -0
- common/env/helper.go +42 -0
- common/helper/helper.go +139 -0
- common/helper/key.go +5 -0
- common/helper/time.go +15 -0
- common/init.go +57 -0
- common/loggger/constants.go +3 -0
- common/loggger/logger.go +103 -0
- common/random/main.go +61 -0
- common/rate-limit.go +70 -0
- common/token.go +193 -0
- common/utils.go +243 -0
- controller/admin.go +417 -0
- controller/api.go +14 -0
- controller/auth.go +162 -0
- controller/chat.go +1827 -0
- controller/video.go +514 -0
- data/.env +18 -0
- data/models_list.json +134 -0
- docker-compose.yml +16 -0
- docs/img.png +3 -0
- docs/img2.png +3 -0
- docs/img3.png +0 -0
- docs/img4.png +3 -0
- docs/img5.png +3 -0
- docs/img6.png +3 -0
- docs/img7.png +3 -0
- go.mod +53 -0
- go.sum +476 -0
- job/cookie.go +35 -0
- main.go +62 -0
- middleware/auth.go +63 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,9 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
docs/img.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
docs/img2.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
docs/img4.png filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
docs/img5.png filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
docs/img6.png filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
docs/img7.png filter=lfs diff=lfs merge=lfs -text
|
.github/ISSUE_TEMPLATE/bug_report.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
name: 报告问题
|
| 3 |
+
about: 使用简练详细的语言描述你遇到的问题
|
| 4 |
+
title: ''
|
| 5 |
+
labels: bug
|
| 6 |
+
assignees: ''
|
| 7 |
+
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
**温馨提示: 未`star`项目会被自动关闭issue哦!**
|
| 11 |
+
|
| 12 |
+
**例行检查**
|
| 13 |
+
|
| 14 |
+
+ [ ] 我已确认目前没有类似 issue
|
| 15 |
+
+ [ ] 我已确认我已升级到最新版本
|
| 16 |
+
+ [ ] 我理解并愿意跟进此 issue,协助测试和提供反馈
|
| 17 |
+
+ [ ] 我理解并认可上述内容,并理解项目维护者精力有限,不遵循规则的 issue 可能会被无视或直接关闭
|
| 18 |
+
|
| 19 |
+
**问题描述**
|
| 20 |
+
|
| 21 |
+
**复现步骤**
|
| 22 |
+
|
| 23 |
+
**预期结果**
|
| 24 |
+
|
| 25 |
+
**相关截图**
|
| 26 |
+
如果没有的话,请删除此节。
|
.github/ISSUE_TEMPLATE/config.yml
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
blank_issues_enabled: false
|
| 2 |
+
contact_links:
|
| 3 |
+
- name: 赞赏支持
|
| 4 |
+
# url:
|
| 5 |
+
about: 请作者喝杯咖啡,以激励作者持续开发
|
.github/ISSUE_TEMPLATE/feature_request.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
name: 功能请求
|
| 3 |
+
about: 使用简练详细的语言描述希望加入的新功能
|
| 4 |
+
title: ''
|
| 5 |
+
labels: enhancement
|
| 6 |
+
assignees: ''
|
| 7 |
+
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
**温馨提示: 未`star`项目会被自动关闭issue哦!**
|
| 11 |
+
|
| 12 |
+
**例行检查**
|
| 13 |
+
|
| 14 |
+
+ [ ] 我已确认目前没有类似 issue
|
| 15 |
+
+ [ ] 我已确认我已升级到最新版本
|
| 16 |
+
+ [ ] 我理解并愿意跟进此 issue,协助测试和提供反馈
|
| 17 |
+
+ [ ] 我理解并认可上述内容,并理解项目维护者精力有限,不遵循规则的 issue 可能会被无视或直接关闭
|
| 18 |
+
|
| 19 |
+
**功能描述**
|
| 20 |
+
|
| 21 |
+
**应用场景**
|
.github/close_issue.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
issue_labels = ['no respect']
|
| 5 |
+
github_repo = 'deanxv/genspark2api'
|
| 6 |
+
github_token = os.getenv("GITHUB_TOKEN")
|
| 7 |
+
headers = {
|
| 8 |
+
'Authorization': 'Bearer ' + github_token,
|
| 9 |
+
'Accept': 'application/vnd.github+json',
|
| 10 |
+
'X-GitHub-Api-Version': '2022-11-28',
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def get_stargazers(repo):
|
| 15 |
+
page = 1
|
| 16 |
+
_stargazers = {}
|
| 17 |
+
while True:
|
| 18 |
+
queries = {
|
| 19 |
+
'per_page': 100,
|
| 20 |
+
'page': page,
|
| 21 |
+
}
|
| 22 |
+
url = 'https://api.github.com/repos/{}/stargazers?'.format(repo)
|
| 23 |
+
|
| 24 |
+
resp = requests.get(url, headers=headers, params=queries)
|
| 25 |
+
if resp.status_code != 200:
|
| 26 |
+
raise Exception('Error get stargazers: ' + resp.text)
|
| 27 |
+
|
| 28 |
+
data = resp.json()
|
| 29 |
+
if not data:
|
| 30 |
+
break
|
| 31 |
+
|
| 32 |
+
for stargazer in data:
|
| 33 |
+
_stargazers[stargazer['login']] = True
|
| 34 |
+
page += 1
|
| 35 |
+
|
| 36 |
+
print('list stargazers done, total: ' + str(len(_stargazers)))
|
| 37 |
+
return _stargazers
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def get_issues(repo):
|
| 41 |
+
page = 1
|
| 42 |
+
_issues = []
|
| 43 |
+
while True:
|
| 44 |
+
queries = {
|
| 45 |
+
'state': 'open',
|
| 46 |
+
'sort': 'created',
|
| 47 |
+
'direction': 'desc',
|
| 48 |
+
'per_page': 100,
|
| 49 |
+
'page': page,
|
| 50 |
+
}
|
| 51 |
+
url = 'https://api.github.com/repos/{}/issues?'.format(repo)
|
| 52 |
+
|
| 53 |
+
resp = requests.get(url, headers=headers, params=queries)
|
| 54 |
+
if resp.status_code != 200:
|
| 55 |
+
raise Exception('Error get issues: ' + resp.text)
|
| 56 |
+
|
| 57 |
+
data = resp.json()
|
| 58 |
+
if not data:
|
| 59 |
+
break
|
| 60 |
+
|
| 61 |
+
_issues += data
|
| 62 |
+
page += 1
|
| 63 |
+
|
| 64 |
+
print('list issues done, total: ' + str(len(_issues)))
|
| 65 |
+
return _issues
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def close_issue(repo, issue_number):
|
| 69 |
+
url = 'https://api.github.com/repos/{}/issues/{}'.format(repo, issue_number)
|
| 70 |
+
data = {
|
| 71 |
+
'state': 'closed',
|
| 72 |
+
'state_reason': 'not_planned',
|
| 73 |
+
'labels': issue_labels,
|
| 74 |
+
}
|
| 75 |
+
resp = requests.patch(url, headers=headers, json=data)
|
| 76 |
+
if resp.status_code != 200:
|
| 77 |
+
raise Exception('Error close issue: ' + resp.text)
|
| 78 |
+
|
| 79 |
+
print('issue: {} closed'.format(issue_number))
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def lock_issue(repo, issue_number):
|
| 83 |
+
url = 'https://api.github.com/repos/{}/issues/{}/lock'.format(repo, issue_number)
|
| 84 |
+
data = {
|
| 85 |
+
'lock_reason': 'spam',
|
| 86 |
+
}
|
| 87 |
+
resp = requests.put(url, headers=headers, json=data)
|
| 88 |
+
if resp.status_code != 204:
|
| 89 |
+
raise Exception('Error lock issue: ' + resp.text)
|
| 90 |
+
|
| 91 |
+
print('issue: {} locked'.format(issue_number))
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
if '__main__' == __name__:
|
| 95 |
+
stargazers = get_stargazers(github_repo)
|
| 96 |
+
|
| 97 |
+
issues = get_issues(github_repo)
|
| 98 |
+
for issue in issues:
|
| 99 |
+
login = issue['user']['login']
|
| 100 |
+
if login not in stargazers:
|
| 101 |
+
print('issue: {}, login: {} not in stargazers'.format(issue['number'], login))
|
| 102 |
+
close_issue(github_repo, issue['number'])
|
| 103 |
+
lock_issue(github_repo, issue['number'])
|
| 104 |
+
|
| 105 |
+
print('done')
|
.github/workflows/CloseIssue.yml
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: CloseIssue
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
workflow_dispatch:
|
| 5 |
+
issues:
|
| 6 |
+
types: [ opened ]
|
| 7 |
+
|
| 8 |
+
jobs:
|
| 9 |
+
run-python-script:
|
| 10 |
+
runs-on: ubuntu-latest
|
| 11 |
+
|
| 12 |
+
steps:
|
| 13 |
+
- uses: actions/checkout@v3
|
| 14 |
+
- uses: actions/setup-python@v4
|
| 15 |
+
with:
|
| 16 |
+
python-version: "3.10"
|
| 17 |
+
|
| 18 |
+
- name: Install Dependencies
|
| 19 |
+
run: pip install requests
|
| 20 |
+
|
| 21 |
+
- name: Run close_issue.py Script
|
| 22 |
+
env:
|
| 23 |
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
| 24 |
+
run: python .github/close_issue.py
|
.github/workflows/docker-image-amd64.yml
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Publish Docker image (amd64)
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
push:
|
| 5 |
+
tags:
|
| 6 |
+
- '*'
|
| 7 |
+
workflow_dispatch:
|
| 8 |
+
inputs:
|
| 9 |
+
name:
|
| 10 |
+
description: 'reason'
|
| 11 |
+
required: false
|
| 12 |
+
jobs:
|
| 13 |
+
push_to_registries:
|
| 14 |
+
name: Push Docker image to multiple registries
|
| 15 |
+
runs-on: ubuntu-latest
|
| 16 |
+
environment: github-pages
|
| 17 |
+
permissions:
|
| 18 |
+
packages: write
|
| 19 |
+
contents: read
|
| 20 |
+
steps:
|
| 21 |
+
- name: Check out the repo
|
| 22 |
+
uses: actions/checkout@v3
|
| 23 |
+
|
| 24 |
+
- name: Save version info
|
| 25 |
+
run: |
|
| 26 |
+
git describe --tags > VERSION
|
| 27 |
+
|
| 28 |
+
- name: Log in to Docker Hub
|
| 29 |
+
uses: docker/login-action@v2
|
| 30 |
+
with:
|
| 31 |
+
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
| 32 |
+
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
| 33 |
+
|
| 34 |
+
- name: Log in to the Container registry
|
| 35 |
+
uses: docker/login-action@v2
|
| 36 |
+
with:
|
| 37 |
+
registry: ghcr.io
|
| 38 |
+
username: ${{ github.actor }}
|
| 39 |
+
password: ${{ secrets.GITHUB_TOKEN }}
|
| 40 |
+
|
| 41 |
+
- name: Extract metadata (tags, labels) for Docker
|
| 42 |
+
id: meta
|
| 43 |
+
uses: docker/metadata-action@v4
|
| 44 |
+
with:
|
| 45 |
+
images: |
|
| 46 |
+
deanxv/genspark2api
|
| 47 |
+
ghcr.io/${{ github.repository }}
|
| 48 |
+
|
| 49 |
+
- name: Build and push Docker images
|
| 50 |
+
uses: docker/build-push-action@v3
|
| 51 |
+
with:
|
| 52 |
+
context: .
|
| 53 |
+
push: true
|
| 54 |
+
tags: ${{ steps.meta.outputs.tags }}
|
| 55 |
+
labels: ${{ steps.meta.outputs.labels }}
|
.github/workflows/docker-image-arm64.yml
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Publish Docker image (arm64)
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
push:
|
| 5 |
+
tags:
|
| 6 |
+
- '*'
|
| 7 |
+
- '!*-alpha*'
|
| 8 |
+
workflow_dispatch:
|
| 9 |
+
inputs:
|
| 10 |
+
name:
|
| 11 |
+
description: 'reason'
|
| 12 |
+
required: false
|
| 13 |
+
jobs:
|
| 14 |
+
push_to_registries:
|
| 15 |
+
name: Push Docker image to multiple registries
|
| 16 |
+
runs-on: ubuntu-latest
|
| 17 |
+
environment: github-pages
|
| 18 |
+
permissions:
|
| 19 |
+
packages: write
|
| 20 |
+
contents: read
|
| 21 |
+
steps:
|
| 22 |
+
- name: Check out the repo
|
| 23 |
+
uses: actions/checkout@v3
|
| 24 |
+
|
| 25 |
+
- name: Save version info
|
| 26 |
+
run: |
|
| 27 |
+
git describe --tags > VERSION
|
| 28 |
+
|
| 29 |
+
- name: Set up QEMU
|
| 30 |
+
uses: docker/setup-qemu-action@v2
|
| 31 |
+
|
| 32 |
+
- name: Set up Docker Buildx
|
| 33 |
+
uses: docker/setup-buildx-action@v2
|
| 34 |
+
|
| 35 |
+
- name: Log in to Docker Hub
|
| 36 |
+
uses: docker/login-action@v2
|
| 37 |
+
with:
|
| 38 |
+
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
| 39 |
+
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
| 40 |
+
|
| 41 |
+
- name: Log in to the Container registry
|
| 42 |
+
uses: docker/login-action@v2
|
| 43 |
+
with:
|
| 44 |
+
registry: ghcr.io
|
| 45 |
+
username: ${{ github.actor }}
|
| 46 |
+
password: ${{ secrets.GITHUB_TOKEN }}
|
| 47 |
+
|
| 48 |
+
- name: Extract metadata (tags, labels) for Docker
|
| 49 |
+
id: meta
|
| 50 |
+
uses: docker/metadata-action@v4
|
| 51 |
+
with:
|
| 52 |
+
images: |
|
| 53 |
+
deanxv/genspark2api
|
| 54 |
+
ghcr.io/${{ github.repository }}
|
| 55 |
+
|
| 56 |
+
- name: Build and push Docker images
|
| 57 |
+
uses: docker/build-push-action@v3
|
| 58 |
+
with:
|
| 59 |
+
context: .
|
| 60 |
+
platforms: linux/amd64,linux/arm64
|
| 61 |
+
push: true
|
| 62 |
+
tags: ${{ steps.meta.outputs.tags }}
|
| 63 |
+
labels: ${{ steps.meta.outputs.labels }}
|
.github/workflows/github-pages.yml
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Build GitHub Pages
|
| 2 |
+
on:
|
| 3 |
+
workflow_dispatch:
|
| 4 |
+
inputs:
|
| 5 |
+
name:
|
| 6 |
+
description: 'Reason'
|
| 7 |
+
required: false
|
| 8 |
+
jobs:
|
| 9 |
+
build-and-deploy:
|
| 10 |
+
runs-on: ubuntu-latest
|
| 11 |
+
steps:
|
| 12 |
+
- name: Checkout 🛎️
|
| 13 |
+
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.
|
| 14 |
+
with:
|
| 15 |
+
persist-credentials: false
|
| 16 |
+
- 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.
|
| 17 |
+
env:
|
| 18 |
+
CI: ""
|
| 19 |
+
run: |
|
| 20 |
+
cd web
|
| 21 |
+
npm install
|
| 22 |
+
npm run build
|
| 23 |
+
|
| 24 |
+
- name: Deploy 🚀
|
| 25 |
+
uses: JamesIves/github-pages-deploy-action@releases/v3
|
| 26 |
+
with:
|
| 27 |
+
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
|
| 28 |
+
BRANCH: gh-pages # The branch the action should deploy to.
|
| 29 |
+
FOLDER: web/build # The folder the action should deploy.
|
.github/workflows/linux-release.yml
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Linux Release
|
| 2 |
+
permissions:
|
| 3 |
+
contents: write
|
| 4 |
+
|
| 5 |
+
on:
|
| 6 |
+
push:
|
| 7 |
+
tags:
|
| 8 |
+
- '*'
|
| 9 |
+
- '!*-alpha*'
|
| 10 |
+
jobs:
|
| 11 |
+
release:
|
| 12 |
+
runs-on: ubuntu-latest
|
| 13 |
+
steps:
|
| 14 |
+
- name: Checkout
|
| 15 |
+
uses: actions/checkout@v3
|
| 16 |
+
with:
|
| 17 |
+
fetch-depth: 0
|
| 18 |
+
- uses: actions/setup-node@v3
|
| 19 |
+
with:
|
| 20 |
+
node-version: 16
|
| 21 |
+
- name: Set up Go
|
| 22 |
+
uses: actions/setup-go@v3
|
| 23 |
+
with:
|
| 24 |
+
go-version: '>=1.18.0'
|
| 25 |
+
- name: Build Backend (amd64)
|
| 26 |
+
run: |
|
| 27 |
+
go mod download
|
| 28 |
+
go build -ldflags "-s -w -X 'genspark2api/common.Version=$(git describe --tags)' -extldflags '-static'" -o genspark2api
|
| 29 |
+
|
| 30 |
+
- name: Build Backend (arm64)
|
| 31 |
+
run: |
|
| 32 |
+
sudo apt-get update
|
| 33 |
+
sudo apt-get install gcc-aarch64-linux-gnu
|
| 34 |
+
CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -ldflags "-s -w -X 'genspark2api/common.Version=$(git describe --tags)' -extldflags '-static'" -o genspark2api-arm64
|
| 35 |
+
|
| 36 |
+
- name: Release
|
| 37 |
+
uses: softprops/action-gh-release@v1
|
| 38 |
+
if: startsWith(github.ref, 'refs/tags/')
|
| 39 |
+
with:
|
| 40 |
+
files: |
|
| 41 |
+
genspark2api
|
| 42 |
+
genspark2api-arm64
|
| 43 |
+
draft: false
|
| 44 |
+
generate_release_notes: true
|
| 45 |
+
env:
|
| 46 |
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
.github/workflows/macos-release.yml
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: macOS Release
|
| 2 |
+
permissions:
|
| 3 |
+
contents: write
|
| 4 |
+
|
| 5 |
+
on:
|
| 6 |
+
push:
|
| 7 |
+
tags:
|
| 8 |
+
- '*'
|
| 9 |
+
- '!*-alpha*'
|
| 10 |
+
jobs:
|
| 11 |
+
release:
|
| 12 |
+
runs-on: macos-latest
|
| 13 |
+
steps:
|
| 14 |
+
- name: Checkout
|
| 15 |
+
uses: actions/checkout@v3
|
| 16 |
+
with:
|
| 17 |
+
fetch-depth: 0
|
| 18 |
+
- uses: actions/setup-node@v3
|
| 19 |
+
with:
|
| 20 |
+
node-version: 16
|
| 21 |
+
- name: Set up Go
|
| 22 |
+
uses: actions/setup-go@v3
|
| 23 |
+
with:
|
| 24 |
+
go-version: '>=1.18.0'
|
| 25 |
+
- name: Build Backend
|
| 26 |
+
run: |
|
| 27 |
+
go mod download
|
| 28 |
+
go build -ldflags "-X 'genspark2api/common.Version=$(git describe --tags)'" -o genspark2api-macos
|
| 29 |
+
- name: Release
|
| 30 |
+
uses: softprops/action-gh-release@v1
|
| 31 |
+
if: startsWith(github.ref, 'refs/tags/')
|
| 32 |
+
with:
|
| 33 |
+
files: genspark2api-macos
|
| 34 |
+
draft: false
|
| 35 |
+
generate_release_notes: true
|
| 36 |
+
env:
|
| 37 |
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
.github/workflows/windows-release.yml
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Windows Release
|
| 2 |
+
permissions:
|
| 3 |
+
contents: write
|
| 4 |
+
|
| 5 |
+
on:
|
| 6 |
+
push:
|
| 7 |
+
tags:
|
| 8 |
+
- '*'
|
| 9 |
+
- '!*-alpha*'
|
| 10 |
+
jobs:
|
| 11 |
+
release:
|
| 12 |
+
runs-on: windows-latest
|
| 13 |
+
defaults:
|
| 14 |
+
run:
|
| 15 |
+
shell: bash
|
| 16 |
+
steps:
|
| 17 |
+
- name: Checkout
|
| 18 |
+
uses: actions/checkout@v3
|
| 19 |
+
with:
|
| 20 |
+
fetch-depth: 0
|
| 21 |
+
- uses: actions/setup-node@v3
|
| 22 |
+
with:
|
| 23 |
+
node-version: 16
|
| 24 |
+
- name: Set up Go
|
| 25 |
+
uses: actions/setup-go@v3
|
| 26 |
+
with:
|
| 27 |
+
go-version: '>=1.18.0'
|
| 28 |
+
- name: Build Backend
|
| 29 |
+
run: |
|
| 30 |
+
go mod download
|
| 31 |
+
go build -ldflags "-s -w -X 'genspark2api/common.Version=$(git describe --tags)'" -o genspark2api.exe
|
| 32 |
+
- name: Release
|
| 33 |
+
uses: softprops/action-gh-release@v1
|
| 34 |
+
if: startsWith(github.ref, 'refs/tags/')
|
| 35 |
+
with:
|
| 36 |
+
files: genspark2api.exe
|
| 37 |
+
draft: false
|
| 38 |
+
generate_release_notes: true
|
| 39 |
+
env:
|
| 40 |
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
.gitignore
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.idea
|
| 2 |
+
.vscode
|
| 3 |
+
upload
|
| 4 |
+
*.exe
|
| 5 |
+
*.db
|
| 6 |
+
build
|
Dockerfile
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 使用 Golang 镜像作为构建阶段
|
| 2 |
+
FROM golang:1.21.0-bookworm AS builder
|
| 3 |
+
|
| 4 |
+
# 设置环境变量
|
| 5 |
+
ENV GO111MODULE=on \
|
| 6 |
+
CGO_ENABLED=0 \
|
| 7 |
+
GOOS=linux
|
| 8 |
+
|
| 9 |
+
# 设置工作目录
|
| 10 |
+
WORKDIR /build
|
| 11 |
+
|
| 12 |
+
# 复制 go.mod 和 go.sum 文件,先下载依赖
|
| 13 |
+
COPY go.mod go.sum ./
|
| 14 |
+
#ENV GOPROXY=https://goproxy.cn,direct
|
| 15 |
+
RUN go mod download
|
| 16 |
+
|
| 17 |
+
# 复制整个项目并构建可执行文件
|
| 18 |
+
COPY . .
|
| 19 |
+
RUN go build -o /genspark2api
|
| 20 |
+
|
| 21 |
+
# 使用 Debian slim 镜像作为最终镜像 (Hugging Face支持性更好)
|
| 22 |
+
FROM debian:bookworm-slim
|
| 23 |
+
|
| 24 |
+
# 安装基本的运行时依赖
|
| 25 |
+
RUN apt-get update && apt-get install -y ca-certificates tzdata && rm -rf /var/lib/apt/lists/*
|
| 26 |
+
|
| 27 |
+
# 从构建阶段复制可执行文件
|
| 28 |
+
COPY --from=builder /genspark2api /genspark2api
|
| 29 |
+
COPY --from=builder /build/public /app/genspark2api/public
|
| 30 |
+
|
| 31 |
+
# 创建数据目录并确保正确的权限
|
| 32 |
+
RUN mkdir -p /app/genspark2api/data && chmod -R 755 /app/genspark2api
|
| 33 |
+
|
| 34 |
+
# 设置工作目录
|
| 35 |
+
WORKDIR /app/genspark2api
|
| 36 |
+
|
| 37 |
+
# 设置环境变量
|
| 38 |
+
ENV PORT=7860
|
| 39 |
+
ENV HOST=0.0.0.0
|
| 40 |
+
ENV GS_COOKIE=session_id=b0860552-21bc-48fc-a636-ab7bf76338df:b6528b346b053630d68d262aaa5ffb18fd1cce4e8eee5b39e7d4fa75d39568d5
|
| 41 |
+
ENV AUTO_MODEL_CHAT_MAP_TYPE=1
|
| 42 |
+
|
| 43 |
+
# 暴露Hugging Face默认端口
|
| 44 |
+
EXPOSE 7860
|
| 45 |
+
|
| 46 |
+
# 设置入口命令
|
| 47 |
+
CMD ["/genspark2api"]
|
LICENSE
ADDED
|
@@ -0,0 +1,674 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
GNU GENERAL PUBLIC LICENSE
|
| 2 |
+
Version 3, 29 June 2007
|
| 3 |
+
|
| 4 |
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
| 5 |
+
Everyone is permitted to copy and distribute verbatim copies
|
| 6 |
+
of this license document, but changing it is not allowed.
|
| 7 |
+
|
| 8 |
+
Preamble
|
| 9 |
+
|
| 10 |
+
The GNU General Public License is a free, copyleft license for
|
| 11 |
+
software and other kinds of works.
|
| 12 |
+
|
| 13 |
+
The licenses for most software and other practical works are designed
|
| 14 |
+
to take away your freedom to share and change the works. By contrast,
|
| 15 |
+
the GNU General Public License is intended to guarantee your freedom to
|
| 16 |
+
share and change all versions of a program--to make sure it remains free
|
| 17 |
+
software for all its users. We, the Free Software Foundation, use the
|
| 18 |
+
GNU General Public License for most of our software; it applies also to
|
| 19 |
+
any other work released this way by its authors. You can apply it to
|
| 20 |
+
your programs, too.
|
| 21 |
+
|
| 22 |
+
When we speak of free software, we are referring to freedom, not
|
| 23 |
+
price. Our General Public Licenses are designed to make sure that you
|
| 24 |
+
have the freedom to distribute copies of free software (and charge for
|
| 25 |
+
them if you wish), that you receive source code or can get it if you
|
| 26 |
+
want it, that you can change the software or use pieces of it in new
|
| 27 |
+
free programs, and that you know you can do these things.
|
| 28 |
+
|
| 29 |
+
To protect your rights, we need to prevent others from denying you
|
| 30 |
+
these rights or asking you to surrender the rights. Therefore, you have
|
| 31 |
+
certain responsibilities if you distribute copies of the software, or if
|
| 32 |
+
you modify it: responsibilities to respect the freedom of others.
|
| 33 |
+
|
| 34 |
+
For example, if you distribute copies of such a program, whether
|
| 35 |
+
gratis or for a fee, you must pass on to the recipients the same
|
| 36 |
+
freedoms that you received. You must make sure that they, too, receive
|
| 37 |
+
or can get the source code. And you must show them these terms so they
|
| 38 |
+
know their rights.
|
| 39 |
+
|
| 40 |
+
Developers that use the GNU GPL protect your rights with two steps:
|
| 41 |
+
(1) assert copyright on the software, and (2) offer you this License
|
| 42 |
+
giving you legal permission to copy, distribute and/or modify it.
|
| 43 |
+
|
| 44 |
+
For the developers' and authors' protection, the GPL clearly explains
|
| 45 |
+
that there is no warranty for this free software. For both users' and
|
| 46 |
+
authors' sake, the GPL requires that modified versions be marked as
|
| 47 |
+
changed, so that their problems will not be attributed erroneously to
|
| 48 |
+
authors of previous versions.
|
| 49 |
+
|
| 50 |
+
Some devices are designed to deny users access to install or run
|
| 51 |
+
modified versions of the software inside them, although the manufacturer
|
| 52 |
+
can do so. This is fundamentally incompatible with the aim of
|
| 53 |
+
protecting users' freedom to change the software. The systematic
|
| 54 |
+
pattern of such abuse occurs in the area of products for individuals to
|
| 55 |
+
use, which is precisely where it is most unacceptable. Therefore, we
|
| 56 |
+
have designed this version of the GPL to prohibit the practice for those
|
| 57 |
+
products. If such problems arise substantially in other domains, we
|
| 58 |
+
stand ready to extend this provision to those domains in future versions
|
| 59 |
+
of the GPL, as needed to protect the freedom of users.
|
| 60 |
+
|
| 61 |
+
Finally, every program is threatened constantly by software patents.
|
| 62 |
+
States should not allow patents to restrict development and use of
|
| 63 |
+
software on general-purpose computers, but in those that do, we wish to
|
| 64 |
+
avoid the special danger that patents applied to a free program could
|
| 65 |
+
make it effectively proprietary. To prevent this, the GPL assures that
|
| 66 |
+
patents cannot be used to render the program non-free.
|
| 67 |
+
|
| 68 |
+
The precise terms and conditions for copying, distribution and
|
| 69 |
+
modification follow.
|
| 70 |
+
|
| 71 |
+
TERMS AND CONDITIONS
|
| 72 |
+
|
| 73 |
+
0. Definitions.
|
| 74 |
+
|
| 75 |
+
"This License" refers to version 3 of the GNU General Public License.
|
| 76 |
+
|
| 77 |
+
"Copyright" also means copyright-like laws that apply to other kinds of
|
| 78 |
+
works, such as semiconductor masks.
|
| 79 |
+
|
| 80 |
+
"The Program" refers to any copyrightable work licensed under this
|
| 81 |
+
License. Each licensee is addressed as "you". "Licensees" and
|
| 82 |
+
"recipients" may be individuals or organizations.
|
| 83 |
+
|
| 84 |
+
To "modify" a work means to copy from or adapt all or part of the work
|
| 85 |
+
in a fashion requiring copyright permission, other than the making of an
|
| 86 |
+
exact copy. The resulting work is called a "modified version" of the
|
| 87 |
+
earlier work or a work "based on" the earlier work.
|
| 88 |
+
|
| 89 |
+
A "covered work" means either the unmodified Program or a work based
|
| 90 |
+
on the Program.
|
| 91 |
+
|
| 92 |
+
To "propagate" a work means to do anything with it that, without
|
| 93 |
+
permission, would make you directly or secondarily liable for
|
| 94 |
+
infringement under applicable copyright law, except executing it on a
|
| 95 |
+
computer or modifying a private copy. Propagation includes copying,
|
| 96 |
+
distribution (with or without modification), making available to the
|
| 97 |
+
public, and in some countries other activities as well.
|
| 98 |
+
|
| 99 |
+
To "convey" a work means any kind of propagation that enables other
|
| 100 |
+
parties to make or receive copies. Mere interaction with a user through
|
| 101 |
+
a computer network, with no transfer of a copy, is not conveying.
|
| 102 |
+
|
| 103 |
+
An interactive user interface displays "Appropriate Legal Notices"
|
| 104 |
+
to the extent that it includes a convenient and prominently visible
|
| 105 |
+
feature that (1) displays an appropriate copyright notice, and (2)
|
| 106 |
+
tells the user that there is no warranty for the work (except to the
|
| 107 |
+
extent that warranties are provided), that licensees may convey the
|
| 108 |
+
work under this License, and how to view a copy of this License. If
|
| 109 |
+
the interface presents a list of user commands or options, such as a
|
| 110 |
+
menu, a prominent item in the list meets this criterion.
|
| 111 |
+
|
| 112 |
+
1. Source Code.
|
| 113 |
+
|
| 114 |
+
The "source code" for a work means the preferred form of the work
|
| 115 |
+
for making modifications to it. "Object code" means any non-source
|
| 116 |
+
form of a work.
|
| 117 |
+
|
| 118 |
+
A "Standard Interface" means an interface that either is an official
|
| 119 |
+
standard defined by a recognized standards body, or, in the case of
|
| 120 |
+
interfaces specified for a particular programming language, one that
|
| 121 |
+
is widely used among developers working in that language.
|
| 122 |
+
|
| 123 |
+
The "System Libraries" of an executable work include anything, other
|
| 124 |
+
than the work as a whole, that (a) is included in the normal form of
|
| 125 |
+
packaging a Major Component, but which is not part of that Major
|
| 126 |
+
Component, and (b) serves only to enable use of the work with that
|
| 127 |
+
Major Component, or to implement a Standard Interface for which an
|
| 128 |
+
implementation is available to the public in source code form. A
|
| 129 |
+
"Major Component", in this context, means a major essential component
|
| 130 |
+
(kernel, window system, and so on) of the specific operating system
|
| 131 |
+
(if any) on which the executable work runs, or a compiler used to
|
| 132 |
+
produce the work, or an object code interpreter used to run it.
|
| 133 |
+
|
| 134 |
+
The "Corresponding Source" for a work in object code form means all
|
| 135 |
+
the source code needed to generate, install, and (for an executable
|
| 136 |
+
work) run the object code and to modify the work, including scripts to
|
| 137 |
+
control those activities. However, it does not include the work's
|
| 138 |
+
System Libraries, or general-purpose tools or generally available free
|
| 139 |
+
programs which are used unmodified in performing those activities but
|
| 140 |
+
which are not part of the work. For example, Corresponding Source
|
| 141 |
+
includes interface definition files associated with source files for
|
| 142 |
+
the work, and the source code for shared libraries and dynamically
|
| 143 |
+
linked subprograms that the work is specifically designed to require,
|
| 144 |
+
such as by intimate data communication or control flow between those
|
| 145 |
+
subprograms and other parts of the work.
|
| 146 |
+
|
| 147 |
+
The Corresponding Source need not include anything that users
|
| 148 |
+
can regenerate automatically from other parts of the Corresponding
|
| 149 |
+
Source.
|
| 150 |
+
|
| 151 |
+
The Corresponding Source for a work in source code form is that
|
| 152 |
+
same work.
|
| 153 |
+
|
| 154 |
+
2. Basic Permissions.
|
| 155 |
+
|
| 156 |
+
All rights granted under this License are granted for the term of
|
| 157 |
+
copyright on the Program, and are irrevocable provided the stated
|
| 158 |
+
conditions are met. This License explicitly affirms your unlimited
|
| 159 |
+
permission to run the unmodified Program. The output from running a
|
| 160 |
+
covered work is covered by this License only if the output, given its
|
| 161 |
+
content, constitutes a covered work. This License acknowledges your
|
| 162 |
+
rights of fair use or other equivalent, as provided by copyright law.
|
| 163 |
+
|
| 164 |
+
You may make, run and propagate covered works that you do not
|
| 165 |
+
convey, without conditions so long as your license otherwise remains
|
| 166 |
+
in force. You may convey covered works to others for the sole purpose
|
| 167 |
+
of having them make modifications exclusively for you, or provide you
|
| 168 |
+
with facilities for running those works, provided that you comply with
|
| 169 |
+
the terms of this License in conveying all material for which you do
|
| 170 |
+
not control copyright. Those thus making or running the covered works
|
| 171 |
+
for you must do so exclusively on your behalf, under your direction
|
| 172 |
+
and control, on terms that prohibit them from making any copies of
|
| 173 |
+
your copyrighted material outside their relationship with you.
|
| 174 |
+
|
| 175 |
+
Conveying under any other circumstances is permitted solely under
|
| 176 |
+
the conditions stated below. Sublicensing is not allowed; section 10
|
| 177 |
+
makes it unnecessary.
|
| 178 |
+
|
| 179 |
+
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
| 180 |
+
|
| 181 |
+
No covered work shall be deemed part of an effective technological
|
| 182 |
+
measure under any applicable law fulfilling obligations under article
|
| 183 |
+
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
| 184 |
+
similar laws prohibiting or restricting circumvention of such
|
| 185 |
+
measures.
|
| 186 |
+
|
| 187 |
+
When you convey a covered work, you waive any legal power to forbid
|
| 188 |
+
circumvention of technological measures to the extent such circumvention
|
| 189 |
+
is effected by exercising rights under this License with respect to
|
| 190 |
+
the covered work, and you disclaim any intention to limit operation or
|
| 191 |
+
modification of the work as a means of enforcing, against the work's
|
| 192 |
+
users, your or third parties' legal rights to forbid circumvention of
|
| 193 |
+
technological measures.
|
| 194 |
+
|
| 195 |
+
4. Conveying Verbatim Copies.
|
| 196 |
+
|
| 197 |
+
You may convey verbatim copies of the Program's source code as you
|
| 198 |
+
receive it, in any medium, provided that you conspicuously and
|
| 199 |
+
appropriately publish on each copy an appropriate copyright notice;
|
| 200 |
+
keep intact all notices stating that this License and any
|
| 201 |
+
non-permissive terms added in accord with section 7 apply to the code;
|
| 202 |
+
keep intact all notices of the absence of any warranty; and give all
|
| 203 |
+
recipients a copy of this License along with the Program.
|
| 204 |
+
|
| 205 |
+
You may charge any price or no price for each copy that you convey,
|
| 206 |
+
and you may offer support or warranty protection for a fee.
|
| 207 |
+
|
| 208 |
+
5. Conveying Modified Source Versions.
|
| 209 |
+
|
| 210 |
+
You may convey a work based on the Program, or the modifications to
|
| 211 |
+
produce it from the Program, in the form of source code under the
|
| 212 |
+
terms of section 4, provided that you also meet all of these conditions:
|
| 213 |
+
|
| 214 |
+
a) The work must carry prominent notices stating that you modified
|
| 215 |
+
it, and giving a relevant date.
|
| 216 |
+
|
| 217 |
+
b) The work must carry prominent notices stating that it is
|
| 218 |
+
released under this License and any conditions added under section
|
| 219 |
+
7. This requirement modifies the requirement in section 4 to
|
| 220 |
+
"keep intact all notices".
|
| 221 |
+
|
| 222 |
+
c) You must license the entire work, as a whole, under this
|
| 223 |
+
License to anyone who comes into possession of a copy. This
|
| 224 |
+
License will therefore apply, along with any applicable section 7
|
| 225 |
+
additional terms, to the whole of the work, and all its parts,
|
| 226 |
+
regardless of how they are packaged. This License gives no
|
| 227 |
+
permission to license the work in any other way, but it does not
|
| 228 |
+
invalidate such permission if you have separately received it.
|
| 229 |
+
|
| 230 |
+
d) If the work has interactive user interfaces, each must display
|
| 231 |
+
Appropriate Legal Notices; however, if the Program has interactive
|
| 232 |
+
interfaces that do not display Appropriate Legal Notices, your
|
| 233 |
+
work need not make them do so.
|
| 234 |
+
|
| 235 |
+
A compilation of a covered work with other separate and independent
|
| 236 |
+
works, which are not by their nature extensions of the covered work,
|
| 237 |
+
and which are not combined with it such as to form a larger program,
|
| 238 |
+
in or on a volume of a storage or distribution medium, is called an
|
| 239 |
+
"aggregate" if the compilation and its resulting copyright are not
|
| 240 |
+
used to limit the access or legal rights of the compilation's users
|
| 241 |
+
beyond what the individual works permit. Inclusion of a covered work
|
| 242 |
+
in an aggregate does not cause this License to apply to the other
|
| 243 |
+
parts of the aggregate.
|
| 244 |
+
|
| 245 |
+
6. Conveying Non-Source Forms.
|
| 246 |
+
|
| 247 |
+
You may convey a covered work in object code form under the terms
|
| 248 |
+
of sections 4 and 5, provided that you also convey the
|
| 249 |
+
machine-readable Corresponding Source under the terms of this License,
|
| 250 |
+
in one of these ways:
|
| 251 |
+
|
| 252 |
+
a) Convey the object code in, or embodied in, a physical product
|
| 253 |
+
(including a physical distribution medium), accompanied by the
|
| 254 |
+
Corresponding Source fixed on a durable physical medium
|
| 255 |
+
customarily used for software interchange.
|
| 256 |
+
|
| 257 |
+
b) Convey the object code in, or embodied in, a physical product
|
| 258 |
+
(including a physical distribution medium), accompanied by a
|
| 259 |
+
written offer, valid for at least three years and valid for as
|
| 260 |
+
long as you offer spare parts or customer support for that product
|
| 261 |
+
model, to give anyone who possesses the object code either (1) a
|
| 262 |
+
copy of the Corresponding Source for all the software in the
|
| 263 |
+
product that is covered by this License, on a durable physical
|
| 264 |
+
medium customarily used for software interchange, for a price no
|
| 265 |
+
more than your reasonable cost of physically performing this
|
| 266 |
+
conveying of source, or (2) access to copy the
|
| 267 |
+
Corresponding Source from a network server at no charge.
|
| 268 |
+
|
| 269 |
+
c) Convey individual copies of the object code with a copy of the
|
| 270 |
+
written offer to provide the Corresponding Source. This
|
| 271 |
+
alternative is allowed only occasionally and noncommercially, and
|
| 272 |
+
only if you received the object code with such an offer, in accord
|
| 273 |
+
with subsection 6b.
|
| 274 |
+
|
| 275 |
+
d) Convey the object code by offering access from a designated
|
| 276 |
+
place (gratis or for a charge), and offer equivalent access to the
|
| 277 |
+
Corresponding Source in the same way through the same place at no
|
| 278 |
+
further charge. You need not require recipients to copy the
|
| 279 |
+
Corresponding Source along with the object code. If the place to
|
| 280 |
+
copy the object code is a network server, the Corresponding Source
|
| 281 |
+
may be on a different server (operated by you or a third party)
|
| 282 |
+
that supports equivalent copying facilities, provided you maintain
|
| 283 |
+
clear directions next to the object code saying where to find the
|
| 284 |
+
Corresponding Source. Regardless of what server hosts the
|
| 285 |
+
Corresponding Source, you remain obligated to ensure that it is
|
| 286 |
+
available for as long as needed to satisfy these requirements.
|
| 287 |
+
|
| 288 |
+
e) Convey the object code using peer-to-peer transmission, provided
|
| 289 |
+
you inform other peers where the object code and Corresponding
|
| 290 |
+
Source of the work are being offered to the general public at no
|
| 291 |
+
charge under subsection 6d.
|
| 292 |
+
|
| 293 |
+
A separable portion of the object code, whose source code is excluded
|
| 294 |
+
from the Corresponding Source as a System Library, need not be
|
| 295 |
+
included in conveying the object code work.
|
| 296 |
+
|
| 297 |
+
A "User Product" is either (1) a "consumer product", which means any
|
| 298 |
+
tangible personal property which is normally used for personal, family,
|
| 299 |
+
or household purposes, or (2) anything designed or sold for incorporation
|
| 300 |
+
into a dwelling. In determining whether a product is a consumer product,
|
| 301 |
+
doubtful cases shall be resolved in favor of coverage. For a particular
|
| 302 |
+
product received by a particular user, "normally used" refers to a
|
| 303 |
+
typical or common use of that class of product, regardless of the status
|
| 304 |
+
of the particular user or of the way in which the particular user
|
| 305 |
+
actually uses, or expects or is expected to use, the product. A product
|
| 306 |
+
is a consumer product regardless of whether the product has substantial
|
| 307 |
+
commercial, industrial or non-consumer uses, unless such uses represent
|
| 308 |
+
the only significant mode of use of the product.
|
| 309 |
+
|
| 310 |
+
"Installation Information" for a User Product means any methods,
|
| 311 |
+
procedures, authorization keys, or other information required to install
|
| 312 |
+
and execute modified versions of a covered work in that User Product from
|
| 313 |
+
a modified version of its Corresponding Source. The information must
|
| 314 |
+
suffice to ensure that the continued functioning of the modified object
|
| 315 |
+
code is in no case prevented or interfered with solely because
|
| 316 |
+
modification has been made.
|
| 317 |
+
|
| 318 |
+
If you convey an object code work under this section in, or with, or
|
| 319 |
+
specifically for use in, a User Product, and the conveying occurs as
|
| 320 |
+
part of a transaction in which the right of possession and use of the
|
| 321 |
+
User Product is transferred to the recipient in perpetuity or for a
|
| 322 |
+
fixed term (regardless of how the transaction is characterized), the
|
| 323 |
+
Corresponding Source conveyed under this section must be accompanied
|
| 324 |
+
by the Installation Information. But this requirement does not apply
|
| 325 |
+
if neither you nor any third party retains the ability to install
|
| 326 |
+
modified object code on the User Product (for example, the work has
|
| 327 |
+
been installed in ROM).
|
| 328 |
+
|
| 329 |
+
The requirement to provide Installation Information does not include a
|
| 330 |
+
requirement to continue to provide support service, warranty, or updates
|
| 331 |
+
for a work that has been modified or installed by the recipient, or for
|
| 332 |
+
the User Product in which it has been modified or installed. Access to a
|
| 333 |
+
network may be denied when the modification itself materially and
|
| 334 |
+
adversely affects the operation of the network or violates the rules and
|
| 335 |
+
protocols for communication across the network.
|
| 336 |
+
|
| 337 |
+
Corresponding Source conveyed, and Installation Information provided,
|
| 338 |
+
in accord with this section must be in a format that is publicly
|
| 339 |
+
documented (and with an implementation available to the public in
|
| 340 |
+
source code form), and must require no special password or key for
|
| 341 |
+
unpacking, reading or copying.
|
| 342 |
+
|
| 343 |
+
7. Additional Terms.
|
| 344 |
+
|
| 345 |
+
"Additional permissions" are terms that supplement the terms of this
|
| 346 |
+
License by making exceptions from one or more of its conditions.
|
| 347 |
+
Additional permissions that are applicable to the entire Program shall
|
| 348 |
+
be treated as though they were included in this License, to the extent
|
| 349 |
+
that they are valid under applicable law. If additional permissions
|
| 350 |
+
apply only to part of the Program, that part may be used separately
|
| 351 |
+
under those permissions, but the entire Program remains governed by
|
| 352 |
+
this License without regard to the additional permissions.
|
| 353 |
+
|
| 354 |
+
When you convey a copy of a covered work, you may at your option
|
| 355 |
+
remove any additional permissions from that copy, or from any part of
|
| 356 |
+
it. (Additional permissions may be written to require their own
|
| 357 |
+
removal in certain cases when you modify the work.) You may place
|
| 358 |
+
additional permissions on material, added by you to a covered work,
|
| 359 |
+
for which you have or can give appropriate copyright permission.
|
| 360 |
+
|
| 361 |
+
Notwithstanding any other provision of this License, for material you
|
| 362 |
+
add to a covered work, you may (if authorized by the copyright holders of
|
| 363 |
+
that material) supplement the terms of this License with terms:
|
| 364 |
+
|
| 365 |
+
a) Disclaiming warranty or limiting liability differently from the
|
| 366 |
+
terms of sections 15 and 16 of this License; or
|
| 367 |
+
|
| 368 |
+
b) Requiring preservation of specified reasonable legal notices or
|
| 369 |
+
author attributions in that material or in the Appropriate Legal
|
| 370 |
+
Notices displayed by works containing it; or
|
| 371 |
+
|
| 372 |
+
c) Prohibiting misrepresentation of the origin of that material, or
|
| 373 |
+
requiring that modified versions of such material be marked in
|
| 374 |
+
reasonable ways as different from the original version; or
|
| 375 |
+
|
| 376 |
+
d) Limiting the use for publicity purposes of names of licensors or
|
| 377 |
+
authors of the material; or
|
| 378 |
+
|
| 379 |
+
e) Declining to grant rights under trademark law for use of some
|
| 380 |
+
trade names, trademarks, or service marks; or
|
| 381 |
+
|
| 382 |
+
f) Requiring indemnification of licensors and authors of that
|
| 383 |
+
material by anyone who conveys the material (or modified versions of
|
| 384 |
+
it) with contractual assumptions of liability to the recipient, for
|
| 385 |
+
any liability that these contractual assumptions directly impose on
|
| 386 |
+
those licensors and authors.
|
| 387 |
+
|
| 388 |
+
All other non-permissive additional terms are considered "further
|
| 389 |
+
restrictions" within the meaning of section 10. If the Program as you
|
| 390 |
+
received it, or any part of it, contains a notice stating that it is
|
| 391 |
+
governed by this License along with a term that is a further
|
| 392 |
+
restriction, you may remove that term. If a license document contains
|
| 393 |
+
a further restriction but permits relicensing or conveying under this
|
| 394 |
+
License, you may add to a covered work material governed by the terms
|
| 395 |
+
of that license document, provided that the further restriction does
|
| 396 |
+
not survive such relicensing or conveying.
|
| 397 |
+
|
| 398 |
+
If you add terms to a covered work in accord with this section, you
|
| 399 |
+
must place, in the relevant source files, a statement of the
|
| 400 |
+
additional terms that apply to those files, or a notice indicating
|
| 401 |
+
where to find the applicable terms.
|
| 402 |
+
|
| 403 |
+
Additional terms, permissive or non-permissive, may be stated in the
|
| 404 |
+
form of a separately written license, or stated as exceptions;
|
| 405 |
+
the above requirements apply either way.
|
| 406 |
+
|
| 407 |
+
8. Termination.
|
| 408 |
+
|
| 409 |
+
You may not propagate or modify a covered work except as expressly
|
| 410 |
+
provided under this License. Any attempt otherwise to propagate or
|
| 411 |
+
modify it is void, and will automatically terminate your rights under
|
| 412 |
+
this License (including any patent licenses granted under the third
|
| 413 |
+
paragraph of section 11).
|
| 414 |
+
|
| 415 |
+
However, if you cease all violation of this License, then your
|
| 416 |
+
license from a particular copyright holder is reinstated (a)
|
| 417 |
+
provisionally, unless and until the copyright holder explicitly and
|
| 418 |
+
finally terminates your license, and (b) permanently, if the copyright
|
| 419 |
+
holder fails to notify you of the violation by some reasonable means
|
| 420 |
+
prior to 60 days after the cessation.
|
| 421 |
+
|
| 422 |
+
Moreover, your license from a particular copyright holder is
|
| 423 |
+
reinstated permanently if the copyright holder notifies you of the
|
| 424 |
+
violation by some reasonable means, this is the first time you have
|
| 425 |
+
received notice of violation of this License (for any work) from that
|
| 426 |
+
copyright holder, and you cure the violation prior to 30 days after
|
| 427 |
+
your receipt of the notice.
|
| 428 |
+
|
| 429 |
+
Termination of your rights under this section does not terminate the
|
| 430 |
+
licenses of parties who have received copies or rights from you under
|
| 431 |
+
this License. If your rights have been terminated and not permanently
|
| 432 |
+
reinstated, you do not qualify to receive new licenses for the same
|
| 433 |
+
material under section 10.
|
| 434 |
+
|
| 435 |
+
9. Acceptance Not Required for Having Copies.
|
| 436 |
+
|
| 437 |
+
You are not required to accept this License in order to receive or
|
| 438 |
+
run a copy of the Program. Ancillary propagation of a covered work
|
| 439 |
+
occurring solely as a consequence of using peer-to-peer transmission
|
| 440 |
+
to receive a copy likewise does not require acceptance. However,
|
| 441 |
+
nothing other than this License grants you permission to propagate or
|
| 442 |
+
modify any covered work. These actions infringe copyright if you do
|
| 443 |
+
not accept this License. Therefore, by modifying or propagating a
|
| 444 |
+
covered work, you indicate your acceptance of this License to do so.
|
| 445 |
+
|
| 446 |
+
10. Automatic Licensing of Downstream Recipients.
|
| 447 |
+
|
| 448 |
+
Each time you convey a covered work, the recipient automatically
|
| 449 |
+
receives a license from the original licensors, to run, modify and
|
| 450 |
+
propagate that work, subject to this License. You are not responsible
|
| 451 |
+
for enforcing compliance by third parties with this License.
|
| 452 |
+
|
| 453 |
+
An "entity transaction" is a transaction transferring control of an
|
| 454 |
+
organization, or substantially all assets of one, or subdividing an
|
| 455 |
+
organization, or merging organizations. If propagation of a covered
|
| 456 |
+
work results from an entity transaction, each party to that
|
| 457 |
+
transaction who receives a copy of the work also receives whatever
|
| 458 |
+
licenses to the work the party's predecessor in interest had or could
|
| 459 |
+
give under the previous paragraph, plus a right to possession of the
|
| 460 |
+
Corresponding Source of the work from the predecessor in interest, if
|
| 461 |
+
the predecessor has it or can get it with reasonable efforts.
|
| 462 |
+
|
| 463 |
+
You may not impose any further restrictions on the exercise of the
|
| 464 |
+
rights granted or affirmed under this License. For example, you may
|
| 465 |
+
not impose a license fee, royalty, or other charge for exercise of
|
| 466 |
+
rights granted under this License, and you may not initiate litigation
|
| 467 |
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
| 468 |
+
any patent claim is infringed by making, using, selling, offering for
|
| 469 |
+
sale, or importing the Program or any portion of it.
|
| 470 |
+
|
| 471 |
+
11. Patents.
|
| 472 |
+
|
| 473 |
+
A "contributor" is a copyright holder who authorizes use under this
|
| 474 |
+
License of the Program or a work on which the Program is based. The
|
| 475 |
+
work thus licensed is called the contributor's "contributor version".
|
| 476 |
+
|
| 477 |
+
A contributor's "essential patent claims" are all patent claims
|
| 478 |
+
owned or controlled by the contributor, whether already acquired or
|
| 479 |
+
hereafter acquired, that would be infringed by some manner, permitted
|
| 480 |
+
by this License, of making, using, or selling its contributor version,
|
| 481 |
+
but do not include claims that would be infringed only as a
|
| 482 |
+
consequence of further modification of the contributor version. For
|
| 483 |
+
purposes of this definition, "control" includes the right to grant
|
| 484 |
+
patent sublicenses in a manner consistent with the requirements of
|
| 485 |
+
this License.
|
| 486 |
+
|
| 487 |
+
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
| 488 |
+
patent license under the contributor's essential patent claims, to
|
| 489 |
+
make, use, sell, offer for sale, import and otherwise run, modify and
|
| 490 |
+
propagate the contents of its contributor version.
|
| 491 |
+
|
| 492 |
+
In the following three paragraphs, a "patent license" is any express
|
| 493 |
+
agreement or commitment, however denominated, not to enforce a patent
|
| 494 |
+
(such as an express permission to practice a patent or covenant not to
|
| 495 |
+
sue for patent infringement). To "grant" such a patent license to a
|
| 496 |
+
party means to make such an agreement or commitment not to enforce a
|
| 497 |
+
patent against the party.
|
| 498 |
+
|
| 499 |
+
If you convey a covered work, knowingly relying on a patent license,
|
| 500 |
+
and the Corresponding Source of the work is not available for anyone
|
| 501 |
+
to copy, free of charge and under the terms of this License, through a
|
| 502 |
+
publicly available network server or other readily accessible means,
|
| 503 |
+
then you must either (1) cause the Corresponding Source to be so
|
| 504 |
+
available, or (2) arrange to deprive yourself of the benefit of the
|
| 505 |
+
patent license for this particular work, or (3) arrange, in a manner
|
| 506 |
+
consistent with the requirements of this License, to extend the patent
|
| 507 |
+
license to downstream recipients. "Knowingly relying" means you have
|
| 508 |
+
actual knowledge that, but for the patent license, your conveying the
|
| 509 |
+
covered work in a country, or your recipient's use of the covered work
|
| 510 |
+
in a country, would infringe one or more identifiable patents in that
|
| 511 |
+
country that you have reason to believe are valid.
|
| 512 |
+
|
| 513 |
+
If, pursuant to or in connection with a single transaction or
|
| 514 |
+
arrangement, you convey, or propagate by procuring conveyance of, a
|
| 515 |
+
covered work, and grant a patent license to some of the parties
|
| 516 |
+
receiving the covered work authorizing them to use, propagate, modify
|
| 517 |
+
or convey a specific copy of the covered work, then the patent license
|
| 518 |
+
you grant is automatically extended to all recipients of the covered
|
| 519 |
+
work and works based on it.
|
| 520 |
+
|
| 521 |
+
A patent license is "discriminatory" if it does not include within
|
| 522 |
+
the scope of its coverage, prohibits the exercise of, or is
|
| 523 |
+
conditioned on the non-exercise of one or more of the rights that are
|
| 524 |
+
specifically granted under this License. You may not convey a covered
|
| 525 |
+
work if you are a party to an arrangement with a third party that is
|
| 526 |
+
in the business of distributing software, under which you make payment
|
| 527 |
+
to the third party based on the extent of your activity of conveying
|
| 528 |
+
the work, and under which the third party grants, to any of the
|
| 529 |
+
parties who would receive the covered work from you, a discriminatory
|
| 530 |
+
patent license (a) in connection with copies of the covered work
|
| 531 |
+
conveyed by you (or copies made from those copies), or (b) primarily
|
| 532 |
+
for and in connection with specific products or compilations that
|
| 533 |
+
contain the covered work, unless you entered into that arrangement,
|
| 534 |
+
or that patent license was granted, prior to 28 March 2007.
|
| 535 |
+
|
| 536 |
+
Nothing in this License shall be construed as excluding or limiting
|
| 537 |
+
any implied license or other defenses to infringement that may
|
| 538 |
+
otherwise be available to you under applicable patent law.
|
| 539 |
+
|
| 540 |
+
12. No Surrender of Others' Freedom.
|
| 541 |
+
|
| 542 |
+
If conditions are imposed on you (whether by court order, agreement or
|
| 543 |
+
otherwise) that contradict the conditions of this License, they do not
|
| 544 |
+
excuse you from the conditions of this License. If you cannot convey a
|
| 545 |
+
covered work so as to satisfy simultaneously your obligations under this
|
| 546 |
+
License and any other pertinent obligations, then as a consequence you may
|
| 547 |
+
not convey it at all. For example, if you agree to terms that obligate you
|
| 548 |
+
to collect a royalty for further conveying from those to whom you convey
|
| 549 |
+
the Program, the only way you could satisfy both those terms and this
|
| 550 |
+
License would be to refrain entirely from conveying the Program.
|
| 551 |
+
|
| 552 |
+
13. Use with the GNU Affero General Public License.
|
| 553 |
+
|
| 554 |
+
Notwithstanding any other provision of this License, you have
|
| 555 |
+
permission to link or combine any covered work with a work licensed
|
| 556 |
+
under version 3 of the GNU Affero General Public License into a single
|
| 557 |
+
combined work, and to convey the resulting work. The terms of this
|
| 558 |
+
License will continue to apply to the part which is the covered work,
|
| 559 |
+
but the special requirements of the GNU Affero General Public License,
|
| 560 |
+
section 13, concerning interaction through a network will apply to the
|
| 561 |
+
combination as such.
|
| 562 |
+
|
| 563 |
+
14. Revised Versions of this License.
|
| 564 |
+
|
| 565 |
+
The Free Software Foundation may publish revised and/or new versions of
|
| 566 |
+
the GNU General Public License from time to time. Such new versions will
|
| 567 |
+
be similar in spirit to the present version, but may differ in detail to
|
| 568 |
+
address new problems or concerns.
|
| 569 |
+
|
| 570 |
+
Each version is given a distinguishing version number. If the
|
| 571 |
+
Program specifies that a certain numbered version of the GNU General
|
| 572 |
+
Public License "or any later version" applies to it, you have the
|
| 573 |
+
option of following the terms and conditions either of that numbered
|
| 574 |
+
version or of any later version published by the Free Software
|
| 575 |
+
Foundation. If the Program does not specify a version number of the
|
| 576 |
+
GNU General Public License, you may choose any version ever published
|
| 577 |
+
by the Free Software Foundation.
|
| 578 |
+
|
| 579 |
+
If the Program specifies that a proxy can decide which future
|
| 580 |
+
versions of the GNU General Public License can be used, that proxy's
|
| 581 |
+
public statement of acceptance of a version permanently authorizes you
|
| 582 |
+
to choose that version for the Program.
|
| 583 |
+
|
| 584 |
+
Later license versions may give you additional or different
|
| 585 |
+
permissions. However, no additional obligations are imposed on any
|
| 586 |
+
author or copyright holder as a result of your choosing to follow a
|
| 587 |
+
later version.
|
| 588 |
+
|
| 589 |
+
15. Disclaimer of Warranty.
|
| 590 |
+
|
| 591 |
+
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
| 592 |
+
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
| 593 |
+
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
| 594 |
+
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
| 595 |
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
| 596 |
+
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
| 597 |
+
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
| 598 |
+
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
| 599 |
+
|
| 600 |
+
16. Limitation of Liability.
|
| 601 |
+
|
| 602 |
+
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
| 603 |
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
| 604 |
+
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
| 605 |
+
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
| 606 |
+
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
| 607 |
+
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
| 608 |
+
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
| 609 |
+
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
| 610 |
+
SUCH DAMAGES.
|
| 611 |
+
|
| 612 |
+
17. Interpretation of Sections 15 and 16.
|
| 613 |
+
|
| 614 |
+
If the disclaimer of warranty and limitation of liability provided
|
| 615 |
+
above cannot be given local legal effect according to their terms,
|
| 616 |
+
reviewing courts shall apply local law that most closely approximates
|
| 617 |
+
an absolute waiver of all civil liability in connection with the
|
| 618 |
+
Program, unless a warranty or assumption of liability accompanies a
|
| 619 |
+
copy of the Program in return for a fee.
|
| 620 |
+
|
| 621 |
+
END OF TERMS AND CONDITIONS
|
| 622 |
+
|
| 623 |
+
How to Apply These Terms to Your New Programs
|
| 624 |
+
|
| 625 |
+
If you develop a new program, and you want it to be of the greatest
|
| 626 |
+
possible use to the public, the best way to achieve this is to make it
|
| 627 |
+
free software which everyone can redistribute and change under these terms.
|
| 628 |
+
|
| 629 |
+
To do so, attach the following notices to the program. It is safest
|
| 630 |
+
to attach them to the start of each source file to most effectively
|
| 631 |
+
state the exclusion of warranty; and each file should have at least
|
| 632 |
+
the "copyright" line and a pointer to where the full notice is found.
|
| 633 |
+
|
| 634 |
+
<one line to give the program's name and a brief idea of what it does.>
|
| 635 |
+
Copyright (C) <year> <name of author>
|
| 636 |
+
|
| 637 |
+
This program is free software: you can redistribute it and/or modify
|
| 638 |
+
it under the terms of the GNU General Public License as published by
|
| 639 |
+
the Free Software Foundation, either version 3 of the License, or
|
| 640 |
+
(at your option) any later version.
|
| 641 |
+
|
| 642 |
+
This program is distributed in the hope that it will be useful,
|
| 643 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 644 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 645 |
+
GNU General Public License for more details.
|
| 646 |
+
|
| 647 |
+
You should have received a copy of the GNU General Public License
|
| 648 |
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
| 649 |
+
|
| 650 |
+
Also add information on how to contact you by electronic and paper mail.
|
| 651 |
+
|
| 652 |
+
If the program does terminal interaction, make it output a short
|
| 653 |
+
notice like this when it starts in an interactive mode:
|
| 654 |
+
|
| 655 |
+
<program> Copyright (C) <year> <name of author>
|
| 656 |
+
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
| 657 |
+
This is free software, and you are welcome to redistribute it
|
| 658 |
+
under certain conditions; type `show c' for details.
|
| 659 |
+
|
| 660 |
+
The hypothetical commands `show w' and `show c' should show the appropriate
|
| 661 |
+
parts of the General Public License. Of course, your program's commands
|
| 662 |
+
might be different; for a GUI interface, you would use an "about box".
|
| 663 |
+
|
| 664 |
+
You should also get your employer (if you work as a programmer) or school,
|
| 665 |
+
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
| 666 |
+
For more information on this, and how to apply and follow the GNU GPL, see
|
| 667 |
+
<https://www.gnu.org/licenses/>.
|
| 668 |
+
|
| 669 |
+
The GNU General Public License does not permit incorporating your program
|
| 670 |
+
into proprietary programs. If your program is a subroutine library, you
|
| 671 |
+
may consider it more useful to permit linking proprietary applications with
|
| 672 |
+
the library. If this is what you want to do, use the GNU Lesser General
|
| 673 |
+
Public License instead of this License. But first, please read
|
| 674 |
+
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
README.md
CHANGED
|
@@ -1,11 +1,349 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
|
|
|
|
|
|
| 7 |
pinned: false
|
| 8 |
-
license: mit
|
| 9 |
---
|
| 10 |
|
| 11 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
sdk_version: "3.9"
|
| 8 |
+
app_file: app.py
|
| 9 |
pinned: false
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 13 |
+
|
| 14 |
+
<p align="right">
|
| 15 |
+
<strong>中文</strong>
|
| 16 |
+
</p>
|
| 17 |
+
<div align="center">
|
| 18 |
+
|
| 19 |
+
# Genspark2API
|
| 20 |
+
|
| 21 |
+
_觉得有点意思的话 别忘了点个 ⭐_
|
| 22 |
+
|
| 23 |
+
<a href="https://t.me/+LGKwlC_xa-E5ZDk9">
|
| 24 |
+
<img src="https://telegram.org/img/website_icon.svg" width="16" height="16" style="vertical-align: middle;">
|
| 25 |
+
<span style="text-decoration: none; font-size: 12px; color: #0088cc; vertical-align: middle;">Telegram 交流群</span>
|
| 26 |
+
</a>
|
| 27 |
+
|
| 28 |
+
<sup><i>(原`coze-discord-proxy`交流群, 此项目仍可进此群**交流** / **反馈bug**)</i></sup>
|
| 29 |
+
<sup><i>(群内提供公益API、AI机器人)</i></sup>
|
| 30 |
+
|
| 31 |
+
</div>
|
| 32 |
+
|
| 33 |
+
> ⚠️目前官方强制校验`ReCaptchaV3`不通过则模型降智/生图异常,请参考[genspark-playwright-prxoy服务过V3验证](#genspark-playwright-prxoy服务过V3验证)并配置环境变量`RECAPTCHA_PROXY_URL`。
|
| 34 |
+
|
| 35 |
+
## 功能
|
| 36 |
+
|
| 37 |
+
- [x] 支持对话接口(流式/非流式)(`/chat/completions`)(请求非以下列表的模型会触发`Mixture-of-Agents`模式)
|
| 38 |
+
- **gpt-4o**
|
| 39 |
+
- **o1**
|
| 40 |
+
- **o3-mini-high**
|
| 41 |
+
- **claude-3-5-sonnet**
|
| 42 |
+
- **claude-3-7-sonnet**
|
| 43 |
+
- **claude-3-7-sonnet-thinking**
|
| 44 |
+
- **claude-3-5-haiku**
|
| 45 |
+
- **gemini-2.0-flash**
|
| 46 |
+
- **deep-seek-v3**
|
| 47 |
+
- **deep-seek-r1**
|
| 48 |
+
- [x] 支持**联网搜索**,在模型名后添加`-search`即可(如:`gpt-4o-search`)
|
| 49 |
+
- [x] 支持识别**图片**/**文件**多轮对话
|
| 50 |
+
- [x] 支持文生图接口(`/images/generations`)
|
| 51 |
+
- **flux**
|
| 52 |
+
- **flux-speed**
|
| 53 |
+
- **flux-pro/ultra**
|
| 54 |
+
- **ideogram**
|
| 55 |
+
- **ideogram/V_2A**
|
| 56 |
+
- **recraft-v3**
|
| 57 |
+
- **dall-e-3**
|
| 58 |
+
- **imagen3**
|
| 59 |
+
- [x] 支持文/图生视频接口(`/videos/generations`),详情查看[文/图生视频请求格式](#生视频请求格式)
|
| 60 |
+
- [x] 支持自定义请求头校验值(Authorization)
|
| 61 |
+
- [x] 支持cookie池(随机)
|
| 62 |
+
- [x] 支持请求失败自动切换cookie重试(需配置cookie池)
|
| 63 |
+
- [x] 可配置自动删除对话记录
|
| 64 |
+
- [x] 可配置代理请求(环境变量`PROXY_URL`)
|
| 65 |
+
- [x] 可配置Model绑定Chat(解决模型自动切换导致**降智**),详细请看[进阶配置](#解决模型自动切换导致降智问题)。
|
| 66 |
+
|
| 67 |
+
### 接口文档:
|
| 68 |
+
|
| 69 |
+
略
|
| 70 |
+
|
| 71 |
+
### 示例:
|
| 72 |
+
|
| 73 |
+
<span><img src="docs/img2.png" width="800"/></span>
|
| 74 |
+
|
| 75 |
+
## 如何使用
|
| 76 |
+
|
| 77 |
+
略
|
| 78 |
+
|
| 79 |
+
## 如何集成NextChat
|
| 80 |
+
|
| 81 |
+
填 接口地址(ip:端口/域名) 及 API-Key(`PROXY_SECRET`),其它的随便填随便选。
|
| 82 |
+
|
| 83 |
+
> 如果自己没有搭建NextChat面板,这里有个已经搭建好的可以使用 [NeatChat](https://ai.aytsao.cn/)
|
| 84 |
+
|
| 85 |
+
<span><img src="docs/img5.png" width="800"/></span>
|
| 86 |
+
|
| 87 |
+
## 如何集成one-api
|
| 88 |
+
|
| 89 |
+
填 `BaseURL`(ip:端口/域名) 及 密钥(`PROXY_SECRET`),其它的随便填随便选。
|
| 90 |
+
|
| 91 |
+
<span><img src="docs/img3.png" width="800"/></span>
|
| 92 |
+
|
| 93 |
+
## 部署
|
| 94 |
+
|
| 95 |
+
### 基于 Docker-Compose(All In One) 进行部署
|
| 96 |
+
|
| 97 |
+
```shell
|
| 98 |
+
docker-compose pull && docker-compose up -d
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
#### docker-compose.yml
|
| 102 |
+
|
| 103 |
+
```docker
|
| 104 |
+
version: '3.4'
|
| 105 |
+
|
| 106 |
+
services:
|
| 107 |
+
genspark2api:
|
| 108 |
+
image: deanxv/genspark2api:latest
|
| 109 |
+
container_name: genspark2api
|
| 110 |
+
restart: always
|
| 111 |
+
ports:
|
| 112 |
+
- "7055:7055"
|
| 113 |
+
volumes:
|
| 114 |
+
- ./data:/app/genspark2api/data
|
| 115 |
+
environment:
|
| 116 |
+
- GS_COOKIE=****** # cookie (多个请以,分隔)
|
| 117 |
+
- API_SECRET=123456 # [可选]接口密钥-修改此行为请求头校验的值(多个请以,分隔)
|
| 118 |
+
- TZ=Asia/Shanghai
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
### 基于 Docker 进行部署
|
| 122 |
+
|
| 123 |
+
```docker
|
| 124 |
+
docker run --name genspark2api -d --restart always \
|
| 125 |
+
-p 7055:7055 \
|
| 126 |
+
-v $(pwd)/data:/app/genspark2api/data \
|
| 127 |
+
-e GS_COOKIE=***** \
|
| 128 |
+
-e API_SECRET="123456" \
|
| 129 |
+
-e TZ=Asia/Shanghai \
|
| 130 |
+
deanxv/genspark2api
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
其中`API_SECRET`、`GS_COOKIE`修改为自己的。
|
| 134 |
+
|
| 135 |
+
如果上面的镜像无法拉取,可以尝试使用 GitHub 的 Docker 镜像,将上面的`deanxv/genspark2api`替换为`ghcr.io/deanxv/genspark2api`即可。
|
| 136 |
+
|
| 137 |
+
### 部署到第三方平台
|
| 138 |
+
|
| 139 |
+
<details>
|
| 140 |
+
<summary><strong>部署到 Hugging Face</strong></summary>
|
| 141 |
+
<div>
|
| 142 |
+
|
| 143 |
+
1. 首先 **fork** 一份代码到自己的GitHub仓库。
|
| 144 |
+
2. 登录 [Hugging Face](https://huggingface.co/),创建一个新的Space:
|
| 145 |
+
- 选择 **Docker** 作为Space类型
|
| 146 |
+
- 链接你fork的GitHub仓库
|
| 147 |
+
|
| 148 |
+
3. 配置环境变量(在Space的Settings -> Repository secrets中添加):
|
| 149 |
+
- `GS_COOKIE` - 你的cookie值,例如:`session_id=b0860552-21bc-48fc-a636-ab7bf76338df:b6528b346b053630d68d262aaa5ffb18fd1cce4e8eee5b39e7d4fa75d39568d5`
|
| 150 |
+
- `API_SECRET` - API密钥,用于验证请求
|
| 151 |
+
- `AUTO_MODEL_CHAT_MAP_TYPE` - 设置为1,启用自动模型绑定chat,解决模型降智问题
|
| 152 |
+
|
| 153 |
+
4. Hugging Face会自动检测仓库中的Dockerfile并基于此构建容器。
|
| 154 |
+
|
| 155 |
+
5. 构建完成后,你可以通过Hugging Face Space生成的URL访问你的API服务。
|
| 156 |
+
|
| 157 |
+
> 注意:Hugging Face免费账户有一定的资源限制,如果使用量大,可能需要升级到付费账户。
|
| 158 |
+
> 默认情况下,Hugging Face Spaces会在一段时间无活动后休眠,可以在设置中修改休眠策略。
|
| 159 |
+
|
| 160 |
+
</div>
|
| 161 |
+
</details>
|
| 162 |
+
|
| 163 |
+
<details>
|
| 164 |
+
<summary><strong>部署到 Zeabur</strong></summary>
|
| 165 |
+
<div>
|
| 166 |
+
|
| 167 |
+
[](https://zeabur.com?referralCode=deanxv&utm_source=deanxv)
|
| 168 |
+
|
| 169 |
+
> Zeabur 的服务器在国外,自动解决了网络的问题,~~同时免费的额度也足够个人使用~~
|
| 170 |
+
|
| 171 |
+
1. 首先 **fork** 一份代码。
|
| 172 |
+
2. 进入 [Zeabur](https://zeabur.com?referralCode=deanxv),使用github登录,进入控制台。
|
| 173 |
+
3. 在 Service -> Add Service,选择 Git(第一次使用需要先授权),选择你 fork 的仓库。
|
| 174 |
+
4. Deploy 会自动开始,先取消。
|
| 175 |
+
5. 添加环境变量
|
| 176 |
+
|
| 177 |
+
`GS_COOKIE:******` cookie (多个请以,分隔)
|
| 178 |
+
|
| 179 |
+
`API_SECRET:123456` [可选]接口密钥-修改此行为请求头校验的值(多个请以,分隔)(与openai-API-KEY用法一致)
|
| 180 |
+
|
| 181 |
+
保存。
|
| 182 |
+
|
| 183 |
+
6. 选择 Redeploy。
|
| 184 |
+
|
| 185 |
+
</div>
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
</details>
|
| 189 |
+
|
| 190 |
+
<details>
|
| 191 |
+
<summary><strong>部署到 Render</strong></summary>
|
| 192 |
+
<div>
|
| 193 |
+
|
| 194 |
+
> Render 提供免费额度,绑卡后可以进一步提升额度
|
| 195 |
+
|
| 196 |
+
Render 可以直接部署 docker 镜像,不需要 fork 仓库:[Render](https://dashboard.render.com)
|
| 197 |
+
|
| 198 |
+
</div>
|
| 199 |
+
</details>
|
| 200 |
+
|
| 201 |
+
## 配置
|
| 202 |
+
|
| 203 |
+
### 环境变量
|
| 204 |
+
|
| 205 |
+
1. `PORT=7055` [可选]端口,默认为7055
|
| 206 |
+
2. `DEBUG=true` [可选]DEBUG模式,可打印更多信息[true:打开、false:关闭]
|
| 207 |
+
3. `API_SECRET=123456` [可选]接口密钥-修改此行为请求头(Authorization)校验的值(同API-KEY)(多个请以,分隔)
|
| 208 |
+
4. `GS_COOKIE=******` cookie (多个请以,分隔)
|
| 209 |
+
5. `AUTO_DEL_CHAT=0` [可选]对话完成自动删除(默认:0)[0:关闭,1:开启]
|
| 210 |
+
6. `REQUEST_RATE_LIMIT=60` [可选]每分钟下的单ip请求速率限制,默认:60次/min
|
| 211 |
+
7. `PROXY_URL=http://127.0.0.1:10801` [可选]代理
|
| 212 |
+
8. `RECAPTCHA_PROXY_URL=http://127.0.0.1:7022` [可选]genspark-playwright-prxoy验证服务地址,仅填写域名或ip:端口即可。(示例:`RECAPTCHA_PROXY_URL=https://genspark-playwright-prxoy.com`或`RECAPTCHA_PROXY_URL=http://127.0.0.1:7022`),详情请看[genspark-playwright-prxoy服务过V3验证](#genspark-playwright-prxoy服务过V3验证)
|
| 213 |
+
9. `AUTO_MODEL_CHAT_MAP_TYPE=1` [可选]自动配置Model绑定Chat(默认:1)[0:关闭,1:开启]
|
| 214 |
+
10. `MODEL_CHAT_MAP=claude-3-7-sonnet=a649******00fa,gpt-4o=su74******47hd` [可选]Model绑定Chat(多个请以,分隔),详细请看[进阶配置](#解决模型自动切换导致降智问题)
|
| 215 |
+
11. `ROUTE_PREFIX=hf` [可选]路由前缀,默认为空,添加该变量后的接口示例:`/hf/v1/chat/completions`
|
| 216 |
+
12. `RATE_LIMIT_COOKIE_LOCK_DURATION=600` [可选]到达速率限制的cookie禁用时间,默认为600s
|
| 217 |
+
13. `REASONING_HIDE=0` [可选]**隐藏**推理过程(默认:0)[0:关闭,1:开启]
|
| 218 |
+
|
| 219 |
+
~~14.`SESSION_IMAGE_CHAT_MAP=aed9196b-********-4ed6e32f7e4d=0c6785e6-********-7ff6e5a2a29c,aefwer6b-********-casds22=fda234-********-sfaw123` [可选]Session绑定Image-Chat(多个请以,分隔),详细请看[进阶配置](#生图模型配置)~~
|
| 220 |
+
|
| 221 |
+
~~15. `YES_CAPTCHA_CLIENT_KEY=******` [可选]YesCaptcha Client Key 过谷歌验证,详细请看[使用YesCaptcha过谷歌验证](#使用YesCaptcha过谷歌验证)~~
|
| 222 |
+
|
| 223 |
+
### cookie获取方式
|
| 224 |
+
|
| 225 |
+
1. 打开**F12**开发者工具。
|
| 226 |
+
2. 发起对话。
|
| 227 |
+
3. 点击ask请求,请求头中的**cookie**即为环境变量**GS_COOKIE**所需值。
|
| 228 |
+
|
| 229 |
+
> **【注】** 其中`session_id=f9c60******cb6d`是必须的,其他内容可要可不要,即环境变量`GS_COOKIE=session_id=f9c60******cb6d`
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+

|
| 233 |
+
|
| 234 |
+
## 进阶配置
|
| 235 |
+
|
| 236 |
+
### 解决模型自动切换导致降智问题
|
| 237 |
+
|
| 238 |
+
#### 方案一 (默认启用此配置)【推荐】
|
| 239 |
+
|
| 240 |
+
> 配置环境变量 **AUTO_MODEL_CHAT_MAP_TYPE=1**
|
| 241 |
+
>
|
| 242 |
+
> 此配置下,会在调用模型时获取对话的id,并绑定模型。
|
| 243 |
+
|
| 244 |
+
#### 方案二
|
| 245 |
+
|
| 246 |
+
> 配置环境变量 MODEL_CHAT_MAP
|
| 247 |
+
>
|
| 248 |
+
> 【作用】指定对话,解决模型自动切换导致降智问题。
|
| 249 |
+
|
| 250 |
+
1. 打开**F12**开发者工具。
|
| 251 |
+
2. 选择需要绑定的对话的模型(示例:`claude-3-7-sonnet`),发起对话。
|
| 252 |
+
3. 点击ask请求,此时最上方url中的`id`(或响应中的`id`)即为此对话唯一id。
|
| 253 |
+

|
| 254 |
+
4. 配置环境变量 `MODEL_CHAT_MAP=claude-3-7-sonnet=3cdcc******474c5` (多个请以,分隔)
|
| 255 |
+
|
| 256 |
+
### genspark-playwright-prxoy服务过V3验证
|
| 257 |
+
|
| 258 |
+
1. docker部署genspark-playwright-prxoy
|
| 259 |
+
|
| 260 |
+
#### docker
|
| 261 |
+
|
| 262 |
+
```docker
|
| 263 |
+
docker run --name genspark-playwright-proxy -d --restart always \
|
| 264 |
+
-p 7022:7022 \
|
| 265 |
+
-v $(pwd)/data:/app/genspark-playwright-proxy/data \
|
| 266 |
+
-e PROXY_URL=http://account:pwd@ip:port # [可选] 推荐(住宅)动态代理,配置代理后过验证概率更高,但响应会变慢。
|
| 267 |
+
-e TZ=Asia/Shanghai \
|
| 268 |
+
deanxv/genspark-playwright-proxy
|
| 269 |
+
```
|
| 270 |
+
|
| 271 |
+
#### docker-compose
|
| 272 |
+
|
| 273 |
+
```docker-compose
|
| 274 |
+
version: '3.4'
|
| 275 |
+
|
| 276 |
+
services:
|
| 277 |
+
genspark-playwright-prxoy:
|
| 278 |
+
image: deanxv/genspark-playwright-proxy:latest
|
| 279 |
+
container_name: genspark-playwright-prxoy
|
| 280 |
+
restart: always
|
| 281 |
+
ports:
|
| 282 |
+
- "7022:7022"
|
| 283 |
+
volumes:
|
| 284 |
+
- ./data:/app/genspark-playwright-prxoy/data
|
| 285 |
+
environment:
|
| 286 |
+
- PROXY_URL=http://account:pwd@ip:port # [可选] 推荐(住宅)动态代理,配置代理后过验证概率更高,但响应会变慢。
|
| 287 |
+
```
|
| 288 |
+
|
| 289 |
+
2. 部署后配置`genspark2api`环境变量`RECAPTCHA_PROXY_URL`,仅填写域名或ip:端口即可。(示例:`RECAPTCHA_PROXY_URL=https://genspark-playwright-prxoy.com`或`RECAPTCHA_PROXY_URL=http://127.0.0.1:7022`)
|
| 290 |
+
|
| 291 |
+
3. 重启`genspark2api`服务。
|
| 292 |
+
|
| 293 |
+
## 报错排查
|
| 294 |
+
|
| 295 |
+
> `Detected Cloudflare Challenge Page`
|
| 296 |
+
>
|
| 297 |
+
|
| 298 |
+
被Cloudflare拦截出5s盾,可配置`PROXY_URL`。
|
| 299 |
+
|
| 300 |
+
(【推荐方案】[自建ipv6代理池绕过cf对ip的速率限制及5s盾](https://linux.do/t/topic/367413)或购买[IProyal](https://iproyal.cn/?r=244330))
|
| 301 |
+
|
| 302 |
+
> `Genspark Service Unavailable`
|
| 303 |
+
>
|
| 304 |
+
Genspark官方服务不可用,请稍后再试。
|
| 305 |
+
|
| 306 |
+
> `All cookies are temporarily unavailable.`
|
| 307 |
+
>
|
| 308 |
+
所有用户(cookie)均到达速率限制,更换用户cookie或稍后再试。
|
| 309 |
+
|
| 310 |
+
## 生视频请求格式
|
| 311 |
+
|
| 312 |
+
### Request
|
| 313 |
+
|
| 314 |
+
**Endpoint**: `POST /v1/videos/generations`
|
| 315 |
+
|
| 316 |
+
**Content-Type**: `application/json`
|
| 317 |
+
|
| 318 |
+
#### Request Parameters
|
| 319 |
+
|
| 320 |
+
| 字段 Field | 类型 Type | 必填 Required | 描述 Description | 可选值 Accepted Values |
|
| 321 |
+
|--------------|---------|-------------|---------------------------|-------------------------------------------------------------------------------------------------|
|
| 322 |
+
| model | string | 是 | 使用的视频生成模型 | 模型列表: `kling/v1.6/standard`\|`pixverse/v3.5/turbo`\|`lumadream/ray-2`\|`gemini/veo2`\|`hunyuan` |
|
| 323 |
+
| aspect_ratio | string | 是 | 视频宽高比 | `9:16` \| `16:9` \| `3:4` \|`1:1` \| `4:3` |
|
| 324 |
+
| duration | int | 是 | 视频时长(单位:秒) | 正整数 |
|
| 325 |
+
| prompt | string | 是 | 生成视频的文本描述 | - |
|
| 326 |
+
| auto_prompt | bool | 是 | 是否自动优化提示词 | `true` \| `false` |
|
| 327 |
+
| image | string | 否 | 用于视频生成的基底图片(Base64编码/url) | Base64字符串/url |
|
| 328 |
+
|
| 329 |
+
---
|
| 330 |
+
|
| 331 |
+
### Response
|
| 332 |
+
|
| 333 |
+
#### Response Object
|
| 334 |
+
|
| 335 |
+
```json
|
| 336 |
+
{
|
| 337 |
+
"created": 1677664796,
|
| 338 |
+
"data": [
|
| 339 |
+
{
|
| 340 |
+
"url": "https://example.com/video.mp4",
|
| 341 |
+
}
|
| 342 |
+
]
|
| 343 |
+
}
|
| 344 |
+
```
|
| 345 |
+
|
| 346 |
+
## 其他
|
| 347 |
+
|
| 348 |
+
**Genspark**(
|
| 349 |
+
注册领取1个月Plus): [https://www.genspark.ai](https://www.genspark.ai/invite?invite_code=YjVjMGRkYWVMZmE4YUw5MDc0TDM1ODlMZDYwMzQ4OTJlNmEx)
|
check/check.go
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package check
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"genspark2api/common"
|
| 5 |
+
"genspark2api/common/config"
|
| 6 |
+
logger "genspark2api/common/loggger"
|
| 7 |
+
"github.com/samber/lo"
|
| 8 |
+
"regexp"
|
| 9 |
+
"strings"
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
func CheckEnvVariable() {
|
| 13 |
+
logger.SysLog("environment variable checking...")
|
| 14 |
+
|
| 15 |
+
if config.GSCookie == "" {
|
| 16 |
+
logger.FatalLog("环境变量 GS_COOKIE 未设置")
|
| 17 |
+
}
|
| 18 |
+
if config.YesCaptchaClientKey == "" {
|
| 19 |
+
//logger.SysLog("环境变量 YES_CAPTCHA_CLIENT_KEY 未设置,将无法使用 YesCaptcha 过谷歌验证,导致无法调用文生图模型 \n ClientKey获取地址:https://yescaptcha.com/i/021iAE")
|
| 20 |
+
}
|
| 21 |
+
if config.ModelChatMapStr != "" {
|
| 22 |
+
pattern := `^([a-zA-Z0-9\-\/]+=([a-zA-Z0-9\-\.]+))(,[a-zA-Z0-9\-\/]+=([a-zA-Z0-9\-\.]+))*`
|
| 23 |
+
match, _ := regexp.MatchString(pattern, config.ModelChatMapStr)
|
| 24 |
+
if !match {
|
| 25 |
+
logger.FatalLog("环境变量 MODEL_CHAT_MAP 设置有误")
|
| 26 |
+
} else {
|
| 27 |
+
modelChatMap := make(map[string]string)
|
| 28 |
+
pairs := strings.Split(config.ModelChatMapStr, ",")
|
| 29 |
+
|
| 30 |
+
for _, pair := range pairs {
|
| 31 |
+
kv := strings.Split(pair, "=")
|
| 32 |
+
if !lo.Contains(common.DefaultOpenaiModelList, kv[0]) {
|
| 33 |
+
logger.FatalLog("环境变量 MODEL_CHAT_MAP 中 MODEL 有误")
|
| 34 |
+
}
|
| 35 |
+
modelChatMap[kv[0]] = kv[1]
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
config.ModelChatMap = modelChatMap
|
| 39 |
+
|
| 40 |
+
if config.AutoModelChatMapType == 1 {
|
| 41 |
+
logger.FatalLog("环境变量 MODEL_CHAT_MAP 有值时,环境变量 AUTO_MODEL_CHAT_MAP_TYPE 不能设置为1")
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
if config.SessionImageChatMapStr != "" {
|
| 48 |
+
pattern := `^([a-zA-Z0-9\-\/]+=([a-zA-Z0-9\-\.]+))(,[a-zA-Z0-9\-\/]+=([a-zA-Z0-9\-\.]+))*`
|
| 49 |
+
match, _ := regexp.MatchString(pattern, config.SessionImageChatMapStr)
|
| 50 |
+
if !match {
|
| 51 |
+
logger.FatalLog("环境变量 SESSION_IMAGE_CHAT_MAP 设置有误")
|
| 52 |
+
} else {
|
| 53 |
+
sessionImageChatMap := make(map[string]string)
|
| 54 |
+
pairs := strings.Split(config.SessionImageChatMapStr, ",")
|
| 55 |
+
|
| 56 |
+
for _, pair := range pairs {
|
| 57 |
+
kv := strings.Split(pair, "=")
|
| 58 |
+
sessionImageChatMap["session_id="+kv[0]] = kv[1]
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
config.SessionImageChatMap = sessionImageChatMap
|
| 62 |
+
}
|
| 63 |
+
} else {
|
| 64 |
+
//logger.SysLog("环境变量 SESSION_IMAGE_CHAT_MAP 未设置,生图可能会异常")
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
logger.SysLog("environment variable check pass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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package config
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"errors"
|
| 5 |
+
"genspark2api/common/env"
|
| 6 |
+
"genspark2api/yescaptcha"
|
| 7 |
+
"math/rand"
|
| 8 |
+
"os"
|
| 9 |
+
"strings"
|
| 10 |
+
"sync"
|
| 11 |
+
"time"
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
var ApiSecret = os.Getenv("API_SECRET")
|
| 15 |
+
var ApiSecrets = strings.Split(os.Getenv("API_SECRET"), ",")
|
| 16 |
+
|
| 17 |
+
var GSCookie = os.Getenv("GS_COOKIE")
|
| 18 |
+
|
| 19 |
+
//var GSCookies = strings.Split(os.Getenv("GS_COOKIE"), ",")
|
| 20 |
+
|
| 21 |
+
// var IpBlackList = os.Getenv("IP_BLACK_LIST")
|
| 22 |
+
var IpBlackList = strings.Split(os.Getenv("IP_BLACK_LIST"), ",")
|
| 23 |
+
|
| 24 |
+
var AutoDelChat = env.Int("AUTO_DEL_CHAT", 0)
|
| 25 |
+
var ProxyUrl = env.String("PROXY_URL", "")
|
| 26 |
+
var AutoModelChatMapType = env.Int("AUTO_MODEL_CHAT_MAP_TYPE", 1)
|
| 27 |
+
var YesCaptchaClientKey = env.String("YES_CAPTCHA_CLIENT_KEY", "")
|
| 28 |
+
|
| 29 |
+
// var CheatUrl = env.String("CHEAT_URL", "https://gs-cheat.aytsao.cn/genspark/create/req/body")
|
| 30 |
+
var RecaptchaProxyUrl = env.String("RECAPTCHA_PROXY_URL", "")
|
| 31 |
+
|
| 32 |
+
// 隐藏思考过程
|
| 33 |
+
var ReasoningHide = env.Int("REASONING_HIDE", 0)
|
| 34 |
+
|
| 35 |
+
// 前置message
|
| 36 |
+
var PRE_MESSAGES_JSON = env.String("PRE_MESSAGES_JSON", "")
|
| 37 |
+
|
| 38 |
+
var RateLimitCookieLockDuration = env.Int("RATE_LIMIT_COOKIE_LOCK_DURATION", 10*60)
|
| 39 |
+
|
| 40 |
+
// 路由前缀
|
| 41 |
+
var RoutePrefix = env.String("ROUTE_PREFIX", "")
|
| 42 |
+
var ModelChatMapStr = env.String("MODEL_CHAT_MAP", "")
|
| 43 |
+
var ModelChatMap = make(map[string]string)
|
| 44 |
+
var SessionImageChatMap = make(map[string]string)
|
| 45 |
+
var GlobalSessionManager *SessionManager
|
| 46 |
+
|
| 47 |
+
var SessionImageChatMapStr = env.String("SESSION_IMAGE_CHAT_MAP", "")
|
| 48 |
+
var YescaptchaClient *yescaptcha.Client
|
| 49 |
+
|
| 50 |
+
var AllDialogRecordEnable = os.Getenv("ALL_DIALOG_RECORD_ENABLE")
|
| 51 |
+
var RequestOutTime = os.Getenv("REQUEST_OUT_TIME")
|
| 52 |
+
var StreamRequestOutTime = os.Getenv("STREAM_REQUEST_OUT_TIME")
|
| 53 |
+
var SwaggerEnable = os.Getenv("SWAGGER_ENABLE")
|
| 54 |
+
var OnlyOpenaiApi = os.Getenv("ONLY_OPENAI_API")
|
| 55 |
+
|
| 56 |
+
var DebugEnabled = os.Getenv("DEBUG") == "true"
|
| 57 |
+
|
| 58 |
+
var RateLimitKeyExpirationDuration = 20 * time.Minute
|
| 59 |
+
|
| 60 |
+
var RequestOutTimeDuration = 5 * time.Minute
|
| 61 |
+
|
| 62 |
+
var (
|
| 63 |
+
RequestRateLimitNum = env.Int("REQUEST_RATE_LIMIT", 60)
|
| 64 |
+
RequestRateLimitDuration int64 = 1 * 60
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
type RateLimitCookie struct {
|
| 68 |
+
ExpirationTime time.Time // 过期时间
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
var (
|
| 72 |
+
rateLimitCookies sync.Map // 使用 sync.Map 管理限速 Cookie
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
func AddRateLimitCookie(cookie string, expirationTime time.Time) {
|
| 76 |
+
rateLimitCookies.Store(cookie, RateLimitCookie{
|
| 77 |
+
ExpirationTime: expirationTime,
|
| 78 |
+
})
|
| 79 |
+
//fmt.Printf("Storing cookie: %s with value: %+v\n", cookie, RateLimitCookie{ExpirationTime: expirationTime})
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
type CookieManager struct {
|
| 83 |
+
Cookies []string
|
| 84 |
+
currentIndex int
|
| 85 |
+
mu sync.Mutex
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
var (
|
| 89 |
+
GSCookies []string // 存储所有的 cookies
|
| 90 |
+
cookiesMutex sync.Mutex // 保护 GSCookies 的互斥锁
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
// InitGSCookies 初始化 GSCookies
|
| 94 |
+
func InitGSCookies() {
|
| 95 |
+
cookiesMutex.Lock()
|
| 96 |
+
defer cookiesMutex.Unlock()
|
| 97 |
+
|
| 98 |
+
GSCookies = []string{}
|
| 99 |
+
|
| 100 |
+
// 从环境变量中读取 GS_COOKIE 并拆分为切片
|
| 101 |
+
cookieStr := os.Getenv("GS_COOKIE")
|
| 102 |
+
if cookieStr != "" {
|
| 103 |
+
|
| 104 |
+
for _, cookie := range strings.Split(cookieStr, ",") {
|
| 105 |
+
// 如果 cookie 不包含 "session_id=",则添加前缀
|
| 106 |
+
if !strings.Contains(cookie, "session_id=") {
|
| 107 |
+
cookie = "session_id=" + cookie
|
| 108 |
+
}
|
| 109 |
+
GSCookies = append(GSCookies, cookie)
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
// RemoveCookie 删除指定的 cookie(支持并发)
|
| 115 |
+
func RemoveCookie(cookieToRemove string) {
|
| 116 |
+
cookiesMutex.Lock()
|
| 117 |
+
defer cookiesMutex.Unlock()
|
| 118 |
+
|
| 119 |
+
// 创建一个新的切片,过滤掉需要删除的 cookie
|
| 120 |
+
var newCookies []string
|
| 121 |
+
for _, cookie := range GetGSCookies() {
|
| 122 |
+
if cookie != cookieToRemove {
|
| 123 |
+
newCookies = append(newCookies, cookie)
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
// 更新 GSCookies
|
| 128 |
+
GSCookies = newCookies
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
// GetGSCookies 获取 GSCookies 的副本
|
| 132 |
+
func GetGSCookies() []string {
|
| 133 |
+
//cookiesMutex.Lock()
|
| 134 |
+
//defer cookiesMutex.Unlock()
|
| 135 |
+
|
| 136 |
+
// 返回 GSCookies 的副本,避免外部直接修改
|
| 137 |
+
cookiesCopy := make([]string, len(GSCookies))
|
| 138 |
+
copy(cookiesCopy, GSCookies)
|
| 139 |
+
return cookiesCopy
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
// NewCookieManager 创建 CookieManager
|
| 143 |
+
func NewCookieManager() *CookieManager {
|
| 144 |
+
var validCookies []string
|
| 145 |
+
// 遍历 GSCookies
|
| 146 |
+
for _, cookie := range GetGSCookies() {
|
| 147 |
+
cookie = strings.TrimSpace(cookie)
|
| 148 |
+
if cookie == "" {
|
| 149 |
+
continue // 忽略空字符串
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
// 检查是否在 RateLimitCookies 中
|
| 153 |
+
if value, ok := rateLimitCookies.Load(cookie); ok {
|
| 154 |
+
rateLimitCookie, ok := value.(RateLimitCookie) // 正确转换为 RateLimitCookie
|
| 155 |
+
if !ok {
|
| 156 |
+
continue
|
| 157 |
+
}
|
| 158 |
+
if rateLimitCookie.ExpirationTime.After(time.Now()) {
|
| 159 |
+
// 如果未过期,忽略该 cookie
|
| 160 |
+
continue
|
| 161 |
+
} else {
|
| 162 |
+
// 如果已过期,从 RateLimitCookies 中删除
|
| 163 |
+
rateLimitCookies.Delete(cookie)
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
// 添加到有效 cookie 列表
|
| 168 |
+
validCookies = append(validCookies, cookie)
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
return &CookieManager{
|
| 172 |
+
Cookies: validCookies,
|
| 173 |
+
currentIndex: 0,
|
| 174 |
+
}
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
func IsRateLimited(cookie string) bool {
|
| 178 |
+
if value, ok := rateLimitCookies.Load(cookie); ok {
|
| 179 |
+
rateLimitCookie := value.(RateLimitCookie)
|
| 180 |
+
return rateLimitCookie.ExpirationTime.After(time.Now())
|
| 181 |
+
}
|
| 182 |
+
return false
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
func (cm *CookieManager) RemoveCookie(cookieToRemove string) error {
|
| 186 |
+
cm.mu.Lock()
|
| 187 |
+
defer cm.mu.Unlock()
|
| 188 |
+
|
| 189 |
+
if len(cm.Cookies) == 0 {
|
| 190 |
+
return errors.New("no cookies available")
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
// 查找要删除的cookie的索引
|
| 194 |
+
index := -1
|
| 195 |
+
for i, cookie := range cm.Cookies {
|
| 196 |
+
if cookie == cookieToRemove {
|
| 197 |
+
index = i
|
| 198 |
+
break
|
| 199 |
+
}
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
// 如果没找到要删除的cookie
|
| 203 |
+
if index == -1 {
|
| 204 |
+
return errors.New("RemoveCookie -> cookie not found")
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
// 从切片中删除cookie
|
| 208 |
+
cm.Cookies = append(cm.Cookies[:index], cm.Cookies[index+1:]...)
|
| 209 |
+
|
| 210 |
+
// 如果当前索引大于或等于删除后的切片长度,重置为0
|
| 211 |
+
if cm.currentIndex >= len(cm.Cookies) {
|
| 212 |
+
cm.currentIndex = 0
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
return nil
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
func (cm *CookieManager) GetNextCookie() (string, error) {
|
| 219 |
+
cm.mu.Lock()
|
| 220 |
+
defer cm.mu.Unlock()
|
| 221 |
+
|
| 222 |
+
if len(cm.Cookies) == 0 {
|
| 223 |
+
return "", errors.New("no cookies available")
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
cm.currentIndex = (cm.currentIndex + 1) % len(cm.Cookies)
|
| 227 |
+
return cm.Cookies[cm.currentIndex], nil
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
func (cm *CookieManager) GetRandomCookie() (string, error) {
|
| 231 |
+
cm.mu.Lock()
|
| 232 |
+
defer cm.mu.Unlock()
|
| 233 |
+
|
| 234 |
+
if len(cm.Cookies) == 0 {
|
| 235 |
+
return "", errors.New("no cookies available")
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
// 生成随机索引
|
| 239 |
+
randomIndex := rand.Intn(len(cm.Cookies))
|
| 240 |
+
// 更新当前索引
|
| 241 |
+
cm.currentIndex = randomIndex
|
| 242 |
+
|
| 243 |
+
return cm.Cookies[randomIndex], nil
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
// SessionKey 定义复合键结构
|
| 247 |
+
type SessionKey struct {
|
| 248 |
+
Cookie string
|
| 249 |
+
Model string
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
// SessionManager 会话管理器
|
| 253 |
+
type SessionManager struct {
|
| 254 |
+
sessions map[SessionKey]string
|
| 255 |
+
mutex sync.RWMutex
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
// NewSessionManager 创建新的会话管理器
|
| 259 |
+
func NewSessionManager() *SessionManager {
|
| 260 |
+
return &SessionManager{
|
| 261 |
+
sessions: make(map[SessionKey]string),
|
| 262 |
+
}
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
// AddSession 添加会话记录(写操作,需要写锁)
|
| 266 |
+
func (sm *SessionManager) AddSession(cookie string, model string, chatID string) {
|
| 267 |
+
sm.mutex.Lock()
|
| 268 |
+
defer sm.mutex.Unlock()
|
| 269 |
+
|
| 270 |
+
key := SessionKey{
|
| 271 |
+
Cookie: cookie,
|
| 272 |
+
Model: model,
|
| 273 |
+
}
|
| 274 |
+
sm.sessions[key] = chatID
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
// GetChatID 获取会话ID(读操作,使用读锁)
|
| 278 |
+
func (sm *SessionManager) GetChatID(cookie string, model string) (string, bool) {
|
| 279 |
+
sm.mutex.RLock()
|
| 280 |
+
defer sm.mutex.RUnlock()
|
| 281 |
+
|
| 282 |
+
key := SessionKey{
|
| 283 |
+
Cookie: cookie,
|
| 284 |
+
Model: model,
|
| 285 |
+
}
|
| 286 |
+
chatID, exists := sm.sessions[key]
|
| 287 |
+
return chatID, exists
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
// DeleteSession 删除会话记录(写操作,需要写锁)
|
| 291 |
+
func (sm *SessionManager) DeleteSession(cookie string, model string) {
|
| 292 |
+
sm.mutex.Lock()
|
| 293 |
+
defer sm.mutex.Unlock()
|
| 294 |
+
|
| 295 |
+
key := SessionKey{
|
| 296 |
+
Cookie: cookie,
|
| 297 |
+
Model: model,
|
| 298 |
+
}
|
| 299 |
+
delete(sm.sessions, key)
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
// GetChatIDsByCookie 获取指定cookie关联的所有chatID列表(读操作,使用读锁)
|
| 303 |
+
func (sm *SessionManager) GetChatIDsByCookie(cookie string) []string {
|
| 304 |
+
sm.mutex.RLock()
|
| 305 |
+
defer sm.mutex.RUnlock()
|
| 306 |
+
|
| 307 |
+
var chatIDs []string
|
| 308 |
+
for key, chatID := range sm.sessions {
|
| 309 |
+
if key.Cookie == cookie {
|
| 310 |
+
chatIDs = append(chatIDs, chatID)
|
| 311 |
+
}
|
| 312 |
+
}
|
| 313 |
+
return chatIDs
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
type SessionMapManager struct {
|
| 317 |
+
sessionMap map[string]string
|
| 318 |
+
keys []string
|
| 319 |
+
currentIndex int
|
| 320 |
+
mu sync.Mutex
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
func NewSessionMapManager() *SessionMapManager {
|
| 324 |
+
// 从初始map中提取所有的key
|
| 325 |
+
keys := make([]string, 0, len(SessionImageChatMap))
|
| 326 |
+
for k := range SessionImageChatMap {
|
| 327 |
+
keys = append(keys, k)
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
return &SessionMapManager{
|
| 331 |
+
sessionMap: SessionImageChatMap,
|
| 332 |
+
keys: keys,
|
| 333 |
+
currentIndex: 0,
|
| 334 |
+
}
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
// GetCurrentKeyValue 获取当前索引对应的键值对
|
| 338 |
+
func (sm *SessionMapManager) GetCurrentKeyValue() (string, string, error) {
|
| 339 |
+
sm.mu.Lock()
|
| 340 |
+
defer sm.mu.Unlock()
|
| 341 |
+
|
| 342 |
+
if len(sm.keys) == 0 {
|
| 343 |
+
return "", "", errors.New("no sessions available")
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
currentKey := sm.keys[sm.currentIndex]
|
| 347 |
+
return currentKey, sm.sessionMap[currentKey], nil
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
// GetNextKeyValue 获取下一个键值对
|
| 351 |
+
func (sm *SessionMapManager) GetNextKeyValue() (string, string, error) {
|
| 352 |
+
sm.mu.Lock()
|
| 353 |
+
defer sm.mu.Unlock()
|
| 354 |
+
|
| 355 |
+
if len(sm.keys) == 0 {
|
| 356 |
+
return "", "", errors.New("no sessions available")
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
sm.currentIndex = (sm.currentIndex + 1) % len(sm.keys)
|
| 360 |
+
currentKey := sm.keys[sm.currentIndex]
|
| 361 |
+
return currentKey, sm.sessionMap[currentKey], nil
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
// GetRandomKeyValue 随机获取一个键值对
|
| 365 |
+
func (sm *SessionMapManager) GetRandomKeyValue() (string, string, error) {
|
| 366 |
+
sm.mu.Lock()
|
| 367 |
+
defer sm.mu.Unlock()
|
| 368 |
+
|
| 369 |
+
if len(sm.keys) == 0 {
|
| 370 |
+
return "", "", errors.New("no sessions available")
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
randomIndex := rand.Intn(len(sm.keys))
|
| 374 |
+
sm.currentIndex = randomIndex
|
| 375 |
+
currentKey := sm.keys[randomIndex]
|
| 376 |
+
return currentKey, sm.sessionMap[currentKey], nil
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
// AddKeyValue 添加新的键值对
|
| 380 |
+
func (sm *SessionMapManager) AddKeyValue(key, value string) {
|
| 381 |
+
sm.mu.Lock()
|
| 382 |
+
defer sm.mu.Unlock()
|
| 383 |
+
|
| 384 |
+
// 如果key不存在,则添加到keys切片中
|
| 385 |
+
if _, exists := sm.sessionMap[key]; !exists {
|
| 386 |
+
sm.keys = append(sm.keys, key)
|
| 387 |
+
}
|
| 388 |
+
sm.sessionMap[key] = value
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
// RemoveKey 删除指定的键值对
|
| 392 |
+
func (sm *SessionMapManager) RemoveKey(key string) {
|
| 393 |
+
sm.mu.Lock()
|
| 394 |
+
defer sm.mu.Unlock()
|
| 395 |
+
|
| 396 |
+
if _, exists := sm.sessionMap[key]; !exists {
|
| 397 |
+
return
|
| 398 |
+
}
|
| 399 |
+
|
| 400 |
+
// 从map中删除
|
| 401 |
+
delete(sm.sessionMap, key)
|
| 402 |
+
|
| 403 |
+
// 从keys切片中删除
|
| 404 |
+
for i, k := range sm.keys {
|
| 405 |
+
if k == key {
|
| 406 |
+
sm.keys = append(sm.keys[:i], sm.keys[i+1:]...)
|
| 407 |
+
break
|
| 408 |
+
}
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
// 调整currentIndex如果需要
|
| 412 |
+
if sm.currentIndex >= len(sm.keys) && len(sm.keys) > 0 {
|
| 413 |
+
sm.currentIndex = len(sm.keys) - 1
|
| 414 |
+
}
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
// GetSize 获取当前map的大小
|
| 418 |
+
func (sm *SessionMapManager) GetSize() int {
|
| 419 |
+
sm.mu.Lock()
|
| 420 |
+
defer sm.mu.Unlock()
|
| 421 |
+
return len(sm.keys)
|
| 422 |
+
}
|
common/constants.go
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package common
|
| 2 |
+
|
| 3 |
+
import "time"
|
| 4 |
+
|
| 5 |
+
var StartTime = time.Now().Unix() // unit: second
|
| 6 |
+
var Version = "v1.12.0" // this hard coding will be replaced automatically when building, no need to manually change
|
| 7 |
+
|
| 8 |
+
var DefaultOpenaiModelList = []string{
|
| 9 |
+
"gpt-4o",
|
| 10 |
+
"o1",
|
| 11 |
+
"o3-mini-high",
|
| 12 |
+
"claude-3-7-sonnet",
|
| 13 |
+
"claude-3-7-sonnet-thinking",
|
| 14 |
+
"claude-3-5-haiku",
|
| 15 |
+
"gemini-2.0-flash",
|
| 16 |
+
"deep-seek-v3",
|
| 17 |
+
"deep-seek-r1",
|
| 18 |
+
|
| 19 |
+
"flux",
|
| 20 |
+
"flux-speed",
|
| 21 |
+
"flux-pro/ultra",
|
| 22 |
+
"ideogram",
|
| 23 |
+
"ideogram/V_2A",
|
| 24 |
+
"recraft-v3",
|
| 25 |
+
"dall-e-3",
|
| 26 |
+
"imagen3",
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
var TextModelList = []string{
|
| 30 |
+
"gpt-4o",
|
| 31 |
+
"o1",
|
| 32 |
+
"o3-mini-high",
|
| 33 |
+
"claude-3-7-sonnet",
|
| 34 |
+
"claude-3-7-sonnet-thinking",
|
| 35 |
+
"claude-3-5-haiku",
|
| 36 |
+
"gemini-2.0-flash",
|
| 37 |
+
"deep-seek-v3",
|
| 38 |
+
"deep-seek-r1",
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
var MixtureModelList = []string{
|
| 42 |
+
"gpt-4o",
|
| 43 |
+
"claude-3-7-sonnet",
|
| 44 |
+
"gemini-2.0-flash",
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
var ImageModelList = []string{
|
| 48 |
+
"flux",
|
| 49 |
+
"flux-speed",
|
| 50 |
+
"flux-pro/ultra",
|
| 51 |
+
"ideogram",
|
| 52 |
+
"ideogram/V_2A",
|
| 53 |
+
"recraft-v3",
|
| 54 |
+
"dall-e-3",
|
| 55 |
+
"imagen3",
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
var VideoModelList = []string{
|
| 59 |
+
"kling/v1.6/standard",
|
| 60 |
+
"pixverse/v3.5/turbo",
|
| 61 |
+
"lumadream/ray-2",
|
| 62 |
+
"gemini/veo2",
|
| 63 |
+
"hunyuan",
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
//
|
common/env/helper.go
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package env
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"os"
|
| 5 |
+
"strconv"
|
| 6 |
+
)
|
| 7 |
+
|
| 8 |
+
func Bool(env string, defaultValue bool) bool {
|
| 9 |
+
if env == "" || os.Getenv(env) == "" {
|
| 10 |
+
return defaultValue
|
| 11 |
+
}
|
| 12 |
+
return os.Getenv(env) == "true"
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
func Int(env string, defaultValue int) int {
|
| 16 |
+
if env == "" || os.Getenv(env) == "" {
|
| 17 |
+
return defaultValue
|
| 18 |
+
}
|
| 19 |
+
num, err := strconv.Atoi(os.Getenv(env))
|
| 20 |
+
if err != nil {
|
| 21 |
+
return defaultValue
|
| 22 |
+
}
|
| 23 |
+
return num
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
func Float64(env string, defaultValue float64) float64 {
|
| 27 |
+
if env == "" || os.Getenv(env) == "" {
|
| 28 |
+
return defaultValue
|
| 29 |
+
}
|
| 30 |
+
num, err := strconv.ParseFloat(os.Getenv(env), 64)
|
| 31 |
+
if err != nil {
|
| 32 |
+
return defaultValue
|
| 33 |
+
}
|
| 34 |
+
return num
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
func String(env string, defaultValue string) string {
|
| 38 |
+
if env == "" || os.Getenv(env) == "" {
|
| 39 |
+
return defaultValue
|
| 40 |
+
}
|
| 41 |
+
return os.Getenv(env)
|
| 42 |
+
}
|
common/helper/helper.go
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package helper
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"fmt"
|
| 5 |
+
"genspark2api/common/random"
|
| 6 |
+
"github.com/gin-gonic/gin"
|
| 7 |
+
"html/template"
|
| 8 |
+
"log"
|
| 9 |
+
"net"
|
| 10 |
+
"os/exec"
|
| 11 |
+
"runtime"
|
| 12 |
+
"strconv"
|
| 13 |
+
"strings"
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
func OpenBrowser(url string) {
|
| 17 |
+
var err error
|
| 18 |
+
|
| 19 |
+
switch runtime.GOOS {
|
| 20 |
+
case "linux":
|
| 21 |
+
err = exec.Command("xdg-open", url).Start()
|
| 22 |
+
case "windows":
|
| 23 |
+
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
|
| 24 |
+
case "darwin":
|
| 25 |
+
err = exec.Command("open", url).Start()
|
| 26 |
+
}
|
| 27 |
+
if err != nil {
|
| 28 |
+
log.Println(err)
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
func GetIp() (ip string) {
|
| 33 |
+
ips, err := net.InterfaceAddrs()
|
| 34 |
+
if err != nil {
|
| 35 |
+
log.Println(err)
|
| 36 |
+
return ip
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
for _, a := range ips {
|
| 40 |
+
if ipNet, ok := a.(*net.IPNet); ok && !ipNet.IP.IsLoopback() {
|
| 41 |
+
if ipNet.IP.To4() != nil {
|
| 42 |
+
ip = ipNet.IP.String()
|
| 43 |
+
if strings.HasPrefix(ip, "10") {
|
| 44 |
+
return
|
| 45 |
+
}
|
| 46 |
+
if strings.HasPrefix(ip, "172") {
|
| 47 |
+
return
|
| 48 |
+
}
|
| 49 |
+
if strings.HasPrefix(ip, "192.168") {
|
| 50 |
+
return
|
| 51 |
+
}
|
| 52 |
+
ip = ""
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
return
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
var sizeKB = 1024
|
| 60 |
+
var sizeMB = sizeKB * 1024
|
| 61 |
+
var sizeGB = sizeMB * 1024
|
| 62 |
+
|
| 63 |
+
func Bytes2Size(num int64) string {
|
| 64 |
+
numStr := ""
|
| 65 |
+
unit := "B"
|
| 66 |
+
if num/int64(sizeGB) > 1 {
|
| 67 |
+
numStr = fmt.Sprintf("%.2f", float64(num)/float64(sizeGB))
|
| 68 |
+
unit = "GB"
|
| 69 |
+
} else if num/int64(sizeMB) > 1 {
|
| 70 |
+
numStr = fmt.Sprintf("%d", int(float64(num)/float64(sizeMB)))
|
| 71 |
+
unit = "MB"
|
| 72 |
+
} else if num/int64(sizeKB) > 1 {
|
| 73 |
+
numStr = fmt.Sprintf("%d", int(float64(num)/float64(sizeKB)))
|
| 74 |
+
unit = "KB"
|
| 75 |
+
} else {
|
| 76 |
+
numStr = fmt.Sprintf("%d", num)
|
| 77 |
+
}
|
| 78 |
+
return numStr + " " + unit
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
func Interface2String(inter interface{}) string {
|
| 82 |
+
switch inter := inter.(type) {
|
| 83 |
+
case string:
|
| 84 |
+
return inter
|
| 85 |
+
case int:
|
| 86 |
+
return fmt.Sprintf("%d", inter)
|
| 87 |
+
case float64:
|
| 88 |
+
return fmt.Sprintf("%f", inter)
|
| 89 |
+
}
|
| 90 |
+
return "Not Implemented"
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
func UnescapeHTML(x string) interface{} {
|
| 94 |
+
return template.HTML(x)
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
func IntMax(a int, b int) int {
|
| 98 |
+
if a >= b {
|
| 99 |
+
return a
|
| 100 |
+
} else {
|
| 101 |
+
return b
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
func GenRequestID() string {
|
| 106 |
+
return GetTimeString() + random.GetRandomNumberString(8)
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
func GetResponseID(c *gin.Context) string {
|
| 110 |
+
logID := c.GetString(RequestIdKey)
|
| 111 |
+
return fmt.Sprintf("chatcmpl-%s", logID)
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
func Max(a int, b int) int {
|
| 115 |
+
if a >= b {
|
| 116 |
+
return a
|
| 117 |
+
} else {
|
| 118 |
+
return b
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
func AssignOrDefault(value string, defaultValue string) string {
|
| 123 |
+
if len(value) != 0 {
|
| 124 |
+
return value
|
| 125 |
+
}
|
| 126 |
+
return defaultValue
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
func MessageWithRequestId(message string, id string) string {
|
| 130 |
+
return fmt.Sprintf("%s (request id: %s)", message, id)
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
func String2Int(str string) int {
|
| 134 |
+
num, err := strconv.Atoi(str)
|
| 135 |
+
if err != nil {
|
| 136 |
+
return 0
|
| 137 |
+
}
|
| 138 |
+
return num
|
| 139 |
+
}
|
common/helper/key.go
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package helper
|
| 2 |
+
|
| 3 |
+
const (
|
| 4 |
+
RequestIdKey = "X-Request-Id"
|
| 5 |
+
)
|
common/helper/time.go
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package helper
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"fmt"
|
| 5 |
+
"time"
|
| 6 |
+
)
|
| 7 |
+
|
| 8 |
+
func GetTimestamp() int64 {
|
| 9 |
+
return time.Now().Unix()
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
func GetTimeString() string {
|
| 13 |
+
now := time.Now()
|
| 14 |
+
return fmt.Sprintf("%s%d", now.Format("20060102150405"), now.UnixNano()%1e9)
|
| 15 |
+
}
|
common/init.go
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package common
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"flag"
|
| 5 |
+
"fmt"
|
| 6 |
+
"log"
|
| 7 |
+
"os"
|
| 8 |
+
"path/filepath"
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
var (
|
| 12 |
+
Port = flag.Int("port", 7055, "the listening port")
|
| 13 |
+
PrintVersion = flag.Bool("version", false, "print version and exit")
|
| 14 |
+
PrintHelp = flag.Bool("help", false, "print help and exit")
|
| 15 |
+
LogDir = flag.String("log-dir", "", "specify the log directory")
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
// UploadPath Maybe override by ENV_VAR
|
| 19 |
+
var UploadPath = "upload"
|
| 20 |
+
|
| 21 |
+
func printHelp() {
|
| 22 |
+
fmt.Println("genspark2api" + Version + "")
|
| 23 |
+
fmt.Println("Copyright (C) 2024 Dean. All rights reserved.")
|
| 24 |
+
fmt.Println("GitHub: https://github.com/deanxv/genspark2api ")
|
| 25 |
+
fmt.Println("Usage: genspark2api [--port <port>] [--log-dir <log directory>] [--version] [--help]")
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
func init() {
|
| 29 |
+
flag.Parse()
|
| 30 |
+
|
| 31 |
+
if *PrintVersion {
|
| 32 |
+
fmt.Println(Version)
|
| 33 |
+
os.Exit(0)
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
if *PrintHelp {
|
| 37 |
+
printHelp()
|
| 38 |
+
os.Exit(0)
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
if os.Getenv("UPLOAD_PATH") != "" {
|
| 42 |
+
UploadPath = os.Getenv("UPLOAD_PATH")
|
| 43 |
+
}
|
| 44 |
+
if *LogDir != "" {
|
| 45 |
+
var err error
|
| 46 |
+
*LogDir, err = filepath.Abs(*LogDir)
|
| 47 |
+
if err != nil {
|
| 48 |
+
log.Fatal(err)
|
| 49 |
+
}
|
| 50 |
+
if _, err := os.Stat(*LogDir); os.IsNotExist(err) {
|
| 51 |
+
err = os.Mkdir(*LogDir, 0777)
|
| 52 |
+
if err != nil {
|
| 53 |
+
log.Fatal(err)
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
}
|
common/loggger/constants.go
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package logger
|
| 2 |
+
|
| 3 |
+
var LogDir string
|
common/loggger/logger.go
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package logger
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"context"
|
| 5 |
+
"fmt"
|
| 6 |
+
"genspark2api/common/config"
|
| 7 |
+
"genspark2api/common/helper"
|
| 8 |
+
"io"
|
| 9 |
+
"log"
|
| 10 |
+
"os"
|
| 11 |
+
"path/filepath"
|
| 12 |
+
"sync"
|
| 13 |
+
"time"
|
| 14 |
+
|
| 15 |
+
"github.com/gin-gonic/gin"
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
const (
|
| 19 |
+
loggerDEBUG = "DEBUG"
|
| 20 |
+
loggerINFO = "INFO"
|
| 21 |
+
loggerWarn = "WARN"
|
| 22 |
+
loggerError = "ERR"
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
var setupLogOnce sync.Once
|
| 26 |
+
|
| 27 |
+
func SetupLogger() {
|
| 28 |
+
setupLogOnce.Do(func() {
|
| 29 |
+
if LogDir != "" {
|
| 30 |
+
logPath := filepath.Join(LogDir, fmt.Sprintf("genspark2api-%s.log", time.Now().Format("20060102")))
|
| 31 |
+
fd, err := os.OpenFile(logPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
| 32 |
+
if err != nil {
|
| 33 |
+
log.Fatal("failed to open log file")
|
| 34 |
+
}
|
| 35 |
+
gin.DefaultWriter = io.MultiWriter(os.Stdout, fd)
|
| 36 |
+
gin.DefaultErrorWriter = io.MultiWriter(os.Stderr, fd)
|
| 37 |
+
}
|
| 38 |
+
})
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
func SysLog(s string) {
|
| 42 |
+
t := time.Now()
|
| 43 |
+
_, _ = fmt.Fprintf(gin.DefaultWriter, "[SYS] %v | %s \n", t.Format("2006/01/02 - 15:04:05"), s)
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
func SysError(s string) {
|
| 47 |
+
t := time.Now()
|
| 48 |
+
_, _ = fmt.Fprintf(gin.DefaultErrorWriter, "[SYS] %v | %s \n", t.Format("2006/01/02 - 15:04:05"), s)
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
func Debug(ctx context.Context, msg string) {
|
| 52 |
+
if config.DebugEnabled {
|
| 53 |
+
logHelper(ctx, loggerDEBUG, msg)
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
func Info(ctx context.Context, msg string) {
|
| 58 |
+
logHelper(ctx, loggerINFO, msg)
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
func Warn(ctx context.Context, msg string) {
|
| 62 |
+
logHelper(ctx, loggerWarn, msg)
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
func Error(ctx context.Context, msg string) {
|
| 66 |
+
logHelper(ctx, loggerError, msg)
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
func Debugf(ctx context.Context, format string, a ...any) {
|
| 70 |
+
Debug(ctx, fmt.Sprintf(format, a...))
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
func Infof(ctx context.Context, format string, a ...any) {
|
| 74 |
+
Info(ctx, fmt.Sprintf(format, a...))
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
func Warnf(ctx context.Context, format string, a ...any) {
|
| 78 |
+
Warn(ctx, fmt.Sprintf(format, a...))
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
func Errorf(ctx context.Context, format string, a ...any) {
|
| 82 |
+
Error(ctx, fmt.Sprintf(format, a...))
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
func logHelper(ctx context.Context, level string, msg string) {
|
| 86 |
+
writer := gin.DefaultErrorWriter
|
| 87 |
+
if level == loggerINFO {
|
| 88 |
+
writer = gin.DefaultWriter
|
| 89 |
+
}
|
| 90 |
+
id := ctx.Value(helper.RequestIdKey)
|
| 91 |
+
if id == nil {
|
| 92 |
+
id = helper.GenRequestID()
|
| 93 |
+
}
|
| 94 |
+
now := time.Now()
|
| 95 |
+
_, _ = fmt.Fprintf(writer, "[%s] %v | %s | %s \n", level, now.Format("2006/01/02 - 15:04:05"), id, msg)
|
| 96 |
+
SetupLogger()
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
func FatalLog(v ...any) {
|
| 100 |
+
t := time.Now()
|
| 101 |
+
_, _ = fmt.Fprintf(gin.DefaultErrorWriter, "[FATAL] %v | %v \n", t.Format("2006/01/02 - 15:04:05"), v)
|
| 102 |
+
os.Exit(1)
|
| 103 |
+
}
|
common/random/main.go
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package random
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"github.com/google/uuid"
|
| 5 |
+
"math/rand"
|
| 6 |
+
"strings"
|
| 7 |
+
"time"
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
func GetUUID() string {
|
| 11 |
+
code := uuid.New().String()
|
| 12 |
+
code = strings.Replace(code, "-", "", -1)
|
| 13 |
+
return code
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
const keyChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
| 17 |
+
const keyNumbers = "0123456789"
|
| 18 |
+
|
| 19 |
+
func init() {
|
| 20 |
+
rand.Seed(time.Now().UnixNano())
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
func GenerateKey() string {
|
| 24 |
+
rand.Seed(time.Now().UnixNano())
|
| 25 |
+
key := make([]byte, 48)
|
| 26 |
+
for i := 0; i < 16; i++ {
|
| 27 |
+
key[i] = keyChars[rand.Intn(len(keyChars))]
|
| 28 |
+
}
|
| 29 |
+
uuid_ := GetUUID()
|
| 30 |
+
for i := 0; i < 32; i++ {
|
| 31 |
+
c := uuid_[i]
|
| 32 |
+
if i%2 == 0 && c >= 'a' && c <= 'z' {
|
| 33 |
+
c = c - 'a' + 'A'
|
| 34 |
+
}
|
| 35 |
+
key[i+16] = c
|
| 36 |
+
}
|
| 37 |
+
return string(key)
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
func GetRandomString(length int) string {
|
| 41 |
+
rand.Seed(time.Now().UnixNano())
|
| 42 |
+
key := make([]byte, length)
|
| 43 |
+
for i := 0; i < length; i++ {
|
| 44 |
+
key[i] = keyChars[rand.Intn(len(keyChars))]
|
| 45 |
+
}
|
| 46 |
+
return string(key)
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
func GetRandomNumberString(length int) string {
|
| 50 |
+
rand.Seed(time.Now().UnixNano())
|
| 51 |
+
key := make([]byte, length)
|
| 52 |
+
for i := 0; i < length; i++ {
|
| 53 |
+
key[i] = keyNumbers[rand.Intn(len(keyNumbers))]
|
| 54 |
+
}
|
| 55 |
+
return string(key)
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
// RandRange returns a random number between min and max (max is not included)
|
| 59 |
+
func RandRange(min, max int) int {
|
| 60 |
+
return min + rand.Intn(max-min)
|
| 61 |
+
}
|
common/rate-limit.go
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package common
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"sync"
|
| 5 |
+
"time"
|
| 6 |
+
)
|
| 7 |
+
|
| 8 |
+
type InMemoryRateLimiter struct {
|
| 9 |
+
store map[string]*[]int64
|
| 10 |
+
mutex sync.Mutex
|
| 11 |
+
expirationDuration time.Duration
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
func (l *InMemoryRateLimiter) Init(expirationDuration time.Duration) {
|
| 15 |
+
if l.store == nil {
|
| 16 |
+
l.mutex.Lock()
|
| 17 |
+
if l.store == nil {
|
| 18 |
+
l.store = make(map[string]*[]int64)
|
| 19 |
+
l.expirationDuration = expirationDuration
|
| 20 |
+
if expirationDuration > 0 {
|
| 21 |
+
go l.clearExpiredItems()
|
| 22 |
+
}
|
| 23 |
+
}
|
| 24 |
+
l.mutex.Unlock()
|
| 25 |
+
}
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
func (l *InMemoryRateLimiter) clearExpiredItems() {
|
| 29 |
+
for {
|
| 30 |
+
time.Sleep(l.expirationDuration)
|
| 31 |
+
l.mutex.Lock()
|
| 32 |
+
now := time.Now().Unix()
|
| 33 |
+
for key := range l.store {
|
| 34 |
+
queue := l.store[key]
|
| 35 |
+
size := len(*queue)
|
| 36 |
+
if size == 0 || now-(*queue)[size-1] > int64(l.expirationDuration.Seconds()) {
|
| 37 |
+
delete(l.store, key)
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
l.mutex.Unlock()
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
// Request parameter duration's unit is seconds
|
| 45 |
+
func (l *InMemoryRateLimiter) Request(key string, maxRequestNum int, duration int64) bool {
|
| 46 |
+
l.mutex.Lock()
|
| 47 |
+
defer l.mutex.Unlock()
|
| 48 |
+
// [old <-- new]
|
| 49 |
+
queue, ok := l.store[key]
|
| 50 |
+
now := time.Now().Unix()
|
| 51 |
+
if ok {
|
| 52 |
+
if len(*queue) < maxRequestNum {
|
| 53 |
+
*queue = append(*queue, now)
|
| 54 |
+
return true
|
| 55 |
+
} else {
|
| 56 |
+
if now-(*queue)[0] >= duration {
|
| 57 |
+
*queue = (*queue)[1:]
|
| 58 |
+
*queue = append(*queue, now)
|
| 59 |
+
return true
|
| 60 |
+
} else {
|
| 61 |
+
return false
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
} else {
|
| 65 |
+
s := make([]int64, 0, maxRequestNum)
|
| 66 |
+
l.store[key] = &s
|
| 67 |
+
*(l.store[key]) = append(*(l.store[key]), now)
|
| 68 |
+
}
|
| 69 |
+
return true
|
| 70 |
+
}
|
common/token.go
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package common
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"errors"
|
| 5 |
+
"fmt"
|
| 6 |
+
logger "genspark2api/common/loggger"
|
| 7 |
+
"genspark2api/model"
|
| 8 |
+
"github.com/pkoukk/tiktoken-go"
|
| 9 |
+
"strings"
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
// tokenEncoderMap won't grow after initialization
|
| 13 |
+
var tokenEncoderMap = map[string]*tiktoken.Tiktoken{}
|
| 14 |
+
var defaultTokenEncoder *tiktoken.Tiktoken
|
| 15 |
+
|
| 16 |
+
func InitTokenEncoders() {
|
| 17 |
+
logger.SysLog("initializing token encoders...")
|
| 18 |
+
gpt35TokenEncoder, err := tiktoken.EncodingForModel("gpt-3.5-turbo")
|
| 19 |
+
if err != nil {
|
| 20 |
+
logger.FatalLog(fmt.Sprintf("failed to get gpt-3.5-turbo token encoder: %s", err.Error()))
|
| 21 |
+
}
|
| 22 |
+
defaultTokenEncoder = gpt35TokenEncoder
|
| 23 |
+
gpt4oTokenEncoder, err := tiktoken.EncodingForModel("gpt-4o")
|
| 24 |
+
if err != nil {
|
| 25 |
+
logger.FatalLog(fmt.Sprintf("failed to get gpt-4o token encoder: %s", err.Error()))
|
| 26 |
+
}
|
| 27 |
+
gpt4TokenEncoder, err := tiktoken.EncodingForModel("gpt-4")
|
| 28 |
+
if err != nil {
|
| 29 |
+
logger.FatalLog(fmt.Sprintf("failed to get gpt-4 token encoder: %s", err.Error()))
|
| 30 |
+
}
|
| 31 |
+
for _, model := range DefaultOpenaiModelList {
|
| 32 |
+
if strings.HasPrefix(model, "gpt-3.5") {
|
| 33 |
+
tokenEncoderMap[model] = gpt35TokenEncoder
|
| 34 |
+
} else if strings.HasPrefix(model, "gpt-4o") {
|
| 35 |
+
tokenEncoderMap[model] = gpt4oTokenEncoder
|
| 36 |
+
} else if strings.HasPrefix(model, "gpt-4") {
|
| 37 |
+
tokenEncoderMap[model] = gpt4TokenEncoder
|
| 38 |
+
} else {
|
| 39 |
+
tokenEncoderMap[model] = nil
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
logger.SysLog("token encoders initialized.")
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
func getTokenEncoder(model string) *tiktoken.Tiktoken {
|
| 46 |
+
tokenEncoder, ok := tokenEncoderMap[model]
|
| 47 |
+
if ok && tokenEncoder != nil {
|
| 48 |
+
return tokenEncoder
|
| 49 |
+
}
|
| 50 |
+
if ok {
|
| 51 |
+
tokenEncoder, err := tiktoken.EncodingForModel(model)
|
| 52 |
+
if err != nil {
|
| 53 |
+
//logger.SysError(fmt.Sprintf("[IGNORE] | failed to get token encoder for model %s: %s, using encoder for gpt-3.5-turbo", model, err.Error()))
|
| 54 |
+
tokenEncoder = defaultTokenEncoder
|
| 55 |
+
}
|
| 56 |
+
tokenEncoderMap[model] = tokenEncoder
|
| 57 |
+
return tokenEncoder
|
| 58 |
+
}
|
| 59 |
+
return defaultTokenEncoder
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
func getTokenNum(tokenEncoder *tiktoken.Tiktoken, text string) int {
|
| 63 |
+
return len(tokenEncoder.Encode(text, nil, nil))
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
func CountTokenMessages(messages []model.OpenAIChatMessage, model string) int {
|
| 67 |
+
tokenEncoder := getTokenEncoder(model)
|
| 68 |
+
// Reference:
|
| 69 |
+
// https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb
|
| 70 |
+
// https://github.com/pkoukk/tiktoken-go/issues/6
|
| 71 |
+
//
|
| 72 |
+
// Every message follows <|start|>{role/name}\n{content}<|end|>\n
|
| 73 |
+
var tokensPerMessage int
|
| 74 |
+
if model == "gpt-3.5-turbo-0301" {
|
| 75 |
+
tokensPerMessage = 4
|
| 76 |
+
} else {
|
| 77 |
+
tokensPerMessage = 3
|
| 78 |
+
}
|
| 79 |
+
tokenNum := 0
|
| 80 |
+
for _, message := range messages {
|
| 81 |
+
tokenNum += tokensPerMessage
|
| 82 |
+
switch v := message.Content.(type) {
|
| 83 |
+
case string:
|
| 84 |
+
tokenNum += getTokenNum(tokenEncoder, v)
|
| 85 |
+
case []any:
|
| 86 |
+
for _, it := range v {
|
| 87 |
+
m := it.(map[string]any)
|
| 88 |
+
switch m["type"] {
|
| 89 |
+
case "text":
|
| 90 |
+
if textValue, ok := m["text"]; ok {
|
| 91 |
+
if textString, ok := textValue.(string); ok {
|
| 92 |
+
tokenNum += getTokenNum(tokenEncoder, textString)
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
case "image_url":
|
| 96 |
+
imageUrl, ok := m["image_url"].(map[string]any)
|
| 97 |
+
if ok {
|
| 98 |
+
url := imageUrl["url"].(string)
|
| 99 |
+
detail := ""
|
| 100 |
+
if imageUrl["detail"] != nil {
|
| 101 |
+
detail = imageUrl["detail"].(string)
|
| 102 |
+
}
|
| 103 |
+
imageTokens, err := countImageTokens(url, detail, model)
|
| 104 |
+
if err != nil {
|
| 105 |
+
logger.SysError("error counting image tokens: " + err.Error())
|
| 106 |
+
} else {
|
| 107 |
+
tokenNum += imageTokens
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
tokenNum += getTokenNum(tokenEncoder, message.Role)
|
| 114 |
+
}
|
| 115 |
+
tokenNum += 3 // Every reply is primed with <|start|>assistant<|message|>
|
| 116 |
+
return tokenNum
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
const (
|
| 120 |
+
lowDetailCost = 85
|
| 121 |
+
highDetailCostPerTile = 170
|
| 122 |
+
additionalCost = 85
|
| 123 |
+
// gpt-4o-mini cost higher than other model
|
| 124 |
+
gpt4oMiniLowDetailCost = 2833
|
| 125 |
+
gpt4oMiniHighDetailCost = 5667
|
| 126 |
+
gpt4oMiniAdditionalCost = 2833
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
// https://platform.openai.com/docs/guides/vision/calculating-costs
|
| 130 |
+
// https://github.com/openai/openai-cookbook/blob/05e3f9be4c7a2ae7ecf029a7c32065b024730ebe/examples/How_to_count_tokens_with_tiktoken.ipynb
|
| 131 |
+
func countImageTokens(url string, detail string, model string) (_ int, err error) {
|
| 132 |
+
// Reference: https://platform.openai.com/docs/guides/vision/low-or-high-fidelity-image-understanding
|
| 133 |
+
// detail == "auto" is undocumented on how it works, it just said the model will use the auto setting which will look at the image input size and decide if it should use the low or high setting.
|
| 134 |
+
// According to the official guide, "low" disable the high-res model,
|
| 135 |
+
// and only receive low-res 512px x 512px version of the image, indicating
|
| 136 |
+
// that image is treated as low-res when size is smaller than 512px x 512px,
|
| 137 |
+
// then we can assume that image size larger than 512px x 512px is treated
|
| 138 |
+
// as high-res. Then we have the following logic:
|
| 139 |
+
// if detail == "" || detail == "auto" {
|
| 140 |
+
// width, height, err = image.GetImageSize(url)
|
| 141 |
+
// if err != nil {
|
| 142 |
+
// return 0, err
|
| 143 |
+
// }
|
| 144 |
+
// fetchSize = false
|
| 145 |
+
// // not sure if this is correct
|
| 146 |
+
// if width > 512 || height > 512 {
|
| 147 |
+
// detail = "high"
|
| 148 |
+
// } else {
|
| 149 |
+
// detail = "low"
|
| 150 |
+
// }
|
| 151 |
+
// }
|
| 152 |
+
|
| 153 |
+
// However, in my test, it seems to be always the same as "high".
|
| 154 |
+
// The following image, which is 125x50, is still treated as high-res, taken
|
| 155 |
+
// 255 tokens in the response of non-stream chat completion api.
|
| 156 |
+
// https://upload.wikimedia.org/wikipedia/commons/1/10/18_Infantry_Division_Messina.jpg
|
| 157 |
+
if detail == "" || detail == "auto" {
|
| 158 |
+
// assume by test, not sure if this is correct
|
| 159 |
+
detail = "low"
|
| 160 |
+
}
|
| 161 |
+
switch detail {
|
| 162 |
+
case "low":
|
| 163 |
+
if strings.HasPrefix(model, "gpt-4o-mini") {
|
| 164 |
+
return gpt4oMiniLowDetailCost, nil
|
| 165 |
+
}
|
| 166 |
+
return lowDetailCost, nil
|
| 167 |
+
default:
|
| 168 |
+
return 0, errors.New("invalid detail option")
|
| 169 |
+
}
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
func CountTokenInput(input any, model string) int {
|
| 173 |
+
switch v := input.(type) {
|
| 174 |
+
case string:
|
| 175 |
+
return CountTokenText(v, model)
|
| 176 |
+
case []string:
|
| 177 |
+
text := ""
|
| 178 |
+
for _, s := range v {
|
| 179 |
+
text += s
|
| 180 |
+
}
|
| 181 |
+
return CountTokenText(text, model)
|
| 182 |
+
}
|
| 183 |
+
return 0
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
func CountTokenText(text string, model string) int {
|
| 187 |
+
tokenEncoder := getTokenEncoder(model)
|
| 188 |
+
return getTokenNum(tokenEncoder, text)
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
func CountToken(text string) int {
|
| 192 |
+
return CountTokenInput(text, "gpt-3.5-turbo")
|
| 193 |
+
}
|
common/utils.go
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
+
|
| 3 |
+
import (
|
| 4 |
+
"encoding/base64"
|
| 5 |
+
"fmt"
|
| 6 |
+
"github.com/google/uuid"
|
| 7 |
+
jsoniter "github.com/json-iterator/go"
|
| 8 |
+
_ "github.com/pkoukk/tiktoken-go"
|
| 9 |
+
"math/rand"
|
| 10 |
+
"regexp"
|
| 11 |
+
"strings"
|
| 12 |
+
"time"
|
| 13 |
+
"unicode/utf8"
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
// splitStringByBytes 将字符串按照指定的字节数进行切割
|
| 17 |
+
func SplitStringByBytes(s string, size int) []string {
|
| 18 |
+
var result []string
|
| 19 |
+
|
| 20 |
+
for len(s) > 0 {
|
| 21 |
+
// 初始切割点
|
| 22 |
+
l := size
|
| 23 |
+
if l > len(s) {
|
| 24 |
+
l = len(s)
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
// 确保不在字符中间切割
|
| 28 |
+
for l > 0 && !utf8.ValidString(s[:l]) {
|
| 29 |
+
l--
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
// 如果 l 减到 0,说明 size 太小,无法容纳一个完整的字符
|
| 33 |
+
if l == 0 {
|
| 34 |
+
l = len(s)
|
| 35 |
+
for l > 0 && !utf8.ValidString(s[:l]) {
|
| 36 |
+
l--
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
result = append(result, s[:l])
|
| 41 |
+
s = s[l:]
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
return result
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
func Obj2Bytes(obj interface{}) ([]byte, error) {
|
| 48 |
+
// 创建一个jsonIter的Encoder
|
| 49 |
+
configCompatibleWithStandardLibrary := jsoniter.ConfigCompatibleWithStandardLibrary
|
| 50 |
+
// 将结构体转换为JSON文本并保持顺序
|
| 51 |
+
bytes, err := configCompatibleWithStandardLibrary.Marshal(obj)
|
| 52 |
+
if err != nil {
|
| 53 |
+
return nil, err
|
| 54 |
+
}
|
| 55 |
+
return bytes, nil
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
func GetUUID() string {
|
| 59 |
+
code := uuid.New().String()
|
| 60 |
+
code = strings.Replace(code, "-", "", -1)
|
| 61 |
+
return code
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
// RandomElement 返回给定切片中的随机元素
|
| 65 |
+
func RandomElement[T any](slice []T) (T, error) {
|
| 66 |
+
if len(slice) == 0 {
|
| 67 |
+
var zero T
|
| 68 |
+
return zero, fmt.Errorf("empty slice")
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
// 确保每次随机都不一样
|
| 72 |
+
rand.Seed(time.Now().UnixNano())
|
| 73 |
+
|
| 74 |
+
// 随机选择一个索引
|
| 75 |
+
index := rand.Intn(len(slice))
|
| 76 |
+
return slice[index], nil
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
func SliceContains(slice []string, str string) bool {
|
| 80 |
+
for _, item := range slice {
|
| 81 |
+
if strings.Contains(str, item) {
|
| 82 |
+
return true
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
return false
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
func IsImageBase64(s string) bool {
|
| 89 |
+
// 检查字符串是否符合数据URL的格式
|
| 90 |
+
if !strings.HasPrefix(s, "data:image/") || !strings.Contains(s, ";base64,") {
|
| 91 |
+
return false
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
if !strings.Contains(s, ";base64,") {
|
| 95 |
+
return false
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
// 获取";base64,"后的Base64编码部分
|
| 99 |
+
dataParts := strings.Split(s, ";base64,")
|
| 100 |
+
if len(dataParts) != 2 {
|
| 101 |
+
return false
|
| 102 |
+
}
|
| 103 |
+
base64Data := dataParts[1]
|
| 104 |
+
|
| 105 |
+
// 尝试Base64解码
|
| 106 |
+
_, err := base64.StdEncoding.DecodeString(base64Data)
|
| 107 |
+
return err == nil
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
func IsBase64(s string) bool {
|
| 111 |
+
// 检查字符串是否符合数据URL的格式
|
| 112 |
+
//if !strings.HasPrefix(s, "data:image/") || !strings.Contains(s, ";base64,") {
|
| 113 |
+
// return false
|
| 114 |
+
//}
|
| 115 |
+
|
| 116 |
+
if !strings.Contains(s, ";base64,") {
|
| 117 |
+
return false
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
// 获取";base64,"后的Base64编码部分
|
| 121 |
+
dataParts := strings.Split(s, ";base64,")
|
| 122 |
+
if len(dataParts) != 2 {
|
| 123 |
+
return false
|
| 124 |
+
}
|
| 125 |
+
base64Data := dataParts[1]
|
| 126 |
+
|
| 127 |
+
// 尝试Base64解码
|
| 128 |
+
_, err := base64.StdEncoding.DecodeString(base64Data)
|
| 129 |
+
return err == nil
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
//<h1 data-translate="block_headline">Sorry, you have been blocked</h1>
|
| 133 |
+
|
| 134 |
+
func IsCloudflareBlock(data string) bool {
|
| 135 |
+
if strings.Contains(data, `<h1 data-translate="block_headline">Sorry, you have been blocked</h1>`) {
|
| 136 |
+
return true
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
return false
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
func IsCloudflareChallenge(data string) bool {
|
| 143 |
+
// 检查基本的 HTML 结构
|
| 144 |
+
htmlPattern := `^<!DOCTYPE html><html.*?><head>.*?</head><body.*?>.*?</body></html>$`
|
| 145 |
+
|
| 146 |
+
// 检查 Cloudflare 特征
|
| 147 |
+
cfPatterns := []string{
|
| 148 |
+
`<title>Just a moment\.\.\.</title>`, // 标题特征
|
| 149 |
+
`window\._cf_chl_opt`, // CF 配置对象
|
| 150 |
+
`challenge-platform/h/b/orchestrate/chl_page`, // CF challenge 路径
|
| 151 |
+
`cdn-cgi/challenge-platform`, // CDN 路径特征
|
| 152 |
+
`<meta http-equiv="refresh" content="\d+">`, // 刷新 meta 标签
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
// 首先检查整体 HTML 结构
|
| 156 |
+
matched, _ := regexp.MatchString(htmlPattern, strings.TrimSpace(data))
|
| 157 |
+
if !matched {
|
| 158 |
+
return false
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
// 检查是否包含 Cloudflare 特征
|
| 162 |
+
for _, pattern := range cfPatterns {
|
| 163 |
+
if matched, _ := regexp.MatchString(pattern, data); matched {
|
| 164 |
+
return true
|
| 165 |
+
}
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
return false
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
func IsRateLimit(data string) bool {
|
| 172 |
+
if data == "Rate limit exceeded cf1" || data == "Rate limit exceeded cf2" {
|
| 173 |
+
return true
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
return false
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
func IsNotLogin(data string) bool {
|
| 180 |
+
if strings.Contains(data, `{"status":-5,"message":"not login","data":{}}`) {
|
| 181 |
+
return true
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
return false
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
func IsServerError(data string) bool {
|
| 188 |
+
if data == "Internal Server Error" {
|
| 189 |
+
return true
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
return false
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
func IsServerOverloaded(data string) bool {
|
| 196 |
+
if strings.Contains(data, `data: {"id": "", "role": "assistant", "content": "Server overloaded, please try again later.", "action": null, "recommend_actions": null, "is_prompt": false, "render_template": null, "session_state": null, "message_type": null, "type": "message_result"}`) {
|
| 197 |
+
return true
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
return false
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
func IsFreeLimit(data string) bool {
|
| 204 |
+
if strings.Contains(data, `data: {"id": "", "role": "assistant", "content": "You've reached your free usage limit today", "action": {"type": "ACTION_QUOTA_EXCEEDED", "query_string": null, "update_flow_data": null, "label": null, "user_s_input": null, "action_params": null}, "recommend_actions": null, "is_prompt": true, "render_template": null, "session_state": {"consume_usage_quota_exceeded": true}, "message_type": null, "type": "message_result"}`) {
|
| 205 |
+
return true
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
return false
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
func IsServiceUnavailablePage(data string) bool {
|
| 212 |
+
// 检查基本的 HTML 结构
|
| 213 |
+
htmlPattern := `^<!doctype html><html.*?><head>.*?</head><body.*?>.*?</body></html>`
|
| 214 |
+
|
| 215 |
+
// 检查 Service Unavailable 页面特征
|
| 216 |
+
suPatterns := []string{
|
| 217 |
+
`<title>Genspark</title>`, // 标题特征
|
| 218 |
+
`Service\s+Unavailable`, // 错误信息
|
| 219 |
+
`class="bb".*?class="s1".*?class="s2".*?class="s3"`, // 特征性类名结构
|
| 220 |
+
`genspark_logo\.png`, // Logo 图片
|
| 221 |
+
`gensparkpublicblob-cdn.*?\.azurefd\.net`, // CDN 域名
|
| 222 |
+
`<div class="tt">Service Unavailable</div>`, // 错误信息容器
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
// 首先检查整体 HTML 结构
|
| 226 |
+
matched, _ := regexp.MatchString(htmlPattern, strings.TrimSpace(data))
|
| 227 |
+
if !matched {
|
| 228 |
+
return false
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
// 检查特征模式,至少匹配其中的 3 个才认为是目标页面
|
| 232 |
+
matchCount := 0
|
| 233 |
+
for _, pattern := range suPatterns {
|
| 234 |
+
if matched, _ := regexp.MatchString(pattern, data); matched {
|
| 235 |
+
matchCount++
|
| 236 |
+
}
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
return matchCount >= 3
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
//<!doctype html><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><title>Genspark</title><link rel="icon" href="https://gensparkpublicblob-cdn-e6g4btgjavb5a7gh.z03.azurefd.net/user-upload-image/manual/favicon.ico"><style>body,html{margin:0;padding:0;font-family:Arial}.bb{width:100vw;height:100vh;position:absolute;overflow:hidden}.logo img{margin:20px 0 0 24px;height:24px}.iw{display:flex;flex-direction:column;height:100vh;width:100%}.s1{position:absolute;top:0;left:0;margin-top:-5%;margin-left:15%;width:289px;height:289px;border-radius:289px;opacity:.6;background:radial-gradient(55.64% 49.84%,#2c10d6 0,rgba(44,16,214,.36) 100%);filter:blur(120px)}.s2{position:absolute;top:0;left:0;margin-top:10%;margin-left:50%;width:204.845px;height:204.845px;transform:rotate(-131.346deg);flex-shrink:0;background:radial-gradient(55.64% 49.84%,#7fd1ff 0,rgba(44,16,214,.36) 100%);filter:blur(120px)}.s3{position:absolute;bottom:0;right:0;margin-bottom:10%;margin-right:10%;width:251px;height:251px;border-radius:289.093px;background:radial-gradient(88.27% 88.27% at 90.98% 61.04%,#ce7fff 0,#ffe4af 100%);filter:blur(120px)}.cc{display:flex;justify-content:center;align-items:center;height:100%;width:100%}.hh{align-items:center;display:flex;width:100vw}.dd{margin-top:-200px}.tt{color:#000;text-align:center;font-size:40px;font-style:normal;font-weight:700}@media (max-width:800px){.tt{font-size:30px}}</style></head><body><div class="bb"><div class="s1"></div><div class="s2"></div><div class="s3"></div></div><div class="iw"><div class="hh"><div class="logo"><img src="https://gensparkpublicblob-cdn-e6g4btgjavb5a7gh.z03.azurefd.net/user-upload-image/manual/genspark_logo.png" alt="logo"></div></div><div class="cc"><div class="dd"><div class="tt">Service Unavailable</div></div></div></div></body></html>
|
| 243 |
+
//<!doctype html><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><title>Genspark</title><link rel="icon" href="https://gensparkpublicblob-cdn-e6g4btgjavb5a7gh.z03.azurefd.net/user-upload-image/manual/favicon.ico"><style>body,html{margin:0;padding:0;font-family:Arial}.bb{width:100vw;height:100vh;position:absolute;overflow:hidden}.logo img{margin:20px 0 0 24px;height:24px}.iw{display:flex;flex-direction:column;height:100vh;width:100%!}(MISSING).s1{position:absolute;top:0;left:0;margin-top:-5%!;(MISSING)margin-left:15%!;(MISSING)width:289px;height:289px;border-radius:289px;opacity:.6;background:radial-gradient(55.64%,#2c10d6 0,rgba(44,16,214,.36) 100%!)(MISSING);filter:blur(120px)}.s2{position:absolute;top:0;left:0;margin-top:10%!;(MISSING)margin-left:50%!;(MISSING)width:204.845px;height:204.845px;transform:rotate(-131.346deg);flex-shrink:0;background:radial-gradient(55.64%,#7fd1ff 0,rgba(44,16,214,.36) 100%!)(MISSING);filter:blur(120px)}.s3{position:absolute;bottom:0;right:0;margin-bottom:10%!;(MISSING)margin-right:10%!;(MISSING)width:251px;height:251px;border-radius:289.093px;background:radial-gradient(88.27% at 90.98%,#ce7fff 0,#ffe4af 100%!)(MISSING);filter:blur(120px)}.cc{display:flex;justify-content:center;align-items:center;height:100%!;(MISSING)width:100%!}(MISSING).hh{align-items:center;display:flex;width:100vw}.dd{margin-top:-200px}.tt{color:#000;text-align:center;font-size:40px;font-style:normal;font-weight:700}@media (max-width:800px){.tt{font-size:30px}}</style></head><body><div class="bb"><div class="s1"></div><div class="s2"></div><div class="s3"></div></div><div class="iw"><div class="hh"><div class="logo"><img src="https://gensparkpublicblob-cdn-e6g4btgjavb5a7gh.z03.azurefd.net/user-upload-image/manual/genspark_logo.png" alt="logo"></div></div><div class="cc"><div class="dd"><div class="tt">Service Unavailable</div></div></div></div></body></html>
|
controller/admin.go
ADDED
|
@@ -0,0 +1,417 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package controller
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"encoding/json"
|
| 5 |
+
"fmt"
|
| 6 |
+
"genspark2api/common"
|
| 7 |
+
"genspark2api/common/config"
|
| 8 |
+
logger "genspark2api/common/loggger"
|
| 9 |
+
"io/ioutil"
|
| 10 |
+
"net/http"
|
| 11 |
+
"os"
|
| 12 |
+
"strings"
|
| 13 |
+
"time"
|
| 14 |
+
|
| 15 |
+
"github.com/gin-gonic/gin"
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
// 系统启动时间
|
| 19 |
+
var startTime = time.Now()
|
| 20 |
+
|
| 21 |
+
// GSCookie 定义cookie的结构
|
| 22 |
+
type GSCookie struct {
|
| 23 |
+
Value string // cookie值
|
| 24 |
+
RequestCount int // 请求次数
|
| 25 |
+
FailCount int // 失败请求数
|
| 26 |
+
LastUsedTime time.Time // 最后使用时间
|
| 27 |
+
Disabled bool // 是否禁用
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
// 模拟的Cookie统计
|
| 31 |
+
var cookieStats = make(map[string]*GSCookie)
|
| 32 |
+
|
| 33 |
+
// 模型信息
|
| 34 |
+
type ModelInfo struct {
|
| 35 |
+
ID string `json:"id"`
|
| 36 |
+
Name string `json:"name"`
|
| 37 |
+
Category string `json:"category"`
|
| 38 |
+
Enabled bool `json:"enabled"`
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
// ModelsListRequest 请求体
|
| 42 |
+
type ModelsListRequest struct {
|
| 43 |
+
Models []ModelInfo `json:"models"`
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
// 全局变量,存储模型列表
|
| 47 |
+
var modelsList []ModelInfo
|
| 48 |
+
var modelsListFile = "./data/models_list.json"
|
| 49 |
+
|
| 50 |
+
// 初始化模型列表
|
| 51 |
+
func init() {
|
| 52 |
+
// 加载模型列表(如果存在)
|
| 53 |
+
loadModelsList()
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
// AdminIndex 返回管理界面
|
| 57 |
+
func AdminIndex(c *gin.Context) {
|
| 58 |
+
c.File("./public/index.html")
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
// GetConfig 获取当前配置
|
| 62 |
+
func GetConfig(c *gin.Context) {
|
| 63 |
+
// 从环境变量获取配置
|
| 64 |
+
configData := map[string]string{
|
| 65 |
+
"GS_COOKIE": os.Getenv("GS_COOKIE"),
|
| 66 |
+
"API_SECRET": os.Getenv("API_SECRET"),
|
| 67 |
+
"AUTO_MODEL_CHAT_MAP_TYPE": os.Getenv("AUTO_MODEL_CHAT_MAP_TYPE"),
|
| 68 |
+
"AUTO_DEL_CHAT": os.Getenv("AUTO_DEL_CHAT"),
|
| 69 |
+
"MODEL_CHAT_MAP": os.Getenv("MODEL_CHAT_MAP"),
|
| 70 |
+
"PROXY_URL": os.Getenv("PROXY_URL"),
|
| 71 |
+
"RECAPTCHA_PROXY_URL": os.Getenv("RECAPTCHA_PROXY_URL"),
|
| 72 |
+
"REQUEST_RATE_LIMIT": os.Getenv("REQUEST_RATE_LIMIT"),
|
| 73 |
+
"RATE_LIMIT_COOKIE_LOCK_DURATION": os.Getenv("RATE_LIMIT_COOKIE_LOCK_DURATION"),
|
| 74 |
+
"ROUTE_PREFIX": os.Getenv("ROUTE_PREFIX"),
|
| 75 |
+
"DEBUG": os.Getenv("DEBUG"),
|
| 76 |
+
"REASONING_HIDE": os.Getenv("REASONING_HIDE"),
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
c.JSON(http.StatusOK, configData)
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
// SaveConfig 保存配置到.env文件
|
| 83 |
+
func SaveConfig(c *gin.Context) {
|
| 84 |
+
// 解析请求体
|
| 85 |
+
var configData map[string]string
|
| 86 |
+
if err := c.ShouldBindJSON(&configData); err != nil {
|
| 87 |
+
c.JSON(http.StatusBadRequest, gin.H{
|
| 88 |
+
"success": false,
|
| 89 |
+
"message": "无效的请求数据",
|
| 90 |
+
})
|
| 91 |
+
return
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
// 读取现有的.env文件(如果存在)
|
| 95 |
+
envFilePath := "./data/.env"
|
| 96 |
+
envLines := []string{}
|
| 97 |
+
envMap := make(map[string]string)
|
| 98 |
+
|
| 99 |
+
// 确保data目录存在
|
| 100 |
+
if err := os.MkdirAll("./data", 0755); err != nil {
|
| 101 |
+
logger.SysLog(fmt.Sprintf("创建data目录失败: %s", err.Error()))
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
if fileData, err := ioutil.ReadFile(envFilePath); err == nil {
|
| 105 |
+
content := string(fileData)
|
| 106 |
+
lines := strings.Split(content, "\n")
|
| 107 |
+
for _, line := range lines {
|
| 108 |
+
line = strings.TrimSpace(line)
|
| 109 |
+
if line != "" && !strings.HasPrefix(line, "#") {
|
| 110 |
+
parts := strings.SplitN(line, "=", 2)
|
| 111 |
+
if len(parts) == 2 {
|
| 112 |
+
key := strings.TrimSpace(parts[0])
|
| 113 |
+
value := strings.TrimSpace(parts[1])
|
| 114 |
+
envMap[key] = value
|
| 115 |
+
} else {
|
| 116 |
+
envLines = append(envLines, line) // 保留非键值对行
|
| 117 |
+
}
|
| 118 |
+
} else {
|
| 119 |
+
envLines = append(envLines, line) // 保留注释和空行
|
| 120 |
+
}
|
| 121 |
+
}
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
// 更新配置
|
| 125 |
+
for key, value := range configData {
|
| 126 |
+
if value != "" {
|
| 127 |
+
envMap[key] = value
|
| 128 |
+
// 同时更新环境变量
|
| 129 |
+
os.Setenv(key, value)
|
| 130 |
+
}
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
// 重建.env文件内容
|
| 134 |
+
var newContent strings.Builder
|
| 135 |
+
|
| 136 |
+
// 先写入非键值对的行
|
| 137 |
+
for _, line := range envLines {
|
| 138 |
+
if !strings.Contains(line, "=") {
|
| 139 |
+
newContent.WriteString(line)
|
| 140 |
+
newContent.WriteString("\n")
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
// 写入所有配置
|
| 145 |
+
for key, value := range envMap {
|
| 146 |
+
newContent.WriteString(fmt.Sprintf("%s=%s\n", key, value))
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
// 写入文件
|
| 150 |
+
if err := ioutil.WriteFile(envFilePath, []byte(newContent.String()), 0644); err != nil {
|
| 151 |
+
c.JSON(http.StatusInternalServerError, gin.H{
|
| 152 |
+
"success": false,
|
| 153 |
+
"message": "保存配置失败: " + err.Error(),
|
| 154 |
+
})
|
| 155 |
+
return
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
// 特殊处理 - 如果更新了GS_COOKIE,则重新初始化cookie池
|
| 159 |
+
if _, ok := configData["GS_COOKIE"]; ok {
|
| 160 |
+
config.InitGSCookies()
|
| 161 |
+
// 更新Cookie统计信息
|
| 162 |
+
updateCookieStats()
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
c.JSON(http.StatusOK, gin.H{
|
| 166 |
+
"success": true,
|
| 167 |
+
"message": "配置已保存",
|
| 168 |
+
})
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
// updateCookieStats 更新Cookie统计信息
|
| 172 |
+
func updateCookieStats() {
|
| 173 |
+
// 获取当前所有Cookie
|
| 174 |
+
currentCookies := config.GetGSCookies()
|
| 175 |
+
|
| 176 |
+
// 为新的Cookie创建统计条目
|
| 177 |
+
for _, cookie := range currentCookies {
|
| 178 |
+
if _, exists := cookieStats[cookie]; !exists {
|
| 179 |
+
cookieStats[cookie] = &GSCookie{
|
| 180 |
+
Value: cookie,
|
| 181 |
+
RequestCount: 0,
|
| 182 |
+
FailCount: 0,
|
| 183 |
+
LastUsedTime: time.Now(),
|
| 184 |
+
Disabled: false,
|
| 185 |
+
}
|
| 186 |
+
}
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
// 移除不再存在的Cookie
|
| 190 |
+
for cookie := range cookieStats {
|
| 191 |
+
exists := false
|
| 192 |
+
for _, currentCookie := range currentCookies {
|
| 193 |
+
if cookie == currentCookie {
|
| 194 |
+
exists = true
|
| 195 |
+
break
|
| 196 |
+
}
|
| 197 |
+
}
|
| 198 |
+
if !exists {
|
| 199 |
+
delete(cookieStats, cookie)
|
| 200 |
+
}
|
| 201 |
+
}
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
// GetStatus 获取系统状态信息
|
| 205 |
+
func GetStatus(c *gin.Context) {
|
| 206 |
+
// 计算运行时间
|
| 207 |
+
uptime := time.Since(startTime).String()
|
| 208 |
+
|
| 209 |
+
// 确保Cookie统计已更新
|
| 210 |
+
updateCookieStats()
|
| 211 |
+
|
| 212 |
+
// Cookie池信息
|
| 213 |
+
cookieCount := len(config.GetGSCookies())
|
| 214 |
+
cookies := make([]map[string]interface{}, 0, cookieCount)
|
| 215 |
+
|
| 216 |
+
// 获取所有Cookie信息
|
| 217 |
+
for cookie, stats := range cookieStats {
|
| 218 |
+
cookieInfo := map[string]interface{}{
|
| 219 |
+
"value": cookie,
|
| 220 |
+
"active": !stats.Disabled,
|
| 221 |
+
"requestCount": stats.RequestCount,
|
| 222 |
+
"lastUsed": stats.LastUsedTime.Format("2006-01-02 15:04:05"),
|
| 223 |
+
}
|
| 224 |
+
cookies = append(cookies, cookieInfo)
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
// 计算请求统计
|
| 228 |
+
totalRequests := 0
|
| 229 |
+
successRequests := 0
|
| 230 |
+
failedRequests := 0
|
| 231 |
+
|
| 232 |
+
for _, stats := range cookieStats {
|
| 233 |
+
totalRequests += stats.RequestCount
|
| 234 |
+
successRequests += (stats.RequestCount - stats.FailCount)
|
| 235 |
+
failedRequests += stats.FailCount
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
// 返回状态信息
|
| 239 |
+
c.JSON(http.StatusOK, gin.H{
|
| 240 |
+
"version": common.Version,
|
| 241 |
+
"uptime": uptime,
|
| 242 |
+
"cookieCount": cookieCount,
|
| 243 |
+
"totalRequests": totalRequests,
|
| 244 |
+
"successRequests": successRequests,
|
| 245 |
+
"failedRequests": failedRequests,
|
| 246 |
+
"cookies": cookies,
|
| 247 |
+
})
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
// GetModels 获取模型列表
|
| 251 |
+
func GetModels(c *gin.Context) {
|
| 252 |
+
// 如果模型列表为空,从默认OpenAI模型列表初始化
|
| 253 |
+
if len(modelsList) == 0 {
|
| 254 |
+
initializeModelsFromDefaults()
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
c.JSON(http.StatusOK, gin.H{
|
| 258 |
+
"models": modelsList,
|
| 259 |
+
})
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
// SaveModels 保存模型列表
|
| 263 |
+
func SaveModels(c *gin.Context) {
|
| 264 |
+
var request ModelsListRequest
|
| 265 |
+
if err := c.ShouldBindJSON(&request); err != nil {
|
| 266 |
+
c.JSON(http.StatusBadRequest, gin.H{
|
| 267 |
+
"success": false,
|
| 268 |
+
"message": "无效的请求数据",
|
| 269 |
+
})
|
| 270 |
+
return
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
// 更新模型列表
|
| 274 |
+
modelsList = request.Models
|
| 275 |
+
|
| 276 |
+
// 保存到文件
|
| 277 |
+
if err := saveModelsToFile(); err != nil {
|
| 278 |
+
c.JSON(http.StatusInternalServerError, gin.H{
|
| 279 |
+
"success": false,
|
| 280 |
+
"message": "保存模型列表失败: " + err.Error(),
|
| 281 |
+
})
|
| 282 |
+
return
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
// 更新DefaultOpenaiModelList
|
| 286 |
+
updateDefaultOpenaiModelList()
|
| 287 |
+
|
| 288 |
+
c.JSON(http.StatusOK, gin.H{
|
| 289 |
+
"success": true,
|
| 290 |
+
"message": "模型列表已保存",
|
| 291 |
+
})
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
// 从默认值初始化模型列表
|
| 295 |
+
func initializeModelsFromDefaults() {
|
| 296 |
+
// 清空现有列表
|
| 297 |
+
modelsList = []ModelInfo{}
|
| 298 |
+
|
| 299 |
+
// 文本模型
|
| 300 |
+
for _, model := range common.TextModelList {
|
| 301 |
+
modelsList = append(modelsList, ModelInfo{
|
| 302 |
+
ID: model,
|
| 303 |
+
Name: getModelDisplayName(model),
|
| 304 |
+
Category: "text",
|
| 305 |
+
Enabled: true,
|
| 306 |
+
})
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
// 图像模型
|
| 310 |
+
for _, model := range common.ImageModelList {
|
| 311 |
+
modelsList = append(modelsList, ModelInfo{
|
| 312 |
+
ID: model,
|
| 313 |
+
Name: getModelDisplayName(model),
|
| 314 |
+
Category: "image",
|
| 315 |
+
Enabled: true,
|
| 316 |
+
})
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
// 视频模型
|
| 320 |
+
for _, model := range common.VideoModelList {
|
| 321 |
+
modelsList = append(modelsList, ModelInfo{
|
| 322 |
+
ID: model,
|
| 323 |
+
Name: getModelDisplayName(model),
|
| 324 |
+
Category: "video",
|
| 325 |
+
Enabled: true,
|
| 326 |
+
})
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
// 保存到文件
|
| 330 |
+
saveModelsToFile()
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
// 获取模型显示名称
|
| 334 |
+
func getModelDisplayName(modelID string) string {
|
| 335 |
+
// 生成一个友好的显示名称
|
| 336 |
+
displayName := modelID
|
| 337 |
+
|
| 338 |
+
// 转换为首字母大写
|
| 339 |
+
parts := strings.Split(displayName, "-")
|
| 340 |
+
for i, part := range parts {
|
| 341 |
+
if len(part) > 0 {
|
| 342 |
+
// 对一些常见缩写进行特殊处理
|
| 343 |
+
if part == "gpt" || part == "dall" {
|
| 344 |
+
parts[i] = strings.ToUpper(part)
|
| 345 |
+
} else {
|
| 346 |
+
parts[i] = strings.ToUpper(part[:1]) + part[1:]
|
| 347 |
+
}
|
| 348 |
+
}
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
displayName = strings.Join(parts, " ")
|
| 352 |
+
displayName = strings.Replace(displayName, "/", " ", -1)
|
| 353 |
+
|
| 354 |
+
return displayName
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
// 保存模型列表到文件
|
| 358 |
+
func saveModelsToFile() error {
|
| 359 |
+
// 确保data目录存在
|
| 360 |
+
if err := os.MkdirAll("./data", 0755); err != nil {
|
| 361 |
+
return err
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
// 序列化数据
|
| 365 |
+
data, err := json.MarshalIndent(modelsList, "", " ")
|
| 366 |
+
if err != nil {
|
| 367 |
+
return err
|
| 368 |
+
}
|
| 369 |
+
|
| 370 |
+
// 写入文件
|
| 371 |
+
return ioutil.WriteFile(modelsListFile, data, 0644)
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
// 从文件加载模型列表
|
| 375 |
+
func loadModelsList() {
|
| 376 |
+
// 如果文件不存在,则初始化默认值
|
| 377 |
+
if _, err := os.Stat(modelsListFile); os.IsNotExist(err) {
|
| 378 |
+
initializeModelsFromDefaults()
|
| 379 |
+
return
|
| 380 |
+
}
|
| 381 |
+
|
| 382 |
+
// 读取文件
|
| 383 |
+
data, err := ioutil.ReadFile(modelsListFile)
|
| 384 |
+
if err != nil {
|
| 385 |
+
logger.SysLog(fmt.Sprintf("无法读取模型列表文件: %s", err.Error()))
|
| 386 |
+
initializeModelsFromDefaults()
|
| 387 |
+
return
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
// 解析JSON
|
| 391 |
+
if err := json.Unmarshal(data, &modelsList); err != nil {
|
| 392 |
+
logger.SysLog(fmt.Sprintf("解析模型列表文件失败: %s", err.Error()))
|
| 393 |
+
initializeModelsFromDefaults()
|
| 394 |
+
return
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
// 如果列表为空,初始化默认值
|
| 398 |
+
if len(modelsList) == 0 {
|
| 399 |
+
initializeModelsFromDefaults()
|
| 400 |
+
}
|
| 401 |
+
|
| 402 |
+
// 更新DefaultOpenaiModelList
|
| 403 |
+
updateDefaultOpenaiModelList()
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
// 更新DefaultOpenaiModelList
|
| 407 |
+
func updateDefaultOpenaiModelList() {
|
| 408 |
+
// 清空现有列表
|
| 409 |
+
common.DefaultOpenaiModelList = []string{}
|
| 410 |
+
|
| 411 |
+
// 遍历模型列表,将启用的模型添加到DefaultOpenaiModelList
|
| 412 |
+
for _, model := range modelsList {
|
| 413 |
+
if model.Enabled {
|
| 414 |
+
common.DefaultOpenaiModelList = append(common.DefaultOpenaiModelList, model.ID)
|
| 415 |
+
}
|
| 416 |
+
}
|
| 417 |
+
}
|
controller/api.go
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package controller
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"github.com/deanxv/CycleTLS/cycletls"
|
| 5 |
+
"github.com/gin-gonic/gin"
|
| 6 |
+
)
|
| 7 |
+
|
| 8 |
+
// ChatForOpenAI 处理OpenAI聊天请求
|
| 9 |
+
func InitModelChatMap(c *gin.Context) {
|
| 10 |
+
client := cycletls.Init()
|
| 11 |
+
defer safeClose(client)
|
| 12 |
+
|
| 13 |
+
// TODO
|
| 14 |
+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package controller
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"crypto/sha256"
|
| 5 |
+
"crypto/subtle"
|
| 6 |
+
"encoding/base64"
|
| 7 |
+
"encoding/json"
|
| 8 |
+
"genspark2api/common/config"
|
| 9 |
+
"net/http"
|
| 10 |
+
"os"
|
| 11 |
+
"time"
|
| 12 |
+
|
| 13 |
+
"github.com/gin-gonic/gin"
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
// 登录请求体
|
| 17 |
+
type LoginRequest struct {
|
| 18 |
+
Username string `json:"username"`
|
| 19 |
+
Password string `json:"password"`
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
// JWT声明结构
|
| 23 |
+
type JWTClaims struct {
|
| 24 |
+
Username string `json:"username"`
|
| 25 |
+
Exp int64 `json:"exp"`
|
| 26 |
+
Iat int64 `json:"iat"`
|
| 27 |
+
Iss string `json:"iss"`
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
// 生成JWT令牌
|
| 31 |
+
func generateToken(username string) (string, error) {
|
| 32 |
+
// 创建JWT声明
|
| 33 |
+
nowTime := time.Now()
|
| 34 |
+
expireTime := nowTime.Add(24 * time.Hour) // 令牌有效期为24小时
|
| 35 |
+
|
| 36 |
+
claims := JWTClaims{
|
| 37 |
+
Username: username,
|
| 38 |
+
Exp: expireTime.Unix(),
|
| 39 |
+
Iat: nowTime.Unix(),
|
| 40 |
+
Iss: "genspark2api",
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
// 序列化claims为JSON
|
| 44 |
+
claimsJSON, err := json.Marshal(claims)
|
| 45 |
+
if err != nil {
|
| 46 |
+
return "", err
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
// Base64编码payload
|
| 50 |
+
payload := base64.RawURLEncoding.EncodeToString(claimsJSON)
|
| 51 |
+
|
| 52 |
+
// 创建header
|
| 53 |
+
header := base64.RawURLEncoding.EncodeToString([]byte(`{"alg":"HS256","typ":"JWT"}`))
|
| 54 |
+
|
| 55 |
+
// 计算签名
|
| 56 |
+
signatureInput := header + "." + payload
|
| 57 |
+
|
| 58 |
+
// 使用API_SECRET的SHA256哈希签名
|
| 59 |
+
h := sha256.New()
|
| 60 |
+
h.Write([]byte(signatureInput + config.ApiSecret))
|
| 61 |
+
signature := base64.RawURLEncoding.EncodeToString(h.Sum(nil))
|
| 62 |
+
|
| 63 |
+
// 组装JWT
|
| 64 |
+
token := header + "." + payload + "." + signature
|
| 65 |
+
|
| 66 |
+
return token, nil
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
// LoginPage 返回登录页面
|
| 70 |
+
func LoginPage(c *gin.Context) {
|
| 71 |
+
c.File("./public/login.html")
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
// Login 处理用户登录
|
| 75 |
+
func Login(c *gin.Context) {
|
| 76 |
+
// 解析请求体
|
| 77 |
+
var loginReq LoginRequest
|
| 78 |
+
if err := c.ShouldBindJSON(&loginReq); err != nil {
|
| 79 |
+
c.JSON(http.StatusBadRequest, gin.H{
|
| 80 |
+
"success": false,
|
| 81 |
+
"message": "无效的请求数据",
|
| 82 |
+
})
|
| 83 |
+
return
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
// 验证用户名
|
| 87 |
+
if loginReq.Username != "maltose" {
|
| 88 |
+
c.JSON(http.StatusUnauthorized, gin.H{
|
| 89 |
+
"success": false,
|
| 90 |
+
"message": "用户名或密码错误",
|
| 91 |
+
})
|
| 92 |
+
return
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
// 获取API_SECRET作为密码
|
| 96 |
+
apiSecret := os.Getenv("API_SECRET")
|
| 97 |
+
if apiSecret == "" {
|
| 98 |
+
apiSecret = config.ApiSecret
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
// 如果API_SECRET包含多个值(逗号分隔),只取第一个
|
| 102 |
+
for i := 0; i < len(apiSecret); i++ {
|
| 103 |
+
if apiSecret[i] == ',' {
|
| 104 |
+
apiSecret = apiSecret[:i]
|
| 105 |
+
break
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
// 验证密码 - 使用恒定时间比较避免时序攻击
|
| 110 |
+
if subtle.ConstantTimeCompare([]byte(loginReq.Password), []byte(apiSecret)) != 1 {
|
| 111 |
+
c.JSON(http.StatusUnauthorized, gin.H{
|
| 112 |
+
"success": false,
|
| 113 |
+
"message": "用户名或密码错误",
|
| 114 |
+
})
|
| 115 |
+
return
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
// 生成JWT令牌
|
| 119 |
+
token, err := generateToken(loginReq.Username)
|
| 120 |
+
if err != nil {
|
| 121 |
+
c.JSON(http.StatusInternalServerError, gin.H{
|
| 122 |
+
"success": false,
|
| 123 |
+
"message": "生成令牌失败",
|
| 124 |
+
})
|
| 125 |
+
return
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
// 返回成功响应和令牌
|
| 129 |
+
c.JSON(http.StatusOK, gin.H{
|
| 130 |
+
"success": true,
|
| 131 |
+
"message": "登录成功",
|
| 132 |
+
"token": token,
|
| 133 |
+
})
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
// VerifyAuth 验证当前用户是否已登录
|
| 137 |
+
func VerifyAuth(c *gin.Context) {
|
| 138 |
+
// 获取Authorization头
|
| 139 |
+
authHeader := c.GetHeader("Authorization")
|
| 140 |
+
if authHeader == "" {
|
| 141 |
+
c.JSON(http.StatusUnauthorized, gin.H{
|
| 142 |
+
"success": false,
|
| 143 |
+
"message": "未授权",
|
| 144 |
+
})
|
| 145 |
+
return
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
// 简单验证格式,实际项目中应该有完整的JWT验证
|
| 149 |
+
if len(authHeader) < 10 {
|
| 150 |
+
c.JSON(http.StatusUnauthorized, gin.H{
|
| 151 |
+
"success": false,
|
| 152 |
+
"message": "无效的令牌",
|
| 153 |
+
})
|
| 154 |
+
return
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
// 成功响应
|
| 158 |
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spark2api/common/loggger"
|
| 12 |
+
"genspark2api/model"
|
| 13 |
+
"github.com/deanxv/CycleTLS/cycletls"
|
| 14 |
+
"github.com/gin-gonic/gin"
|
| 15 |
+
"github.com/samber/lo"
|
| 16 |
+
"io"
|
| 17 |
+
"io/ioutil"
|
| 18 |
+
"net/http"
|
| 19 |
+
"strings"
|
| 20 |
+
"time"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
const (
|
| 24 |
+
errNoValidCookies = "No valid cookies available"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
const (
|
| 28 |
+
baseURL = "https://www.genspark.ai"
|
| 29 |
+
apiEndpoint = baseURL + "/api/copilot/ask"
|
| 30 |
+
deleteEndpoint = baseURL + "/api/project/delete?project_id=%s"
|
| 31 |
+
uploadEndpoint = baseURL + "/api/get_upload_personal_image_url"
|
| 32 |
+
chatType = "COPILOT_MOA_CHAT"
|
| 33 |
+
imageType = "COPILOT_MOA_IMAGE"
|
| 34 |
+
videoType = "COPILOT_MOA_VIDEO"
|
| 35 |
+
responseIDFormat = "chatcmpl-%s"
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
type OpenAIChatMessage struct {
|
| 39 |
+
Role string `json:"role"`
|
| 40 |
+
Content interface{} `json:"content"`
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
type OpenAIChatCompletionRequest struct {
|
| 44 |
+
Messages []OpenAIChatMessage
|
| 45 |
+
Model string
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
// ChatForOpenAI 处理OpenAI聊天请求
|
| 49 |
+
func ChatForOpenAI(c *gin.Context) {
|
| 50 |
+
client := cycletls.Init()
|
| 51 |
+
defer safeClose(client)
|
| 52 |
+
|
| 53 |
+
var openAIReq model.OpenAIChatCompletionRequest
|
| 54 |
+
if err := c.BindJSON(&openAIReq); err != nil {
|
| 55 |
+
logger.Errorf(c.Request.Context(), err.Error())
|
| 56 |
+
c.JSON(http.StatusInternalServerError, model.OpenAIErrorResponse{
|
| 57 |
+
OpenAIError: model.OpenAIError{
|
| 58 |
+
Message: "Invalid request parameters",
|
| 59 |
+
Type: "request_error",
|
| 60 |
+
Code: "500",
|
| 61 |
+
},
|
| 62 |
+
})
|
| 63 |
+
return
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
// 模型映射
|
| 67 |
+
if strings.HasPrefix(openAIReq.Model, "deepseek") {
|
| 68 |
+
openAIReq.Model = strings.Replace(openAIReq.Model, "deepseek", "deep-seek", 1)
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
// 初始化cookie
|
| 72 |
+
|
| 73 |
+
cookieManager := config.NewCookieManager()
|
| 74 |
+
cookie, err := cookieManager.GetRandomCookie()
|
| 75 |
+
if err != nil {
|
| 76 |
+
logger.Errorf(c.Request.Context(), "Failed to get initial cookie: %v", err)
|
| 77 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": errNoValidCookies})
|
| 78 |
+
return
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
if lo.Contains(common.ImageModelList, openAIReq.Model) {
|
| 82 |
+
responseId := fmt.Sprintf(responseIDFormat, time.Now().Format("20060102150405"))
|
| 83 |
+
|
| 84 |
+
if len(openAIReq.GetUserContent()) == 0 {
|
| 85 |
+
logger.Errorf(c.Request.Context(), "user content is null")
|
| 86 |
+
c.JSON(http.StatusInternalServerError, model.OpenAIErrorResponse{
|
| 87 |
+
OpenAIError: model.OpenAIError{
|
| 88 |
+
Message: "Invalid request parameters",
|
| 89 |
+
Type: "request_error",
|
| 90 |
+
Code: "500",
|
| 91 |
+
},
|
| 92 |
+
})
|
| 93 |
+
return
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
jsonData, err := json.Marshal(openAIReq.GetUserContent()[0])
|
| 97 |
+
if err != nil {
|
| 98 |
+
logger.Errorf(c.Request.Context(), err.Error())
|
| 99 |
+
c.JSON(500, gin.H{"error": "Failed to marshal request body"})
|
| 100 |
+
return
|
| 101 |
+
}
|
| 102 |
+
resp, err := ImageProcess(c, client, model.OpenAIImagesGenerationRequest{
|
| 103 |
+
Model: openAIReq.Model,
|
| 104 |
+
Prompt: openAIReq.GetUserContent()[0],
|
| 105 |
+
})
|
| 106 |
+
|
| 107 |
+
if err != nil {
|
| 108 |
+
logger.Errorf(c.Request.Context(), err.Error())
|
| 109 |
+
c.JSON(http.StatusInternalServerError, model.OpenAIErrorResponse{
|
| 110 |
+
OpenAIError: model.OpenAIError{
|
| 111 |
+
Message: err.Error(),
|
| 112 |
+
Type: "request_error",
|
| 113 |
+
Code: "500",
|
| 114 |
+
},
|
| 115 |
+
})
|
| 116 |
+
return
|
| 117 |
+
} else {
|
| 118 |
+
data := resp.Data
|
| 119 |
+
var content []string
|
| 120 |
+
for _, item := range data {
|
| 121 |
+
content = append(content, fmt.Sprintf("", item.URL))
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
if openAIReq.Stream {
|
| 125 |
+
streamResp := createStreamResponse(responseId, openAIReq.Model, jsonData, model.OpenAIDelta{Content: strings.Join(content, "\n"), Role: "assistant"}, nil)
|
| 126 |
+
err := sendSSEvent(c, streamResp)
|
| 127 |
+
if err != nil {
|
| 128 |
+
logger.Errorf(c.Request.Context(), err.Error())
|
| 129 |
+
c.JSON(http.StatusInternalServerError, model.OpenAIErrorResponse{
|
| 130 |
+
OpenAIError: model.OpenAIError{
|
| 131 |
+
Message: err.Error(),
|
| 132 |
+
Type: "request_error",
|
| 133 |
+
Code: "500",
|
| 134 |
+
},
|
| 135 |
+
})
|
| 136 |
+
return
|
| 137 |
+
}
|
| 138 |
+
c.SSEvent("", " [DONE]")
|
| 139 |
+
return
|
| 140 |
+
} else {
|
| 141 |
+
|
| 142 |
+
jsonBytes, _ := json.Marshal(openAIReq.Messages)
|
| 143 |
+
promptTokens := common.CountTokenText(string(jsonBytes), openAIReq.Model)
|
| 144 |
+
completionTokens := common.CountTokenText(strings.Join(content, "\n"), openAIReq.Model)
|
| 145 |
+
|
| 146 |
+
finishReason := "stop"
|
| 147 |
+
// 创建并返回 OpenAIChatCompletionResponse 结构
|
| 148 |
+
resp := model.OpenAIChatCompletionResponse{
|
| 149 |
+
ID: fmt.Sprintf(responseIDFormat, time.Now().Format("20060102150405")),
|
| 150 |
+
Object: "chat.completion",
|
| 151 |
+
Created: time.Now().Unix(),
|
| 152 |
+
Model: openAIReq.Model,
|
| 153 |
+
Choices: []model.OpenAIChoice{
|
| 154 |
+
{
|
| 155 |
+
Message: model.OpenAIMessage{
|
| 156 |
+
Role: "assistant",
|
| 157 |
+
Content: strings.Join(content, "\n"),
|
| 158 |
+
},
|
| 159 |
+
FinishReason: &finishReason,
|
| 160 |
+
},
|
| 161 |
+
},
|
| 162 |
+
Usage: model.OpenAIUsage{
|
| 163 |
+
PromptTokens: promptTokens,
|
| 164 |
+
CompletionTokens: completionTokens,
|
| 165 |
+
TotalTokens: promptTokens + completionTokens,
|
| 166 |
+
},
|
| 167 |
+
}
|
| 168 |
+
c.JSON(200, resp)
|
| 169 |
+
return
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
}
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
var isSearchModel bool
|
| 176 |
+
if strings.HasSuffix(openAIReq.Model, "-search") {
|
| 177 |
+
isSearchModel = true
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
requestBody, err := createRequestBody(c, client, cookie, &openAIReq)
|
| 181 |
+
|
| 182 |
+
if err != nil {
|
| 183 |
+
c.JSON(500, gin.H{"error": err.Error()})
|
| 184 |
+
return
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
//jsonData, err := json.Marshal(requestBody)
|
| 188 |
+
//if err != nil {
|
| 189 |
+
// c.JSON(500, gin.H{"error": "Failed to marshal request body"})
|
| 190 |
+
// return
|
| 191 |
+
//}
|
| 192 |
+
|
| 193 |
+
if openAIReq.Stream {
|
| 194 |
+
handleStreamRequest(c, client, cookie, cookieManager, requestBody, openAIReq.Model, isSearchModel)
|
| 195 |
+
} else {
|
| 196 |
+
handleNonStreamRequest(c, client, cookie, cookieManager, requestBody, openAIReq.Model, isSearchModel)
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
func processMessages(c *gin.Context, client cycletls.CycleTLS, cookie string, messages []model.OpenAIChatMessage) error {
|
| 202 |
+
//client := cycletls.Init()
|
| 203 |
+
//defer client.Close()
|
| 204 |
+
|
| 205 |
+
for i, message := range messages {
|
| 206 |
+
if contentArray, ok := message.Content.([]interface{}); ok {
|
| 207 |
+
for j, content := range contentArray {
|
| 208 |
+
if contentMap, ok := content.(map[string]interface{}); ok {
|
| 209 |
+
if contentType, ok := contentMap["type"].(string); ok && contentType == "image_url" {
|
| 210 |
+
if imageMap, ok := contentMap["image_url"].(map[string]interface{}); ok {
|
| 211 |
+
if url, ok := imageMap["url"].(string); ok {
|
| 212 |
+
err := processUrl(c, client, cookie, url, imageMap, j, contentArray)
|
| 213 |
+
if err != nil {
|
| 214 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("processUrl err %v\n", err))
|
| 215 |
+
return fmt.Errorf("processUrl err: %v", err)
|
| 216 |
+
}
|
| 217 |
+
}
|
| 218 |
+
}
|
| 219 |
+
}
|
| 220 |
+
}
|
| 221 |
+
}
|
| 222 |
+
messages[i].Content = contentArray
|
| 223 |
+
}
|
| 224 |
+
}
|
| 225 |
+
return nil
|
| 226 |
+
}
|
| 227 |
+
func processUrl(c *gin.Context, client cycletls.CycleTLS, cookie string, url string, imageMap map[string]interface{}, index int, contentArray []interface{}) error {
|
| 228 |
+
// 判断是否为URL
|
| 229 |
+
if strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://") {
|
| 230 |
+
// 下载文件
|
| 231 |
+
bytes, err := fetchImageBytes(url)
|
| 232 |
+
if err != nil {
|
| 233 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("fetchImageBytes err %v\n", err))
|
| 234 |
+
return fmt.Errorf("fetchImageBytes err %v\n", err)
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
err = processBytes(c, client, cookie, bytes, imageMap, index, contentArray)
|
| 238 |
+
if err != nil {
|
| 239 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("processBytes err %v\n", err))
|
| 240 |
+
return fmt.Errorf("processBytes err %v\n", err)
|
| 241 |
+
}
|
| 242 |
+
} else {
|
| 243 |
+
// 尝试解析base64
|
| 244 |
+
var bytes []byte
|
| 245 |
+
var err error
|
| 246 |
+
|
| 247 |
+
// 处理可能包含 data:image/ 前缀的base64
|
| 248 |
+
base64Str := url
|
| 249 |
+
if strings.Contains(url, ";base64,") {
|
| 250 |
+
base64Str = strings.Split(url, ";base64,")[1]
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
bytes, err = base64.StdEncoding.DecodeString(base64Str)
|
| 254 |
+
if err != nil {
|
| 255 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("base64.StdEncoding.DecodeString err %v\n", err))
|
| 256 |
+
return fmt.Errorf("base64.StdEncoding.DecodeString err: %v\n", err)
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
err = processBytes(c, client, cookie, bytes, imageMap, index, contentArray)
|
| 260 |
+
if err != nil {
|
| 261 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("processBytes err %v\n", err))
|
| 262 |
+
return fmt.Errorf("processBytes err: %v\n", err)
|
| 263 |
+
}
|
| 264 |
+
}
|
| 265 |
+
return nil
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
func processBytes(c *gin.Context, client cycletls.CycleTLS, cookie string, bytes []byte, imageMap map[string]interface{}, index int, contentArray []interface{}) error {
|
| 269 |
+
// 检查是否为图片类型
|
| 270 |
+
contentType := http.DetectContentType(bytes)
|
| 271 |
+
if strings.HasPrefix(contentType, "image/") {
|
| 272 |
+
// 是图片类型,转换为base64
|
| 273 |
+
base64Data := "data:image/jpeg;base64," + base64.StdEncoding.EncodeToString(bytes)
|
| 274 |
+
imageMap["url"] = base64Data
|
| 275 |
+
} else {
|
| 276 |
+
response, err := makeGetUploadUrlRequest(client, cookie)
|
| 277 |
+
if err != nil {
|
| 278 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("makeGetUploadUrlRequest err %v\n", err))
|
| 279 |
+
return fmt.Errorf("makeGetUploadUrlRequest err: %v\n", err)
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
var jsonResponse map[string]interface{}
|
| 283 |
+
if err := json.Unmarshal([]byte(response.Body), &jsonResponse); err != nil {
|
| 284 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("Unmarshal err %v\n", err))
|
| 285 |
+
return fmt.Errorf("Unmarshal err: %v\n", err)
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
uploadImageUrl, ok := jsonResponse["data"].(map[string]interface{})["upload_image_url"].(string)
|
| 289 |
+
privateStorageUrl, ok := jsonResponse["data"].(map[string]interface{})["private_storage_url"].(string)
|
| 290 |
+
|
| 291 |
+
if !ok {
|
| 292 |
+
//fmt.Println("Failed to extract upload_image_url")
|
| 293 |
+
return fmt.Errorf("Failed to extract upload_image_url")
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
// 发送OPTIONS预检请求
|
| 297 |
+
//_, err = makeOptionsRequest(client, uploadImageUrl)
|
| 298 |
+
//if err != nil {
|
| 299 |
+
// return
|
| 300 |
+
//}
|
| 301 |
+
// 上传文件
|
| 302 |
+
_, err = makeUploadRequest(client, uploadImageUrl, bytes)
|
| 303 |
+
if err != nil {
|
| 304 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("makeUploadRequest err %v\n", err))
|
| 305 |
+
return fmt.Errorf("makeUploadRequest err: %v\n", err)
|
| 306 |
+
}
|
| 307 |
+
//fmt.Println(resp)
|
| 308 |
+
|
| 309 |
+
// 创建新的 private_file 格式的内容
|
| 310 |
+
privateFile := map[string]interface{}{
|
| 311 |
+
"type": "private_file",
|
| 312 |
+
"private_file": map[string]interface{}{
|
| 313 |
+
"name": "file", // 你可能需要从原始文件名或其他地方获取
|
| 314 |
+
"type": contentType,
|
| 315 |
+
"size": len(bytes),
|
| 316 |
+
"ext": strings.Split(contentType, "/")[1], // 简单处理,可能需要更复杂的逻辑
|
| 317 |
+
"private_storage_url": privateStorageUrl,
|
| 318 |
+
},
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
// 替换数组中的元素
|
| 322 |
+
contentArray[index] = privateFile
|
| 323 |
+
}
|
| 324 |
+
return nil
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
// 获取文件字节数组的函数
|
| 328 |
+
func fetchImageBytes(url string) ([]byte, error) {
|
| 329 |
+
resp, err := http.Get(url)
|
| 330 |
+
if err != nil {
|
| 331 |
+
return nil, fmt.Errorf("http.Get err: %v\n", err)
|
| 332 |
+
}
|
| 333 |
+
defer resp.Body.Close()
|
| 334 |
+
|
| 335 |
+
return ioutil.ReadAll(resp.Body)
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
func createRequestBody(c *gin.Context, client cycletls.CycleTLS, cookie string, openAIReq *model.OpenAIChatCompletionRequest) (map[string]interface{}, error) {
|
| 339 |
+
openAIReq.SystemMessagesProcess(openAIReq.Model)
|
| 340 |
+
if config.PRE_MESSAGES_JSON != "" {
|
| 341 |
+
err := openAIReq.PrependMessagesFromJSON(config.PRE_MESSAGES_JSON)
|
| 342 |
+
if err != nil {
|
| 343 |
+
return nil, fmt.Errorf("PrependMessagesFromJSON err: %v PrependMessagesFromJSON:", err, config.PRE_MESSAGES_JSON)
|
| 344 |
+
}
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
// 处理消息中的图像 URL
|
| 348 |
+
err := processMessages(c, client, cookie, openAIReq.Messages)
|
| 349 |
+
if err != nil {
|
| 350 |
+
logger.Errorf(c.Request.Context(), "processMessages err: %v", err)
|
| 351 |
+
return nil, fmt.Errorf("processMessages err: %v", err)
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
currentQueryString := fmt.Sprintf("type=%s", chatType)
|
| 355 |
+
//查找 key 对应的 value
|
| 356 |
+
if chatId, ok := config.ModelChatMap[openAIReq.Model]; ok {
|
| 357 |
+
currentQueryString = fmt.Sprintf("id=%s&type=%s", chatId, chatType)
|
| 358 |
+
} else if chatId, ok := config.GlobalSessionManager.GetChatID(cookie, openAIReq.Model); ok {
|
| 359 |
+
currentQueryString = fmt.Sprintf("id=%s&type=%s", chatId, chatType)
|
| 360 |
+
} else {
|
| 361 |
+
openAIReq.FilterUserMessage()
|
| 362 |
+
}
|
| 363 |
+
requestWebKnowledge := false
|
| 364 |
+
models := []string{openAIReq.Model}
|
| 365 |
+
if strings.HasSuffix(openAIReq.Model, "-search") {
|
| 366 |
+
openAIReq.Model = strings.Replace(openAIReq.Model, "-search", "", 1)
|
| 367 |
+
requestWebKnowledge = true
|
| 368 |
+
models = []string{openAIReq.Model}
|
| 369 |
+
}
|
| 370 |
+
if !lo.Contains(common.TextModelList, openAIReq.Model) {
|
| 371 |
+
models = common.MixtureModelList
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
// 创建请求体
|
| 375 |
+
requestBody := map[string]interface{}{
|
| 376 |
+
"type": chatType,
|
| 377 |
+
"current_query_string": currentQueryString,
|
| 378 |
+
"messages": openAIReq.Messages,
|
| 379 |
+
"action_params": map[string]interface{}{},
|
| 380 |
+
"extra_data": map[string]interface{}{
|
| 381 |
+
"models": models,
|
| 382 |
+
"run_with_another_model": false,
|
| 383 |
+
"writingContent": nil,
|
| 384 |
+
"request_web_knowledge": requestWebKnowledge,
|
| 385 |
+
},
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
logger.Debug(c.Request.Context(), fmt.Sprintf("RequestBody: %v", requestBody))
|
| 389 |
+
|
| 390 |
+
return requestBody, nil
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
func createImageRequestBody(c *gin.Context, cookie string, openAIReq *model.OpenAIImagesGenerationRequest, chatId string) (map[string]interface{}, error) {
|
| 394 |
+
|
| 395 |
+
if openAIReq.Model == "dall-e-3" {
|
| 396 |
+
openAIReq.Model = "dalle-3"
|
| 397 |
+
}
|
| 398 |
+
// 创建模型配置
|
| 399 |
+
modelConfigs := []map[string]interface{}{
|
| 400 |
+
{
|
| 401 |
+
"model": openAIReq.Model,
|
| 402 |
+
"aspect_ratio": "auto",
|
| 403 |
+
"use_personalized_models": false,
|
| 404 |
+
"fashion_profile_id": nil,
|
| 405 |
+
"hd": false,
|
| 406 |
+
"reflection_enabled": false,
|
| 407 |
+
"style": "auto",
|
| 408 |
+
},
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
// 创建消息数组
|
| 412 |
+
var messages []map[string]interface{}
|
| 413 |
+
|
| 414 |
+
if openAIReq.Image != "" {
|
| 415 |
+
var base64Data string
|
| 416 |
+
|
| 417 |
+
if strings.HasPrefix(openAIReq.Image, "http://") || strings.HasPrefix(openAIReq.Image, "https://") {
|
| 418 |
+
// 下载文件
|
| 419 |
+
bytes, err := fetchImageBytes(openAIReq.Image)
|
| 420 |
+
if err != nil {
|
| 421 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("fetchImageBytes err %v\n", err))
|
| 422 |
+
return nil, fmt.Errorf("fetchImageBytes err %v\n", err)
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
contentType := http.DetectContentType(bytes)
|
| 426 |
+
if strings.HasPrefix(contentType, "image/") {
|
| 427 |
+
// 是图片类型,转换为base64
|
| 428 |
+
base64Data = "data:image/jpeg;base64," + base64.StdEncoding.EncodeToString(bytes)
|
| 429 |
+
}
|
| 430 |
+
} else if common.IsImageBase64(openAIReq.Image) {
|
| 431 |
+
// 如果已经是 base64 格式
|
| 432 |
+
if !strings.HasPrefix(openAIReq.Image, "data:image") {
|
| 433 |
+
base64Data = "data:image/jpeg;base64," + openAIReq.Image
|
| 434 |
+
} else {
|
| 435 |
+
base64Data = openAIReq.Image
|
| 436 |
+
}
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
// 构建包含图片的消息
|
| 440 |
+
if base64Data != "" {
|
| 441 |
+
messages = []map[string]interface{}{
|
| 442 |
+
{
|
| 443 |
+
"role": "user",
|
| 444 |
+
"content": []map[string]interface{}{
|
| 445 |
+
{
|
| 446 |
+
"type": "image_url",
|
| 447 |
+
"image_url": map[string]interface{}{
|
| 448 |
+
"url": base64Data,
|
| 449 |
+
},
|
| 450 |
+
},
|
| 451 |
+
{
|
| 452 |
+
"type": "text",
|
| 453 |
+
"text": openAIReq.Prompt,
|
| 454 |
+
},
|
| 455 |
+
},
|
| 456 |
+
},
|
| 457 |
+
}
|
| 458 |
+
}
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
// 如果没有图片或处理图片失败,使用纯文本消息
|
| 462 |
+
if len(messages) == 0 {
|
| 463 |
+
messages = []map[string]interface{}{
|
| 464 |
+
{
|
| 465 |
+
"role": "user",
|
| 466 |
+
"content": openAIReq.Prompt,
|
| 467 |
+
},
|
| 468 |
+
}
|
| 469 |
+
}
|
| 470 |
+
var currentQueryString string
|
| 471 |
+
if len(chatId) != 0 {
|
| 472 |
+
currentQueryString = fmt.Sprintf("id=%s&type=%s", chatId, imageType)
|
| 473 |
+
} else {
|
| 474 |
+
currentQueryString = fmt.Sprintf("type=%s", imageType)
|
| 475 |
+
}
|
| 476 |
+
|
| 477 |
+
// 创建请求体
|
| 478 |
+
requestBody := map[string]interface{}{
|
| 479 |
+
"type": "COPILOT_MOA_IMAGE",
|
| 480 |
+
//"current_query_string": "type=COPILOT_MOA_IMAGE",
|
| 481 |
+
"current_query_string": currentQueryString,
|
| 482 |
+
"messages": messages,
|
| 483 |
+
"user_s_input": openAIReq.Prompt,
|
| 484 |
+
"action_params": map[string]interface{}{},
|
| 485 |
+
"extra_data": map[string]interface{}{
|
| 486 |
+
"model_configs": modelConfigs,
|
| 487 |
+
"llm_model": "gpt-4o",
|
| 488 |
+
"imageModelMap": map[string]interface{}{},
|
| 489 |
+
"writingContent": nil,
|
| 490 |
+
},
|
| 491 |
+
}
|
| 492 |
+
|
| 493 |
+
logger.Debug(c.Request.Context(), fmt.Sprintf("RequestBody: %v", requestBody))
|
| 494 |
+
|
| 495 |
+
if strings.TrimSpace(config.RecaptchaProxyUrl) == "" ||
|
| 496 |
+
(!strings.HasPrefix(config.RecaptchaProxyUrl, "http://") &&
|
| 497 |
+
!strings.HasPrefix(config.RecaptchaProxyUrl, "https://")) {
|
| 498 |
+
return requestBody, nil
|
| 499 |
+
} else {
|
| 500 |
+
|
| 501 |
+
tr := &http.Transport{
|
| 502 |
+
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
| 503 |
+
}
|
| 504 |
+
client := &http.Client{Transport: tr}
|
| 505 |
+
|
| 506 |
+
// 检查并补充 RecaptchaProxyUrl 的末尾斜杠
|
| 507 |
+
if !strings.HasSuffix(config.RecaptchaProxyUrl, "/") {
|
| 508 |
+
config.RecaptchaProxyUrl += "/"
|
| 509 |
+
}
|
| 510 |
+
|
| 511 |
+
// 创建请求
|
| 512 |
+
req, err := http.NewRequest("GET", fmt.Sprintf("%sgenspark", config.RecaptchaProxyUrl), nil)
|
| 513 |
+
if err != nil {
|
| 514 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("创建/genspark请求失败 %v\n", err))
|
| 515 |
+
return nil, err
|
| 516 |
+
}
|
| 517 |
+
|
| 518 |
+
// 设置请求头
|
| 519 |
+
req.Header.Set("Content-Type", "application/json")
|
| 520 |
+
req.Header.Set("Cookie", cookie)
|
| 521 |
+
|
| 522 |
+
// 发送请求
|
| 523 |
+
resp, err := client.Do(req)
|
| 524 |
+
if err != nil {
|
| 525 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("发送/genspark请求失败 %v\n", err))
|
| 526 |
+
return nil, err
|
| 527 |
+
}
|
| 528 |
+
defer resp.Body.Close()
|
| 529 |
+
|
| 530 |
+
// 读取响应体
|
| 531 |
+
body, err := io.ReadAll(resp.Body)
|
| 532 |
+
if err != nil {
|
| 533 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("读取/genspark响应失败 %v\n", err))
|
| 534 |
+
return nil, err
|
| 535 |
+
}
|
| 536 |
+
|
| 537 |
+
type Response struct {
|
| 538 |
+
Code int `json:"code"`
|
| 539 |
+
Token string `json:"token"`
|
| 540 |
+
Message string `json:"message"`
|
| 541 |
+
}
|
| 542 |
+
|
| 543 |
+
if resp.StatusCode == 200 {
|
| 544 |
+
var response Response
|
| 545 |
+
if err := json.Unmarshal(body, &response); err != nil {
|
| 546 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("读取/genspark JSON 失败 %v\n", err))
|
| 547 |
+
return nil, err
|
| 548 |
+
}
|
| 549 |
+
|
| 550 |
+
if response.Code == 200 {
|
| 551 |
+
logger.Debugf(c.Request.Context(), fmt.Sprintf("g_recaptcha_token: %v\n", response.Token))
|
| 552 |
+
requestBody["g_recaptcha_token"] = response.Token
|
| 553 |
+
logger.Infof(c.Request.Context(), fmt.Sprintf("cheat success!"))
|
| 554 |
+
return requestBody, nil
|
| 555 |
+
} else {
|
| 556 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("读取/genspark token 失败 %v\n", err))
|
| 557 |
+
return nil, err
|
| 558 |
+
}
|
| 559 |
+
} else {
|
| 560 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("请求/genspark失败 %v\n", err))
|
| 561 |
+
return nil, err
|
| 562 |
+
}
|
| 563 |
+
}
|
| 564 |
+
}
|
| 565 |
+
|
| 566 |
+
// createStreamResponse 创建流式响应
|
| 567 |
+
func createStreamResponse(responseId, modelName string, jsonData []byte, delta model.OpenAIDelta, finishReason *string) model.OpenAIChatCompletionResponse {
|
| 568 |
+
promptTokens := common.CountTokenText(string(jsonData), modelName)
|
| 569 |
+
completionTokens := common.CountTokenText(delta.Content, modelName)
|
| 570 |
+
return model.OpenAIChatCompletionResponse{
|
| 571 |
+
ID: responseId,
|
| 572 |
+
Object: "chat.completion.chunk",
|
| 573 |
+
Created: time.Now().Unix(),
|
| 574 |
+
Model: modelName,
|
| 575 |
+
Choices: []model.OpenAIChoice{
|
| 576 |
+
{
|
| 577 |
+
Index: 0,
|
| 578 |
+
Delta: delta,
|
| 579 |
+
FinishReason: finishReason,
|
| 580 |
+
},
|
| 581 |
+
},
|
| 582 |
+
Usage: model.OpenAIUsage{
|
| 583 |
+
PromptTokens: promptTokens,
|
| 584 |
+
CompletionTokens: completionTokens,
|
| 585 |
+
TotalTokens: promptTokens + completionTokens,
|
| 586 |
+
},
|
| 587 |
+
}
|
| 588 |
+
}
|
| 589 |
+
|
| 590 |
+
// handleMessageFieldDelta 处理消息字段增量
|
| 591 |
+
func handleMessageFieldDelta(c *gin.Context, event map[string]interface{}, responseId, modelName string, jsonData []byte) error {
|
| 592 |
+
fieldName, ok := event["field_name"].(string)
|
| 593 |
+
if !ok {
|
| 594 |
+
return nil
|
| 595 |
+
}
|
| 596 |
+
|
| 597 |
+
// 基础允许列表(所有配置下都需要处理的字段)
|
| 598 |
+
baseAllowed := fieldName == "session_state.answer" ||
|
| 599 |
+
strings.Contains(fieldName, "session_state.streaming_detail_answer") ||
|
| 600 |
+
fieldName == "session_state.streaming_markmap"
|
| 601 |
+
|
| 602 |
+
// 需要显示思考过程时需要额外处理的字段
|
| 603 |
+
if config.ReasoningHide != 1 {
|
| 604 |
+
baseAllowed = baseAllowed ||
|
| 605 |
+
fieldName == "session_state.answerthink_is_started" ||
|
| 606 |
+
fieldName == "session_state.answerthink" ||
|
| 607 |
+
fieldName == "session_state.answerthink_is_finished"
|
| 608 |
+
}
|
| 609 |
+
|
| 610 |
+
if !baseAllowed {
|
| 611 |
+
return nil
|
| 612 |
+
}
|
| 613 |
+
|
| 614 |
+
// 获取 delta 内容
|
| 615 |
+
var delta string
|
| 616 |
+
switch {
|
| 617 |
+
case (modelName == "o1" || modelName == "o3-mini-high") && fieldName == "session_state.answer":
|
| 618 |
+
delta, _ = event["field_value"].(string)
|
| 619 |
+
default:
|
| 620 |
+
delta, _ = event["delta"].(string)
|
| 621 |
+
}
|
| 622 |
+
|
| 623 |
+
// 创建基础响应
|
| 624 |
+
createResponse := func(content string) model.OpenAIChatCompletionResponse {
|
| 625 |
+
return createStreamResponse(
|
| 626 |
+
responseId,
|
| 627 |
+
modelName,
|
| 628 |
+
jsonData,
|
| 629 |
+
model.OpenAIDelta{Content: content, Role: "assistant"},
|
| 630 |
+
nil,
|
| 631 |
+
)
|
| 632 |
+
}
|
| 633 |
+
|
| 634 |
+
// 发送基础事件
|
| 635 |
+
var err error
|
| 636 |
+
if err = sendSSEvent(c, createResponse(delta)); err != nil {
|
| 637 |
+
return err
|
| 638 |
+
}
|
| 639 |
+
|
| 640 |
+
// 处理思考过程标记
|
| 641 |
+
if config.ReasoningHide != 1 {
|
| 642 |
+
switch fieldName {
|
| 643 |
+
case "session_state.answerthink_is_started":
|
| 644 |
+
err = sendSSEvent(c, createResponse("<think>\n"))
|
| 645 |
+
case "session_state.answerthink_is_finished":
|
| 646 |
+
err = sendSSEvent(c, createResponse("\n</think>"))
|
| 647 |
+
}
|
| 648 |
+
}
|
| 649 |
+
|
| 650 |
+
return err
|
| 651 |
+
}
|
| 652 |
+
|
| 653 |
+
type Content struct {
|
| 654 |
+
DetailAnswer string `json:"detailAnswer"`
|
| 655 |
+
}
|
| 656 |
+
|
| 657 |
+
func getDetailAnswer(eventMap map[string]interface{}) (string, error) {
|
| 658 |
+
// 获取 content 字段的值
|
| 659 |
+
contentStr, ok := eventMap["content"].(string)
|
| 660 |
+
if !ok {
|
| 661 |
+
return "", fmt.Errorf("content is not a string")
|
| 662 |
+
}
|
| 663 |
+
|
| 664 |
+
// 解析内层的 JSON
|
| 665 |
+
var content Content
|
| 666 |
+
if err := json.Unmarshal([]byte(contentStr), &content); err != nil {
|
| 667 |
+
return "", err
|
| 668 |
+
}
|
| 669 |
+
|
| 670 |
+
return content.DetailAnswer, nil
|
| 671 |
+
}
|
| 672 |
+
|
| 673 |
+
// handleMessageResult 处理消息结果
|
| 674 |
+
func handleMessageResult(c *gin.Context, event map[string]interface{}, responseId, modelName string, jsonData []byte, searchModel bool) bool {
|
| 675 |
+
finishReason := "stop"
|
| 676 |
+
var delta string
|
| 677 |
+
var err error
|
| 678 |
+
if modelName == "o1" && searchModel {
|
| 679 |
+
delta, err = getDetailAnswer(event)
|
| 680 |
+
if err != nil {
|
| 681 |
+
logger.Errorf(c.Request.Context(), "getDetailAnswer err: %v", err)
|
| 682 |
+
return false
|
| 683 |
+
}
|
| 684 |
+
}
|
| 685 |
+
|
| 686 |
+
streamResp := createStreamResponse(responseId, modelName, jsonData, model.OpenAIDelta{Content: delta, Role: "assistant"}, &finishReason)
|
| 687 |
+
if err := sendSSEvent(c, streamResp); err != nil {
|
| 688 |
+
logger.Warnf(c.Request.Context(), "sendSSEvent err: %v", err)
|
| 689 |
+
return false
|
| 690 |
+
}
|
| 691 |
+
c.SSEvent("", " [DONE]")
|
| 692 |
+
return false
|
| 693 |
+
}
|
| 694 |
+
|
| 695 |
+
// sendSSEvent 发送SSE事件
|
| 696 |
+
func sendSSEvent(c *gin.Context, response model.OpenAIChatCompletionResponse) error {
|
| 697 |
+
jsonResp, err := json.Marshal(response)
|
| 698 |
+
if err != nil {
|
| 699 |
+
logger.Errorf(c.Request.Context(), "Failed to marshal response: %v", err)
|
| 700 |
+
return err
|
| 701 |
+
}
|
| 702 |
+
c.SSEvent("", " "+string(jsonResp))
|
| 703 |
+
c.Writer.Flush()
|
| 704 |
+
return nil
|
| 705 |
+
}
|
| 706 |
+
|
| 707 |
+
// makeRequest 发送HTTP请求
|
| 708 |
+
func makeRequest(client cycletls.CycleTLS, jsonData []byte, cookie string, isStream bool) (cycletls.Response, error) {
|
| 709 |
+
accept := "application/json"
|
| 710 |
+
if isStream {
|
| 711 |
+
accept = "text/event-stream"
|
| 712 |
+
}
|
| 713 |
+
|
| 714 |
+
return client.Do(apiEndpoint, cycletls.Options{
|
| 715 |
+
Timeout: 10 * 60 * 60,
|
| 716 |
+
Proxy: config.ProxyUrl, // 在每个请求中设置代理
|
| 717 |
+
Body: string(jsonData),
|
| 718 |
+
Method: "POST",
|
| 719 |
+
Headers: map[string]string{
|
| 720 |
+
"Content-Type": "application/json",
|
| 721 |
+
"Accept": accept,
|
| 722 |
+
"Origin": baseURL,
|
| 723 |
+
"Referer": baseURL + "/",
|
| 724 |
+
"Cookie": cookie,
|
| 725 |
+
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome",
|
| 726 |
+
},
|
| 727 |
+
}, "POST")
|
| 728 |
+
}
|
| 729 |
+
|
| 730 |
+
// makeRequest 发送HTTP请求
|
| 731 |
+
func makeImageRequest(client cycletls.CycleTLS, jsonData []byte, cookie string) (cycletls.Response, error) {
|
| 732 |
+
|
| 733 |
+
accept := "*/*"
|
| 734 |
+
|
| 735 |
+
return client.Do(apiEndpoint, cycletls.Options{
|
| 736 |
+
UserAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome",
|
| 737 |
+
Timeout: 10 * 60 * 60,
|
| 738 |
+
Proxy: config.ProxyUrl, // 在每个请求中设置代理
|
| 739 |
+
Body: string(jsonData),
|
| 740 |
+
Method: "POST",
|
| 741 |
+
Headers: map[string]string{
|
| 742 |
+
"Content-Type": "application/json",
|
| 743 |
+
"Accept": accept,
|
| 744 |
+
"Origin": baseURL,
|
| 745 |
+
"Referer": baseURL + "/",
|
| 746 |
+
"Cookie": cookie,
|
| 747 |
+
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome",
|
| 748 |
+
},
|
| 749 |
+
}, "POST")
|
| 750 |
+
}
|
| 751 |
+
|
| 752 |
+
func makeDeleteRequest(client cycletls.CycleTLS, cookie, projectId string) (cycletls.Response, error) {
|
| 753 |
+
|
| 754 |
+
// 不删除环境变量中的map中的对话
|
| 755 |
+
|
| 756 |
+
for _, v := range config.ModelChatMap {
|
| 757 |
+
if v == projectId {
|
| 758 |
+
return cycletls.Response{}, nil
|
| 759 |
+
}
|
| 760 |
+
}
|
| 761 |
+
for _, v := range config.GlobalSessionManager.GetChatIDsByCookie(cookie) {
|
| 762 |
+
if v == projectId {
|
| 763 |
+
return cycletls.Response{}, nil
|
| 764 |
+
}
|
| 765 |
+
}
|
| 766 |
+
for _, v := range config.SessionImageChatMap {
|
| 767 |
+
if v == projectId {
|
| 768 |
+
return cycletls.Response{}, nil
|
| 769 |
+
}
|
| 770 |
+
}
|
| 771 |
+
|
| 772 |
+
accept := "application/json"
|
| 773 |
+
|
| 774 |
+
return client.Do(fmt.Sprintf(deleteEndpoint, projectId), cycletls.Options{
|
| 775 |
+
Timeout: 10 * 60 * 60,
|
| 776 |
+
Proxy: config.ProxyUrl, // 在每个请求中设置代理
|
| 777 |
+
Method: "GET",
|
| 778 |
+
Headers: map[string]string{
|
| 779 |
+
"Content-Type": "application/json",
|
| 780 |
+
"Accept": accept,
|
| 781 |
+
"Origin": baseURL,
|
| 782 |
+
"Referer": baseURL + "/",
|
| 783 |
+
"Cookie": cookie,
|
| 784 |
+
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome",
|
| 785 |
+
},
|
| 786 |
+
}, "GET")
|
| 787 |
+
}
|
| 788 |
+
|
| 789 |
+
func makeGetUploadUrlRequest(client cycletls.CycleTLS, cookie string) (cycletls.Response, error) {
|
| 790 |
+
|
| 791 |
+
accept := "*/*"
|
| 792 |
+
|
| 793 |
+
return client.Do(fmt.Sprintf(uploadEndpoint), cycletls.Options{
|
| 794 |
+
Timeout: 10 * 60 * 60,
|
| 795 |
+
Proxy: config.ProxyUrl, // 在每个请求中设置代理
|
| 796 |
+
Method: "GET",
|
| 797 |
+
Headers: map[string]string{
|
| 798 |
+
"Content-Type": "application/json",
|
| 799 |
+
"Accept": accept,
|
| 800 |
+
"Origin": baseURL,
|
| 801 |
+
"Referer": baseURL + "/",
|
| 802 |
+
"Cookie": cookie,
|
| 803 |
+
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome",
|
| 804 |
+
},
|
| 805 |
+
}, "GET")
|
| 806 |
+
}
|
| 807 |
+
|
| 808 |
+
//func makeOptionsRequest(client cycletls.CycleTLS, uploadUrl string) (cycletls.Response, error) {
|
| 809 |
+
// return client.Do(uploadUrl, cycletls.Options{
|
| 810 |
+
// Method: "OPTIONS",
|
| 811 |
+
// Headers: map[string]string{
|
| 812 |
+
// "Accept": "*/*",
|
| 813 |
+
// "Access-Control-Request-Headers": "x-ms-blob-type",
|
| 814 |
+
// "Access-Control-Request-Method": "PUT",
|
| 815 |
+
// "Origin": "https://www.genspark.ai",
|
| 816 |
+
// "Sec-Fetch-Dest": "empty",
|
| 817 |
+
// "Sec-Fetch-Mode": "cors",
|
| 818 |
+
// "Sec-Fetch-Site": "cross-site",
|
| 819 |
+
// },
|
| 820 |
+
// UserAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
|
| 821 |
+
// }, "OPTIONS")
|
| 822 |
+
//}
|
| 823 |
+
|
| 824 |
+
func makeUploadRequest(client cycletls.CycleTLS, uploadUrl string, fileBytes []byte) (cycletls.Response, error) {
|
| 825 |
+
return client.Do(uploadUrl, cycletls.Options{
|
| 826 |
+
Timeout: 10 * 60 * 60,
|
| 827 |
+
Proxy: config.ProxyUrl, // 在每个请求中设置代理
|
| 828 |
+
Method: "PUT",
|
| 829 |
+
Body: string(fileBytes),
|
| 830 |
+
Headers: map[string]string{
|
| 831 |
+
"Accept": "*/*",
|
| 832 |
+
"x-ms-blob-type": "BlockBlob",
|
| 833 |
+
"Content-Type": "application/octet-stream",
|
| 834 |
+
"Content-Length": fmt.Sprintf("%d", len(fileBytes)),
|
| 835 |
+
"Origin": "https://www.genspark.ai",
|
| 836 |
+
"Sec-Fetch-Dest": "empty",
|
| 837 |
+
"Sec-Fetch-Mode": "cors",
|
| 838 |
+
"Sec-Fetch-Site": "cross-site",
|
| 839 |
+
},
|
| 840 |
+
}, "PUT")
|
| 841 |
+
}
|
| 842 |
+
|
| 843 |
+
// handleStreamRequest 处理流式请求
|
| 844 |
+
//func handleStreamRequest(c *gin.Context, client cycletls.CycleTLS, cookie string, jsonData []byte, model string) {
|
| 845 |
+
// c.Header("Content-Type", "text/event-stream")
|
| 846 |
+
// c.Header("Cache-Control", "no-cache")
|
| 847 |
+
// c.Header("Connection", "keep-alive")
|
| 848 |
+
//
|
| 849 |
+
// responseId := fmt.Sprintf(responseIDFormat, time.Now().Format("20060102150405"))
|
| 850 |
+
//
|
| 851 |
+
// c.Stream(func(w io.Writer) bool {
|
| 852 |
+
// sseChan, err := makeStreamRequest(c, client, jsonData, cookie)
|
| 853 |
+
// if err != nil {
|
| 854 |
+
// logger.Errorf(c.Request.Context(), "makeStreamRequest err: %v", err)
|
| 855 |
+
// return false
|
| 856 |
+
// }
|
| 857 |
+
//
|
| 858 |
+
// return handleStreamResponse(c, sseChan, responseId, cookie, model, jsonData)
|
| 859 |
+
// })
|
| 860 |
+
//}
|
| 861 |
+
|
| 862 |
+
func handleStreamRequest(c *gin.Context, client cycletls.CycleTLS, cookie string, cookieManager *config.CookieManager, requestBody map[string]interface{}, modelName string, searchModel bool) {
|
| 863 |
+
const (
|
| 864 |
+
errNoValidCookies = "No valid cookies available"
|
| 865 |
+
errCloudflareChallengeMsg = "Detected Cloudflare Challenge Page"
|
| 866 |
+
errCloudflareBlock = "CloudFlare: Sorry, you have been blocked"
|
| 867 |
+
errServerErrMsg = "An error occurred with the current request, please try again."
|
| 868 |
+
errServiceUnavailable = "Genspark Service Unavailable"
|
| 869 |
+
)
|
| 870 |
+
|
| 871 |
+
c.Header("Content-Type", "text/event-stream")
|
| 872 |
+
c.Header("Cache-Control", "no-cache")
|
| 873 |
+
c.Header("Connection", "keep-alive")
|
| 874 |
+
|
| 875 |
+
responseId := fmt.Sprintf(responseIDFormat, time.Now().Format("20060102150405"))
|
| 876 |
+
ctx := c.Request.Context()
|
| 877 |
+
maxRetries := len(cookieManager.Cookies)
|
| 878 |
+
|
| 879 |
+
c.Stream(func(w io.Writer) bool {
|
| 880 |
+
for attempt := 0; attempt < maxRetries; attempt++ {
|
| 881 |
+
|
| 882 |
+
requestBody, err := cheat(requestBody, c, cookie)
|
| 883 |
+
if err != nil {
|
| 884 |
+
c.JSON(500, gin.H{"error": err.Error()})
|
| 885 |
+
return false
|
| 886 |
+
}
|
| 887 |
+
jsonData, err := json.Marshal(requestBody)
|
| 888 |
+
if err != nil {
|
| 889 |
+
c.JSON(500, gin.H{"error": "Failed to marshal request body"})
|
| 890 |
+
return false
|
| 891 |
+
}
|
| 892 |
+
sseChan, err := makeStreamRequest(c, client, jsonData, cookie)
|
| 893 |
+
if err != nil {
|
| 894 |
+
logger.Errorf(ctx, "makeStreamRequest err on attempt %d: %v", attempt+1, err)
|
| 895 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
| 896 |
+
return false
|
| 897 |
+
}
|
| 898 |
+
|
| 899 |
+
var projectId string
|
| 900 |
+
isRateLimit := false
|
| 901 |
+
SSELoop:
|
| 902 |
+
for response := range sseChan {
|
| 903 |
+
if response.Done {
|
| 904 |
+
logger.Debugf(ctx, response.Data)
|
| 905 |
+
return false
|
| 906 |
+
}
|
| 907 |
+
|
| 908 |
+
data := response.Data
|
| 909 |
+
if data == "" {
|
| 910 |
+
continue
|
| 911 |
+
}
|
| 912 |
+
|
| 913 |
+
logger.Debug(ctx, strings.TrimSpace(data))
|
| 914 |
+
|
| 915 |
+
switch {
|
| 916 |
+
case common.IsCloudflareChallenge(data):
|
| 917 |
+
logger.Errorf(ctx, errCloudflareChallengeMsg)
|
| 918 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": errCloudflareChallengeMsg})
|
| 919 |
+
return false
|
| 920 |
+
case common.IsCloudflareBlock(data):
|
| 921 |
+
logger.Errorf(ctx, errCloudflareBlock)
|
| 922 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": errCloudflareBlock})
|
| 923 |
+
return false
|
| 924 |
+
case common.IsServiceUnavailablePage(data):
|
| 925 |
+
logger.Errorf(ctx, errServiceUnavailable)
|
| 926 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": errServiceUnavailable})
|
| 927 |
+
return false
|
| 928 |
+
case common.IsServerError(data):
|
| 929 |
+
logger.Errorf(ctx, errServerErrMsg)
|
| 930 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": errServerErrMsg})
|
| 931 |
+
return false
|
| 932 |
+
case common.IsRateLimit(data):
|
| 933 |
+
isRateLimit = true
|
| 934 |
+
logger.Warnf(ctx, "Cookie rate limited, switching to next cookie, attempt %d/%d, COOKIE:%s", attempt+1, maxRetries, cookie)
|
| 935 |
+
config.AddRateLimitCookie(cookie, time.Now().Add(time.Duration(config.RateLimitCookieLockDuration)*time.Second))
|
| 936 |
+
break SSELoop // 使用 label 跳出 SSE 循环
|
| 937 |
+
case common.IsFreeLimit(data):
|
| 938 |
+
isRateLimit = true
|
| 939 |
+
logger.Warnf(ctx, "Cookie free rate limited, switching to next cookie, attempt %d/%d, COOKIE:%s", attempt+1, maxRetries, cookie)
|
| 940 |
+
config.AddRateLimitCookie(cookie, time.Now().Add(24*60*60*time.Second))
|
| 941 |
+
// 删除cookie
|
| 942 |
+
//config.RemoveCookie(cookie)
|
| 943 |
+
break SSELoop // 使用 label 跳出 SSE 循环
|
| 944 |
+
case common.IsNotLogin(data):
|
| 945 |
+
isRateLimit = true
|
| 946 |
+
logger.Warnf(ctx, "Cookie Not Login, switching to next cookie, attempt %d/%d, COOKIE:%s", attempt+1, maxRetries, cookie)
|
| 947 |
+
// 删除cookie
|
| 948 |
+
config.RemoveCookie(cookie)
|
| 949 |
+
break SSELoop // 使用 label 跳出 SSE 循环
|
| 950 |
+
}
|
| 951 |
+
|
| 952 |
+
// 处理事件流数据
|
| 953 |
+
if shouldContinue := processStreamData(c, data, &projectId, cookie, responseId, modelName, jsonData, searchModel); !shouldContinue {
|
| 954 |
+
return false
|
| 955 |
+
}
|
| 956 |
+
}
|
| 957 |
+
|
| 958 |
+
if !isRateLimit {
|
| 959 |
+
return true
|
| 960 |
+
}
|
| 961 |
+
|
| 962 |
+
// 获取下一个可用的cookie继续尝试
|
| 963 |
+
cookie, err = cookieManager.GetNextCookie()
|
| 964 |
+
if err != nil {
|
| 965 |
+
logger.Errorf(ctx, "No more valid cookies available after attempt %d", attempt+1)
|
| 966 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": errNoValidCookies})
|
| 967 |
+
return false
|
| 968 |
+
}
|
| 969 |
+
|
| 970 |
+
// requestBody重制chatId
|
| 971 |
+
currentQueryString := fmt.Sprintf("type=%s", chatType)
|
| 972 |
+
if chatId, ok := config.GlobalSessionManager.GetChatID(cookie, modelName); ok {
|
| 973 |
+
currentQueryString = fmt.Sprintf("id=%s&type=%s", chatId, chatType)
|
| 974 |
+
}
|
| 975 |
+
requestBody["current_query_string"] = currentQueryString
|
| 976 |
+
}
|
| 977 |
+
|
| 978 |
+
logger.Errorf(ctx, "All cookies exhausted after %d attempts", maxRetries)
|
| 979 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": "All cookies are temporarily unavailable."})
|
| 980 |
+
return false
|
| 981 |
+
})
|
| 982 |
+
}
|
| 983 |
+
|
| 984 |
+
func cheat(requestBody map[string]interface{}, c *gin.Context, cookie string) (map[string]interface{}, error) {
|
| 985 |
+
if strings.TrimSpace(config.RecaptchaProxyUrl) == "" ||
|
| 986 |
+
(!strings.HasPrefix(config.RecaptchaProxyUrl, "http://") &&
|
| 987 |
+
!strings.HasPrefix(config.RecaptchaProxyUrl, "https://")) {
|
| 988 |
+
return requestBody, nil
|
| 989 |
+
} else {
|
| 990 |
+
|
| 991 |
+
tr := &http.Transport{
|
| 992 |
+
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
| 993 |
+
}
|
| 994 |
+
client := &http.Client{Transport: tr}
|
| 995 |
+
|
| 996 |
+
// 检查并补充 RecaptchaProxyUrl 的末尾斜杠
|
| 997 |
+
if !strings.HasSuffix(config.RecaptchaProxyUrl, "/") {
|
| 998 |
+
config.RecaptchaProxyUrl += "/"
|
| 999 |
+
}
|
| 1000 |
+
|
| 1001 |
+
// 创建请求
|
| 1002 |
+
req, err := http.NewRequest("GET", fmt.Sprintf("%sgenspark", config.RecaptchaProxyUrl), nil)
|
| 1003 |
+
if err != nil {
|
| 1004 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("创建/genspark请求失败 %v\n", err))
|
| 1005 |
+
return nil, err
|
| 1006 |
+
}
|
| 1007 |
+
|
| 1008 |
+
// 设置请求头
|
| 1009 |
+
req.Header.Set("Content-Type", "application/json")
|
| 1010 |
+
req.Header.Set("Cookie", cookie)
|
| 1011 |
+
|
| 1012 |
+
// 发送请求
|
| 1013 |
+
resp, err := client.Do(req)
|
| 1014 |
+
if err != nil {
|
| 1015 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("发送/genspark请求失败 %v\n", err))
|
| 1016 |
+
return nil, err
|
| 1017 |
+
}
|
| 1018 |
+
defer resp.Body.Close()
|
| 1019 |
+
|
| 1020 |
+
// 读取响应体
|
| 1021 |
+
body, err := io.ReadAll(resp.Body)
|
| 1022 |
+
if err != nil {
|
| 1023 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("读取/genspark响应失败 %v\n", err))
|
| 1024 |
+
return nil, err
|
| 1025 |
+
}
|
| 1026 |
+
|
| 1027 |
+
type Response struct {
|
| 1028 |
+
Code int `json:"code"`
|
| 1029 |
+
Token string `json:"token"`
|
| 1030 |
+
Message string `json:"message"`
|
| 1031 |
+
}
|
| 1032 |
+
|
| 1033 |
+
if resp.StatusCode == 200 {
|
| 1034 |
+
var response Response
|
| 1035 |
+
if err := json.Unmarshal(body, &response); err != nil {
|
| 1036 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("读取/genspark JSON 失败 %v\n", err))
|
| 1037 |
+
return nil, err
|
| 1038 |
+
}
|
| 1039 |
+
|
| 1040 |
+
if response.Code == 200 {
|
| 1041 |
+
logger.Debugf(c.Request.Context(), fmt.Sprintf("g_recaptcha_token: %v\n", response.Token))
|
| 1042 |
+
requestBody["g_recaptcha_token"] = response.Token
|
| 1043 |
+
logger.Infof(c.Request.Context(), fmt.Sprintf("cheat success!"))
|
| 1044 |
+
return requestBody, nil
|
| 1045 |
+
} else {
|
| 1046 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("读取/genspark token 失败,查看 playwright-proxy log"))
|
| 1047 |
+
return nil, err
|
| 1048 |
+
}
|
| 1049 |
+
} else {
|
| 1050 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("请求/genspark失败,查看 playwright-proxy log"))
|
| 1051 |
+
return nil, err
|
| 1052 |
+
}
|
| 1053 |
+
}
|
| 1054 |
+
}
|
| 1055 |
+
|
| 1056 |
+
// 处理流式数据的辅助函数,返回bool表示是否继续处理
|
| 1057 |
+
func processStreamData(c *gin.Context, data string, projectId *string, cookie, responseId, model string, jsonData []byte, searchModel bool) bool {
|
| 1058 |
+
data = strings.TrimSpace(data)
|
| 1059 |
+
//if !strings.HasPrefix(data, "data: ") {
|
| 1060 |
+
// return true
|
| 1061 |
+
//}
|
| 1062 |
+
data = strings.TrimPrefix(data, "data: ")
|
| 1063 |
+
if !strings.HasPrefix(data, "{\"id\":") && !strings.HasPrefix(data, "{\"message_id\":") {
|
| 1064 |
+
return true
|
| 1065 |
+
}
|
| 1066 |
+
var event map[string]interface{}
|
| 1067 |
+
if err := json.Unmarshal([]byte(data), &event); err != nil {
|
| 1068 |
+
logger.Errorf(c.Request.Context(), "Failed to unmarshal event: %v", err)
|
| 1069 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
| 1070 |
+
return false
|
| 1071 |
+
}
|
| 1072 |
+
|
| 1073 |
+
eventType, ok := event["type"].(string)
|
| 1074 |
+
if !ok {
|
| 1075 |
+
return true
|
| 1076 |
+
}
|
| 1077 |
+
|
| 1078 |
+
switch eventType {
|
| 1079 |
+
case "project_start":
|
| 1080 |
+
*projectId, _ = event["id"].(string)
|
| 1081 |
+
case "message_field":
|
| 1082 |
+
if err := handleMessageFieldDelta(c, event, responseId, model, jsonData); err != nil {
|
| 1083 |
+
logger.Errorf(c.Request.Context(), "handleMessageFieldDelta err: %v", err)
|
| 1084 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
| 1085 |
+
return false
|
| 1086 |
+
}
|
| 1087 |
+
case "message_field_delta":
|
| 1088 |
+
if err := handleMessageFieldDelta(c, event, responseId, model, jsonData); err != nil {
|
| 1089 |
+
logger.Errorf(c.Request.Context(), "handleMessageFieldDelta err: %v", err)
|
| 1090 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
| 1091 |
+
return false
|
| 1092 |
+
}
|
| 1093 |
+
case "message_result":
|
| 1094 |
+
go func() {
|
| 1095 |
+
if config.AutoModelChatMapType == 1 {
|
| 1096 |
+
// 保存映射
|
| 1097 |
+
config.GlobalSessionManager.AddSession(cookie, model, *projectId)
|
| 1098 |
+
} else {
|
| 1099 |
+
if config.AutoDelChat == 1 {
|
| 1100 |
+
client := cycletls.Init()
|
| 1101 |
+
defer safeClose(client)
|
| 1102 |
+
makeDeleteRequest(client, cookie, *projectId)
|
| 1103 |
+
}
|
| 1104 |
+
}
|
| 1105 |
+
}()
|
| 1106 |
+
|
| 1107 |
+
return handleMessageResult(c, event, responseId, model, jsonData, searchModel)
|
| 1108 |
+
}
|
| 1109 |
+
|
| 1110 |
+
return true
|
| 1111 |
+
}
|
| 1112 |
+
|
| 1113 |
+
func makeStreamRequest(c *gin.Context, client cycletls.CycleTLS, jsonData []byte, cookie string) (<-chan cycletls.SSEResponse, error) {
|
| 1114 |
+
|
| 1115 |
+
options := cycletls.Options{
|
| 1116 |
+
Timeout: 10 * 60 * 60,
|
| 1117 |
+
Proxy: config.ProxyUrl, // 在每个请求中设置代理
|
| 1118 |
+
Body: string(jsonData),
|
| 1119 |
+
Method: "POST",
|
| 1120 |
+
Headers: map[string]string{
|
| 1121 |
+
"Content-Type": "application/json",
|
| 1122 |
+
"Accept": "text/event-stream",
|
| 1123 |
+
"Origin": baseURL,
|
| 1124 |
+
"Referer": baseURL + "/",
|
| 1125 |
+
"Cookie": cookie,
|
| 1126 |
+
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome",
|
| 1127 |
+
},
|
| 1128 |
+
}
|
| 1129 |
+
|
| 1130 |
+
logger.Debug(c.Request.Context(), fmt.Sprintf("cookie: %v", cookie))
|
| 1131 |
+
|
| 1132 |
+
sseChan, err := client.DoSSE(apiEndpoint, options, "POST")
|
| 1133 |
+
if err != nil {
|
| 1134 |
+
logger.Errorf(c, "Failed to make stream request: %v", err)
|
| 1135 |
+
return nil, fmt.Errorf("Failed to make stream request: %v", err)
|
| 1136 |
+
}
|
| 1137 |
+
return sseChan, nil
|
| 1138 |
+
}
|
| 1139 |
+
|
| 1140 |
+
// handleNonStreamRequest 处理非流式请求
|
| 1141 |
+
//
|
| 1142 |
+
// func handleNonStreamRequest(c *gin.Context, client cycletls.CycleTLS, cookie string, jsonData []byte, modelName string) {
|
| 1143 |
+
// response, err := makeRequest(client, jsonData, cookie, false)
|
| 1144 |
+
// if err != nil {
|
| 1145 |
+
// logger.Errorf(c.Request.Context(), "makeRequest err: %v", err)
|
| 1146 |
+
// c.JSON(500, gin.H{"error": err.Error()})
|
| 1147 |
+
// return
|
| 1148 |
+
// }
|
| 1149 |
+
//
|
| 1150 |
+
// reader := strings.NewReader(response.Body)
|
| 1151 |
+
// scanner := bufio.NewScanner(reader)
|
| 1152 |
+
//
|
| 1153 |
+
// var content string
|
| 1154 |
+
// var firstline string
|
| 1155 |
+
// for scanner.Scan() {
|
| 1156 |
+
// line := scanner.Text()
|
| 1157 |
+
// firstline = line
|
| 1158 |
+
// logger.Debug(c.Request.Context(), strings.TrimSpace(line))
|
| 1159 |
+
//
|
| 1160 |
+
// if common.IsCloudflareChallenge(line) {
|
| 1161 |
+
// logger.Errorf(c.Request.Context(), "Detected Cloudflare Challenge Page")
|
| 1162 |
+
// c.JSON(500, gin.H{"error": "Detected Cloudflare Challenge Page"})
|
| 1163 |
+
// return
|
| 1164 |
+
// }
|
| 1165 |
+
//
|
| 1166 |
+
// if common.IsRateLimit(line) {
|
| 1167 |
+
// logger.Errorf(c.Request.Context(), "Cookie has reached the rate Limit")
|
| 1168 |
+
// c.JSON(500, gin.H{"error": "Cookie has reached the rate Limit"})
|
| 1169 |
+
// return
|
| 1170 |
+
// }
|
| 1171 |
+
//
|
| 1172 |
+
// if strings.HasPrefix(line, "data: ") {
|
| 1173 |
+
// data := strings.TrimPrefix(line, "data: ")
|
| 1174 |
+
// var parsedResponse struct {
|
| 1175 |
+
// Type string `json:"type"`
|
| 1176 |
+
// FieldName string `json:"field_name"`
|
| 1177 |
+
// Content string `json:"content"`
|
| 1178 |
+
// }
|
| 1179 |
+
// if err := json.Unmarshal([]byte(data), &parsedResponse); err != nil {
|
| 1180 |
+
// logger.Warnf(c.Request.Context(), "Failed to unmarshal response: %v", err)
|
| 1181 |
+
// continue
|
| 1182 |
+
// }
|
| 1183 |
+
// if parsedResponse.Type == "message_result" {
|
| 1184 |
+
// content = parsedResponse.Content
|
| 1185 |
+
// break
|
| 1186 |
+
// }
|
| 1187 |
+
// }
|
| 1188 |
+
// }
|
| 1189 |
+
//
|
| 1190 |
+
// if content == "" {
|
| 1191 |
+
// logger.Errorf(c.Request.Context(), firstline)
|
| 1192 |
+
// c.JSON(500, gin.H{"error": "No valid response content"})
|
| 1193 |
+
// return
|
| 1194 |
+
// }
|
| 1195 |
+
//
|
| 1196 |
+
// promptTokens := common.CountTokenText(string(jsonData), modelName)
|
| 1197 |
+
// completionTokens := common.CountTokenText(content, modelName)
|
| 1198 |
+
//
|
| 1199 |
+
// finishReason := "stop"
|
| 1200 |
+
// // 创建并返回 OpenAIChatCompletionResponse 结构
|
| 1201 |
+
// resp := model.OpenAIChatCompletionResponse{
|
| 1202 |
+
// ID: fmt.Sprintf(responseIDFormat, time.Now().Format("20060102150405")),
|
| 1203 |
+
// Object: "chat.completion",
|
| 1204 |
+
// Created: time.Now().Unix(),
|
| 1205 |
+
// Model: modelName,
|
| 1206 |
+
// Choices: []model.OpenAIChoice{
|
| 1207 |
+
// {
|
| 1208 |
+
// Message: model.OpenAIMessage{
|
| 1209 |
+
// Role: "assistant",
|
| 1210 |
+
// Content: content,
|
| 1211 |
+
// },
|
| 1212 |
+
// FinishReason: &finishReason,
|
| 1213 |
+
// },
|
| 1214 |
+
// },
|
| 1215 |
+
// Usage: model.OpenAIUsage{
|
| 1216 |
+
// PromptTokens: promptTokens,
|
| 1217 |
+
// CompletionTokens: completionTokens,
|
| 1218 |
+
// TotalTokens: promptTokens + completionTokens,
|
| 1219 |
+
// },
|
| 1220 |
+
// }
|
| 1221 |
+
//
|
| 1222 |
+
// c.JSON(200, resp)
|
| 1223 |
+
// }
|
| 1224 |
+
func handleNonStreamRequest(c *gin.Context, client cycletls.CycleTLS, cookie string, cookieManager *config.CookieManager, requestBody map[string]interface{}, modelName string, searchModel bool) {
|
| 1225 |
+
const (
|
| 1226 |
+
errCloudflareChallengeMsg = "Detected Cloudflare Challenge Page"
|
| 1227 |
+
errCloudflareBlock = "CloudFlare: Sorry, you have been blocked"
|
| 1228 |
+
errServerErrMsg = "An error occurred with the current request, please try again."
|
| 1229 |
+
errServiceUnavailable = "Genspark Service Unavailable"
|
| 1230 |
+
errNoValidResponseContent = "No valid response content"
|
| 1231 |
+
)
|
| 1232 |
+
|
| 1233 |
+
ctx := c.Request.Context()
|
| 1234 |
+
maxRetries := len(cookieManager.Cookies)
|
| 1235 |
+
|
| 1236 |
+
for attempt := 0; attempt < maxRetries; attempt++ {
|
| 1237 |
+
requestBody, err := cheat(requestBody, c, cookie)
|
| 1238 |
+
if err != nil {
|
| 1239 |
+
c.JSON(500, gin.H{"error": err.Error()})
|
| 1240 |
+
return
|
| 1241 |
+
}
|
| 1242 |
+
jsonData, err := json.Marshal(requestBody)
|
| 1243 |
+
if err != nil {
|
| 1244 |
+
c.JSON(500, gin.H{"error": "Failed to marshal request body"})
|
| 1245 |
+
return
|
| 1246 |
+
}
|
| 1247 |
+
response, err := makeRequest(client, jsonData, cookie, false)
|
| 1248 |
+
if err != nil {
|
| 1249 |
+
logger.Errorf(ctx, "makeRequest err: %v", err)
|
| 1250 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
| 1251 |
+
return
|
| 1252 |
+
}
|
| 1253 |
+
|
| 1254 |
+
scanner := bufio.NewScanner(strings.NewReader(response.Body))
|
| 1255 |
+
var content string
|
| 1256 |
+
var answerThink string
|
| 1257 |
+
var firstLine string
|
| 1258 |
+
var projectId string
|
| 1259 |
+
isRateLimit := false
|
| 1260 |
+
|
| 1261 |
+
for scanner.Scan() {
|
| 1262 |
+
line := scanner.Text()
|
| 1263 |
+
if firstLine == "" {
|
| 1264 |
+
firstLine = line
|
| 1265 |
+
}
|
| 1266 |
+
if line == "" {
|
| 1267 |
+
continue
|
| 1268 |
+
}
|
| 1269 |
+
logger.Debug(ctx, strings.TrimSpace(line))
|
| 1270 |
+
|
| 1271 |
+
switch {
|
| 1272 |
+
case common.IsCloudflareChallenge(line):
|
| 1273 |
+
logger.Errorf(ctx, errCloudflareChallengeMsg)
|
| 1274 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": errCloudflareChallengeMsg})
|
| 1275 |
+
return
|
| 1276 |
+
case common.IsCloudflareBlock(line):
|
| 1277 |
+
logger.Errorf(ctx, errCloudflareBlock)
|
| 1278 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": errCloudflareBlock})
|
| 1279 |
+
return
|
| 1280 |
+
case common.IsRateLimit(line):
|
| 1281 |
+
isRateLimit = true
|
| 1282 |
+
logger.Warnf(ctx, "Cookie rate limited, switching to next cookie, attempt %d/%d, COOKIE:%s", attempt+1, maxRetries, cookie)
|
| 1283 |
+
config.AddRateLimitCookie(cookie, time.Now().Add(time.Duration(config.RateLimitCookieLockDuration)*time.Second))
|
| 1284 |
+
break
|
| 1285 |
+
case common.IsFreeLimit(line):
|
| 1286 |
+
isRateLimit = true
|
| 1287 |
+
logger.Warnf(ctx, "Cookie free rate limited, switching to next cookie, attempt %d/%d, COOKIE:%s", attempt+1, maxRetries, cookie)
|
| 1288 |
+
config.AddRateLimitCookie(cookie, time.Now().Add(24*60*60*time.Second))
|
| 1289 |
+
// 删除cookie
|
| 1290 |
+
//config.RemoveCookie(cookie)
|
| 1291 |
+
break
|
| 1292 |
+
case common.IsNotLogin(line):
|
| 1293 |
+
isRateLimit = true
|
| 1294 |
+
logger.Warnf(ctx, "Cookie Not Login, switching to next cookie, attempt %d/%d, COOKIE:%s", attempt+1, maxRetries, cookie)
|
| 1295 |
+
// 删除cookie
|
| 1296 |
+
config.RemoveCookie(cookie)
|
| 1297 |
+
break
|
| 1298 |
+
case common.IsServiceUnavailablePage(line):
|
| 1299 |
+
logger.Errorf(ctx, errServiceUnavailable)
|
| 1300 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": errServiceUnavailable})
|
| 1301 |
+
return
|
| 1302 |
+
case common.IsServerError(line):
|
| 1303 |
+
logger.Errorf(ctx, errServerErrMsg)
|
| 1304 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": errServerErrMsg})
|
| 1305 |
+
return
|
| 1306 |
+
case strings.HasPrefix(line, "data: "):
|
| 1307 |
+
|
| 1308 |
+
data := strings.TrimPrefix(line, "data: ")
|
| 1309 |
+
var parsedResponse struct {
|
| 1310 |
+
Type string `json:"type"`
|
| 1311 |
+
FieldName string `json:"field_name"`
|
| 1312 |
+
Content string `json:"content"`
|
| 1313 |
+
Id string `json:"id"`
|
| 1314 |
+
Delta string `json:"delta"`
|
| 1315 |
+
}
|
| 1316 |
+
if err := json.Unmarshal([]byte(data), &parsedResponse); err != nil {
|
| 1317 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
| 1318 |
+
return
|
| 1319 |
+
}
|
| 1320 |
+
if parsedResponse.Type == "project_start" {
|
| 1321 |
+
projectId = parsedResponse.Id
|
| 1322 |
+
}
|
| 1323 |
+
if parsedResponse.Type == "message_field" {
|
| 1324 |
+
// 提取思考过程
|
| 1325 |
+
if config.ReasoningHide != 1 {
|
| 1326 |
+
if parsedResponse.FieldName == "session_state.answerthink_is_started" {
|
| 1327 |
+
answerThink = "<think>\n"
|
| 1328 |
+
}
|
| 1329 |
+
if parsedResponse.FieldName == "session_state.answerthink_is_finished" {
|
| 1330 |
+
answerThink = answerThink + "\n</think>"
|
| 1331 |
+
}
|
| 1332 |
+
}
|
| 1333 |
+
}
|
| 1334 |
+
if parsedResponse.Type == "message_field_delta" {
|
| 1335 |
+
// 提取思考过程
|
| 1336 |
+
if config.ReasoningHide != 1 {
|
| 1337 |
+
if parsedResponse.FieldName == "session_state.answerthink" {
|
| 1338 |
+
answerThink = answerThink + parsedResponse.Delta
|
| 1339 |
+
}
|
| 1340 |
+
}
|
| 1341 |
+
}
|
| 1342 |
+
if parsedResponse.Type == "message_result" {
|
| 1343 |
+
// 删除临时会话
|
| 1344 |
+
go func() {
|
| 1345 |
+
if config.AutoModelChatMapType == 1 {
|
| 1346 |
+
// 保存映射
|
| 1347 |
+
config.GlobalSessionManager.AddSession(cookie, modelName, projectId)
|
| 1348 |
+
} else {
|
| 1349 |
+
if config.AutoDelChat == 1 {
|
| 1350 |
+
client := cycletls.Init()
|
| 1351 |
+
defer safeClose(client)
|
| 1352 |
+
makeDeleteRequest(client, cookie, projectId)
|
| 1353 |
+
}
|
| 1354 |
+
}
|
| 1355 |
+
}()
|
| 1356 |
+
if modelName == "o1" && searchModel {
|
| 1357 |
+
// 解析内层的 JSON
|
| 1358 |
+
var content Content
|
| 1359 |
+
if err := json.Unmarshal([]byte(parsedResponse.Content), &content); err != nil {
|
| 1360 |
+
logger.Errorf(ctx, "Failed to unmarshal response content: %v err %s", parsedResponse.Content, err.Error())
|
| 1361 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to unmarshal response content"})
|
| 1362 |
+
return
|
| 1363 |
+
}
|
| 1364 |
+
parsedResponse.Content = content.DetailAnswer
|
| 1365 |
+
}
|
| 1366 |
+
content = strings.TrimSpace(answerThink + parsedResponse.Content)
|
| 1367 |
+
break
|
| 1368 |
+
}
|
| 1369 |
+
}
|
| 1370 |
+
}
|
| 1371 |
+
|
| 1372 |
+
if !isRateLimit {
|
| 1373 |
+
if content == "" {
|
| 1374 |
+
logger.Warnf(ctx, firstLine)
|
| 1375 |
+
//c.JSON(http.StatusInternalServerError, gin.H{"error": errNoValidResponseContent})
|
| 1376 |
+
} else {
|
| 1377 |
+
promptTokens := common.CountTokenText(string(jsonData), modelName)
|
| 1378 |
+
completionTokens := common.CountTokenText(content, modelName)
|
| 1379 |
+
finishReason := "stop"
|
| 1380 |
+
|
| 1381 |
+
c.JSON(http.StatusOK, model.OpenAIChatCompletionResponse{
|
| 1382 |
+
ID: fmt.Sprintf(responseIDFormat, time.Now().Format("20060102150405")),
|
| 1383 |
+
Object: "chat.completion",
|
| 1384 |
+
Created: time.Now().Unix(),
|
| 1385 |
+
Model: modelName,
|
| 1386 |
+
Choices: []model.OpenAIChoice{{
|
| 1387 |
+
Message: model.OpenAIMessage{
|
| 1388 |
+
Role: "assistant",
|
| 1389 |
+
Content: content,
|
| 1390 |
+
},
|
| 1391 |
+
FinishReason: &finishReason,
|
| 1392 |
+
}},
|
| 1393 |
+
Usage: model.OpenAIUsage{
|
| 1394 |
+
PromptTokens: promptTokens,
|
| 1395 |
+
CompletionTokens: completionTokens,
|
| 1396 |
+
TotalTokens: promptTokens + completionTokens,
|
| 1397 |
+
},
|
| 1398 |
+
})
|
| 1399 |
+
return
|
| 1400 |
+
}
|
| 1401 |
+
}
|
| 1402 |
+
|
| 1403 |
+
cookie, err = cookieManager.GetNextCookie()
|
| 1404 |
+
if err != nil {
|
| 1405 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": "No more valid cookies available"})
|
| 1406 |
+
return
|
| 1407 |
+
}
|
| 1408 |
+
// requestBody重制chatId
|
| 1409 |
+
currentQueryString := fmt.Sprintf("type=%s", chatType)
|
| 1410 |
+
if chatId, ok := config.GlobalSessionManager.GetChatID(cookie, modelName); ok {
|
| 1411 |
+
currentQueryString = fmt.Sprintf("id=%s&type=%s", chatId, chatType)
|
| 1412 |
+
}
|
| 1413 |
+
requestBody["current_query_string"] = currentQueryString
|
| 1414 |
+
}
|
| 1415 |
+
|
| 1416 |
+
logger.Errorf(ctx, "All cookies exhausted after %d attempts", maxRetries)
|
| 1417 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": "All cookies are temporarily unavailable."})
|
| 1418 |
+
}
|
| 1419 |
+
|
| 1420 |
+
func OpenaiModels(c *gin.Context) {
|
| 1421 |
+
var modelsResp []string
|
| 1422 |
+
|
| 1423 |
+
modelsResp = common.DefaultOpenaiModelList
|
| 1424 |
+
|
| 1425 |
+
var openaiModelListResponse model.OpenaiModelListResponse
|
| 1426 |
+
var openaiModelResponse []model.OpenaiModelResponse
|
| 1427 |
+
openaiModelListResponse.Object = "list"
|
| 1428 |
+
|
| 1429 |
+
for _, modelResp := range modelsResp {
|
| 1430 |
+
openaiModelResponse = append(openaiModelResponse, model.OpenaiModelResponse{
|
| 1431 |
+
ID: modelResp,
|
| 1432 |
+
Object: "model",
|
| 1433 |
+
})
|
| 1434 |
+
}
|
| 1435 |
+
openaiModelListResponse.Data = openaiModelResponse
|
| 1436 |
+
c.JSON(http.StatusOK, openaiModelListResponse)
|
| 1437 |
+
return
|
| 1438 |
+
}
|
| 1439 |
+
|
| 1440 |
+
func ImagesForOpenAI(c *gin.Context) {
|
| 1441 |
+
|
| 1442 |
+
client := cycletls.Init()
|
| 1443 |
+
defer safeClose(client)
|
| 1444 |
+
|
| 1445 |
+
var openAIReq model.OpenAIImagesGenerationRequest
|
| 1446 |
+
if err := c.BindJSON(&openAIReq); err != nil {
|
| 1447 |
+
c.JSON(400, gin.H{"error": err.Error()})
|
| 1448 |
+
return
|
| 1449 |
+
}
|
| 1450 |
+
// 初始化cookie
|
| 1451 |
+
//cookieManager := config.NewCookieManager()
|
| 1452 |
+
//cookie, err := cookieManager.GetRandomCookie()
|
| 1453 |
+
//
|
| 1454 |
+
//if err != nil {
|
| 1455 |
+
// logger.Errorf(c.Request.Context(), "Failed to get initial cookie: %v", err)
|
| 1456 |
+
// c.JSON(http.StatusInternalServerError, gin.H{"error": errNoValidCookies})
|
| 1457 |
+
// return
|
| 1458 |
+
//}
|
| 1459 |
+
|
| 1460 |
+
resp, err := ImageProcess(c, client, openAIReq)
|
| 1461 |
+
if err != nil {
|
| 1462 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("ImageProcess err %v\n", err))
|
| 1463 |
+
c.JSON(http.StatusInternalServerError, model.OpenAIErrorResponse{
|
| 1464 |
+
OpenAIError: model.OpenAIError{
|
| 1465 |
+
Message: err.Error(),
|
| 1466 |
+
Type: "request_error",
|
| 1467 |
+
Code: "500",
|
| 1468 |
+
},
|
| 1469 |
+
})
|
| 1470 |
+
return
|
| 1471 |
+
} else {
|
| 1472 |
+
c.JSON(200, resp)
|
| 1473 |
+
}
|
| 1474 |
+
|
| 1475 |
+
}
|
| 1476 |
+
|
| 1477 |
+
func ImageProcess(c *gin.Context, client cycletls.CycleTLS, openAIReq model.OpenAIImagesGenerationRequest) (*model.OpenAIImagesGenerationResponse, error) {
|
| 1478 |
+
const (
|
| 1479 |
+
errNoValidCookies = "No valid cookies available"
|
| 1480 |
+
errRateLimitMsg = "Rate limit reached, please try again later"
|
| 1481 |
+
errServerErrMsg = "An error occurred with the current request, please try again"
|
| 1482 |
+
errNoValidTaskIDs = "No valid task IDs received"
|
| 1483 |
+
)
|
| 1484 |
+
|
| 1485 |
+
var (
|
| 1486 |
+
sessionImageChatManager *config.SessionMapManager
|
| 1487 |
+
maxRetries int
|
| 1488 |
+
cookie string
|
| 1489 |
+
chatId string
|
| 1490 |
+
)
|
| 1491 |
+
|
| 1492 |
+
cookieManager := config.NewCookieManager()
|
| 1493 |
+
sessionImageChatManager = config.NewSessionMapManager()
|
| 1494 |
+
ctx := c.Request.Context()
|
| 1495 |
+
|
| 1496 |
+
// Initialize session manager and get initial cookie
|
| 1497 |
+
if len(config.SessionImageChatMap) == 0 {
|
| 1498 |
+
//logger.Warnf(ctx, "未配置环境变量 SESSION_IMAGE_CHAT_MAP, 可能会生图失败!")
|
| 1499 |
+
maxRetries = len(cookieManager.Cookies)
|
| 1500 |
+
|
| 1501 |
+
var err error
|
| 1502 |
+
cookie, err = cookieManager.GetRandomCookie()
|
| 1503 |
+
if err != nil {
|
| 1504 |
+
logger.Errorf(ctx, "Failed to get initial cookie: %v", err)
|
| 1505 |
+
return nil, fmt.Errorf(errNoValidCookies)
|
| 1506 |
+
}
|
| 1507 |
+
} else {
|
| 1508 |
+
maxRetries = sessionImageChatManager.GetSize()
|
| 1509 |
+
cookie, chatId, _ = sessionImageChatManager.GetRandomKeyValue()
|
| 1510 |
+
}
|
| 1511 |
+
|
| 1512 |
+
for attempt := 0; attempt < maxRetries; attempt++ {
|
| 1513 |
+
// Create request body
|
| 1514 |
+
requestBody, err := createImageRequestBody(c, cookie, &openAIReq, chatId)
|
| 1515 |
+
if err != nil {
|
| 1516 |
+
logger.Errorf(ctx, "Failed to create request body: %v", err)
|
| 1517 |
+
return nil, err
|
| 1518 |
+
}
|
| 1519 |
+
|
| 1520 |
+
// Marshal request body
|
| 1521 |
+
jsonData, err := json.Marshal(requestBody)
|
| 1522 |
+
if err != nil {
|
| 1523 |
+
logger.Errorf(ctx, "Failed to marshal request body: %v", err)
|
| 1524 |
+
return nil, err
|
| 1525 |
+
}
|
| 1526 |
+
|
| 1527 |
+
// Make request
|
| 1528 |
+
response, err := makeImageRequest(client, jsonData, cookie)
|
| 1529 |
+
if err != nil {
|
| 1530 |
+
logger.Errorf(ctx, "Failed to make image request: %v", err)
|
| 1531 |
+
return nil, err
|
| 1532 |
+
}
|
| 1533 |
+
|
| 1534 |
+
body := response.Body
|
| 1535 |
+
|
| 1536 |
+
// Handle different response cases
|
| 1537 |
+
switch {
|
| 1538 |
+
case common.IsRateLimit(body):
|
| 1539 |
+
logger.Warnf(ctx, "Cookie rate limited, switching to next cookie, attempt %d/%d, COOKIE:%s", attempt+1, maxRetries, cookie)
|
| 1540 |
+
//if sessionImageChatManager != nil {
|
| 1541 |
+
// cookie, chatId, err = sessionImageChatManager.GetNextKeyValue()
|
| 1542 |
+
// if err != nil {
|
| 1543 |
+
// logger.Errorf(ctx, "No more valid cookies available after attempt %d", attempt+1)
|
| 1544 |
+
// c.JSON(http.StatusInternalServerError, gin.H{"error": errNoValidCookies})
|
| 1545 |
+
// return nil, fmt.Errorf(errNoValidCookies)
|
| 1546 |
+
// }
|
| 1547 |
+
//} else {
|
| 1548 |
+
//cookieManager := config.NewCookieManager()
|
| 1549 |
+
config.AddRateLimitCookie(cookie, time.Now().Add(time.Duration(config.RateLimitCookieLockDuration)*time.Second))
|
| 1550 |
+
cookie, err = cookieManager.GetNextCookie()
|
| 1551 |
+
if err != nil {
|
| 1552 |
+
logger.Errorf(ctx, "No more valid cookies available after attempt %d", attempt+1)
|
| 1553 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": errNoValidCookies})
|
| 1554 |
+
return nil, fmt.Errorf(errNoValidCookies)
|
| 1555 |
+
//}
|
| 1556 |
+
}
|
| 1557 |
+
continue
|
| 1558 |
+
case common.IsFreeLimit(body):
|
| 1559 |
+
logger.Warnf(ctx, "Cookie free rate limited, switching to next cookie, attempt %d/%d, COOKIE:%s", attempt+1, maxRetries, cookie)
|
| 1560 |
+
//if sessionImageChatManager != nil {
|
| 1561 |
+
// cookie, chatId, err = sessionImageChatManager.GetNextKeyValue()
|
| 1562 |
+
// if err != nil {
|
| 1563 |
+
// logger.Errorf(ctx, "No more valid cookies available after attempt %d", attempt+1)
|
| 1564 |
+
// c.JSON(http.StatusInternalServerError, gin.H{"error": errNoValidCookies})
|
| 1565 |
+
// return nil, fmt.Errorf(errNoValidCookies)
|
| 1566 |
+
// }
|
| 1567 |
+
//} else {
|
| 1568 |
+
//cookieManager := config.NewCookieManager()
|
| 1569 |
+
config.AddRateLimitCookie(cookie, time.Now().Add(24*60*60*time.Second))
|
| 1570 |
+
// 删除cookie
|
| 1571 |
+
//config.RemoveCookie(cookie)
|
| 1572 |
+
cookie, err = cookieManager.GetNextCookie()
|
| 1573 |
+
if err != nil {
|
| 1574 |
+
logger.Errorf(ctx, "No more valid cookies available after attempt %d", attempt+1)
|
| 1575 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": errNoValidCookies})
|
| 1576 |
+
return nil, fmt.Errorf(errNoValidCookies)
|
| 1577 |
+
//}
|
| 1578 |
+
}
|
| 1579 |
+
continue
|
| 1580 |
+
case common.IsNotLogin(body):
|
| 1581 |
+
logger.Warnf(ctx, "Cookie Not Login, switching to next cookie, attempt %d/%d, COOKIE:%s", attempt+1, maxRetries, cookie)
|
| 1582 |
+
//if sessionImageChatManager != nil {
|
| 1583 |
+
// //sessionImageChatManager.RemoveKey(cookie)
|
| 1584 |
+
// cookie, chatId, err = sessionImageChatManager.GetNextKeyValue()
|
| 1585 |
+
// if err != nil {
|
| 1586 |
+
// logger.Errorf(ctx, "No more valid cookies available after attempt %d", attempt+1)
|
| 1587 |
+
// c.JSON(http.StatusInternalServerError, gin.H{"error": errNoValidCookies})
|
| 1588 |
+
// return nil, fmt.Errorf(errNoValidCookies)
|
| 1589 |
+
// }
|
| 1590 |
+
//} else {
|
| 1591 |
+
//cookieManager := config.NewCookieManager()
|
| 1592 |
+
//err := cookieManager.RemoveCookie(cookie)
|
| 1593 |
+
//if err != nil {
|
| 1594 |
+
// logger.Errorf(ctx, "Failed to remove cookie: %v", err)
|
| 1595 |
+
//}
|
| 1596 |
+
cookie, err = cookieManager.GetNextCookie()
|
| 1597 |
+
if err != nil {
|
| 1598 |
+
logger.Errorf(ctx, "No more valid cookies available after attempt %d", attempt+1)
|
| 1599 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": errNoValidCookies})
|
| 1600 |
+
return nil, fmt.Errorf(errNoValidCookies)
|
| 1601 |
+
//}
|
| 1602 |
+
|
| 1603 |
+
}
|
| 1604 |
+
continue
|
| 1605 |
+
case common.IsServerError(body):
|
| 1606 |
+
logger.Errorf(ctx, errServerErrMsg)
|
| 1607 |
+
return nil, fmt.Errorf(errServerErrMsg)
|
| 1608 |
+
case common.IsServerOverloaded(body):
|
| 1609 |
+
//logger.Errorf(ctx, fmt.Sprintf("Server overloaded, please try again later.%s", "官方服务超载或环境变量 SESSION_IMAGE_CHAT_MAP 未配置"))
|
| 1610 |
+
logger.Errorf(ctx, fmt.Sprintf("Server overloaded, please try again later.%s", "官方服务超载"))
|
| 1611 |
+
return nil, fmt.Errorf("Server overloaded, please try again later.")
|
| 1612 |
+
}
|
| 1613 |
+
|
| 1614 |
+
// Extract task IDs
|
| 1615 |
+
projectId, taskIDs := extractTaskIDs(response.Body)
|
| 1616 |
+
if len(taskIDs) == 0 {
|
| 1617 |
+
logger.Errorf(ctx, "Response body: %s", response.Body)
|
| 1618 |
+
return nil, fmt.Errorf(errNoValidTaskIDs)
|
| 1619 |
+
}
|
| 1620 |
+
|
| 1621 |
+
// Poll for image URLs
|
| 1622 |
+
imageURLs := pollTaskStatus(c, client, taskIDs, cookie)
|
| 1623 |
+
if len(imageURLs) == 0 {
|
| 1624 |
+
logger.Warnf(ctx, "No image URLs received, retrying with next cookie")
|
| 1625 |
+
continue
|
| 1626 |
+
}
|
| 1627 |
+
|
| 1628 |
+
// Create response object
|
| 1629 |
+
result := &model.OpenAIImagesGenerationResponse{
|
| 1630 |
+
Created: time.Now().Unix(),
|
| 1631 |
+
Data: make([]*model.OpenAIImagesGenerationDataResponse, 0, len(imageURLs)),
|
| 1632 |
+
}
|
| 1633 |
+
|
| 1634 |
+
// Process image URLs
|
| 1635 |
+
for _, url := range imageURLs {
|
| 1636 |
+
data := &model.OpenAIImagesGenerationDataResponse{
|
| 1637 |
+
URL: url,
|
| 1638 |
+
RevisedPrompt: openAIReq.Prompt,
|
| 1639 |
+
}
|
| 1640 |
+
|
| 1641 |
+
if openAIReq.ResponseFormat == "b64_json" {
|
| 1642 |
+
base64Str, err := getBase64ByUrl(data.URL)
|
| 1643 |
+
if err != nil {
|
| 1644 |
+
logger.Errorf(ctx, "getBase64ByUrl error: %v", err)
|
| 1645 |
+
continue
|
| 1646 |
+
}
|
| 1647 |
+
data.B64Json = "data:image/webp;base64," + base64Str
|
| 1648 |
+
}
|
| 1649 |
+
|
| 1650 |
+
result.Data = append(result.Data, data)
|
| 1651 |
+
}
|
| 1652 |
+
|
| 1653 |
+
// Handle successful case
|
| 1654 |
+
if len(result.Data) > 0 {
|
| 1655 |
+
// Delete temporary session if needed
|
| 1656 |
+
if config.AutoDelChat == 1 {
|
| 1657 |
+
go func() {
|
| 1658 |
+
client := cycletls.Init()
|
| 1659 |
+
defer safeClose(client)
|
| 1660 |
+
makeDeleteRequest(client, cookie, projectId)
|
| 1661 |
+
}()
|
| 1662 |
+
}
|
| 1663 |
+
return result, nil
|
| 1664 |
+
}
|
| 1665 |
+
}
|
| 1666 |
+
|
| 1667 |
+
// All retries exhausted
|
| 1668 |
+
logger.Errorf(ctx, "All cookies exhausted after %d attempts", maxRetries)
|
| 1669 |
+
return nil, fmt.Errorf("all cookies are temporarily unavailable")
|
| 1670 |
+
}
|
| 1671 |
+
func extractTaskIDs(responseBody string) (string, []string) {
|
| 1672 |
+
var taskIDs []string
|
| 1673 |
+
var projectId string
|
| 1674 |
+
|
| 1675 |
+
// 分行处理响应
|
| 1676 |
+
lines := strings.Split(responseBody, "\n")
|
| 1677 |
+
for _, line := range lines {
|
| 1678 |
+
|
| 1679 |
+
// 找到包含project_id的行
|
| 1680 |
+
if strings.Contains(line, "project_start") {
|
| 1681 |
+
// 去掉"data: "前缀
|
| 1682 |
+
jsonStr := strings.TrimPrefix(line, "data: ")
|
| 1683 |
+
|
| 1684 |
+
// 解析JSON
|
| 1685 |
+
var jsonResp struct {
|
| 1686 |
+
ProjectID string `json:"id"`
|
| 1687 |
+
}
|
| 1688 |
+
if err := json.Unmarshal([]byte(jsonStr), &jsonResp); err != nil {
|
| 1689 |
+
continue
|
| 1690 |
+
}
|
| 1691 |
+
|
| 1692 |
+
// 保存project_id
|
| 1693 |
+
projectId = jsonResp.ProjectID
|
| 1694 |
+
}
|
| 1695 |
+
|
| 1696 |
+
// 找到包含task_id的行
|
| 1697 |
+
if strings.Contains(line, "task_id") {
|
| 1698 |
+
// 去掉"data: "前缀
|
| 1699 |
+
jsonStr := strings.TrimPrefix(line, "data: ")
|
| 1700 |
+
|
| 1701 |
+
// 解析外层JSON
|
| 1702 |
+
var outerJSON struct {
|
| 1703 |
+
Content string `json:"content"`
|
| 1704 |
+
}
|
| 1705 |
+
if err := json.Unmarshal([]byte(jsonStr), &outerJSON); err != nil {
|
| 1706 |
+
continue
|
| 1707 |
+
}
|
| 1708 |
+
|
| 1709 |
+
// 解析内层JSON (content字段)
|
| 1710 |
+
var innerJSON struct {
|
| 1711 |
+
GeneratedImages []struct {
|
| 1712 |
+
TaskID string `json:"task_id"`
|
| 1713 |
+
} `json:"generated_images"`
|
| 1714 |
+
}
|
| 1715 |
+
if err := json.Unmarshal([]byte(outerJSON.Content), &innerJSON); err != nil {
|
| 1716 |
+
continue
|
| 1717 |
+
}
|
| 1718 |
+
|
| 1719 |
+
// 提取所有task_id
|
| 1720 |
+
for _, img := range innerJSON.GeneratedImages {
|
| 1721 |
+
if img.TaskID != "" {
|
| 1722 |
+
taskIDs = append(taskIDs, img.TaskID)
|
| 1723 |
+
}
|
| 1724 |
+
}
|
| 1725 |
+
}
|
| 1726 |
+
}
|
| 1727 |
+
return projectId, taskIDs
|
| 1728 |
+
}
|
| 1729 |
+
|
| 1730 |
+
func pollTaskStatus(c *gin.Context, client cycletls.CycleTLS, taskIDs []string, cookie string) []string {
|
| 1731 |
+
var imageURLs []string
|
| 1732 |
+
|
| 1733 |
+
requestData := map[string]interface{}{
|
| 1734 |
+
"task_ids": taskIDs,
|
| 1735 |
+
}
|
| 1736 |
+
|
| 1737 |
+
jsonData, err := json.Marshal(requestData)
|
| 1738 |
+
if err != nil {
|
| 1739 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to marshal request data"})
|
| 1740 |
+
return imageURLs
|
| 1741 |
+
}
|
| 1742 |
+
|
| 1743 |
+
sseChan, err := client.DoSSE("https://www.genspark.ai/api/ig_tasks_status", cycletls.Options{
|
| 1744 |
+
Timeout: 10 * 60 * 60,
|
| 1745 |
+
Proxy: config.ProxyUrl, // 在每个请求中设置代理
|
| 1746 |
+
Body: string(jsonData),
|
| 1747 |
+
Method: "POST",
|
| 1748 |
+
Headers: map[string]string{
|
| 1749 |
+
"Content-Type": "application/json",
|
| 1750 |
+
"Accept": "*/*",
|
| 1751 |
+
"Origin": baseURL,
|
| 1752 |
+
"Referer": baseURL + "/",
|
| 1753 |
+
"Cookie": cookie,
|
| 1754 |
+
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome",
|
| 1755 |
+
},
|
| 1756 |
+
}, "POST")
|
| 1757 |
+
if err != nil {
|
| 1758 |
+
logger.Errorf(c, "Failed to make stream request: %v", err)
|
| 1759 |
+
return imageURLs
|
| 1760 |
+
}
|
| 1761 |
+
for response := range sseChan {
|
| 1762 |
+
if response.Done {
|
| 1763 |
+
//logger.Warnf(c.Request.Context(), response.Data)
|
| 1764 |
+
return imageURLs
|
| 1765 |
+
}
|
| 1766 |
+
|
| 1767 |
+
data := response.Data
|
| 1768 |
+
if data == "" {
|
| 1769 |
+
continue
|
| 1770 |
+
}
|
| 1771 |
+
|
| 1772 |
+
logger.Debug(c.Request.Context(), strings.TrimSpace(data))
|
| 1773 |
+
|
| 1774 |
+
var responseData map[string]interface{}
|
| 1775 |
+
if err := json.Unmarshal([]byte(data), &responseData); err != nil {
|
| 1776 |
+
continue
|
| 1777 |
+
}
|
| 1778 |
+
|
| 1779 |
+
if responseData["type"] == "TASKS_STATUS_COMPLETE" {
|
| 1780 |
+
if finalStatus, ok := responseData["final_status"].(map[string]interface{}); ok {
|
| 1781 |
+
for _, taskID := range taskIDs {
|
| 1782 |
+
if task, exists := finalStatus[taskID].(map[string]interface{}); exists {
|
| 1783 |
+
if status, ok := task["status"].(string); ok && status == "SUCCESS" {
|
| 1784 |
+
if urls, ok := task["image_urls"].([]interface{}); ok && len(urls) > 0 {
|
| 1785 |
+
if imageURL, ok := urls[0].(string); ok {
|
| 1786 |
+
imageURLs = append(imageURLs, imageURL)
|
| 1787 |
+
}
|
| 1788 |
+
}
|
| 1789 |
+
}
|
| 1790 |
+
}
|
| 1791 |
+
}
|
| 1792 |
+
}
|
| 1793 |
+
}
|
| 1794 |
+
}
|
| 1795 |
+
|
| 1796 |
+
return imageURLs
|
| 1797 |
+
}
|
| 1798 |
+
|
| 1799 |
+
func getBase64ByUrl(url string) (string, error) {
|
| 1800 |
+
resp, err := http.Get(url)
|
| 1801 |
+
if err != nil {
|
| 1802 |
+
return "", fmt.Errorf("failed to fetch image: %w", err)
|
| 1803 |
+
}
|
| 1804 |
+
defer resp.Body.Close()
|
| 1805 |
+
|
| 1806 |
+
if resp.StatusCode != http.StatusOK {
|
| 1807 |
+
return "", fmt.Errorf("received non-200 status code: %d", resp.StatusCode)
|
| 1808 |
+
}
|
| 1809 |
+
|
| 1810 |
+
imgData, err := io.ReadAll(resp.Body)
|
| 1811 |
+
if err != nil {
|
| 1812 |
+
return "", fmt.Errorf("failed to read image data: %w", err)
|
| 1813 |
+
}
|
| 1814 |
+
|
| 1815 |
+
// Encode the image data to Base64
|
| 1816 |
+
base64Str := base64.StdEncoding.EncodeToString(imgData)
|
| 1817 |
+
return base64Str, nil
|
| 1818 |
+
}
|
| 1819 |
+
|
| 1820 |
+
func safeClose(client cycletls.CycleTLS) {
|
| 1821 |
+
if client.ReqChan != nil {
|
| 1822 |
+
close(client.ReqChan)
|
| 1823 |
+
}
|
| 1824 |
+
if client.RespChan != nil {
|
| 1825 |
+
close(client.RespChan)
|
| 1826 |
+
}
|
| 1827 |
+
}
|
controller/video.go
ADDED
|
@@ -0,0 +1,514 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package controller
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"crypto/tls"
|
| 5 |
+
"encoding/base64"
|
| 6 |
+
"encoding/json"
|
| 7 |
+
"fmt"
|
| 8 |
+
"genspark2api/common"
|
| 9 |
+
"genspark2api/common/config"
|
| 10 |
+
logger "genspark2api/common/loggger"
|
| 11 |
+
"genspark2api/model"
|
| 12 |
+
"github.com/deanxv/CycleTLS/cycletls"
|
| 13 |
+
"github.com/gin-gonic/gin"
|
| 14 |
+
"github.com/samber/lo"
|
| 15 |
+
"io"
|
| 16 |
+
"net/http"
|
| 17 |
+
"strings"
|
| 18 |
+
"time"
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
func VideosForOpenAI(c *gin.Context) {
|
| 22 |
+
|
| 23 |
+
client := cycletls.Init()
|
| 24 |
+
defer safeClose(client)
|
| 25 |
+
|
| 26 |
+
var openAIReq model.VideosGenerationRequest
|
| 27 |
+
if err := c.BindJSON(&openAIReq); err != nil {
|
| 28 |
+
c.JSON(400, gin.H{"error": err.Error()})
|
| 29 |
+
return
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
if lo.Contains(common.VideoModelList, openAIReq.Model) == false {
|
| 33 |
+
c.JSON(400, gin.H{"error": "Invalid model"})
|
| 34 |
+
return
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
resp, err := VideoProcess(c, client, openAIReq)
|
| 38 |
+
if err != nil {
|
| 39 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("VideoProcess err %v\n", err))
|
| 40 |
+
c.JSON(http.StatusInternalServerError, model.OpenAIErrorResponse{
|
| 41 |
+
OpenAIError: model.OpenAIError{
|
| 42 |
+
Message: err.Error(),
|
| 43 |
+
Type: "request_error",
|
| 44 |
+
Code: "500",
|
| 45 |
+
},
|
| 46 |
+
})
|
| 47 |
+
return
|
| 48 |
+
} else {
|
| 49 |
+
c.JSON(200, resp)
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
func VideoProcess(c *gin.Context, client cycletls.CycleTLS, openAIReq model.VideosGenerationRequest) (*model.VideosGenerationResponse, error) {
|
| 55 |
+
const (
|
| 56 |
+
errNoValidCookies = "No valid cookies available"
|
| 57 |
+
errServerErrMsg = "An error occurred with the current request, please try again"
|
| 58 |
+
errNoValidTaskIDs = "No valid task IDs received"
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
var (
|
| 62 |
+
maxRetries int
|
| 63 |
+
cookie string
|
| 64 |
+
chatId string
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
cookieManager := config.NewCookieManager()
|
| 68 |
+
ctx := c.Request.Context()
|
| 69 |
+
|
| 70 |
+
// Initialize session manager and get initial cookie
|
| 71 |
+
if len(config.SessionImageChatMap) == 0 {
|
| 72 |
+
//logger.Warnf(ctx, "未配置环境变量 SESSION_IMAGE_CHAT_MAP, 可能会生图失败!")
|
| 73 |
+
maxRetries = len(cookieManager.Cookies)
|
| 74 |
+
|
| 75 |
+
var err error
|
| 76 |
+
cookie, err = cookieManager.GetRandomCookie()
|
| 77 |
+
if err != nil {
|
| 78 |
+
logger.Errorf(ctx, "Failed to get initial cookie: %v", err)
|
| 79 |
+
return nil, fmt.Errorf(errNoValidCookies)
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
for attempt := 0; attempt < maxRetries; attempt++ {
|
| 84 |
+
// Create request body
|
| 85 |
+
requestBody, err := createVideoRequestBody(c, cookie, &openAIReq, chatId)
|
| 86 |
+
if err != nil {
|
| 87 |
+
logger.Errorf(ctx, "Failed to create request body: %v", err)
|
| 88 |
+
return nil, err
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
// Marshal request body
|
| 92 |
+
jsonData, err := json.Marshal(requestBody)
|
| 93 |
+
if err != nil {
|
| 94 |
+
logger.Errorf(ctx, "Failed to marshal request body: %v", err)
|
| 95 |
+
return nil, err
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
// Make request
|
| 99 |
+
response, err := makeVideoRequest(client, jsonData, cookie)
|
| 100 |
+
if err != nil {
|
| 101 |
+
logger.Errorf(ctx, "Failed to make video request: %v", err)
|
| 102 |
+
return nil, err
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
body := response.Body
|
| 106 |
+
|
| 107 |
+
switch {
|
| 108 |
+
case common.IsRateLimit(body):
|
| 109 |
+
logger.Warnf(ctx, "Cookie rate limited, switching to next cookie, attempt %d/%d, COOKIE:%s", attempt+1, maxRetries, cookie)
|
| 110 |
+
config.AddRateLimitCookie(cookie, time.Now().Add(time.Duration(config.RateLimitCookieLockDuration)*time.Second))
|
| 111 |
+
cookie, err = cookieManager.GetNextCookie()
|
| 112 |
+
if err != nil {
|
| 113 |
+
logger.Errorf(ctx, "No more valid cookies available after attempt %d", attempt+1)
|
| 114 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": errNoValidCookies})
|
| 115 |
+
return nil, fmt.Errorf(errNoValidCookies)
|
| 116 |
+
}
|
| 117 |
+
continue
|
| 118 |
+
case common.IsFreeLimit(body):
|
| 119 |
+
logger.Warnf(ctx, "Cookie free rate limited, switching to next cookie, attempt %d/%d, COOKIE:%s", attempt+1, maxRetries, cookie)
|
| 120 |
+
config.AddRateLimitCookie(cookie, time.Now().Add(24*60*60*time.Second))
|
| 121 |
+
cookie, err = cookieManager.GetNextCookie()
|
| 122 |
+
if err != nil {
|
| 123 |
+
logger.Errorf(ctx, "No more valid cookies available after attempt %d", attempt+1)
|
| 124 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": errNoValidCookies})
|
| 125 |
+
return nil, fmt.Errorf(errNoValidCookies)
|
| 126 |
+
}
|
| 127 |
+
continue
|
| 128 |
+
case common.IsNotLogin(body):
|
| 129 |
+
logger.Warnf(ctx, "Cookie Not Login, switching to next cookie, attempt %d/%d, COOKIE:%s", attempt+1, maxRetries, cookie)
|
| 130 |
+
cookie, err = cookieManager.GetNextCookie()
|
| 131 |
+
if err != nil {
|
| 132 |
+
logger.Errorf(ctx, "No more valid cookies available after attempt %d", attempt+1)
|
| 133 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": errNoValidCookies})
|
| 134 |
+
return nil, fmt.Errorf(errNoValidCookies)
|
| 135 |
+
}
|
| 136 |
+
continue
|
| 137 |
+
case common.IsServerError(body):
|
| 138 |
+
logger.Errorf(ctx, errServerErrMsg)
|
| 139 |
+
return nil, fmt.Errorf(errServerErrMsg)
|
| 140 |
+
case common.IsServerOverloaded(body):
|
| 141 |
+
logger.Errorf(ctx, fmt.Sprintf("Server overloaded, please try again later.%s", "官方服务超载"))
|
| 142 |
+
return nil, fmt.Errorf("Server overloaded, please try again later.")
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
projectId, taskIDs := extractVideoTaskIDs(response.Body)
|
| 146 |
+
if len(taskIDs) == 0 {
|
| 147 |
+
logger.Errorf(ctx, "Response body: %s", response.Body)
|
| 148 |
+
return nil, fmt.Errorf(errNoValidTaskIDs)
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
// Poll for image URLs
|
| 152 |
+
imageURLs := pollVideoTaskStatus(c, client, taskIDs, cookie)
|
| 153 |
+
if len(imageURLs) == 0 {
|
| 154 |
+
logger.Warnf(ctx, "No image URLs received, retrying with next cookie")
|
| 155 |
+
continue
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
// Create response object
|
| 159 |
+
result := &model.VideosGenerationResponse{
|
| 160 |
+
Created: time.Now().Unix(),
|
| 161 |
+
Data: make([]*model.VideosGenerationDataResponse, 0, len(imageURLs)),
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
// Process image URLs
|
| 165 |
+
for _, url := range imageURLs {
|
| 166 |
+
data := &model.VideosGenerationDataResponse{
|
| 167 |
+
URL: url,
|
| 168 |
+
RevisedPrompt: openAIReq.Prompt,
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
//if openAIReq.ResponseFormat == "b64_json" {
|
| 172 |
+
// base64Str, err := getBase64ByUrl(data.URL)
|
| 173 |
+
// if err != nil {
|
| 174 |
+
// logger.Errorf(ctx, "getBase64ByUrl error: %v", err)
|
| 175 |
+
// continue
|
| 176 |
+
// }
|
| 177 |
+
// data.B64Json = "data:image/webp;base64," + base64Str
|
| 178 |
+
//}
|
| 179 |
+
|
| 180 |
+
result.Data = append(result.Data, data)
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
// Handle successful case
|
| 184 |
+
if len(result.Data) > 0 {
|
| 185 |
+
// Delete temporary session if needed
|
| 186 |
+
if config.AutoDelChat == 1 {
|
| 187 |
+
go func() {
|
| 188 |
+
client := cycletls.Init()
|
| 189 |
+
defer safeClose(client)
|
| 190 |
+
makeDeleteRequest(client, cookie, projectId)
|
| 191 |
+
}()
|
| 192 |
+
}
|
| 193 |
+
return result, nil
|
| 194 |
+
}
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
// All retries exhausted
|
| 198 |
+
logger.Errorf(ctx, "All cookies exhausted after %d attempts", maxRetries)
|
| 199 |
+
return nil, fmt.Errorf("all cookies are temporarily unavailable")
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
func createVideoRequestBody(c *gin.Context, cookie string, openAIReq *model.VideosGenerationRequest, chatId string) (map[string]interface{}, error) {
|
| 203 |
+
|
| 204 |
+
// 创建模型配置
|
| 205 |
+
modelConfigs := []map[string]interface{}{
|
| 206 |
+
{
|
| 207 |
+
"model": openAIReq.Model,
|
| 208 |
+
"aspect_ratio": openAIReq.AspectRatio,
|
| 209 |
+
"reflection_enabled": openAIReq.AutoPrompt,
|
| 210 |
+
"duration": openAIReq.Duration,
|
| 211 |
+
},
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
// 创建消息数组
|
| 215 |
+
var messages []map[string]interface{}
|
| 216 |
+
|
| 217 |
+
if openAIReq.Image != "" {
|
| 218 |
+
var base64Data string
|
| 219 |
+
|
| 220 |
+
if strings.HasPrefix(openAIReq.Image, "http://") || strings.HasPrefix(openAIReq.Image, "https://") {
|
| 221 |
+
// 下载文件
|
| 222 |
+
bytes, err := fetchImageBytes(openAIReq.Image)
|
| 223 |
+
if err != nil {
|
| 224 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("fetchImageBytes err %v\n", err))
|
| 225 |
+
return nil, fmt.Errorf("fetchImageBytes err %v\n", err)
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
contentType := http.DetectContentType(bytes)
|
| 229 |
+
if strings.HasPrefix(contentType, "image/") {
|
| 230 |
+
// 是图片类型,转换为base64
|
| 231 |
+
base64Data = "data:image/jpeg;base64," + base64.StdEncoding.EncodeToString(bytes)
|
| 232 |
+
}
|
| 233 |
+
} else if common.IsImageBase64(openAIReq.Image) {
|
| 234 |
+
// 如果已经是 base64 格式
|
| 235 |
+
if !strings.HasPrefix(openAIReq.Image, "data:image") {
|
| 236 |
+
base64Data = "data:image/jpeg;base64," + openAIReq.Image
|
| 237 |
+
} else {
|
| 238 |
+
base64Data = openAIReq.Image
|
| 239 |
+
}
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
// 构建包含图片的消息
|
| 243 |
+
if base64Data != "" {
|
| 244 |
+
messages = []map[string]interface{}{
|
| 245 |
+
{
|
| 246 |
+
"role": "user",
|
| 247 |
+
"content": []map[string]interface{}{
|
| 248 |
+
{
|
| 249 |
+
"type": "image_url",
|
| 250 |
+
"image_url": map[string]interface{}{
|
| 251 |
+
"url": base64Data,
|
| 252 |
+
},
|
| 253 |
+
},
|
| 254 |
+
{
|
| 255 |
+
"type": "text",
|
| 256 |
+
"text": openAIReq.Prompt,
|
| 257 |
+
},
|
| 258 |
+
},
|
| 259 |
+
},
|
| 260 |
+
}
|
| 261 |
+
}
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
// 如果没有图片或处理图片失败,使用纯文本消息
|
| 265 |
+
if len(messages) == 0 {
|
| 266 |
+
messages = []map[string]interface{}{
|
| 267 |
+
{
|
| 268 |
+
"role": "user",
|
| 269 |
+
"content": openAIReq.Prompt,
|
| 270 |
+
},
|
| 271 |
+
}
|
| 272 |
+
}
|
| 273 |
+
var currentQueryString string
|
| 274 |
+
if len(chatId) != 0 {
|
| 275 |
+
currentQueryString = fmt.Sprintf("id=%s&type=%s", chatId, videoType)
|
| 276 |
+
} else {
|
| 277 |
+
currentQueryString = fmt.Sprintf("type=%s", videoType)
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
// 创建请求体
|
| 281 |
+
requestBody := map[string]interface{}{
|
| 282 |
+
"type": "COPILOT_MOA_VIDEO",
|
| 283 |
+
//"current_query_string": "type=COPILOT_MOA_IMAGE",
|
| 284 |
+
"current_query_string": currentQueryString,
|
| 285 |
+
"messages": messages,
|
| 286 |
+
"user_s_input": openAIReq.Prompt,
|
| 287 |
+
"action_params": map[string]interface{}{},
|
| 288 |
+
"extra_data": map[string]interface{}{
|
| 289 |
+
"model_configs": modelConfigs,
|
| 290 |
+
"imageModelMap": map[string]interface{}{},
|
| 291 |
+
},
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
logger.Debug(c.Request.Context(), fmt.Sprintf("RequestBody: %v", requestBody))
|
| 295 |
+
|
| 296 |
+
if strings.TrimSpace(config.RecaptchaProxyUrl) == "" ||
|
| 297 |
+
(!strings.HasPrefix(config.RecaptchaProxyUrl, "http://") &&
|
| 298 |
+
!strings.HasPrefix(config.RecaptchaProxyUrl, "https://")) {
|
| 299 |
+
return requestBody, nil
|
| 300 |
+
} else {
|
| 301 |
+
|
| 302 |
+
tr := &http.Transport{
|
| 303 |
+
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
| 304 |
+
}
|
| 305 |
+
client := &http.Client{Transport: tr}
|
| 306 |
+
|
| 307 |
+
// 检查并补充 RecaptchaProxyUrl 的末尾斜杠
|
| 308 |
+
if !strings.HasSuffix(config.RecaptchaProxyUrl, "/") {
|
| 309 |
+
config.RecaptchaProxyUrl += "/"
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
// 创建请求
|
| 313 |
+
req, err := http.NewRequest("GET", fmt.Sprintf("%sgenspark", config.RecaptchaProxyUrl), nil)
|
| 314 |
+
if err != nil {
|
| 315 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("创建/genspark请求失败 %v\n", err))
|
| 316 |
+
return nil, err
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
// 设置请求头
|
| 320 |
+
req.Header.Set("Content-Type", "application/json")
|
| 321 |
+
req.Header.Set("Cookie", cookie)
|
| 322 |
+
|
| 323 |
+
// 发送请求
|
| 324 |
+
resp, err := client.Do(req)
|
| 325 |
+
if err != nil {
|
| 326 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("发送/genspark请求失败 %v\n", err))
|
| 327 |
+
return nil, err
|
| 328 |
+
}
|
| 329 |
+
defer resp.Body.Close()
|
| 330 |
+
|
| 331 |
+
// 读取响应体
|
| 332 |
+
body, err := io.ReadAll(resp.Body)
|
| 333 |
+
if err != nil {
|
| 334 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("读取/genspark响应失败 %v\n", err))
|
| 335 |
+
return nil, err
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
type Response struct {
|
| 339 |
+
Code int `json:"code"`
|
| 340 |
+
Token string `json:"token"`
|
| 341 |
+
Message string `json:"message"`
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
if resp.StatusCode == 200 {
|
| 345 |
+
var response Response
|
| 346 |
+
if err := json.Unmarshal(body, &response); err != nil {
|
| 347 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("读取/genspark JSON 失败 %v\n", err))
|
| 348 |
+
return nil, err
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
if response.Code == 200 {
|
| 352 |
+
logger.Debugf(c.Request.Context(), fmt.Sprintf("g_recaptcha_token: %v\n", response.Token))
|
| 353 |
+
requestBody["g_recaptcha_token"] = response.Token
|
| 354 |
+
logger.Infof(c.Request.Context(), fmt.Sprintf("cheat success!"))
|
| 355 |
+
return requestBody, nil
|
| 356 |
+
} else {
|
| 357 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("读取/genspark token 失败 %v\n", err))
|
| 358 |
+
return nil, err
|
| 359 |
+
}
|
| 360 |
+
} else {
|
| 361 |
+
logger.Errorf(c.Request.Context(), fmt.Sprintf("请求/genspark失败 %v\n", err))
|
| 362 |
+
return nil, err
|
| 363 |
+
}
|
| 364 |
+
}
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
func makeVideoRequest(client cycletls.CycleTLS, jsonData []byte, cookie string) (cycletls.Response, error) {
|
| 368 |
+
|
| 369 |
+
accept := "*/*"
|
| 370 |
+
|
| 371 |
+
return client.Do(apiEndpoint, cycletls.Options{
|
| 372 |
+
UserAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome",
|
| 373 |
+
Timeout: 10 * 60 * 60,
|
| 374 |
+
Proxy: config.ProxyUrl, // 在每个请求中设置代理
|
| 375 |
+
Body: string(jsonData),
|
| 376 |
+
Method: "POST",
|
| 377 |
+
Headers: map[string]string{
|
| 378 |
+
"Content-Type": "application/json",
|
| 379 |
+
"Accept": accept,
|
| 380 |
+
"Origin": baseURL,
|
| 381 |
+
"Referer": baseURL + "/",
|
| 382 |
+
"Cookie": cookie,
|
| 383 |
+
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome",
|
| 384 |
+
},
|
| 385 |
+
}, "POST")
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
func extractVideoTaskIDs(responseBody string) (string, []string) {
|
| 389 |
+
var taskIDs []string
|
| 390 |
+
var projectId string
|
| 391 |
+
|
| 392 |
+
// 分行处理响应
|
| 393 |
+
lines := strings.Split(responseBody, "\n")
|
| 394 |
+
for _, line := range lines {
|
| 395 |
+
|
| 396 |
+
// 找到包含project_id的行
|
| 397 |
+
if strings.Contains(line, "project_start") {
|
| 398 |
+
// 去掉"data: "前缀
|
| 399 |
+
jsonStr := strings.TrimPrefix(line, "data: ")
|
| 400 |
+
|
| 401 |
+
// 解析JSON
|
| 402 |
+
var jsonResp struct {
|
| 403 |
+
ProjectID string `json:"id"`
|
| 404 |
+
}
|
| 405 |
+
if err := json.Unmarshal([]byte(jsonStr), &jsonResp); err != nil {
|
| 406 |
+
continue
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
// 保存project_id
|
| 410 |
+
projectId = jsonResp.ProjectID
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
// 找到包含task_id的行
|
| 414 |
+
if strings.Contains(line, "task_id") {
|
| 415 |
+
// 去掉"data: "前缀
|
| 416 |
+
jsonStr := strings.TrimPrefix(line, "data: ")
|
| 417 |
+
|
| 418 |
+
// 解析外层JSON
|
| 419 |
+
var outerJSON struct {
|
| 420 |
+
Content string `json:"content"`
|
| 421 |
+
}
|
| 422 |
+
if err := json.Unmarshal([]byte(jsonStr), &outerJSON); err != nil {
|
| 423 |
+
continue
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
// 解析内层JSON (content字段)
|
| 427 |
+
var innerJSON struct {
|
| 428 |
+
GeneratedVideos []struct {
|
| 429 |
+
TaskID string `json:"task_id"`
|
| 430 |
+
} `json:"generated_videos"`
|
| 431 |
+
}
|
| 432 |
+
if err := json.Unmarshal([]byte(outerJSON.Content), &innerJSON); err != nil {
|
| 433 |
+
continue
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
// 提取所有task_id
|
| 437 |
+
for _, img := range innerJSON.GeneratedVideos {
|
| 438 |
+
if img.TaskID != "" {
|
| 439 |
+
taskIDs = append(taskIDs, img.TaskID)
|
| 440 |
+
}
|
| 441 |
+
}
|
| 442 |
+
}
|
| 443 |
+
}
|
| 444 |
+
return projectId, taskIDs
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
func pollVideoTaskStatus(c *gin.Context, client cycletls.CycleTLS, taskIDs []string, cookie string) []string {
|
| 448 |
+
var imageURLs []string
|
| 449 |
+
|
| 450 |
+
requestData := map[string]interface{}{
|
| 451 |
+
"task_ids": taskIDs,
|
| 452 |
+
}
|
| 453 |
+
|
| 454 |
+
jsonData, err := json.Marshal(requestData)
|
| 455 |
+
if err != nil {
|
| 456 |
+
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to marshal request data"})
|
| 457 |
+
return imageURLs
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
sseChan, err := client.DoSSE("https://www.genspark.ai/api/vg_tasks_status", cycletls.Options{
|
| 461 |
+
Timeout: 10 * 60 * 60,
|
| 462 |
+
Proxy: config.ProxyUrl, // 在每个请求中设置代理
|
| 463 |
+
Body: string(jsonData),
|
| 464 |
+
Method: "POST",
|
| 465 |
+
Headers: map[string]string{
|
| 466 |
+
"Content-Type": "application/json",
|
| 467 |
+
"Accept": "*/*",
|
| 468 |
+
"Origin": baseURL,
|
| 469 |
+
"Referer": baseURL + "/",
|
| 470 |
+
"Cookie": cookie,
|
| 471 |
+
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome",
|
| 472 |
+
},
|
| 473 |
+
}, "POST")
|
| 474 |
+
if err != nil {
|
| 475 |
+
logger.Errorf(c, "Failed to make stream request: %v", err)
|
| 476 |
+
return imageURLs
|
| 477 |
+
}
|
| 478 |
+
for response := range sseChan {
|
| 479 |
+
if response.Done {
|
| 480 |
+
//logger.Warnf(c.Request.Context(), response.Data)
|
| 481 |
+
return imageURLs
|
| 482 |
+
}
|
| 483 |
+
|
| 484 |
+
data := response.Data
|
| 485 |
+
if data == "" {
|
| 486 |
+
continue
|
| 487 |
+
}
|
| 488 |
+
|
| 489 |
+
logger.Debug(c.Request.Context(), strings.TrimSpace(data))
|
| 490 |
+
|
| 491 |
+
var responseData map[string]interface{}
|
| 492 |
+
if err := json.Unmarshal([]byte(data), &responseData); err != nil {
|
| 493 |
+
continue
|
| 494 |
+
}
|
| 495 |
+
|
| 496 |
+
if responseData["type"] == "TASKS_STATUS_COMPLETE" {
|
| 497 |
+
if finalStatus, ok := responseData["final_status"].(map[string]interface{}); ok {
|
| 498 |
+
for _, taskID := range taskIDs {
|
| 499 |
+
if task, exists := finalStatus[taskID].(map[string]interface{}); exists {
|
| 500 |
+
if status, ok := task["status"].(string); ok && status == "SUCCESS" {
|
| 501 |
+
if urls, ok := task["video_urls"].([]interface{}); ok && len(urls) > 0 {
|
| 502 |
+
if imageURL, ok := urls[0].(string); ok {
|
| 503 |
+
imageURLs = append(imageURLs, imageURL)
|
| 504 |
+
}
|
| 505 |
+
}
|
| 506 |
+
}
|
| 507 |
+
}
|
| 508 |
+
}
|
| 509 |
+
}
|
| 510 |
+
}
|
| 511 |
+
}
|
| 512 |
+
|
| 513 |
+
return imageURLs
|
| 514 |
+
}
|
data/.env
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
AUTO_DEL_CHAT=0
|
| 13 |
+
MODEL_CHAT_MAP=claude-3-7-sonnet=1e0b254c-c5fb-447f-8a3d-7e91d8fa9768,claude-3-7-sonnet-thinking=70705b2a-3429-4aab-8f8a-8f5858b81a96,claude-3-5-haiku=1796a25d-9ef5-4f6b-bc5b-583a7e8c40fc,deep-seek-v3=5ccc1792-9a7d-4a2f-ae7d-b65fd95b8cf3
|
| 14 |
+
API_SECRET=123456
|
| 15 |
+
GS_COOKIE=session_id=b0860552-21bc-48fc-a636-ab7bf76338df:b6528b346b053630d68d262aaa5ffb18fd1cce4e8eee5b39e7d4fa75d39568d5
|
| 16 |
+
DEBUG=true
|
| 17 |
+
REASONING_HIDE=0
|
| 18 |
+
AUTO_MODEL_CHAT_MAP_TYPE=1
|
data/models_list.json
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"id": "gpt-4o",
|
| 4 |
+
"name": "GPT 4o",
|
| 5 |
+
"category": "text",
|
| 6 |
+
"enabled": true
|
| 7 |
+
},
|
| 8 |
+
{
|
| 9 |
+
"id": "o1",
|
| 10 |
+
"name": "O1",
|
| 11 |
+
"category": "text",
|
| 12 |
+
"enabled": true
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"id": "o3-mini-high",
|
| 16 |
+
"name": "O3 Mini High",
|
| 17 |
+
"category": "text",
|
| 18 |
+
"enabled": true
|
| 19 |
+
},
|
| 20 |
+
{
|
| 21 |
+
"id": "claude-3-7-sonnet",
|
| 22 |
+
"name": "Claude 3 7 Sonnet",
|
| 23 |
+
"category": "text",
|
| 24 |
+
"enabled": true
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"id": "claude-3-7-sonnet-thinking",
|
| 28 |
+
"name": "Claude 3 7 Sonnet Thinking",
|
| 29 |
+
"category": "text",
|
| 30 |
+
"enabled": true
|
| 31 |
+
},
|
| 32 |
+
{
|
| 33 |
+
"id": "claude-3-5-haiku",
|
| 34 |
+
"name": "Claude 3 5 Haiku",
|
| 35 |
+
"category": "text",
|
| 36 |
+
"enabled": true
|
| 37 |
+
},
|
| 38 |
+
{
|
| 39 |
+
"id": "gemini-2.0-flash",
|
| 40 |
+
"name": "Gemini 2.0 Flash",
|
| 41 |
+
"category": "text",
|
| 42 |
+
"enabled": true
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"id": "deep-seek-v3",
|
| 46 |
+
"name": "Deep Seek V3",
|
| 47 |
+
"category": "text",
|
| 48 |
+
"enabled": true
|
| 49 |
+
},
|
| 50 |
+
{
|
| 51 |
+
"id": "deep-seek-r1",
|
| 52 |
+
"name": "Deep Seek R1",
|
| 53 |
+
"category": "text",
|
| 54 |
+
"enabled": true
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"id": "flux",
|
| 58 |
+
"name": "Flux",
|
| 59 |
+
"category": "image",
|
| 60 |
+
"enabled": true
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
"id": "flux-speed",
|
| 64 |
+
"name": "Flux Speed",
|
| 65 |
+
"category": "image",
|
| 66 |
+
"enabled": true
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"id": "flux-pro/ultra",
|
| 70 |
+
"name": "Flux Pro ultra",
|
| 71 |
+
"category": "image",
|
| 72 |
+
"enabled": true
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"id": "ideogram",
|
| 76 |
+
"name": "Ideogram",
|
| 77 |
+
"category": "image",
|
| 78 |
+
"enabled": true
|
| 79 |
+
},
|
| 80 |
+
{
|
| 81 |
+
"id": "ideogram/V_2A",
|
| 82 |
+
"name": "Ideogram V_2A",
|
| 83 |
+
"category": "image",
|
| 84 |
+
"enabled": true
|
| 85 |
+
},
|
| 86 |
+
{
|
| 87 |
+
"id": "recraft-v3",
|
| 88 |
+
"name": "Recraft V3",
|
| 89 |
+
"category": "image",
|
| 90 |
+
"enabled": true
|
| 91 |
+
},
|
| 92 |
+
{
|
| 93 |
+
"id": "dall-e-3",
|
| 94 |
+
"name": "DALL E 3",
|
| 95 |
+
"category": "image",
|
| 96 |
+
"enabled": true
|
| 97 |
+
},
|
| 98 |
+
{
|
| 99 |
+
"id": "imagen3",
|
| 100 |
+
"name": "Imagen3",
|
| 101 |
+
"category": "image",
|
| 102 |
+
"enabled": true
|
| 103 |
+
},
|
| 104 |
+
{
|
| 105 |
+
"id": "kling/v1.6/standard",
|
| 106 |
+
"name": "Kling v1.6 standard",
|
| 107 |
+
"category": "video",
|
| 108 |
+
"enabled": true
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
"id": "pixverse/v3.5/turbo",
|
| 112 |
+
"name": "Pixverse v3.5 turbo",
|
| 113 |
+
"category": "video",
|
| 114 |
+
"enabled": true
|
| 115 |
+
},
|
| 116 |
+
{
|
| 117 |
+
"id": "lumadream/ray-2",
|
| 118 |
+
"name": "Lumadream ray 2",
|
| 119 |
+
"category": "video",
|
| 120 |
+
"enabled": true
|
| 121 |
+
},
|
| 122 |
+
{
|
| 123 |
+
"id": "gemini/veo2",
|
| 124 |
+
"name": "Gemini veo2",
|
| 125 |
+
"category": "video",
|
| 126 |
+
"enabled": true
|
| 127 |
+
},
|
| 128 |
+
{
|
| 129 |
+
"id": "hunyuan",
|
| 130 |
+
"name": "Hunyuan",
|
| 131 |
+
"category": "video",
|
| 132 |
+
"enabled": true
|
| 133 |
+
}
|
| 134 |
+
]
|
docker-compose.yml
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.4'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
genspark2api:
|
| 5 |
+
image: deanxv/genspark2api:latest
|
| 6 |
+
container_name: genspark2api
|
| 7 |
+
restart: always
|
| 8 |
+
ports:
|
| 9 |
+
- "7055:7055"
|
| 10 |
+
volumes:
|
| 11 |
+
- ./data:/app/genspark2api/data
|
| 12 |
+
environment:
|
| 13 |
+
- GS_COOKIE=session_id=b0860552-21bc-48fc-a636-ab7bf76338df:b6528b346b053630d68d262aaa5ffb18fd1cce4e8eee5b39e7d4fa75d39568d5 # cookie (多个请以,分隔)
|
| 14 |
+
- API_SECRET=123456 # [可选]接口密钥-修改此行为请求头校验的值(多个请以,分隔)
|
| 15 |
+
- AUTO_MODEL_CHAT_MAP_TYPE=1 # 启用自动模型绑定chat,解决模型降智问题
|
| 16 |
+
- TZ=Asia/Shanghai
|
docs/img.png
ADDED
|
Git LFS Details
|
docs/img2.png
ADDED
|
Git LFS Details
|
docs/img3.png
ADDED
|
docs/img4.png
ADDED
|
Git LFS Details
|
docs/img5.png
ADDED
|
Git LFS Details
|
docs/img6.png
ADDED
|
Git LFS Details
|
docs/img7.png
ADDED
|
Git LFS Details
|
go.mod
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
module genspark2api
|
| 2 |
+
|
| 3 |
+
go 1.23.0
|
| 4 |
+
|
| 5 |
+
toolchain go1.23.2
|
| 6 |
+
|
| 7 |
+
require (
|
| 8 |
+
github.com/deanxv/CycleTLS/cycletls v0.0.0-20250208071223-7956a8a6a221
|
| 9 |
+
github.com/gin-contrib/cors v1.7.3
|
| 10 |
+
github.com/gin-gonic/gin v1.10.0
|
| 11 |
+
github.com/google/uuid v1.6.0
|
| 12 |
+
github.com/json-iterator/go v1.1.12
|
| 13 |
+
github.com/pkoukk/tiktoken-go v0.1.7
|
| 14 |
+
github.com/samber/lo v1.49.1
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
require (
|
| 18 |
+
github.com/Danny-Dasilva/fhttp v0.0.0-20240217042913-eeeb0b347ce1 // indirect
|
| 19 |
+
github.com/andybalholm/brotli v1.1.1 // indirect
|
| 20 |
+
github.com/bytedance/sonic v1.12.9 // indirect
|
| 21 |
+
github.com/bytedance/sonic/loader v0.2.3 // indirect
|
| 22 |
+
github.com/cloudflare/circl v1.6.0 // indirect
|
| 23 |
+
github.com/cloudwego/base64x v0.1.5 // indirect
|
| 24 |
+
github.com/dlclark/regexp2 v1.11.5 // indirect
|
| 25 |
+
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
|
| 26 |
+
github.com/gin-contrib/sse v1.0.0 // indirect
|
| 27 |
+
github.com/go-playground/locales v0.14.1 // indirect
|
| 28 |
+
github.com/go-playground/universal-translator v0.18.1 // indirect
|
| 29 |
+
github.com/go-playground/validator/v10 v10.25.0 // indirect
|
| 30 |
+
github.com/goccy/go-json v0.10.5 // indirect
|
| 31 |
+
github.com/google/go-cmp v0.6.0 // indirect
|
| 32 |
+
github.com/gorilla/websocket v1.5.3 // indirect
|
| 33 |
+
github.com/klauspost/compress v1.18.0 // indirect
|
| 34 |
+
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
|
| 35 |
+
github.com/kr/pretty v0.3.1 // indirect
|
| 36 |
+
github.com/leodido/go-urn v1.4.0 // indirect
|
| 37 |
+
github.com/mattn/go-isatty v0.0.20 // indirect
|
| 38 |
+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
| 39 |
+
github.com/modern-go/reflect2 v1.0.2 // indirect
|
| 40 |
+
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
|
| 41 |
+
github.com/refraction-networking/utls v1.6.7 // indirect
|
| 42 |
+
github.com/rogpeppe/go-internal v1.11.0 // indirect
|
| 43 |
+
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
| 44 |
+
github.com/ugorji/go/codec v1.2.12 // indirect
|
| 45 |
+
golang.org/x/arch v0.14.0 // indirect
|
| 46 |
+
golang.org/x/crypto v0.35.0 // indirect
|
| 47 |
+
golang.org/x/net v0.35.0 // indirect
|
| 48 |
+
golang.org/x/sys v0.30.0 // indirect
|
| 49 |
+
golang.org/x/text v0.22.0 // indirect
|
| 50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
| 2 |
+
cloud.google.com/go v0.31.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
| 3 |
+
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
| 4 |
+
cloud.google.com/go v0.37.0/go.mod h1:TS1dMSSfndXH133OKGwekG838Om/cQT0BUHV3HcBgoo=
|
| 5 |
+
dmitri.shuralyov.com/app/changes v0.0.0-20180602232624-0a106ad413e3/go.mod h1:Yl+fi1br7+Rr3LqpNJf1/uxUdtRUV+Tnj0o93V2B9MU=
|
| 6 |
+
dmitri.shuralyov.com/html/belt v0.0.0-20180602232347-f7d459c86be0/go.mod h1:JLBrvjyP0v+ecvNYvCpyZgu5/xkfAUhi6wJj28eUfSU=
|
| 7 |
+
dmitri.shuralyov.com/service/change v0.0.0-20181023043359-a85b471d5412/go.mod h1:a1inKt/atXimZ4Mv927x+r7UpyzRUf4emIoiiSC2TN4=
|
| 8 |
+
dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D6DFvNNtx+9ybjezNCa8XF0xaYcETyp6rHWU=
|
| 9 |
+
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
|
| 10 |
+
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
| 11 |
+
github.com/Danny-Dasilva/fhttp v0.0.0-20240217042913-eeeb0b347ce1 h1:/lqhaiz7xdPr6kuaW1tQ/8DdpWdxkdyd9W/6EHz4oRw=
|
| 12 |
+
github.com/Danny-Dasilva/fhttp v0.0.0-20240217042913-eeeb0b347ce1/go.mod h1:Hvab/V/YKCDXsEpKYKHjAXH5IFOmoq9FsfxjztEqvDc=
|
| 13 |
+
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
| 14 |
+
github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=
|
| 15 |
+
github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
|
| 16 |
+
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
|
| 17 |
+
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
| 18 |
+
github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g=
|
| 19 |
+
github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s=
|
| 20 |
+
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
|
| 21 |
+
github.com/bytedance/sonic v1.12.9 h1:Od1BvK55NnewtGaJsTDeAOSnLVO2BTSLOe0+ooKokmQ=
|
| 22 |
+
github.com/bytedance/sonic v1.12.9/go.mod h1:uVvFidNmlt9+wa31S1urfwwthTWteBgG0hWuoKAXTx8=
|
| 23 |
+
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
|
| 24 |
+
github.com/bytedance/sonic/loader v0.2.3 h1:yctD0Q3v2NOGfSWPLPvG2ggA2kV6TS6s4wioyEqssH0=
|
| 25 |
+
github.com/bytedance/sonic/loader v0.2.3/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
|
| 26 |
+
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
| 27 |
+
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
| 28 |
+
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
| 29 |
+
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
| 30 |
+
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
|
| 31 |
+
github.com/cloudflare/circl v1.6.0 h1:cr5JKic4HI+LkINy2lg3W2jF8sHCVTBncJr5gIIq7qk=
|
| 32 |
+
github.com/cloudflare/circl v1.6.0/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
|
| 33 |
+
github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4=
|
| 34 |
+
github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
|
| 35 |
+
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
|
| 36 |
+
github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
| 37 |
+
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
| 38 |
+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
| 39 |
+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
| 40 |
+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
| 41 |
+
github.com/deanxv/CycleTLS/cycletls v0.0.0-20250208071223-7956a8a6a221 h1:zykIpPFKX7DsNfsK3UpwN78oec/x9fND1hZrib7zod8=
|
| 42 |
+
github.com/deanxv/CycleTLS/cycletls v0.0.0-20250208071223-7956a8a6a221/go.mod h1:eAyIp7Lbyq6WnJDGicqf7nYr0bTj5FQ0HXQbIesuuJ8=
|
| 43 |
+
github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZQ=
|
| 44 |
+
github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
|
| 45 |
+
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
| 46 |
+
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
|
| 47 |
+
github.com/francoispqt/gojay v1.2.13/go.mod h1:ehT5mTG4ua4581f1++1WLG0vPdaA9HaiDsoyrBGkyDY=
|
| 48 |
+
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
| 49 |
+
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
| 50 |
+
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
|
| 51 |
+
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
|
| 52 |
+
github.com/gaukas/godicttls v0.0.4/go.mod h1:l6EenT4TLWgTdwslVb4sEMOCf7Bv0JAK67deKr9/NCI=
|
| 53 |
+
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
| 54 |
+
github.com/gin-contrib/cors v1.7.3 h1:hV+a5xp8hwJoTw7OY+a70FsL8JkVVFTXw9EcfrYUdns=
|
| 55 |
+
github.com/gin-contrib/cors v1.7.3/go.mod h1:M3bcKZhxzsvI+rlRSkkxHyljJt1ESd93COUvemZ79j4=
|
| 56 |
+
github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E=
|
| 57 |
+
github.com/gin-contrib/sse v1.0.0/go.mod h1:zNuFdwarAygJBht0NTKiSi3jRf6RbqeILZ9Sp6Slhe0=
|
| 58 |
+
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
|
| 59 |
+
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
|
| 60 |
+
github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
|
| 61 |
+
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
|
| 62 |
+
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
| 63 |
+
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
| 64 |
+
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
| 65 |
+
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
| 66 |
+
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
| 67 |
+
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
| 68 |
+
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
| 69 |
+
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
| 70 |
+
github.com/go-playground/validator/v10 v10.25.0 h1:5Dh7cjvzR7BRZadnsVOzPhWsrwUr0nmsZJxEAnFLNO8=
|
| 71 |
+
github.com/go-playground/validator/v10 v10.25.0/go.mod h1:GGzBIJMuE98Ic/kJsBXbz1x/7cByt++cQ+YOuDM5wus=
|
| 72 |
+
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
|
| 73 |
+
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
|
| 74 |
+
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
|
| 75 |
+
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
|
| 76 |
+
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
| 77 |
+
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
| 78 |
+
github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E=
|
| 79 |
+
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
| 80 |
+
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
| 81 |
+
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
| 82 |
+
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
| 83 |
+
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
| 84 |
+
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
| 85 |
+
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
| 86 |
+
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
| 87 |
+
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
| 88 |
+
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
| 89 |
+
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
| 90 |
+
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
| 91 |
+
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
| 92 |
+
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
| 93 |
+
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
| 94 |
+
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
| 95 |
+
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
| 96 |
+
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
| 97 |
+
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
| 98 |
+
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
| 99 |
+
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
| 100 |
+
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
| 101 |
+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
| 102 |
+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
| 103 |
+
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
|
| 104 |
+
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
|
| 105 |
+
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
| 106 |
+
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
| 107 |
+
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
| 108 |
+
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
| 109 |
+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
| 110 |
+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
| 111 |
+
github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY=
|
| 112 |
+
github.com/googleapis/gax-go/v2 v2.0.3/go.mod h1:LLvjysVCY1JZeum8Z6l8qUty8fiNwE08qbEPm1M08qg=
|
| 113 |
+
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
| 114 |
+
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
| 115 |
+
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
| 116 |
+
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
|
| 117 |
+
github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw=
|
| 118 |
+
github.com/h12w/go-socks5 v0.0.0-20200522160539-76189e178364 h1:5XxdakFhqd9dnXoAZy1Mb2R/DZ6D1e+0bGC/JhucGYI=
|
| 119 |
+
github.com/h12w/go-socks5 v0.0.0-20200522160539-76189e178364/go.mod h1:eDJQioIyy4Yn3MVivT7rv/39gAJTrA7lgmYr8EW950c=
|
| 120 |
+
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
| 121 |
+
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
| 122 |
+
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU=
|
| 123 |
+
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
| 124 |
+
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
| 125 |
+
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
| 126 |
+
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
|
| 127 |
+
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
| 128 |
+
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
| 129 |
+
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
|
| 130 |
+
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
|
| 131 |
+
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
| 132 |
+
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
|
| 133 |
+
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
| 134 |
+
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
|
| 135 |
+
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
| 136 |
+
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
| 137 |
+
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
| 138 |
+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
| 139 |
+
github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
| 140 |
+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
| 141 |
+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
| 142 |
+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
| 143 |
+
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
| 144 |
+
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
| 145 |
+
github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI=
|
| 146 |
+
github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
| 147 |
+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
| 148 |
+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
| 149 |
+
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
| 150 |
+
github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4=
|
| 151 |
+
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
| 152 |
+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
| 153 |
+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
| 154 |
+
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
| 155 |
+
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
| 156 |
+
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
| 157 |
+
github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo=
|
| 158 |
+
github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM=
|
| 159 |
+
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
| 160 |
+
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
|
| 161 |
+
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
| 162 |
+
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
|
| 163 |
+
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
|
| 164 |
+
github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
|
| 165 |
+
github.com/onsi/ginkgo/v2 v2.1.4/go.mod h1:um6tUpWM/cxCK3/FK8BXqEiUMUwRgSM4JXG47RKZmLU=
|
| 166 |
+
github.com/onsi/ginkgo/v2 v2.1.6/go.mod h1:MEH45j8TBi6u9BMogfbp0stKC5cdGjumZj5Y7AG4VIk=
|
| 167 |
+
github.com/onsi/ginkgo/v2 v2.2.0/go.mod h1:MEH45j8TBi6u9BMogfbp0stKC5cdGjumZj5Y7AG4VIk=
|
| 168 |
+
github.com/onsi/ginkgo/v2 v2.3.0/go.mod h1:Eew0uilEqZmIEZr8JrvYlvOM7Rr6xzTmMV8AyFNU9d0=
|
| 169 |
+
github.com/onsi/ginkgo/v2 v2.4.0/go.mod h1:iHkDK1fKGcBoEHT5W7YBq4RFWaQulw+caOMkAt4OrFo=
|
| 170 |
+
github.com/onsi/ginkgo/v2 v2.5.0/go.mod h1:Luc4sArBICYCS8THh8v3i3i5CuSZO+RaQRaJoeNwomw=
|
| 171 |
+
github.com/onsi/ginkgo/v2 v2.7.0/go.mod h1:yjiuMwPokqY1XauOgju45q3sJt6VzQ/Fict1LFVcsAo=
|
| 172 |
+
github.com/onsi/ginkgo/v2 v2.8.1/go.mod h1:N1/NbDngAFcSLdyZ+/aYTYGSlq9qMCS/cNKGJjy+csc=
|
| 173 |
+
github.com/onsi/ginkgo/v2 v2.9.0/go.mod h1:4xkjoL/tZv4SMWeww56BU5kAt19mVB47gTWxmrTcxyk=
|
| 174 |
+
github.com/onsi/ginkgo/v2 v2.9.1/go.mod h1:FEcmzVcCHl+4o9bQZVab+4dC9+j+91t2FHSzmGAPfuo=
|
| 175 |
+
github.com/onsi/ginkgo/v2 v2.9.2/go.mod h1:WHcJJG2dIlcCqVfBAwUCrJxSPFb6v4azBwgxeMeDuts=
|
| 176 |
+
github.com/onsi/ginkgo/v2 v2.9.5/go.mod h1:tvAoo1QUJwNEU2ITftXTpR7R1RbCzoZUOs3RonqW57k=
|
| 177 |
+
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
| 178 |
+
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
| 179 |
+
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
|
| 180 |
+
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
|
| 181 |
+
github.com/onsi/gomega v1.20.1/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo=
|
| 182 |
+
github.com/onsi/gomega v1.21.1/go.mod h1:iYAIXgPSaDHak0LCMA+AWBpIKBr8WZicMxnE8luStNc=
|
| 183 |
+
github.com/onsi/gomega v1.22.1/go.mod h1:x6n7VNe4hw0vkyYUM4mjIXx3JbLiPaBPNgB7PRQ1tuM=
|
| 184 |
+
github.com/onsi/gomega v1.24.0/go.mod h1:Z/NWtiqwBrwUt4/2loMmHL63EDLnYHmVbuBpDr2vQAg=
|
| 185 |
+
github.com/onsi/gomega v1.24.1/go.mod h1:3AOiACssS3/MajrniINInwbfOOtfZvplPzuRSmvt1jM=
|
| 186 |
+
github.com/onsi/gomega v1.26.0/go.mod h1:r+zV744Re+DiYCIPRlYOTxn0YkOLcAnW8k1xXdMPGhM=
|
| 187 |
+
github.com/onsi/gomega v1.27.1/go.mod h1:aHX5xOykVYzWOV4WqQy0sy8BQptgukenXpCXfadcIAw=
|
| 188 |
+
github.com/onsi/gomega v1.27.3/go.mod h1:5vG284IBtfDAmDyrK+eGyZmUgUlmi+Wngqo557cZ6Gw=
|
| 189 |
+
github.com/onsi/gomega v1.27.4/go.mod h1:riYq/GJKh8hhoM01HN6Vmuy93AarCXCBGpvFDK3q3fQ=
|
| 190 |
+
github.com/onsi/gomega v1.27.6/go.mod h1:PIQNjfQwkP3aQAH7lf7j87O/5FiNr+ZR8+ipb+qQlhg=
|
| 191 |
+
github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8=
|
| 192 |
+
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
|
| 193 |
+
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
|
| 194 |
+
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2 h1:JhzVVoYvbOACxoUmOs6V/G4D5nPVUW73rKvXxP4XUJc=
|
| 195 |
+
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2/go.mod h1:iIss55rKnNBTvrwdmkUpLnDpZoAHvWaiq5+iMmen4AE=
|
| 196 |
+
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
| 197 |
+
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
| 198 |
+
github.com/pkoukk/tiktoken-go v0.1.7 h1:qOBHXX4PHtvIvmOtyg1EeKlwFRiMKAcoMp4Q+bLQDmw=
|
| 199 |
+
github.com/pkoukk/tiktoken-go v0.1.7/go.mod h1:9NiV+i9mJKGj1rYOT+njbv+ZwA/zJxYdewGl6qVatpg=
|
| 200 |
+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
| 201 |
+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
| 202 |
+
github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
| 203 |
+
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
| 204 |
+
github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
|
| 205 |
+
github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
| 206 |
+
github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A=
|
| 207 |
+
github.com/quic-go/qtls-go1-20 v0.3.1/go.mod h1:X9Nh97ZL80Z+bX/gUXMbipO6OxdiDi58b/fMC9mAL+k=
|
| 208 |
+
github.com/quic-go/quic-go v0.37.4/go.mod h1:YsbH1r4mSHPJcLF4k4zruUkLBqctEMBDR6VPvcYjIsU=
|
| 209 |
+
github.com/refraction-networking/utls v1.5.4/go.mod h1:SPuDbBmgLGp8s+HLNc83FuavwZCFoMmExj+ltUHiHUw=
|
| 210 |
+
github.com/refraction-networking/utls v1.6.7 h1:zVJ7sP1dJx/WtVuITug3qYUq034cDq9B2MR1K67ULZM=
|
| 211 |
+
github.com/refraction-networking/utls v1.6.7/go.mod h1:BC3O4vQzye5hqpmDTWUqi4P5DDhzJfkV1tdqtawQIH0=
|
| 212 |
+
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
| 213 |
+
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
| 214 |
+
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
| 215 |
+
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
|
| 216 |
+
github.com/samber/lo v1.49.1 h1:4BIFyVfuQSEpluc7Fua+j1NolZHiEHEpaSEKdsH0tew=
|
| 217 |
+
github.com/samber/lo v1.49.1/go.mod h1:dO6KHFzUKXgP8LDhU0oI8d2hekjXnGOu0DB8Jecxd6o=
|
| 218 |
+
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
|
| 219 |
+
github.com/shurcooL/component v0.0.0-20170202220835-f88ec8f54cc4/go.mod h1:XhFIlyj5a1fBNx5aJTbKoIq0mNaPvOagO+HjB3EtxrY=
|
| 220 |
+
github.com/shurcooL/events v0.0.0-20181021180414-410e4ca65f48/go.mod h1:5u70Mqkb5O5cxEA8nxTsgrgLehJeAw6Oc4Ab1c/P1HM=
|
| 221 |
+
github.com/shurcooL/github_flavored_markdown v0.0.0-20181002035957-2122de532470/go.mod h1:2dOwnU2uBioM+SGy2aZoq1f/Sd1l9OkAeAUvjSyvgU0=
|
| 222 |
+
github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk=
|
| 223 |
+
github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041/go.mod h1:N5mDOmsrJOB+vfqUK+7DmDyjhSLIIBnXo9lvZJj3MWQ=
|
| 224 |
+
github.com/shurcooL/gofontwoff v0.0.0-20180329035133-29b52fc0a18d/go.mod h1:05UtEgK5zq39gLST6uB0cf3NEHjETfB4Fgr3Gx5R9Vw=
|
| 225 |
+
github.com/shurcooL/gopherjslib v0.0.0-20160914041154-feb6d3990c2c/go.mod h1:8d3azKNyqcHP1GaQE/c6dDgjkgSx2BZ4IoEi4F1reUI=
|
| 226 |
+
github.com/shurcooL/highlight_diff v0.0.0-20170515013008-09bb4053de1b/go.mod h1:ZpfEhSmds4ytuByIcDnOLkTHGUI6KNqRNPDLHDk+mUU=
|
| 227 |
+
github.com/shurcooL/highlight_go v0.0.0-20181028180052-98c3abbbae20/go.mod h1:UDKB5a1T23gOMUJrI+uSuH0VRDStOiUVSjBTRDVBVag=
|
| 228 |
+
github.com/shurcooL/home v0.0.0-20181020052607-80b7ffcb30f9/go.mod h1:+rgNQw2P9ARFAs37qieuu7ohDNQ3gds9msbT2yn85sg=
|
| 229 |
+
github.com/shurcooL/htmlg v0.0.0-20170918183704-d01228ac9e50/go.mod h1:zPn1wHpTIePGnXSHpsVPWEktKXHr6+SS6x/IKRb7cpw=
|
| 230 |
+
github.com/shurcooL/httperror v0.0.0-20170206035902-86b7830d14cc/go.mod h1:aYMfkZ6DWSJPJ6c4Wwz3QtW22G7mf/PEgaB9k/ik5+Y=
|
| 231 |
+
github.com/shurcooL/httpfs v0.0.0-20171119174359-809beceb2371/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
|
| 232 |
+
github.com/shurcooL/httpgzip v0.0.0-20180522190206-b1c53ac65af9/go.mod h1:919LwcH0M7/W4fcZ0/jy0qGght1GIhqyS/EgWGH2j5Q=
|
| 233 |
+
github.com/shurcooL/issues v0.0.0-20181008053335-6292fdc1e191/go.mod h1:e2qWDig5bLteJ4fwvDAc2NHzqFEthkqn7aOZAOpj+PQ=
|
| 234 |
+
github.com/shurcooL/issuesapp v0.0.0-20180602232740-048589ce2241/go.mod h1:NPpHK2TI7iSaM0buivtFUc9offApnI0Alt/K8hcHy0I=
|
| 235 |
+
github.com/shurcooL/notifications v0.0.0-20181007000457-627ab5aea122/go.mod h1:b5uSkrEVM1jQUspwbixRBhaIjIzL2xazXp6kntxYle0=
|
| 236 |
+
github.com/shurcooL/octicon v0.0.0-20181028054416-fa4f57f9efb2/go.mod h1:eWdoE5JD4R5UVWDucdOPg1g2fqQRq78IQa9zlOV1vpQ=
|
| 237 |
+
github.com/shurcooL/reactions v0.0.0-20181006231557-f2e0b4ca5b82/go.mod h1:TCR1lToEk4d2s07G3XGfz2QrgHXg4RJBvjrOozvoWfk=
|
| 238 |
+
github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
| 239 |
+
github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYEDaXHZDBsXlPCDqdhQuJkuw4NOtaxYe3xii4=
|
| 240 |
+
github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw=
|
| 241 |
+
github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:UdhH50NIW0fCiwBSr0co2m7BnFLdv4fQTgdqdJTHFeE=
|
| 242 |
+
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA=
|
| 243 |
+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
| 244 |
+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
| 245 |
+
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
| 246 |
+
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
| 247 |
+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
| 248 |
+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
| 249 |
+
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
| 250 |
+
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
| 251 |
+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
| 252 |
+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
| 253 |
+
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
| 254 |
+
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
| 255 |
+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
| 256 |
+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
| 257 |
+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
| 258 |
+
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
|
| 259 |
+
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
| 260 |
+
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
| 261 |
+
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
|
| 262 |
+
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
| 263 |
+
github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU=
|
| 264 |
+
github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM=
|
| 265 |
+
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
|
| 266 |
+
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
|
| 267 |
+
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
| 268 |
+
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
| 269 |
+
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
| 270 |
+
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
| 271 |
+
go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA=
|
| 272 |
+
go4.org v0.0.0-20180809161055-417644f6feb5/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE=
|
| 273 |
+
golang.org/x/arch v0.14.0 h1:z9JUEZWr8x4rR0OU6c4/4t6E6jOZ8/QBS2bBYBm4tx4=
|
| 274 |
+
golang.org/x/arch v0.14.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
|
| 275 |
+
golang.org/x/build v0.0.0-20190111050920-041ab4dc3f9d/go.mod h1:OWs+y06UdEOHN4y+MfF/py+xQ/tYqIWW03b70/CG9Rw=
|
| 276 |
+
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
| 277 |
+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
| 278 |
+
golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
| 279 |
+
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
| 280 |
+
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
| 281 |
+
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
| 282 |
+
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
|
| 283 |
+
golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
|
| 284 |
+
golang.org/x/crypto v0.4.0/go.mod h1:3quD/ATkf6oY+rnes5c3ExXTbLc8mueNue5/DoinL80=
|
| 285 |
+
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
|
| 286 |
+
golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs=
|
| 287 |
+
golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ=
|
| 288 |
+
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
| 289 |
+
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
|
| 290 |
+
golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
| 291 |
+
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
| 292 |
+
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
| 293 |
+
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
| 294 |
+
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
| 295 |
+
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
|
| 296 |
+
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
| 297 |
+
golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI=
|
| 298 |
+
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
| 299 |
+
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
| 300 |
+
golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
| 301 |
+
golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
| 302 |
+
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
| 303 |
+
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
| 304 |
+
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
| 305 |
+
golang.org/x/net v0.0.0-20181029044818-c44066c5c816/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
| 306 |
+
golang.org/x/net v0.0.0-20181106065722-10aee1819953/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
| 307 |
+
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
| 308 |
+
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
| 309 |
+
golang.org/x/net v0.0.0-20190313220215-9f648a60d977/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
| 310 |
+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
| 311 |
+
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
| 312 |
+
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
| 313 |
+
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
| 314 |
+
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
| 315 |
+
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
| 316 |
+
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
|
| 317 |
+
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
| 318 |
+
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
| 319 |
+
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
| 320 |
+
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
| 321 |
+
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
|
| 322 |
+
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
|
| 323 |
+
golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
|
| 324 |
+
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
|
| 325 |
+
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
| 326 |
+
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
| 327 |
+
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
|
| 328 |
+
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
| 329 |
+
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
|
| 330 |
+
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
|
| 331 |
+
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
|
| 332 |
+
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
| 333 |
+
golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
| 334 |
+
golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
| 335 |
+
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
| 336 |
+
golang.org/x/perf v0.0.0-20180704124530-6e6d33e29852/go.mod h1:JLpeXjPJfIyPr5TlbXLkXWLhP8nz10XfvxElABhCtcw=
|
| 337 |
+
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
| 338 |
+
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
| 339 |
+
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
| 340 |
+
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
| 341 |
+
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
| 342 |
+
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
| 343 |
+
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
| 344 |
+
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
| 345 |
+
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
| 346 |
+
golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
| 347 |
+
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
| 348 |
+
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
| 349 |
+
golang.org/x/sys v0.0.0-20181029174526-d69651ed3497/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
| 350 |
+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
| 351 |
+
golang.org/x/sys v0.0.0-20190316082340-a2f829d7f35f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
| 352 |
+
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
| 353 |
+
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
| 354 |
+
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
| 355 |
+
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
| 356 |
+
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
| 357 |
+
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
| 358 |
+
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
| 359 |
+
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
| 360 |
+
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
| 361 |
+
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
| 362 |
+
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
| 363 |
+
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
| 364 |
+
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
| 365 |
+
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
| 366 |
+
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
| 367 |
+
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
| 368 |
+
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
| 369 |
+
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
| 370 |
+
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
| 371 |
+
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
| 372 |
+
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
| 373 |
+
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
| 374 |
+
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
| 375 |
+
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
| 376 |
+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
| 377 |
+
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
| 378 |
+
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
| 379 |
+
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
|
| 380 |
+
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
| 381 |
+
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
| 382 |
+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
| 383 |
+
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
| 384 |
+
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
|
| 385 |
+
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
|
| 386 |
+
golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ=
|
| 387 |
+
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
| 388 |
+
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
|
| 389 |
+
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
|
| 390 |
+
golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
|
| 391 |
+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
| 392 |
+
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
| 393 |
+
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
| 394 |
+
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
| 395 |
+
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
| 396 |
+
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
| 397 |
+
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
| 398 |
+
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
| 399 |
+
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
| 400 |
+
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
| 401 |
+
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
| 402 |
+
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
| 403 |
+
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
|
| 404 |
+
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
|
| 405 |
+
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
| 406 |
+
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
| 407 |
+
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
| 408 |
+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
| 409 |
+
golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
| 410 |
+
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
| 411 |
+
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
| 412 |
+
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
| 413 |
+
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
| 414 |
+
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
| 415 |
+
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
|
| 416 |
+
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
| 417 |
+
golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA=
|
| 418 |
+
golang.org/x/tools v0.4.0/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ=
|
| 419 |
+
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
| 420 |
+
golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s=
|
| 421 |
+
golang.org/x/tools v0.9.1/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc=
|
| 422 |
+
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
| 423 |
+
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
| 424 |
+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
| 425 |
+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
| 426 |
+
google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
|
| 427 |
+
google.golang.org/api v0.0.0-20181030000543-1d582fd0359e/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
|
| 428 |
+
google.golang.org/api v0.1.0/go.mod h1:UGEZY7KEX120AnNLIHFMKIo4obdJhkp2tPbaPlQx13Y=
|
| 429 |
+
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
| 430 |
+
google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
| 431 |
+
google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
| 432 |
+
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
| 433 |
+
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
| 434 |
+
google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
| 435 |
+
google.golang.org/genproto v0.0.0-20181029155118-b69ba1387ce2/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
| 436 |
+
google.golang.org/genproto v0.0.0-20181202183823-bd91e49a0898/go.mod h1:7Ep/1NZk928CDR8SjdVbjWNpdIf6nzjE3BTgJDr2Atg=
|
| 437 |
+
google.golang.org/genproto v0.0.0-20190306203927-b5d61aea6440/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
| 438 |
+
google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
|
| 439 |
+
google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio=
|
| 440 |
+
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
|
| 441 |
+
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
| 442 |
+
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
| 443 |
+
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
| 444 |
+
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
| 445 |
+
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
| 446 |
+
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
| 447 |
+
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
| 448 |
+
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
| 449 |
+
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
| 450 |
+
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
| 451 |
+
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
|
| 452 |
+
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
| 453 |
+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
| 454 |
+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
| 455 |
+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
| 456 |
+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
| 457 |
+
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
| 458 |
+
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
|
| 459 |
+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
| 460 |
+
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
| 461 |
+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
| 462 |
+
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
| 463 |
+
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
| 464 |
+
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
| 465 |
+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
| 466 |
+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
| 467 |
+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
| 468 |
+
grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o=
|
| 469 |
+
h12.io/socks v1.0.3 h1:Ka3qaQewws4j4/eDQnOdpr4wXsC//dXtWvftlIcCQUo=
|
| 470 |
+
h12.io/socks v1.0.3/go.mod h1:AIhxy1jOId/XCz9BO+EIgNL2rQiPTBNnOfnVnQ+3Eck=
|
| 471 |
+
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
| 472 |
+
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
| 473 |
+
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
| 474 |
+
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
|
| 475 |
+
sourcegraph.com/sourcegraph/go-diff v0.5.0/go.mod h1:kuch7UrkMzY0X+p9CRK03kfuPQ2zzQcaEFbx8wA8rck=
|
| 476 |
+
sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3QxT9HOBeFhu6RdvsftgpsbFHBF5Cas6cDKZ0=
|
job/cookie.go
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package job
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"genspark2api/common/config"
|
| 5 |
+
logger "genspark2api/common/loggger"
|
| 6 |
+
"math/rand"
|
| 7 |
+
"time"
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
func LoadCookieTask() {
|
| 11 |
+
for {
|
| 12 |
+
source := rand.NewSource(time.Now().UnixNano())
|
| 13 |
+
randomNumber := rand.New(source).Intn(60) // 生成0到60之间的随机整数
|
| 14 |
+
|
| 15 |
+
// 计算距离下一个时间间隔
|
| 16 |
+
now := time.Now()
|
| 17 |
+
next := time.Date(now.Year(), now.Month(), now.Day(), 17, 5, 0, 0, now.Location())
|
| 18 |
+
|
| 19 |
+
// 如果当前时间已经超过9点,那么等待到第二天的9点
|
| 20 |
+
if now.After(next) {
|
| 21 |
+
next = next.Add(24 * time.Hour)
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
delay := next.Sub(now)
|
| 25 |
+
|
| 26 |
+
// 等待直到下一个间隔
|
| 27 |
+
time.Sleep(delay + time.Duration(randomNumber)*time.Second)
|
| 28 |
+
|
| 29 |
+
logger.SysLog("genspark2api Scheduled LoadCookieTask Task Job Start!")
|
| 30 |
+
|
| 31 |
+
config.InitGSCookies()
|
| 32 |
+
|
| 33 |
+
logger.SysLog("genspark2api Scheduled LoadCookieTask Task Job End!")
|
| 34 |
+
}
|
| 35 |
+
}
|
main.go
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package main
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"fmt"
|
| 5 |
+
"genspark2api/check"
|
| 6 |
+
"genspark2api/common"
|
| 7 |
+
"genspark2api/common/config"
|
| 8 |
+
logger "genspark2api/common/loggger"
|
| 9 |
+
"genspark2api/middleware"
|
| 10 |
+
"genspark2api/router"
|
| 11 |
+
"genspark2api/yescaptcha"
|
| 12 |
+
"os"
|
| 13 |
+
"strconv"
|
| 14 |
+
|
| 15 |
+
"github.com/gin-gonic/gin"
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
func main() {
|
| 19 |
+
logger.SetupLogger()
|
| 20 |
+
logger.SysLog(fmt.Sprintf("genspark2api %s starting...", common.Version))
|
| 21 |
+
|
| 22 |
+
check.CheckEnvVariable()
|
| 23 |
+
|
| 24 |
+
if os.Getenv("GIN_MODE") != "debug" {
|
| 25 |
+
gin.SetMode(gin.ReleaseMode)
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
var err error
|
| 29 |
+
|
| 30 |
+
common.InitTokenEncoders()
|
| 31 |
+
config.InitGSCookies()
|
| 32 |
+
config.YescaptchaClient = yescaptcha.NewClient(config.YesCaptchaClientKey, nil)
|
| 33 |
+
|
| 34 |
+
config.GlobalSessionManager = config.NewSessionManager()
|
| 35 |
+
|
| 36 |
+
// 定时任务 每天9点整重载GS_COOKIES
|
| 37 |
+
//go job.LoadCookieTask()
|
| 38 |
+
|
| 39 |
+
server := gin.New()
|
| 40 |
+
server.Use(gin.Recovery())
|
| 41 |
+
server.Use(middleware.RequestId())
|
| 42 |
+
middleware.SetUpLogger(server)
|
| 43 |
+
|
| 44 |
+
router.SetRouter(server)
|
| 45 |
+
var port = os.Getenv("PORT")
|
| 46 |
+
if port == "" {
|
| 47 |
+
port = strconv.Itoa(*common.Port)
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
if config.DebugEnabled {
|
| 51 |
+
logger.SysLog("running in DEBUG mode.")
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
logger.SysLog("genspark2api start success. enjoy it! ^_^\n")
|
| 55 |
+
|
| 56 |
+
err = server.Run(":" + port)
|
| 57 |
+
|
| 58 |
+
if err != nil {
|
| 59 |
+
logger.FatalLog("failed to start HTTP server: " + err.Error())
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
}
|
middleware/auth.go
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package middleware
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"genspark2api/common/config"
|
| 5 |
+
"genspark2api/model"
|
| 6 |
+
"github.com/gin-gonic/gin"
|
| 7 |
+
"github.com/samber/lo"
|
| 8 |
+
"net/http"
|
| 9 |
+
"strings"
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
func isValidSecret(secret string) bool {
|
| 13 |
+
return config.ApiSecret != "" && !lo.Contains(config.ApiSecrets, secret)
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
func authHelper(c *gin.Context) {
|
| 17 |
+
secret := c.Request.Header.Get("proxy-secret")
|
| 18 |
+
if isValidSecret(secret) {
|
| 19 |
+
c.JSON(http.StatusUnauthorized, gin.H{
|
| 20 |
+
"success": false,
|
| 21 |
+
"message": "无权进行此操作,未提供正确的 api-secret",
|
| 22 |
+
})
|
| 23 |
+
c.Abort()
|
| 24 |
+
return
|
| 25 |
+
}
|
| 26 |
+
c.Next()
|
| 27 |
+
return
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
func authHelperForOpenai(c *gin.Context) {
|
| 31 |
+
secret := c.Request.Header.Get("Authorization")
|
| 32 |
+
secret = strings.Replace(secret, "Bearer ", "", 1)
|
| 33 |
+
if isValidSecret(secret) {
|
| 34 |
+
c.JSON(http.StatusUnauthorized, model.OpenAIErrorResponse{
|
| 35 |
+
OpenAIError: model.OpenAIError{
|
| 36 |
+
Message: "authorization(api-secret)校验失败",
|
| 37 |
+
Type: "invalid_request_error",
|
| 38 |
+
Code: "invalid_authorization",
|
| 39 |
+
},
|
| 40 |
+
})
|
| 41 |
+
c.Abort()
|
| 42 |
+
return
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
if config.ApiSecret == "" {
|
| 46 |
+
c.Request.Header.Set("Authorization", "")
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
c.Next()
|
| 50 |
+
return
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
func Auth() func(c *gin.Context) {
|
| 54 |
+
return func(c *gin.Context) {
|
| 55 |
+
authHelper(c)
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
func OpenAIAuth() func(c *gin.Context) {
|
| 60 |
+
return func(c *gin.Context) {
|
| 61 |
+
authHelperForOpenai(c)
|
| 62 |
+
}
|
| 63 |
+
}
|