Spaces:
Paused
Paused
Upload 46 files
Browse files- .gitattributes +6 -0
- .gitignore +6 -0
- Dockerfile +35 -0
- LICENSE +674 -0
- README.md +383 -9
- check/check.go +68 -0
- common/config/config.go +422 -0
- common/constants.go +78 -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/api.go +14 -0
- controller/chat.go +1827 -0
- controller/video.go +514 -0
- docker-compose.yml +15 -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
- hugging face/Dockerfile +27 -0
- hugging face/README.md +8 -0
- hugging face/supervisord.conf +22 -0
- job/cookie.go +35 -0
- main.go +61 -0
- middleware/auth.go +63 -0
- middleware/cors.go +15 -0
- middleware/ip-list.go +28 -0
- middleware/logger.go +25 -0
- middleware/rate-limit.go +36 -0
- middleware/request-id.go +18 -0
- model/openai.go +229 -0
- router/api-router.go +47 -0
- router/main.go +9 -0
- yescaptcha/main.go +222 -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
|
.gitignore
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.idea
|
| 2 |
+
.vscode
|
| 3 |
+
upload
|
| 4 |
+
*.exe
|
| 5 |
+
*.db
|
| 6 |
+
build
|
Dockerfile
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 使用 Golang 镜像作为构建阶段
|
| 2 |
+
FROM golang 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 |
+
# 使用 Alpine 镜像作为最终镜像
|
| 22 |
+
FROM alpine
|
| 23 |
+
|
| 24 |
+
# 安装基本的运行时依赖
|
| 25 |
+
RUN apk --no-cache add ca-certificates tzdata
|
| 26 |
+
|
| 27 |
+
# 从构建阶段复制可执行文件
|
| 28 |
+
COPY --from=builder /genspark2api .
|
| 29 |
+
|
| 30 |
+
# 暴露端口
|
| 31 |
+
EXPOSE 7055
|
| 32 |
+
# 工作目录
|
| 33 |
+
WORKDIR /app/genspark2api/data
|
| 34 |
+
# 设置入口命令
|
| 35 |
+
ENTRYPOINT ["/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,385 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
-
title: Genspark2api
|
| 3 |
-
emoji: 👀
|
| 4 |
-
colorFrom: purple
|
| 5 |
-
colorTo: gray
|
| 6 |
-
sdk: docker
|
| 7 |
-
pinned: false
|
| 8 |
-
license: mit
|
| 9 |
-
---
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<p align="right">
|
| 2 |
+
<strong>中文</strong>
|
| 3 |
+
</p>
|
| 4 |
+
<div align="center">
|
| 5 |
+
|
| 6 |
+
# Genspark2API
|
| 7 |
+
|
| 8 |
+
_觉得有点意思的话 别忘了点个 ⭐_
|
| 9 |
+
|
| 10 |
+
<a href="https://t.me/+LGKwlC_xa-E5ZDk9">
|
| 11 |
+
<img src="https://img.shields.io/badge/Telegram-AI Wave交流群-0088cc?style=for-the-badge&logo=telegram&logoColor=white" alt="Telegram 交流群" />
|
| 12 |
+
</a>
|
| 13 |
+
|
| 14 |
+
<sup><i>AI Wave 社群</i></sup> · <sup><i>(群内提供公益API、AI机器人)</i></sup>
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
</div>
|
| 18 |
+
|
| 19 |
+
> ⚠️目前官方强制校验`ReCaptchaV3`
|
| 20 |
+
> 不通过则模型降智/生图异常,请参考[genspark-playwright-prxoy服务过V3验证](#genspark-playwright-prxoy服务过V3验证)并配置环境变量
|
| 21 |
+
`RECAPTCHA_PROXY_URL`。
|
| 22 |
+
|
| 23 |
+
## 功能
|
| 24 |
+
|
| 25 |
+
- [x] 支持对话接口(流式/非流式)(`/chat/completions`)(请求非以下列表的模型会触发`Mixture-of-Agents`模式)
|
| 26 |
+
- **gpt-4.1**
|
| 27 |
+
- **o1**
|
| 28 |
+
- **o3**,
|
| 29 |
+
- **o3-pro**,
|
| 30 |
+
- **o4-mini-high**
|
| 31 |
+
- **claude-3-7-sonnet-thinking**
|
| 32 |
+
- **claude-3-7-sonnet**
|
| 33 |
+
- **gemini-2.5-pro**
|
| 34 |
+
- **gemini-2.0-flash**
|
| 35 |
+
- **deep-seek-v3**
|
| 36 |
+
- **deep-seek-r1**
|
| 37 |
+
- **claude-sonnet-4-thinking**
|
| 38 |
+
- **claude-sonnet-4**
|
| 39 |
+
- [x] 支持**联网搜索**,在模型名后添加`-search`即可(如:`gpt-4o-search`)
|
| 40 |
+
- [x] 支持识别**图片**/**文件**多轮对话
|
| 41 |
+
- [x] 支持文生图接口(`/images/generations`)
|
| 42 |
+
- **flux**
|
| 43 |
+
- **flux-speed**
|
| 44 |
+
- **flux-pro/ultra**
|
| 45 |
+
- **ideogram**
|
| 46 |
+
- **ideogram/V_2A**
|
| 47 |
+
- **recraft-v3**
|
| 48 |
+
- **dall-e-3**
|
| 49 |
+
- **imagen3**
|
| 50 |
+
- **imagen4**
|
| 51 |
+
- **gpt-image-1**
|
| 52 |
+
- [x] 支持文/图生视频接口(`/videos/generations`),详情查看[文/图生视频请求格式](#生视频请求格式)
|
| 53 |
+
- [x] 支持自定义请求头校验值(Authorization)
|
| 54 |
+
- [x] 支持cookie池(随机)
|
| 55 |
+
- [x] 支持请求失败自动切换cookie重试(需配置cookie池)
|
| 56 |
+
- [x] 可配置自动删除对话记录
|
| 57 |
+
- [x] 可配置代理请求(环境变量`PROXY_URL`)
|
| 58 |
+
- [x] 可配置Model绑定Chat(解决模型自动切换导致**降智**),详细请看[进阶配置](#解决模型自动切换导致降智问题)。
|
| 59 |
+
|
| 60 |
+
### 接口文档:
|
| 61 |
+
|
| 62 |
+
略
|
| 63 |
+
|
| 64 |
+
### 示例:
|
| 65 |
+
|
| 66 |
+
<span><img src="docs/img2.png" width="800"/></span>
|
| 67 |
+
|
| 68 |
+
## 如何使用
|
| 69 |
+
|
| 70 |
+
略
|
| 71 |
+
|
| 72 |
+
## 如何集成NextChat
|
| 73 |
+
|
| 74 |
+
填 接口地址(ip:端口/域名) 及 API-Key(`PROXY_SECRET`),其它的随便填随便选。
|
| 75 |
+
|
| 76 |
+
> 如果自己没有搭建NextChat面板,这里有个已经搭建好的可以使用 [NeatChat](https://ai.aytsao.cn/)
|
| 77 |
+
|
| 78 |
+
<span><img src="docs/img5.png" width="800"/></span>
|
| 79 |
+
|
| 80 |
+
## 如何集成one-api
|
| 81 |
+
|
| 82 |
+
填 `BaseURL`(ip:端口/域名) 及 密钥(`PROXY_SECRET`),其它的随便填随便选。
|
| 83 |
+
|
| 84 |
+
<span><img src="docs/img3.png" width="800"/></span>
|
| 85 |
+
|
| 86 |
+
## 部署
|
| 87 |
+
|
| 88 |
+
### 基于 Docker-Compose(All In One) 进行部署
|
| 89 |
+
|
| 90 |
+
```shell
|
| 91 |
+
docker-compose pull && docker-compose up -d
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
#### docker-compose.yml
|
| 95 |
+
|
| 96 |
+
```docker
|
| 97 |
+
version: '3.4'
|
| 98 |
+
|
| 99 |
+
services:
|
| 100 |
+
genspark2api:
|
| 101 |
+
image: deanxv/genspark2api:latest
|
| 102 |
+
container_name: genspark2api
|
| 103 |
+
restart: always
|
| 104 |
+
ports:
|
| 105 |
+
- "7055:7055"
|
| 106 |
+
volumes:
|
| 107 |
+
- ./data:/app/genspark2api/data
|
| 108 |
+
environment:
|
| 109 |
+
- GS_COOKIE=****** # cookie (多个请以,分隔)
|
| 110 |
+
- API_SECRET=123456 # [可选]接口密钥-修改此行为请求头校验的值(多个请以,分隔)
|
| 111 |
+
- TZ=Asia/Shanghai
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
### 基于 Docker 进行部署
|
| 115 |
+
|
| 116 |
+
```docker
|
| 117 |
+
docker run --name genspark2api -d --restart always \
|
| 118 |
+
-p 7055:7055 \
|
| 119 |
+
-v $(pwd)/data:/app/genspark2api/data \
|
| 120 |
+
-e GS_COOKIE=***** \
|
| 121 |
+
-e API_SECRET="123456" \
|
| 122 |
+
-e TZ=Asia/Shanghai \
|
| 123 |
+
deanxv/genspark2api
|
| 124 |
+
```
|
| 125 |
+
|
| 126 |
+
其中`API_SECRET`、`GS_COOKIE`修改为自己的。
|
| 127 |
+
|
| 128 |
+
如果上面的镜像无法拉取,可以尝试使用 GitHub 的 Docker 镜像,将上面的`deanxv/genspark2api`替换为
|
| 129 |
+
`ghcr.io/deanxv/genspark2api`即可。
|
| 130 |
+
|
| 131 |
+
### 部署到第三方平台
|
| 132 |
+
|
| 133 |
+
<details>
|
| 134 |
+
<summary><strong>部署到 Zeabur</strong></summary>
|
| 135 |
+
<div>
|
| 136 |
+
|
| 137 |
+
[](https://zeabur.com?referralCode=deanxv&utm_source=deanxv)
|
| 138 |
+
|
| 139 |
+
> Zeabur 的服务器在国外,自动解决了网络的问题,~~同时免费的额度也足够个人使用~~
|
| 140 |
+
|
| 141 |
+
1. 首先 **fork** 一份代码。
|
| 142 |
+
2. 进入 [Zeabur](https://zeabur.com?referralCode=deanxv),使用github登录,进入控制台。
|
| 143 |
+
3. 在 Service -> Add Service,选择 Git(第一次使用需要先授权),选择你 fork 的仓库。
|
| 144 |
+
4. Deploy 会自动开始,先取消。
|
| 145 |
+
5. 添加环境变量
|
| 146 |
+
|
| 147 |
+
`GS_COOKIE:******` cookie (多个请以,分隔)
|
| 148 |
+
|
| 149 |
+
`API_SECRET:123456` [可选]接口密钥-修改此行为请求头校验的值(多个请以,分隔)(与openai-API-KEY用法一致)
|
| 150 |
+
|
| 151 |
+
保存。
|
| 152 |
+
|
| 153 |
+
6. 选择 Redeploy。
|
| 154 |
+
|
| 155 |
+
</div>
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
</details>
|
| 159 |
+
|
| 160 |
+
<details>
|
| 161 |
+
<summary><strong>部署到 Hugging Face</strong></summary>
|
| 162 |
+
<div>
|
| 163 |
+
|
| 164 |
+
> Hugging Face Spaces 提供免费的 Docker 容器部署服务。
|
| 165 |
+
|
| 166 |
+
1. 在 Hugging Face 上创建一个新的 Space: [https://huggingface.co/new-space](https://huggingface.co/new-space)
|
| 167 |
+
2. **Owner** 选择你自己, **Space name** 随意填写。
|
| 168 |
+
3. **Select the Space SDK** 选择 **Docker**。
|
| 169 |
+
4. **Docker template** 选�� **Blank**。
|
| 170 |
+
5. **Space hardware** 选择免费的 `CPU upgrade`。
|
| 171 |
+
6. 点击 **Create Space**。
|
| 172 |
+
7. 你会进入到仓库的文件页面, 点击 **Add file** -> **Create a new file**。
|
| 173 |
+
8. 文件名填写 `Dockerfile`。
|
| 174 |
+
9. 在 `Dockerfile` 中输入以下内容:
|
| 175 |
+
```Dockerfile
|
| 176 |
+
FROM ghcr.io/deanxv/genspark2api:latest
|
| 177 |
+
```
|
| 178 |
+
然后点击 **Commit new file**。
|
| 179 |
+
10. 进入 Space 的 **Settings** 页面, 在左侧菜单选择 **Variables and secrets**。
|
| 180 |
+
11. 点击 **New secret** 添加以下环境变量:
|
| 181 |
+
- `GS_COOKIE`: **必须**, 你的 Genspark Cookie。
|
| 182 |
+
- `API_SECRET`: **推荐**, 你的 API 密钥, 用于保护你的服务。
|
| 183 |
+
- 其他可选环境变量请参考 [环境变量](#环境变量) 章节。
|
| 184 |
+
12. 添加完环境变量后, Hugging Face 会自动重新构建和部署你的 Space。部署完成后, 你的 API 地址就是 `https://<space-name>.hf.space`。
|
| 185 |
+
|
| 186 |
+
</div>
|
| 187 |
+
</details>
|
| 188 |
+
|
| 189 |
+
<details>
|
| 190 |
+
<summary><strong>部署到 Render</strong></summary>
|
| 191 |
+
<div>
|
| 192 |
+
|
| 193 |
+
> Render 提供免费额度,绑卡后可以进一步提升额度
|
| 194 |
+
|
| 195 |
+
Render 可以直接部署 docker 镜像,不需要 fork 仓库:[Render](https://dashboard.render.com)
|
| 196 |
+
|
| 197 |
+
</div>
|
| 198 |
+
</details>
|
| 199 |
+
|
| 200 |
+
## 配置
|
| 201 |
+
|
| 202 |
+
### 环境变量
|
| 203 |
+
|
| 204 |
+
1. `PORT=7055` [可选]端口,默认为7055
|
| 205 |
+
2. `DEBUG=true` [可选]DEBUG模式,可打印更多信息[true:打开、false:关闭]
|
| 206 |
+
3. `API_SECRET=123456` [可选]接口密钥-修改此行为请求头(Authorization)校验的值(同API-KEY)(多个请以,分隔)
|
| 207 |
+
4. `GS_COOKIE=******` cookie (多个请以,分隔)
|
| 208 |
+
5. `AUTO_DEL_CHAT=0` [可选]对话完成自动删除(默认:0)[0:关闭,1:开启]
|
| 209 |
+
6. `REQUEST_RATE_LIMIT=60` [可选]每分钟下的单ip请求速率限制,默认:60次/min
|
| 210 |
+
7. `PROXY_URL=http://127.0.0.1:10801` [可选]代理
|
| 211 |
+
8. `RECAPTCHA_PROXY_URL=http://127.0.0.1:7022` [可选]genspark-playwright-prxoy验证服务地址,仅填写域名或ip:端口即可。(
|
| 212 |
+
示例:`RECAPTCHA_PROXY_URL=https://genspark-playwright-prxoy.com`或`RECAPTCHA_PROXY_URL=http://127.0.0.1:7022`)
|
| 213 |
+
,详情请看[genspark-playwright-prxoy服务过V3验证](#genspark-playwright-prxoy服务过V3验证)
|
| 214 |
+
9. `AUTO_MODEL_CHAT_MAP_TYPE=1` [可选]自动配置Model绑定Chat(默认:1)[0:关闭,1:开启]
|
| 215 |
+
10. `MODEL_CHAT_MAP=claude-3-7-sonnet=a649******00fa,gpt-4o=su74******47hd` [可选]Model绑定Chat(多个请以,分隔)
|
| 216 |
+
,详细请看[进阶配置](#解决模型自动切换导致降智问题)
|
| 217 |
+
11. `ROUTE_PREFIX=hf` [可选]路由前缀,默认为空,添加该变量后的接口示例:`/hf/v1/chat/completions`
|
| 218 |
+
12. `RATE_LIMIT_COOKIE_LOCK_DURATION=600` [可选]到达速率限制的cookie禁用时间,默认为600s
|
| 219 |
+
13. `REASONING_HIDE=0` [可选]**隐藏**推理过程(默认:0)[0:关闭,1:开启]
|
| 220 |
+
|
| 221 |
+
~~14.
|
| 222 |
+
`SESSION_IMAGE_CHAT_MAP=aed9196b-********-4ed6e32f7e4d=0c6785e6-********-7ff6e5a2a29c,aefwer6b-********-casds22=fda234-********-sfaw123` [可选]
|
| 223 |
+
Session绑定Image-Chat(多个请以,分隔),详细请看[进阶配置](#生图模型配置)~~
|
| 224 |
+
|
| 225 |
+
~~15. `YES_CAPTCHA_CLIENT_KEY=******` [可选]YesCaptcha Client Key
|
| 226 |
+
过谷歌验证,详细请看[使用YesCaptcha过谷歌验证](#使用YesCaptcha过谷歌验证)~~
|
| 227 |
+
|
| 228 |
+
### cookie获取方式
|
| 229 |
+
|
| 230 |
+
1. 打开**F12**开发者工具。
|
| 231 |
+
2. 发起对话。
|
| 232 |
+
3. 点击ask请求,请求头中的**cookie**即为环境变量**GS_COOKIE**所需值。
|
| 233 |
+
|
| 234 |
+
> **【注】** 其中`session_id=f9c60******cb6d`是必须的,其他内容可要可不要,即环境变量`GS_COOKIE=session_id=f9c60******cb6d`
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+

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

|
| 259 |
+
4. 配置环境变量 `MODEL_CHAT_MAP=claude-3-7-sonnet=3cdcc******474c5` (多个请以,分隔)
|
| 260 |
+
|
| 261 |
+
### genspark-playwright-prxoy服务过V3验证
|
| 262 |
+
|
| 263 |
+
1. docker部署genspark-playwright-prxoy
|
| 264 |
+
|
| 265 |
+
#### docker
|
| 266 |
+
|
| 267 |
+
```docker
|
| 268 |
+
docker run --name genspark-playwright-proxy -d --restart always \
|
| 269 |
+
-p 7022:7022 \
|
| 270 |
+
-v $(pwd)/data:/app/genspark-playwright-proxy/data \
|
| 271 |
+
-e PROXY_URL=http://account:pwd@ip:port # [可选] 推荐(住宅)动态代理,配置代理后过验证概率更高,但响应会变慢。
|
| 272 |
+
-e TZ=Asia/Shanghai \
|
| 273 |
+
deanxv/genspark-playwright-proxy
|
| 274 |
+
```
|
| 275 |
+
|
| 276 |
+
#### docker-compose
|
| 277 |
+
|
| 278 |
+
```docker-compose
|
| 279 |
+
version: '3.4'
|
| 280 |
+
|
| 281 |
+
services:
|
| 282 |
+
genspark-playwright-prxoy:
|
| 283 |
+
image: deanxv/genspark-playwright-proxy:latest
|
| 284 |
+
container_name: genspark-playwright-prxoy
|
| 285 |
+
restart: always
|
| 286 |
+
ports:
|
| 287 |
+
- "7022:7022"
|
| 288 |
+
volumes:
|
| 289 |
+
- ./data:/app/genspark-playwright-prxoy/data
|
| 290 |
+
environment:
|
| 291 |
+
- PROXY_URL=http://account:pwd@ip:port # [可选] 推荐(住宅)动态代理,配置代理后过验证概率更高,但响应会变慢。
|
| 292 |
+
```
|
| 293 |
+
|
| 294 |
+
2. 部署后配置`genspark2api`环境变量`RECAPTCHA_PROXY_URL`,仅填写域名或ip:端口即可。(示例:
|
| 295 |
+
`RECAPTCHA_PROXY_URL=https://genspark-playwright-prxoy.com`或`RECAPTCHA_PROXY_URL=http://127.0.0.1:7022`)
|
| 296 |
+
|
| 297 |
+
3. 重启`genspark2api`服务。
|
| 298 |
+
|
| 299 |
+
#### 接入自定义Recaptcha服务
|
| 300 |
+
|
| 301 |
+
###### 接口:获取令牌
|
| 302 |
+
|
| 303 |
+
###### 基本信息
|
| 304 |
+
|
| 305 |
+
- **接口地址**:`/genspark`
|
| 306 |
+
- **请求方式**:GET
|
| 307 |
+
- **接口描述**:获取用户认证令牌
|
| 308 |
+
|
| 309 |
+
###### 请求参数
|
| 310 |
+
|
| 311 |
+
###### 请求头
|
| 312 |
+
|
| 313 |
+
| 参数名 | 必选 | 类型 | 说明 |
|
| 314 |
+
|--------|----|--------|--------|
|
| 315 |
+
| cookie | 是 | string | 用户会话凭证 |
|
| 316 |
+
|
| 317 |
+
###### 响应参数
|
| 318 |
+
|
| 319 |
+
###### 响应示例
|
| 320 |
+
|
| 321 |
+
```json
|
| 322 |
+
{
|
| 323 |
+
"code": 200,
|
| 324 |
+
"token": "ey********pe"
|
| 325 |
+
}
|
| 326 |
+
```
|
| 327 |
+
|
| 328 |
+
## 报错排查
|
| 329 |
+
|
| 330 |
+
> `Detected Cloudflare Challenge Page`
|
| 331 |
+
>
|
| 332 |
+
|
| 333 |
+
被Cloudflare拦截出5s盾,可配置`PROXY_URL`。
|
| 334 |
+
|
| 335 |
+
(【推荐方案】[自建ipv6代理池绕过cf对ip的速率限制及5s盾](https://linux.do/t/topic/367413)
|
| 336 |
+
或购买[IProyal](https://iproyal.cn/?r=244330))
|
| 337 |
+
|
| 338 |
+
> `Genspark Service Unavailable`
|
| 339 |
+
>
|
| 340 |
+
Genspark官方服务不可用,请稍后再试。
|
| 341 |
+
|
| 342 |
+
> `All cookies are temporarily unavailable.`
|
| 343 |
+
>
|
| 344 |
+
所有用户(cookie)均到达速率限制,更换用户cookie或稍后再试。
|
| 345 |
+
|
| 346 |
+
## 生视频请求格式
|
| 347 |
+
|
| 348 |
+
### Request
|
| 349 |
+
|
| 350 |
+
**Endpoint**: `POST /v1/videos/generations`
|
| 351 |
+
|
| 352 |
+
**Content-Type**: `application/json`
|
| 353 |
+
|
| 354 |
+
#### Request Parameters
|
| 355 |
+
|
| 356 |
+
| 字段 Field | 类型 Type | 必填 Required | 描述 Description | 可选值 Accepted Values |
|
| 357 |
+
|--------------|---------|-------------|---------------------------|-------------------------------------------------------------------------------------------------|
|
| 358 |
+
| model | string | 是 | 使用的视频生成模型 | 模型列表: `kling/v1.6/standard`\|`pixverse/v3.5/turbo`\|`lumadream/ray-2`\|`gemini/veo2`\|`hunyuan` |
|
| 359 |
+
| aspect_ratio | string | 是 | 视频宽高比 | `9:16` \| `16:9` \| `3:4` \|`1:1` \| `4:3` |
|
| 360 |
+
| duration | int | 是 | 视频时长(单位:秒) | 正整数 |
|
| 361 |
+
| prompt | string | 是 | 生成视频的文本描述 | - |
|
| 362 |
+
| auto_prompt | bool | 是 | 是否自动优化提示词 | `true` \| `false` |
|
| 363 |
+
| image | string | 否 | 用于视频生成的基底图片(Base64编码/url) | Base64字符串/url |
|
| 364 |
+
|
| 365 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 366 |
|
| 367 |
+
### Response
|
| 368 |
+
|
| 369 |
+
#### Response Object
|
| 370 |
+
|
| 371 |
+
```json
|
| 372 |
+
{
|
| 373 |
+
"created": 1677664796,
|
| 374 |
+
"data": [
|
| 375 |
+
{
|
| 376 |
+
"url": "https://example.com/video.mp4"
|
| 377 |
+
}
|
| 378 |
+
]
|
| 379 |
+
}
|
| 380 |
+
```
|
| 381 |
+
|
| 382 |
+
## 其他
|
| 383 |
+
|
| 384 |
+
**Genspark**(
|
| 385 |
+
注册领取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 passed.")
|
| 68 |
+
}
|
common/config/config.go
ADDED
|
@@ -0,0 +1,422 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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"
|
| 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,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package common
|
| 2 |
+
|
| 3 |
+
import "time"
|
| 4 |
+
|
| 5 |
+
var StartTime = time.Now().Unix() // unit: second
|
| 6 |
+
var Version = "v1.12.5" // this hard coding will be replaced automatically when building, no need to manually change
|
| 7 |
+
|
| 8 |
+
var DefaultOpenaiModelList = []string{
|
| 9 |
+
"gpt-4.1",
|
| 10 |
+
"o1",
|
| 11 |
+
"o3",
|
| 12 |
+
"o3-pro",
|
| 13 |
+
"o4-mini-high",
|
| 14 |
+
"claude-3-7-sonnet-thinking",
|
| 15 |
+
"claude-3-7-sonnet",
|
| 16 |
+
"gemini-2.5-pro",
|
| 17 |
+
"gemini-2.0-flash",
|
| 18 |
+
"deep-seek-v3",
|
| 19 |
+
"deep-seek-r1",
|
| 20 |
+
"claude-sonnet-4-thinking",
|
| 21 |
+
"claude-sonnet-4",
|
| 22 |
+
|
| 23 |
+
"flux",
|
| 24 |
+
"flux-speed",
|
| 25 |
+
"flux-pro/ultra",
|
| 26 |
+
"ideogram",
|
| 27 |
+
"ideogram/V_2A",
|
| 28 |
+
"recraft-v3",
|
| 29 |
+
"dall-e-3",
|
| 30 |
+
"imagen3",
|
| 31 |
+
"imagen4",
|
| 32 |
+
"gpt-image-1",
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
var TextModelList = []string{
|
| 36 |
+
"gpt-4.1",
|
| 37 |
+
"o1",
|
| 38 |
+
"o3",
|
| 39 |
+
"o3-pro",
|
| 40 |
+
"o4-mini-high",
|
| 41 |
+
"claude-3-7-sonnet-thinking",
|
| 42 |
+
"claude-3-7-sonnet",
|
| 43 |
+
"gemini-2.5-pro",
|
| 44 |
+
"gemini-2.0-flash",
|
| 45 |
+
"deep-seek-v3",
|
| 46 |
+
"deep-seek-r1",
|
| 47 |
+
"claude-sonnet-4-thinking",
|
| 48 |
+
"claude-sonnet-4",
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
var MixtureModelList = []string{
|
| 52 |
+
"gpt-4o",
|
| 53 |
+
"claude-3-7-sonnet",
|
| 54 |
+
"gemini-2.0-flash",
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
var ImageModelList = []string{
|
| 58 |
+
"flux",
|
| 59 |
+
"flux-speed",
|
| 60 |
+
"flux-pro/ultra",
|
| 61 |
+
"ideogram",
|
| 62 |
+
"ideogram/V_2A",
|
| 63 |
+
"recraft-v3",
|
| 64 |
+
"dall-e-3",
|
| 65 |
+
"imagen3",
|
| 66 |
+
"imagen4",
|
| 67 |
+
"gpt-image-1",
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
var VideoModelList = []string{
|
| 71 |
+
"kling/v1.6/standard",
|
| 72 |
+
"pixverse/v3.5/turbo",
|
| 73 |
+
"lumadream/ray-2",
|
| 74 |
+
"gemini/veo2",
|
| 75 |
+
"hunyuan",
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
//
|
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 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package common
|
| 2 |
+
|
| 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/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 |
+
}
|
controller/chat.go
ADDED
|
@@ -0,0 +1,1827 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package controller
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"bufio"
|
| 5 |
+
"crypto/tls"
|
| 6 |
+
"encoding/base64"
|
| 7 |
+
"encoding/json"
|
| 8 |
+
"fmt"
|
| 9 |
+
"genspark2api/common"
|
| 10 |
+
"genspark2api/common/config"
|
| 11 |
+
logger "genspark2api/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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| 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 |
+
}
|
docker-compose.yml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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=****** # cookie (多个请以,分隔)
|
| 14 |
+
- API_SECRET=123456 # [可选]接口密钥-修改此行为请求头校验的值(多个请以,分隔)
|
| 15 |
+
- 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 |
+
google.golang.org/protobuf v1.36.5 // indirect
|
| 51 |
+
gopkg.in/yaml.v3 v3.0.1 // indirect
|
| 52 |
+
h12.io/socks v1.0.3 // indirect
|
| 53 |
+
)
|
go.sum
ADDED
|
@@ -0,0 +1,476 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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H133OKGwekG838Om/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=
|
hugging face/Dockerfile
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Stage 1: Get the genspark2api binary
|
| 2 |
+
FROM ghcr.io/deanxv/genspark2api:latest AS genspark2api
|
| 3 |
+
|
| 4 |
+
# Stage 2: Get the genspark-playwright-proxy files
|
| 5 |
+
FROM deanxv/genspark-playwright-proxy:latest AS proxy
|
| 6 |
+
|
| 7 |
+
# Final stage: Combine them into a new image
|
| 8 |
+
# Use the proxy image as base because it contains Node.js and browser dependencies
|
| 9 |
+
FROM deanxv/genspark-playwright-proxy:latest
|
| 10 |
+
|
| 11 |
+
# Install supervisor
|
| 12 |
+
RUN apt-get update && apt-get install -y supervisor && rm -rf /var/lib/apt/lists/*
|
| 13 |
+
|
| 14 |
+
# Create directories for services
|
| 15 |
+
RUN mkdir -p /app/genspark2api
|
| 16 |
+
|
| 17 |
+
# Copy the genspark2api binary from the first stage
|
| 18 |
+
COPY --from=genspark2api /genspark2api /app/genspark2api/genspark2api
|
| 19 |
+
|
| 20 |
+
# Copy the supervisor configuration file
|
| 21 |
+
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
| 22 |
+
|
| 23 |
+
# Expose the ports for both services (though only one will be mapped by Hugging Face)
|
| 24 |
+
EXPOSE 7055 7022
|
| 25 |
+
|
| 26 |
+
# Start supervisor to manage both services
|
| 27 |
+
CMD ["/usr/bin/supervisord"]
|
hugging face/README.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: API Proxy
|
| 3 |
+
emoji: 🚀
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: green
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 7055
|
| 8 |
+
---
|
hugging face/supervisord.conf
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[supervisord]
|
| 2 |
+
nodaemon=true
|
| 3 |
+
|
| 4 |
+
[program:genspark2api]
|
| 5 |
+
command=/app/genspark2api/genspark2api
|
| 6 |
+
autostart=true
|
| 7 |
+
autorestart=true
|
| 8 |
+
stdout_logfile=/dev/stdout
|
| 9 |
+
stdout_logfile_maxbytes=0
|
| 10 |
+
stderr_logfile=/dev/stderr
|
| 11 |
+
stderr_logfile_maxbytes=0
|
| 12 |
+
directory=/app/genspark2api
|
| 13 |
+
|
| 14 |
+
[program:proxy]
|
| 15 |
+
command=node /app/proxy/app.js
|
| 16 |
+
autostart=true
|
| 17 |
+
autorestart=true
|
| 18 |
+
stdout_logfile=/dev/stdout
|
| 19 |
+
stdout_logfile_maxbytes=0
|
| 20 |
+
stderr_logfile=/dev/stderr
|
| 21 |
+
stderr_logfile_maxbytes=0
|
| 22 |
+
directory=/app/proxy
|
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,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
"github.com/gin-gonic/gin"
|
| 13 |
+
"os"
|
| 14 |
+
"strconv"
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
func main() {
|
| 18 |
+
logger.SetupLogger()
|
| 19 |
+
logger.SysLog(fmt.Sprintf("genspark2api %s starting...", common.Version))
|
| 20 |
+
|
| 21 |
+
check.CheckEnvVariable()
|
| 22 |
+
|
| 23 |
+
if os.Getenv("GIN_MODE") != "debug" {
|
| 24 |
+
gin.SetMode(gin.ReleaseMode)
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
var err error
|
| 28 |
+
|
| 29 |
+
common.InitTokenEncoders()
|
| 30 |
+
config.InitGSCookies()
|
| 31 |
+
config.YescaptchaClient = yescaptcha.NewClient(config.YesCaptchaClientKey, nil)
|
| 32 |
+
|
| 33 |
+
config.GlobalSessionManager = config.NewSessionManager()
|
| 34 |
+
|
| 35 |
+
// 定时任务 每天9点整重载GS_COOKIES
|
| 36 |
+
//go job.LoadCookieTask()
|
| 37 |
+
|
| 38 |
+
server := gin.New()
|
| 39 |
+
server.Use(gin.Recovery())
|
| 40 |
+
server.Use(middleware.RequestId())
|
| 41 |
+
middleware.SetUpLogger(server)
|
| 42 |
+
|
| 43 |
+
router.SetRouter(server)
|
| 44 |
+
var port = os.Getenv("PORT")
|
| 45 |
+
if port == "" {
|
| 46 |
+
port = strconv.Itoa(*common.Port)
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
if config.DebugEnabled {
|
| 50 |
+
logger.SysLog("running in DEBUG mode.")
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
logger.SysLog("genspark2api start success. enjoy it! ^_^\n")
|
| 54 |
+
|
| 55 |
+
err = server.Run(":" + port)
|
| 56 |
+
|
| 57 |
+
if err != nil {
|
| 58 |
+
logger.FatalLog("failed to start HTTP server: " + err.Error())
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
}
|
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 |
+
}
|
middleware/cors.go
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package middleware
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"github.com/gin-contrib/cors"
|
| 5 |
+
"github.com/gin-gonic/gin"
|
| 6 |
+
)
|
| 7 |
+
|
| 8 |
+
func CORS() gin.HandlerFunc {
|
| 9 |
+
config := cors.DefaultConfig()
|
| 10 |
+
config.AllowAllOrigins = true
|
| 11 |
+
config.AllowCredentials = true
|
| 12 |
+
config.AllowMethods = []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}
|
| 13 |
+
config.AllowHeaders = []string{"*"}
|
| 14 |
+
return cors.New(config)
|
| 15 |
+
}
|
middleware/ip-list.go
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package middleware
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"genspark2api/common/config"
|
| 5 |
+
"github.com/gin-gonic/gin"
|
| 6 |
+
"net/http"
|
| 7 |
+
"strings"
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
// IPBlacklistMiddleware 检查请求的IP是否在黑名单中
|
| 11 |
+
func IPBlacklistMiddleware() gin.HandlerFunc {
|
| 12 |
+
return func(c *gin.Context) {
|
| 13 |
+
// 获取请求的IP地址
|
| 14 |
+
clientIP := c.ClientIP()
|
| 15 |
+
|
| 16 |
+
// 检查IP是否在黑名单中
|
| 17 |
+
for _, blockedIP := range config.IpBlackList {
|
| 18 |
+
if strings.TrimSpace(blockedIP) == clientIP {
|
| 19 |
+
// 如果在黑名单中,返回403 Forbidden
|
| 20 |
+
c.AbortWithStatusJSON(http.StatusForbidden, gin.H{"error": "Forbidden"})
|
| 21 |
+
return
|
| 22 |
+
}
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
// 如果不在黑名单中,继续处理请求
|
| 26 |
+
c.Next()
|
| 27 |
+
}
|
| 28 |
+
}
|
middleware/logger.go
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package middleware
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"fmt"
|
| 5 |
+
"genspark2api/common/helper"
|
| 6 |
+
"github.com/gin-gonic/gin"
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
func SetUpLogger(server *gin.Engine) {
|
| 10 |
+
server.Use(gin.LoggerWithFormatter(func(param gin.LogFormatterParams) string {
|
| 11 |
+
var requestID string
|
| 12 |
+
if param.Keys != nil {
|
| 13 |
+
requestID = param.Keys[helper.RequestIdKey].(string)
|
| 14 |
+
}
|
| 15 |
+
return fmt.Sprintf("[GIN] %s | %s | %3d | %13v | %15s | %7s %s\n",
|
| 16 |
+
param.TimeStamp.Format("2006/01/02 - 15:04:05"),
|
| 17 |
+
requestID,
|
| 18 |
+
param.StatusCode,
|
| 19 |
+
param.Latency,
|
| 20 |
+
param.ClientIP,
|
| 21 |
+
param.Method,
|
| 22 |
+
param.Path,
|
| 23 |
+
)
|
| 24 |
+
}))
|
| 25 |
+
}
|
middleware/rate-limit.go
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package middleware
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"genspark2api/common"
|
| 5 |
+
"genspark2api/common/config"
|
| 6 |
+
"github.com/gin-gonic/gin"
|
| 7 |
+
"net/http"
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
var timeFormat = "2006-01-02T15:04:05.000Z"
|
| 11 |
+
|
| 12 |
+
var inMemoryRateLimiter common.InMemoryRateLimiter
|
| 13 |
+
|
| 14 |
+
func memoryRateLimiter(c *gin.Context, maxRequestNum int, duration int64, mark string) {
|
| 15 |
+
key := mark + c.ClientIP()
|
| 16 |
+
if !inMemoryRateLimiter.Request(key, maxRequestNum, duration) {
|
| 17 |
+
c.JSON(http.StatusTooManyRequests, gin.H{
|
| 18 |
+
"success": false,
|
| 19 |
+
"message": "请求过于频繁,请稍后再试",
|
| 20 |
+
})
|
| 21 |
+
c.Abort()
|
| 22 |
+
return
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
func rateLimitFactory(maxRequestNum int, duration int64, mark string) func(c *gin.Context) {
|
| 27 |
+
// It's safe to call multi times.
|
| 28 |
+
inMemoryRateLimiter.Init(config.RateLimitKeyExpirationDuration)
|
| 29 |
+
return func(c *gin.Context) {
|
| 30 |
+
memoryRateLimiter(c, maxRequestNum, duration, mark)
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
func RequestRateLimit() func(c *gin.Context) {
|
| 35 |
+
return rateLimitFactory(config.RequestRateLimitNum, config.RequestRateLimitDuration, "REQUEST_RATE_LIMIT")
|
| 36 |
+
}
|
middleware/request-id.go
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package middleware
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"context"
|
| 5 |
+
"genspark2api/common/helper"
|
| 6 |
+
"github.com/gin-gonic/gin"
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
func RequestId() func(c *gin.Context) {
|
| 10 |
+
return func(c *gin.Context) {
|
| 11 |
+
id := helper.GenRequestID()
|
| 12 |
+
c.Set(helper.RequestIdKey, id)
|
| 13 |
+
ctx := context.WithValue(c.Request.Context(), helper.RequestIdKey, id)
|
| 14 |
+
c.Request = c.Request.WithContext(ctx)
|
| 15 |
+
c.Header(helper.RequestIdKey, id)
|
| 16 |
+
c.Next()
|
| 17 |
+
}
|
| 18 |
+
}
|
model/openai.go
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package model
|
| 2 |
+
|
| 3 |
+
import "encoding/json"
|
| 4 |
+
|
| 5 |
+
type OpenAIChatCompletionRequest struct {
|
| 6 |
+
Model string `json:"model"`
|
| 7 |
+
Stream bool `json:"stream"`
|
| 8 |
+
Messages []OpenAIChatMessage `json:"messages"`
|
| 9 |
+
OpenAIChatCompletionExtraRequest
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
type OpenAIChatCompletionExtraRequest struct {
|
| 13 |
+
ChannelId *string `json:"channelId"`
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
type SessionState struct {
|
| 17 |
+
Models []string `json:"models"`
|
| 18 |
+
Layers int `json:"layers"`
|
| 19 |
+
Answer string `json:"answer"`
|
| 20 |
+
AnswerIsFinished bool `json:"answer_is_finished"`
|
| 21 |
+
}
|
| 22 |
+
type OpenAIChatMessage struct {
|
| 23 |
+
Role string `json:"role"`
|
| 24 |
+
Content interface{} `json:"content"`
|
| 25 |
+
IsPrompt bool `json:"is_prompt"`
|
| 26 |
+
SessionState *SessionState `json:"session_state"`
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
func (r *OpenAIChatCompletionRequest) AddMessage(message OpenAIChatMessage) {
|
| 30 |
+
r.Messages = append([]OpenAIChatMessage{message}, r.Messages...)
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
func (r *OpenAIChatCompletionRequest) PrependMessagesFromJSON(jsonString string) error {
|
| 34 |
+
var newMessages []OpenAIChatMessage
|
| 35 |
+
err := json.Unmarshal([]byte(jsonString), &newMessages)
|
| 36 |
+
if err != nil {
|
| 37 |
+
return err
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
// 查找最后一个 system role 的索引
|
| 41 |
+
var insertIndex int
|
| 42 |
+
for i := len(r.Messages) - 1; i >= 0; i-- {
|
| 43 |
+
if r.Messages[i].Role == "system" {
|
| 44 |
+
insertIndex = i + 1
|
| 45 |
+
break
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
// 将 newMessages 插入到找到的索引后面
|
| 50 |
+
r.Messages = append(r.Messages[:insertIndex], append(newMessages, r.Messages[insertIndex:]...)...)
|
| 51 |
+
return nil
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
func (r *OpenAIChatCompletionRequest) SystemMessagesProcess(model string) {
|
| 55 |
+
if r.Messages == nil {
|
| 56 |
+
return
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
if model == "deep-seek-r1" {
|
| 60 |
+
for i := range r.Messages {
|
| 61 |
+
if r.Messages[i].Role == "system" {
|
| 62 |
+
r.Messages[i].Role = "user"
|
| 63 |
+
}
|
| 64 |
+
if r.Messages[i].Role == "assistant" {
|
| 65 |
+
r.Messages[i].IsPrompt = false
|
| 66 |
+
r.Messages[i].SessionState = &SessionState{
|
| 67 |
+
Models: []string{model},
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
func (r *OpenAIChatCompletionRequest) FilterUserMessage() {
|
| 75 |
+
if r.Messages == nil {
|
| 76 |
+
return
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
// 返回最后一个role为user的元素
|
| 80 |
+
for i := len(r.Messages) - 1; i >= 0; i-- {
|
| 81 |
+
if r.Messages[i].Role == "user" {
|
| 82 |
+
r.Messages = r.Messages[i:]
|
| 83 |
+
break
|
| 84 |
+
}
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
type OpenAIErrorResponse struct {
|
| 89 |
+
OpenAIError OpenAIError `json:"error"`
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
type OpenAIError struct {
|
| 93 |
+
Message string `json:"message"`
|
| 94 |
+
Type string `json:"type"`
|
| 95 |
+
Param string `json:"param"`
|
| 96 |
+
Code string `json:"code"`
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
type OpenAIChatCompletionResponse struct {
|
| 100 |
+
ID string `json:"id"`
|
| 101 |
+
Object string `json:"object"`
|
| 102 |
+
Created int64 `json:"created"`
|
| 103 |
+
Model string `json:"model"`
|
| 104 |
+
Choices []OpenAIChoice `json:"choices"`
|
| 105 |
+
Usage OpenAIUsage `json:"usage"`
|
| 106 |
+
SystemFingerprint *string `json:"system_fingerprint"`
|
| 107 |
+
Suggestions []string `json:"suggestions"`
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
type OpenAIChoice struct {
|
| 111 |
+
Index int `json:"index"`
|
| 112 |
+
Message OpenAIMessage `json:"message"`
|
| 113 |
+
LogProbs *string `json:"logprobs"`
|
| 114 |
+
FinishReason *string `json:"finish_reason"`
|
| 115 |
+
Delta OpenAIDelta `json:"delta"`
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
type OpenAIMessage struct {
|
| 119 |
+
Role string `json:"role"`
|
| 120 |
+
Content string `json:"content"`
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
type OpenAIUsage struct {
|
| 124 |
+
PromptTokens int `json:"prompt_tokens"`
|
| 125 |
+
CompletionTokens int `json:"completion_tokens"`
|
| 126 |
+
TotalTokens int `json:"total_tokens"`
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
type OpenAIDelta struct {
|
| 130 |
+
Content string `json:"content"`
|
| 131 |
+
Role string `json:"role"`
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
type OpenAIImagesGenerationRequest struct {
|
| 135 |
+
OpenAIChatCompletionExtraRequest
|
| 136 |
+
Model string `json:"model"`
|
| 137 |
+
Prompt string `json:"prompt"`
|
| 138 |
+
ResponseFormat string `json:"response_format"`
|
| 139 |
+
Image string `json:"image"`
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
type VideosGenerationRequest struct {
|
| 143 |
+
ResponseFormat string `json:"response_format"`
|
| 144 |
+
Model string `json:"model"`
|
| 145 |
+
AspectRatio string `json:"aspect_ratio"`
|
| 146 |
+
Duration int `json:"duration"`
|
| 147 |
+
Prompt string `json:"prompt"`
|
| 148 |
+
AutoPrompt bool `json:"auto_prompt"`
|
| 149 |
+
Image string `json:"image"`
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
type VideosGenerationResponse struct {
|
| 153 |
+
Created int64 `json:"created"`
|
| 154 |
+
Data []*VideosGenerationDataResponse `json:"data"`
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
type VideosGenerationDataResponse struct {
|
| 158 |
+
URL string `json:"url"`
|
| 159 |
+
RevisedPrompt string `json:"revised_prompt"`
|
| 160 |
+
B64Json string `json:"b64_json"`
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
type OpenAIImagesGenerationResponse struct {
|
| 164 |
+
Created int64 `json:"created"`
|
| 165 |
+
DailyLimit bool `json:"dailyLimit"`
|
| 166 |
+
Data []*OpenAIImagesGenerationDataResponse `json:"data"`
|
| 167 |
+
Suggestions []string `json:"suggestions"`
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
type OpenAIImagesGenerationDataResponse struct {
|
| 171 |
+
URL string `json:"url"`
|
| 172 |
+
RevisedPrompt string `json:"revised_prompt"`
|
| 173 |
+
B64Json string `json:"b64_json"`
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
type OpenAIGPT4VImagesReq struct {
|
| 177 |
+
Type string `json:"type"`
|
| 178 |
+
Text string `json:"text"`
|
| 179 |
+
ImageURL struct {
|
| 180 |
+
URL string `json:"url"`
|
| 181 |
+
} `json:"image_url"`
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
type GetUserContent interface {
|
| 185 |
+
GetUserContent() []string
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
type OpenAIModerationRequest struct {
|
| 189 |
+
Input string `json:"input"`
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
type OpenAIModerationResponse struct {
|
| 193 |
+
ID string `json:"id"`
|
| 194 |
+
Model string `json:"model"`
|
| 195 |
+
Results []struct {
|
| 196 |
+
Flagged bool `json:"flagged"`
|
| 197 |
+
Categories map[string]bool `json:"categories"`
|
| 198 |
+
CategoryScores map[string]float64 `json:"category_scores"`
|
| 199 |
+
} `json:"results"`
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
type OpenaiModelResponse struct {
|
| 203 |
+
ID string `json:"id"`
|
| 204 |
+
Object string `json:"object"`
|
| 205 |
+
//Created time.Time `json:"created"`
|
| 206 |
+
//OwnedBy string `json:"owned_by"`
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
// ModelList represents a list of models.
|
| 210 |
+
type OpenaiModelListResponse struct {
|
| 211 |
+
Object string `json:"object"`
|
| 212 |
+
Data []OpenaiModelResponse `json:"data"`
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
func (r *OpenAIChatCompletionRequest) GetUserContent() []string {
|
| 216 |
+
var userContent []string
|
| 217 |
+
|
| 218 |
+
for i := len(r.Messages) - 1; i >= 0; i-- {
|
| 219 |
+
if r.Messages[i].Role == "user" {
|
| 220 |
+
switch contentObj := r.Messages[i].Content.(type) {
|
| 221 |
+
case string:
|
| 222 |
+
userContent = append(userContent, contentObj)
|
| 223 |
+
}
|
| 224 |
+
break
|
| 225 |
+
}
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
return userContent
|
| 229 |
+
}
|
router/api-router.go
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package router
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"fmt"
|
| 5 |
+
"genspark2api/common/config"
|
| 6 |
+
"genspark2api/controller"
|
| 7 |
+
"genspark2api/middleware"
|
| 8 |
+
"github.com/gin-gonic/gin"
|
| 9 |
+
"strings"
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
func SetApiRouter(router *gin.Engine) {
|
| 13 |
+
router.Use(middleware.CORS())
|
| 14 |
+
//router.Use(gzip.Gzip(gzip.DefaultCompression))
|
| 15 |
+
router.Use(middleware.IPBlacklistMiddleware())
|
| 16 |
+
router.Use(middleware.RequestRateLimit())
|
| 17 |
+
|
| 18 |
+
router.GET("/")
|
| 19 |
+
|
| 20 |
+
//router.GET("/api/init/model/chat/map", controller.InitModelChatMap)
|
| 21 |
+
//https://api.openai.com/v1/images/generations
|
| 22 |
+
v1Router := router.Group(fmt.Sprintf("%s/v1", ProcessPath(config.RoutePrefix)))
|
| 23 |
+
v1Router.Use(middleware.OpenAIAuth())
|
| 24 |
+
v1Router.POST("/chat/completions", controller.ChatForOpenAI)
|
| 25 |
+
v1Router.POST("/images/generations", controller.ImagesForOpenAI)
|
| 26 |
+
v1Router.POST("/videos/generations", controller.VideosForOpenAI)
|
| 27 |
+
v1Router.GET("/models", controller.OpenaiModels)
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
func ProcessPath(path string) string {
|
| 31 |
+
// 判断字符串是否为空
|
| 32 |
+
if path == "" {
|
| 33 |
+
return ""
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
// 判断开头是否为/,不是则添加
|
| 37 |
+
if !strings.HasPrefix(path, "/") {
|
| 38 |
+
path = "/" + path
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
// 判断结尾是否为/,是则去掉
|
| 42 |
+
if strings.HasSuffix(path, "/") {
|
| 43 |
+
path = path[:len(path)-1]
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
return path
|
| 47 |
+
}
|
router/main.go
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package router
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"github.com/gin-gonic/gin"
|
| 5 |
+
)
|
| 6 |
+
|
| 7 |
+
func SetRouter(router *gin.Engine) {
|
| 8 |
+
SetApiRouter(router)
|
| 9 |
+
}
|
yescaptcha/main.go
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package yescaptcha
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"bytes"
|
| 5 |
+
"context"
|
| 6 |
+
"encoding/json"
|
| 7 |
+
"errors"
|
| 8 |
+
"io/ioutil"
|
| 9 |
+
"net/http"
|
| 10 |
+
"time"
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
const (
|
| 14 |
+
defaultAPIEndpoint = "https://api.yescaptcha.com"
|
| 15 |
+
createTaskPath = "/createTask"
|
| 16 |
+
getResultPath = "/getTaskResult"
|
| 17 |
+
maxRetries = 20
|
| 18 |
+
pollingInterval = 3 * time.Second
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
// Client represents a YesCaptcha API client
|
| 22 |
+
type Client struct {
|
| 23 |
+
clientKey string
|
| 24 |
+
apiEndpoint string
|
| 25 |
+
httpClient *http.Client
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
// Options contains configuration options for the YesCaptcha client
|
| 29 |
+
type Options struct {
|
| 30 |
+
APIEndpoint string
|
| 31 |
+
HTTPClient *http.Client
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
// NewClient creates a new YesCaptcha client with the given client key and options
|
| 35 |
+
func NewClient(clientKey string, opts *Options) *Client {
|
| 36 |
+
client := &Client{
|
| 37 |
+
clientKey: clientKey,
|
| 38 |
+
apiEndpoint: defaultAPIEndpoint,
|
| 39 |
+
httpClient: &http.Client{Timeout: 30 * time.Second},
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
if opts != nil {
|
| 43 |
+
if opts.APIEndpoint != "" {
|
| 44 |
+
client.apiEndpoint = opts.APIEndpoint
|
| 45 |
+
}
|
| 46 |
+
if opts.HTTPClient != nil {
|
| 47 |
+
client.httpClient = opts.HTTPClient
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
return client
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
// RecaptchaV3Request contains the parameters for solving a ReCaptcha V3 challenge
|
| 55 |
+
type RecaptchaV3Request struct {
|
| 56 |
+
WebsiteURL string
|
| 57 |
+
WebsiteKey string
|
| 58 |
+
PageAction string
|
| 59 |
+
MinScore float64
|
| 60 |
+
SoftID string
|
| 61 |
+
Callback string
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
type createTaskRequest struct {
|
| 65 |
+
ClientKey string `json:"clientKey"`
|
| 66 |
+
Task task `json:"task"`
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
type task struct {
|
| 70 |
+
Type string `json:"type"`
|
| 71 |
+
WebsiteURL string `json:"websiteURL"`
|
| 72 |
+
WebsiteKey string `json:"websiteKey"`
|
| 73 |
+
PageAction string `json:"pageAction"`
|
| 74 |
+
MinScore float64 `json:"minScore,omitempty"`
|
| 75 |
+
SoftID string `json:"softId,omitempty"`
|
| 76 |
+
Callback string `json:"callback,omitempty"`
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
type createTaskResponse struct {
|
| 80 |
+
ErrorID int `json:"errorId"`
|
| 81 |
+
ErrorCode string `json:"errorCode"`
|
| 82 |
+
ErrorDescription string `json:"errorDescription"`
|
| 83 |
+
TaskID string `json:"taskId"`
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
type getResultRequest struct {
|
| 87 |
+
ClientKey string `json:"clientKey"`
|
| 88 |
+
TaskID string `json:"taskId"`
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
type getResultResponse struct {
|
| 92 |
+
ErrorID int `json:"errorId"`
|
| 93 |
+
ErrorCode string `json:"errorCode"`
|
| 94 |
+
ErrorDescription string `json:"errorDescription"`
|
| 95 |
+
Status string `json:"status"`
|
| 96 |
+
Solution solution `json:"solution"`
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
type solution struct {
|
| 100 |
+
GRecaptchaResponse string `json:"gRecaptchaResponse"`
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
// SolveRecaptchaV3 solves a ReCaptcha V3 challenge with context
|
| 104 |
+
func (c *Client) SolveRecaptchaV3(ctx context.Context, req RecaptchaV3Request) (string, error) {
|
| 105 |
+
taskID, err := c.createTask(ctx, req)
|
| 106 |
+
if err != nil {
|
| 107 |
+
return "", err
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
return c.waitForResult(ctx, taskID)
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
func (c *Client) createTask(ctx context.Context, req RecaptchaV3Request) (string, error) {
|
| 114 |
+
request := createTaskRequest{
|
| 115 |
+
ClientKey: c.clientKey,
|
| 116 |
+
Task: task{
|
| 117 |
+
Type: "RecaptchaV3TaskProxyless",
|
| 118 |
+
WebsiteURL: req.WebsiteURL,
|
| 119 |
+
WebsiteKey: req.WebsiteKey,
|
| 120 |
+
PageAction: req.PageAction,
|
| 121 |
+
MinScore: req.MinScore,
|
| 122 |
+
SoftID: req.SoftID,
|
| 123 |
+
Callback: req.Callback,
|
| 124 |
+
},
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
jsonData, err := json.Marshal(request)
|
| 128 |
+
if err != nil {
|
| 129 |
+
return "", err
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
httpReq, err := http.NewRequestWithContext(ctx, "POST", c.apiEndpoint+createTaskPath, bytes.NewBuffer(jsonData))
|
| 133 |
+
if err != nil {
|
| 134 |
+
return "", err
|
| 135 |
+
}
|
| 136 |
+
httpReq.Header.Set("Content-Type", "application/json")
|
| 137 |
+
|
| 138 |
+
resp, err := c.httpClient.Do(httpReq)
|
| 139 |
+
if err != nil {
|
| 140 |
+
return "", err
|
| 141 |
+
}
|
| 142 |
+
defer resp.Body.Close()
|
| 143 |
+
|
| 144 |
+
body, err := ioutil.ReadAll(resp.Body)
|
| 145 |
+
if err != nil {
|
| 146 |
+
return "", err
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
var response createTaskResponse
|
| 150 |
+
if err := json.Unmarshal(body, &response); err != nil {
|
| 151 |
+
return "", err
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
if response.ErrorID != 0 {
|
| 155 |
+
return "", errors.New(response.ErrorDescription)
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
return response.TaskID, nil
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
func (c *Client) waitForResult(ctx context.Context, taskID string) (string, error) {
|
| 162 |
+
ticker := time.NewTicker(pollingInterval)
|
| 163 |
+
defer ticker.Stop()
|
| 164 |
+
|
| 165 |
+
for i := 0; i < maxRetries; i++ {
|
| 166 |
+
select {
|
| 167 |
+
case <-ctx.Done():
|
| 168 |
+
return "", ctx.Err()
|
| 169 |
+
case <-ticker.C:
|
| 170 |
+
result, err := c.getTaskResult(ctx, taskID)
|
| 171 |
+
if err != nil {
|
| 172 |
+
return "", err
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
if result.Status == "ready" {
|
| 176 |
+
return result.Solution.GRecaptchaResponse, nil
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
if result.ErrorID != 0 {
|
| 180 |
+
return "", errors.New(result.ErrorDescription)
|
| 181 |
+
}
|
| 182 |
+
}
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
return "", errors.New("timeout waiting for captcha solution")
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
func (c *Client) getTaskResult(ctx context.Context, taskID string) (*getResultResponse, error) {
|
| 189 |
+
request := getResultRequest{
|
| 190 |
+
ClientKey: c.clientKey,
|
| 191 |
+
TaskID: taskID,
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
jsonData, err := json.Marshal(request)
|
| 195 |
+
if err != nil {
|
| 196 |
+
return nil, err
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
httpReq, err := http.NewRequestWithContext(ctx, "POST", c.apiEndpoint+getResultPath, bytes.NewBuffer(jsonData))
|
| 200 |
+
if err != nil {
|
| 201 |
+
return nil, err
|
| 202 |
+
}
|
| 203 |
+
httpReq.Header.Set("Content-Type", "application/json")
|
| 204 |
+
|
| 205 |
+
resp, err := c.httpClient.Do(httpReq)
|
| 206 |
+
if err != nil {
|
| 207 |
+
return nil, err
|
| 208 |
+
}
|
| 209 |
+
defer resp.Body.Close()
|
| 210 |
+
|
| 211 |
+
body, err := ioutil.ReadAll(resp.Body)
|
| 212 |
+
if err != nil {
|
| 213 |
+
return nil, err
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
var response getResultResponse
|
| 217 |
+
if err := json.Unmarshal(body, &response); err != nil {
|
| 218 |
+
return nil, err
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
return &response, nil
|
| 222 |
+
}
|