init
This commit is contained in:
parent
2b92a6e07c
commit
85f8c54a91
9
.dockerignore
Normal file
9
.dockerignore
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
logs
|
||||||
|
dist
|
||||||
|
doc
|
||||||
|
node_modules
|
||||||
|
.vscode
|
||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
README.md
|
||||||
|
*.tar.gz
|
||||||
135
.gitignore
vendored
135
.gitignore
vendored
@ -1,132 +1,5 @@
|
|||||||
# ---> Node
|
dist/
|
||||||
# Logs
|
|
||||||
logs
|
|
||||||
*.log
|
|
||||||
npm-debug.log*
|
|
||||||
yarn-debug.log*
|
|
||||||
yarn-error.log*
|
|
||||||
lerna-debug.log*
|
|
||||||
.pnpm-debug.log*
|
|
||||||
|
|
||||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
|
||||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
|
||||||
|
|
||||||
# Runtime data
|
|
||||||
pids
|
|
||||||
*.pid
|
|
||||||
*.seed
|
|
||||||
*.pid.lock
|
|
||||||
|
|
||||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
|
||||||
lib-cov
|
|
||||||
|
|
||||||
# Coverage directory used by tools like istanbul
|
|
||||||
coverage
|
|
||||||
*.lcov
|
|
||||||
|
|
||||||
# nyc test coverage
|
|
||||||
.nyc_output
|
|
||||||
|
|
||||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
|
||||||
.grunt
|
|
||||||
|
|
||||||
# Bower dependency directory (https://bower.io/)
|
|
||||||
bower_components
|
|
||||||
|
|
||||||
# node-waf configuration
|
|
||||||
.lock-wscript
|
|
||||||
|
|
||||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
|
||||||
build/Release
|
|
||||||
|
|
||||||
# Dependency directories
|
|
||||||
node_modules/
|
node_modules/
|
||||||
jspm_packages/
|
logs/
|
||||||
|
.vercel
|
||||||
# Snowpack dependency directory (https://snowpack.dev/)
|
package-lock.json
|
||||||
web_modules/
|
|
||||||
|
|
||||||
# TypeScript cache
|
|
||||||
*.tsbuildinfo
|
|
||||||
|
|
||||||
# Optional npm cache directory
|
|
||||||
.npm
|
|
||||||
|
|
||||||
# Optional eslint cache
|
|
||||||
.eslintcache
|
|
||||||
|
|
||||||
# Optional stylelint cache
|
|
||||||
.stylelintcache
|
|
||||||
|
|
||||||
# Microbundle cache
|
|
||||||
.rpt2_cache/
|
|
||||||
.rts2_cache_cjs/
|
|
||||||
.rts2_cache_es/
|
|
||||||
.rts2_cache_umd/
|
|
||||||
|
|
||||||
# Optional REPL history
|
|
||||||
.node_repl_history
|
|
||||||
|
|
||||||
# Output of 'npm pack'
|
|
||||||
*.tgz
|
|
||||||
|
|
||||||
# Yarn Integrity file
|
|
||||||
.yarn-integrity
|
|
||||||
|
|
||||||
# dotenv environment variable files
|
|
||||||
.env
|
|
||||||
.env.development.local
|
|
||||||
.env.test.local
|
|
||||||
.env.production.local
|
|
||||||
.env.local
|
|
||||||
|
|
||||||
# parcel-bundler cache (https://parceljs.org/)
|
|
||||||
.cache
|
|
||||||
.parcel-cache
|
|
||||||
|
|
||||||
# Next.js build output
|
|
||||||
.next
|
|
||||||
out
|
|
||||||
|
|
||||||
# Nuxt.js build / generate output
|
|
||||||
.nuxt
|
|
||||||
dist
|
|
||||||
|
|
||||||
# Gatsby files
|
|
||||||
.cache/
|
|
||||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
|
||||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
|
||||||
# public
|
|
||||||
|
|
||||||
# vuepress build output
|
|
||||||
.vuepress/dist
|
|
||||||
|
|
||||||
# vuepress v2.x temp and cache directory
|
|
||||||
.temp
|
|
||||||
.cache
|
|
||||||
|
|
||||||
# Docusaurus cache and generated files
|
|
||||||
.docusaurus
|
|
||||||
|
|
||||||
# Serverless directories
|
|
||||||
.serverless/
|
|
||||||
|
|
||||||
# FuseBox cache
|
|
||||||
.fusebox/
|
|
||||||
|
|
||||||
# DynamoDB Local files
|
|
||||||
.dynamodb/
|
|
||||||
|
|
||||||
# TernJS port file
|
|
||||||
.tern-port
|
|
||||||
|
|
||||||
# Stores VSCode versions used for testing VSCode extensions
|
|
||||||
.vscode-test
|
|
||||||
|
|
||||||
# yarn v2
|
|
||||||
.yarn/cache
|
|
||||||
.yarn/unplugged
|
|
||||||
.yarn/build-state.yml
|
|
||||||
.yarn/install-state.gz
|
|
||||||
.pnp.*
|
|
||||||
|
|
||||||
21
Dockerfile
Normal file
21
Dockerfile
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
FROM node:20.19-slim AS BUILD_IMAGE
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY . /app
|
||||||
|
|
||||||
|
RUN yarn install --registry https://registry.npmmirror.com/ --ignore-engines && yarn run build
|
||||||
|
|
||||||
|
FROM node:20.19-slim
|
||||||
|
|
||||||
|
COPY --from=BUILD_IMAGE /app/configs /app/configs
|
||||||
|
COPY --from=BUILD_IMAGE /app/package.json /app/package.json
|
||||||
|
COPY --from=BUILD_IMAGE /app/dist /app/dist
|
||||||
|
COPY --from=BUILD_IMAGE /app/public /app/public
|
||||||
|
COPY --from=BUILD_IMAGE /app/node_modules /app/node_modules
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
EXPOSE 8000
|
||||||
|
|
||||||
|
CMD ["npm", "start"]
|
||||||
674
LICENSE
Normal file
674
LICENSE
Normal file
@ -0,0 +1,674 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||||
@ -1,3 +1,6 @@
|
|||||||
# jimeng-free-api
|
# jimeng-free-api
|
||||||
|
|
||||||
即梦api服务
|
即梦api服务
|
||||||
|
|
||||||
|
### 参考自
|
||||||
|
即梦接口转 API [kimi-free-api](https://github.com/LLM-Red-Team/jimeng-free-api)
|
||||||
6
configs/dev/service.yml
Normal file
6
configs/dev/service.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# 服务名称
|
||||||
|
name: jimeng-free-api
|
||||||
|
# 服务绑定主机地址
|
||||||
|
host: '0.0.0.0'
|
||||||
|
# 服务绑定端口
|
||||||
|
port: 3302
|
||||||
14
configs/dev/system.yml
Normal file
14
configs/dev/system.yml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# 是否开启请求日志
|
||||||
|
requestLog: true
|
||||||
|
# 临时目录路径
|
||||||
|
tmpDir: ./tmp
|
||||||
|
# 日志目录路径
|
||||||
|
logDir: ./logs
|
||||||
|
# 日志写入间隔(毫秒)
|
||||||
|
logWriteInterval: 200
|
||||||
|
# 日志文件有效期(毫秒)
|
||||||
|
logFileExpires: 2626560000
|
||||||
|
# 公共目录路径
|
||||||
|
publicDir: ./public
|
||||||
|
# 临时文件有效期(毫秒)
|
||||||
|
tmpFileExpires: 86400000
|
||||||
BIN
doc/example-0.png
Normal file
BIN
doc/example-0.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 448 KiB |
BIN
doc/example-1.jpeg
Normal file
BIN
doc/example-1.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 308 KiB |
51
package.json
Normal file
51
package.json
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
{
|
||||||
|
"name": "jimeng-free-api",
|
||||||
|
"version": "0.0.6",
|
||||||
|
"description": "jimeng Free API Server",
|
||||||
|
"type": "module",
|
||||||
|
"main": "dist/index.js",
|
||||||
|
"module": "dist/index.mjs",
|
||||||
|
"types": "dist/index.d.ts",
|
||||||
|
"directories": {
|
||||||
|
"dist": "dist"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"dist/"
|
||||||
|
],
|
||||||
|
"scripts": {
|
||||||
|
"dev": "tsup src/index.ts --format cjs,esm --sourcemap --dts --publicDir public --watch --onSuccess \"node --enable-source-maps --no-node-snapshot dist/index.js\"",
|
||||||
|
"start": "node --enable-source-maps --no-node-snapshot dist/index.js",
|
||||||
|
"build": "tsup src/index.ts --format cjs,esm --sourcemap --dts --clean --publicDir public"
|
||||||
|
},
|
||||||
|
"author": "Vinlic",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"axios": "^1.6.7",
|
||||||
|
"colors": "^1.4.0",
|
||||||
|
"crc-32": "^1.2.2",
|
||||||
|
"cron": "^3.1.6",
|
||||||
|
"date-fns": "^3.3.1",
|
||||||
|
"eventsource-parser": "^1.1.2",
|
||||||
|
"form-data": "^4.0.0",
|
||||||
|
"fs-extra": "^11.2.0",
|
||||||
|
"image-size": "^2.0.2",
|
||||||
|
"koa": "^2.15.0",
|
||||||
|
"koa-body": "^5.0.0",
|
||||||
|
"koa-bodyparser": "^4.4.1",
|
||||||
|
"koa-range": "^0.3.0",
|
||||||
|
"koa-router": "^12.0.1",
|
||||||
|
"koa2-cors": "^2.0.6",
|
||||||
|
"lodash": "^4.17.21",
|
||||||
|
"mime": "^4.0.1",
|
||||||
|
"minimist": "^1.2.8",
|
||||||
|
"randomstring": "^1.3.0",
|
||||||
|
"uuid": "^9.0.1",
|
||||||
|
"yaml": "^2.3.4"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/lodash": "^4.14.202",
|
||||||
|
"@types/mime": "^3.0.4",
|
||||||
|
"tsup": "^8.0.2",
|
||||||
|
"typescript": "^5.3.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
10
public/welcome.html
Normal file
10
public/welcome.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<title>🚀 服务已启动</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>jimeng-free-api已启动!<br>请通过LobeChat / NextChat / Dify等客户端或OpenAI SDK接入!</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
14
src/api/consts/exceptions.ts
Normal file
14
src/api/consts/exceptions.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
export default {
|
||||||
|
API_TEST: [-9999, 'API异常错误'],
|
||||||
|
API_REQUEST_PARAMS_INVALID: [-2000, '请求参数非法'],
|
||||||
|
API_REQUEST_FAILED: [-2001, '请求失败'],
|
||||||
|
API_TOKEN_EXPIRES: [-2002, 'Token已失效'],
|
||||||
|
API_FILE_URL_INVALID: [-2003, '远程文件URL非法'],
|
||||||
|
API_FILE_EXECEEDS_SIZE: [-2004, '远程文件超出大小'],
|
||||||
|
API_CHAT_STREAM_PUSHING: [-2005, '已有对话流正在输出'],
|
||||||
|
API_CONTENT_FILTERED: [-2006, '内容由于合规问题已被阻止生成'],
|
||||||
|
API_IMAGE_GENERATION_FAILED: [-2007, '图像生成失败'],
|
||||||
|
API_VIDEO_GENERATION_FAILED: [-2008, '视频生成失败'],
|
||||||
|
API_IMAGE_GENERATION_INSUFFICIENT_POINTS: [-2009, '即梦积分不足'],
|
||||||
|
API_IMAGE_URL: [-2010, '即梦积分不足'],
|
||||||
|
}
|
||||||
227
src/api/controllers/chat.ts
Normal file
227
src/api/controllers/chat.ts
Normal file
@ -0,0 +1,227 @@
|
|||||||
|
import _ from "lodash";
|
||||||
|
import { PassThrough } from "stream";
|
||||||
|
|
||||||
|
import APIException from "@/lib/exceptions/APIException.ts";
|
||||||
|
import EX from "@/api/consts/exceptions.ts";
|
||||||
|
import logger from "@/lib/logger.ts";
|
||||||
|
import util from "@/lib/util.ts";
|
||||||
|
import { generateImages, DEFAULT_MODEL } from "./images.ts";
|
||||||
|
|
||||||
|
// 最大重试次数
|
||||||
|
const MAX_RETRY_COUNT = 3;
|
||||||
|
// 重试延迟
|
||||||
|
const RETRY_DELAY = 5000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析模型
|
||||||
|
*
|
||||||
|
* @param model 模型名称
|
||||||
|
* @returns 模型信息
|
||||||
|
*/
|
||||||
|
function parseModel(model: string) {
|
||||||
|
const [_model, size] = model.split(":");
|
||||||
|
const [_, width, height] = /(\d+)[\W\w](\d+)/.exec(size) ?? [];
|
||||||
|
return {
|
||||||
|
model: _model,
|
||||||
|
width: size ? Math.ceil(parseInt(width) / 2) * 2 : 1024,
|
||||||
|
height: size ? Math.ceil(parseInt(height) / 2) * 2 : 1024,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步对话补全
|
||||||
|
*
|
||||||
|
* @param messages 参考gpt系列消息格式,多轮对话请完整提供上下文
|
||||||
|
* @param refreshToken 用于刷新access_token的refresh_token
|
||||||
|
* @param assistantId 智能体ID,默认使用jimeng原版
|
||||||
|
* @param retryCount 重试次数
|
||||||
|
*/
|
||||||
|
export async function createCompletion(
|
||||||
|
messages: any[],
|
||||||
|
refreshToken: string,
|
||||||
|
_model = DEFAULT_MODEL,
|
||||||
|
retryCount = 0
|
||||||
|
) {
|
||||||
|
return (async () => {
|
||||||
|
if (messages.length === 0)
|
||||||
|
throw new APIException(EX.API_REQUEST_PARAMS_INVALID, "消息不能为空");
|
||||||
|
|
||||||
|
const { model, width, height } = parseModel(_model);
|
||||||
|
logger.info(messages);
|
||||||
|
|
||||||
|
const imageUrls = await generateImages(
|
||||||
|
model,
|
||||||
|
messages[messages.length - 1].content,
|
||||||
|
{
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
},
|
||||||
|
refreshToken
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: util.uuid(),
|
||||||
|
model: _model || model,
|
||||||
|
object: "chat.completion",
|
||||||
|
choices: [
|
||||||
|
{
|
||||||
|
index: 0,
|
||||||
|
message: {
|
||||||
|
role: "assistant",
|
||||||
|
content: imageUrls.reduce(
|
||||||
|
(acc, url, i) => acc + `\n`,
|
||||||
|
""
|
||||||
|
),
|
||||||
|
},
|
||||||
|
finish_reason: "stop",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 },
|
||||||
|
created: util.unixTimestamp(),
|
||||||
|
};
|
||||||
|
})().catch((err) => {
|
||||||
|
if (retryCount < MAX_RETRY_COUNT) {
|
||||||
|
logger.error(`Response error: ${err.stack}`);
|
||||||
|
logger.warn(`Try again after ${RETRY_DELAY / 1000}s...`);
|
||||||
|
return (async () => {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY));
|
||||||
|
return createCompletion(messages, refreshToken, _model, retryCount + 1);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流式对话补全
|
||||||
|
*
|
||||||
|
* @param messages 参考gpt系列消息格式,多轮对话请完整提供上下文
|
||||||
|
* @param refreshToken 用于刷新access_token的refresh_token
|
||||||
|
* @param assistantId 智能体ID,默认使用jimeng原版
|
||||||
|
* @param retryCount 重试次数
|
||||||
|
*/
|
||||||
|
export async function createCompletionStream(
|
||||||
|
messages: any[],
|
||||||
|
refreshToken: string,
|
||||||
|
_model = DEFAULT_MODEL,
|
||||||
|
retryCount = 0
|
||||||
|
) {
|
||||||
|
return (async () => {
|
||||||
|
const { model, width, height } = parseModel(_model);
|
||||||
|
logger.info(messages);
|
||||||
|
|
||||||
|
const stream = new PassThrough();
|
||||||
|
|
||||||
|
if (messages.length === 0) {
|
||||||
|
logger.warn("消息为空,返回空流");
|
||||||
|
stream.end("data: [DONE]\n\n");
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
stream.write(
|
||||||
|
"data: " +
|
||||||
|
JSON.stringify({
|
||||||
|
id: util.uuid(),
|
||||||
|
model: _model || model,
|
||||||
|
object: "chat.completion.chunk",
|
||||||
|
choices: [
|
||||||
|
{
|
||||||
|
index: 0,
|
||||||
|
delta: { role: "assistant", content: "🎨 图像生成中,请稍候..." },
|
||||||
|
finish_reason: null,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}) +
|
||||||
|
"\n\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
generateImages(
|
||||||
|
model,
|
||||||
|
messages[messages.length - 1].content,
|
||||||
|
{ width, height },
|
||||||
|
refreshToken
|
||||||
|
)
|
||||||
|
.then((imageUrls) => {
|
||||||
|
for (let i = 0; i < imageUrls.length; i++) {
|
||||||
|
const url = imageUrls[i];
|
||||||
|
stream.write(
|
||||||
|
"data: " +
|
||||||
|
JSON.stringify({
|
||||||
|
id: util.uuid(),
|
||||||
|
model: _model || model,
|
||||||
|
object: "chat.completion.chunk",
|
||||||
|
choices: [
|
||||||
|
{
|
||||||
|
index: i + 1,
|
||||||
|
delta: {
|
||||||
|
role: "assistant",
|
||||||
|
content: `\n`,
|
||||||
|
},
|
||||||
|
finish_reason: i < imageUrls.length - 1 ? null : "stop",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}) +
|
||||||
|
"\n\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
stream.write(
|
||||||
|
"data: " +
|
||||||
|
JSON.stringify({
|
||||||
|
id: util.uuid(),
|
||||||
|
model: _model || model,
|
||||||
|
object: "chat.completion.chunk",
|
||||||
|
choices: [
|
||||||
|
{
|
||||||
|
index: imageUrls.length + 1,
|
||||||
|
delta: {
|
||||||
|
role: "assistant",
|
||||||
|
content: "图像生成完成!",
|
||||||
|
},
|
||||||
|
finish_reason: "stop",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}) +
|
||||||
|
"\n\n"
|
||||||
|
);
|
||||||
|
stream.end("data: [DONE]\n\n");
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
stream.write(
|
||||||
|
"data: " +
|
||||||
|
JSON.stringify({
|
||||||
|
id: util.uuid(),
|
||||||
|
model: _model || model,
|
||||||
|
object: "chat.completion.chunk",
|
||||||
|
choices: [
|
||||||
|
{
|
||||||
|
index: 1,
|
||||||
|
delta: {
|
||||||
|
role: "assistant",
|
||||||
|
content: `生成图片失败: ${err.message}`,
|
||||||
|
},
|
||||||
|
finish_reason: "stop",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}) +
|
||||||
|
"\n\n"
|
||||||
|
);
|
||||||
|
stream.end("data: [DONE]\n\n");
|
||||||
|
});
|
||||||
|
return stream;
|
||||||
|
})().catch((err) => {
|
||||||
|
if (retryCount < MAX_RETRY_COUNT) {
|
||||||
|
logger.error(`Response error: ${err.stack}`);
|
||||||
|
logger.warn(`Try again after ${RETRY_DELAY / 1000}s...`);
|
||||||
|
return (async () => {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY));
|
||||||
|
return createCompletionStream(
|
||||||
|
messages,
|
||||||
|
refreshToken,
|
||||||
|
_model,
|
||||||
|
retryCount + 1
|
||||||
|
);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
}
|
||||||
292
src/api/controllers/core.ts
Normal file
292
src/api/controllers/core.ts
Normal file
@ -0,0 +1,292 @@
|
|||||||
|
import { PassThrough } from "stream";
|
||||||
|
import path from "path";
|
||||||
|
import _ from "lodash";
|
||||||
|
import mime from "mime";
|
||||||
|
import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
|
||||||
|
|
||||||
|
import APIException from "@/lib/exceptions/APIException.ts";
|
||||||
|
import EX from "@/api/consts/exceptions.ts";
|
||||||
|
import { createParser } from "eventsource-parser";
|
||||||
|
import logger from "@/lib/logger.ts";
|
||||||
|
import util from "@/lib/util.ts";
|
||||||
|
|
||||||
|
// 模型名称
|
||||||
|
const MODEL_NAME = "jimeng";
|
||||||
|
// 默认的AgentID
|
||||||
|
const DEFAULT_ASSISTANT_ID = "513695";
|
||||||
|
// 版本号
|
||||||
|
const VERSION_CODE = "5.8.0";
|
||||||
|
// 平台代码
|
||||||
|
const PLATFORM_CODE = "7";
|
||||||
|
// 设备ID
|
||||||
|
const DEVICE_ID = Math.random() * 999999999999999999 + 7000000000000000000;
|
||||||
|
// WebID
|
||||||
|
const WEB_ID = Math.random() * 999999999999999999 + 7000000000000000000;
|
||||||
|
// 用户ID
|
||||||
|
const USER_ID = util.uuid(false);
|
||||||
|
// 最大重试次数
|
||||||
|
const MAX_RETRY_COUNT = 3;
|
||||||
|
// 重试延迟
|
||||||
|
const RETRY_DELAY = 5000;
|
||||||
|
// 伪装headers
|
||||||
|
const FAKE_HEADERS = {
|
||||||
|
Accept: "application/json, text/plain, */*",
|
||||||
|
"Accept-Encoding": "gzip, deflate, br, zstd",
|
||||||
|
"Accept-language": "zh-CN,zh;q=0.9",
|
||||||
|
"Cache-control": "no-cache",
|
||||||
|
"Last-event-id": "undefined",
|
||||||
|
Appid: DEFAULT_ASSISTANT_ID,
|
||||||
|
Appvr: VERSION_CODE,
|
||||||
|
Origin: "https://jimeng.jianying.com",
|
||||||
|
Pragma: "no-cache",
|
||||||
|
Priority: "u=1, i",
|
||||||
|
Referer: "https://jimeng.jianying.com",
|
||||||
|
Pf: PLATFORM_CODE,
|
||||||
|
"Sec-Ch-Ua":
|
||||||
|
'"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
|
||||||
|
"Sec-Ch-Ua-Mobile": "?0",
|
||||||
|
"Sec-Ch-Ua-Platform": '"Windows"',
|
||||||
|
"Sec-Fetch-Dest": "empty",
|
||||||
|
"Sec-Fetch-Mode": "cors",
|
||||||
|
"Sec-Fetch-Site": "same-origin",
|
||||||
|
"User-Agent":
|
||||||
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
|
||||||
|
};
|
||||||
|
// 文件最大大小
|
||||||
|
const FILE_MAX_SIZE = 100 * 1024 * 1024;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取缓存中的access_token
|
||||||
|
*
|
||||||
|
* 目前jimeng的access_token是固定的,暂无刷新功能
|
||||||
|
*
|
||||||
|
* @param refreshToken 用于刷新access_token的refresh_token
|
||||||
|
*/
|
||||||
|
export async function acquireToken(refreshToken: string): Promise<string> {
|
||||||
|
return refreshToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成cookie
|
||||||
|
*/
|
||||||
|
export function generateCookie(refreshToken: string) {
|
||||||
|
return [
|
||||||
|
`_tea_web_id=${WEB_ID}`,
|
||||||
|
`is_staff_user=false`,
|
||||||
|
`store-region=cn-gd`,
|
||||||
|
`store-region-src=uid`,
|
||||||
|
`sid_guard=${refreshToken}%7C${util.unixTimestamp()}%7C5184000%7CMon%2C+03-Feb-2025+08%3A17%3A09+GMT`,
|
||||||
|
`uid_tt=${USER_ID}`,
|
||||||
|
`uid_tt_ss=${USER_ID}`,
|
||||||
|
`sid_tt=${refreshToken}`,
|
||||||
|
`sessionid=${refreshToken}`,
|
||||||
|
`sessionid_ss=${refreshToken}`,
|
||||||
|
`sid_tt=${refreshToken}`
|
||||||
|
].join("; ");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取积分信息
|
||||||
|
*
|
||||||
|
* @param refreshToken 用于刷新access_token的refresh_token
|
||||||
|
*/
|
||||||
|
export async function getCredit(refreshToken: string) {
|
||||||
|
const {
|
||||||
|
credit: { gift_credit, purchase_credit, vip_credit }
|
||||||
|
} = await request("POST", "/commerce/v1/benefits/user_credit", refreshToken, {
|
||||||
|
data: {},
|
||||||
|
headers: {
|
||||||
|
// Cookie: 'x-web-secsdk-uid=ef44bd0d-0cf6-448c-b517-fd1b5a7267ba; s_v_web_id=verify_m4b1lhlu_DI8qKRlD_7mJJ_4eqx_9shQ_s8eS2QLAbc4n; passport_csrf_token=86f3619c0c4a9c13f24117f71dc18524; passport_csrf_token_default=86f3619c0c4a9c13f24117f71dc18524; n_mh=9-mIeuD4wZnlYrrOvfzG3MuT6aQmCUtmr8FxV8Kl8xY; sid_guard=a7eb745aec44bb3186dbc2083ea9e1a6%7C1733386629%7C5184000%7CMon%2C+03-Feb-2025+08%3A17%3A09+GMT; uid_tt=59a46c7d3f34bda9588b93590cca2e12; uid_tt_ss=59a46c7d3f34bda9588b93590cca2e12; sid_tt=a7eb745aec44bb3186dbc2083ea9e1a6; sessionid=a7eb745aec44bb3186dbc2083ea9e1a6; sessionid_ss=a7eb745aec44bb3186dbc2083ea9e1a6; is_staff_user=false; sid_ucp_v1=1.0.0-KGRiOGY2ODQyNWU1OTk3NzRhYTE2ZmZhYmFjNjdmYjY3NzRmZGRiZTgKHgjToPCw0cwbEIXDxboGGJ-tHyAMMITDxboGOAhAJhoCaGwiIGE3ZWI3NDVhZWM0NGJiMzE4NmRiYzIwODNlYTllMWE2; ssid_ucp_v1=1.0.0-KGRiOGY2ODQyNWU1OTk3NzRhYTE2ZmZhYmFjNjdmYjY3NzRmZGRiZTgKHgjToPCw0cwbEIXDxboGGJ-tHyAMMITDxboGOAhAJhoCaGwiIGE3ZWI3NDVhZWM0NGJiMzE4NmRiYzIwODNlYTllMWE2; store-region=cn-gd; store-region-src=uid; user_spaces_idc={"7444764277623653426":"lf"}; ttwid=1|cxHJViEev1mfkjntdMziir8SwbU8uPNVSaeh9QpEUs8|1733966961|d8d52f5f56607427691be4ac44253f7870a34d25dd05a01b4d89b8a7c5ea82ad; _tea_web_id=7444838473275573797; fpk1=fa6c6a4d9ba074b90003896f36b6960066521c1faec6a60bdcb69ec8ddf85e8360b4c0704412848ec582b2abca73d57a; odin_tt=efe9dc150207879b88509e651a1c4af4e7ffb4cfcb522425a75bd72fbf894eda570bbf7ffb551c8b1de0aa2bfa0bd1be6c4157411ecdcf4464fcaf8dd6657d66',
|
||||||
|
Referer: "https://jimeng.jianying.com/ai-tool/image/generate",
|
||||||
|
// "Device-Time": 1733966964,
|
||||||
|
// Sign: "f3dbb824b378abea7c03cbb152b3a365"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
logger.info(`\n积分信息: \n赠送积分: ${gift_credit}, 购买积分: ${purchase_credit}, VIP积分: ${vip_credit}`);
|
||||||
|
return {
|
||||||
|
giftCredit: gift_credit,
|
||||||
|
purchaseCredit: purchase_credit,
|
||||||
|
vipCredit: vip_credit,
|
||||||
|
totalCredit: gift_credit + purchase_credit + vip_credit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接收今日积分
|
||||||
|
*
|
||||||
|
* @param refreshToken 用于刷新access_token的refresh_token
|
||||||
|
*/
|
||||||
|
export async function receiveCredit(refreshToken: string) {
|
||||||
|
logger.info("正在收取今日积分...")
|
||||||
|
const { cur_total_credits, receive_quota } = await request("POST", "/commerce/v1/benefits/credit_receive", refreshToken, {
|
||||||
|
data: {
|
||||||
|
time_zone: "Asia/Shanghai"
|
||||||
|
},
|
||||||
|
headers: {
|
||||||
|
Referer: "https://jimeng.jianying.com/ai-tool/image/generate"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
logger.info(`\n今日${receive_quota}积分收取成功\n剩余积分: ${cur_total_credits}`);
|
||||||
|
return cur_total_credits;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求jimeng
|
||||||
|
*
|
||||||
|
* @param method 请求方法
|
||||||
|
* @param uri 请求路径
|
||||||
|
* @param params 请求参数
|
||||||
|
* @param headers 请求头
|
||||||
|
*/
|
||||||
|
export async function request(
|
||||||
|
method: string,
|
||||||
|
uri: string,
|
||||||
|
refreshToken: string,
|
||||||
|
options: AxiosRequestConfig = {},
|
||||||
|
host: string= "",
|
||||||
|
region: string= "",
|
||||||
|
) {
|
||||||
|
const token = await acquireToken(refreshToken);
|
||||||
|
const deviceTime = util.unixTimestamp();
|
||||||
|
const sign = util.md5(
|
||||||
|
`9e2c|${uri.slice(-7)}|${PLATFORM_CODE}|${VERSION_CODE}|${deviceTime}||11ac`
|
||||||
|
);
|
||||||
|
const response = await axios.request({
|
||||||
|
method,
|
||||||
|
url: `${host||'https://jimeng.jianying.com'}${uri}`,
|
||||||
|
params: {
|
||||||
|
aid: DEFAULT_ASSISTANT_ID,
|
||||||
|
device_platform: "web",
|
||||||
|
region: region||"CN",
|
||||||
|
web_id: WEB_ID,
|
||||||
|
...(options.params || {}),
|
||||||
|
},
|
||||||
|
headers: {
|
||||||
|
...FAKE_HEADERS,
|
||||||
|
Cookie: generateCookie(token),
|
||||||
|
"Device-Time": deviceTime,
|
||||||
|
Sign: sign,
|
||||||
|
"Sign-Ver": "1",
|
||||||
|
...(options.headers || {}),
|
||||||
|
},
|
||||||
|
timeout: 15000,
|
||||||
|
validateStatus: () => true,
|
||||||
|
..._.omit(options, "params", "headers"),
|
||||||
|
});
|
||||||
|
// 流式响应直接返回response
|
||||||
|
if (options.responseType == "stream") return response;
|
||||||
|
return checkResult(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 预检查文件URL有效性
|
||||||
|
*
|
||||||
|
* @param fileUrl 文件URL
|
||||||
|
*/
|
||||||
|
export async function checkFileUrl(fileUrl: string) {
|
||||||
|
if (util.isBASE64Data(fileUrl)) return;
|
||||||
|
const result = await axios.head(fileUrl, {
|
||||||
|
timeout: 15000,
|
||||||
|
validateStatus: () => true,
|
||||||
|
});
|
||||||
|
if (result.status >= 400)
|
||||||
|
throw new APIException(
|
||||||
|
EX.API_FILE_URL_INVALID,
|
||||||
|
`File ${fileUrl} is not valid: [${result.status}] ${result.statusText}`
|
||||||
|
);
|
||||||
|
// 检查文件大小
|
||||||
|
if (result.headers && result.headers["content-length"]) {
|
||||||
|
const fileSize = parseInt(result.headers["content-length"], 10);
|
||||||
|
if (fileSize > FILE_MAX_SIZE)
|
||||||
|
throw new APIException(
|
||||||
|
EX.API_FILE_EXECEEDS_SIZE,
|
||||||
|
`File ${fileUrl} is not valid`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传文件
|
||||||
|
*
|
||||||
|
* @param fileUrl 文件URL
|
||||||
|
* @param refreshToken 用于刷新access_token的refresh_token
|
||||||
|
* @param isVideoImage 是否是用于视频图像
|
||||||
|
*/
|
||||||
|
export async function uploadFile(
|
||||||
|
fileUrl: string,
|
||||||
|
refreshToken: string,
|
||||||
|
isVideoImage: boolean = false
|
||||||
|
) {
|
||||||
|
// 预检查远程文件URL可用性
|
||||||
|
await checkFileUrl(fileUrl);
|
||||||
|
|
||||||
|
let filename, fileData, mimeType;
|
||||||
|
// 如果是BASE64数据则直接转换为Buffer
|
||||||
|
if (util.isBASE64Data(fileUrl)) {
|
||||||
|
mimeType = util.extractBASE64DataFormat(fileUrl);
|
||||||
|
const ext = mime.getExtension(mimeType);
|
||||||
|
filename = `${util.uuid()}.${ext}`;
|
||||||
|
fileData = Buffer.from(util.removeBASE64DataHeader(fileUrl), "base64");
|
||||||
|
}
|
||||||
|
// 下载文件到内存,如果您的服务器内存很小,建议考虑改造为流直传到下一个接口上,避免停留占用内存
|
||||||
|
else {
|
||||||
|
filename = path.basename(fileUrl);
|
||||||
|
({ data: fileData } = await axios.get(fileUrl, {
|
||||||
|
responseType: "arraybuffer",
|
||||||
|
// 100M限制
|
||||||
|
maxContentLength: FILE_MAX_SIZE,
|
||||||
|
// 60秒超时
|
||||||
|
timeout: 60000,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取文件的MIME类型
|
||||||
|
mimeType = mimeType || mime.getType(filename);
|
||||||
|
|
||||||
|
// 待开发
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查请求结果
|
||||||
|
*
|
||||||
|
* @param result 结果
|
||||||
|
*/
|
||||||
|
export function checkResult(result: AxiosResponse) {
|
||||||
|
const { ret, errmsg, data } = result.data;
|
||||||
|
if (!_.isFinite(Number(ret))) return result.data;
|
||||||
|
if (ret === '0') return data;
|
||||||
|
if (ret === '5000')
|
||||||
|
throw new APIException(EX.API_IMAGE_GENERATION_INSUFFICIENT_POINTS, `[无法生成图像]: 即梦积分可能不足,${errmsg}`);
|
||||||
|
throw new APIException(EX.API_REQUEST_FAILED, `[请求jimeng失败]: ${errmsg}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Token切分
|
||||||
|
*
|
||||||
|
* @param authorization 认证字符串
|
||||||
|
*/
|
||||||
|
export function tokenSplit(authorization: string) {
|
||||||
|
return authorization.replace("Bearer ", "").split(",");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取Token存活状态
|
||||||
|
*/
|
||||||
|
export async function getTokenLiveStatus(refreshToken: string) {
|
||||||
|
const result = await request(
|
||||||
|
"POST",
|
||||||
|
"/passport/account/info/v2",
|
||||||
|
refreshToken,
|
||||||
|
{
|
||||||
|
params: {
|
||||||
|
account_sdk_source: "web",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
const { user_id } = checkResult(result);
|
||||||
|
return !!user_id;
|
||||||
|
} catch (err) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
484
src/api/controllers/images.ts
Normal file
484
src/api/controllers/images.ts
Normal file
@ -0,0 +1,484 @@
|
|||||||
|
import _ from "lodash";
|
||||||
|
|
||||||
|
import APIException from "@/lib/exceptions/APIException.ts";
|
||||||
|
import EX from "@/api/consts/exceptions.ts";
|
||||||
|
import util from "@/lib/util.ts";
|
||||||
|
import { getCredit, receiveCredit, request } from "./core.ts";
|
||||||
|
import logger from "@/lib/logger.ts";
|
||||||
|
|
||||||
|
const DEFAULT_ASSISTANT_ID = "513695";
|
||||||
|
export const DEFAULT_MODEL = "jimeng-3.0";
|
||||||
|
const DRAFT_VERSION = "3.0.2";
|
||||||
|
const MODEL_MAP = {
|
||||||
|
"jimeng-3.0": "high_aes_general_v30l:general_v3.0_18b",
|
||||||
|
"jimeng-2.1": "high_aes_general_v21_L:general_v2.1_L",
|
||||||
|
"jimeng-2.0-pro": "high_aes_general_v20_L:general_v2.0_L",
|
||||||
|
"jimeng-2.0": "high_aes_general_v20:general_v2.0",
|
||||||
|
"jimeng-1.4": "high_aes_general_v14:general_v1.4",
|
||||||
|
"jimeng-xl-pro": "text2img_xl_sft",
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getModel(model: string) {
|
||||||
|
return MODEL_MAP[model] || MODEL_MAP[DEFAULT_MODEL];
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function generateImages(
|
||||||
|
_model: string,
|
||||||
|
prompt: string,
|
||||||
|
{
|
||||||
|
width = 1024,
|
||||||
|
height = 1024,
|
||||||
|
sampleStrength = 0.5,
|
||||||
|
negativePrompt = "",
|
||||||
|
}: {
|
||||||
|
width?: number;
|
||||||
|
height?: number;
|
||||||
|
sampleStrength?: number;
|
||||||
|
negativePrompt?: string;
|
||||||
|
},
|
||||||
|
refreshToken: string
|
||||||
|
) {
|
||||||
|
const model = getModel(_model);
|
||||||
|
logger.info(`使用模型: ${_model} 映射模型: ${model} ${width}x${height} 精细度: ${sampleStrength}`);
|
||||||
|
|
||||||
|
const { totalCredit } = await getCredit(refreshToken);
|
||||||
|
if (totalCredit <= 0)
|
||||||
|
await receiveCredit(refreshToken);
|
||||||
|
|
||||||
|
const componentId = util.uuid();
|
||||||
|
const { aigc_data } = await request(
|
||||||
|
"post",
|
||||||
|
"/mweb/v1/aigc_draft/generate",
|
||||||
|
refreshToken,
|
||||||
|
{
|
||||||
|
params: {
|
||||||
|
babi_param: encodeURIComponent(
|
||||||
|
JSON.stringify({
|
||||||
|
scenario: "image_video_generation",
|
||||||
|
feature_key: "aigc_to_image",
|
||||||
|
feature_entrance: "to_image",
|
||||||
|
feature_entrance_detail: "to_image-" + model,
|
||||||
|
})
|
||||||
|
),
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
extend: {
|
||||||
|
root_model: model,
|
||||||
|
template_id: "",
|
||||||
|
},
|
||||||
|
submit_id: util.uuid(),
|
||||||
|
metrics_extra: JSON.stringify({
|
||||||
|
templateId: "",
|
||||||
|
generateCount: 1,
|
||||||
|
promptSource: "custom",
|
||||||
|
templateSource: "",
|
||||||
|
lastRequestId: "",
|
||||||
|
originRequestId: "",
|
||||||
|
}),
|
||||||
|
draft_content: JSON.stringify({
|
||||||
|
type: "draft",
|
||||||
|
id: util.uuid(),
|
||||||
|
min_version: DRAFT_VERSION,
|
||||||
|
is_from_tsn: true,
|
||||||
|
version: DRAFT_VERSION,
|
||||||
|
main_component_id: componentId,
|
||||||
|
component_list: [
|
||||||
|
{
|
||||||
|
type: "image_base_component",
|
||||||
|
id: componentId,
|
||||||
|
min_version: DRAFT_VERSION,
|
||||||
|
generate_type: "generate",
|
||||||
|
aigc_mode: "workbench",
|
||||||
|
abilities: {
|
||||||
|
type: "",
|
||||||
|
id: util.uuid(),
|
||||||
|
generate: {
|
||||||
|
type: "",
|
||||||
|
id: util.uuid(),
|
||||||
|
core_param: {
|
||||||
|
type: "",
|
||||||
|
id: util.uuid(),
|
||||||
|
model,
|
||||||
|
prompt,
|
||||||
|
negative_prompt: negativePrompt,
|
||||||
|
seed: Math.floor(Math.random() * 100000000) + 2500000000,
|
||||||
|
sample_strength: sampleStrength,
|
||||||
|
image_ratio: 1,
|
||||||
|
large_image_info: {
|
||||||
|
type: "",
|
||||||
|
id: util.uuid(),
|
||||||
|
height,
|
||||||
|
width,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
history_option: {
|
||||||
|
type: "",
|
||||||
|
id: util.uuid(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
http_common_info: {
|
||||||
|
aid: Number(DEFAULT_ASSISTANT_ID),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const historyId = aigc_data.history_record_id;
|
||||||
|
if (!historyId)
|
||||||
|
throw new APIException(EX.API_IMAGE_GENERATION_FAILED, "记录ID不存在");
|
||||||
|
let status = 20, failCode, item_list = [];
|
||||||
|
while (status === 20) {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||||
|
const result = await request("post", "/mweb/v1/get_history_by_ids", refreshToken, {
|
||||||
|
data: {
|
||||||
|
history_ids: [historyId],
|
||||||
|
image_info: {
|
||||||
|
width: 2048,
|
||||||
|
height: 2048,
|
||||||
|
format: "webp",
|
||||||
|
image_scene_list: [
|
||||||
|
{
|
||||||
|
scene: "smart_crop",
|
||||||
|
width: 360,
|
||||||
|
height: 360,
|
||||||
|
uniq_key: "smart_crop-w:360-h:360",
|
||||||
|
format: "webp",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scene: "smart_crop",
|
||||||
|
width: 480,
|
||||||
|
height: 480,
|
||||||
|
uniq_key: "smart_crop-w:480-h:480",
|
||||||
|
format: "webp",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scene: "smart_crop",
|
||||||
|
width: 720,
|
||||||
|
height: 720,
|
||||||
|
uniq_key: "smart_crop-w:720-h:720",
|
||||||
|
format: "webp",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scene: "smart_crop",
|
||||||
|
width: 720,
|
||||||
|
height: 480,
|
||||||
|
uniq_key: "smart_crop-w:720-h:480",
|
||||||
|
format: "webp",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scene: "smart_crop",
|
||||||
|
width: 360,
|
||||||
|
height: 240,
|
||||||
|
uniq_key: "smart_crop-w:360-h:240",
|
||||||
|
format: "webp",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scene: "smart_crop",
|
||||||
|
width: 240,
|
||||||
|
height: 320,
|
||||||
|
uniq_key: "smart_crop-w:240-h:320",
|
||||||
|
format: "webp",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scene: "smart_crop",
|
||||||
|
width: 480,
|
||||||
|
height: 640,
|
||||||
|
uniq_key: "smart_crop-w:480-h:640",
|
||||||
|
format: "webp",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scene: "normal",
|
||||||
|
width: 2400,
|
||||||
|
height: 2400,
|
||||||
|
uniq_key: "2400",
|
||||||
|
format: "webp",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scene: "normal",
|
||||||
|
width: 1080,
|
||||||
|
height: 1080,
|
||||||
|
uniq_key: "1080",
|
||||||
|
format: "webp",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scene: "normal",
|
||||||
|
width: 720,
|
||||||
|
height: 720,
|
||||||
|
uniq_key: "720",
|
||||||
|
format: "webp",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scene: "normal",
|
||||||
|
width: 480,
|
||||||
|
height: 480,
|
||||||
|
uniq_key: "480",
|
||||||
|
format: "webp",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scene: "normal",
|
||||||
|
width: 360,
|
||||||
|
height: 360,
|
||||||
|
uniq_key: "360",
|
||||||
|
format: "webp",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
http_common_info: {
|
||||||
|
aid: Number(DEFAULT_ASSISTANT_ID),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!result[historyId])
|
||||||
|
throw new APIException(EX.API_IMAGE_GENERATION_FAILED, "记录不存在");
|
||||||
|
status = result[historyId].status;
|
||||||
|
failCode = result[historyId].fail_code;
|
||||||
|
item_list = result[historyId].item_list;
|
||||||
|
}
|
||||||
|
if (status === 30) {
|
||||||
|
if (failCode === '2038')
|
||||||
|
throw new APIException(EX.API_CONTENT_FILTERED);
|
||||||
|
else
|
||||||
|
throw new APIException(EX.API_IMAGE_GENERATION_FAILED);
|
||||||
|
}
|
||||||
|
return item_list.map((item) => {
|
||||||
|
if(!item?.image?.large_images?.[0]?.image_url)
|
||||||
|
return item?.common_attr?.cover_url || null;
|
||||||
|
return item.image.large_images[0].image_url;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function uploadImages(
|
||||||
|
_model: string,
|
||||||
|
prompt: string,
|
||||||
|
{
|
||||||
|
width = 1024,
|
||||||
|
height = 1024,
|
||||||
|
sampleStrength = 0.5,
|
||||||
|
negativePrompt = "",
|
||||||
|
}: {
|
||||||
|
width?: number;
|
||||||
|
height?: number;
|
||||||
|
sampleStrength?: number;
|
||||||
|
negativePrompt?: string;
|
||||||
|
},
|
||||||
|
refreshToken: string
|
||||||
|
) {
|
||||||
|
const model = getModel(_model);
|
||||||
|
logger.info(`使用模型: ${_model} 映射模型: ${model} ${width}x${height} 精细度: ${sampleStrength}`);
|
||||||
|
|
||||||
|
const { totalCredit } = await getCredit(refreshToken);
|
||||||
|
if (totalCredit <= 0)
|
||||||
|
await receiveCredit(refreshToken);
|
||||||
|
|
||||||
|
const componentId = util.uuid();
|
||||||
|
const { aigc_data } = await request(
|
||||||
|
"post",
|
||||||
|
"/mweb/v1/get_upload_token",
|
||||||
|
refreshToken,
|
||||||
|
{
|
||||||
|
params: {
|
||||||
|
babi_param: encodeURIComponent(
|
||||||
|
JSON.stringify({
|
||||||
|
scenario: "image_video_generation",
|
||||||
|
feature_key: "aigc_to_image",
|
||||||
|
feature_entrance: "to_image",
|
||||||
|
feature_entrance_detail: "to_image-" + model,
|
||||||
|
})
|
||||||
|
),
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
extend: {
|
||||||
|
root_model: model,
|
||||||
|
template_id: "",
|
||||||
|
},
|
||||||
|
submit_id: util.uuid(),
|
||||||
|
metrics_extra: JSON.stringify({
|
||||||
|
templateId: "",
|
||||||
|
generateCount: 1,
|
||||||
|
promptSource: "custom",
|
||||||
|
templateSource: "",
|
||||||
|
lastRequestId: "",
|
||||||
|
originRequestId: "",
|
||||||
|
}),
|
||||||
|
draft_content: JSON.stringify({
|
||||||
|
type: "draft",
|
||||||
|
id: util.uuid(),
|
||||||
|
min_version: DRAFT_VERSION,
|
||||||
|
is_from_tsn: true,
|
||||||
|
version: DRAFT_VERSION,
|
||||||
|
main_component_id: componentId,
|
||||||
|
component_list: [
|
||||||
|
{
|
||||||
|
type: "image_base_component",
|
||||||
|
id: componentId,
|
||||||
|
min_version: DRAFT_VERSION,
|
||||||
|
generate_type: "generate",
|
||||||
|
aigc_mode: "workbench",
|
||||||
|
abilities: {
|
||||||
|
type: "",
|
||||||
|
id: util.uuid(),
|
||||||
|
generate: {
|
||||||
|
type: "",
|
||||||
|
id: util.uuid(),
|
||||||
|
core_param: {
|
||||||
|
type: "",
|
||||||
|
id: util.uuid(),
|
||||||
|
model,
|
||||||
|
prompt,
|
||||||
|
negative_prompt: negativePrompt,
|
||||||
|
seed: Math.floor(Math.random() * 100000000) + 2500000000,
|
||||||
|
sample_strength: sampleStrength,
|
||||||
|
image_ratio: 1,
|
||||||
|
large_image_info: {
|
||||||
|
type: "",
|
||||||
|
id: util.uuid(),
|
||||||
|
height,
|
||||||
|
width,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
history_option: {
|
||||||
|
type: "",
|
||||||
|
id: util.uuid(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
http_common_info: {
|
||||||
|
aid: Number(DEFAULT_ASSISTANT_ID),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const historyId = aigc_data.history_record_id;
|
||||||
|
if (!historyId)
|
||||||
|
throw new APIException(EX.API_IMAGE_GENERATION_FAILED, "记录ID不存在");
|
||||||
|
let status = 20, failCode, item_list = [];
|
||||||
|
while (status === 20) {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||||
|
const result = await request("post", "/mweb/v1/get_history_by_ids", refreshToken, {
|
||||||
|
data: {
|
||||||
|
history_ids: [historyId],
|
||||||
|
image_info: {
|
||||||
|
width: 2048,
|
||||||
|
height: 2048,
|
||||||
|
format: "webp",
|
||||||
|
image_scene_list: [
|
||||||
|
{
|
||||||
|
scene: "smart_crop",
|
||||||
|
width: 360,
|
||||||
|
height: 360,
|
||||||
|
uniq_key: "smart_crop-w:360-h:360",
|
||||||
|
format: "webp",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scene: "smart_crop",
|
||||||
|
width: 480,
|
||||||
|
height: 480,
|
||||||
|
uniq_key: "smart_crop-w:480-h:480",
|
||||||
|
format: "webp",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scene: "smart_crop",
|
||||||
|
width: 720,
|
||||||
|
height: 720,
|
||||||
|
uniq_key: "smart_crop-w:720-h:720",
|
||||||
|
format: "webp",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scene: "smart_crop",
|
||||||
|
width: 720,
|
||||||
|
height: 480,
|
||||||
|
uniq_key: "smart_crop-w:720-h:480",
|
||||||
|
format: "webp",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scene: "smart_crop",
|
||||||
|
width: 360,
|
||||||
|
height: 240,
|
||||||
|
uniq_key: "smart_crop-w:360-h:240",
|
||||||
|
format: "webp",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scene: "smart_crop",
|
||||||
|
width: 240,
|
||||||
|
height: 320,
|
||||||
|
uniq_key: "smart_crop-w:240-h:320",
|
||||||
|
format: "webp",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scene: "smart_crop",
|
||||||
|
width: 480,
|
||||||
|
height: 640,
|
||||||
|
uniq_key: "smart_crop-w:480-h:640",
|
||||||
|
format: "webp",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scene: "normal",
|
||||||
|
width: 2400,
|
||||||
|
height: 2400,
|
||||||
|
uniq_key: "2400",
|
||||||
|
format: "webp",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scene: "normal",
|
||||||
|
width: 1080,
|
||||||
|
height: 1080,
|
||||||
|
uniq_key: "1080",
|
||||||
|
format: "webp",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scene: "normal",
|
||||||
|
width: 720,
|
||||||
|
height: 720,
|
||||||
|
uniq_key: "720",
|
||||||
|
format: "webp",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scene: "normal",
|
||||||
|
width: 480,
|
||||||
|
height: 480,
|
||||||
|
uniq_key: "480",
|
||||||
|
format: "webp",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
scene: "normal",
|
||||||
|
width: 360,
|
||||||
|
height: 360,
|
||||||
|
uniq_key: "360",
|
||||||
|
format: "webp",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
http_common_info: {
|
||||||
|
aid: Number(DEFAULT_ASSISTANT_ID),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!result[historyId])
|
||||||
|
throw new APIException(EX.API_IMAGE_GENERATION_FAILED, "记录不存在");
|
||||||
|
status = result[historyId].status;
|
||||||
|
failCode = result[historyId].fail_code;
|
||||||
|
item_list = result[historyId].item_list;
|
||||||
|
}
|
||||||
|
if (status === 30) {
|
||||||
|
if (failCode === '2038')
|
||||||
|
throw new APIException(EX.API_CONTENT_FILTERED);
|
||||||
|
else
|
||||||
|
throw new APIException(EX.API_IMAGE_GENERATION_FAILED);
|
||||||
|
}
|
||||||
|
return item_list.map((item) => {
|
||||||
|
if(!item?.image?.large_images?.[0]?.image_url)
|
||||||
|
return item?.common_attr?.cover_url || null;
|
||||||
|
return item.image.large_images[0].image_url;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
generateImages,
|
||||||
|
uploadImages,
|
||||||
|
};
|
||||||
417
src/api/controllers/upload.ts
Normal file
417
src/api/controllers/upload.ts
Normal file
@ -0,0 +1,417 @@
|
|||||||
|
import _ from "lodash";
|
||||||
|
import crypto from "crypto";
|
||||||
|
import zlib from "zlib";
|
||||||
|
|
||||||
|
import APIException from "@/lib/exceptions/APIException.ts";
|
||||||
|
import EX from "@/api/consts/exceptions.ts";
|
||||||
|
import util from "@/lib/util.ts";
|
||||||
|
import { getCredit, receiveCredit, request, checkResult } from "./core.ts";
|
||||||
|
import logger from "@/lib/logger.ts";
|
||||||
|
import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
|
||||||
|
|
||||||
|
const DEFAULT_ASSISTANT_ID = "513695";
|
||||||
|
const DRAFT_VERSION = "3.0.2";
|
||||||
|
|
||||||
|
const constant = {
|
||||||
|
"algorithm": "AWS4-HMAC-SHA256",
|
||||||
|
"v4Identifier": "aws4_request",
|
||||||
|
"dateHeader": "X-Amz-Date",
|
||||||
|
"tokenHeader": "x-amz-security-token",
|
||||||
|
"contentSha256Header": "X-Amz-Content-Sha256",
|
||||||
|
"kDatePrefix": "AWS4"
|
||||||
|
}
|
||||||
|
const ff = [
|
||||||
|
"authorization",
|
||||||
|
"content-type",
|
||||||
|
"content-length",
|
||||||
|
"user-agent",
|
||||||
|
"presigned-expires",
|
||||||
|
"expect",
|
||||||
|
"x-amzn-trace-id"
|
||||||
|
]
|
||||||
|
// 伪装headers
|
||||||
|
const FAKE_HEADERS = {
|
||||||
|
// authorization: "AWS4-HMAC-SHA256 Credential=AKTPNTcwMWUwZmE2ODNhNDk3OWE1M2ViNjU1ZDllNjcyMWI/20250529/cn-north-1/imagex/aws4_request, SignedHeaders=x-amz-date;x-amz-security-token, Signature=ca3fb22fa6b1940e45d7c744964d06af50053b3eb1105ae0b840027001190845",
|
||||||
|
"accept": "*/*",
|
||||||
|
"accept-encoding": "gzip, deflate, br, zstd",
|
||||||
|
"accept-language": "zh-CN,zh;q=0.9",
|
||||||
|
"cache-control": "no-cache",
|
||||||
|
"last-event-id": "undefined",
|
||||||
|
"origin": "https://jimeng.jianying.com",
|
||||||
|
"priority": "u=1, i",
|
||||||
|
"referer": "https://jimeng.jianying.com",
|
||||||
|
"sec-ch-ua":'"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
|
||||||
|
"sec-ch-ua-mobile": "?0",
|
||||||
|
"sec-ch-ua-platform": '"Windows"',
|
||||||
|
"sec-fetch-dest": "empty",
|
||||||
|
"sec-fetch-mode": "cors",
|
||||||
|
"sec-fetch-site": "cors-site",
|
||||||
|
"user-agent":
|
||||||
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
|
||||||
|
};
|
||||||
|
const hostStr = "https://imagex.bytedanceapi.com/";
|
||||||
|
const regionStr = "cn-north-1";
|
||||||
|
const serviceNameStr = "imagex";
|
||||||
|
|
||||||
|
|
||||||
|
// const te = {
|
||||||
|
// "accessKeyId": "AKTPMTZjYTJkNWMzOWY1NDYxMmFlMmRlNDUxZTc3ODI4Yzk",
|
||||||
|
// "secretAccessKey": "gWRJ+a7OLWDH+rsGUYNCSlV2r1zltBu+KNvO9TuLgzG+jrFv4ClLyVH/awi1Q3Uq",
|
||||||
|
// "sessionToken": "STS2eyJMVEFjY2Vzc0tleUlEIjoiQUtMVFpUQm1ZbVl4TlRsa1ptVmpOREJqWVRrM09UUTNZbU5pTmprMk1EUXdaV00iLCJBY2Nlc3NLZXlJRCI6IkFLVFBNVFpqWVRKa05XTXpPV1kxTkRZeE1tRmxNbVJsTkRVeFpUYzNPREk0WXprIiwiU2lnbmVkU2VjcmV0QWNjZXNzS2V5IjoiN25ZU0o3T0FCMGZubHlKSENBbzcrOTMyV1FPbkUxck00ZnRuNHpPcVc2Unc1NTJJSWRnY3E1YkF6dWd0VUZaRTZPSzhUa3JBb2c3TW9GV3UzeWplZjV2Y3I2cndUWWM4dklYMzdiZ1BuSWM9IiwiRXhwaXJlZFRpbWUiOjE3NDg1OTEzMDksIlBvbGljeVN0cmluZyI6IntcIlN0YXRlbWVudFwiOlt7XCJFZmZlY3RcIjpcIkFsbG93XCIsXCJBY3Rpb25cIjpbXCJ2b2Q6QXBwbHlVcGxvYWRcIixcInZvZDpBcHBseVVwbG9hZElubmVyXCIsXCJ2b2Q6Q29tbWl0VXBsb2FkXCIsXCJ2b2Q6Q29tbWl0VXBsb2FkSW5uZXJcIixcInZvZDpHZXRVcGxvYWRDYW5kaWRhdGVzXCIsXCJJbWFnZVg6QXBwbHlJbWFnZVVwbG9hZFwiLFwiSW1hZ2VYOkNvbW1pdEltYWdlVXBsb2FkXCIsXCJJbWFnZVg6QXBwbHlVcGxvYWRJbWFnZUZpbGVcIixcIkltYWdlWDpDb21taXRVcGxvYWRJbWFnZUZpbGVcIl0sXCJSZXNvdXJjZVwiOltcIipcIl0sXCJDb25kaXRpb25cIjpcIntcXFwiUFNNXFxcIjpcXFwidmlkZW9jdXQubXdlYi5hcGlcXFwifVwifV19IiwiU2lnbmF0dXJlIjoiZTkyNGRmY2Q2ZjE4OTM1NTg5ZjBjYzk5NDc3MjkxZjU5MDk5NGE0ZGZmMGU1Mjc5YjkwZTk1NmUwY2Q0MWFlMiJ9"
|
||||||
|
// }
|
||||||
|
// const tq = {
|
||||||
|
// "Action": "ApplyImageUpload",
|
||||||
|
// "Version": "2018-08-01",
|
||||||
|
// "ServiceId": "tb4s082cfz",
|
||||||
|
// "FileSize": 1930510,
|
||||||
|
// "s": "5sohmgy6e1p"
|
||||||
|
// }
|
||||||
|
// const ttt = "20250530T064830Z";
|
||||||
|
|
||||||
|
function toQueryString(any) {
|
||||||
|
var e = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : {};
|
||||||
|
return Object.keys(e).map(function(t) {
|
||||||
|
return "".concat(t, "=").concat(encodeURIComponent(e[t]))
|
||||||
|
}).join("&")
|
||||||
|
}
|
||||||
|
function iso8601(e) {
|
||||||
|
return void 0 === e && (e = new Date),
|
||||||
|
e.toISOString().replace(/\.\d{3}Z$/, "Z")
|
||||||
|
}
|
||||||
|
|
||||||
|
function createScope(e, t, r) {
|
||||||
|
return [e.substr(0, 8), t, r, constant.v4Identifier].join("/")
|
||||||
|
}
|
||||||
|
function credentialString(e) {
|
||||||
|
return createScope(e.substr(0, 8), regionStr, serviceNameStr)
|
||||||
|
}
|
||||||
|
function p1(str: any): string { // Changed 'e' to 'str' and added 'any' type for broader compatibility initially
|
||||||
|
let s = String(str); // Ensure it's a string, as query params can be numbers (e.g., FileSize)
|
||||||
|
// encodeURIComponent does not encode: A-Z a-z 0-9 - _ . ! ~ * ' ( )
|
||||||
|
// AWS Signature V4 requires specific encoding for certain characters (RFC3986).
|
||||||
|
// Notably, '*' should be %2A. '!' ' ( ) ' should also be percent-encoded.
|
||||||
|
// '~' is allowed unencoded by RFC3986.
|
||||||
|
return encodeURIComponent(s).replace(/[!'()*]/g, function (c) {
|
||||||
|
return '%' + c.charCodeAt(0).toString(16).toUpperCase();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function help(e) {
|
||||||
|
return Object.keys(e).sort().map(function(t) {
|
||||||
|
var r = e[t];
|
||||||
|
if (null != r) {
|
||||||
|
var n = p1(t);
|
||||||
|
if (n)
|
||||||
|
return Array.isArray(r) ? "".concat(n, "=").concat(r.map(p1).sort().join("&".concat(n, "="))) : "".concat(n, "=").concat(p1(r))
|
||||||
|
}
|
||||||
|
}).filter(function(e) {
|
||||||
|
return e
|
||||||
|
}).join("&")
|
||||||
|
}
|
||||||
|
function isSignableHeader(e) {
|
||||||
|
return 0 === e.toLowerCase().indexOf("x-amz-") || 0 > ff.indexOf(e)
|
||||||
|
}
|
||||||
|
function canonicalHeaderValues(e) {
|
||||||
|
return e.replace(/\s+/g, " ").replace(/^\s+|\s+$/g, "")
|
||||||
|
}
|
||||||
|
function canonicalHeaders(headers) {
|
||||||
|
var t = [];
|
||||||
|
Object.keys(headers).forEach(function(r) {
|
||||||
|
t.push([r, headers[r]])
|
||||||
|
}),
|
||||||
|
t.sort(function(e, t) {
|
||||||
|
return e[0].toLowerCase() < t[0].toLowerCase() ? -1 : 1
|
||||||
|
});
|
||||||
|
var r = [];
|
||||||
|
return t.forEach((t)=>{
|
||||||
|
var n = t[0].toLowerCase();
|
||||||
|
if (isSignableHeader(n)) {
|
||||||
|
var i = t[1];
|
||||||
|
if (null == i || "function" != typeof i.toString)
|
||||||
|
throw Error("Header ".concat(n, " contains invalid value"));
|
||||||
|
r.push("".concat(n, ":").concat(canonicalHeaderValues(i.toString())))
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
r.join("\n")
|
||||||
|
}
|
||||||
|
function canonicalString(query, headers) {
|
||||||
|
var e = []
|
||||||
|
, t = "/";
|
||||||
|
return e.push("get".toUpperCase()),
|
||||||
|
e.push(t),
|
||||||
|
e.push(help(query) || ""),
|
||||||
|
e.push("".concat(canonicalHeaders(headers), "\n")),
|
||||||
|
e.push(signedHeaders(headers)),
|
||||||
|
e.push(hexEncodedHash("")),
|
||||||
|
e.join("\n")
|
||||||
|
}
|
||||||
|
function signedHeaders(headers) {
|
||||||
|
var t = [];
|
||||||
|
return Object.keys(headers).forEach((r)=>{
|
||||||
|
r = r.toLowerCase(),
|
||||||
|
isSignableHeader(r) && t.push(r)
|
||||||
|
}),
|
||||||
|
t.sort().join(";")
|
||||||
|
}
|
||||||
|
function stringToSign(e, query, headers) {
|
||||||
|
let cs = canonicalString(query, headers);
|
||||||
|
// console.log("");
|
||||||
|
// console.log("cs", cs);
|
||||||
|
let cs2 = hexEncodedHash(cs);
|
||||||
|
// console.log("");
|
||||||
|
// console.log("cs2", cs2);
|
||||||
|
// console.log("");
|
||||||
|
var t = [];
|
||||||
|
return t.push(constant.algorithm),
|
||||||
|
t.push(e),
|
||||||
|
t.push(credentialString(e)),
|
||||||
|
t.push(cs2),
|
||||||
|
t.join("\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Overloads for hmac to provide better type inference. Note: message is first, key is second.
|
||||||
|
function hmac(message: string, key: string, encoding: crypto.BinaryToTextEncoding): string;
|
||||||
|
function hmac(message: string, key: string): crypto.BinaryLike;
|
||||||
|
function hmac(message: string, key: crypto.BinaryLike, encoding: crypto.BinaryToTextEncoding): string;
|
||||||
|
function hmac(message: string, key: crypto.BinaryLike): crypto.BinaryLike;
|
||||||
|
function hmac(message: string, key: crypto.KeyObject, encoding: crypto.BinaryToTextEncoding): string;
|
||||||
|
function hmac(message: string, key: crypto.KeyObject): crypto.BinaryLike;
|
||||||
|
// Implementation
|
||||||
|
function hmac(message: string, key: crypto.BinaryLike | crypto.KeyObject, encoding?: crypto.BinaryToTextEncoding): string | Buffer | crypto.BinaryLike {
|
||||||
|
const hash = crypto.createHmac('sha256', key).update(message, 'utf-8');
|
||||||
|
if (encoding) {
|
||||||
|
return hash.digest(encoding);
|
||||||
|
}
|
||||||
|
return hash.digest(); // Returns Buffer by default
|
||||||
|
}
|
||||||
|
function hexEncodedHash(k:string) {
|
||||||
|
return crypto.createHash("sha256").update(k, 'utf-8').digest("hex");
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSigningKey(secretAccessKey: string, dateStamp: string, regionName: string, serviceName: string): crypto.BinaryLike {
|
||||||
|
const kSecret = "AWS4" + secretAccessKey; // kSecret is string
|
||||||
|
// Corrected parameter order: hmac(message, key)
|
||||||
|
const kDate: crypto.BinaryLike = hmac(dateStamp, kSecret); // hmac(string, string) -> Buffer
|
||||||
|
const kRegion: crypto.BinaryLike = hmac(regionName, kDate); // hmac(string, Buffer) -> Buffer
|
||||||
|
const kService: crypto.BinaryLike = hmac(serviceName, kRegion); // hmac(string, Buffer) -> Buffer
|
||||||
|
const kSigning: crypto.BinaryLike = hmac(constant.v4Identifier, kService); // hmac(string, Buffer) -> Buffer
|
||||||
|
return kSigning;
|
||||||
|
}
|
||||||
|
|
||||||
|
function signature(secretAccessKey:string, amzDate:string, query: any, headers: any): string {
|
||||||
|
const dateStamp = amzDate.substring(0, 8); // Extract YYYYMMDD from YYYYMMDDTHHMMSSZ
|
||||||
|
const signingKey: crypto.BinaryLike = getSigningKey(secretAccessKey, dateStamp, regionStr, serviceNameStr);
|
||||||
|
const stringToSignValue = stringToSign(amzDate, query, headers);
|
||||||
|
// The final signature must be a hex string.
|
||||||
|
// Corrected parameter order: hmac(message, key, encoding)
|
||||||
|
return hmac(stringToSignValue, signingKey, 'hex');
|
||||||
|
}
|
||||||
|
|
||||||
|
function authorizationSign(accessKeyId, secretAccessKey, t, query, headers) {
|
||||||
|
var s = signature(secretAccessKey, t, query, headers);
|
||||||
|
// console.log("signature", s);
|
||||||
|
var r = []
|
||||||
|
, n = credentialString(t);
|
||||||
|
return r.push("".concat(constant.algorithm, " Credential=").concat(accessKeyId, "/").concat(n)),
|
||||||
|
r.push("SignedHeaders=".concat(signedHeaders(headers))),
|
||||||
|
r.push("Signature=".concat(s)),
|
||||||
|
r.join(", ")
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求jimeng
|
||||||
|
*
|
||||||
|
* @param method 请求方法
|
||||||
|
* @param uri 请求路径
|
||||||
|
* @param params 请求参数
|
||||||
|
* @param headers 请求头
|
||||||
|
*/
|
||||||
|
async function requestUpload(
|
||||||
|
method: string,
|
||||||
|
uri: string,
|
||||||
|
data: any, // Added data parameter for request body
|
||||||
|
options: AxiosRequestConfig = {},
|
||||||
|
host: string= "",
|
||||||
|
) {
|
||||||
|
let h = {
|
||||||
|
...(options.headers || {}),
|
||||||
|
}
|
||||||
|
// console.log("requestUpload headers", h);
|
||||||
|
// return ""
|
||||||
|
const response = await axios.request({
|
||||||
|
method,
|
||||||
|
url: `${host||'https://jimeng.jianying.com'}${uri}`,
|
||||||
|
data, // Use the new data parameter for the request body
|
||||||
|
params: {
|
||||||
|
...(options.params || {}),
|
||||||
|
},
|
||||||
|
headers: h,
|
||||||
|
timeout: 15000,
|
||||||
|
validateStatus: () => true,
|
||||||
|
..._.omit(options, "params", "headers"),
|
||||||
|
});
|
||||||
|
// 流式响应直接返回response
|
||||||
|
if (options.responseType == "stream") return response;
|
||||||
|
// console.log("response", response);
|
||||||
|
return checkResult(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getUploadToken(refreshToken: string){
|
||||||
|
const res = await request(
|
||||||
|
"post",
|
||||||
|
"/mweb/v1/get_upload_token",
|
||||||
|
refreshToken,
|
||||||
|
{
|
||||||
|
params: {},
|
||||||
|
data: {
|
||||||
|
scene: 2,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
// console.log("get_upload_token", res);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getUploadService(
|
||||||
|
access_key_id:string,
|
||||||
|
secret_access_key:string,
|
||||||
|
session_token:string,
|
||||||
|
space_name:string,
|
||||||
|
upload_domain:string,
|
||||||
|
file_size:number,
|
||||||
|
){
|
||||||
|
// console.log("access_key_id", access_key_id);
|
||||||
|
// console.log("secret_access_key", secret_access_key);
|
||||||
|
// console.log("session_token", session_token);
|
||||||
|
// console.log("space_name", space_name);
|
||||||
|
// console.log("upload_domain", upload_domain);
|
||||||
|
// console.log("file_size", file_size);
|
||||||
|
// console.log("");
|
||||||
|
|
||||||
|
let query = {
|
||||||
|
Action: "ApplyImageUpload",
|
||||||
|
Version: "2018-08-01",
|
||||||
|
ServiceId: space_name,
|
||||||
|
FileSize: file_size,
|
||||||
|
// s :Math.random().toString(36).substring(2)
|
||||||
|
s :"skloxwd3qfb"
|
||||||
|
};
|
||||||
|
|
||||||
|
// query = tq;
|
||||||
|
|
||||||
|
// console.log("query",query);
|
||||||
|
// console.log("");
|
||||||
|
let url = ""+toQueryString(query);
|
||||||
|
let time = new Date();
|
||||||
|
let t = iso8601(time);
|
||||||
|
var r = t.replace(/[:\-]|\.\d{3}/g, "");
|
||||||
|
// var r = "20250530T055559Z";
|
||||||
|
// var r = ttt;
|
||||||
|
// console.log("r", r);
|
||||||
|
let headers = {
|
||||||
|
// "x-amz-security-token": te.sessionToken,
|
||||||
|
"x-amz-security-token": session_token,
|
||||||
|
"x-amz-date": r,
|
||||||
|
};
|
||||||
|
let authorization = authorizationSign(
|
||||||
|
// te.accessKeyId,
|
||||||
|
// te.secretAccessKey,
|
||||||
|
access_key_id,
|
||||||
|
secret_access_key,
|
||||||
|
r,
|
||||||
|
query,
|
||||||
|
headers);
|
||||||
|
// console.log("url", url);
|
||||||
|
// console.log("authorization", authorization);
|
||||||
|
// console.log("headers", headers);
|
||||||
|
return await requestUpload(
|
||||||
|
"get",
|
||||||
|
"?"+url,
|
||||||
|
null,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
...FAKE_HEADERS,
|
||||||
|
...headers,
|
||||||
|
"authorization": authorization,
|
||||||
|
},
|
||||||
|
}, `https://${upload_domain}/`);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function calculateCrc32Hex(data) {
|
||||||
|
// 计算 CRC32 值,Node.js 的 zlib.crc32 返回无符号整数
|
||||||
|
//@ts-ignore
|
||||||
|
const crc32Value = zlib.crc32(data);
|
||||||
|
|
||||||
|
// 将无符号整数转换为十六进制字符串
|
||||||
|
// 使用 >>> 0 确保是无符号操作,尽管 zlib.crc32 已经返回无符号
|
||||||
|
// 使用 toString(16) 转换为十六进制
|
||||||
|
let hexString = (crc32Value >>> 0).toString(16);
|
||||||
|
|
||||||
|
// 补零以确保是 8 位十六进制字符串(如果需要的话,取决于具体的格式要求)
|
||||||
|
// Python 的 hex()[2:] 对于 32 位整数会输出 8 位十六进制(不包括 0x)
|
||||||
|
while (hexString.length < 8) {
|
||||||
|
hexString = '0' + hexString;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hexString;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 伪装headers
|
||||||
|
const FAKE_OSS_HEADERS = {
|
||||||
|
"accept": "*/*",
|
||||||
|
"accept-encoding": "gzip, deflate, br, zstd",
|
||||||
|
"accept-language": "zh-CN,zh;q=0.9",
|
||||||
|
"cache-control": "no-cache",
|
||||||
|
"last-event-id": "undefined",
|
||||||
|
"origin": "https://jimeng.jianying.com",
|
||||||
|
"priority": "u=1, i",
|
||||||
|
"referer": "https://jimeng.jianying.com",
|
||||||
|
"sec-ch-ua":'"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
|
||||||
|
"sec-ch-ua-mobile": "?0",
|
||||||
|
"sec-ch-ua-platform": '"Windows"',
|
||||||
|
"sec-fetch-dest": "empty",
|
||||||
|
"sec-fetch-mode": "cors",
|
||||||
|
"sec-fetch-site": "cors-site",
|
||||||
|
"user-agent":
|
||||||
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
|
||||||
|
};
|
||||||
|
export async function sendFile(url:string, crc32:string, authorization:string, fileBuffer:any){
|
||||||
|
let headers = {
|
||||||
|
"content-type": "application/octet-stream",
|
||||||
|
"content-disposition": 'attachment; filename="undefined"',
|
||||||
|
"content-crc32": crc32,
|
||||||
|
"authorization": authorization,
|
||||||
|
}
|
||||||
|
return await requestUpload(
|
||||||
|
"post",
|
||||||
|
"",
|
||||||
|
fileBuffer, // data is the second param
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
...FAKE_OSS_HEADERS,
|
||||||
|
...headers,
|
||||||
|
"authorization": authorization,
|
||||||
|
},
|
||||||
|
}, url);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export async function uploadImages(
|
||||||
|
_model: string,
|
||||||
|
prompt: string,
|
||||||
|
{
|
||||||
|
width = 1024,
|
||||||
|
height = 1024,
|
||||||
|
sampleStrength = 0.5,
|
||||||
|
negativePrompt = "",
|
||||||
|
}: {
|
||||||
|
width?: number;
|
||||||
|
height?: number;
|
||||||
|
sampleStrength?: number;
|
||||||
|
negativePrompt?: string;
|
||||||
|
},
|
||||||
|
refreshToken: string
|
||||||
|
) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
201
src/api/controllers/video.ts
Normal file
201
src/api/controllers/video.ts
Normal file
@ -0,0 +1,201 @@
|
|||||||
|
import _ from "lodash";
|
||||||
|
|
||||||
|
import APIException from "@/lib/exceptions/APIException.ts";
|
||||||
|
import EX from "@/api/consts/exceptions.ts";
|
||||||
|
import util from "@/lib/util.ts";
|
||||||
|
import { getCredit, receiveCredit, request } from "./core.ts";
|
||||||
|
import logger from "@/lib/logger.ts";
|
||||||
|
|
||||||
|
const DEFAULT_ASSISTANT_ID = "513695";
|
||||||
|
export const DEFAULT_MODEL = "jimeng-v-3.0";
|
||||||
|
const DRAFT_VERSION = "3.0.5";
|
||||||
|
const DRAFT_V_VERSION = "1.0.0";
|
||||||
|
const MODEL_MAP = {
|
||||||
|
"jimeng-v-3.0": "dreamina_ic_generate_video_model_vgfm_3.0",
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getModel(model: string) {
|
||||||
|
return MODEL_MAP[model] || MODEL_MAP[DEFAULT_MODEL];
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function generateVideo(
|
||||||
|
_model: string,
|
||||||
|
prompt: string,
|
||||||
|
{
|
||||||
|
width = 512,
|
||||||
|
height = 512,
|
||||||
|
imgURL = "",
|
||||||
|
duration = 5000,
|
||||||
|
}: {
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
imgURL: string;
|
||||||
|
duration: number;
|
||||||
|
},
|
||||||
|
refreshToken: string
|
||||||
|
) {
|
||||||
|
if(!imgURL){
|
||||||
|
throw new APIException(EX.API_REQUEST_PARAMS_INVALID);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const model = getModel(_model);
|
||||||
|
logger.info(`使用模型: ${_model} : ${model} 参考图片尺寸: ${width}x${height} 图片地址 ${imgURL} 持续时间: ${duration} 提示词: ${prompt}`);
|
||||||
|
|
||||||
|
const { totalCredit } = await getCredit(refreshToken);
|
||||||
|
if (totalCredit <= 0)
|
||||||
|
await receiveCredit(refreshToken);
|
||||||
|
|
||||||
|
const componentId = util.uuid();
|
||||||
|
const originSubmitId = util.uuid();
|
||||||
|
const { aigc_data } = await request(
|
||||||
|
"post",
|
||||||
|
"/mweb/v1/aigc_draft/generate",
|
||||||
|
refreshToken,
|
||||||
|
{
|
||||||
|
params: {
|
||||||
|
babi_param: encodeURIComponent(
|
||||||
|
JSON.stringify({
|
||||||
|
scenario: "image_video_generation",
|
||||||
|
feature_key: "text_to_video",
|
||||||
|
feature_entrance: "to_video",
|
||||||
|
feature_entrance_detail: "to_image-text_to_video",
|
||||||
|
})
|
||||||
|
),
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
extend: {
|
||||||
|
m_video_commerce_info: {
|
||||||
|
resource_id: "generate_video",
|
||||||
|
resource_id_type: "str",
|
||||||
|
resource_sub_type: "aigc",
|
||||||
|
benefit_type: "basic_video_operation_vgfm_v_three"
|
||||||
|
},
|
||||||
|
root_model: model,
|
||||||
|
template_id: "",
|
||||||
|
history_option: {},
|
||||||
|
},
|
||||||
|
submit_id: util.uuid(),
|
||||||
|
metrics_extra: JSON.stringify({
|
||||||
|
promptSource: "custom",
|
||||||
|
originSubmitId: originSubmitId,
|
||||||
|
isDefaultSeed: 1,
|
||||||
|
originTemplateId: "",
|
||||||
|
imageNameMapping: {},
|
||||||
|
}),
|
||||||
|
draft_content: JSON.stringify({
|
||||||
|
type: "draft",
|
||||||
|
id: util.uuid(),
|
||||||
|
min_version: DRAFT_VERSION,
|
||||||
|
min_features: [],
|
||||||
|
is_from_tsn: true,
|
||||||
|
version: "3.2.2",
|
||||||
|
main_component_id: componentId,
|
||||||
|
component_list: [
|
||||||
|
{
|
||||||
|
type: "video_base_component",
|
||||||
|
id: componentId,
|
||||||
|
min_version: DRAFT_V_VERSION,
|
||||||
|
generate_type: "gen_video",
|
||||||
|
aigc_mode: "workbench",
|
||||||
|
metadata: {
|
||||||
|
type: "",
|
||||||
|
id: util.uuid(),
|
||||||
|
created_platform: 3,
|
||||||
|
created_platform_version: "",
|
||||||
|
created_time_in_ms: Date.now(),
|
||||||
|
created_did: "",
|
||||||
|
},
|
||||||
|
abilities: {
|
||||||
|
type: "",
|
||||||
|
id: util.uuid(),
|
||||||
|
gen_video:{
|
||||||
|
type: "",
|
||||||
|
id: util.uuid(),
|
||||||
|
text_to_video_params:{
|
||||||
|
type: "",
|
||||||
|
id: util.uuid(),
|
||||||
|
video_gen_inputs:[
|
||||||
|
{
|
||||||
|
type: "",
|
||||||
|
id: util.uuid(),
|
||||||
|
min_version: DRAFT_V_VERSION,
|
||||||
|
prompt: prompt,
|
||||||
|
first_frame_image:{
|
||||||
|
type: "image",
|
||||||
|
id: util.uuid(),
|
||||||
|
source_from: "upload",
|
||||||
|
platform_type: 1,
|
||||||
|
name: "",
|
||||||
|
image_uri: imgURL,
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
|
format: "",
|
||||||
|
uri: imgURL,
|
||||||
|
},
|
||||||
|
video_mode:2,
|
||||||
|
fps:24,
|
||||||
|
duration_ms:duration,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
video_aspect_ratio:"9:16",
|
||||||
|
seed: Math.floor(Math.random() * 100000000) + 2500000000,
|
||||||
|
model_req_key: model,
|
||||||
|
},
|
||||||
|
video_task_extra:{
|
||||||
|
promptSource: "custom",
|
||||||
|
originSubmitId: originSubmitId,
|
||||||
|
isDefaultSeed: 1,
|
||||||
|
originTemplateId: "",
|
||||||
|
imageNameMapping: {},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
process_type:1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
http_common_info: {
|
||||||
|
aid: Number(DEFAULT_ASSISTANT_ID),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const historyId = aigc_data.history_record_id;
|
||||||
|
if (!historyId)
|
||||||
|
throw new APIException(EX.API_IMAGE_GENERATION_FAILED, "记录ID不存在");
|
||||||
|
let status = 20, failCode, item_list = [];
|
||||||
|
//https://jimeng.jianying.com/mweb/v1/get_history_by_ids?
|
||||||
|
//
|
||||||
|
while (status === 20) {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||||
|
const result = await request("post", "/mweb/v1/get_history_by_ids", refreshToken, {
|
||||||
|
data: {
|
||||||
|
history_ids: [historyId],
|
||||||
|
http_common_info: {
|
||||||
|
aid: Number(DEFAULT_ASSISTANT_ID),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!result[historyId])
|
||||||
|
throw new APIException(EX.API_IMAGE_GENERATION_FAILED, "记录不存在");
|
||||||
|
status = result[historyId].status;
|
||||||
|
failCode = result[historyId].fail_code;
|
||||||
|
item_list = result[historyId].item_list;
|
||||||
|
}
|
||||||
|
if (status === 30) {
|
||||||
|
if (failCode === '2038')
|
||||||
|
throw new APIException(EX.API_CONTENT_FILTERED);
|
||||||
|
else
|
||||||
|
throw new APIException(EX.API_IMAGE_GENERATION_FAILED);
|
||||||
|
}
|
||||||
|
return item_list.map((item) => {
|
||||||
|
if(!item?.video?.transcoded_video?.origin?.video_url)
|
||||||
|
// return item?.common_attr?.cover_url || null;
|
||||||
|
return null;
|
||||||
|
return item.video.transcoded_video.origin.video_url;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
generateVideo,
|
||||||
|
};
|
||||||
36
src/api/routes/chat.ts
Normal file
36
src/api/routes/chat.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
import Request from '@/lib/request/Request.ts';
|
||||||
|
import Response from '@/lib/response/Response.ts';
|
||||||
|
import { tokenSplit } from '@/api/controllers/core.ts';
|
||||||
|
import { createCompletion, createCompletionStream } from '@/api/controllers/chat.ts';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
|
||||||
|
prefix: '/v1/chat',
|
||||||
|
|
||||||
|
post: {
|
||||||
|
|
||||||
|
'/completions': async (request: Request) => {
|
||||||
|
request
|
||||||
|
.validate('body.model', v => _.isUndefined(v) || _.isString(v))
|
||||||
|
.validate('body.messages', _.isArray)
|
||||||
|
.validate('headers.authorization', _.isString)
|
||||||
|
// refresh_token切分
|
||||||
|
const tokens = tokenSplit(request.headers.authorization);
|
||||||
|
// 随机挑选一个refresh_token
|
||||||
|
const token = _.sample(tokens);
|
||||||
|
const { model, messages, stream } = request.body;
|
||||||
|
if (stream) {
|
||||||
|
const stream = await createCompletionStream(messages, token, model);
|
||||||
|
return new Response(stream, {
|
||||||
|
type: "text/event-stream"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return await createCompletion(messages, token, model);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
58
src/api/routes/images.ts
Normal file
58
src/api/routes/images.ts
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import _ from "lodash";
|
||||||
|
|
||||||
|
import Request from "@/lib/request/Request.ts";
|
||||||
|
import { generateImages } from "@/api/controllers/images.ts";
|
||||||
|
import { tokenSplit } from "@/api/controllers/core.ts";
|
||||||
|
import util from "@/lib/util.ts";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
prefix: "/v1/images",
|
||||||
|
|
||||||
|
post: {
|
||||||
|
"/generations": async (request: Request) => {
|
||||||
|
request
|
||||||
|
.validate("body.model", v => _.isUndefined(v) || _.isString(v))
|
||||||
|
.validate("body.prompt", _.isString)
|
||||||
|
.validate("body.negative_prompt", v => _.isUndefined(v) || _.isString(v))
|
||||||
|
.validate("body.width", v => _.isUndefined(v) || _.isFinite(v))
|
||||||
|
.validate("body.height", v => _.isUndefined(v) || _.isFinite(v))
|
||||||
|
.validate("body.sample_strength", v => _.isUndefined(v) || _.isFinite(v))
|
||||||
|
.validate("body.response_format", v => _.isUndefined(v) || _.isString(v))
|
||||||
|
.validate("headers.authorization", _.isString);
|
||||||
|
// refresh_token切分
|
||||||
|
const tokens = tokenSplit(request.headers.authorization);
|
||||||
|
// 随机挑选一个refresh_token
|
||||||
|
const token = _.sample(tokens);
|
||||||
|
const {
|
||||||
|
model,
|
||||||
|
prompt,
|
||||||
|
negative_prompt: negativePrompt,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
sample_strength: sampleStrength,
|
||||||
|
response_format,
|
||||||
|
} = request.body;
|
||||||
|
const responseFormat = _.defaultTo(response_format, "url");
|
||||||
|
const imageUrls = await generateImages(model, prompt, {
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
sampleStrength,
|
||||||
|
negativePrompt,
|
||||||
|
}, token);
|
||||||
|
let data = [];
|
||||||
|
if (responseFormat == "b64_json") {
|
||||||
|
data = (
|
||||||
|
await Promise.all(imageUrls.map((url) => util.fetchFileBASE64(url)))
|
||||||
|
).map((b64) => ({ b64_json: b64 }));
|
||||||
|
} else {
|
||||||
|
data = imageUrls.map((url) => ({
|
||||||
|
url,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
created: util.unixTimestamp(),
|
||||||
|
data,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
33
src/api/routes/index.ts
Normal file
33
src/api/routes/index.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import fs from 'fs-extra';
|
||||||
|
|
||||||
|
import Response from '@/lib/response/Response.ts';
|
||||||
|
import images from "./images.ts";
|
||||||
|
import chat from "./chat.ts";
|
||||||
|
import ping from "./ping.ts";
|
||||||
|
import token from './token.js';
|
||||||
|
// import models from './models.ts';
|
||||||
|
import upload from './upload.ts';
|
||||||
|
import video from './video.ts';
|
||||||
|
|
||||||
|
export default [
|
||||||
|
{
|
||||||
|
get: {
|
||||||
|
'/': async () => {
|
||||||
|
const content = await fs.readFile('public/welcome.html');
|
||||||
|
return new Response(content, {
|
||||||
|
type: 'html',
|
||||||
|
headers: {
|
||||||
|
Expires: '-1'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
images,
|
||||||
|
chat,
|
||||||
|
ping,
|
||||||
|
token,
|
||||||
|
// models,
|
||||||
|
video,
|
||||||
|
upload
|
||||||
|
];
|
||||||
21
src/api/routes/models.ts
Normal file
21
src/api/routes/models.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
|
||||||
|
prefix: '/v1',
|
||||||
|
|
||||||
|
get: {
|
||||||
|
'/models': async () => {
|
||||||
|
return {
|
||||||
|
"data": [
|
||||||
|
{
|
||||||
|
"id": "jimeng",
|
||||||
|
"object": "model",
|
||||||
|
"owned_by": "jimeng-free-api"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
6
src/api/routes/ping.ts
Normal file
6
src/api/routes/ping.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export default {
|
||||||
|
prefix: '/ping',
|
||||||
|
get: {
|
||||||
|
'': async () => "pong"
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/api/routes/token.ts
Normal file
39
src/api/routes/token.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
import Request from '@/lib/request/Request.ts';
|
||||||
|
import Response from '@/lib/response/Response.ts';
|
||||||
|
import { getTokenLiveStatus, getCredit, tokenSplit } from '@/api/controllers/core.ts';
|
||||||
|
import logger from '@/lib/logger.ts';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
|
||||||
|
prefix: '/token',
|
||||||
|
|
||||||
|
post: {
|
||||||
|
|
||||||
|
'/check': async (request: Request) => {
|
||||||
|
request
|
||||||
|
.validate('body.token', _.isString)
|
||||||
|
const live = await getTokenLiveStatus(request.body.token);
|
||||||
|
return {
|
||||||
|
live
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
'/points': async (request: Request) => {
|
||||||
|
request
|
||||||
|
.validate('headers.authorization', _.isString)
|
||||||
|
// refresh_token切分
|
||||||
|
const tokens = tokenSplit(request.headers.authorization);
|
||||||
|
const points = await Promise.all(tokens.map(async (token) => {
|
||||||
|
return {
|
||||||
|
token,
|
||||||
|
points: await getCredit(token)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
return points;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
139
src/api/routes/upload.ts
Normal file
139
src/api/routes/upload.ts
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
import _ from "lodash";
|
||||||
|
import fs from "fs";
|
||||||
|
import { imageSize } from 'image-size';
|
||||||
|
|
||||||
|
import Request from "@/lib/request/Request.ts";
|
||||||
|
import { getUploadToken, getUploadService, uploadImages, calculateCrc32Hex, sendFile } from "@/api/controllers/upload.ts";
|
||||||
|
import { tokenSplit } from "@/api/controllers/core.ts";
|
||||||
|
import util from "@/lib/util.ts";
|
||||||
|
export default {
|
||||||
|
prefix: "/v1/upload",
|
||||||
|
|
||||||
|
post: {
|
||||||
|
"/images": async (request: Request) => {
|
||||||
|
request
|
||||||
|
// .validate("body.model", v => _.isUndefined(v) || _.isString(v))
|
||||||
|
// .validate("body.prompt", _.isString)
|
||||||
|
// .validate("body.negative_prompt", v => _.isUndefined(v) || _.isString(v))
|
||||||
|
// .validate("body.width", v => _.isUndefined(v) || _.isFinite(v))
|
||||||
|
// .validate("body.height", v => _.isUndefined(v) || _.isFinite(v))
|
||||||
|
// .validate("body.sample_strength", v => _.isUndefined(v) || _.isFinite(v))
|
||||||
|
// .validate("body.response_format", v => _.isUndefined(v) || _.isString(v))
|
||||||
|
.validate("headers.authorization", _.isString);
|
||||||
|
const imageFile = request.files['image']||null;
|
||||||
|
// console.log(imageFile);
|
||||||
|
// refresh_token切分
|
||||||
|
const tokens = tokenSplit(request.headers.authorization);
|
||||||
|
// 随机挑选一个refresh_token
|
||||||
|
const token = _.sample(tokens);
|
||||||
|
// const {
|
||||||
|
// model,
|
||||||
|
// prompt,
|
||||||
|
// negative_prompt: negativePrompt,
|
||||||
|
// width,
|
||||||
|
// height,
|
||||||
|
// sample_strength: sampleStrength,
|
||||||
|
// response_format,
|
||||||
|
// } = request.body;
|
||||||
|
// const responseFormat = _.defaultTo(response_format, "url");
|
||||||
|
//获取oss授权信息
|
||||||
|
const uploadInfo = await getUploadToken(token);
|
||||||
|
let file_size = 0;
|
||||||
|
let fileBuffer = null;
|
||||||
|
if (imageFile) {
|
||||||
|
file_size = imageFile.size;
|
||||||
|
// console.log("imageFile.filepath", imageFile.filepath);
|
||||||
|
fileBuffer = await fs.promises.readFile(imageFile.filepath);
|
||||||
|
}
|
||||||
|
if (file_size <= 0){
|
||||||
|
return {
|
||||||
|
error: {
|
||||||
|
message: "请上传图片",
|
||||||
|
type: "invalid_request_error",
|
||||||
|
param: null,
|
||||||
|
code: "invalid_image_size",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let crc32 = "";
|
||||||
|
let dimensions = null;
|
||||||
|
if(fileBuffer){
|
||||||
|
dimensions = imageSize(fileBuffer);
|
||||||
|
if ((dimensions.width*dimensions.height) < (100*100)){
|
||||||
|
return {
|
||||||
|
error: {
|
||||||
|
message: "图片尺寸小于100x100",
|
||||||
|
type: "invalid_request_error",
|
||||||
|
param: null,
|
||||||
|
code: "invalid_image_size",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
crc32 = calculateCrc32Hex(fileBuffer);
|
||||||
|
// console.log("crc32", crc32);
|
||||||
|
}
|
||||||
|
//预上传请求
|
||||||
|
let upres = await getUploadService(
|
||||||
|
uploadInfo.access_key_id,
|
||||||
|
uploadInfo.secret_access_key,
|
||||||
|
uploadInfo.session_token,
|
||||||
|
uploadInfo.space_name,
|
||||||
|
uploadInfo.upload_domain,
|
||||||
|
// te.accessKeyId,
|
||||||
|
// te.secretAccessKey,
|
||||||
|
// te.sessionToken,
|
||||||
|
// "tb4s082cfz",
|
||||||
|
// "imagex.bytedanceapi.com",
|
||||||
|
file_size,
|
||||||
|
);
|
||||||
|
//发送图片
|
||||||
|
if(upres && upres.ResponseMetadata){
|
||||||
|
let resData = upres.ResponseMetadata;
|
||||||
|
// console.log("upres", resData);
|
||||||
|
if(resData.Error){
|
||||||
|
return {
|
||||||
|
error: {
|
||||||
|
message: resData.Error.Message,
|
||||||
|
type: "图片服务返回错误",
|
||||||
|
param: null,
|
||||||
|
code: "invalid_request_error",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let Result = upres.Result;
|
||||||
|
// console.log("Result", Result);
|
||||||
|
let UploadHost = Result.UploadAddress.UploadHosts[0];
|
||||||
|
let StoreUri = Result.UploadAddress.StoreInfos[0].StoreUri;
|
||||||
|
let UploadID = Result.UploadAddress.StoreInfos[0].UploadID;
|
||||||
|
let Auth = Result.UploadAddress.StoreInfos[0].Auth;
|
||||||
|
let url = `https://${UploadHost}/upload/v1/${StoreUri}`;
|
||||||
|
// content-crc32: b7a66685
|
||||||
|
// console.log("url", url);
|
||||||
|
// console.log("UploadID", UploadID);
|
||||||
|
// console.log("Auth", Auth);
|
||||||
|
let fres = await sendFile(url, crc32, Auth, fileBuffer);
|
||||||
|
// console.log("fres", fres);
|
||||||
|
if(!fres || fres.message != "Success"){
|
||||||
|
return {
|
||||||
|
error: {
|
||||||
|
message: fres?(fres.message||'upload 请求失败'):'upload 请求失败',
|
||||||
|
type: "图片上传失败",
|
||||||
|
param: null,
|
||||||
|
code: fres?(fres.code||505):505,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//上传结束
|
||||||
|
return {
|
||||||
|
created: util.unixTimestamp(),
|
||||||
|
data:{
|
||||||
|
imgURI:StoreUri,
|
||||||
|
fileSize:file_size,
|
||||||
|
width:dimensions.width,
|
||||||
|
height:dimensions.height,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
49
src/api/routes/video.ts
Normal file
49
src/api/routes/video.ts
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import _ from "lodash";
|
||||||
|
|
||||||
|
import Request from "@/lib/request/Request.ts";
|
||||||
|
import { generateVideo } from "@/api/controllers/video.ts";
|
||||||
|
import { tokenSplit } from "@/api/controllers/core.ts";
|
||||||
|
import util from "@/lib/util.ts";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
prefix: "/v1/video",
|
||||||
|
|
||||||
|
post: {
|
||||||
|
"/generations": async (request: Request) => {
|
||||||
|
request
|
||||||
|
.validate("body.model", v => _.isUndefined(v) || _.isString(v))
|
||||||
|
.validate("body.prompt", _.isString)
|
||||||
|
.validate("body.image", v => _.isUndefined(v) || _.isString(v))
|
||||||
|
.validate("body.width", v => _.isUndefined(v) || _.isFinite(v))
|
||||||
|
.validate("body.height", v => _.isUndefined(v) || _.isFinite(v))
|
||||||
|
.validate("body.duration", v => _.isUndefined(v) || _.isFinite(v))
|
||||||
|
.validate("headers.authorization", _.isString);
|
||||||
|
// refresh_token切分
|
||||||
|
const tokens = tokenSplit(request.headers.authorization);
|
||||||
|
// 随机挑选一个refresh_token
|
||||||
|
const token = _.sample(tokens);
|
||||||
|
const {
|
||||||
|
model,
|
||||||
|
prompt,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
image,
|
||||||
|
duration,
|
||||||
|
} = request.body;
|
||||||
|
const imageUrls = await generateVideo(model, prompt, {
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
imgURL:image,
|
||||||
|
duration:duration*1000,
|
||||||
|
}, token);
|
||||||
|
let data = [];
|
||||||
|
data = imageUrls.map((url) => ({
|
||||||
|
url,
|
||||||
|
}));
|
||||||
|
return {
|
||||||
|
created: util.unixTimestamp(),
|
||||||
|
data,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
82
src/daemon.ts
Normal file
82
src/daemon.ts
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
/**
|
||||||
|
* 守护进程
|
||||||
|
*/
|
||||||
|
|
||||||
|
import process from 'process';
|
||||||
|
import path from 'path';
|
||||||
|
import { spawn } from 'child_process';
|
||||||
|
|
||||||
|
import fs from 'fs-extra';
|
||||||
|
import { format as dateFormat } from 'date-fns';
|
||||||
|
import 'colors';
|
||||||
|
|
||||||
|
const CRASH_RESTART_LIMIT = 600; //进程崩溃重启次数限制
|
||||||
|
const CRASH_RESTART_DELAY = 5000; //进程崩溃重启延迟
|
||||||
|
const LOG_PATH = path.resolve("./logs/daemon.log"); //守护进程日志路径
|
||||||
|
let crashCount = 0; //进程崩溃次数
|
||||||
|
let currentProcess; //当前运行进程
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 写入守护进程日志
|
||||||
|
*/
|
||||||
|
function daemonLog(value, color?: string) {
|
||||||
|
try {
|
||||||
|
const head = `[daemon][${dateFormat(new Date(), "yyyy-MM-dd HH:mm:ss.SSS")}] `;
|
||||||
|
value = head + value;
|
||||||
|
console.log(color ? value[color] : value);
|
||||||
|
fs.ensureDirSync(path.dirname(LOG_PATH));
|
||||||
|
fs.appendFileSync(LOG_PATH, value + "\n");
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
console.error("daemon log write error:", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
daemonLog(`daemon pid: ${process.pid}`);
|
||||||
|
|
||||||
|
function createProcess() {
|
||||||
|
const childProcess = spawn("node", ["index.js", ...process.argv.slice(2)]); //启动子进程
|
||||||
|
childProcess.stdout.pipe(process.stdout, { end: false }); //将子进程输出管道到当前进程输出
|
||||||
|
childProcess.stderr.pipe(process.stderr, { end: false }); //将子进程错误输出管道到当前进程输出
|
||||||
|
currentProcess = childProcess; //更新当前进程
|
||||||
|
daemonLog(`process(${childProcess.pid}) has started`);
|
||||||
|
childProcess.on("error", err => daemonLog(`process(${childProcess.pid}) error: ${err.stack}`, "red"));
|
||||||
|
childProcess.on("close", code => {
|
||||||
|
if(code === 0) //进程正常退出
|
||||||
|
daemonLog(`process(${childProcess.pid}) has exited`);
|
||||||
|
else if(code === 2) //进程已被杀死
|
||||||
|
daemonLog(`process(${childProcess.pid}) has been killed!`, "bgYellow");
|
||||||
|
else if(code === 3) { //进程主动重启
|
||||||
|
daemonLog(`process(${childProcess.pid}) has restart`, "yellow");
|
||||||
|
createProcess(); //重新创建进程
|
||||||
|
}
|
||||||
|
else { //进程发生崩溃
|
||||||
|
if(crashCount++ < CRASH_RESTART_LIMIT) { //进程崩溃次数未达重启次数上限前尝试重启
|
||||||
|
daemonLog(`process(${childProcess.pid}) has crashed! delay ${CRASH_RESTART_DELAY}ms try restarting...(${crashCount})`, "bgRed");
|
||||||
|
setTimeout(() => createProcess(), CRASH_RESTART_DELAY); //延迟指定时长后再重启
|
||||||
|
}
|
||||||
|
else //进程已崩溃,且无法重启
|
||||||
|
daemonLog(`process(${childProcess.pid}) has crashed! unable to restart`, "bgRed");
|
||||||
|
}
|
||||||
|
}); //子进程关闭监听
|
||||||
|
}
|
||||||
|
|
||||||
|
process.on("exit", code => {
|
||||||
|
if(code === 0)
|
||||||
|
daemonLog("daemon process exited");
|
||||||
|
else if(code === 2)
|
||||||
|
daemonLog("daemon process has been killed!");
|
||||||
|
}); //守护进程退出事件
|
||||||
|
|
||||||
|
process.on("SIGTERM", () => {
|
||||||
|
daemonLog("received kill signal", "yellow");
|
||||||
|
currentProcess && currentProcess.kill("SIGINT");
|
||||||
|
process.exit(2);
|
||||||
|
}); //kill退出守护进程
|
||||||
|
|
||||||
|
process.on("SIGINT", () => {
|
||||||
|
currentProcess && currentProcess.kill("SIGINT");
|
||||||
|
process.exit(0);
|
||||||
|
}); //主动退出守护进程
|
||||||
|
|
||||||
|
createProcess(); //创建进程
|
||||||
32
src/index.ts
Normal file
32
src/index.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
import environment from "@/lib/environment.ts";
|
||||||
|
import config from "@/lib/config.ts";
|
||||||
|
import "@/lib/initialize.ts";
|
||||||
|
import server from "@/lib/server.ts";
|
||||||
|
import routes from "@/api/routes/index.ts";
|
||||||
|
import logger from "@/lib/logger.ts";
|
||||||
|
|
||||||
|
const startupTime = performance.now();
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
logger.header();
|
||||||
|
|
||||||
|
logger.info("<<<< jimeng free server >>>>");
|
||||||
|
logger.info("Version:", environment.package.version);
|
||||||
|
logger.info("Process id:", process.pid);
|
||||||
|
logger.info("Environment:", environment.env);
|
||||||
|
logger.info("Service name:", config.service.name);
|
||||||
|
|
||||||
|
server.attachRoutes(routes);
|
||||||
|
await server.listen();
|
||||||
|
|
||||||
|
config.service.bindAddress &&
|
||||||
|
logger.success("Service bind address:", config.service.bindAddress);
|
||||||
|
})()
|
||||||
|
.then(() =>
|
||||||
|
logger.success(
|
||||||
|
`Service startup completed (${Math.floor(performance.now() - startupTime)}ms)`
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.catch((err) => console.error(err));
|
||||||
14
src/lib/config.ts
Normal file
14
src/lib/config.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import serviceConfig from "./configs/service-config.ts";
|
||||||
|
import systemConfig from "./configs/system-config.ts";
|
||||||
|
|
||||||
|
class Config {
|
||||||
|
|
||||||
|
/** 服务配置 */
|
||||||
|
service = serviceConfig;
|
||||||
|
|
||||||
|
/** 系统配置 */
|
||||||
|
system = systemConfig;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new Config();
|
||||||
68
src/lib/configs/service-config.ts
Normal file
68
src/lib/configs/service-config.ts
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
import fs from 'fs-extra';
|
||||||
|
import yaml from 'yaml';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
import environment from '../environment.ts';
|
||||||
|
import util from '../util.ts';
|
||||||
|
|
||||||
|
const CONFIG_PATH = path.join(path.resolve(), 'configs/', environment.env, "/service.yml");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务配置
|
||||||
|
*/
|
||||||
|
export class ServiceConfig {
|
||||||
|
|
||||||
|
/** 服务名称 */
|
||||||
|
name: string;
|
||||||
|
/** @type {string} 服务绑定主机地址 */
|
||||||
|
host;
|
||||||
|
/** @type {number} 服务绑定端口 */
|
||||||
|
port;
|
||||||
|
/** @type {string} 服务路由前缀 */
|
||||||
|
urlPrefix;
|
||||||
|
/** @type {string} 服务绑定地址(外部访问地址) */
|
||||||
|
bindAddress;
|
||||||
|
|
||||||
|
constructor(options?: any) {
|
||||||
|
const { name, host, port, urlPrefix, bindAddress } = options || {};
|
||||||
|
this.name = _.defaultTo(name, 'jimeng-free-api');
|
||||||
|
this.host = _.defaultTo(host, '0.0.0.0');
|
||||||
|
this.port = _.defaultTo(port, 5566);
|
||||||
|
this.urlPrefix = _.defaultTo(urlPrefix, '');
|
||||||
|
this.bindAddress = bindAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
get addressHost() {
|
||||||
|
if(this.bindAddress) return this.bindAddress;
|
||||||
|
const ipAddresses = util.getIPAddressesByIPv4();
|
||||||
|
for(let ipAddress of ipAddresses) {
|
||||||
|
if(ipAddress === this.host)
|
||||||
|
return ipAddress;
|
||||||
|
}
|
||||||
|
return ipAddresses[0] || "127.0.0.1";
|
||||||
|
}
|
||||||
|
|
||||||
|
get address() {
|
||||||
|
return `${this.addressHost}:${this.port}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
get pageDirUrl() {
|
||||||
|
return `http://127.0.0.1:${this.port}/page`;
|
||||||
|
}
|
||||||
|
|
||||||
|
get publicDirUrl() {
|
||||||
|
return `http://127.0.0.1:${this.port}/public`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static load() {
|
||||||
|
const external = _.pickBy(environment, (v, k) => ["name", "host", "port"].includes(k) && !_.isUndefined(v));
|
||||||
|
if(!fs.pathExistsSync(CONFIG_PATH)) return new ServiceConfig(external);
|
||||||
|
const data = yaml.parse(fs.readFileSync(CONFIG_PATH).toString());
|
||||||
|
return new ServiceConfig({ ...data, ...external });
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ServiceConfig.load();
|
||||||
84
src/lib/configs/system-config.ts
Normal file
84
src/lib/configs/system-config.ts
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
import fs from 'fs-extra';
|
||||||
|
import yaml from 'yaml';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
import environment from '../environment.ts';
|
||||||
|
|
||||||
|
const CONFIG_PATH = path.join(path.resolve(), 'configs/', environment.env, "/system.yml");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统配置
|
||||||
|
*/
|
||||||
|
export class SystemConfig {
|
||||||
|
|
||||||
|
/** 是否开启请求日志 */
|
||||||
|
requestLog: boolean;
|
||||||
|
/** 临时目录路径 */
|
||||||
|
tmpDir: string;
|
||||||
|
/** 日志目录路径 */
|
||||||
|
logDir: string;
|
||||||
|
/** 日志写入间隔(毫秒) */
|
||||||
|
logWriteInterval: number;
|
||||||
|
/** 日志文件有效期(毫秒) */
|
||||||
|
logFileExpires: number;
|
||||||
|
/** 公共目录路径 */
|
||||||
|
publicDir: string;
|
||||||
|
/** 临时文件有效期(毫秒) */
|
||||||
|
tmpFileExpires: number;
|
||||||
|
/** 请求体配置 */
|
||||||
|
requestBody: any;
|
||||||
|
/** 是否调试模式 */
|
||||||
|
debug: boolean;
|
||||||
|
|
||||||
|
constructor(options?: any) {
|
||||||
|
const { requestLog, tmpDir, logDir, logWriteInterval, logFileExpires, publicDir, tmpFileExpires, requestBody, debug } = options || {};
|
||||||
|
this.requestLog = _.defaultTo(requestLog, false);
|
||||||
|
this.tmpDir = _.defaultTo(tmpDir, './tmp');
|
||||||
|
this.logDir = _.defaultTo(logDir, './logs');
|
||||||
|
this.logWriteInterval = _.defaultTo(logWriteInterval, 200);
|
||||||
|
this.logFileExpires = _.defaultTo(logFileExpires, 2626560000);
|
||||||
|
this.publicDir = _.defaultTo(publicDir, './public');
|
||||||
|
this.tmpFileExpires = _.defaultTo(tmpFileExpires, 86400000);
|
||||||
|
this.requestBody = Object.assign(requestBody || {}, {
|
||||||
|
enableTypes: ['json', 'form', 'text', 'xml'],
|
||||||
|
encoding: 'utf-8',
|
||||||
|
formLimit: '100mb',
|
||||||
|
jsonLimit: '100mb',
|
||||||
|
textLimit: '100mb',
|
||||||
|
xmlLimit: '100mb',
|
||||||
|
formidable: {
|
||||||
|
maxFileSize: '100mb'
|
||||||
|
},
|
||||||
|
multipart: true,
|
||||||
|
parsedMethods: ['POST', 'PUT', 'PATCH']
|
||||||
|
});
|
||||||
|
this.debug = _.defaultTo(debug, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
get rootDirPath() {
|
||||||
|
return path.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
get tmpDirPath() {
|
||||||
|
return path.resolve(this.tmpDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
get logDirPath() {
|
||||||
|
return path.resolve(this.logDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
get publicDirPath() {
|
||||||
|
return path.resolve(this.publicDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
static load() {
|
||||||
|
if (!fs.pathExistsSync(CONFIG_PATH)) return new SystemConfig();
|
||||||
|
const data = yaml.parse(fs.readFileSync(CONFIG_PATH).toString());
|
||||||
|
return new SystemConfig(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SystemConfig.load();
|
||||||
5
src/lib/consts/exceptions.ts
Normal file
5
src/lib/consts/exceptions.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export default {
|
||||||
|
SYSTEM_ERROR: [-1000, '系统异常'],
|
||||||
|
SYSTEM_REQUEST_VALIDATION_ERROR: [-1001, '请求参数校验错误'],
|
||||||
|
SYSTEM_NOT_ROUTE_MATCHING: [-1002, '无匹配的路由']
|
||||||
|
} as Record<string, [number, string]>
|
||||||
44
src/lib/environment.ts
Normal file
44
src/lib/environment.ts
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
import fs from 'fs-extra';
|
||||||
|
import minimist from 'minimist';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
const cmdArgs = minimist(process.argv.slice(2)); //获取命令行参数
|
||||||
|
const envVars = process.env; //获取环境变量
|
||||||
|
|
||||||
|
class Environment {
|
||||||
|
|
||||||
|
/** 命令行参数 */
|
||||||
|
cmdArgs: any;
|
||||||
|
/** 环境变量 */
|
||||||
|
envVars: any;
|
||||||
|
/** 环境名称 */
|
||||||
|
env?: string;
|
||||||
|
/** 服务名称 */
|
||||||
|
name?: string;
|
||||||
|
/** 服务地址 */
|
||||||
|
host?: string;
|
||||||
|
/** 服务端口 */
|
||||||
|
port?: number;
|
||||||
|
/** 包参数 */
|
||||||
|
package: any;
|
||||||
|
|
||||||
|
constructor(options: any = {}) {
|
||||||
|
const { cmdArgs, envVars, package: _package } = options;
|
||||||
|
this.cmdArgs = cmdArgs;
|
||||||
|
this.envVars = envVars;
|
||||||
|
this.env = _.defaultTo(cmdArgs.env || envVars.SERVER_ENV, 'dev');
|
||||||
|
this.name = cmdArgs.name || envVars.SERVER_NAME || undefined;
|
||||||
|
this.host = cmdArgs.host || envVars.SERVER_HOST || undefined;
|
||||||
|
this.port = Number(cmdArgs.port || envVars.SERVER_PORT) ? Number(cmdArgs.port || envVars.SERVER_PORT) : undefined;
|
||||||
|
this.package = _package;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new Environment({
|
||||||
|
cmdArgs,
|
||||||
|
envVars,
|
||||||
|
package: JSON.parse(fs.readFileSync(path.join(path.resolve(), "package.json")).toString())
|
||||||
|
});
|
||||||
14
src/lib/exceptions/APIException.ts
Normal file
14
src/lib/exceptions/APIException.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import Exception from './Exception.js';
|
||||||
|
|
||||||
|
export default class APIException extends Exception {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造异常
|
||||||
|
*
|
||||||
|
* @param {[number, string]} exception 异常
|
||||||
|
*/
|
||||||
|
constructor(exception: (string | number)[], errmsg?: string) {
|
||||||
|
super(exception, errmsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
47
src/lib/exceptions/Exception.ts
Normal file
47
src/lib/exceptions/Exception.ts
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import assert from 'assert';
|
||||||
|
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
export default class Exception extends Error {
|
||||||
|
|
||||||
|
/** 错误码 */
|
||||||
|
errcode: number;
|
||||||
|
/** 错误消息 */
|
||||||
|
errmsg: string;
|
||||||
|
/** 数据 */
|
||||||
|
data: any;
|
||||||
|
/** HTTP状态码 */
|
||||||
|
httpStatusCode: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造异常
|
||||||
|
*
|
||||||
|
* @param exception 异常
|
||||||
|
* @param _errmsg 异常消息
|
||||||
|
*/
|
||||||
|
constructor(exception: (string | number)[], _errmsg?: string) {
|
||||||
|
assert(_.isArray(exception), 'Exception must be Array');
|
||||||
|
const [errcode, errmsg] = exception as [number, string];
|
||||||
|
assert(_.isFinite(errcode), 'Exception errcode invalid');
|
||||||
|
assert(_.isString(errmsg), 'Exception errmsg invalid');
|
||||||
|
super(_errmsg || errmsg);
|
||||||
|
this.errcode = errcode;
|
||||||
|
this.errmsg = _errmsg || errmsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
compare(exception: (string | number)[]) {
|
||||||
|
const [errcode] = exception as [number, string];
|
||||||
|
return this.errcode == errcode;
|
||||||
|
}
|
||||||
|
|
||||||
|
setHTTPStatusCode(value: number) {
|
||||||
|
this.httpStatusCode = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
setData(value: any) {
|
||||||
|
this.data = _.defaultTo(value, null);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
61
src/lib/http-status-codes.ts
Normal file
61
src/lib/http-status-codes.ts
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
export default {
|
||||||
|
|
||||||
|
CONTINUE: 100, //客户端应当继续发送请求。这个临时响应是用来通知客户端它的部分请求已经被服务器接收,且仍未被拒绝。客户端应当继续发送请求的剩余部分,或者如果请求已经完成,忽略这个响应。服务器必须在请求完成后向客户端发送一个最终响应
|
||||||
|
SWITCHING_PROTOCOLS: 101, //服务器已经理解了客户端的请求,并将通过Upgrade 消息头通知客户端采用不同的协议来完成这个请求。在发送完这个响应最后的空行后,服务器将会切换到在Upgrade 消息头中定义的那些协议。只有在切换新的协议更有好处的时候才应该采取类似措施。例如,切换到新的HTTP 版本比旧版本更有优势,或者切换到一个实时且同步的协议以传送利用此类特性的资源
|
||||||
|
PROCESSING: 102, //处理将被继续执行
|
||||||
|
|
||||||
|
OK: 200, //请求已成功,请求所希望的响应头或数据体将随此响应返回
|
||||||
|
CREATED: 201, //请求已经被实现,而且有一个新的资源已经依据请求的需要而建立,且其 URI 已经随Location 头信息返回。假如需要的资源无法及时建立的话,应当返回 '202 Accepted'
|
||||||
|
ACCEPTED: 202, //服务器已接受请求,但尚未处理。正如它可能被拒绝一样,最终该请求可能会也可能不会被执行。在异步操作的场合下,没有比发送这个状态码更方便的做法了。返回202状态码的响应的目的是允许服务器接受其他过程的请求(例如某个每天只执行一次的基于批处理的操作),而不必让客户端一直保持与服务器的连接直到批处理操作全部完成。在接受请求处理并返回202状态码的响应应当在返回的实体中包含一些指示处理当前状态的信息,以及指向处理状态监视器或状态预测的指针,以便用户能够估计操作是否已经完成
|
||||||
|
NON_AUTHORITATIVE_INFO: 203, //服务器已成功处理了请求,但返回的实体头部元信息不是在原始服务器上有效的确定集合,而是来自本地或者第三方的拷贝。当前的信息可能是原始版本的子集或者超集。例如,包含资源的元数据可能导致原始服务器知道元信息的超级。使用此状态码不是必须的,而且只有在响应不使用此状态码便会返回200 OK的情况下才是合适的
|
||||||
|
NO_CONTENT: 204, //服务器成功处理了请求,但不需要返回任何实体内容,并且希望返回更新了的元信息。响应可能通过实体头部的形式,返回新的或更新后的元信息。如果存在这些头部信息,则应当与所请求的变量相呼应。如果客户端是浏览器的话,那么用户浏览器应保留发送了该请求的页面,而不产生任何文档视图上的变化,即使按照规范新的或更新后的元信息应当被应用到用户浏览器活动视图中的文档。由于204响应被禁止包含任何消息体,因此它始终以消息头后的第一个空行结尾
|
||||||
|
RESET_CONTENT: 205, //服务器成功处理了请求,且没有返回任何内容。但是与204响应不同,返回此状态码的响应要求请求者重置文档视图。该响应主要是被用于接受用户输入后,立即重置表单,以便用户能够轻松地开始另一次输入。与204响应一样,该响应也被禁止包含任何消息体,且以消息头后的第一个空行结束
|
||||||
|
PARTIAL_CONTENT: 206, //服务器已经成功处理了部分 GET 请求。类似于FlashGet或者迅雷这类的HTTP下载工具都是使用此类响应实现断点续传或者将一个大文档分解为多个下载段同时下载。该请求必须包含 Range 头信息来指示客户端希望得到的内容范围,并且可能包含 If-Range 来作为请求条件。响应必须包含如下的头部域:Content-Range 用以指示本次响应中返回的内容的范围;如果是Content-Type为multipart/byteranges的多段下载,则每一段multipart中都应包含Content-Range域用以指示本段的内容范围。假如响应中包含Content-Length,那么它的数值必须匹配它返回的内容范围的真实字节数。Date和ETag或Content-Location,假如同样的请求本应该返回200响应。Expires, Cache-Control,和/或 Vary,假如其值可能与之前相同变量的其他响应对应的值不同的话。假如本响应请求使用了 If-Range 强缓存验证,那么本次响应不应该包含其他实体头;假如本响应的请求使用了 If-Range 弱缓存验证,那么本次响应禁止包含其他实体头;这避免了缓存的实体内容和更新了的实体头信息之间的不一致。否则,本响应就应当包含所有本应该返回200响应中应当返回的所有实体头部域。假如 ETag 或 Latest-Modified 头部不能精确匹配的话,则客户端缓存应禁止将206响应返回的内容与之前任何缓存过的内容组合在一起。任何不支持 Range 以及 Content-Range 头的缓存都禁止缓存206响应返回的内容
|
||||||
|
MULTIPLE_STATUS: 207, //代表之后的消息体将是一个XML消息,并且可能依照之前子请求数量的不同,包含一系列独立的响应代码
|
||||||
|
|
||||||
|
MULTIPLE_CHOICES: 300, //被请求的资源有一系列可供选择的回馈信息,每个都有自己特定的地址和浏览器驱动的商议信息。用户或浏览器能够自行选择一个首选的地址进行重定向。除非这是一个HEAD请求,否则该响应应当包括一个资源特性及地址的列表的实体,以便用户或浏览器从中选择最合适的重定向地址。这个实体的格式由Content-Type定义的格式所决定。浏览器可能根据响应的格式以及浏览器自身能力,自动作出最合适的选择。当然,RFC 2616规范并没有规定这样的自动选择该如何进行。如果服务器本身已经有了首选的回馈选择,那么在Location中应当指明这个回馈的 URI;浏览器可能会将这个 Location 值作为自动重定向的地址。此外,除非额外指定,否则这个响应也是可缓存的
|
||||||
|
MOVED_PERMANENTLY: 301, //被请求的资源已永久移动到新位置,并且将来任何对此资源的引用都应该使用本响应返回的若干个URI之一。如果可能,拥有链接编辑功能的客户端应当自动把请求的地址修改为从服务器反馈回来的地址。除非额外指定,否则这个响应也是可缓存的。新的永久性的URI应当在响应的Location域中返回。除非这是一个HEAD请求,否则响应的实体中应当包含指向新的URI的超链接及简短说明。如果这不是一个GET或者HEAD请求,因此浏览器禁止自动进行重定向,除非得到用户的确认,因为请求的条件可能因此发生变化。注意:对于某些使用 HTTP/1.0 协议的浏览器,当它们发送的POST请求得到了一个301响应的话,接下来的重定向请求将会变成GET方式
|
||||||
|
FOUND: 302, //请求的资源现在临时从不同的URI响应请求。由于这样的重定向是临时的,客户端应当继续向原有地址发送以后的请求。只有在Cache-Control或Expires中进行了指定的情况下,这个响应才是可缓存的。新的临时性的URI应当在响应的 Location 域中返回。除非这是一个HEAD请求,否则响应的实体中应当包含指向新的URI的超链接及简短说明。如果这不是一个GET或者HEAD请求,那么浏览器禁止自动进行重定向,除非得到用户的确认,因为请求的条件可能因此发生变化。注意:虽然RFC 1945和RFC 2068规范不允许客户端在重定向时改变请求的方法,但是很多现存的浏览器将302响应视作为303响应,并且使用GET方式访问在Location中规定的URI,而无视原先请求的方法。状态码303和307被添加了进来,用以明确服务器期待客户端进行何种反应
|
||||||
|
SEE_OTHER: 303, //对应当前请求的响应可以在另一个URI上被找到,而且客户端应当采用 GET 的方式访问那个资源。这个方法的存在主要是为了允许由脚本激活的POST请求输出重定向到一个新的资源。这个新的 URI 不是原始资源的替代引用。同时,303响应禁止被缓存。当然,第二个请求(重定向)可能被缓存。新的 URI 应当在响应的Location域中返回。除非这是一个HEAD请求,否则响应的实体中应当包含指向新的URI的超链接及简短说明。注意:许多 HTTP/1.1 版以前的浏览器不能正确理解303状态。如果需要考虑与这些浏览器之间的互动,302状态码应该可以胜任,因为大多数的浏览器处理302响应时的方式恰恰就是上述规范要求客户端处理303响应时应当做的
|
||||||
|
NOT_MODIFIED: 304, //如果客户端发送了一个带条件的GET请求且该请求已被允许,而文档的内容(自上次访问以来或者根据请求的条件)并没有改变,则服务器应当返回这个状态码。304响应禁止包含消息体,因此始终以消息头后的第一个空行结尾。该响应必须包含以下的头信息:Date,除非这个服务器没有时钟。假如没有时钟的服务器也遵守这些规则,那么代理服务器以及客户端可以自行将Date字段添加到接收到的响应头中去(正如RFC 2068中规定的一样),缓存机制将会正常工作。ETag或 Content-Location,假如同样的请求本应返回200响应。Expires, Cache-Control,和/或Vary,假如其值可能与之前相同变量的其他响应对应的值不同的话。假如本响应请求使用了强缓存验证,那么本次响应不应该包含其他实体头;否则(例如,某个带条件的 GET 请求使用了弱缓存验证),本次响应禁止包含其他实体头;这避免了缓存了的实体内容和更新了的实体头信息之间的不一致。假如某个304响应指明了当前某个实体没有缓存,那么缓存系统必须忽视这个响应,并且重复发送不包含限制条件的请求。假如接收到一个要求更新某个缓存条目的304响应,那么缓存系统必须更新整个条目以反映所有在响应中被更新的字段的值
|
||||||
|
USE_PROXY: 305, //被请求的资源必须通过指定的代理才能被访问。Location域中将给出指定的代理所在的URI信息,接收者需要重复发送一个单独的请求,通过这个代理才能访问相应资源。只有原始服务器才能建立305响应。注意:RFC 2068中没有明确305响应是为了重定向一个单独的请求,而且只能被原始服务器建立。忽视这些限制可能导致严重的安全后果
|
||||||
|
UNUSED: 306, //在最新版的规范中,306状态码已经不再被使用
|
||||||
|
TEMPORARY_REDIRECT: 307, //请求的资源现在临时从不同的URI 响应请求。由于这样的重定向是临时的,客户端应当继续向原有地址发送以后的请求。只有在Cache-Control或Expires中进行了指定的情况下,这个响应才是可缓存的。新的临时性的URI 应当在响应的Location域中返回。除非这是一个HEAD请求,否则响应的实体中应当包含指向新的URI 的超链接及简短说明。因为部分浏览器不能识别307响应,因此需要添加上述必要信息以便用户能够理解并向新的 URI 发出访问请求。如果这不是一个GET或者HEAD请求,那么浏览器禁止自动进行重定向,除非得到用户的确认,因为请求的条件可能因此发生变化
|
||||||
|
|
||||||
|
BAD_REQUEST: 400, //1.语义有误,当前请求无法被服务器理解。除非进行修改,否则客户端不应该重复提交这个请求 2.请求参数有误
|
||||||
|
UNAUTHORIZED: 401, //当前请求需要用户验证。该响应必须包含一个适用于被请求资源的 WWW-Authenticate 信息头用以询问用户信息。客户端可以重复提交一个包含恰当的 Authorization 头信息的请求。如果当前请求已经包含了 Authorization 证书,那么401响应代表着服务器验证已经拒绝了那些证书。如果401响应包含了与前一个响应相同的身份验证询问,且浏览器已经至少尝试了一次验证,那么浏览器应当向用户展示响应中包含的实体信息,因为这个实体信息中可能包含了相关诊断信息。参见RFC 2617
|
||||||
|
PAYMENT_REQUIRED: 402, //该状态码是为了将来可能的需求而预留的
|
||||||
|
FORBIDDEN: 403, //服务器已经理解请求,但是拒绝执行它。与401响应不同的是,身份验证并不能提供任何帮助,而且这个请求也不应该被重复提交。如果这不是一个HEAD请求,而且服务器希望能够讲清楚为何请求不能被执行,那么就应该在实体内描述拒绝的原因。当然服务器也可以返回一个404响应,假如它不希望让客户端获得任何信息
|
||||||
|
NOT_FOUND: 404, //请求失败,请求所希望得到的资源未被在服务器上发现。没有信息能够告诉用户这个状况到底是暂时的还是永久的。假如服务器知道情况的话,应当使用410状态码来告知旧资源因为某些内部的配置机制问题,已经永久的不可用,而且没有任何可以跳转的地址。404这个状态码被广泛应用于当服务器不想揭示到底为何请求被拒绝或者没有其他适合的响应可用的情况下
|
||||||
|
METHOD_NOT_ALLOWED: 405, //请求行中指定的请求方法不能被用于请求相应的资源。该响应必须返回一个Allow 头信息用以表示出当前资源能够接受的请求方法的列表。鉴于PUT,DELETE方法会对服务器上的资源进行写操作,因而绝大部分的网页服务器都不支持或者在默认配置下不允许上述请求方法,对于此类请求均会返回405错误
|
||||||
|
NO_ACCEPTABLE: 406, //请求的资源的内容特性无法满足请求头中的条件,因而无法生成响应实体。除非这是一个 HEAD 请求,否则该响应就应当返回一个包含可以让用户或者浏览器从中选择最合适的实体特性以及地址列表的实体。实体的格式由Content-Type头中定义的媒体类型决定。浏览器可以根据格式及自身能力自行作出最佳选择。但是,规范中并没有定义任何作出此类自动选择的标准
|
||||||
|
PROXY_AUTHENTICATION_REQUIRED: 407, //与401响应类似,只不过客户端必须在代理服务器上进行身份验证。代理服务器必须返回一个Proxy-Authenticate用以进行身份询问。客户端可以返回一个Proxy-Authorization信息头用以验证。参见RFC 2617
|
||||||
|
REQUEST_TIMEOUT: 408, //请求超时。客户端没有在服务器预备等待的时间内完成一个请求的发送。客户端可以随时再次提交这一请求而无需进行任何更改
|
||||||
|
CONFLICT: 409, //由于和被请求的资源的当前状态之间存在冲突,请求无法完成。这个代码只允许用在这样的情况下才能被使用:用户被认为能够解决冲突,并且会重新提交新的请求。该响应应当包含足够的信息以便用户发现冲突的源头。冲突通常发生于对PUT请求的处理中。例如,在采用版本检查的环境下,某次PUT提交的对特定资源的修改请求所附带的版本信息与之前的某个(第三方)请求向冲突,那么此时服务器就应该返回一个409错误,告知用户请求无法完成。此时,响应实体中很可能会包含两个冲突版本之间的差异比较,以便用户重新提交归并以后的新版本
|
||||||
|
GONE: 410, //被请求的资源在服务器上已经不再可用,而且没有任何已知的转发地址。这样的状况应当被认为是永久性的。如果可能,拥有链接编辑功能的客户端应当在获得用户许可后删除所有指向这个地址的引用。如果服务器不知道或者无法确定这个状况是否是永久的,那么就应该使用404状态码。除非额外说明,否则这个响应是可缓存的。410响应的目的主要是帮助网站管理员维护网站,通知用户该资源已经不再可用,并且服务器拥有者希望所有指向这个资源的远端连接也被删除。这类事件在限时、增值服务中很普遍。同样,410响应也被用于通知客户端在当前服务器站点上,原本属于某个个人的资源已经不再可用。当然,是否需要把所有永久不可用的资源标记为'410 Gone',以及是否需要保持此标记多长时间,完全取决于服务器拥有者
|
||||||
|
LENGTH_REQUIRED: 411, //服务器拒绝在没有定义Content-Length头的情况下接受请求。在添加了表明请求消息体长度的有效Content-Length头之后,客户端可以再次提交该请求
|
||||||
|
PRECONDITION_FAILED: 412, //服务器在验证在请求的头字段中给出先决条件时,没能满足其中的一个或多个。这个状态码允许客户端在获取资源时在请求的元信息(请求头字段数据)中设置先决条件,以此避免该请求方法被应用到其希望的内容以外的资源上
|
||||||
|
REQUEST_ENTITY_TOO_LARGE: 413, //服务器拒绝处理当前请求,因为该请求提交的实体数据大小超过了服务器愿意或者能够处理的范围。此种情况下,服务器可以关闭连接以免客户端继续发送此请求。如果这个状况是临时的,服务器应当返回一个 Retry-After 的响应头,以告知客户端可以在多少时间以后重新尝试
|
||||||
|
REQUEST_URI_TOO_LONG: 414, //请求的URI长度超过了服务器能够解释的长度,因此服务器拒绝对该请求提供服务。这比较少见,通常的情况包括:本应使用POST方法的表单提交变成了GET方法,导致查询字符串(Query String)过长。重定向URI “黑洞”,例如每次重定向把旧的URI作为新的URI的一部分,导致在若干次重定向后URI超长。客户端正在尝试利用某些服务器中存在的安全漏洞攻击服务器。这类服务器使用固定长度的缓冲读取或操作请求的URI,当GET后的参数超过某个数值后,可能会产生缓冲区溢出,导致任意代码被执行[1]。没有此类漏洞的服务器,应当返回414状态码
|
||||||
|
UNSUPPORTED_MEDIA_TYPE: 415, //对于当前请求的方法和所请求的资源,请求中提交的实体并不是服务器中所支持的格式,因此请求被拒绝
|
||||||
|
REQUESTED_RANGE_NOT_SATISFIABLE: 416, //如果请求中包含了Range请求头,并且Range中指定的任何数据范围都与当前资源的可用范围不重合,同时请求中又没有定义If-Range请求头,那么服务器就应当返回416状态码。假如Range使用的是字节范围,那么这种情况就是指请求指定的所有数据范围的首字节位置都超过了当前资源的长度。服务器也应当在返回416状态码的同时,包含一个Content-Range实体头,用以指明当前资源的长度。这个响应也被禁止使用multipart/byteranges作为其 Content-Type
|
||||||
|
EXPECTION_FAILED: 417, //在请求头Expect中指定的预期内容无法被服务器满足,或者这个服务器是一个代理服务器,它有明显的证据证明在当前路由的下一个节点上,Expect的内容无法被满足
|
||||||
|
TOO_MANY_CONNECTIONS: 421, //从当前客户端所在的IP地址到服务器的连接数超过了服务器许可的最大范围。通常,这里的IP地址指的是从服务器上看到的客户端地址(比如用户的网关或者代理服务器地址)。在这种情况下,连接数的计算可能涉及到不止一个终端用户
|
||||||
|
UNPROCESSABLE_ENTITY: 422, //请求格式正确,但是由于含有语义错误,无法响应
|
||||||
|
FAILED_DEPENDENCY: 424, //由于之前的某个请求发生的错误,导致当前请求失败,例如PROPPATCH
|
||||||
|
UNORDERED_COLLECTION: 425, //在WebDav Advanced Collections 草案中定义,但是未出现在《WebDAV 顺序集协议》(RFC 3658)中
|
||||||
|
UPGRADE_REQUIRED: 426, //客户端应当切换到TLS/1.0
|
||||||
|
RETRY_WITH: 449, //由微软扩展,代表请求应当在执行完适当的操作后进行重试
|
||||||
|
|
||||||
|
INTERNAL_SERVER_ERROR: 500, //服务器遇到了一个未曾预料的状况,导致了它无法完成对请求的处理。一般来说,这个问题都会在服务器的程序码出错时出现
|
||||||
|
NOT_IMPLEMENTED: 501, //服务器不支持当前请求所需要的某个功能。当服务器无法识别请求的方法,并且无法支持其对任何资源的请求
|
||||||
|
BAD_GATEWAY: 502, //作为网关或者代理工作的服务器尝试执行请求时,从上游服务器接收到无效的响应
|
||||||
|
SERVICE_UNAVAILABLE: 503, //由于临时的服务器维护或者过载,服务器当前无法处理请求。这个状况是临时的,并且将在一段时间以后恢复。如果能够预计延迟时间,那么响应中可以包含一个 Retry-After 头用以标明这个延迟时间。如果没有给出这个 Retry-After 信息,那么客户端应当以处理500响应的方式处理它。注意:503状态码的存在并不意味着服务器在过载的时候必须使用它。某些服务器只不过是希望拒绝客户端的连接
|
||||||
|
GATEWAY_TIMEOUT: 504, //作为网关或者代理工作的服务器尝试执行请求时,未能及时从上游服务器(URI标识出的服务器,例如HTTP、FTP、LDAP)或者辅助服务器(例如DNS)收到响应。注意:某些代理服务器在DNS查询超时时会返回400或者500错误
|
||||||
|
HTTP_VERSION_NOT_SUPPORTED: 505, //服务器不支持,或者拒绝支持在请求中使用的HTTP版本。这暗示着服务器不能或不愿使用与客户端相同的版本。响应中应当包含一个描述了为何版本不被支持以及服务器支持哪些协议的实体
|
||||||
|
VARIANT_ALSO_NEGOTIATES: 506, //服务器存在内部配置错误:被请求的协商变元资源被配置为在透明内容协商中使用自己,因此在一个协商处理中不是一个合适的重点
|
||||||
|
INSUFFICIENT_STORAGE: 507, //服务器无法存储完成请求所必须的内容。这个状况被认为是临时的
|
||||||
|
BANDWIDTH_LIMIT_EXCEEDED: 509, //服务器达到带宽限制。这不是一个官方的状态码,但是仍被广泛使用
|
||||||
|
NOT_EXTENDED: 510 //获取资源所需要的策略并没有没满足
|
||||||
|
|
||||||
|
};
|
||||||
28
src/lib/initialize.ts
Normal file
28
src/lib/initialize.ts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import logger from './logger.js';
|
||||||
|
|
||||||
|
// 允许无限量的监听器
|
||||||
|
process.setMaxListeners(Infinity);
|
||||||
|
// 输出未捕获异常
|
||||||
|
process.on("uncaughtException", (err, origin) => {
|
||||||
|
logger.error(`An unhandled error occurred: ${origin}`, err);
|
||||||
|
});
|
||||||
|
// 输出未处理的Promise.reject
|
||||||
|
process.on("unhandledRejection", (_, promise) => {
|
||||||
|
promise.catch(err => logger.error("An unhandled rejection occurred:", err));
|
||||||
|
});
|
||||||
|
// 输出系统警告信息
|
||||||
|
process.on("warning", warning => logger.warn("System warning: ", warning));
|
||||||
|
// 进程退出监听
|
||||||
|
process.on("exit", () => {
|
||||||
|
logger.info("Service exit");
|
||||||
|
logger.footer();
|
||||||
|
});
|
||||||
|
// 进程被kill
|
||||||
|
process.on("SIGTERM", () => {
|
||||||
|
logger.warn("received kill signal");
|
||||||
|
process.exit(2);
|
||||||
|
});
|
||||||
|
// Ctrl-C进程退出
|
||||||
|
process.on("SIGINT", () => {
|
||||||
|
process.exit(0);
|
||||||
|
});
|
||||||
4
src/lib/interfaces/ICompletionMessage.ts
Normal file
4
src/lib/interfaces/ICompletionMessage.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export default interface ICompletionMessage {
|
||||||
|
role: 'system' | 'assistant' | 'user' | 'function';
|
||||||
|
content: string;
|
||||||
|
}
|
||||||
184
src/lib/logger.ts
Normal file
184
src/lib/logger.ts
Normal file
@ -0,0 +1,184 @@
|
|||||||
|
import path from 'path';
|
||||||
|
import _util from 'util';
|
||||||
|
|
||||||
|
import 'colors';
|
||||||
|
import _ from 'lodash';
|
||||||
|
import fs from 'fs-extra';
|
||||||
|
import { format as dateFormat } from 'date-fns';
|
||||||
|
|
||||||
|
import config from './config.ts';
|
||||||
|
import util from './util.ts';
|
||||||
|
|
||||||
|
const isVercelEnv = process.env.VERCEL;
|
||||||
|
|
||||||
|
class LogWriter {
|
||||||
|
|
||||||
|
#buffers = [];
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
!isVercelEnv && fs.ensureDirSync(config.system.logDirPath);
|
||||||
|
!isVercelEnv && this.work();
|
||||||
|
}
|
||||||
|
|
||||||
|
push(content) {
|
||||||
|
const buffer = Buffer.from(content);
|
||||||
|
this.#buffers.push(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
writeSync(buffer) {
|
||||||
|
!isVercelEnv && fs.appendFileSync(path.join(config.system.logDirPath, `/${util.getDateString()}.log`), buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
async write(buffer) {
|
||||||
|
!isVercelEnv && await fs.appendFile(path.join(config.system.logDirPath, `/${util.getDateString()}.log`), buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
flush() {
|
||||||
|
if(!this.#buffers.length) return;
|
||||||
|
!isVercelEnv && fs.appendFileSync(path.join(config.system.logDirPath, `/${util.getDateString()}.log`), Buffer.concat(this.#buffers));
|
||||||
|
}
|
||||||
|
|
||||||
|
work() {
|
||||||
|
if (!this.#buffers.length) return setTimeout(this.work.bind(this), config.system.logWriteInterval);
|
||||||
|
const buffer = Buffer.concat(this.#buffers);
|
||||||
|
this.#buffers = [];
|
||||||
|
this.write(buffer)
|
||||||
|
.finally(() => setTimeout(this.work.bind(this), config.system.logWriteInterval))
|
||||||
|
.catch(err => console.error("Log write error:", err));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class LogText {
|
||||||
|
|
||||||
|
/** @type {string} 日志级别 */
|
||||||
|
level;
|
||||||
|
/** @type {string} 日志文本 */
|
||||||
|
text;
|
||||||
|
/** @type {string} 日志来源 */
|
||||||
|
source;
|
||||||
|
/** @type {Date} 日志发生时间 */
|
||||||
|
time = new Date();
|
||||||
|
|
||||||
|
constructor(level, ...params) {
|
||||||
|
this.level = level;
|
||||||
|
this.text = _util.format.apply(null, params);
|
||||||
|
this.source = this.#getStackTopCodeInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
#getStackTopCodeInfo() {
|
||||||
|
const unknownInfo = { name: "unknown", codeLine: 0, codeColumn: 0 };
|
||||||
|
const stackArray = new Error().stack.split("\n");
|
||||||
|
const text = stackArray[4];
|
||||||
|
if (!text)
|
||||||
|
return unknownInfo;
|
||||||
|
const match = text.match(/at (.+) \((.+)\)/) || text.match(/at (.+)/);
|
||||||
|
if (!match || !_.isString(match[2] || match[1]))
|
||||||
|
return unknownInfo;
|
||||||
|
const temp = match[2] || match[1];
|
||||||
|
const _match = temp.match(/([a-zA-Z0-9_\-\.]+)\:(\d+)\:(\d+)$/);
|
||||||
|
if (!_match)
|
||||||
|
return unknownInfo;
|
||||||
|
const [, scriptPath, codeLine, codeColumn] = _match as any;
|
||||||
|
return {
|
||||||
|
name: scriptPath ? scriptPath.replace(/.js$/, "") : "unknown",
|
||||||
|
path: scriptPath || null,
|
||||||
|
codeLine: parseInt(codeLine || 0),
|
||||||
|
codeColumn: parseInt(codeColumn || 0)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
toString() {
|
||||||
|
return `[${dateFormat(this.time, "yyyy-MM-dd HH:mm:ss.SSS")}][${this.level}][${this.source.name}<${this.source.codeLine},${this.source.codeColumn}>] ${this.text}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Logger {
|
||||||
|
|
||||||
|
/** @type {Object} 系统配置 */
|
||||||
|
config = {};
|
||||||
|
/** @type {Object} 日志级别映射 */
|
||||||
|
static Level = {
|
||||||
|
Success: "success",
|
||||||
|
Info: "info",
|
||||||
|
Log: "log",
|
||||||
|
Debug: "debug",
|
||||||
|
Warning: "warning",
|
||||||
|
Error: "error",
|
||||||
|
Fatal: "fatal"
|
||||||
|
};
|
||||||
|
/** @type {Object} 日志级别文本颜色樱色 */
|
||||||
|
static LevelColor = {
|
||||||
|
[Logger.Level.Success]: "green",
|
||||||
|
[Logger.Level.Info]: "brightCyan",
|
||||||
|
[Logger.Level.Debug]: "white",
|
||||||
|
[Logger.Level.Warning]: "brightYellow",
|
||||||
|
[Logger.Level.Error]: "brightRed",
|
||||||
|
[Logger.Level.Fatal]: "red"
|
||||||
|
};
|
||||||
|
#writer;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.#writer = new LogWriter();
|
||||||
|
}
|
||||||
|
|
||||||
|
header() {
|
||||||
|
this.#writer.writeSync(Buffer.from(`\n\n===================== LOG START ${dateFormat(new Date(), "yyyy-MM-dd HH:mm:ss.SSS")} =====================\n\n`));
|
||||||
|
}
|
||||||
|
|
||||||
|
footer() {
|
||||||
|
this.#writer.flush(); //将未写入文件的日志缓存写入
|
||||||
|
this.#writer.writeSync(Buffer.from(`\n\n===================== LOG END ${dateFormat(new Date(), "yyyy-MM-dd HH:mm:ss.SSS")} =====================\n\n`));
|
||||||
|
}
|
||||||
|
|
||||||
|
success(...params) {
|
||||||
|
const content = new LogText(Logger.Level.Success, ...params).toString();
|
||||||
|
console.info(content[Logger.LevelColor[Logger.Level.Success]]);
|
||||||
|
this.#writer.push(content + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
info(...params) {
|
||||||
|
const content = new LogText(Logger.Level.Info, ...params).toString();
|
||||||
|
console.info(content[Logger.LevelColor[Logger.Level.Info]]);
|
||||||
|
this.#writer.push(content + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
log(...params) {
|
||||||
|
const content = new LogText(Logger.Level.Log, ...params).toString();
|
||||||
|
console.log(content[Logger.LevelColor[Logger.Level.Log]]);
|
||||||
|
this.#writer.push(content + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
debug(...params) {
|
||||||
|
if(!config.system.debug) return; //非调试模式忽略debug
|
||||||
|
const content = new LogText(Logger.Level.Debug, ...params).toString();
|
||||||
|
console.debug(content[Logger.LevelColor[Logger.Level.Debug]]);
|
||||||
|
this.#writer.push(content + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
warn(...params) {
|
||||||
|
const content = new LogText(Logger.Level.Warning, ...params).toString();
|
||||||
|
console.warn(content[Logger.LevelColor[Logger.Level.Warning]]);
|
||||||
|
this.#writer.push(content + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
error(...params) {
|
||||||
|
const content = new LogText(Logger.Level.Error, ...params).toString();
|
||||||
|
console.error(content[Logger.LevelColor[Logger.Level.Error]]);
|
||||||
|
this.#writer.push(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
fatal(...params) {
|
||||||
|
const content = new LogText(Logger.Level.Fatal, ...params).toString();
|
||||||
|
console.error(content[Logger.LevelColor[Logger.Level.Fatal]]);
|
||||||
|
this.#writer.push(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
destory() {
|
||||||
|
this.#writer.destory();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new Logger();
|
||||||
72
src/lib/request/Request.ts
Normal file
72
src/lib/request/Request.ts
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
import APIException from '@/lib/exceptions/APIException.ts';
|
||||||
|
import EX from '@/api/consts/exceptions.ts';
|
||||||
|
import logger from '@/lib/logger.ts';
|
||||||
|
import util from '@/lib/util.ts';
|
||||||
|
|
||||||
|
export interface RequestOptions {
|
||||||
|
time?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class Request {
|
||||||
|
|
||||||
|
/** 请求方法 */
|
||||||
|
method: string;
|
||||||
|
/** 请求URL */
|
||||||
|
url: string;
|
||||||
|
/** 请求路径 */
|
||||||
|
path: string;
|
||||||
|
/** 请求载荷类型 */
|
||||||
|
type: string;
|
||||||
|
/** 请求headers */
|
||||||
|
headers: any;
|
||||||
|
/** 请求原始查询字符串 */
|
||||||
|
search: string;
|
||||||
|
/** 请求查询参数 */
|
||||||
|
query: any;
|
||||||
|
/** 请求URL参数 */
|
||||||
|
params: any;
|
||||||
|
/** 请求载荷 */
|
||||||
|
body: any;
|
||||||
|
/** 上传的文件 */
|
||||||
|
files: any[];
|
||||||
|
/** 客户端IP地址 */
|
||||||
|
remoteIP: string | null;
|
||||||
|
/** 请求接受时间戳(毫秒) */
|
||||||
|
time: number;
|
||||||
|
|
||||||
|
constructor(ctx, options: RequestOptions = {}) {
|
||||||
|
const { time } = options;
|
||||||
|
this.method = ctx.request.method;
|
||||||
|
this.url = ctx.request.url;
|
||||||
|
this.path = ctx.request.path;
|
||||||
|
this.type = ctx.request.type;
|
||||||
|
this.headers = ctx.request.headers || {};
|
||||||
|
this.search = ctx.request.search;
|
||||||
|
this.query = ctx.query || {};
|
||||||
|
this.params = ctx.params || {};
|
||||||
|
this.body = ctx.request.body || {};
|
||||||
|
this.files = ctx.request.files || {};
|
||||||
|
this.remoteIP = this.headers["X-Real-IP"] || this.headers["x-real-ip"] || this.headers["X-Forwarded-For"] || this.headers["x-forwarded-for"] || ctx.ip || null;
|
||||||
|
this.time = Number(_.defaultTo(time, util.timestamp()));
|
||||||
|
}
|
||||||
|
|
||||||
|
validate(key: string, fn?: Function, message?: string) {
|
||||||
|
try {
|
||||||
|
const value = _.get(this, key);
|
||||||
|
if (fn) {
|
||||||
|
if (fn(value) === false)
|
||||||
|
throw `[Mismatch] -> ${fn}`;
|
||||||
|
}
|
||||||
|
else if (_.isUndefined(value))
|
||||||
|
throw '[Undefined]';
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
logger.warn(`Params ${key} invalid:`, err);
|
||||||
|
throw new APIException(EX.API_REQUEST_PARAMS_INVALID, message || `Params ${key} invalid`);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
41
src/lib/response/Body.ts
Normal file
41
src/lib/response/Body.ts
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
export interface BodyOptions {
|
||||||
|
code?: number;
|
||||||
|
message?: string;
|
||||||
|
data?: any;
|
||||||
|
statusCode?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class Body {
|
||||||
|
|
||||||
|
/** 状态码 */
|
||||||
|
code: number;
|
||||||
|
/** 状态消息 */
|
||||||
|
message: string;
|
||||||
|
/** 载荷 */
|
||||||
|
data: any;
|
||||||
|
/** HTTP状态码 */
|
||||||
|
statusCode: number;
|
||||||
|
|
||||||
|
constructor(options: BodyOptions = {}) {
|
||||||
|
const { code, message, data, statusCode } = options;
|
||||||
|
this.code = Number(_.defaultTo(code, 0));
|
||||||
|
this.message = _.defaultTo(message, 'OK');
|
||||||
|
this.data = _.defaultTo(data, null);
|
||||||
|
this.statusCode = Number(_.defaultTo(statusCode, 200));
|
||||||
|
}
|
||||||
|
|
||||||
|
toObject() {
|
||||||
|
return {
|
||||||
|
code: this.code,
|
||||||
|
message: this.message,
|
||||||
|
data: this.data
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static isInstance(value) {
|
||||||
|
return value instanceof Body;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
31
src/lib/response/FailureBody.ts
Normal file
31
src/lib/response/FailureBody.ts
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
import Body from './Body.ts';
|
||||||
|
import Exception from '../exceptions/Exception.ts';
|
||||||
|
import APIException from '../exceptions/APIException.ts';
|
||||||
|
import EX from '../consts/exceptions.ts';
|
||||||
|
import HTTP_STATUS_CODES from '../http-status-codes.ts';
|
||||||
|
|
||||||
|
export default class FailureBody extends Body {
|
||||||
|
|
||||||
|
constructor(error: APIException | Exception | Error, _data?: any) {
|
||||||
|
let errcode, errmsg, data = _data, httpStatusCode = HTTP_STATUS_CODES.OK;;
|
||||||
|
if(_.isString(error))
|
||||||
|
error = new Exception(EX.SYSTEM_ERROR, error);
|
||||||
|
else if(error instanceof APIException || error instanceof Exception)
|
||||||
|
({ errcode, errmsg, data, httpStatusCode } = error);
|
||||||
|
else if(_.isError(error))
|
||||||
|
({ errcode, errmsg, data, httpStatusCode } = new Exception(EX.SYSTEM_ERROR, error.message));
|
||||||
|
super({
|
||||||
|
code: errcode || -1,
|
||||||
|
message: errmsg || 'Internal error',
|
||||||
|
data,
|
||||||
|
statusCode: httpStatusCode
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static isInstance(value) {
|
||||||
|
return value instanceof FailureBody;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
63
src/lib/response/Response.ts
Normal file
63
src/lib/response/Response.ts
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
import mime from 'mime';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
import Body from './Body.ts';
|
||||||
|
import util from '../util.ts';
|
||||||
|
|
||||||
|
export interface ResponseOptions {
|
||||||
|
statusCode?: number;
|
||||||
|
type?: string;
|
||||||
|
headers?: Record<string, any>;
|
||||||
|
redirect?: string;
|
||||||
|
body?: any;
|
||||||
|
size?: number;
|
||||||
|
time?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class Response {
|
||||||
|
|
||||||
|
/** 响应HTTP状态码 */
|
||||||
|
statusCode: number;
|
||||||
|
/** 响应内容类型 */
|
||||||
|
type: string;
|
||||||
|
/** 响应headers */
|
||||||
|
headers: Record<string, any>;
|
||||||
|
/** 重定向目标 */
|
||||||
|
redirect: string;
|
||||||
|
/** 响应载荷 */
|
||||||
|
body: any;
|
||||||
|
/** 响应载荷大小 */
|
||||||
|
size: number;
|
||||||
|
/** 响应时间戳 */
|
||||||
|
time: number;
|
||||||
|
|
||||||
|
constructor(body: any, options: ResponseOptions = {}) {
|
||||||
|
const { statusCode, type, headers, redirect, size, time } = options;
|
||||||
|
this.statusCode = Number(_.defaultTo(statusCode, Body.isInstance(body) ? body.statusCode : undefined))
|
||||||
|
this.type = type;
|
||||||
|
this.headers = headers;
|
||||||
|
this.redirect = redirect;
|
||||||
|
this.size = size;
|
||||||
|
this.time = Number(_.defaultTo(time, util.timestamp()));
|
||||||
|
this.body = body;
|
||||||
|
}
|
||||||
|
|
||||||
|
injectTo(ctx) {
|
||||||
|
this.redirect && ctx.redirect(this.redirect);
|
||||||
|
this.statusCode && (ctx.status = this.statusCode);
|
||||||
|
this.type && (ctx.type = mime.getType(this.type) || this.type);
|
||||||
|
const headers = this.headers || {};
|
||||||
|
if(this.size && !headers["Content-Length"] && !headers["content-length"])
|
||||||
|
headers["Content-Length"] = this.size;
|
||||||
|
ctx.set(headers);
|
||||||
|
if(Body.isInstance(this.body))
|
||||||
|
ctx.body = this.body.toObject();
|
||||||
|
else
|
||||||
|
ctx.body = this.body;
|
||||||
|
}
|
||||||
|
|
||||||
|
static isInstance(value) {
|
||||||
|
return value instanceof Response;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
19
src/lib/response/SuccessfulBody.ts
Normal file
19
src/lib/response/SuccessfulBody.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
import Body from './Body.ts';
|
||||||
|
|
||||||
|
export default class SuccessfulBody extends Body {
|
||||||
|
|
||||||
|
constructor(data: any, message?: string) {
|
||||||
|
super({
|
||||||
|
code: 0,
|
||||||
|
message: _.defaultTo(message, "OK"),
|
||||||
|
data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static isInstance(value) {
|
||||||
|
return value instanceof SuccessfulBody;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
173
src/lib/server.ts
Normal file
173
src/lib/server.ts
Normal file
@ -0,0 +1,173 @@
|
|||||||
|
import Koa from 'koa';
|
||||||
|
import KoaRouter from 'koa-router';
|
||||||
|
import koaRange from 'koa-range';
|
||||||
|
import koaCors from "koa2-cors";
|
||||||
|
import koaBody from 'koa-body';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
import Exception from './exceptions/Exception.ts';
|
||||||
|
import Request from './request/Request.ts';
|
||||||
|
import Response from './response/Response.js';
|
||||||
|
import FailureBody from './response/FailureBody.ts';
|
||||||
|
import EX from './consts/exceptions.ts';
|
||||||
|
import logger from './logger.ts';
|
||||||
|
import config from './config.ts';
|
||||||
|
|
||||||
|
class Server {
|
||||||
|
|
||||||
|
app;
|
||||||
|
router;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.app = new Koa();
|
||||||
|
this.app.use(koaCors());
|
||||||
|
// 范围请求支持
|
||||||
|
this.app.use(koaRange);
|
||||||
|
this.router = new KoaRouter({ prefix: config.service.urlPrefix });
|
||||||
|
// 前置处理异常拦截
|
||||||
|
this.app.use(async (ctx: any, next: Function) => {
|
||||||
|
if(ctx.request.type === "application/xml" || ctx.request.type === "application/ssml+xml")
|
||||||
|
ctx.req.headers["content-type"] = "text/xml";
|
||||||
|
try { await next() }
|
||||||
|
catch (err) {
|
||||||
|
logger.error(err);
|
||||||
|
const failureBody = new FailureBody(err);
|
||||||
|
new Response(failureBody).injectTo(ctx);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// 载荷解析器支持
|
||||||
|
this.app.use(koaBody(_.clone(config.system.requestBody)));
|
||||||
|
this.app.on("error", (err: any) => {
|
||||||
|
// 忽略连接重试、中断、管道、取消错误
|
||||||
|
if (["ECONNRESET", "ECONNABORTED", "EPIPE", "ECANCELED"].includes(err.code)) return;
|
||||||
|
logger.error(err);
|
||||||
|
});
|
||||||
|
logger.success("Server initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 附加路由
|
||||||
|
*
|
||||||
|
* @param routes 路由列表
|
||||||
|
*/
|
||||||
|
attachRoutes(routes: any[]) {
|
||||||
|
routes.forEach((route: any) => {
|
||||||
|
const prefix = route.prefix || "";
|
||||||
|
for (let method in route) {
|
||||||
|
if(method === "prefix") continue;
|
||||||
|
if (!_.isObject(route[method])) {
|
||||||
|
logger.warn(`Router ${prefix} ${method} invalid`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (let uri in route[method]) {
|
||||||
|
this.router[method](`${prefix}${uri}`, async ctx => {
|
||||||
|
const { request, response } = await this.#requestProcessing(ctx, route[method][uri]);
|
||||||
|
if(response != null && config.system.requestLog)
|
||||||
|
logger.info(`<- ${request.method} ${request.url} ${response.time - request.time}ms`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logger.info(`Route ${config.service.urlPrefix || ""}${prefix} attached`);
|
||||||
|
});
|
||||||
|
this.app.use(this.router.routes());
|
||||||
|
this.app.use((ctx: any) => {
|
||||||
|
const request = new Request(ctx);
|
||||||
|
logger.debug(`-> ${ctx.request.method} ${ctx.request.url} request is not supported - ${request.remoteIP || "unknown"}`);
|
||||||
|
// const failureBody = new FailureBody(new Exception(EX.SYSTEM_NOT_ROUTE_MATCHING, "Request is not supported"));
|
||||||
|
// const response = new Response(failureBody);
|
||||||
|
const message = `[请求有误]: 正确请求为 POST -> /v1/chat/completions,当前请求为 ${ctx.request.method} -> ${ctx.request.url} 请纠正`;
|
||||||
|
logger.warn(message);
|
||||||
|
const failureBody = new FailureBody(new Error(message));
|
||||||
|
const response = new Response(failureBody);
|
||||||
|
response.injectTo(ctx);
|
||||||
|
if(config.system.requestLog)
|
||||||
|
logger.info(`<- ${request.method} ${request.url} ${response.time - request.time}ms`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求处理
|
||||||
|
*
|
||||||
|
* @param ctx 上下文
|
||||||
|
* @param routeFn 路由方法
|
||||||
|
*/
|
||||||
|
#requestProcessing(ctx: any, routeFn: Function): Promise<any> {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
const request = new Request(ctx);
|
||||||
|
try {
|
||||||
|
if(config.system.requestLog)
|
||||||
|
logger.info(`-> ${request.method} ${request.url}`);
|
||||||
|
routeFn(request)
|
||||||
|
.then(response => {
|
||||||
|
try {
|
||||||
|
if(!Response.isInstance(response)) {
|
||||||
|
const _response = new Response(response);
|
||||||
|
_response.injectTo(ctx);
|
||||||
|
return resolve({ request, response: _response });
|
||||||
|
}
|
||||||
|
response.injectTo(ctx);
|
||||||
|
resolve({ request, response });
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
logger.error(err);
|
||||||
|
const failureBody = new FailureBody(err);
|
||||||
|
const response = new Response(failureBody);
|
||||||
|
response.injectTo(ctx);
|
||||||
|
resolve({ request, response });
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
try {
|
||||||
|
logger.error(err);
|
||||||
|
const failureBody = new FailureBody(err);
|
||||||
|
const response = new Response(failureBody);
|
||||||
|
response.injectTo(ctx);
|
||||||
|
resolve({ request, response });
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
logger.error(err);
|
||||||
|
const failureBody = new FailureBody(err);
|
||||||
|
const response = new Response(failureBody);
|
||||||
|
response.injectTo(ctx);
|
||||||
|
resolve({ request, response });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
logger.error(err);
|
||||||
|
const failureBody = new FailureBody(err);
|
||||||
|
const response = new Response(failureBody);
|
||||||
|
response.injectTo(ctx);
|
||||||
|
resolve({ request, response });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 监听端口
|
||||||
|
*/
|
||||||
|
async listen() {
|
||||||
|
const host = config.service.host;
|
||||||
|
const port = config.service.port;
|
||||||
|
await Promise.all([
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
if(host === "0.0.0.0" || host === "localhost" || host === "127.0.0.1")
|
||||||
|
return resolve(null);
|
||||||
|
this.app.listen(port, "localhost", err => {
|
||||||
|
if(err) return reject(err);
|
||||||
|
resolve(null);
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
this.app.listen(port, host, err => {
|
||||||
|
if(err) return reject(err);
|
||||||
|
resolve(null);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
logger.success(`Server listening on port ${port} (${host})`);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new Server();
|
||||||
307
src/lib/util.ts
Normal file
307
src/lib/util.ts
Normal file
@ -0,0 +1,307 @@
|
|||||||
|
import os from "os";
|
||||||
|
import path from "path";
|
||||||
|
import crypto from "crypto";
|
||||||
|
import { Readable, Writable } from "stream";
|
||||||
|
|
||||||
|
import "colors";
|
||||||
|
import mime from "mime";
|
||||||
|
import axios from "axios";
|
||||||
|
import fs from "fs-extra";
|
||||||
|
import { v1 as uuid } from "uuid";
|
||||||
|
import { format as dateFormat } from "date-fns";
|
||||||
|
import CRC32 from "crc-32";
|
||||||
|
import randomstring from "randomstring";
|
||||||
|
import _ from "lodash";
|
||||||
|
import { CronJob } from "cron";
|
||||||
|
|
||||||
|
import HTTP_STATUS_CODE from "./http-status-codes.ts";
|
||||||
|
|
||||||
|
const autoIdMap = new Map();
|
||||||
|
|
||||||
|
const util = {
|
||||||
|
is2DArrays(value: any) {
|
||||||
|
return (
|
||||||
|
_.isArray(value) &&
|
||||||
|
(!value[0] || (_.isArray(value[0]) && _.isArray(value[value.length - 1])))
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
uuid: (separator = true) => (separator ? uuid() : uuid().replace(/\-/g, "")),
|
||||||
|
|
||||||
|
autoId: (prefix = "") => {
|
||||||
|
let index = autoIdMap.get(prefix);
|
||||||
|
if (index > 999999) index = 0; //超过最大数字则重置为0
|
||||||
|
autoIdMap.set(prefix, (index || 0) + 1);
|
||||||
|
return `${prefix}${index || 1}`;
|
||||||
|
},
|
||||||
|
|
||||||
|
ignoreJSONParse(value: string) {
|
||||||
|
const result = _.attempt(() => JSON.parse(value));
|
||||||
|
if (_.isError(result)) return null;
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
|
||||||
|
generateRandomString(options: any): string {
|
||||||
|
return randomstring.generate(options);
|
||||||
|
},
|
||||||
|
|
||||||
|
getResponseContentType(value: any): string | null {
|
||||||
|
return value.headers
|
||||||
|
? value.headers["content-type"] || value.headers["Content-Type"]
|
||||||
|
: null;
|
||||||
|
},
|
||||||
|
|
||||||
|
mimeToExtension(value: string) {
|
||||||
|
let extension = mime.getExtension(value);
|
||||||
|
if (extension == "mpga") return "mp3";
|
||||||
|
return extension;
|
||||||
|
},
|
||||||
|
|
||||||
|
extractURLExtension(value: string) {
|
||||||
|
const extname = path.extname(new URL(value).pathname);
|
||||||
|
return extname.substring(1).toLowerCase();
|
||||||
|
},
|
||||||
|
|
||||||
|
createCronJob(cronPatterns: any, callback?: Function) {
|
||||||
|
if (!_.isFunction(callback))
|
||||||
|
throw new Error("callback must be an Function");
|
||||||
|
return new CronJob(
|
||||||
|
cronPatterns,
|
||||||
|
() => callback(),
|
||||||
|
null,
|
||||||
|
false,
|
||||||
|
"Asia/Shanghai"
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
getDateString(format = "yyyy-MM-dd", date = new Date()) {
|
||||||
|
return dateFormat(date, format);
|
||||||
|
},
|
||||||
|
|
||||||
|
getIPAddressesByIPv4(): string[] {
|
||||||
|
const interfaces = os.networkInterfaces();
|
||||||
|
const addresses = [];
|
||||||
|
for (let name in interfaces) {
|
||||||
|
const networks = interfaces[name];
|
||||||
|
const results = networks.filter(
|
||||||
|
(network) =>
|
||||||
|
network.family === "IPv4" &&
|
||||||
|
network.address !== "127.0.0.1" &&
|
||||||
|
!network.internal
|
||||||
|
);
|
||||||
|
if (results[0] && results[0].address) addresses.push(results[0].address);
|
||||||
|
}
|
||||||
|
return addresses;
|
||||||
|
},
|
||||||
|
|
||||||
|
getMACAddressesByIPv4(): string[] {
|
||||||
|
const interfaces = os.networkInterfaces();
|
||||||
|
const addresses = [];
|
||||||
|
for (let name in interfaces) {
|
||||||
|
const networks = interfaces[name];
|
||||||
|
const results = networks.filter(
|
||||||
|
(network) =>
|
||||||
|
network.family === "IPv4" &&
|
||||||
|
network.address !== "127.0.0.1" &&
|
||||||
|
!network.internal
|
||||||
|
);
|
||||||
|
if (results[0] && results[0].mac) addresses.push(results[0].mac);
|
||||||
|
}
|
||||||
|
return addresses;
|
||||||
|
},
|
||||||
|
|
||||||
|
generateSSEData(event?: string, data?: string, retry?: number) {
|
||||||
|
return `event: ${event || "message"}\ndata: ${(data || "")
|
||||||
|
.replace(/\n/g, "\\n")
|
||||||
|
.replace(/\s/g, "\\s")}\nretry: ${retry || 3000}\n\n`;
|
||||||
|
},
|
||||||
|
|
||||||
|
buildDataBASE64(type, ext, buffer) {
|
||||||
|
return `data:${type}/${ext.replace("jpg", "jpeg")};base64,${buffer.toString(
|
||||||
|
"base64"
|
||||||
|
)}`;
|
||||||
|
},
|
||||||
|
|
||||||
|
isLinux() {
|
||||||
|
return os.platform() !== "win32";
|
||||||
|
},
|
||||||
|
|
||||||
|
isIPAddress(value) {
|
||||||
|
return (
|
||||||
|
_.isString(value) &&
|
||||||
|
(/^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$/.test(
|
||||||
|
value
|
||||||
|
) ||
|
||||||
|
/\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*/.test(
|
||||||
|
value
|
||||||
|
))
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
isPort(value) {
|
||||||
|
return _.isNumber(value) && value > 0 && value < 65536;
|
||||||
|
},
|
||||||
|
|
||||||
|
isReadStream(value): boolean {
|
||||||
|
return (
|
||||||
|
value &&
|
||||||
|
(value instanceof Readable || "readable" in value || value.readable)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
isWriteStream(value): boolean {
|
||||||
|
return (
|
||||||
|
value &&
|
||||||
|
(value instanceof Writable || "writable" in value || value.writable)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
isHttpStatusCode(value) {
|
||||||
|
return _.isNumber(value) && Object.values(HTTP_STATUS_CODE).includes(value);
|
||||||
|
},
|
||||||
|
|
||||||
|
isURL(value) {
|
||||||
|
return !_.isUndefined(value) && /^(http|https)/.test(value);
|
||||||
|
},
|
||||||
|
|
||||||
|
isSrc(value) {
|
||||||
|
return !_.isUndefined(value) && /^\/.+\.[0-9a-zA-Z]+(\?.+)?$/.test(value);
|
||||||
|
},
|
||||||
|
|
||||||
|
isBASE64(value) {
|
||||||
|
return !_.isUndefined(value) && /^[a-zA-Z0-9\/\+]+(=?)+$/.test(value);
|
||||||
|
},
|
||||||
|
|
||||||
|
isBASE64Data(value) {
|
||||||
|
return /^data:/.test(value);
|
||||||
|
},
|
||||||
|
|
||||||
|
extractBASE64DataFormat(value): string | null {
|
||||||
|
const match = value.trim().match(/^data:(.+);base64,/);
|
||||||
|
if (!match) return null;
|
||||||
|
return match[1];
|
||||||
|
},
|
||||||
|
|
||||||
|
removeBASE64DataHeader(value): string {
|
||||||
|
return value.replace(/^data:(.+);base64,/, "");
|
||||||
|
},
|
||||||
|
|
||||||
|
isDataString(value): boolean {
|
||||||
|
return /^(base64|json):/.test(value);
|
||||||
|
},
|
||||||
|
|
||||||
|
isStringNumber(value) {
|
||||||
|
return _.isFinite(Number(value));
|
||||||
|
},
|
||||||
|
|
||||||
|
isUnixTimestamp(value) {
|
||||||
|
return /^[0-9]{10}$/.test(`${value}`);
|
||||||
|
},
|
||||||
|
|
||||||
|
isTimestamp(value) {
|
||||||
|
return /^[0-9]{13}$/.test(`${value}`);
|
||||||
|
},
|
||||||
|
|
||||||
|
isEmail(value) {
|
||||||
|
return /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/.test(
|
||||||
|
value
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
isAsyncFunction(value) {
|
||||||
|
return Object.prototype.toString.call(value) === "[object AsyncFunction]";
|
||||||
|
},
|
||||||
|
|
||||||
|
async isAPNG(filePath) {
|
||||||
|
let head;
|
||||||
|
const readStream = fs.createReadStream(filePath, { start: 37, end: 40 });
|
||||||
|
const readPromise = new Promise((resolve, reject) => {
|
||||||
|
readStream.once("end", resolve);
|
||||||
|
readStream.once("error", reject);
|
||||||
|
});
|
||||||
|
readStream.once("data", (data) => (head = data));
|
||||||
|
await readPromise;
|
||||||
|
return head.compare(Buffer.from([0x61, 0x63, 0x54, 0x4c])) === 0;
|
||||||
|
},
|
||||||
|
|
||||||
|
unixTimestamp() {
|
||||||
|
return parseInt(`${Date.now() / 1000}`);
|
||||||
|
},
|
||||||
|
|
||||||
|
timestamp() {
|
||||||
|
return Date.now();
|
||||||
|
},
|
||||||
|
|
||||||
|
urlJoin(...values) {
|
||||||
|
let url = "";
|
||||||
|
for (let i = 0; i < values.length; i++)
|
||||||
|
url += `${i > 0 ? "/" : ""}${values[i]
|
||||||
|
.replace(/^\/*/, "")
|
||||||
|
.replace(/\/*$/, "")}`;
|
||||||
|
return url;
|
||||||
|
},
|
||||||
|
|
||||||
|
millisecondsToHmss(milliseconds) {
|
||||||
|
if (_.isString(milliseconds)) return milliseconds;
|
||||||
|
milliseconds = parseInt(milliseconds);
|
||||||
|
const sec = Math.floor(milliseconds / 1000);
|
||||||
|
const hours = Math.floor(sec / 3600);
|
||||||
|
const minutes = Math.floor((sec - hours * 3600) / 60);
|
||||||
|
const seconds = sec - hours * 3600 - minutes * 60;
|
||||||
|
const ms = (milliseconds % 60000) - seconds * 1000;
|
||||||
|
return `${hours > 9 ? hours : "0" + hours}:${
|
||||||
|
minutes > 9 ? minutes : "0" + minutes
|
||||||
|
}:${seconds > 9 ? seconds : "0" + seconds}.${ms}`;
|
||||||
|
},
|
||||||
|
|
||||||
|
millisecondsToTimeString(milliseconds) {
|
||||||
|
if (milliseconds < 1000) return `${milliseconds}ms`;
|
||||||
|
if (milliseconds < 60000)
|
||||||
|
return `${parseFloat((milliseconds / 1000).toFixed(2))}s`;
|
||||||
|
return `${Math.floor(milliseconds / 1000 / 60)}m${Math.floor(
|
||||||
|
(milliseconds / 1000) % 60
|
||||||
|
)}s`;
|
||||||
|
},
|
||||||
|
|
||||||
|
rgbToHex(r, g, b): string {
|
||||||
|
return ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
|
||||||
|
},
|
||||||
|
|
||||||
|
hexToRgb(hex) {
|
||||||
|
const value = parseInt(hex.replace(/^#/, ""), 16);
|
||||||
|
return [(value >> 16) & 255, (value >> 8) & 255, value & 255];
|
||||||
|
},
|
||||||
|
|
||||||
|
md5(value) {
|
||||||
|
return crypto.createHash("md5").update(value).digest("hex");
|
||||||
|
},
|
||||||
|
|
||||||
|
crc32(value) {
|
||||||
|
return _.isBuffer(value) ? CRC32.buf(value) : CRC32.str(value);
|
||||||
|
},
|
||||||
|
|
||||||
|
arrayParse(value): any[] {
|
||||||
|
return _.isArray(value) ? value : [value];
|
||||||
|
},
|
||||||
|
|
||||||
|
booleanParse(value) {
|
||||||
|
return value === "true" || value === true ? true : false;
|
||||||
|
},
|
||||||
|
|
||||||
|
encodeBASE64(value) {
|
||||||
|
return Buffer.from(value).toString("base64");
|
||||||
|
},
|
||||||
|
|
||||||
|
decodeBASE64(value) {
|
||||||
|
return Buffer.from(value, "base64").toString();
|
||||||
|
},
|
||||||
|
|
||||||
|
async fetchFileBASE64(url: string) {
|
||||||
|
const result = await axios.get(url, {
|
||||||
|
responseType: "arraybuffer",
|
||||||
|
});
|
||||||
|
return result.data.toString("base64");
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default util;
|
||||||
38
temp/1.txt
Normal file
38
temp/1.txt
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
fd240d0ec5a3cc1537b0aa8776e7f911
|
||||||
|
|
||||||
|
|
||||||
|
Bearer fd240d0ec5a3cc1537b0aa8776e7f911
|
||||||
|
|
||||||
|
{
|
||||||
|
"model": "jimeng-3.0",
|
||||||
|
"prompt": "高达在宇宙中飞行",
|
||||||
|
"negativePrompt": "",
|
||||||
|
"width": 1024,
|
||||||
|
"height": 1024,
|
||||||
|
"sample_strength": 0.5
|
||||||
|
}
|
||||||
|
|
||||||
|
"GET
|
||||||
|
/
|
||||||
|
Action=ApplyImageUpload&FileSize=2603128&ServiceId=tb4s082cfz&Version=2018-08-01&s=odorxpjp67n
|
||||||
|
x-amz-date:20250529T162653Z
|
||||||
|
x-amz-security-token:STS2eyJMVEFjY2Vzc0tleUlEIjoiQUtMVFpUQm1ZbVl4TlRsa1ptVmpOREJqWVRrM09UUTNZbU5pTmprMk1EUXdaV00iLCJBY2Nlc3NLZXlJRCI6IkFLVFBPVGN3WkRnNVpXTTFPVEV6TkdFek9UbGhOMkkzWTJKaE5HSXdORGM0TURZIiwiU2lnbmVkU2VjcmV0QWNjZXNzS2V5IjoiVDhFMTd4QmdzVEJheHRHWHlGenhOcXlySnZWb0g3TFFETG44UENQa0czd0VOaVc1OUFGU1VRRDIyTGdHenhkcGlUc1JJMmdtd3Rqd1B2YWRza2VwYVhMV1Z0Vi9rUEQxVEwza2pYcitZSVU9IiwiRXhwaXJlZFRpbWUiOjE3NDg1Mzk2MTEsIlBvbGljeVN0cmluZyI6IntcIlN0YXRlbWVudFwiOlt7XCJFZmZlY3RcIjpcIkFsbG93XCIsXCJBY3Rpb25cIjpbXCJ2b2Q6QXBwbHlVcGxvYWRcIixcInZvZDpBcHBseVVwbG9hZElubmVyXCIsXCJ2b2Q6Q29tbWl0VXBsb2FkXCIsXCJ2b2Q6Q29tbWl0VXBsb2FkSW5uZXJcIixcInZvZDpHZXRVcGxvYWRDYW5kaWRhdGVzXCIsXCJJbWFnZVg6QXBwbHlJbWFnZVVwbG9hZFwiLFwiSW1hZ2VYOkNvbW1pdEltYWdlVXBsb2FkXCIsXCJJbWFnZVg6QXBwbHlVcGxvYWRJbWFnZUZpbGVcIixcIkltYWdlWDpDb21taXRVcGxvYWRJbWFnZUZpbGVcIl0sXCJSZXNvdXJjZVwiOltcIipcIl0sXCJDb25kaXRpb25cIjpcIntcXFwiUFNNXFxcIjpcXFwidmlkZW9jdXQubXdlYi5hcGlcXFwifVwifV19IiwiU2lnbmF0dXJlIjoiMmJiYjdjODQ2NWE2NDhhNGVmMWQ0MTZiYzQ3ZGQ4NjJmMDMyNWM1MDIwNmZkNDI2MGJlZmZjNzM2N2E5YmNhOCJ9
|
||||||
|
|
||||||
|
x-amz-date;x-amz-security-token
|
||||||
|
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||||
|
|
||||||
|
def generateAuthorization(secretAccessKey, region, service, canonical_querystring, amz_date, SessionToken, date_stamp, AccessKeyID):
|
||||||
|
signing_key = getSignatureKey(secretAccessKey, date_stamp, region, service)
|
||||||
|
canonical_headers = 'x-amz-date:' + amz_date + '\n' + 'x-amz-security-token:' + SessionToken + '\n'
|
||||||
|
canonical_request = "GET" + '\n' +
|
||||||
|
"/" + '\n' + canonical_querystring +
|
||||||
|
'\n' + canonical_headers +
|
||||||
|
'\n' + 'x-amz-date;x-amz-security-token' +
|
||||||
|
'\n' + hashlib.sha256("".encode("utf-8")).hexdigest()
|
||||||
|
algorithm = 'AWS4-HMAC-SHA256'
|
||||||
|
credential_scope = date_stamp + '/' + region + '/' + service + '/' + 'aws4_request'
|
||||||
|
string_to_sign = algorithm + '\n' + amz_date + '\n' + credential_scope + '\n' +
|
||||||
|
hashlib.sha256(canonical_request.encode("utf-8")).hexdigest()
|
||||||
|
Signature = hmac.new(signing_key, string_to_sign.encode("utf-8"), hashlib.sha256).hexdigest()
|
||||||
|
data = f"AWS4-HMAC-SHA256 Credential={AccessKeyID}/{date_stamp}/{region}/{service}/aws4_request, SignedHeaders=x-amz-date;x-amz-security-token, Signature={Signature}"
|
||||||
|
return data
|
||||||
1350
temp/2.txt
Normal file
1350
temp/2.txt
Normal file
File diff suppressed because it is too large
Load Diff
961
temp/3.txt
Normal file
961
temp/3.txt
Normal file
@ -0,0 +1,961 @@
|
|||||||
|
{
|
||||||
|
"ret": "0",
|
||||||
|
"errmsg": "success",
|
||||||
|
"systime": "1748504868",
|
||||||
|
"logid": "20250529154748307F1240F9F4DA62E3EE",
|
||||||
|
"data": {
|
||||||
|
"18763140978434": {
|
||||||
|
"generate_type": 10,
|
||||||
|
"history_record_id": "18763140978434",
|
||||||
|
"origin_history_record_id": null,
|
||||||
|
"created_time": 1748504839.742,
|
||||||
|
"item_list": [
|
||||||
|
{
|
||||||
|
"common_attr": {
|
||||||
|
"id": "7509771059025956130",
|
||||||
|
"effect_id": "7509771059025956130",
|
||||||
|
"effect_type": 53,
|
||||||
|
"title": "",
|
||||||
|
"description": "",
|
||||||
|
"cover_url": "https://p3-sign.douyinpic.com/tos-cn-p-148450/oYQvoRhUp4BIwITW4EwGJia0hBRDEiEaEgwdU~tplv-noop.image?dy_q=1748504868\u0026l=20250529154748307F1240F9F4DA62E3EE\u0026x-expires=1749109673\u0026x-signature=K%2FzjpuY%2FXBKVEN0dRqsJfmZqkQo%3D",
|
||||||
|
"item_urls": [
|
||||||
|
""
|
||||||
|
],
|
||||||
|
"md5": "",
|
||||||
|
"create_time": 1748504867,
|
||||||
|
"status": 102,
|
||||||
|
"review_info": {
|
||||||
|
"review_status": 1,
|
||||||
|
"review_code_list": []
|
||||||
|
},
|
||||||
|
"aspect_ratio": 0,
|
||||||
|
"publish_source": "user_post_mweb_item",
|
||||||
|
"collection_ids": [],
|
||||||
|
"extra": "",
|
||||||
|
"has_published": false,
|
||||||
|
"cover_url_map": {},
|
||||||
|
"local_item_id": "7509771059025956130",
|
||||||
|
"update_time": 0,
|
||||||
|
"cover_uri": "tos-cn-p-148450/oYQvoRhUp4BIwITW4EwGJia0hBRDEiEaEgwdU",
|
||||||
|
"smart_crop_loc": null,
|
||||||
|
"cover_height": 0,
|
||||||
|
"cover_width": 0
|
||||||
|
},
|
||||||
|
"author": null,
|
||||||
|
"video": {
|
||||||
|
"video_id": "v0d870g10004d0s126nog65ka2e2imgg",
|
||||||
|
"duration": 6,
|
||||||
|
"origin_video": null,
|
||||||
|
"transcoded_video": {
|
||||||
|
"origin": {
|
||||||
|
"vid": "",
|
||||||
|
"fps": 24,
|
||||||
|
"width": 1248,
|
||||||
|
"height": 704,
|
||||||
|
"duration": 0,
|
||||||
|
"video_url": "https://v3-artist.vlabvod.com/76e24e6998b9ec1041ec7a4fef016bda/68414ba9/video/tos/cn/tos-cn-v-148450/o8ED4IN8ahWJgpTREJwEQoAtwGURivhIBQ0iE/?a=4066\u0026ch=0\u0026cr=0\u0026dr=0\u0026er=0\u0026cd=0%7C0%7C0%7C0\u0026br=6777\u0026bt=6777\u0026cs=0\u0026ds=12\u0026ft=5QYTUxhhe6BMyq.fL0kJD12Nzj\u0026mime_type=video_mp4\u0026qs=0\u0026rc=NWlnOjg3Ojg8OmU4Zjw1aEBpanA1NW45cjk0MzczNDM7M0BeNV4zMV5gXmAxYTRfXjEzYSNkZmJeMmRrL3BhLS1kNGFzcw%3D%3D\u0026btag=c0000e00008000\u0026dy_q=1748504868\u0026feature_id=7bed9f9dfbb915a044e5d473759ce9df\u0026l=20250529154748307F1240F9F4DA62E3EE",
|
||||||
|
"cover_url": "",
|
||||||
|
"format": "mp4",
|
||||||
|
"definition": "origin",
|
||||||
|
"logo_type": "",
|
||||||
|
"encryption_key": "",
|
||||||
|
"md5": "66e785209c4994ee420249eb8fc6b9fc",
|
||||||
|
"size": 4352073,
|
||||||
|
"video_id": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"video_size_type": 1,
|
||||||
|
"cover_uri": "tos-cn-p-148450/oYQvoRhUp4BIwITW4EwGJia0hBRDEiEaEgwdU",
|
||||||
|
"transcode_status": 1,
|
||||||
|
"duration_ms": 5042,
|
||||||
|
"thumb": {
|
||||||
|
"detail_infos": [
|
||||||
|
{
|
||||||
|
"frame_count": 5,
|
||||||
|
"image_width": 1280,
|
||||||
|
"image_height": 720,
|
||||||
|
"uri": "tos-cn-p-148450/ooQH4FooBBetAhD3QfChyNCgETETCOoaS8ESBR",
|
||||||
|
"url": "https://p3-sign.douyinpic.com/tos-cn-p-148450/ooQH4FooBBetAhD3QfChyNCgETETCOoaS8ESBR~tplv-noop.image?dy_q=1748504868\u0026l=20250529154748307F1240F9F4DA62E3EE\u0026x-expires=1749109673\u0026x-signature=WDLlIRpUJJe8ASqg5dz57DFtLiA%3D"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"thumb_common_info": {
|
||||||
|
"single_frame_width": 320,
|
||||||
|
"single_frame_height": 180,
|
||||||
|
"total_set_num": 5
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"watermark_type": 1,
|
||||||
|
"cover_url": "https://p3-sign.douyinpic.com/tos-cn-p-148450/oYQvoRhUp4BIwITW4EwGJia0hBRDEiEaEgwdU~tplv-noop.image?dy_q=1748504868\u0026l=20250529154748307F1240F9F4DA62E3EE\u0026x-expires=1749109673\u0026x-signature=K%2FzjpuY%2FXBKVEN0dRqsJfmZqkQo%3D",
|
||||||
|
"duration_info": "{\"play_info_duration\":5.017,\"v_duration\":5.042,\"a_duration\":0}",
|
||||||
|
"vda_status": 10,
|
||||||
|
"video_model": "{\"status\":10,\"message\":\"success\",\"enable_ssl\":true,\"auto_definition\":\"360p\",\"enable_adaptive\":false,\"video_id\":\"v0d870g10004d0s126nog65ka2e2imgg\",\"video_duration\":5.017,\"media_type\":\"video\",\"url_expire\":1748508473,\"big_thumbs\":[{\"img_num\":5,\"uri\":\"tos-cn-p-148450/ooQH4FooBBetAhD3QfChyNCgETETCOoaS8ESBR\",\"img_url\":\"https://p3-sign.douyinpic.com/tos-cn-p-148450/ooQH4FooBBetAhD3QfChyNCgETETCOoaS8ESBR~tplv-noop.image?dy_q=1748504868\u0026l=20250529154748307F1240F9F4DA62E3EE\u0026x-expires=1748508473\u0026x-signature=OmtZ1qy2eiRPQNT%2FMchiBPhEws0%3D\",\"img_urls\":[\"https://p3-sign.douyinpic.com/tos-cn-p-148450/ooQH4FooBBetAhD3QfChyNCgETETCOoaS8ESBR~tplv-noop.image?dy_q=1748504868\u0026l=20250529154748307F1240F9F4DA62E3EE\u0026x-expires=1748508473\u0026x-signature=OmtZ1qy2eiRPQNT%2FMchiBPhEws0%3D\"],\"img_x_size\":320,\"img_y_size\":180,\"img_x_len\":4,\"img_y_len\":4,\"duration\":5.041667,\"interval\":1,\"fext\":\"jpeg\"}],\"fallback_api\":\"https://vas-lf-x.snssdk.com/video/fplay/1/402cc26a443693774b62ed9a6ffd505f/v0d870g10004d0s126nog65ka2e2imgg?aid=0\u0026device_platform=unknown\u0026force_fids=OGZhMg%3D%3D\u0026imp=false\u0026key_seed=tXHBjl9vBONus9KXjsHFA4EIp%2BEJtjjnTLOGeQehyac%3D\u0026logo_type=default\u0026multi_rate_audios=true\u0026stream_type=normal\u0026vps=6\",\"video_list\":{\"video_1\":{\"definition\":\"origin\",\"quality\":\"normal\",\"vtype\":\"mp4\",\"vwidth\":1248,\"vheight\":704,\"bitrate\":6939721,\"real_bitrate\":6939721,\"fps\":24,\"codec_type\":\"h264\",\"size\":4352073,\"main_url\":\"aHR0cHM6Ly92MjYtZGVmYXVsdC4zNjV5Zy5jb20vNTRmY2I0MzZkOTY1OTk5OTI2M2UyMzRmY2JjZTMxNDEvNjgzODFmMzkvdmlkZW8vdG9zL2NuL3Rvcy1jbi12LTE0ODQ1MC9vOEVENElOOGFoV0pncFRSRUp3RVFvQXR3R1VSaXZoSUJRMGlFLz9hPTAmY2g9MCZjcj0wJmRyPTAmZXI9MCZscj1kZWZhdWx0JmNkPTAlN0MwJTdDMCU3QzAmYnI9Njc3NyZidD02Nzc3JmNzPTAmZHM9MTImZnQ9T2kucGk3N0pXSDZCTXN4R21fcjBQRDFJTiZtaW1lX3R5cGU9dmlkZW9fbXA0JnFzPTAmcmM9Tldsbk9qZzNPamc4T21VNFpqdzFhRUJwYW5BMU5XNDVjamswTXpjek5ETTdNMEJlTlY0ek1WNWdYbUF4WVRSZlhqRXpZU05rWm1KZU1tUnJMM0JoTFMxa05HRnpjdyUzRCUzRCZidGFnPWMwMDAwZTAwMDA4MDAwJmR5X3E9MTc0ODUwNDg2OCZmZWF0dXJlX2lkPTdiZWQ5ZjlkZmJiOTE1YTA0NGU1ZDQ3Mzc1OWNlOWRmJmw9MjAyNTA1MjkxNTQ3NDgzMDdGMTI0MEY5RjREQTYyRTNFRQ==\",\"backup_url_1\":\"aHR0cHM6Ly92MTEtZGVmYXVsdC4zNjV5Zy5jb20vNWU0NmU2N2ViMjViNTU4MDFiYTA5YmRkYjM1YzY3ZjIvNjgzODFmMzkvdmlkZW8vdG9zL2NuL3Rvcy1jbi12LTE0ODQ1MC9vOEVENElOOGFoV0pncFRSRUp3RVFvQXR3R1VSaXZoSUJRMGlFLz9hPTAmY2g9MCZjcj0wJmRyPTAmZXI9MCZscj1kZWZhdWx0JmNkPTAlN0MwJTdDMCU3QzAmYnI9Njc3NyZidD02Nzc3JmNzPTAmZHM9MTImZnQ9T2kucGk3N0pXSDZCTXN4R21fcjBQRDFJTiZtaW1lX3R5cGU9dmlkZW9fbXA0JnFzPTAmcmM9Tldsbk9qZzNPamc4T21VNFpqdzFhRUJwYW5BMU5XNDVjamswTXpjek5ETTdNMEJlTlY0ek1WNWdYbUF4WVRSZlhqRXpZU05rWm1KZU1tUnJMM0JoTFMxa05HRnpjdyUzRCUzRCZidGFnPWMwMDAwZTAwMDA4MDAwJmR5X3E9MTc0ODUwNDg2OCZmZWF0dXJlX2lkPTdiZWQ5ZjlkZmJiOTE1YTA0NGU1ZDQ3Mzc1OWNlOWRmJmw9MjAyNTA1MjkxNTQ3NDgzMDdGMTI0MEY5RjREQTYyRTNFRQ==\",\"file_id\":\"6e42a9bc75db47c9a5c7a44567ad8fa2\",\"quality_type\":0,\"encryption_method\":\"\",\"audio_channels\":\"0.0\",\"feature_id\":\"7bed9f9dfbb915a044e5d473759ce9df\",\"gear_des_key\":\"0:MP4|1:normal|2:h264|4:origin|5:normal\",\"audio_sample_rate\":\"0\",\"url_expire\":1748508473,\"preload_size\":327680,\"preload_interval\":60,\"preload_min_step\":5,\"preload_max_step\":10,\"file_hash\":\"66e785209c4994ee420249eb8fc6b9fc\"}},\"popularity_level\":0,\"has_embedded_subtitle\":false,\"poster_url\":\"https://p3-sign.douyinpic.com/tos-cn-p-148450/oYQvoRhUp4BIwITW4EwGJia0hBRDEiEaEgwdU~tplv-noop.image?dy_q=1748504868\u0026l=20250529154748307F1240F9F4DA62E3EE\u0026x-expires=1748508473\u0026x-signature=Rg9kPF9NJtoikYamVTdtO2AI1N8%3D\",\"key_seed\":\"tXHBjl9vBONus9KXjsHFA4EIp+EJtjjnTLOGeQehyac=\"}",
|
||||||
|
"has_audio": false,
|
||||||
|
"is_mute": false
|
||||||
|
},
|
||||||
|
"aigc_image_params": {
|
||||||
|
"generate_type": 10,
|
||||||
|
"first_generate_type": 10,
|
||||||
|
"text2video_params": {
|
||||||
|
"video_gen_inputs": [
|
||||||
|
{
|
||||||
|
"prompt": "高达大战eva初号机",
|
||||||
|
"lens_motion_type": "",
|
||||||
|
"motion_speed": "",
|
||||||
|
"vid": "",
|
||||||
|
"ending_control": "",
|
||||||
|
"pre_task_id": "0",
|
||||||
|
"audio_vid": "",
|
||||||
|
"video_mode": 2,
|
||||||
|
"fps": 24,
|
||||||
|
"duration_ms": 5000,
|
||||||
|
"template_id": "0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"video_aspect_ratio": "16:9",
|
||||||
|
"seed": 1787401630,
|
||||||
|
"task_scene": "",
|
||||||
|
"priority": 0,
|
||||||
|
"video_gen_inputs_extra": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"model_req_key": "dreamina_ic_generate_video_model_vgfm_3.0",
|
||||||
|
"model_config": {
|
||||||
|
"icon_url": "https://p9-heycan-hgt-sign.byteimg.com/tos-cn-i-3jr8j4ixpe/new_video_30~tplv-3jr8j4ixpe-resize:0:0.webp?lk3s=8e790bc3\u0026x-expires=1780040868\u0026x-signature=JwzxSH1o0tLfhGzFr2MSVXsqA20%3D",
|
||||||
|
"model_name_starling_key": "video_3",
|
||||||
|
"model_tip_starling_key": "new_default_model_beginner_friendly",
|
||||||
|
"model_req_key": "dreamina_ic_generate_video_model_vgfm_3.0",
|
||||||
|
"is_new_model": false,
|
||||||
|
"sample_steps": null,
|
||||||
|
"blend_enable": null,
|
||||||
|
"feats": [
|
||||||
|
"support_first_image"
|
||||||
|
],
|
||||||
|
"model_name": "视频 3.0",
|
||||||
|
"model_tip": "响应精准,支持多镜头和运镜",
|
||||||
|
"feature_key": "dreamina_video_3",
|
||||||
|
"duration_option": [
|
||||||
|
5,
|
||||||
|
10
|
||||||
|
],
|
||||||
|
"lens_motion_type_option": null,
|
||||||
|
"motion_speed_option": null,
|
||||||
|
"camera_strength_option": null,
|
||||||
|
"video_aspect_ratio_option": [
|
||||||
|
"21:9",
|
||||||
|
"16:9",
|
||||||
|
"4:3",
|
||||||
|
"1:1",
|
||||||
|
"3:4",
|
||||||
|
"9:16"
|
||||||
|
],
|
||||||
|
"commercial_config": {
|
||||||
|
"commerce_info_map": {
|
||||||
|
"basic": {
|
||||||
|
"resource_sub_type": "aigc",
|
||||||
|
"resource_id_type": "str",
|
||||||
|
"resource_id": "generate_video",
|
||||||
|
"benefit_type": "basic_video_operation_vgfm_v_three",
|
||||||
|
"amount": 0
|
||||||
|
},
|
||||||
|
"retry": {
|
||||||
|
"resource_sub_type": "aigc",
|
||||||
|
"resource_id_type": "str",
|
||||||
|
"resource_id": "generate_video",
|
||||||
|
"benefit_type": "basic_video_operation_vgfm_v_three",
|
||||||
|
"amount": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"fps": 24,
|
||||||
|
"extra": {},
|
||||||
|
"feats_cant_combine": null,
|
||||||
|
"model_bg_prompt_starling_key": ""
|
||||||
|
},
|
||||||
|
"video_model_config": {
|
||||||
|
"icon": {
|
||||||
|
"image_uri": "tos-cn-i-3jr8j4ixpe/new_video_30",
|
||||||
|
"image_url": "https://p9-heycan-hgt-sign.byteimg.com/tos-cn-i-3jr8j4ixpe/new_video_30~tplv-3jr8j4ixpe-resize:0:0.webp?lk3s=8e790bc3\u0026x-expires=1780040868\u0026x-signature=JwzxSH1o0tLfhGzFr2MSVXsqA20%3D",
|
||||||
|
"width": 0,
|
||||||
|
"height": 0,
|
||||||
|
"format": "webp",
|
||||||
|
"smart_crop_loc": null
|
||||||
|
},
|
||||||
|
"model_name": "视频 3.0",
|
||||||
|
"model_name_starling_key": "video_3",
|
||||||
|
"model_tip": "响应精准,支持多镜头和运镜",
|
||||||
|
"model_tip_starling_key": "new_default_model_beginner_friendly",
|
||||||
|
"feature_key": "dreamina_video_3",
|
||||||
|
"icon_tag": "new",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"key": "resolution",
|
||||||
|
"value_type": "enum",
|
||||||
|
"enum_val": {
|
||||||
|
"enum_type": "string",
|
||||||
|
"string_value": [
|
||||||
|
"720p",
|
||||||
|
"1080p"
|
||||||
|
],
|
||||||
|
"double_value": null,
|
||||||
|
"int_value": null,
|
||||||
|
"default_val_idx": 0
|
||||||
|
},
|
||||||
|
"forbidden_display": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "input_media_type",
|
||||||
|
"value_type": "enum",
|
||||||
|
"enum_val": {
|
||||||
|
"enum_type": "string",
|
||||||
|
"string_value": [
|
||||||
|
"prompt",
|
||||||
|
"first_frame"
|
||||||
|
],
|
||||||
|
"double_value": null,
|
||||||
|
"int_value": null,
|
||||||
|
"default_val_idx": 0
|
||||||
|
},
|
||||||
|
"forbidden_display": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "frames",
|
||||||
|
"value_type": "enum",
|
||||||
|
"enum_val": {
|
||||||
|
"enum_type": "int",
|
||||||
|
"string_value": null,
|
||||||
|
"double_value": null,
|
||||||
|
"int_value": [
|
||||||
|
120,
|
||||||
|
240
|
||||||
|
],
|
||||||
|
"default_val_idx": 0
|
||||||
|
},
|
||||||
|
"forbidden_display": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "fps",
|
||||||
|
"value_type": "enum",
|
||||||
|
"enum_val": {
|
||||||
|
"enum_type": "int",
|
||||||
|
"string_value": null,
|
||||||
|
"double_value": null,
|
||||||
|
"int_value": [
|
||||||
|
24
|
||||||
|
],
|
||||||
|
"default_val_idx": 0
|
||||||
|
},
|
||||||
|
"forbidden_display": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "video_aspect_ratio",
|
||||||
|
"value_type": "enum",
|
||||||
|
"enum_val": {
|
||||||
|
"enum_type": "string",
|
||||||
|
"string_value": [
|
||||||
|
"21:9",
|
||||||
|
"16:9",
|
||||||
|
"4:3",
|
||||||
|
"1:1",
|
||||||
|
"3:4",
|
||||||
|
"9:16"
|
||||||
|
],
|
||||||
|
"double_value": null,
|
||||||
|
"int_value": null,
|
||||||
|
"default_val_idx": 1
|
||||||
|
},
|
||||||
|
"forbidden_display": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"commercial_config": {
|
||||||
|
"default": {
|
||||||
|
"resource_sub_type": "aigc",
|
||||||
|
"resource_id_type": "str",
|
||||||
|
"resource_id": "generate_video",
|
||||||
|
"benefit_type": "basic_video_operation_vgfm_v_three",
|
||||||
|
"amount": 0
|
||||||
|
},
|
||||||
|
"format": "{resolution}",
|
||||||
|
"format_conf": {
|
||||||
|
"1080p": {
|
||||||
|
"resource_sub_type": "aigc",
|
||||||
|
"resource_id_type": "str",
|
||||||
|
"resource_id": "generate_video",
|
||||||
|
"benefit_type": "basic_video_operation_vgfm_v_three_1080",
|
||||||
|
"amount": 0
|
||||||
|
},
|
||||||
|
"720p": {
|
||||||
|
"resource_sub_type": "aigc",
|
||||||
|
"resource_id_type": "str",
|
||||||
|
"resource_id": "generate_video",
|
||||||
|
"benefit_type": "basic_video_operation_vgfm_v_three",
|
||||||
|
"amount": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"model_req_key": "dreamina_ic_generate_video_model_vgfm_3.0",
|
||||||
|
"extra": {
|
||||||
|
"pop_icon": {
|
||||||
|
"image_uri": "tos-cn-i-3jr8j4ixpe/vgfm_lite_cover",
|
||||||
|
"image_url": "https://p9-heycan-hgt-sign.byteimg.com/tos-cn-i-3jr8j4ixpe/vgfm_lite_cover~tplv-3jr8j4ixpe-resize:0:0.webp?lk3s=8e790bc3\u0026x-expires=1780040868\u0026x-signature=srxEpaLESvQNRYdDwFmVPLWNZ9w%3D",
|
||||||
|
"width": 0,
|
||||||
|
"height": 0,
|
||||||
|
"format": "webp",
|
||||||
|
"smart_crop_loc": null
|
||||||
|
},
|
||||||
|
"model_source": "by Seedance 1.0"
|
||||||
|
},
|
||||||
|
"model_status": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"template_id": "0",
|
||||||
|
"insta_drag_params": {
|
||||||
|
"origin_item_id": null
|
||||||
|
},
|
||||||
|
"hide_ref_images": false
|
||||||
|
},
|
||||||
|
"statistic": {
|
||||||
|
"feedback_status": 0
|
||||||
|
},
|
||||||
|
"category_id_list": [],
|
||||||
|
"aigc_flow": {
|
||||||
|
"version": "0.1.2"
|
||||||
|
},
|
||||||
|
"aigc_draft": {
|
||||||
|
"version": "3.0.5",
|
||||||
|
"uri": "aigc-draft/4652100572930",
|
||||||
|
"content": "",
|
||||||
|
"update_time": 0,
|
||||||
|
"last_preview_time": 0,
|
||||||
|
"resource_type": "",
|
||||||
|
"public_uri": "",
|
||||||
|
"variables": [],
|
||||||
|
"resource_width": 0,
|
||||||
|
"resource_height": 0,
|
||||||
|
"node_keys": [],
|
||||||
|
"cost": 0
|
||||||
|
},
|
||||||
|
"gen_result_data": {
|
||||||
|
"result_code": 0,
|
||||||
|
"result_msg": "Success"
|
||||||
|
},
|
||||||
|
"extra": {
|
||||||
|
"template_type": "video",
|
||||||
|
"ai_feature": "text_generate_video"
|
||||||
|
},
|
||||||
|
"ai_feature": {
|
||||||
|
"features": [
|
||||||
|
{
|
||||||
|
"type": "text_generate_video"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"is_merged": true
|
||||||
|
},
|
||||||
|
"sharing_info": {
|
||||||
|
"share_status": 2
|
||||||
|
},
|
||||||
|
"metadata_param": "{\"effect_id\":\"gen_video\",\"effect_type\":\"tool\"}"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"origin_item_list": [],
|
||||||
|
"task": {
|
||||||
|
"task_id": "4647703308546",
|
||||||
|
"submit_id": "daed2f59-ebc0-467e-a31c-c6e44e25cdc6",
|
||||||
|
"aid": 0,
|
||||||
|
"status": 50,
|
||||||
|
"finish_time": 1748504868,
|
||||||
|
"history_id": "18763140978434",
|
||||||
|
"task_payload": null,
|
||||||
|
"original_input": {
|
||||||
|
"video_gen_inputs": [
|
||||||
|
{
|
||||||
|
"prompt": "高达大战eva初号机",
|
||||||
|
"lens_motion_type": "",
|
||||||
|
"motion_speed": "",
|
||||||
|
"vid": "",
|
||||||
|
"ending_control": "",
|
||||||
|
"pre_task_id": "0",
|
||||||
|
"audio_vid": "",
|
||||||
|
"video_mode": 2,
|
||||||
|
"fps": 24,
|
||||||
|
"duration_ms": 5000,
|
||||||
|
"template_id": "0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"video_aspect_ratio": "16:9",
|
||||||
|
"seed": 1787401630,
|
||||||
|
"task_scene": "",
|
||||||
|
"priority": 0,
|
||||||
|
"model_req_key": "dreamina_ic_generate_video_model_vgfm_3.0",
|
||||||
|
"model_config": {
|
||||||
|
"icon_url": "https://p3-heycan-hgt-sign.byteimg.com/tos-cn-i-3jr8j4ixpe/new_video_30~tplv-3jr8j4ixpe-resize:0:0.webp?lk3s=8e790bc3\u0026x-expires=1780040868\u0026x-signature=xxJ56UEOiCBHwKLd7PqATVSieFc%3D",
|
||||||
|
"model_name_starling_key": "video_3",
|
||||||
|
"model_tip_starling_key": "new_default_model_beginner_friendly",
|
||||||
|
"model_req_key": "dreamina_ic_generate_video_model_vgfm_3.0",
|
||||||
|
"is_new_model": false,
|
||||||
|
"sample_steps": null,
|
||||||
|
"blend_enable": null,
|
||||||
|
"feats": [
|
||||||
|
"support_first_image"
|
||||||
|
],
|
||||||
|
"model_name": "视频 3.0",
|
||||||
|
"model_tip": "响应精准,支持多镜头和运镜",
|
||||||
|
"feature_key": "dreamina_video_3",
|
||||||
|
"duration_option": [
|
||||||
|
5,
|
||||||
|
10
|
||||||
|
],
|
||||||
|
"lens_motion_type_option": null,
|
||||||
|
"motion_speed_option": null,
|
||||||
|
"camera_strength_option": null,
|
||||||
|
"video_aspect_ratio_option": [
|
||||||
|
"21:9",
|
||||||
|
"16:9",
|
||||||
|
"4:3",
|
||||||
|
"1:1",
|
||||||
|
"3:4",
|
||||||
|
"9:16"
|
||||||
|
],
|
||||||
|
"commercial_config": {
|
||||||
|
"commerce_info_map": {
|
||||||
|
"basic": {
|
||||||
|
"resource_sub_type": "aigc",
|
||||||
|
"resource_id_type": "str",
|
||||||
|
"resource_id": "generate_video",
|
||||||
|
"benefit_type": "basic_video_operation_vgfm_v_three",
|
||||||
|
"amount": 0
|
||||||
|
},
|
||||||
|
"retry": {
|
||||||
|
"resource_sub_type": "aigc",
|
||||||
|
"resource_id_type": "str",
|
||||||
|
"resource_id": "generate_video",
|
||||||
|
"benefit_type": "basic_video_operation_vgfm_v_three",
|
||||||
|
"amount": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"fps": 24,
|
||||||
|
"extra": {},
|
||||||
|
"feats_cant_combine": null,
|
||||||
|
"model_bg_prompt_starling_key": ""
|
||||||
|
},
|
||||||
|
"video_model_config": {
|
||||||
|
"icon": {
|
||||||
|
"image_uri": "tos-cn-i-3jr8j4ixpe/new_video_30",
|
||||||
|
"image_url": "https://p3-heycan-hgt-sign.byteimg.com/tos-cn-i-3jr8j4ixpe/new_video_30~tplv-3jr8j4ixpe-resize:0:0.webp?lk3s=8e790bc3\u0026x-expires=1780040868\u0026x-signature=xxJ56UEOiCBHwKLd7PqATVSieFc%3D",
|
||||||
|
"width": 0,
|
||||||
|
"height": 0,
|
||||||
|
"format": "webp",
|
||||||
|
"smart_crop_loc": null
|
||||||
|
},
|
||||||
|
"model_name": "视频 3.0",
|
||||||
|
"model_name_starling_key": "video_3",
|
||||||
|
"model_tip": "响应精准,支持多镜头和运镜",
|
||||||
|
"model_tip_starling_key": "new_default_model_beginner_friendly",
|
||||||
|
"feature_key": "dreamina_video_3",
|
||||||
|
"icon_tag": "new",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"key": "resolution",
|
||||||
|
"value_type": "enum",
|
||||||
|
"enum_val": {
|
||||||
|
"enum_type": "string",
|
||||||
|
"string_value": [
|
||||||
|
"720p",
|
||||||
|
"1080p"
|
||||||
|
],
|
||||||
|
"double_value": null,
|
||||||
|
"int_value": null,
|
||||||
|
"default_val_idx": 0
|
||||||
|
},
|
||||||
|
"forbidden_display": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "input_media_type",
|
||||||
|
"value_type": "enum",
|
||||||
|
"enum_val": {
|
||||||
|
"enum_type": "string",
|
||||||
|
"string_value": [
|
||||||
|
"prompt",
|
||||||
|
"first_frame"
|
||||||
|
],
|
||||||
|
"double_value": null,
|
||||||
|
"int_value": null,
|
||||||
|
"default_val_idx": 0
|
||||||
|
},
|
||||||
|
"forbidden_display": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "frames",
|
||||||
|
"value_type": "enum",
|
||||||
|
"enum_val": {
|
||||||
|
"enum_type": "int",
|
||||||
|
"string_value": null,
|
||||||
|
"double_value": null,
|
||||||
|
"int_value": [
|
||||||
|
120,
|
||||||
|
240
|
||||||
|
],
|
||||||
|
"default_val_idx": 0
|
||||||
|
},
|
||||||
|
"forbidden_display": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "fps",
|
||||||
|
"value_type": "enum",
|
||||||
|
"enum_val": {
|
||||||
|
"enum_type": "int",
|
||||||
|
"string_value": null,
|
||||||
|
"double_value": null,
|
||||||
|
"int_value": [
|
||||||
|
24
|
||||||
|
],
|
||||||
|
"default_val_idx": 0
|
||||||
|
},
|
||||||
|
"forbidden_display": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "video_aspect_ratio",
|
||||||
|
"value_type": "enum",
|
||||||
|
"enum_val": {
|
||||||
|
"enum_type": "string",
|
||||||
|
"string_value": [
|
||||||
|
"21:9",
|
||||||
|
"16:9",
|
||||||
|
"4:3",
|
||||||
|
"1:1",
|
||||||
|
"3:4",
|
||||||
|
"9:16"
|
||||||
|
],
|
||||||
|
"double_value": null,
|
||||||
|
"int_value": null,
|
||||||
|
"default_val_idx": 1
|
||||||
|
},
|
||||||
|
"forbidden_display": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"commercial_config": {
|
||||||
|
"default": {
|
||||||
|
"resource_sub_type": "aigc",
|
||||||
|
"resource_id_type": "str",
|
||||||
|
"resource_id": "generate_video",
|
||||||
|
"benefit_type": "basic_video_operation_vgfm_v_three",
|
||||||
|
"amount": 0
|
||||||
|
},
|
||||||
|
"format": "{resolution}",
|
||||||
|
"format_conf": {
|
||||||
|
"1080p": {
|
||||||
|
"resource_sub_type": "aigc",
|
||||||
|
"resource_id_type": "str",
|
||||||
|
"resource_id": "generate_video",
|
||||||
|
"benefit_type": "basic_video_operation_vgfm_v_three_1080",
|
||||||
|
"amount": 0
|
||||||
|
},
|
||||||
|
"720p": {
|
||||||
|
"resource_sub_type": "aigc",
|
||||||
|
"resource_id_type": "str",
|
||||||
|
"resource_id": "generate_video",
|
||||||
|
"benefit_type": "basic_video_operation_vgfm_v_three",
|
||||||
|
"amount": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"model_req_key": "dreamina_ic_generate_video_model_vgfm_3.0",
|
||||||
|
"extra": {
|
||||||
|
"pop_icon": {
|
||||||
|
"image_uri": "tos-cn-i-3jr8j4ixpe/vgfm_lite_cover",
|
||||||
|
"image_url": "https://p6-heycan-hgt-sign.byteimg.com/tos-cn-i-3jr8j4ixpe/vgfm_lite_cover~tplv-3jr8j4ixpe-resize:0:0.webp?lk3s=8e790bc3\u0026x-expires=1780040868\u0026x-signature=tVwWqcvYaTkXH0ijjKE9VWVn%2FAE%3D",
|
||||||
|
"width": 0,
|
||||||
|
"height": 0,
|
||||||
|
"format": "webp",
|
||||||
|
"smart_crop_loc": null
|
||||||
|
},
|
||||||
|
"model_source": "by Seedance 1.0"
|
||||||
|
},
|
||||||
|
"model_status": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"req_first_frame_image": null,
|
||||||
|
"ai_gen_prompt": "",
|
||||||
|
"priority": 0,
|
||||||
|
"lip_sync_info": {
|
||||||
|
"lip_sync_extra": "",
|
||||||
|
"lip_sync_video_url": "",
|
||||||
|
"lip_sync_audio_url": "",
|
||||||
|
"labcv_task_id": ""
|
||||||
|
},
|
||||||
|
"multi_size_first_frame_image": null,
|
||||||
|
"multi_size_end_frame_image": null,
|
||||||
|
"process_flows": [
|
||||||
|
{
|
||||||
|
"task_id": "4647703308546",
|
||||||
|
"cur_process_flows": [
|
||||||
|
1
|
||||||
|
],
|
||||||
|
"history_id": "18763140978434"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"create_time": 0,
|
||||||
|
"aigc_image_params": {
|
||||||
|
"generate_type": 10,
|
||||||
|
"first_generate_type": 10,
|
||||||
|
"text2video_params": {
|
||||||
|
"video_gen_inputs": [
|
||||||
|
{
|
||||||
|
"prompt": "高达大战eva初号机",
|
||||||
|
"lens_motion_type": "",
|
||||||
|
"motion_speed": "",
|
||||||
|
"vid": "",
|
||||||
|
"ending_control": "",
|
||||||
|
"pre_task_id": "0",
|
||||||
|
"audio_vid": "",
|
||||||
|
"video_mode": 2,
|
||||||
|
"fps": 24,
|
||||||
|
"duration_ms": 5000,
|
||||||
|
"template_id": "0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"video_aspect_ratio": "16:9",
|
||||||
|
"seed": 1787401630,
|
||||||
|
"task_scene": "",
|
||||||
|
"priority": 0,
|
||||||
|
"video_gen_inputs_extra": [
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
"model_req_key": "dreamina_ic_generate_video_model_vgfm_3.0",
|
||||||
|
"model_config": {
|
||||||
|
"icon_url": "https://p9-heycan-hgt-sign.byteimg.com/tos-cn-i-3jr8j4ixpe/new_video_30~tplv-3jr8j4ixpe-resize:0:0.webp?lk3s=8e790bc3\u0026x-expires=1780040868\u0026x-signature=JwzxSH1o0tLfhGzFr2MSVXsqA20%3D",
|
||||||
|
"model_name_starling_key": "video_3",
|
||||||
|
"model_tip_starling_key": "new_default_model_beginner_friendly",
|
||||||
|
"model_req_key": "dreamina_ic_generate_video_model_vgfm_3.0",
|
||||||
|
"is_new_model": false,
|
||||||
|
"sample_steps": null,
|
||||||
|
"blend_enable": null,
|
||||||
|
"feats": [
|
||||||
|
"support_first_image"
|
||||||
|
],
|
||||||
|
"model_name": "视频 3.0",
|
||||||
|
"model_tip": "响应精准,支持多镜头和运镜",
|
||||||
|
"feature_key": "dreamina_video_3",
|
||||||
|
"duration_option": [
|
||||||
|
5,
|
||||||
|
10
|
||||||
|
],
|
||||||
|
"lens_motion_type_option": null,
|
||||||
|
"motion_speed_option": null,
|
||||||
|
"camera_strength_option": null,
|
||||||
|
"video_aspect_ratio_option": [
|
||||||
|
"21:9",
|
||||||
|
"16:9",
|
||||||
|
"4:3",
|
||||||
|
"1:1",
|
||||||
|
"3:4",
|
||||||
|
"9:16"
|
||||||
|
],
|
||||||
|
"commercial_config": {
|
||||||
|
"commerce_info_map": {
|
||||||
|
"basic": {
|
||||||
|
"resource_sub_type": "aigc",
|
||||||
|
"resource_id_type": "str",
|
||||||
|
"resource_id": "generate_video",
|
||||||
|
"benefit_type": "basic_video_operation_vgfm_v_three",
|
||||||
|
"amount": 0
|
||||||
|
},
|
||||||
|
"retry": {
|
||||||
|
"resource_sub_type": "aigc",
|
||||||
|
"resource_id_type": "str",
|
||||||
|
"resource_id": "generate_video",
|
||||||
|
"benefit_type": "basic_video_operation_vgfm_v_three",
|
||||||
|
"amount": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"fps": 24,
|
||||||
|
"extra": {},
|
||||||
|
"feats_cant_combine": null,
|
||||||
|
"model_bg_prompt_starling_key": ""
|
||||||
|
},
|
||||||
|
"video_model_config": {
|
||||||
|
"icon": {
|
||||||
|
"image_uri": "tos-cn-i-3jr8j4ixpe/new_video_30",
|
||||||
|
"image_url": "https://p9-heycan-hgt-sign.byteimg.com/tos-cn-i-3jr8j4ixpe/new_video_30~tplv-3jr8j4ixpe-resize:0:0.webp?lk3s=8e790bc3\u0026x-expires=1780040868\u0026x-signature=JwzxSH1o0tLfhGzFr2MSVXsqA20%3D",
|
||||||
|
"width": 0,
|
||||||
|
"height": 0,
|
||||||
|
"format": "webp",
|
||||||
|
"smart_crop_loc": null
|
||||||
|
},
|
||||||
|
"model_name": "视频 3.0",
|
||||||
|
"model_name_starling_key": "video_3",
|
||||||
|
"model_tip": "响应精准,支持多镜头和运镜",
|
||||||
|
"model_tip_starling_key": "new_default_model_beginner_friendly",
|
||||||
|
"feature_key": "dreamina_video_3",
|
||||||
|
"icon_tag": "new",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"key": "resolution",
|
||||||
|
"value_type": "enum",
|
||||||
|
"enum_val": {
|
||||||
|
"enum_type": "string",
|
||||||
|
"string_value": [
|
||||||
|
"720p",
|
||||||
|
"1080p"
|
||||||
|
],
|
||||||
|
"double_value": null,
|
||||||
|
"int_value": null,
|
||||||
|
"default_val_idx": 0
|
||||||
|
},
|
||||||
|
"forbidden_display": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "input_media_type",
|
||||||
|
"value_type": "enum",
|
||||||
|
"enum_val": {
|
||||||
|
"enum_type": "string",
|
||||||
|
"string_value": [
|
||||||
|
"prompt",
|
||||||
|
"first_frame"
|
||||||
|
],
|
||||||
|
"double_value": null,
|
||||||
|
"int_value": null,
|
||||||
|
"default_val_idx": 0
|
||||||
|
},
|
||||||
|
"forbidden_display": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "frames",
|
||||||
|
"value_type": "enum",
|
||||||
|
"enum_val": {
|
||||||
|
"enum_type": "int",
|
||||||
|
"string_value": null,
|
||||||
|
"double_value": null,
|
||||||
|
"int_value": [
|
||||||
|
120,
|
||||||
|
240
|
||||||
|
],
|
||||||
|
"default_val_idx": 0
|
||||||
|
},
|
||||||
|
"forbidden_display": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "fps",
|
||||||
|
"value_type": "enum",
|
||||||
|
"enum_val": {
|
||||||
|
"enum_type": "int",
|
||||||
|
"string_value": null,
|
||||||
|
"double_value": null,
|
||||||
|
"int_value": [
|
||||||
|
24
|
||||||
|
],
|
||||||
|
"default_val_idx": 0
|
||||||
|
},
|
||||||
|
"forbidden_display": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "video_aspect_ratio",
|
||||||
|
"value_type": "enum",
|
||||||
|
"enum_val": {
|
||||||
|
"enum_type": "string",
|
||||||
|
"string_value": [
|
||||||
|
"21:9",
|
||||||
|
"16:9",
|
||||||
|
"4:3",
|
||||||
|
"1:1",
|
||||||
|
"3:4",
|
||||||
|
"9:16"
|
||||||
|
],
|
||||||
|
"double_value": null,
|
||||||
|
"int_value": null,
|
||||||
|
"default_val_idx": 1
|
||||||
|
},
|
||||||
|
"forbidden_display": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"commercial_config": {
|
||||||
|
"default": {
|
||||||
|
"resource_sub_type": "aigc",
|
||||||
|
"resource_id_type": "str",
|
||||||
|
"resource_id": "generate_video",
|
||||||
|
"benefit_type": "basic_video_operation_vgfm_v_three",
|
||||||
|
"amount": 0
|
||||||
|
},
|
||||||
|
"format": "{resolution}",
|
||||||
|
"format_conf": {
|
||||||
|
"1080p": {
|
||||||
|
"resource_sub_type": "aigc",
|
||||||
|
"resource_id_type": "str",
|
||||||
|
"resource_id": "generate_video",
|
||||||
|
"benefit_type": "basic_video_operation_vgfm_v_three_1080",
|
||||||
|
"amount": 0
|
||||||
|
},
|
||||||
|
"720p": {
|
||||||
|
"resource_sub_type": "aigc",
|
||||||
|
"resource_id_type": "str",
|
||||||
|
"resource_id": "generate_video",
|
||||||
|
"benefit_type": "basic_video_operation_vgfm_v_three",
|
||||||
|
"amount": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"model_req_key": "dreamina_ic_generate_video_model_vgfm_3.0",
|
||||||
|
"extra": {
|
||||||
|
"pop_icon": {
|
||||||
|
"image_uri": "tos-cn-i-3jr8j4ixpe/vgfm_lite_cover",
|
||||||
|
"image_url": "https://p9-heycan-hgt-sign.byteimg.com/tos-cn-i-3jr8j4ixpe/vgfm_lite_cover~tplv-3jr8j4ixpe-resize:0:0.webp?lk3s=8e790bc3\u0026x-expires=1780040868\u0026x-signature=srxEpaLESvQNRYdDwFmVPLWNZ9w%3D",
|
||||||
|
"width": 0,
|
||||||
|
"height": 0,
|
||||||
|
"format": "webp",
|
||||||
|
"smart_crop_loc": null
|
||||||
|
},
|
||||||
|
"model_source": "by Seedance 1.0"
|
||||||
|
},
|
||||||
|
"model_status": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"template_id": "0",
|
||||||
|
"insta_drag_params": {
|
||||||
|
"origin_item_id": null
|
||||||
|
},
|
||||||
|
"hide_ref_images": false
|
||||||
|
},
|
||||||
|
"ref_item": null,
|
||||||
|
"resp_ret": {
|
||||||
|
"ret": "0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"mode": "workbench",
|
||||||
|
"asset_option": {
|
||||||
|
"has_favorited": false
|
||||||
|
},
|
||||||
|
"uid": "4476817135373291",
|
||||||
|
"aigc_flow": {
|
||||||
|
"version": "3.0.5"
|
||||||
|
},
|
||||||
|
"status": 50,
|
||||||
|
"history_group_key_md5": "1de0cb9377711654f790d75bfa42c115",
|
||||||
|
"history_group_key": "generate_video#高达大战eva初号机",
|
||||||
|
"draft_content": "{\"type\":\"draft\",\"id\":\"919f1ac7-9459-3750-0660-eba50aa7f37c\",\"min_version\":\"3.0.5\",\"min_features\":[],\"is_from_tsn\":true,\"version\":\"3.0.5\",\"main_component_id\":\"554271af-f6f1-9b2f-eab2-ce7cb2f2c06f\",\"component_list\":[{\"type\":\"video_base_component\",\"id\":\"554271af-f6f1-9b2f-eab2-ce7cb2f2c06f\",\"min_version\":\"1.0.0\",\"gen_type\":10,\"metadata\":{\"type\":\"\",\"id\":\"a3bc124b-29f8-a01d-4745-7f21fd6f9f7a\",\"created_platform\":3,\"created_platform_version\":\"\",\"created_time_in_ms\":\"1748504839676\",\"created_did\":\"\"},\"generate_type\":\"gen_video\",\"aigc_mode\":\"workbench\",\"abilities\":{\"type\":\"\",\"id\":\"e0b8fac3-add3-ae9a-01be-e40ea8a316de\",\"gen_video\":{\"type\":\"\",\"id\":\"9a8b908b-40b5-7621-66bb-d01a9d60ad5c\",\"text_to_video_params\":{\"type\":\"\",\"id\":\"5b19e7d3-9892-995a-4aee-dd0a5ad92f28\",\"video_gen_inputs\":[{\"type\":\"\",\"id\":\"a6fa509f-8f3c-f8e0-17da-b2b4faf67b45\",\"min_version\":\"3.0.5\",\"prompt\":\"高达大战eva初号机\",\"video_mode\":2,\"fps\":24,\"duration_ms\":5000}],\"video_aspect_ratio\":\"16:9\",\"seed\":1787401630,\"model_req_key\":\"dreamina_ic_generate_video_model_vgfm_3.0\"},\"video_task_extra\":\"{\\\"promptSource\\\":\\\"custom\\\",\\\"originSubmitId\\\":\\\"685b0c61-af75-410f-ba9c-76f4624be7e7\\\",\\\"isDefaultSeed\\\":1,\\\"originTemplateId\\\":\\\"\\\",\\\"imageNameMapping\\\":{}}\"}},\"process_type\":1}]}",
|
||||||
|
"fail_code": "0",
|
||||||
|
"submit_id": "daed2f59-ebc0-467e-a31c-c6e44e25cdc6",
|
||||||
|
"capflow_id": "8abf7180_84c0_49fe_96b7_f40c515127e3",
|
||||||
|
"metrics_extra": "{\"promptSource\":\"custom\",\"originSubmitId\":\"685b0c61-af75-410f-ba9c-76f4624be7e7\",\"isDefaultSeed\":1,\"originTemplateId\":\"\",\"imageNameMapping\":{}}",
|
||||||
|
"fail_msg": "Success",
|
||||||
|
"generate_id": "20250529154719AB298A2D9B3B486C5B92",
|
||||||
|
"finish_time": 1748504868,
|
||||||
|
"model_info": {
|
||||||
|
"icon_url": "https://p6-heycan-hgt-sign.byteimg.com/tos-cn-i-3jr8j4ixpe/new_video_30~tplv-3jr8j4ixpe-resize:0:0.webp?lk3s=8e790bc3\u0026x-expires=1780040868\u0026x-signature=42cZHRrHmXNXEbl3kte8urdepnw%3D",
|
||||||
|
"model_name_starling_key": "video_3",
|
||||||
|
"model_tip_starling_key": "new_default_model_beginner_friendly",
|
||||||
|
"model_req_key": "dreamina_ic_generate_video_model_vgfm_3.0",
|
||||||
|
"model_name": "视频 3.0",
|
||||||
|
"commercial_config": {
|
||||||
|
"commerce_info_map": {
|
||||||
|
"basic": {
|
||||||
|
"resource_sub_type": "aigc",
|
||||||
|
"resource_id_type": "str",
|
||||||
|
"resource_id": "generate_video",
|
||||||
|
"benefit_type": "basic_video_operation_vgfm_v_three",
|
||||||
|
"amount": 0
|
||||||
|
},
|
||||||
|
"retry": {
|
||||||
|
"resource_sub_type": "aigc",
|
||||||
|
"resource_id_type": "str",
|
||||||
|
"resource_id": "generate_video",
|
||||||
|
"benefit_type": "basic_video_operation_vgfm_v_three",
|
||||||
|
"amount": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"video_model_options": [
|
||||||
|
{
|
||||||
|
"key": "resolution",
|
||||||
|
"value_type": "enum",
|
||||||
|
"enum_val": {
|
||||||
|
"enum_type": "string",
|
||||||
|
"string_value": [
|
||||||
|
"720p",
|
||||||
|
"1080p"
|
||||||
|
],
|
||||||
|
"double_value": null,
|
||||||
|
"int_value": null,
|
||||||
|
"default_val_idx": 0
|
||||||
|
},
|
||||||
|
"forbidden_display": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "input_media_type",
|
||||||
|
"value_type": "enum",
|
||||||
|
"enum_val": {
|
||||||
|
"enum_type": "string",
|
||||||
|
"string_value": [
|
||||||
|
"prompt",
|
||||||
|
"first_frame"
|
||||||
|
],
|
||||||
|
"double_value": null,
|
||||||
|
"int_value": null,
|
||||||
|
"default_val_idx": 0
|
||||||
|
},
|
||||||
|
"forbidden_display": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "frames",
|
||||||
|
"value_type": "enum",
|
||||||
|
"enum_val": {
|
||||||
|
"enum_type": "int",
|
||||||
|
"string_value": null,
|
||||||
|
"double_value": null,
|
||||||
|
"int_value": [
|
||||||
|
120,
|
||||||
|
240
|
||||||
|
],
|
||||||
|
"default_val_idx": 0
|
||||||
|
},
|
||||||
|
"forbidden_display": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "fps",
|
||||||
|
"value_type": "enum",
|
||||||
|
"enum_val": {
|
||||||
|
"enum_type": "int",
|
||||||
|
"string_value": null,
|
||||||
|
"double_value": null,
|
||||||
|
"int_value": [
|
||||||
|
24
|
||||||
|
],
|
||||||
|
"default_val_idx": 0
|
||||||
|
},
|
||||||
|
"forbidden_display": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "video_aspect_ratio",
|
||||||
|
"value_type": "enum",
|
||||||
|
"enum_val": {
|
||||||
|
"enum_type": "string",
|
||||||
|
"string_value": [
|
||||||
|
"21:9",
|
||||||
|
"16:9",
|
||||||
|
"4:3",
|
||||||
|
"1:1",
|
||||||
|
"3:4",
|
||||||
|
"9:16"
|
||||||
|
],
|
||||||
|
"double_value": null,
|
||||||
|
"int_value": null,
|
||||||
|
"default_val_idx": 1
|
||||||
|
},
|
||||||
|
"forbidden_display": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"forecast_generate_cost": 37,
|
||||||
|
"forecast_queue_cost": 0,
|
||||||
|
"fail_starling_key": "",
|
||||||
|
"fail_starling_message": "",
|
||||||
|
"min_feats": null,
|
||||||
|
"lip_sync_info": {
|
||||||
|
"lip_sync_extra": "",
|
||||||
|
"lip_sync_video_url": "",
|
||||||
|
"lip_sync_audio_url": "",
|
||||||
|
"labcv_task_id": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
79430
temp/3013.265ac0fd.js
Normal file
79430
temp/3013.265ac0fd.js
Normal file
File diff suppressed because one or more lines are too long
13553
temp/lib-uploader.2.js
Normal file
13553
temp/lib-uploader.2.js
Normal file
File diff suppressed because one or more lines are too long
480
temp/lib-uploader.3.js
Normal file
480
temp/lib-uploader.3.js
Normal file
@ -0,0 +1,480 @@
|
|||||||
|
|
||||||
|
(function (e, t) {
|
||||||
|
if (
|
||||||
|
("undefined" != typeof window &&
|
||||||
|
window.crypto &&
|
||||||
|
(r = window.crypto),
|
||||||
|
"undefined" != typeof self &&
|
||||||
|
self.crypto &&
|
||||||
|
(r = self.crypto),
|
||||||
|
"undefined" != typeof globalThis &&
|
||||||
|
globalThis.crypto &&
|
||||||
|
(r = globalThis.crypto),
|
||||||
|
!r &&
|
||||||
|
"undefined" != typeof window &&
|
||||||
|
window.msCrypto &&
|
||||||
|
(r = window.msCrypto),
|
||||||
|
!r && void 0 !== o && o.crypto && (r = o.crypto),
|
||||||
|
!r)
|
||||||
|
)
|
||||||
|
try {
|
||||||
|
r = n.default;
|
||||||
|
} catch (e) {}
|
||||||
|
var r,
|
||||||
|
i = function () {
|
||||||
|
if (r) {
|
||||||
|
if ("function" == typeof r.getRandomValues)
|
||||||
|
try {
|
||||||
|
return r.getRandomValues(
|
||||||
|
new Uint32Array(1)
|
||||||
|
)[0];
|
||||||
|
} catch (e) {}
|
||||||
|
if ("function" == typeof r.randomBytes)
|
||||||
|
try {
|
||||||
|
return r.randomBytes(4).readInt32LE();
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
throw Error(
|
||||||
|
"Native crypto module could not be used to get secure random number."
|
||||||
|
);
|
||||||
|
},
|
||||||
|
s =
|
||||||
|
Object.create ||
|
||||||
|
(function () {
|
||||||
|
function e() {}
|
||||||
|
return function (t) {
|
||||||
|
var r;
|
||||||
|
return (
|
||||||
|
(e.prototype = t),
|
||||||
|
(r = new e()),
|
||||||
|
(e.prototype = null),
|
||||||
|
r
|
||||||
|
);
|
||||||
|
};
|
||||||
|
})(),
|
||||||
|
a = {},
|
||||||
|
c = (a.lib = {}),
|
||||||
|
u = (c.Base = {
|
||||||
|
extend: function (e) {
|
||||||
|
var t = s(this);
|
||||||
|
return (
|
||||||
|
e && t.mixIn(e),
|
||||||
|
(t.hasOwnProperty("init") &&
|
||||||
|
this.init !== t.init) ||
|
||||||
|
(t.init = function () {
|
||||||
|
t.$super.init.apply(this, arguments);
|
||||||
|
}),
|
||||||
|
(t.init.prototype = t),
|
||||||
|
(t.$super = this),
|
||||||
|
t
|
||||||
|
);
|
||||||
|
},
|
||||||
|
create: function () {
|
||||||
|
var e = this.extend();
|
||||||
|
return e.init.apply(e, arguments), e;
|
||||||
|
},
|
||||||
|
init: function () {},
|
||||||
|
mixIn: function (e) {
|
||||||
|
for (var t in e)
|
||||||
|
e.hasOwnProperty(t) && (this[t] = e[t]);
|
||||||
|
e.hasOwnProperty("toString") &&
|
||||||
|
(this.toString = e.toString);
|
||||||
|
},
|
||||||
|
clone: function () {
|
||||||
|
return this.init.prototype.extend(this);
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
l = (c.WordArray = u.extend({
|
||||||
|
init: function (e, t) {
|
||||||
|
(e = this.words = e || []),
|
||||||
|
(this.sigBytes =
|
||||||
|
null != t ? t : 4 * e.length);
|
||||||
|
},
|
||||||
|
toString: function (e) {
|
||||||
|
return (e || p).stringify(this);
|
||||||
|
},
|
||||||
|
concat: function (e) {
|
||||||
|
var t = this.words,
|
||||||
|
r = e.words,
|
||||||
|
n = this.sigBytes,
|
||||||
|
i = e.sigBytes;
|
||||||
|
if ((this.clamp(), n % 4))
|
||||||
|
for (var o = 0; o < i; o++) {
|
||||||
|
var s =
|
||||||
|
(r[o >>> 2] >>> (24 - (o % 4) * 8)) & 255;
|
||||||
|
t[(n + o) >>> 2] |=
|
||||||
|
s << (24 - ((n + o) % 4) * 8);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
for (var a = 0; a < i; a += 4)
|
||||||
|
t[(n + a) >>> 2] = r[a >>> 2];
|
||||||
|
return (this.sigBytes += i), this;
|
||||||
|
},
|
||||||
|
clamp: function () {
|
||||||
|
var t = this.words,
|
||||||
|
r = this.sigBytes;
|
||||||
|
(t[r >>> 2] &=
|
||||||
|
0xffffffff << (32 - (r % 4) * 8)),
|
||||||
|
(t.length = e.ceil(r / 4));
|
||||||
|
},
|
||||||
|
clone: function () {
|
||||||
|
var e = u.clone.call(this);
|
||||||
|
return (e.words = this.words.slice(0)), e;
|
||||||
|
},
|
||||||
|
random: function (e) {
|
||||||
|
for (var t = [], r = 0; r < e; r += 4)
|
||||||
|
t.push(i());
|
||||||
|
return new l.init(t, e);
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
f = (a.enc = {}),
|
||||||
|
p = (f.Hex = {
|
||||||
|
stringify: function (e) {
|
||||||
|
for (
|
||||||
|
var t = e.words,
|
||||||
|
r = e.sigBytes,
|
||||||
|
n = [],
|
||||||
|
i = 0;
|
||||||
|
i < r;
|
||||||
|
i++
|
||||||
|
) {
|
||||||
|
var o =
|
||||||
|
(t[i >>> 2] >>> (24 - (i % 4) * 8)) & 255;
|
||||||
|
n.push((o >>> 4).toString(16)),
|
||||||
|
n.push((15 & o).toString(16));
|
||||||
|
}
|
||||||
|
return n.join("");
|
||||||
|
},
|
||||||
|
parse: function (e) {
|
||||||
|
for (
|
||||||
|
var t = e.length, r = [], n = 0;
|
||||||
|
n < t;
|
||||||
|
n += 2
|
||||||
|
)
|
||||||
|
r[n >>> 3] |=
|
||||||
|
parseInt(e.substr(n, 2), 16) <<
|
||||||
|
(24 - (n % 8) * 4);
|
||||||
|
return new l.init(r, t / 2);
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
h = (f.Latin1 = {
|
||||||
|
stringify: function (e) {
|
||||||
|
for (
|
||||||
|
var t = e.words,
|
||||||
|
r = e.sigBytes,
|
||||||
|
n = [],
|
||||||
|
i = 0;
|
||||||
|
i < r;
|
||||||
|
i++
|
||||||
|
) {
|
||||||
|
var o =
|
||||||
|
(t[i >>> 2] >>> (24 - (i % 4) * 8)) & 255;
|
||||||
|
n.push(String.fromCharCode(o));
|
||||||
|
}
|
||||||
|
return n.join("");
|
||||||
|
},
|
||||||
|
parse: function (e) {
|
||||||
|
for (
|
||||||
|
var t = e.length, r = [], n = 0;
|
||||||
|
n < t;
|
||||||
|
n++
|
||||||
|
)
|
||||||
|
r[n >>> 2] |=
|
||||||
|
(255 & e.charCodeAt(n)) <<
|
||||||
|
(24 - (n % 4) * 8);
|
||||||
|
return new l.init(r, t);
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
d = (f.Utf8 = {
|
||||||
|
stringify: function (e) {
|
||||||
|
try {
|
||||||
|
return decodeURIComponent(
|
||||||
|
escape(h.stringify(e))
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
throw Error("Malformed UTF-8 data");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
parse: function (e) {
|
||||||
|
return h.parse(unescape(encodeURIComponent(e)));
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
g = (c.BufferedBlockAlgorithm = u.extend({
|
||||||
|
reset: function () {
|
||||||
|
(this._data = new l.init()),
|
||||||
|
(this._nDataBytes = 0);
|
||||||
|
},
|
||||||
|
_append: function (e) {
|
||||||
|
"string" == typeof e && (e = d.parse(e)),
|
||||||
|
this._data.concat(e),
|
||||||
|
(this._nDataBytes += e.sigBytes);
|
||||||
|
},
|
||||||
|
_process: function (t) {
|
||||||
|
var r,
|
||||||
|
n = this._data,
|
||||||
|
i = n.words,
|
||||||
|
o = n.sigBytes,
|
||||||
|
s = this.blockSize,
|
||||||
|
a = o / (4 * s),
|
||||||
|
c =
|
||||||
|
(a = t
|
||||||
|
? e.ceil(a)
|
||||||
|
: e.max(
|
||||||
|
(0 | a) - this._minBufferSize,
|
||||||
|
0
|
||||||
|
)) * s,
|
||||||
|
u = e.min(4 * c, o);
|
||||||
|
if (c) {
|
||||||
|
for (var f = 0; f < c; f += s)
|
||||||
|
this._doProcessBlock(i, f);
|
||||||
|
(r = i.splice(0, c)), (n.sigBytes -= u);
|
||||||
|
}
|
||||||
|
return new l.init(r, u);
|
||||||
|
},
|
||||||
|
clone: function () {
|
||||||
|
var e = u.clone.call(this);
|
||||||
|
return (e._data = this._data.clone()), e;
|
||||||
|
},
|
||||||
|
_minBufferSize: 0,
|
||||||
|
}));
|
||||||
|
c.Hasher = g.extend({
|
||||||
|
cfg: u.extend(),
|
||||||
|
init: function (e) {
|
||||||
|
(this.cfg = this.cfg.extend(e)), this.reset();
|
||||||
|
},
|
||||||
|
reset: function () {
|
||||||
|
g.reset.call(this), this._doReset();
|
||||||
|
},
|
||||||
|
update: function (e) {
|
||||||
|
return this._append(e), this._process(), this;
|
||||||
|
},
|
||||||
|
finalize: function (e) {
|
||||||
|
return e && this._append(e), this._doFinalize();
|
||||||
|
},
|
||||||
|
blockSize: 16,
|
||||||
|
_createHelper: function (e) {
|
||||||
|
return function (t, r) {
|
||||||
|
return new e.init(r).finalize(t);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
_createHmacHelper: function (e) {
|
||||||
|
return function (t, r) {
|
||||||
|
return new y.HMAC.init(e, r).finalize(t);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
|
var y = (a.algo = {});
|
||||||
|
return a;
|
||||||
|
})(Math);
|
||||||
|
|
||||||
|
var u = function (e, t) {
|
||||||
|
var r, n;
|
||||||
|
e.exports =
|
||||||
|
((r = a.lib.Base),
|
||||||
|
(n = a.enc.Utf8),
|
||||||
|
void (a.algo.HMAC = r.extend({
|
||||||
|
init: function (e, t) {
|
||||||
|
(e = this._hasher = new e.init()),
|
||||||
|
"string" == typeof t && (t = n.parse(t));
|
||||||
|
var r = e.blockSize,
|
||||||
|
i = 4 * r;
|
||||||
|
t.sigBytes > i && (t = e.finalize(t)), t.clamp();
|
||||||
|
for (
|
||||||
|
var o = (this._oKey = t.clone()),
|
||||||
|
s = (this._iKey = t.clone()),
|
||||||
|
a = o.words,
|
||||||
|
c = s.words,
|
||||||
|
u = 0;
|
||||||
|
u < r;
|
||||||
|
u++
|
||||||
|
)
|
||||||
|
(a[u] ^= 0x5c5c5c5c), (c[u] ^= 0x36363636);
|
||||||
|
(o.sigBytes = s.sigBytes = i), this.reset();
|
||||||
|
},
|
||||||
|
reset: function () {
|
||||||
|
var e = this._hasher;
|
||||||
|
e.reset(), e.update(this._iKey);
|
||||||
|
},
|
||||||
|
update: function (e) {
|
||||||
|
return this._hasher.update(e), this;
|
||||||
|
},
|
||||||
|
finalize: function (e) {
|
||||||
|
var t = this._hasher,
|
||||||
|
r = t.finalize(e);
|
||||||
|
return (
|
||||||
|
t.reset(),
|
||||||
|
t.finalize(this._oKey.clone().concat(r))
|
||||||
|
);
|
||||||
|
},
|
||||||
|
})));
|
||||||
|
}
|
||||||
|
|
||||||
|
var c = s(function (e, t) {
|
||||||
|
var r, n, i, o, s, c, u, l, f;
|
||||||
|
e.exports =
|
||||||
|
((r = Math),
|
||||||
|
(i = (n = a.lib).WordArray),
|
||||||
|
(o = n.Hasher),
|
||||||
|
(s = a.algo),
|
||||||
|
(c = []),
|
||||||
|
(u = []),
|
||||||
|
(function () {
|
||||||
|
function e(e) {
|
||||||
|
return (0x100000000 * (e - (0 | e))) | 0;
|
||||||
|
}
|
||||||
|
for (var t = 2, n = 0; n < 64; )
|
||||||
|
(function (e) {
|
||||||
|
for (var t = r.sqrt(e), n = 2; n <= t; n++)
|
||||||
|
if (!(e % n)) return !1;
|
||||||
|
return !0;
|
||||||
|
})(t) &&
|
||||||
|
(n < 8 && (c[n] = e(r.pow(t, 0.5))),
|
||||||
|
(u[n] = e(r.pow(t, 1 / 3))),
|
||||||
|
n++),
|
||||||
|
t++;
|
||||||
|
})(),
|
||||||
|
(l = []),
|
||||||
|
(f = s.SHA256 =
|
||||||
|
o.extend({
|
||||||
|
_doReset: function () {
|
||||||
|
this._hash = new i.init(c.slice(0));
|
||||||
|
},
|
||||||
|
_doProcessBlock: function (e, t) {
|
||||||
|
for (
|
||||||
|
var r = this._hash.words,
|
||||||
|
n = r[0],
|
||||||
|
i = r[1],
|
||||||
|
o = r[2],
|
||||||
|
s = r[3],
|
||||||
|
a = r[4],
|
||||||
|
c = r[5],
|
||||||
|
f = r[6],
|
||||||
|
p = r[7],
|
||||||
|
h = 0;
|
||||||
|
h < 64;
|
||||||
|
h++
|
||||||
|
) {
|
||||||
|
if (h < 16) l[h] = 0 | e[t + h];
|
||||||
|
else {
|
||||||
|
var d = l[h - 15],
|
||||||
|
g =
|
||||||
|
((d << 25) | (d >>> 7)) ^
|
||||||
|
((d << 14) | (d >>> 18)) ^
|
||||||
|
(d >>> 3),
|
||||||
|
y = l[h - 2],
|
||||||
|
m =
|
||||||
|
((y << 15) | (y >>> 17)) ^
|
||||||
|
((y << 13) | (y >>> 19)) ^
|
||||||
|
(y >>> 10);
|
||||||
|
l[h] = g + l[h - 7] + m + l[h - 16];
|
||||||
|
}
|
||||||
|
var v = (n & i) ^ (n & o) ^ (i & o),
|
||||||
|
b =
|
||||||
|
((n << 30) | (n >>> 2)) ^
|
||||||
|
((n << 19) | (n >>> 13)) ^
|
||||||
|
((n << 10) | (n >>> 22)),
|
||||||
|
_ =
|
||||||
|
p +
|
||||||
|
(((a << 26) | (a >>> 6)) ^
|
||||||
|
((a << 21) | (a >>> 11)) ^
|
||||||
|
((a << 7) | (a >>> 25))) +
|
||||||
|
((a & c) ^ (~a & f)) +
|
||||||
|
u[h] +
|
||||||
|
l[h];
|
||||||
|
(p = f),
|
||||||
|
(f = c),
|
||||||
|
(c = a),
|
||||||
|
(a = (s + _) | 0),
|
||||||
|
(s = o),
|
||||||
|
(o = i),
|
||||||
|
(i = n),
|
||||||
|
(n = (_ + (b + v)) | 0);
|
||||||
|
}
|
||||||
|
(r[0] = (r[0] + n) | 0),
|
||||||
|
(r[1] = (r[1] + i) | 0),
|
||||||
|
(r[2] = (r[2] + o) | 0),
|
||||||
|
(r[3] = (r[3] + s) | 0),
|
||||||
|
(r[4] = (r[4] + a) | 0),
|
||||||
|
(r[5] = (r[5] + c) | 0),
|
||||||
|
(r[6] = (r[6] + f) | 0),
|
||||||
|
(r[7] = (r[7] + p) | 0);
|
||||||
|
},
|
||||||
|
_doFinalize: function () {
|
||||||
|
var e = this._data,
|
||||||
|
t = e.words,
|
||||||
|
n = 8 * this._nDataBytes,
|
||||||
|
i = 8 * e.sigBytes;
|
||||||
|
return (
|
||||||
|
(t[i >>> 5] |= 128 << (24 - (i % 32))),
|
||||||
|
(t[14 + (((i + 64) >>> 9) << 4)] = r.floor(
|
||||||
|
n / 0x100000000
|
||||||
|
)),
|
||||||
|
(t[15 + (((i + 64) >>> 9) << 4)] = n),
|
||||||
|
(e.sigBytes = 4 * t.length),
|
||||||
|
this._process(),
|
||||||
|
this._hash
|
||||||
|
);
|
||||||
|
},
|
||||||
|
clone: function () {
|
||||||
|
var e = o.clone.call(this);
|
||||||
|
return (e._hash = this._hash.clone()), e;
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
(a.SHA256 = o._createHelper(f)),
|
||||||
|
(a.HmacSHA256 = o._createHmacHelper(f)),
|
||||||
|
a.SHA256);
|
||||||
|
}),
|
||||||
|
u =
|
||||||
|
(s()),
|
||||||
|
l = {
|
||||||
|
hmac: function (e, t) {
|
||||||
|
return u(t, e);
|
||||||
|
},
|
||||||
|
sha256: function (e) {
|
||||||
|
return c(e);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
f = [
|
||||||
|
"authorization",
|
||||||
|
"content-type",
|
||||||
|
"content-length",
|
||||||
|
"user-agent",
|
||||||
|
"presigned-expires",
|
||||||
|
"expect",
|
||||||
|
"x-amzn-trace-id",
|
||||||
|
],
|
||||||
|
p = function (e) {
|
||||||
|
try {
|
||||||
|
return encodeURIComponent(e)
|
||||||
|
.replace(/[^A-Za-z0-9_.~\-%]+/g, escape)
|
||||||
|
.replace(/[*]/g, function (e) {
|
||||||
|
return "%".concat(
|
||||||
|
e.charCodeAt(0).toString(16).toUpperCase()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
h = function (e) {
|
||||||
|
return Object.keys(e)
|
||||||
|
.sort()
|
||||||
|
.map(function (t) {
|
||||||
|
var r = e[t];
|
||||||
|
if (null != r) {
|
||||||
|
var n = p(t);
|
||||||
|
if (n)
|
||||||
|
return Array.isArray(r)
|
||||||
|
? ""
|
||||||
|
.concat(n, "=")
|
||||||
|
.concat(
|
||||||
|
r.map(p).sort().join("&".concat(n, "="))
|
||||||
|
)
|
||||||
|
: "".concat(n, "=").concat(p(r));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter(function (e) {
|
||||||
|
return e;
|
||||||
|
})
|
||||||
|
.join("&");
|
||||||
|
};
|
||||||
926
temp/lib-uploader.4.js
Normal file
926
temp/lib-uploader.4.js
Normal file
@ -0,0 +1,926 @@
|
|||||||
|
( () => {
|
||||||
|
"use strict";
|
||||||
|
var e = {}
|
||||||
|
, t = {};
|
||||||
|
function o(a) {
|
||||||
|
var n = t[a];
|
||||||
|
if (void 0 !== n)
|
||||||
|
return n.exports;
|
||||||
|
var r = t[a] = {
|
||||||
|
id: a,
|
||||||
|
loaded: !1,
|
||||||
|
exports: {}
|
||||||
|
};
|
||||||
|
return e[a].call(r.exports, r, r.exports, o),
|
||||||
|
r.loaded = !0,
|
||||||
|
r.exports
|
||||||
|
}
|
||||||
|
o.m = e,
|
||||||
|
o.n = function(e) {
|
||||||
|
var t = e && e.__esModule ? function() {
|
||||||
|
return e.default
|
||||||
|
}
|
||||||
|
: function() {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
;
|
||||||
|
return o.d(t, {
|
||||||
|
a: t
|
||||||
|
}),
|
||||||
|
t
|
||||||
|
}
|
||||||
|
,
|
||||||
|
( () => {
|
||||||
|
var e, t = Object.getPrototypeOf ? function(e) {
|
||||||
|
return Object.getPrototypeOf(e)
|
||||||
|
}
|
||||||
|
: function(e) {
|
||||||
|
return e.__proto__
|
||||||
|
}
|
||||||
|
;
|
||||||
|
o.t = function(a, n) {
|
||||||
|
if (1 & n && (a = this(a)),
|
||||||
|
8 & n || "object" == typeof a && a && (4 & n && a.__esModule || 16 & n && "function" == typeof a.then))
|
||||||
|
return a;
|
||||||
|
var r = Object.create(null);
|
||||||
|
o.r(r);
|
||||||
|
var i = {};
|
||||||
|
e = e || [null, t({}), t([]), t(t)];
|
||||||
|
for (var c = 2 & n && a; "object" == typeof c && !~e.indexOf(c); c = t(c))
|
||||||
|
Object.getOwnPropertyNames(c).forEach((function(e) {
|
||||||
|
i[e] = function() {
|
||||||
|
return a[e]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
return i.default = function() {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
,
|
||||||
|
o.d(r, i),
|
||||||
|
r
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)(),
|
||||||
|
o.d = function(e, t) {
|
||||||
|
for (var a in t)
|
||||||
|
o.o(t, a) && !o.o(e, a) && Object.defineProperty(e, a, {
|
||||||
|
enumerable: !0,
|
||||||
|
get: t[a]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
,
|
||||||
|
o.f = {},
|
||||||
|
o.e = function(e) {
|
||||||
|
return Promise.all(Object.keys(o.f).reduce((function(t, a) {
|
||||||
|
return o.f[a](e, t),
|
||||||
|
t
|
||||||
|
}
|
||||||
|
), []))
|
||||||
|
}
|
||||||
|
,
|
||||||
|
o.hmd = function(e) {
|
||||||
|
return !(e = Object.create(e)).children && (e.children = []),
|
||||||
|
Object.defineProperty(e, "exports", {
|
||||||
|
enumerable: !0,
|
||||||
|
set: function() {
|
||||||
|
throw Error("ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: " + e.id)
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
e
|
||||||
|
}
|
||||||
|
,
|
||||||
|
o.u = function(e) {
|
||||||
|
return "static/js/async/" + ({
|
||||||
|
108: "ai-tool/explore/page",
|
||||||
|
1097: "ai-tool/activity/page",
|
||||||
|
1106: "heic2any",
|
||||||
|
1144: "ai-tool/image/generate/page",
|
||||||
|
1275: "feature-editor",
|
||||||
|
1385: "activity-award",
|
||||||
|
1460: "ai-tool/video/lip-sync/generate/page",
|
||||||
|
1553: "lv-upload-components",
|
||||||
|
1554: "ai-tool/work-detail/(id$)/page",
|
||||||
|
1618: "okee-fe-icons",
|
||||||
|
1637: "lib-ever-cloud-sdk",
|
||||||
|
1732: "ThirdPartyCallback",
|
||||||
|
1857: "lib-account-api-oversea",
|
||||||
|
1990: "bundle_file-md5-calc-service",
|
||||||
|
2073: "ExplorePageWorkDetailContribution",
|
||||||
|
2126: "lib-polyfill",
|
||||||
|
2175: "lv-useless-components",
|
||||||
|
2190: "ui-framework",
|
||||||
|
2213: "PersonalPageGenerateContribution",
|
||||||
|
2349: "Activity",
|
||||||
|
2448: "bundle_graphic_toolkit_service",
|
||||||
|
2467: "DataSubjectRequestBlock",
|
||||||
|
2550: "sider-menu-notification",
|
||||||
|
2652: "bundle_offscreen_canvas_editor_service",
|
||||||
|
2658: "Asset",
|
||||||
|
2707: "lib-lodash",
|
||||||
|
2778: "xgplayer-encrypt__delayed",
|
||||||
|
2870: "lib-graphemer",
|
||||||
|
2906: "ai-tool/video/generate/page",
|
||||||
|
2945: "byted-xgplayer~0",
|
||||||
|
3061: "sider-menu-app-download",
|
||||||
|
3218: "CookieManage",
|
||||||
|
3231: "lib-vetoolkit",
|
||||||
|
3321: "Home",
|
||||||
|
3537: "HomePageGenerateContribution",
|
||||||
|
3613: "title-bar-api-invoke-entrance",
|
||||||
|
3796: "activity-credit",
|
||||||
|
3906: "Login",
|
||||||
|
3971: "lib-firebase",
|
||||||
|
3972: "byted-xgplayer~4",
|
||||||
|
4045: "lib-account-api",
|
||||||
|
4047: "WorkflowEditor~a870cb0f",
|
||||||
|
4104: "byted-xgplayer~2",
|
||||||
|
4118: "PersonalPageWorkDetailContribution",
|
||||||
|
4161: "StoryEditor~76f86101",
|
||||||
|
4266: "DataSubjectRequestDownload",
|
||||||
|
4393: "lib-byted~2",
|
||||||
|
4485: "ai-tool/home/page",
|
||||||
|
4530: "lib-byted~0",
|
||||||
|
4644: "work-detail",
|
||||||
|
4650: "activity-gift",
|
||||||
|
478: "mweb-record-list",
|
||||||
|
4889: "lv-secondary-components",
|
||||||
|
4958: "sider-menu-feedback",
|
||||||
|
513: "lib-mobx",
|
||||||
|
5147: "bundle_story-draft-model",
|
||||||
|
5216: "Workflow",
|
||||||
|
5326: "HomePagePublishContribution",
|
||||||
|
5397: "DataSubjectRequest",
|
||||||
|
5454: "lib-byted~3",
|
||||||
|
5541: "History",
|
||||||
|
5557: "SearchPage",
|
||||||
|
5635: "DataSubjectRequestSubmit",
|
||||||
|
5676: "HistoryDetail",
|
||||||
|
5792: "StoryEditorSideload",
|
||||||
|
5902: "lib-slardar",
|
||||||
|
5949: "base-editor",
|
||||||
|
6125: "lib-crypto",
|
||||||
|
6142: "ai-tool/login/page",
|
||||||
|
6238: "ttwid__delayed",
|
||||||
|
6367: "lib-report",
|
||||||
|
640: "lv-components",
|
||||||
|
6622: "ImageEdit~1",
|
||||||
|
6777: "lib-byted~1",
|
||||||
|
6810: "GuestPerson",
|
||||||
|
7010: "byted-lvRender",
|
||||||
|
7135: "browser-image-compression",
|
||||||
|
7161: "sider-menu-invitation",
|
||||||
|
7163: "lib-uploader",
|
||||||
|
7249: "ai-tool/video/action-copy/generate/page",
|
||||||
|
7288: "title-bar-search",
|
||||||
|
7308: "ImageEdit~0",
|
||||||
|
733: "ai-tool/asset/page",
|
||||||
|
7375: "ai-tool/personal/(id$)/page",
|
||||||
|
7570: "mweb-commercial",
|
||||||
|
7631: "WorkflowEditor~55875ab1",
|
||||||
|
7641: "lib-xstate",
|
||||||
|
7650: "lib-bridge",
|
||||||
|
7694: "okee-mweb-icons",
|
||||||
|
8034: "NoUsePermission",
|
||||||
|
8139: "StoryEditor~1",
|
||||||
|
8263: "xgplayer__delayed",
|
||||||
|
8293: "bundle_content-generation~0",
|
||||||
|
83: "bundle_content-generation~afd697dc",
|
||||||
|
8349: "HomePageWorkDetailContribution",
|
||||||
|
8425: "byted-xgplayer~1",
|
||||||
|
8438: "ExplorePagePublishContribution",
|
||||||
|
8503: "utif",
|
||||||
|
8523: "InviteFission",
|
||||||
|
8574: "Explore",
|
||||||
|
8608: "ExplorePageGenerateContribution",
|
||||||
|
8863: "lib-lottie",
|
||||||
|
8941: "ContentGeneration",
|
||||||
|
8991: "byted-xgplayer~3",
|
||||||
|
9028: "block",
|
||||||
|
9168: "lib-jszip",
|
||||||
|
9391: "bundle_character-generate-modal-service",
|
||||||
|
9392: "$",
|
||||||
|
9410: "absolution-position-slot-help-center",
|
||||||
|
9415: "StoryEditor~0d3dcdc8",
|
||||||
|
9500: "title-bar-user",
|
||||||
|
9580: "sider-menu-activity",
|
||||||
|
9860: "sider-menu-product-hunt"
|
||||||
|
}[e] || e) + "." + {
|
||||||
|
1001: "3432a089",
|
||||||
|
1054: "43e8359e",
|
||||||
|
108: "0313279f",
|
||||||
|
1081: "ea0c3c30",
|
||||||
|
1097: "201261e4",
|
||||||
|
1106: "987c9f41",
|
||||||
|
1144: "f3f9c414",
|
||||||
|
1193: "3b66aeb0",
|
||||||
|
1275: "5f54a6ad",
|
||||||
|
1330: "41930b8a",
|
||||||
|
1384: "90e9d8ca",
|
||||||
|
1385: "05eab03a",
|
||||||
|
1416: "39bdfdef",
|
||||||
|
1460: "0830856c",
|
||||||
|
1553: "bd079fd8",
|
||||||
|
1554: "30fffdc3",
|
||||||
|
1568: "2055fc67",
|
||||||
|
1591: "798586e8",
|
||||||
|
1618: "54b7bc13",
|
||||||
|
1637: "8d534a3a",
|
||||||
|
1654: "e8e90aea",
|
||||||
|
1732: "8ed67bc6",
|
||||||
|
1830: "dcb0a42d",
|
||||||
|
1857: "7bd862fd",
|
||||||
|
187: "cd70137c",
|
||||||
|
1877: "1ce37df2",
|
||||||
|
1990: "b3123294",
|
||||||
|
2060: "32b141d2",
|
||||||
|
2073: "20952ef2",
|
||||||
|
2077: "c3fbc6da",
|
||||||
|
2126: "ca14feb5",
|
||||||
|
2175: "b49f4669",
|
||||||
|
2190: "7f163819",
|
||||||
|
2213: "7ebd49c8",
|
||||||
|
2314: "83dec038",
|
||||||
|
2349: "7b154d73",
|
||||||
|
2448: "6211f952",
|
||||||
|
2467: "a89fadca",
|
||||||
|
2488: "3ccb0515",
|
||||||
|
2550: "8b335470",
|
||||||
|
2652: "a22b996c",
|
||||||
|
2658: "44bca06b",
|
||||||
|
2707: "5202286f",
|
||||||
|
2749: "4043d40d",
|
||||||
|
277: "0e986d8e",
|
||||||
|
2778: "5526f2e3",
|
||||||
|
2870: "b9bba982",
|
||||||
|
2906: "ed777de1",
|
||||||
|
2938: "605eb7df",
|
||||||
|
2945: "7d60812b",
|
||||||
|
2969: "53a2218e",
|
||||||
|
3013: "265ac0fd",
|
||||||
|
3061: "aaf73050",
|
||||||
|
3064: "ab3a8079",
|
||||||
|
3138: "7d590a7a",
|
||||||
|
3164: "315a9192",
|
||||||
|
3189: "b4080d09",
|
||||||
|
3218: "02485d1e",
|
||||||
|
3231: "8b22b69c",
|
||||||
|
3321: "6bc5e5fe",
|
||||||
|
3384: "a7611910",
|
||||||
|
3520: "0a5513ab",
|
||||||
|
3527: "82fab629",
|
||||||
|
3537: "0247a444",
|
||||||
|
3542: "7b9fad59",
|
||||||
|
3613: "46ee9d20",
|
||||||
|
371: "b6c927c3",
|
||||||
|
3758: "a7821af7",
|
||||||
|
3796: "b8a99599",
|
||||||
|
3855: "f5008921",
|
||||||
|
3906: "57f24cbf",
|
||||||
|
3971: "45d02728",
|
||||||
|
3972: "8db8b2d5",
|
||||||
|
4037: "6b0803cb",
|
||||||
|
4045: "565dcba2",
|
||||||
|
4047: "517887e9",
|
||||||
|
4049: "31b51158",
|
||||||
|
4104: "10387a1f",
|
||||||
|
4118: "4b9233b8",
|
||||||
|
4141: "4ff0a8c4",
|
||||||
|
4161: "5a26688d",
|
||||||
|
4189: "b0ddb335",
|
||||||
|
4266: "0e87ddf5",
|
||||||
|
4393: "04b71aa3",
|
||||||
|
4431: "611fb827",
|
||||||
|
4485: "9f7a319b",
|
||||||
|
4530: "4ae91e2a",
|
||||||
|
4605: "f1d169ba",
|
||||||
|
4644: "165b8bf4",
|
||||||
|
465: "fe175ba8",
|
||||||
|
4650: "aa300f46",
|
||||||
|
4717: "82e4464d",
|
||||||
|
478: "f48edd30",
|
||||||
|
4856: "f05c0c07",
|
||||||
|
4882: "405c6f78",
|
||||||
|
4889: "139d96c4",
|
||||||
|
4933: "ababbe11",
|
||||||
|
4937: "7a60bea3",
|
||||||
|
4946: "a9a707fb",
|
||||||
|
4958: "4a870095",
|
||||||
|
5055: "f9a15e83",
|
||||||
|
5074: "04883412",
|
||||||
|
5096: "d6006808",
|
||||||
|
5112: "f0907e48",
|
||||||
|
513: "0e0cfe2c",
|
||||||
|
5147: "55af426f",
|
||||||
|
5216: "4076d83d",
|
||||||
|
5281: "5d3e4359",
|
||||||
|
5326: "879a1012",
|
||||||
|
5362: "acefdad1",
|
||||||
|
5397: "0e90bb5a",
|
||||||
|
5454: "c540284c",
|
||||||
|
5504: "99486bf4",
|
||||||
|
5518: "b264e8cf",
|
||||||
|
5521: "529cdb9a",
|
||||||
|
5541: "5f704b80",
|
||||||
|
5557: "bd9752e8",
|
||||||
|
5635: "cf67344a",
|
||||||
|
5676: "41ada6be",
|
||||||
|
5711: "129bd0d2",
|
||||||
|
5757: "437b47fe",
|
||||||
|
5792: "3c340797",
|
||||||
|
5842: "0814924c",
|
||||||
|
5862: "0de90f9b",
|
||||||
|
59: "7344b495",
|
||||||
|
5902: "c9801873",
|
||||||
|
5949: "3d970df6",
|
||||||
|
5980: "29ab9824",
|
||||||
|
6082: "80748539",
|
||||||
|
6088: "feb41773",
|
||||||
|
6125: "b8c57ce4",
|
||||||
|
613: "6a423ba5",
|
||||||
|
6142: "72e6f5ba",
|
||||||
|
6192: "252b25c0",
|
||||||
|
6238: "8d3467ab",
|
||||||
|
6274: "c69182eb",
|
||||||
|
6351: "02a0e394",
|
||||||
|
6367: "2c9b2aeb",
|
||||||
|
640: "2b6b2658",
|
||||||
|
6533: "c31580fa",
|
||||||
|
6545: "dc3d1849",
|
||||||
|
6622: "0c651f51",
|
||||||
|
6676: "f97ee537",
|
||||||
|
6678: "e5a83cb6",
|
||||||
|
6680: "0ca0a962",
|
||||||
|
6777: "826a89a8",
|
||||||
|
6790: "a23b0f4d",
|
||||||
|
6810: "4d6ed5bd",
|
||||||
|
6826: "0f8021f5",
|
||||||
|
6936: "382b0f8b",
|
||||||
|
6948: "5c0df7f4",
|
||||||
|
7010: "add8a639",
|
||||||
|
7024: "d730f053",
|
||||||
|
7131: "758ccaad",
|
||||||
|
7135: "472d31b5",
|
||||||
|
7161: "479fc40c",
|
||||||
|
7163: "c1f2476f",
|
||||||
|
7174: "a0d9bed7",
|
||||||
|
7249: "c0517e99",
|
||||||
|
7288: "5a5ab8c5",
|
||||||
|
7308: "bcf12382",
|
||||||
|
733: "dd49d967",
|
||||||
|
7375: "1253c86a",
|
||||||
|
742: "9b4ba01c",
|
||||||
|
7429: "3c19e417",
|
||||||
|
7506: "94ba989c",
|
||||||
|
753: "6de48a23",
|
||||||
|
7570: "62ad8e7a",
|
||||||
|
7631: "8a2dd599",
|
||||||
|
7641: "3ced0dde",
|
||||||
|
7650: "536d073a",
|
||||||
|
7694: "a9e29427",
|
||||||
|
7704: "d239b009",
|
||||||
|
795: "a4fca577",
|
||||||
|
8034: "2e8e34c2",
|
||||||
|
8059: "aaefb412",
|
||||||
|
8078: "4e456f1a",
|
||||||
|
81: "3acce1f9",
|
||||||
|
8139: "b6e27689",
|
||||||
|
8165: "3aee4b01",
|
||||||
|
817: "75d8c7e3",
|
||||||
|
8185: "49fae538",
|
||||||
|
8263: "a7d02df1",
|
||||||
|
8293: "f71b9180",
|
||||||
|
83: "41e7f7a2",
|
||||||
|
8349: "2e6f64eb",
|
||||||
|
8425: "3dfe75b5",
|
||||||
|
8438: "23cbb5bd",
|
||||||
|
8461: "fc325dbb",
|
||||||
|
849: "1314d2e5",
|
||||||
|
8503: "0a1d7cde",
|
||||||
|
8523: "997c4661",
|
||||||
|
8537: "1bc49b80",
|
||||||
|
8574: "11c8e5da",
|
||||||
|
8608: "43d9bffc",
|
||||||
|
862: "5cb4b064",
|
||||||
|
8757: "b19a8596",
|
||||||
|
8774: "979d646a",
|
||||||
|
8792: "6239ea1a",
|
||||||
|
8835: "91002e36",
|
||||||
|
8863: "4729dbce",
|
||||||
|
8872: "0ebcc17e",
|
||||||
|
8883: "0ee86a42",
|
||||||
|
8941: "6707cc7f",
|
||||||
|
8962: "58114e1e",
|
||||||
|
8991: "b3afb72a",
|
||||||
|
9028: "48fddc4b",
|
||||||
|
9117: "ef5a65b9",
|
||||||
|
9118: "dcfd9a25",
|
||||||
|
9120: "103f38a7",
|
||||||
|
9168: "23bdc0b9",
|
||||||
|
9327: "3e3522c8",
|
||||||
|
9338: "f5f7f759",
|
||||||
|
9391: "b826cff9",
|
||||||
|
9392: "8f2a5105",
|
||||||
|
9406: "dbf0ed48",
|
||||||
|
9410: "8439374f",
|
||||||
|
9415: "4064df8f",
|
||||||
|
9429: "f95c17a9",
|
||||||
|
9433: "dba8704d",
|
||||||
|
9500: "713a4041",
|
||||||
|
9527: "054054fe",
|
||||||
|
9580: "7f752c89",
|
||||||
|
9647: "6ea65f87",
|
||||||
|
9748: "e43a1259",
|
||||||
|
9860: "decddbaf",
|
||||||
|
9906: "7cb7bfa8",
|
||||||
|
9944: "a620d57f"
|
||||||
|
}[e] + ".js"
|
||||||
|
}
|
||||||
|
,
|
||||||
|
o.miniCssF = function(e) {
|
||||||
|
return "static/css/async/" + ({
|
||||||
|
108: "ai-tool/explore/page",
|
||||||
|
1097: "ai-tool/activity/page",
|
||||||
|
1144: "ai-tool/image/generate/page",
|
||||||
|
1275: "feature-editor",
|
||||||
|
1385: "activity-award",
|
||||||
|
1460: "ai-tool/video/lip-sync/generate/page",
|
||||||
|
1553: "lv-upload-components",
|
||||||
|
1554: "ai-tool/work-detail/(id$)/page",
|
||||||
|
2073: "ExplorePageWorkDetailContribution",
|
||||||
|
2175: "lv-useless-components",
|
||||||
|
2213: "PersonalPageGenerateContribution",
|
||||||
|
2349: "Activity",
|
||||||
|
2467: "DataSubjectRequestBlock",
|
||||||
|
2550: "sider-menu-notification",
|
||||||
|
2652: "bundle_offscreen_canvas_editor_service",
|
||||||
|
2658: "Asset",
|
||||||
|
2906: "ai-tool/video/generate/page",
|
||||||
|
3061: "sider-menu-app-download",
|
||||||
|
3218: "CookieManage",
|
||||||
|
3321: "Home",
|
||||||
|
3537: "HomePageGenerateContribution",
|
||||||
|
3613: "title-bar-api-invoke-entrance",
|
||||||
|
3796: "activity-credit",
|
||||||
|
3906: "Login",
|
||||||
|
4047: "WorkflowEditor~a870cb0f",
|
||||||
|
4118: "PersonalPageWorkDetailContribution",
|
||||||
|
4161: "StoryEditor~76f86101",
|
||||||
|
4266: "DataSubjectRequestDownload",
|
||||||
|
4485: "ai-tool/home/page",
|
||||||
|
4644: "work-detail",
|
||||||
|
4650: "activity-gift",
|
||||||
|
478: "mweb-record-list",
|
||||||
|
4889: "lv-secondary-components",
|
||||||
|
5147: "bundle_story-draft-model",
|
||||||
|
5216: "Workflow",
|
||||||
|
5326: "HomePagePublishContribution",
|
||||||
|
5397: "DataSubjectRequest",
|
||||||
|
5541: "History",
|
||||||
|
5557: "SearchPage",
|
||||||
|
5635: "DataSubjectRequestSubmit",
|
||||||
|
5676: "HistoryDetail",
|
||||||
|
5792: "StoryEditorSideload",
|
||||||
|
6142: "ai-tool/login/page",
|
||||||
|
640: "lv-components",
|
||||||
|
6622: "ImageEdit~1",
|
||||||
|
6810: "GuestPerson",
|
||||||
|
7249: "ai-tool/video/action-copy/generate/page",
|
||||||
|
7288: "title-bar-search",
|
||||||
|
7308: "ImageEdit~0",
|
||||||
|
733: "ai-tool/asset/page",
|
||||||
|
7375: "ai-tool/personal/(id$)/page",
|
||||||
|
7570: "mweb-commercial",
|
||||||
|
7631: "WorkflowEditor~55875ab1",
|
||||||
|
8034: "NoUsePermission",
|
||||||
|
8139: "StoryEditor~1",
|
||||||
|
83: "bundle_content-generation~afd697dc",
|
||||||
|
8349: "HomePageWorkDetailContribution",
|
||||||
|
8438: "ExplorePagePublishContribution",
|
||||||
|
8523: "InviteFission",
|
||||||
|
8574: "Explore",
|
||||||
|
8608: "ExplorePageGenerateContribution",
|
||||||
|
8941: "ContentGeneration",
|
||||||
|
9028: "block",
|
||||||
|
9391: "bundle_character-generate-modal-service",
|
||||||
|
9392: "$",
|
||||||
|
9410: "absolution-position-slot-help-center",
|
||||||
|
9415: "StoryEditor~0d3dcdc8",
|
||||||
|
9500: "title-bar-user",
|
||||||
|
9580: "sider-menu-activity",
|
||||||
|
9860: "sider-menu-product-hunt"
|
||||||
|
}[e] || e) + "." + {
|
||||||
|
1005: "eb1b1784",
|
||||||
|
108: "5d9f0383",
|
||||||
|
1097: "5fcf72dd",
|
||||||
|
1144: "60dcc01a",
|
||||||
|
1275: "05d8e910",
|
||||||
|
1385: "b0299845",
|
||||||
|
1460: "60dcc01a",
|
||||||
|
1553: "b4df8476",
|
||||||
|
1554: "c586851b",
|
||||||
|
2073: "066d87bf",
|
||||||
|
2175: "0aafe5b6",
|
||||||
|
2213: "3fe5a48e",
|
||||||
|
2349: "0f63ba72",
|
||||||
|
2467: "2c824d43",
|
||||||
|
2550: "e0382620",
|
||||||
|
2652: "8ee2272e",
|
||||||
|
2658: "84619fb6",
|
||||||
|
288: "86dd0098",
|
||||||
|
2906: "60dcc01a",
|
||||||
|
3013: "d6c76393",
|
||||||
|
3061: "11bcf1a0",
|
||||||
|
3218: "f91becbe",
|
||||||
|
3321: "7592c319",
|
||||||
|
3537: "6018d688",
|
||||||
|
3613: "e719d991",
|
||||||
|
3796: "b0299845",
|
||||||
|
3906: "04ecbb1e",
|
||||||
|
4047: "641c9bbd",
|
||||||
|
4118: "a320b565",
|
||||||
|
4161: "eadf1f6e",
|
||||||
|
4266: "ffd149ea",
|
||||||
|
4485: "60cc6e9f",
|
||||||
|
4644: "bc9b4aa2",
|
||||||
|
4650: "b0299845",
|
||||||
|
478: "9c877ac1",
|
||||||
|
4889: "04735ffb",
|
||||||
|
5147: "ee6b369e",
|
||||||
|
5216: "10bb6beb",
|
||||||
|
5326: "34bca2c1",
|
||||||
|
5397: "83b61f62",
|
||||||
|
5541: "044ec756",
|
||||||
|
5557: "3522eac5",
|
||||||
|
5635: "0bb94865",
|
||||||
|
5676: "4b734434",
|
||||||
|
5792: "f5891f52",
|
||||||
|
5980: "b98825a1",
|
||||||
|
6142: "8737c0af",
|
||||||
|
640: "52de04c7",
|
||||||
|
6622: "4bccd372",
|
||||||
|
6790: "687d2b84",
|
||||||
|
6810: "7849eabb",
|
||||||
|
6948: "13c1a20a",
|
||||||
|
7249: "60dcc01a",
|
||||||
|
7288: "36a55e06",
|
||||||
|
7308: "a746c684",
|
||||||
|
733: "0d60ed4c",
|
||||||
|
7375: "5f81288a",
|
||||||
|
7570: "990fb0ef",
|
||||||
|
7631: "f08bc1a6",
|
||||||
|
7704: "400e0d89",
|
||||||
|
8034: "9cc82aa2",
|
||||||
|
8139: "cbce920e",
|
||||||
|
83: "8621c007",
|
||||||
|
8349: "3a992ac8",
|
||||||
|
8438: "efed7c55",
|
||||||
|
8523: "c11f699a",
|
||||||
|
8574: "057eaa88",
|
||||||
|
8608: "96b4aa9e",
|
||||||
|
8941: "1f16eca5",
|
||||||
|
9028: "b62927a5",
|
||||||
|
9391: "ecce51c7",
|
||||||
|
9392: "a7e6bb6b",
|
||||||
|
9406: "0b4508f3",
|
||||||
|
9410: "14c4f7ca",
|
||||||
|
9415: "a5c6b8af",
|
||||||
|
9500: "02a74019",
|
||||||
|
9580: "fa87a43e",
|
||||||
|
9860: "55461b9a"
|
||||||
|
}[e] + ".css"
|
||||||
|
}
|
||||||
|
,
|
||||||
|
o.h = function() {
|
||||||
|
return "04e21982347a3c4d"
|
||||||
|
}
|
||||||
|
,
|
||||||
|
o.g = function() {
|
||||||
|
if ("object" == typeof globalThis)
|
||||||
|
return globalThis;
|
||||||
|
try {
|
||||||
|
return this || Function("return this")()
|
||||||
|
} catch (e) {
|
||||||
|
if ("object" == typeof window)
|
||||||
|
return window
|
||||||
|
}
|
||||||
|
}(),
|
||||||
|
o.o = function(e, t) {
|
||||||
|
return Object.prototype.hasOwnProperty.call(e, t)
|
||||||
|
}
|
||||||
|
,
|
||||||
|
( () => {
|
||||||
|
var e = {}
|
||||||
|
, t = "mweb:";
|
||||||
|
o.l = function(a, n, r, i) {
|
||||||
|
if (e[a])
|
||||||
|
e[a].push(n);
|
||||||
|
else {
|
||||||
|
if (void 0 !== r)
|
||||||
|
for (var c, d, f = document.getElementsByTagName("script"), l = 0; l < f.length; l++) {
|
||||||
|
var b = f[l];
|
||||||
|
if (b.getAttribute("src") == a || b.getAttribute("data-webpack") == t + r) {
|
||||||
|
c = b;
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
!c && (d = !0,
|
||||||
|
(c = document.createElement("script")).charset = "utf-8",
|
||||||
|
c.timeout = 120,
|
||||||
|
o.nc && c.setAttribute("nonce", o.nc),
|
||||||
|
c.setAttribute("data-webpack", t + r),
|
||||||
|
c.src = a,
|
||||||
|
0 !== c.src.indexOf(window.location.origin + "/") && (c.crossOrigin = "anonymous")),
|
||||||
|
e[a] = [n];
|
||||||
|
var s = function(t, o) {
|
||||||
|
c.onerror = c.onload = null,
|
||||||
|
clearTimeout(u);
|
||||||
|
var n = e[a];
|
||||||
|
if (delete e[a],
|
||||||
|
c.parentNode && c.parentNode.removeChild(c),
|
||||||
|
n && n.forEach((function(e) {
|
||||||
|
return e(o)
|
||||||
|
}
|
||||||
|
)),
|
||||||
|
t)
|
||||||
|
return t(o)
|
||||||
|
}
|
||||||
|
, u = setTimeout(s.bind(null, void 0, {
|
||||||
|
type: "timeout",
|
||||||
|
target: c
|
||||||
|
}), 12e4);
|
||||||
|
c.onerror = s.bind(null, c.onerror),
|
||||||
|
c.onload = s.bind(null, c.onload),
|
||||||
|
d && document.head.appendChild(c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)(),
|
||||||
|
o.r = function(e) {
|
||||||
|
"undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e, Symbol.toStringTag, {
|
||||||
|
value: "Module"
|
||||||
|
}),
|
||||||
|
Object.defineProperty(e, "__esModule", {
|
||||||
|
value: !0
|
||||||
|
})
|
||||||
|
}
|
||||||
|
,
|
||||||
|
o.nmd = function(e) {
|
||||||
|
return e.paths = [],
|
||||||
|
!e.children && (e.children = []),
|
||||||
|
e
|
||||||
|
}
|
||||||
|
,
|
||||||
|
o.nc = void 0,
|
||||||
|
( () => {
|
||||||
|
var e = [];
|
||||||
|
o.O = function(t, a, n, r) {
|
||||||
|
if (!a) {
|
||||||
|
var i = 1 / 0;
|
||||||
|
for (l = 0; l < e.length; l++) {
|
||||||
|
a = e[l][0],
|
||||||
|
n = e[l][1],
|
||||||
|
r = e[l][2];
|
||||||
|
for (var c = !0, d = 0; d < a.length; d++)
|
||||||
|
(!1 & r || i >= r) && Object.keys(o.O).every((function(e) {
|
||||||
|
return o.O[e](a[d])
|
||||||
|
}
|
||||||
|
)) ? a.splice(d--, 1) : (c = !1,
|
||||||
|
r < i && (i = r));
|
||||||
|
if (c) {
|
||||||
|
e.splice(l--, 1);
|
||||||
|
var f = n();
|
||||||
|
void 0 !== f && (t = f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
r = r || 0;
|
||||||
|
for (var l = e.length; l > 0 && e[l - 1][2] > r; l--)
|
||||||
|
e[l] = e[l - 1];
|
||||||
|
e[l] = [a, n, r]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)(),
|
||||||
|
o.p = "//lf3-lv-buz.vlabstatic.com/obj/image-lvweb-buz/ies/lvweb/mweb_cn_new/",
|
||||||
|
o.rv = function() {
|
||||||
|
return "1.0.14"
|
||||||
|
}
|
||||||
|
,
|
||||||
|
( () => {
|
||||||
|
if ("undefined" != typeof document) {
|
||||||
|
var e = {
|
||||||
|
8242: 0
|
||||||
|
};
|
||||||
|
o.f.miniCss = function(t, a) {
|
||||||
|
if (e[t])
|
||||||
|
a.push(e[t]);
|
||||||
|
else if (0 !== e[t] && {
|
||||||
|
1554: 1,
|
||||||
|
8941: 1,
|
||||||
|
6810: 1,
|
||||||
|
8034: 1,
|
||||||
|
3013: 1,
|
||||||
|
9028: 1,
|
||||||
|
1005: 1,
|
||||||
|
4266: 1,
|
||||||
|
5397: 1,
|
||||||
|
5635: 1,
|
||||||
|
2467: 1,
|
||||||
|
5541: 1,
|
||||||
|
5676: 1,
|
||||||
|
6948: 1,
|
||||||
|
9406: 1,
|
||||||
|
3906: 1,
|
||||||
|
6790: 1,
|
||||||
|
2658: 1,
|
||||||
|
8523: 1,
|
||||||
|
3321: 1,
|
||||||
|
9415: 1,
|
||||||
|
5792: 1,
|
||||||
|
5216: 1,
|
||||||
|
7631: 1,
|
||||||
|
8574: 1,
|
||||||
|
6622: 1,
|
||||||
|
7704: 1,
|
||||||
|
2349: 1,
|
||||||
|
4644: 1,
|
||||||
|
3218: 1,
|
||||||
|
5557: 1,
|
||||||
|
3061: 1,
|
||||||
|
2550: 1,
|
||||||
|
9580: 1,
|
||||||
|
9860: 1,
|
||||||
|
9500: 1,
|
||||||
|
7288: 1,
|
||||||
|
3613: 1,
|
||||||
|
9410: 1,
|
||||||
|
5980: 1,
|
||||||
|
4161: 1,
|
||||||
|
8139: 1,
|
||||||
|
4047: 1,
|
||||||
|
7308: 1,
|
||||||
|
83: 1,
|
||||||
|
2652: 1,
|
||||||
|
5147: 1,
|
||||||
|
9391: 1,
|
||||||
|
288: 1,
|
||||||
|
2213: 1,
|
||||||
|
4118: 1,
|
||||||
|
5326: 1,
|
||||||
|
3537: 1,
|
||||||
|
8349: 1,
|
||||||
|
8608: 1,
|
||||||
|
2073: 1,
|
||||||
|
8438: 1,
|
||||||
|
3796: 1,
|
||||||
|
4650: 1,
|
||||||
|
1385: 1,
|
||||||
|
1553: 1,
|
||||||
|
2175: 1,
|
||||||
|
4889: 1,
|
||||||
|
640: 1,
|
||||||
|
9392: 1,
|
||||||
|
1097: 1,
|
||||||
|
733: 1,
|
||||||
|
108: 1,
|
||||||
|
4485: 1,
|
||||||
|
1144: 1,
|
||||||
|
6142: 1,
|
||||||
|
7375: 1,
|
||||||
|
7249: 1,
|
||||||
|
2906: 1,
|
||||||
|
478: 1,
|
||||||
|
7570: 1,
|
||||||
|
1275: 1,
|
||||||
|
1460: 1
|
||||||
|
}[t]) {
|
||||||
|
var n;
|
||||||
|
a.push(e[t] = (n = t,
|
||||||
|
new Promise((function(e, t) {
|
||||||
|
var a = o.miniCssF(n)
|
||||||
|
, r = o.p + a;
|
||||||
|
if (function(e, t) {
|
||||||
|
for (var o = document.getElementsByTagName("link"), a = 0; a < o.length; a++) {
|
||||||
|
var n = (i = o[a]).getAttribute("data-href") || i.getAttribute("href");
|
||||||
|
if ("stylesheet" === i.rel && (n === e || n === t))
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
var r = document.getElementsByTagName("style");
|
||||||
|
for (a = 0; a < r.length; a++) {
|
||||||
|
var i;
|
||||||
|
if ((n = (i = r[a]).getAttribute("data-href")) === e || n === t)
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
}(a, r))
|
||||||
|
return e();
|
||||||
|
!function(e, t, a, n, r) {
|
||||||
|
var i = document.createElement("link");
|
||||||
|
i.rel = "stylesheet",
|
||||||
|
i.type = "text/css",
|
||||||
|
o.nc && (i.nonce = o.nc),
|
||||||
|
i.onerror = i.onload = function(o) {
|
||||||
|
if (i.onerror = i.onload = null,
|
||||||
|
"load" === o.type)
|
||||||
|
n();
|
||||||
|
else {
|
||||||
|
var a = o && ("load" === o.type ? "missing" : o.type)
|
||||||
|
, c = o && o.target && o.target.href || t
|
||||||
|
, d = Error("Loading CSS chunk " + e + " failed.\\n(" + c + ")");
|
||||||
|
d.code = "CSS_CHUNK_LOAD_FAILED",
|
||||||
|
d.type = a,
|
||||||
|
d.request = c,
|
||||||
|
i.parentNode && i.parentNode.removeChild(i),
|
||||||
|
r(d)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
,
|
||||||
|
i.href = t,
|
||||||
|
0 !== i.href.indexOf(window.location.origin + "/") && (i.crossOrigin = "anonymous"),
|
||||||
|
a ? a.parentNode.insertBefore(i, a.nextSibling) : document.head.appendChild(i)
|
||||||
|
}(n, r, null, e, t)
|
||||||
|
}
|
||||||
|
))).then((function() {
|
||||||
|
e[t] = 0
|
||||||
|
}
|
||||||
|
), (function(o) {
|
||||||
|
throw delete e[t],
|
||||||
|
o
|
||||||
|
}
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)(),
|
||||||
|
( () => {
|
||||||
|
o.b = document.baseURI || self.location.href;
|
||||||
|
var e = {
|
||||||
|
8242: 0
|
||||||
|
};
|
||||||
|
o.f.j = function(t, a) {
|
||||||
|
var n = o.o(e, t) ? e[t] : void 0;
|
||||||
|
if (0 !== n)
|
||||||
|
if (n)
|
||||||
|
a.push(n[2]);
|
||||||
|
else if (/^(1005|288|8242)$/.test(t))
|
||||||
|
e[t] = 0;
|
||||||
|
else {
|
||||||
|
var r = new Promise((function(o, a) {
|
||||||
|
n = e[t] = [o, a]
|
||||||
|
}
|
||||||
|
));
|
||||||
|
a.push(n[2] = r);
|
||||||
|
var i = o.p + o.u(t)
|
||||||
|
, c = Error();
|
||||||
|
o.l(i, (function(a) {
|
||||||
|
if (o.o(e, t) && (0 !== (n = e[t]) && (e[t] = void 0),
|
||||||
|
n)) {
|
||||||
|
var r = a && ("load" === a.type ? "missing" : a.type)
|
||||||
|
, i = a && a.target && a.target.src;
|
||||||
|
c.message = "Loading chunk " + t + " failed.\n(" + r + ": " + i + ")",
|
||||||
|
c.name = "ChunkLoadError",
|
||||||
|
c.type = r,
|
||||||
|
c.request = i,
|
||||||
|
n[1](c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
), "chunk-" + t, t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
,
|
||||||
|
o.O.j = function(t) {
|
||||||
|
return 0 === e[t]
|
||||||
|
}
|
||||||
|
;
|
||||||
|
var t = function(t, a) {
|
||||||
|
var n, r, i = a[0], c = a[1], d = a[2], f = 0;
|
||||||
|
if (i.some((function(t) {
|
||||||
|
return 0 !== e[t]
|
||||||
|
}
|
||||||
|
))) {
|
||||||
|
for (n in c)
|
||||||
|
o.o(c, n) && (o.m[n] = c[n]);
|
||||||
|
if (d)
|
||||||
|
var l = d(o)
|
||||||
|
}
|
||||||
|
for (t && t(a); f < i.length; f++)
|
||||||
|
r = i[f],
|
||||||
|
o.o(e, r) && e[r] && e[r][0](),
|
||||||
|
e[r] = 0;
|
||||||
|
return o.O(l)
|
||||||
|
}
|
||||||
|
, a = self.__LOADABLE_LOADED_CHUNKS__ = self.__LOADABLE_LOADED_CHUNKS__ || [];
|
||||||
|
a.forEach(t.bind(null, 0)),
|
||||||
|
a.push = t.bind(null, a.push.bind(a))
|
||||||
|
}
|
||||||
|
)(),
|
||||||
|
o.ruid = "bundler=rspack@1.0.14"
|
||||||
|
|
||||||
|
window.tttt = {
|
||||||
|
e:e,
|
||||||
|
t:t,
|
||||||
|
i:o,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)()
|
||||||
9898
temp/lib-uploader.c1f2476f.js
Normal file
9898
temp/lib-uploader.c1f2476f.js
Normal file
File diff suppressed because one or more lines are too long
210
temp/sha256_test.html
Normal file
210
temp/sha256_test.html
Normal file
@ -0,0 +1,210 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>SHA256 哈希测试</title>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: sans-serif;
|
||||||
|
margin: 20px;
|
||||||
|
background-color: #f4f4f4;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
background-color: #fff;
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
input[type="text"] {
|
||||||
|
width: calc(100% - 22px);
|
||||||
|
padding: 10px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
button {
|
||||||
|
padding: 10px 15px;
|
||||||
|
background-color: #007bff;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
button:hover {
|
||||||
|
background-color: #0056b3;
|
||||||
|
}
|
||||||
|
#resultRaw,
|
||||||
|
#resultHex {
|
||||||
|
margin-top: 15px;
|
||||||
|
padding: 10px;
|
||||||
|
background-color: #e9ecef;
|
||||||
|
border: 1px solid #ced4da;
|
||||||
|
border-radius: 4px;
|
||||||
|
word-wrap: break-word;
|
||||||
|
}
|
||||||
|
h3 {
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h2>SHA256 哈希计算器</h2>
|
||||||
|
<input type="text" id="inputText" placeholder="在此输入要哈希的文本">
|
||||||
|
<button onclick="calculateHash()">计算 SHA256 哈希</button>
|
||||||
|
|
||||||
|
<h3>CryptoJS WordArray 对象:</h3>
|
||||||
|
<pre id="resultRaw"></pre>
|
||||||
|
|
||||||
|
<h3>十六进制哈希结果:</h3>
|
||||||
|
<pre id="resultHex"></pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container" style="margin-top: 20px;">
|
||||||
|
<h2>AWS V4 签名计算器 (模拟)</h2>
|
||||||
|
|
||||||
|
<button onclick="calculateSignature()">计算签名</button>
|
||||||
|
|
||||||
|
<h3>签名 Query:</h3>
|
||||||
|
<pre id="signatureQuery"></pre>
|
||||||
|
<h3>ISO8601 时间 (X-Amz-Date):</h3>
|
||||||
|
<pre id="isoTime"></pre>
|
||||||
|
<h3>Canonical Request:</h3>
|
||||||
|
<pre id="canonicalRequest"></pre>
|
||||||
|
<h3>String to Sign:</h3>
|
||||||
|
<pre id="stringToSign"></pre>
|
||||||
|
<h3>Authorization Header:</h3>
|
||||||
|
<pre id="authorizationHeader"></pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const te = {
|
||||||
|
"accessKeyId": "AKTPMTZjYTJkNWMzOWY1NDYxMmFlMmRlNDUxZTc3ODI4Yzk",
|
||||||
|
"secretAccessKey": "gWRJ+a7OLWDH+rsGUYNCSlV2r1zltBu+KNvO9TuLgzG+jrFv4ClLyVH/awi1Q3Uq",
|
||||||
|
"sessionToken": "STS2eyJMVEFjY2Vzc0tleUlEIjoiQUtMVFpUQm1ZbVl4TlRsa1ptVmpOREJqWVRrM09UUTNZbU5pTmprMk1EUXdaV00iLCJBY2Nlc3NLZXlJRCI6IkFLVFBNVFpqWVRKa05XTXpPV1kxTkRZeE1tRmxNbVJsTkRVeFpUYzNPREk0WXprIiwiU2lnbmVkU2VjcmV0QWNjZXNzS2V5IjoiN25ZU0o3T0FCMGZubHlKSENBbzcrOTMyV1FPbkUxck00ZnRuNHpPcVc2Unc1NTJJSWRnY3E1YkF6dWd0VUZaRTZPSzhUa3JBb2c3TW9GV3UzeWplZjV2Y3I2cndUWWM4dklYMzdiZ1BuSWM9IiwiRXhwaXJlZFRpbWUiOjE3NDg1OTEzMDksIlBvbGljeVN0cmluZyI6IntcIlN0YXRlbWVudFwiOlt7XCJFZmZlY3RcIjpcIkFsbG93XCIsXCJBY3Rpb25cIjpbXCJ2b2Q6QXBwbHlVcGxvYWRcIixcInZvZDpBcHBseVVwbG9hZElubmVyXCIsXCJ2b2Q6Q29tbWl0VXBsb2FkXCIsXCJ2b2Q6Q29tbWl0VXBsb2FkSW5uZXJcIixcInZvZDpHZXRVcGxvYWRDYW5kaWRhdGVzXCIsXCJJbWFnZVg6QXBwbHlJbWFnZVVwbG9hZFwiLFwiSW1hZ2VYOkNvbW1pdEltYWdlVXBsb2FkXCIsXCJJbWFnZVg6QXBwbHlVcGxvYWRJbWFnZUZpbGVcIixcIkltYWdlWDpDb21taXRVcGxvYWRJbWFnZUZpbGVcIl0sXCJSZXNvdXJjZVwiOltcIipcIl0sXCJDb25kaXRpb25cIjpcIntcXFwiUFNNXFxcIjpcXFwidmlkZW9jdXQubXdlYi5hcGlcXFwifVwifV19IiwiU2lnbmF0dXJlIjoiZTkyNGRmY2Q2ZjE4OTM1NTg5ZjBjYzk5NDc3MjkxZjU5MDk5NGE0ZGZmMGU1Mjc5YjkwZTk1NmUwY2Q0MWFlMiJ9"
|
||||||
|
}
|
||||||
|
const tq = {
|
||||||
|
"Action": "ApplyImageUpload",
|
||||||
|
"Version": "2018-08-01",
|
||||||
|
"ServiceId": "tb4s082cfz",
|
||||||
|
"FileSize": 1930510,
|
||||||
|
"s": "5sohmgy6e1p"
|
||||||
|
}
|
||||||
|
const ttt = "20250530T064830Z";
|
||||||
|
// 辅助函数:将对象转换为查询字符串
|
||||||
|
function toQueryString(obj) {
|
||||||
|
return Object.keys(obj).sort().map(key => {
|
||||||
|
return encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]);
|
||||||
|
}).join('&');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 辅助函数:生成 ISO8601 格式时间字符串 (YYYYMMDDTHHMMSSZ)
|
||||||
|
function getAmzDate(date) {
|
||||||
|
return date.toISOString().replace(/[:\-]*/g, '').split('.')[0] + 'Z';
|
||||||
|
}
|
||||||
|
|
||||||
|
function authorizationSign(accessKeyId, secretAccessKey, amzDate, queryParams, headers) {
|
||||||
|
const service = "imagex"; // 或者从其他地方获取,这里根据 getUploadService 逻辑
|
||||||
|
const region = "cn-north-1"; // 根据您的 regionStr
|
||||||
|
const method = 'GET';
|
||||||
|
const canonicalUri = '/'; // 通常是 API 的路径,这里根据 getUploadService 逻辑是根路径
|
||||||
|
|
||||||
|
// 1. 创建规范请求 (Canonical Request)
|
||||||
|
const canonicalQueryString = toQueryString(queryParams);
|
||||||
|
|
||||||
|
const signedHeaders = Object.keys(headers).map(h => h.toLowerCase()).sort().join(';');
|
||||||
|
let canonicalHeaders = '';
|
||||||
|
Object.keys(headers).sort().forEach(key => {
|
||||||
|
canonicalHeaders += key.toLowerCase() + ':' + String(headers[key]).trim() + '\n';
|
||||||
|
});
|
||||||
|
|
||||||
|
const payloadHash = CryptoJS.SHA256("").toString(CryptoJS.enc.Hex); // GET 请求通常为空 payload
|
||||||
|
|
||||||
|
const canonicalRequest =
|
||||||
|
method + '\n' +
|
||||||
|
canonicalUri + '\n' +
|
||||||
|
canonicalQueryString + '\n' +
|
||||||
|
canonicalHeaders + '\n' +
|
||||||
|
signedHeaders + '\n' +
|
||||||
|
payloadHash;
|
||||||
|
|
||||||
|
document.getElementById('canonicalRequest').textContent = canonicalRequest;
|
||||||
|
console.log("canonicalRequest",canonicalRequest);
|
||||||
|
// 2. 创建待签字符串 (String to Sign)
|
||||||
|
const dateStamp = amzDate.substring(0, 8);
|
||||||
|
const credentialScope = dateStamp + '/' + region + '/' + service + '/' + 'aws4_request';
|
||||||
|
const stringToSign =
|
||||||
|
'AWS4-HMAC-SHA256' + '\n' +
|
||||||
|
amzDate + '\n' +
|
||||||
|
credentialScope + '\n' +
|
||||||
|
CryptoJS.SHA256(canonicalRequest).toString(CryptoJS.enc.Hex);
|
||||||
|
|
||||||
|
document.getElementById('stringToSign').textContent = stringToSign;
|
||||||
|
|
||||||
|
// 3. 计算签名 (Calculate Signature)
|
||||||
|
const kDate = CryptoJS.HmacSHA256(dateStamp, 'AWS4' + secretAccessKey);
|
||||||
|
const kRegion = CryptoJS.HmacSHA256(region, kDate);
|
||||||
|
const kService = CryptoJS.HmacSHA256(service, kRegion);
|
||||||
|
const kSigning = CryptoJS.HmacSHA256('aws4_request', kService);
|
||||||
|
|
||||||
|
console.log("kSigning",kSigning.toString());
|
||||||
|
console.log("stringToSign",stringToSign);
|
||||||
|
const signature = CryptoJS.HmacSHA256(stringToSign, kSigning).toString(CryptoJS.enc.Hex);
|
||||||
|
|
||||||
|
// 4. 构建 Authorization 头部
|
||||||
|
const authorization =
|
||||||
|
'AWS4-HMAC-SHA256 Credential=' + accessKeyId + '/' + credentialScope +
|
||||||
|
', SignedHeaders=' + signedHeaders +
|
||||||
|
', Signature=' + signature;
|
||||||
|
|
||||||
|
return authorization;
|
||||||
|
}
|
||||||
|
|
||||||
|
function calculateSignature(){
|
||||||
|
const access_key_id = te.accessKeyId;
|
||||||
|
const secret_access_key = te.secretAccessKey;
|
||||||
|
const session_token = te.sessionToken;
|
||||||
|
|
||||||
|
let query = tq;
|
||||||
|
document.getElementById('signatureQuery').textContent = JSON.stringify(query, null, 4);
|
||||||
|
|
||||||
|
// const amzDate = getAmzDate(new Date()); // 使用当前时间生成 X-Amz-Date
|
||||||
|
const amzDate = ttt; // 或者使用硬编码的时间进行测试,与TS代码一致
|
||||||
|
document.getElementById('isoTime').textContent = amzDate;
|
||||||
|
|
||||||
|
let headers = {
|
||||||
|
"x-amz-date": amzDate,
|
||||||
|
};
|
||||||
|
if (session_token) {
|
||||||
|
headers["x-amz-security-token"] = session_token;
|
||||||
|
}
|
||||||
|
|
||||||
|
const authorization = authorizationSign(access_key_id, secret_access_key, amzDate, query, headers);
|
||||||
|
document.getElementById('authorizationHeader').textContent = authorization;
|
||||||
|
}
|
||||||
|
|
||||||
|
function calculateHash() {
|
||||||
|
const inputText = document.getElementById('inputText').value;
|
||||||
|
if (inputText === null || inputText.trim() === '') {
|
||||||
|
document.getElementById('resultRaw').textContent = '请输入文本后再计算。';
|
||||||
|
document.getElementById('resultHex').textContent = '';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const hash = CryptoJS.SHA256(inputText);
|
||||||
|
|
||||||
|
// 显示原始 WordArray 对象 (格式化为 JSON 字符串)
|
||||||
|
const rawResult = {
|
||||||
|
words: hash.words,
|
||||||
|
sigBytes: hash.sigBytes
|
||||||
|
};
|
||||||
|
document.getElementById('resultRaw').textContent = JSON.stringify(rawResult, null, 4);
|
||||||
|
|
||||||
|
// 显示十六进制哈希字符串
|
||||||
|
document.getElementById('resultHex').textContent = hash.toString(CryptoJS.enc.Hex);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
21
temp/test-uploader.html
Normal file
21
temp/test-uploader.html
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Test Uploader Library</title>
|
||||||
|
<style>
|
||||||
|
body { font-family: sans-serif; margin: 20px; }
|
||||||
|
#output { margin-top: 20px; padding: 10px; border: 1px solid #ccc; background-color: #f9f9f9; white-space: pre-wrap; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Test Uploader Library</h1>
|
||||||
|
|
||||||
|
<script src="lib-uploader.4.js"></script>
|
||||||
|
<script src="lib-uploader.2.js"></script>
|
||||||
|
<!-- <script src="lib-uploader.c1f2476f.js"></script> -->
|
||||||
|
<script>
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
51
temp/uploadres.json
Normal file
51
temp/uploadres.json
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
{
|
||||||
|
"ResponseMetadata": {
|
||||||
|
"RequestId": "2025052922475201E932216072FC5090DB",
|
||||||
|
"Action": "ApplyImageUpload",
|
||||||
|
"Version": "2018-08-01",
|
||||||
|
"Service": "imagex",
|
||||||
|
"Region": "cn-north-1"
|
||||||
|
},
|
||||||
|
"Result": {
|
||||||
|
"UploadAddress": {
|
||||||
|
"StoreInfos": [
|
||||||
|
{
|
||||||
|
"StoreUri": "tos-cn-i-tb4s082cfz/4db9ec5f1f9f4a50912c4822dd802a73",
|
||||||
|
"Auth": "SpaceKey/tb4s082cfz/1/:version:v2:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NDg1NTE2NzIsInNpZ25hdHVyZUluZm8iOnsiYWNjZXNzS2V5IjoiZmFrZV9hY2Nlc3Nfa2V5IiwiYnVja2V0IjoidG9zLWNuLWktdGI0czA4MmNmeiIsImV4cGlyZSI6MTc0ODU1MTY3MiwiZmlsZUluZm9zIjpbeyJvaWRLZXkiOiI0ZGI5ZWM1ZjFmOWY0YTUwOTEyYzQ4MjJkZDgwMmE3MyIsImZpbGVUeXBlIjoiMSJ9XSwiZXh0cmEiOnsiYmxvY2tfbW9kZSI6IiIsImNvbnRlbnRfdHlwZV9ibG9jayI6IntcIm1pbWVfcGN0XCI6MCxcIm1vZGVcIjowLFwibWltZV9saXN0XCI6bnVsbCxcImNvbmZsaWN0X2Jsb2NrXCI6ZmFsc2V9IiwiZW5jcnlwdF9hbGdvIjoiIiwiZW5jcnlwdF9rZXkiOiIiLCJzcGFjZSI6InRiNHMwODJjZnoifX19.nLTguWWNvqdmSahb5qGFnrTXv7NR6PFPg7nqUSu_ebg",
|
||||||
|
"UploadID": "705a490d4d664e74a9f1b258eac4ebdf"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"UploadHosts": [
|
||||||
|
"tos-hl-x.snssdk.com"
|
||||||
|
],
|
||||||
|
"UploadHeader": null,
|
||||||
|
"SessionKey": "eyJhY2NvdW50VHlwZSI6IkltYWdlWCIsImFwcElkIjoiIiwiYml6VHlwZSI6IiIsImZpbGVUeXBlIjoiaW1hZ2UiLCJsZWdhbCI6IiIsInN0b3JlSW5mb3MiOiJbe1wiU3RvcmVVcmlcIjpcInRvcy1jbi1pLXRiNHMwODJjZnovNGRiOWVjNWYxZjlmNGE1MDkxMmM0ODIyZGQ4MDJhNzNcIixcIkF1dGhcIjpcIlNwYWNlS2V5L3RiNHMwODJjZnovMS86dmVyc2lvbjp2MjpleUpoYkdjaU9pSklVekkxTmlJc0luUjVjQ0k2SWtwWFZDSjkuZXlKbGVIQWlPakUzTkRnMU5URTJOeklzSW5OcFoyNWhkSFZ5WlVsdVptOGlPbnNpWVdOalpYTnpTMlY1SWpvaVptRnJaVjloWTJObGMzTmZhMlY1SWl3aVluVmphMlYwSWpvaWRHOXpMV051TFdrdGRHSTBjekE0TW1ObWVpSXNJbVY0Y0dseVpTSTZNVGMwT0RVMU1UWTNNaXdpWm1sc1pVbHVabTl6SWpwYmV5SnZhV1JMWlhraU9pSTBaR0k1WldNMVpqRm1PV1kwWVRVd09URXlZelE0TWpKa1pEZ3dNbUUzTXlJc0ltWnBiR1ZVZVhCbElqb2lNU0o5WFN3aVpYaDBjbUVpT25zaVlteHZZMnRmYlc5a1pTSTZJaUlzSW1OdmJuUmxiblJmZEhsd1pWOWliRzlqYXlJNkludGNJbTFwYldWZmNHTjBYQ0k2TUN4Y0ltMXZaR1ZjSWpvd0xGd2liV2x0WlY5c2FYTjBYQ0k2Ym5Wc2JDeGNJbU52Ym1ac2FXTjBYMkpzYjJOclhDSTZabUZzYzJWOUlpd2laVzVqY25sd2RGOWhiR2R2SWpvaUlpd2laVzVqY25sd2RGOXJaWGtpT2lJaUxDSnpjR0ZqWlNJNkluUmlOSE13T0RKalpub2lmWDE5Lm5MVGd1V1dOdnFkbVNhaGI1cUdGbnJUWHY3TlI2UEZQZzducVVTdV9lYmdcIixcIlVwbG9hZElEXCI6XCI3MDVhNDkwZDRkNjY0ZTc0YTlmMWIyNThlYWM0ZWJkZlwiLFwiVXBsb2FkSGVhZGVyXCI6bnVsbCxcIlN0b3JhZ2VIZWFkZXJcIjpudWxsfV0iLCJ1cGxvYWRIb3N0IjoidG9zLWhsLXguc25zc2RrLmNvbSIsInVyaSI6InRvcy1jbi1pLXRiNHMwODJjZnovNGRiOWVjNWYxZjlmNGE1MDkxMmM0ODIyZGQ4MDJhNzMiLCJ1c2VySWQiOiIifQ==",
|
||||||
|
"Cloud": ""
|
||||||
|
},
|
||||||
|
"FallbackUploadAddress": {
|
||||||
|
"StoreInfos": null,
|
||||||
|
"UploadHosts": null,
|
||||||
|
"UploadHeader": null,
|
||||||
|
"SessionKey": "",
|
||||||
|
"Cloud": ""
|
||||||
|
},
|
||||||
|
"InnerUploadAddress": {
|
||||||
|
"UploadNodes": [
|
||||||
|
{
|
||||||
|
"StoreInfos": [
|
||||||
|
{
|
||||||
|
"StoreUri": "tos-cn-i-tb4s082cfz/4db9ec5f1f9f4a50912c4822dd802a73",
|
||||||
|
"Auth": "SpaceKey/tb4s082cfz/1/:version:v2:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NDg1NTE2NzIsInNpZ25hdHVyZUluZm8iOnsiYWNjZXNzS2V5IjoiZmFrZV9hY2Nlc3Nfa2V5IiwiYnVja2V0IjoidG9zLWNuLWktdGI0czA4MmNmeiIsImV4cGlyZSI6MTc0ODU1MTY3MiwiZmlsZUluZm9zIjpbeyJvaWRLZXkiOiI0ZGI5ZWM1ZjFmOWY0YTUwOTEyYzQ4MjJkZDgwMmE3MyIsImZpbGVUeXBlIjoiMSJ9XSwiZXh0cmEiOnsiYmxvY2tfbW9kZSI6IiIsImNvbnRlbnRfdHlwZV9ibG9jayI6IntcIm1pbWVfcGN0XCI6MCxcIm1vZGVcIjowLFwibWltZV9saXN0XCI6bnVsbCxcImNvbmZsaWN0X2Jsb2NrXCI6ZmFsc2V9IiwiZW5jcnlwdF9hbGdvIjoiIiwiZW5jcnlwdF9rZXkiOiIiLCJzcGFjZSI6InRiNHMwODJjZnoifX19.nLTguWWNvqdmSahb5qGFnrTXv7NR6PFPg7nqUSu_ebg",
|
||||||
|
"UploadID": "705a490d4d664e74a9f1b258eac4ebdf"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"UploadHost": "tos-hl-x.snssdk.com",
|
||||||
|
"UploadHeader": null,
|
||||||
|
"SessionKey": "eyJhY2NvdW50VHlwZSI6IkltYWdlWCIsImFwcElkIjoiIiwiYml6VHlwZSI6IiIsImZpbGVUeXBlIjoiaW1hZ2UiLCJsZWdhbCI6IiIsInN0b3JlSW5mb3MiOiJbe1wiU3RvcmVVcmlcIjpcInRvcy1jbi1pLXRiNHMwODJjZnovNGRiOWVjNWYxZjlmNGE1MDkxMmM0ODIyZGQ4MDJhNzNcIixcIkF1dGhcIjpcIlNwYWNlS2V5L3RiNHMwODJjZnovMS86dmVyc2lvbjp2MjpleUpoYkdjaU9pSklVekkxTmlJc0luUjVjQ0k2SWtwWFZDSjkuZXlKbGVIQWlPakUzTkRnMU5URTJOeklzSW5OcFoyNWhkSFZ5WlVsdVptOGlPbnNpWVdOalpYTnpTMlY1SWpvaVptRnJaVjloWTJObGMzTmZhMlY1SWl3aVluVmphMlYwSWpvaWRHOXpMV051TFdrdGRHSTBjekE0TW1ObWVpSXNJbVY0Y0dseVpTSTZNVGMwT0RVMU1UWTNNaXdpWm1sc1pVbHVabTl6SWpwYmV5SnZhV1JMWlhraU9pSTBaR0k1WldNMVpqRm1PV1kwWVRVd09URXlZelE0TWpKa1pEZ3dNbUUzTXlJc0ltWnBiR1ZVZVhCbElqb2lNU0o5WFN3aVpYaDBjbUVpT25zaVlteHZZMnRmYlc5a1pTSTZJaUlzSW1OdmJuUmxiblJmZEhsd1pWOWliRzlqYXlJNkludGNJbTFwYldWZmNHTjBYQ0k2TUN4Y0ltMXZaR1ZjSWpvd0xGd2liV2x0WlY5c2FYTjBYQ0k2Ym5Wc2JDeGNJbU52Ym1ac2FXTjBYMkpzYjJOclhDSTZabUZzYzJWOUlpd2laVzVqY25sd2RGOWhiR2R2SWpvaUlpd2laVzVqY25sd2RGOXJaWGtpT2lJaUxDSnpjR0ZqWlNJNkluUmlOSE13T0RKalpub2lmWDE5Lm5MVGd1V1dOdnFkbVNhaGI1cUdGbnJUWHY3TlI2UEZQZzducVVTdV9lYmdcIixcIlVwbG9hZElEXCI6XCI3MDVhNDkwZDRkNjY0ZTc0YTlmMWIyNThlYWM0ZWJkZlwiLFwiVXBsb2FkSGVhZGVyXCI6bnVsbCxcIlN0b3JhZ2VIZWFkZXJcIjpudWxsfV0iLCJ1cGxvYWRIb3N0IjoidG9zLWhsLXguc25zc2RrLmNvbSIsInVyaSI6InRvcy1jbi1pLXRiNHMwODJjZnovNGRiOWVjNWYxZjlmNGE1MDkxMmM0ODIyZGQ4MDJhNzMiLCJ1c2VySWQiOiIifQ=="
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"RequestId": "2025052922475201E932216072FC5090DB",
|
||||||
|
"SDKParam": null
|
||||||
|
}
|
||||||
|
}
|
||||||
16
tsconfig.json
Normal file
16
tsconfig.json
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"baseUrl": ".",
|
||||||
|
"module": "NodeNext",
|
||||||
|
"moduleResolution": "NodeNext",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"allowSyntheticDefaultImports": true,
|
||||||
|
"noEmit": true,
|
||||||
|
"paths": {
|
||||||
|
"@/*": ["src/*"]
|
||||||
|
},
|
||||||
|
"outDir": "./dist"
|
||||||
|
},
|
||||||
|
"include": ["src/**/*", "libs.d.ts"],
|
||||||
|
"exclude": ["node_modules", "dist"]
|
||||||
|
}
|
||||||
27
vercel.json
Normal file
27
vercel.json
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"builds": [
|
||||||
|
{
|
||||||
|
"src": "./dist/*.html",
|
||||||
|
"use": "@vercel/static"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "./dist/index.js",
|
||||||
|
"use": "@vercel/node"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"routes": [
|
||||||
|
{
|
||||||
|
"src": "/",
|
||||||
|
"dest": "/dist/welcome.html"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "/(.*)",
|
||||||
|
"dest": "/dist",
|
||||||
|
"headers": {
|
||||||
|
"Access-Control-Allow-Credentials": "true",
|
||||||
|
"Access-Control-Allow-Methods": "GET,OPTIONS,PATCH,DELETE,POST,PUT",
|
||||||
|
"Access-Control-Allow-Headers": "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, Content-Type, Authorization"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user