mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-14 06:32:36 +01:00
Merge branch 'master' of https://github.com/fosscord/fosscord-server
This commit is contained in:
commit
9abb04d2e6
661
COPYING
Normal file
661
COPYING
Normal file
@ -0,0 +1,661 @@
|
|||||||
|
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 19 November 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 Affero General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works, specifically designed to ensure
|
||||||
|
cooperation with the community in the case of network server software.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
our General Public Licenses are 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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
Developers that use our General Public Licenses protect your rights
|
||||||
|
with two steps: (1) assert copyright on the software, and (2) offer
|
||||||
|
you this License which gives you legal permission to copy, distribute
|
||||||
|
and/or modify the software.
|
||||||
|
|
||||||
|
A secondary benefit of defending all users' freedom is that
|
||||||
|
improvements made in alternate versions of the program, if they
|
||||||
|
receive widespread use, become available for other developers to
|
||||||
|
incorporate. Many developers of free software are heartened and
|
||||||
|
encouraged by the resulting cooperation. However, in the case of
|
||||||
|
software used on network servers, this result may fail to come about.
|
||||||
|
The GNU General Public License permits making a modified version and
|
||||||
|
letting the public access it on a server without ever releasing its
|
||||||
|
source code to the public.
|
||||||
|
|
||||||
|
The GNU Affero General Public License is designed specifically to
|
||||||
|
ensure that, in such cases, the modified source code becomes available
|
||||||
|
to the community. It requires the operator of a network server to
|
||||||
|
provide the source code of the modified version running there to the
|
||||||
|
users of that server. Therefore, public use of a modified version, on
|
||||||
|
a publicly accessible server, gives the public access to the source
|
||||||
|
code of the modified version.
|
||||||
|
|
||||||
|
An older license, called the Affero General Public License and
|
||||||
|
published by Affero, was designed to accomplish similar goals. This is
|
||||||
|
a different license, not a version of the Affero GPL, but Affero has
|
||||||
|
released a new version of the Affero GPL which permits relicensing under
|
||||||
|
this license.
|
||||||
|
|
||||||
|
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 Affero 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. Remote Network Interaction; Use with the GNU General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, if you modify the
|
||||||
|
Program, your modified version must prominently offer all users
|
||||||
|
interacting with it remotely through a computer network (if your version
|
||||||
|
supports such interaction) an opportunity to receive the Corresponding
|
||||||
|
Source of your version by providing access to the Corresponding Source
|
||||||
|
from a network server at no charge, through some standard or customary
|
||||||
|
means of facilitating copying of software. This Corresponding Source
|
||||||
|
shall include the Corresponding Source for any work covered by version 3
|
||||||
|
of the GNU General Public License that is incorporated pursuant to the
|
||||||
|
following paragraph.
|
||||||
|
|
||||||
|
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 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 work with which it is combined will remain governed by version
|
||||||
|
3 of the GNU General Public License.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU Affero 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 Affero 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 Affero 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 Affero 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 Affero 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 Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero 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 your software can interact with users remotely through a computer
|
||||||
|
network, you should also make sure that it provides a way for users to
|
||||||
|
get its source. For example, if your program is a web application, its
|
||||||
|
interface could display a "Source" link that leads users to an archive
|
||||||
|
of the code. There are many ways you could offer source, and different
|
||||||
|
solutions will be better for different programs; see section 13 for the
|
||||||
|
specific requirements.
|
||||||
|
|
||||||
|
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 AGPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
@ -26,10 +26,10 @@ This repository contains:
|
|||||||
- [WebRTC Server](https://github.com/fosscord/fosscord-server/tree/master/webrtc)
|
- [WebRTC Server](https://github.com/fosscord/fosscord-server/tree/master/webrtc)
|
||||||
- [Admin Dashboard](https://github.com/fosscord/fosscord-server/tree/master/dashboard)
|
- [Admin Dashboard](https://github.com/fosscord/fosscord-server/tree/master/dashboard)
|
||||||
|
|
||||||
## [Ressources](https://docs.fosscord.com/resources/)
|
## [Resources](https://docs.fosscord.com/resources/)
|
||||||
|
|
||||||
- [Contributing](https://docs.fosscord.com/contributing/)
|
- [Contributing](https://docs.fosscord.com/contributing/server/)
|
||||||
|
|
||||||
## [Download](https://github.com/fosscord/fosscord-server/releases)
|
## [Download](https://github.com/fosscord/fosscord-server/releases)
|
||||||
|
|
||||||
- _is not done yet_
|
- _Work in progress_
|
||||||
|
File diff suppressed because it is too large
Load Diff
9139
api/assets/schemas.json
Normal file
9139
api/assets/schemas.json
Normal file
File diff suppressed because it is too large
Load Diff
6
api/babel.config.js
Normal file
6
api/babel.config.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
module.exports = {
|
||||||
|
presets: [
|
||||||
|
["@babel/preset-env", { targets: { node: "current" } }],
|
||||||
|
["@babel/preset-typescript", { allowDeclareFields: true }]
|
||||||
|
]
|
||||||
|
};
|
@ -19,7 +19,7 @@
|
|||||||
ASSET_ENDPOINT: "",
|
ASSET_ENDPOINT: "",
|
||||||
MEDIA_PROXY_ENDPOINT: "https://media.discordapp.net",
|
MEDIA_PROXY_ENDPOINT: "https://media.discordapp.net",
|
||||||
WIDGET_ENDPOINT: `//${location.host}/widget`,
|
WIDGET_ENDPOINT: `//${location.host}/widget`,
|
||||||
INVITE_HOST: `${location.hostname}`,
|
INVITE_HOST: `${location.host}/invite`,
|
||||||
GUILD_TEMPLATE_HOST: "discord.new",
|
GUILD_TEMPLATE_HOST: "discord.new",
|
||||||
GIFT_CODE_HOST: "discord.gift",
|
GIFT_CODE_HOST: "discord.gift",
|
||||||
RELEASE_CHANNEL: "stable",
|
RELEASE_CHANNEL: "stable",
|
||||||
@ -45,9 +45,9 @@
|
|||||||
`{"trace":false,"canary":false,"logGatewayEvents":true,"logOverlayEvents":true,"logAnalyticsEvents":true,"sourceMapsEnabled":false,"axeEnabled":false}`
|
`{"trace":false,"canary":false,"logGatewayEvents":true,"logOverlayEvents":true,"logAnalyticsEvents":true,"sourceMapsEnabled":false,"axeEnabled":false}`
|
||||||
);
|
);
|
||||||
</script>
|
</script>
|
||||||
<script src="/assets/1dfc47a02b92fa11de87.js"></script>
|
<script src="/assets/479a2f1e7d625dc134b9.js"></script>
|
||||||
<script src="/assets/60611ef20efa1f11238a.js"></script>
|
<script src="/assets/a15fd133a1d2d77a2424.js"></script>
|
||||||
<script src="/assets/b83bc9f9c08cf5073adf.js"></script>
|
<script src="/assets/97e6fa22aa08ee4daa5e.js"></script>
|
||||||
<script src="/assets/e92920082b09191a5bb0.js"></script>
|
<script src="/assets/9b2b7f0632acd0c5e781.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
66
api/jest/getRouteDescriptions.js
Normal file
66
api/jest/getRouteDescriptions.js
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
const { traverseDirectory } = require("lambert-server");
|
||||||
|
const path = require("path");
|
||||||
|
const express = require("express");
|
||||||
|
const RouteUtility = require("../dist/util/route");
|
||||||
|
const Router = express.Router;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some documentation.
|
||||||
|
*
|
||||||
|
* @type {Map<string, RouteUtility.RouteOptions>}
|
||||||
|
*/
|
||||||
|
const routes = new Map();
|
||||||
|
let currentPath = "";
|
||||||
|
let currentFile = "";
|
||||||
|
const methods = ["get", "post", "put", "delete", "patch"];
|
||||||
|
|
||||||
|
function registerPath(file, method, prefix, path, ...args) {
|
||||||
|
const urlPath = prefix + path;
|
||||||
|
const sourceFile = file.replace("/dist/", "/src/").replace(".js", ".ts");
|
||||||
|
const opts = args.find((x) => typeof x === "object");
|
||||||
|
if (opts) {
|
||||||
|
routes.set(urlPath + "|" + method, opts); // @ts-ignore
|
||||||
|
opts.file = sourceFile;
|
||||||
|
// console.log(method, urlPath, opts);
|
||||||
|
} else {
|
||||||
|
console.log(`${sourceFile}\nrouter.${method}("${path}") is missing the "route()" description middleware\n`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function routeOptions(opts) {
|
||||||
|
return opts;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
RouteUtility.route = routeOptions;
|
||||||
|
|
||||||
|
express.Router = (opts) => {
|
||||||
|
const path = currentPath;
|
||||||
|
const file = currentFile;
|
||||||
|
const router = Router(opts);
|
||||||
|
|
||||||
|
for (const method of methods) {
|
||||||
|
router[method] = registerPath.bind(null, file, method, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return router;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = function getRouteDescriptions() {
|
||||||
|
const root = path.join(__dirname, "..", "dist", "routes", "/");
|
||||||
|
traverseDirectory({ dirname: root, recursive: true }, (file) => {
|
||||||
|
currentFile = file;
|
||||||
|
let path = file.replace(root.slice(0, -1), "");
|
||||||
|
path = path.split(".").slice(0, -1).join("."); // trancate .js/.ts file extension of path
|
||||||
|
path = path.replaceAll("#", ":").replaceAll("\\", "/"); // replace # with : for path parameters and windows paths with slashes
|
||||||
|
if (path.endsWith("/index")) path = path.slice(0, "/index".length * -1); // delete index from path
|
||||||
|
currentPath = path;
|
||||||
|
|
||||||
|
try {
|
||||||
|
require(file);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("error loading file " + file, error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return routes;
|
||||||
|
};
|
@ -1,11 +1,17 @@
|
|||||||
|
const { Config, initDatabase } = require("@fosscord/util");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
const { FosscordServer } = require("../dist/Server");
|
const { FosscordServer } = require("../dist/Server");
|
||||||
const Server = new FosscordServer({ port: 3001 });
|
const Server = new FosscordServer({ port: 3001 });
|
||||||
global.server = Server;
|
global.server = Server;
|
||||||
module.exports = async () => {
|
module.exports = async () => {
|
||||||
try {
|
try {
|
||||||
fs.unlinkSync(`${__dirname}/../database.db`);
|
fs.unlinkSync(path.join(process.cwd(), "database.db"));
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|
||||||
|
await initDatabase();
|
||||||
|
await Config.init();
|
||||||
|
Config.get().limits.rate.disabled = true;
|
||||||
return await Server.start();
|
return await Server.start();
|
||||||
};
|
};
|
||||||
|
|
7623
api/package-lock.json
generated
7623
api/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -5,14 +5,17 @@
|
|||||||
"main": "dist/Server.js",
|
"main": "dist/Server.js",
|
||||||
"types": "dist/Server.d.ts",
|
"types": "dist/Server.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "npm run build && jest --coverage --verbose --forceExit ./tests",
|
"test:only": "jest --coverage --verbose --forceExit ./tests",
|
||||||
|
"test": "npm run build && npm run test:only",
|
||||||
"test:watch": "jest --watch",
|
"test:watch": "jest --watch",
|
||||||
"start": "npm run build && node dist/start",
|
"start": "npm run build && node dist/start",
|
||||||
"build": "npx tsc -b .",
|
"build": "npx tsc -b .",
|
||||||
"build-docker": "tsc -p tsconfig-docker.json",
|
"build-docker": "tsc -p tsconfig-docker.json",
|
||||||
"dev": "tsnd --respawn src/start.ts",
|
"dev": "tsnd --respawn src/start.ts",
|
||||||
"patch": "npx patch-package",
|
"patch": "ts-patch install -s && npx patch-package",
|
||||||
"postinstall": "npm run patch"
|
"postinstall": "npm run patch",
|
||||||
|
"generate:docs": "node scripts/generate_openapi.ts",
|
||||||
|
"generate:schema": "node scripts/generate_schema.ts"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -33,11 +36,15 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://fosscord.com",
|
"homepage": "https://fosscord.com",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@babel/core": "^7.15.5",
|
||||||
|
"@babel/preset-env": "^7.15.6",
|
||||||
|
"@babel/preset-typescript": "^7.15.0",
|
||||||
"@types/amqplib": "^0.8.1",
|
"@types/amqplib": "^0.8.1",
|
||||||
"@types/bcrypt": "^5.0.0",
|
"@types/bcrypt": "^5.0.0",
|
||||||
"@types/express": "^4.17.9",
|
"@types/express": "^4.17.9",
|
||||||
"@types/i18next-node-fs-backend": "^2.1.0",
|
"@types/i18next-node-fs-backend": "^2.1.0",
|
||||||
"@types/jest": "^27.0.1",
|
"@types/jest": "^27.0.1",
|
||||||
|
"@types/jest-expect-message": "^1.0.3",
|
||||||
"@types/jsonwebtoken": "^8.5.0",
|
"@types/jsonwebtoken": "^8.5.0",
|
||||||
"@types/mongodb": "^3.6.9",
|
"@types/mongodb": "^3.6.9",
|
||||||
"@types/mongoose": "^5.10.5",
|
"@types/mongoose": "^5.10.5",
|
||||||
@ -46,21 +53,27 @@
|
|||||||
"@types/multer": "^1.4.5",
|
"@types/multer": "^1.4.5",
|
||||||
"@types/node": "^14.17.9",
|
"@types/node": "^14.17.9",
|
||||||
"@types/node-fetch": "^2.5.7",
|
"@types/node-fetch": "^2.5.7",
|
||||||
|
"@types/supertest": "^2.0.11",
|
||||||
"@zerollup/ts-transform-paths": "^1.7.18",
|
"@zerollup/ts-transform-paths": "^1.7.18",
|
||||||
"0x": "^4.10.2",
|
"0x": "^4.10.2",
|
||||||
|
"babel-jest": "^27.2.0",
|
||||||
"caxa": "^2.1.0",
|
"caxa": "^2.1.0",
|
||||||
"image-size": "^1.0.0",
|
"image-size": "^1.0.0",
|
||||||
"jest": "^26.6.3",
|
"jest": "^26.6.3",
|
||||||
|
"jest-expect-message": "^1.0.2",
|
||||||
|
"jest-runtime": "^27.2.1",
|
||||||
"saslprep": "^1.0.3",
|
"saslprep": "^1.0.3",
|
||||||
"ts-node": "^9.1.1",
|
"ts-node": "^9.1.1",
|
||||||
"ts-node-dev": "^1.1.6",
|
"ts-node-dev": "^1.1.6",
|
||||||
|
"ts-patch": "^1.4.4",
|
||||||
"typescript": "^4.4.2",
|
"typescript": "^4.4.2",
|
||||||
"typescript-json-schema": "^0.50.1"
|
"typescript-json-schema": "0.50.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fosscord/util": "file:../util",
|
"@fosscord/util": "file:../util",
|
||||||
"ajv": "^8.4.0",
|
"@types/morgan": "^1.9.3",
|
||||||
"ajv-formats": "^2.1.0",
|
"ajv": "8.6.2",
|
||||||
|
"ajv-formats": "^2.1.1",
|
||||||
"amqplib": "^0.8.0",
|
"amqplib": "^0.8.0",
|
||||||
"assert": "^1.5.0",
|
"assert": "^1.5.0",
|
||||||
"atomically": "^1.7.0",
|
"atomically": "^1.7.0",
|
||||||
@ -73,7 +86,7 @@
|
|||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"express-validator": "^6.9.2",
|
"express-validator": "^6.9.2",
|
||||||
"form-data": "^3.0.0",
|
"form-data": "^3.0.0",
|
||||||
"i18next": "^19.8.5",
|
"i18next": "^19.9.2",
|
||||||
"i18next-http-middleware": "^3.1.3",
|
"i18next-http-middleware": "^3.1.3",
|
||||||
"i18next-node-fs-backend": "^2.1.3",
|
"i18next-node-fs-backend": "^2.1.3",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
@ -82,17 +95,22 @@
|
|||||||
"mongoose": "^5.12.3",
|
"mongoose": "^5.12.3",
|
||||||
"mongoose-autopopulate": "^0.12.3",
|
"mongoose-autopopulate": "^0.12.3",
|
||||||
"mongoose-long": "^0.3.2",
|
"mongoose-long": "^0.3.2",
|
||||||
|
"morgan": "^1.10.0",
|
||||||
"multer": "^1.4.2",
|
"multer": "^1.4.2",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
"patch-package": "^6.4.7",
|
"patch-package": "^6.4.7",
|
||||||
"supertest": "^6.1.6",
|
"supertest": "^6.1.6",
|
||||||
|
"tsconfig-paths": "^3.11.0",
|
||||||
"typeorm": "^0.2.37"
|
"typeorm": "^0.2.37"
|
||||||
},
|
},
|
||||||
"jest": {
|
"jest": {
|
||||||
"setupFiles": [
|
"setupFiles": [
|
||||||
"<rootDir>/jest/setup.js"
|
"<rootDir>/jest/setup.js"
|
||||||
],
|
],
|
||||||
"globalSetup": "<rootDir>/scripts/globalSetup.js",
|
"setupFilesAfterEnv": [
|
||||||
|
"jest-expect-message"
|
||||||
|
],
|
||||||
|
"globalSetup": "<rootDir>/jest/globalSetup.js",
|
||||||
"verbose": true
|
"verbose": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
249
api/patches/ajv+8.6.2.patch
Normal file
249
api/patches/ajv+8.6.2.patch
Normal file
@ -0,0 +1,249 @@
|
|||||||
|
diff --git a/node_modules/ajv/dist/compile/jtd/parse.js b/node_modules/ajv/dist/compile/jtd/parse.js
|
||||||
|
index 1eeb1be..7684121 100644
|
||||||
|
--- a/node_modules/ajv/dist/compile/jtd/parse.js
|
||||||
|
+++ b/node_modules/ajv/dist/compile/jtd/parse.js
|
||||||
|
@@ -239,6 +239,9 @@ function parseType(cxt) {
|
||||||
|
gen.if(fail, () => parsingError(cxt, codegen_1.str `invalid timestamp`));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
+ case "bigint":
|
||||||
|
+ parseBigInt(cxt);
|
||||||
|
+ break
|
||||||
|
case "float32":
|
||||||
|
case "float64":
|
||||||
|
parseNumber(cxt);
|
||||||
|
@@ -284,6 +287,15 @@ function parseNumber(cxt, maxDigits) {
|
||||||
|
skipWhitespace(cxt);
|
||||||
|
gen.if(codegen_1._ `"-0123456789".indexOf(${jsonSlice(1)}) < 0`, () => jsonSyntaxError(cxt), () => parseWith(cxt, parseJson_1.parseJsonNumber, maxDigits));
|
||||||
|
}
|
||||||
|
+function parseBigInt(cxt, maxDigits) {
|
||||||
|
+ const {gen} = cxt
|
||||||
|
+ skipWhitespace(cxt)
|
||||||
|
+ gen.if(
|
||||||
|
+ _`"-0123456789".indexOf(${jsonSlice(1)}) < 0`,
|
||||||
|
+ () => jsonSyntaxError(cxt),
|
||||||
|
+ () => parseWith(cxt, parseJson_1.parseJsonBigInt, maxDigits)
|
||||||
|
+ )
|
||||||
|
+}
|
||||||
|
function parseBooleanToken(bool, fail) {
|
||||||
|
return (cxt) => {
|
||||||
|
const { gen, data } = cxt;
|
||||||
|
diff --git a/node_modules/ajv/dist/compile/rules.js b/node_modules/ajv/dist/compile/rules.js
|
||||||
|
index 82a591f..1ebd8fe 100644
|
||||||
|
--- a/node_modules/ajv/dist/compile/rules.js
|
||||||
|
+++ b/node_modules/ajv/dist/compile/rules.js
|
||||||
|
@@ -1,7 +1,7 @@
|
||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.getRules = exports.isJSONType = void 0;
|
||||||
|
-const _jsonTypes = ["string", "number", "integer", "boolean", "null", "object", "array"];
|
||||||
|
+const _jsonTypes = ["string", "number", "integer", "boolean", "null", "object", "array","bigint"];
|
||||||
|
const jsonTypes = new Set(_jsonTypes);
|
||||||
|
function isJSONType(x) {
|
||||||
|
return typeof x == "string" && jsonTypes.has(x);
|
||||||
|
@@ -13,10 +13,11 @@ function getRules() {
|
||||||
|
string: { type: "string", rules: [] },
|
||||||
|
array: { type: "array", rules: [] },
|
||||||
|
object: { type: "object", rules: [] },
|
||||||
|
+ bigint: {type: "bigint", rules: []}
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
- types: { ...groups, integer: true, boolean: true, null: true },
|
||||||
|
- rules: [{ rules: [] }, groups.number, groups.string, groups.array, groups.object],
|
||||||
|
+ types: { ...groups, integer: true, boolean: true, null: true, bigint: true },
|
||||||
|
+ rules: [{ rules: [] }, groups.number, groups.string, groups.array, groups.object, groups.bigint],
|
||||||
|
post: { rules: [] },
|
||||||
|
all: {},
|
||||||
|
keywords: {},
|
||||||
|
diff --git a/node_modules/ajv/dist/compile/validate/dataType.js b/node_modules/ajv/dist/compile/validate/dataType.js
|
||||||
|
index 6319e76..8b50b4c 100644
|
||||||
|
--- a/node_modules/ajv/dist/compile/validate/dataType.js
|
||||||
|
+++ b/node_modules/ajv/dist/compile/validate/dataType.js
|
||||||
|
@@ -52,7 +52,7 @@ function coerceAndCheckDataType(it, types) {
|
||||||
|
return checkTypes;
|
||||||
|
}
|
||||||
|
exports.coerceAndCheckDataType = coerceAndCheckDataType;
|
||||||
|
-const COERCIBLE = new Set(["string", "number", "integer", "boolean", "null"]);
|
||||||
|
+const COERCIBLE = new Set(["string", "number", "integer", "boolean", "null","bigint"]);
|
||||||
|
function coerceToTypes(types, coerceTypes) {
|
||||||
|
return coerceTypes
|
||||||
|
? types.filter((t) => COERCIBLE.has(t) || (coerceTypes === "array" && t === "array"))
|
||||||
|
@@ -83,6 +83,14 @@ function coerceData(it, types, coerceTo) {
|
||||||
|
});
|
||||||
|
function coerceSpecificType(t) {
|
||||||
|
switch (t) {
|
||||||
|
+ case "bigint":
|
||||||
|
+ gen
|
||||||
|
+ .elseIf(
|
||||||
|
+ codegen_1._`${dataType} == "boolean" || ${data} === null
|
||||||
|
+ || (${dataType} == "string" && ${data} && ${data} == BigInt(${data}))`
|
||||||
|
+ )
|
||||||
|
+ .assign(coerced, codegen_1._`BigInt(${data})`)
|
||||||
|
+ return
|
||||||
|
case "string":
|
||||||
|
gen
|
||||||
|
.elseIf(codegen_1._ `${dataType} == "number" || ${dataType} == "boolean"`)
|
||||||
|
@@ -143,6 +151,9 @@ function checkDataType(dataType, data, strictNums, correct = DataType.Correct) {
|
||||||
|
case "number":
|
||||||
|
cond = numCond();
|
||||||
|
break;
|
||||||
|
+ case "bigint":
|
||||||
|
+ cond = codegen_1._`typeof ${data} == "bigint" && isFinite(${data})`
|
||||||
|
+ break
|
||||||
|
default:
|
||||||
|
return codegen_1._ `typeof ${data} ${EQ} ${dataType}`;
|
||||||
|
}
|
||||||
|
diff --git a/node_modules/ajv/dist/refs/json-schema-2019-09/meta/validation.json b/node_modules/ajv/dist/refs/json-schema-2019-09/meta/validation.json
|
||||||
|
index 7027a12..25679c8 100644
|
||||||
|
--- a/node_modules/ajv/dist/refs/json-schema-2019-09/meta/validation.json
|
||||||
|
+++ b/node_modules/ajv/dist/refs/json-schema-2019-09/meta/validation.json
|
||||||
|
@@ -78,7 +78,7 @@
|
||||||
|
"default": 0
|
||||||
|
},
|
||||||
|
"simpleTypes": {
|
||||||
|
- "enum": ["array", "boolean", "integer", "null", "number", "object", "string"]
|
||||||
|
+ "enum": ["array", "boolean", "integer", "null", "number", "object", "string","bigint"]
|
||||||
|
},
|
||||||
|
"stringArray": {
|
||||||
|
"type": "array",
|
||||||
|
diff --git a/node_modules/ajv/dist/refs/json-schema-2020-12/meta/validation.json b/node_modules/ajv/dist/refs/json-schema-2020-12/meta/validation.json
|
||||||
|
index e0ae13d..57c9036 100644
|
||||||
|
--- a/node_modules/ajv/dist/refs/json-schema-2020-12/meta/validation.json
|
||||||
|
+++ b/node_modules/ajv/dist/refs/json-schema-2020-12/meta/validation.json
|
||||||
|
@@ -78,7 +78,7 @@
|
||||||
|
"default": 0
|
||||||
|
},
|
||||||
|
"simpleTypes": {
|
||||||
|
- "enum": ["array", "boolean", "integer", "null", "number", "object", "string"]
|
||||||
|
+ "enum": ["array", "boolean", "integer", "null", "number", "object", "string","bigint"]
|
||||||
|
},
|
||||||
|
"stringArray": {
|
||||||
|
"type": "array",
|
||||||
|
diff --git a/node_modules/ajv/dist/refs/json-schema-draft-06.json b/node_modules/ajv/dist/refs/json-schema-draft-06.json
|
||||||
|
index 5410064..774435b 100644
|
||||||
|
--- a/node_modules/ajv/dist/refs/json-schema-draft-06.json
|
||||||
|
+++ b/node_modules/ajv/dist/refs/json-schema-draft-06.json
|
||||||
|
@@ -16,7 +16,7 @@
|
||||||
|
"allOf": [{"$ref": "#/definitions/nonNegativeInteger"}, {"default": 0}]
|
||||||
|
},
|
||||||
|
"simpleTypes": {
|
||||||
|
- "enum": ["array", "boolean", "integer", "null", "number", "object", "string"]
|
||||||
|
+ "enum": ["array", "boolean", "integer", "null", "number", "object", "string","bigint"]
|
||||||
|
},
|
||||||
|
"stringArray": {
|
||||||
|
"type": "array",
|
||||||
|
diff --git a/node_modules/ajv/dist/refs/json-schema-draft-07.json b/node_modules/ajv/dist/refs/json-schema-draft-07.json
|
||||||
|
index 6a74851..fc6dd7d 100644
|
||||||
|
--- a/node_modules/ajv/dist/refs/json-schema-draft-07.json
|
||||||
|
+++ b/node_modules/ajv/dist/refs/json-schema-draft-07.json
|
||||||
|
@@ -16,7 +16,7 @@
|
||||||
|
"allOf": [{"$ref": "#/definitions/nonNegativeInteger"}, {"default": 0}]
|
||||||
|
},
|
||||||
|
"simpleTypes": {
|
||||||
|
- "enum": ["array", "boolean", "integer", "null", "number", "object", "string"]
|
||||||
|
+ "enum": ["array", "boolean", "integer", "null", "number", "object", "string","bigint"]
|
||||||
|
},
|
||||||
|
"stringArray": {
|
||||||
|
"type": "array",
|
||||||
|
diff --git a/node_modules/ajv/dist/refs/jtd-schema.js b/node_modules/ajv/dist/refs/jtd-schema.js
|
||||||
|
index 1ee940a..1148887 100644
|
||||||
|
--- a/node_modules/ajv/dist/refs/jtd-schema.js
|
||||||
|
+++ b/node_modules/ajv/dist/refs/jtd-schema.js
|
||||||
|
@@ -38,6 +38,7 @@ const typeForm = (root) => ({
|
||||||
|
"uint16",
|
||||||
|
"int32",
|
||||||
|
"uint32",
|
||||||
|
+ "bigint",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
diff --git a/node_modules/ajv/dist/runtime/parseJson.js b/node_modules/ajv/dist/runtime/parseJson.js
|
||||||
|
index 2576a6e..e7447b1 100644
|
||||||
|
--- a/node_modules/ajv/dist/runtime/parseJson.js
|
||||||
|
+++ b/node_modules/ajv/dist/runtime/parseJson.js
|
||||||
|
@@ -97,6 +97,71 @@ exports.parseJsonNumber = parseJsonNumber;
|
||||||
|
parseJsonNumber.message = undefined;
|
||||||
|
parseJsonNumber.position = 0;
|
||||||
|
parseJsonNumber.code = 'require("ajv/dist/runtime/parseJson").parseJsonNumber';
|
||||||
|
+
|
||||||
|
+function parseJsonBigInt(s, pos, maxDigits) {
|
||||||
|
+ let numStr = "";
|
||||||
|
+ let c;
|
||||||
|
+ parseJsonBigInt.message = undefined;
|
||||||
|
+ if (s[pos] === "-") {
|
||||||
|
+ numStr += "-";
|
||||||
|
+ pos++;
|
||||||
|
+ }
|
||||||
|
+ if (s[pos] === "0") {
|
||||||
|
+ numStr += "0";
|
||||||
|
+ pos++;
|
||||||
|
+ }
|
||||||
|
+ else {
|
||||||
|
+ if (!parseDigits(maxDigits)) {
|
||||||
|
+ errorMessage();
|
||||||
|
+ return undefined;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ if (maxDigits) {
|
||||||
|
+ parseJsonBigInt.position = pos;
|
||||||
|
+ return BigInt(numStr);
|
||||||
|
+ }
|
||||||
|
+ if (s[pos] === ".") {
|
||||||
|
+ numStr += ".";
|
||||||
|
+ pos++;
|
||||||
|
+ if (!parseDigits()) {
|
||||||
|
+ errorMessage();
|
||||||
|
+ return undefined;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ if (((c = s[pos]), c === "e" || c === "E")) {
|
||||||
|
+ numStr += "e";
|
||||||
|
+ pos++;
|
||||||
|
+ if (((c = s[pos]), c === "+" || c === "-")) {
|
||||||
|
+ numStr += c;
|
||||||
|
+ pos++;
|
||||||
|
+ }
|
||||||
|
+ if (!parseDigits()) {
|
||||||
|
+ errorMessage();
|
||||||
|
+ return undefined;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ parseJsonBigInt.position = pos;
|
||||||
|
+ return BigInt(numStr);
|
||||||
|
+ function parseDigits(maxLen) {
|
||||||
|
+ let digit = false;
|
||||||
|
+ while (((c = s[pos]), c >= "0" && c <= "9" && (maxLen === undefined || maxLen-- > 0))) {
|
||||||
|
+ digit = true;
|
||||||
|
+ numStr += c;
|
||||||
|
+ pos++;
|
||||||
|
+ }
|
||||||
|
+ return digit;
|
||||||
|
+ }
|
||||||
|
+ function errorMessage() {
|
||||||
|
+ parseJsonBigInt.position = pos;
|
||||||
|
+ parseJsonBigInt.message = pos < s.length ? `unexpected token ${s[pos]}` : "unexpected end";
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
+exports.parseJsonBigInt = parseJsonBigInt;
|
||||||
|
+parseJsonBigInt.message = undefined;
|
||||||
|
+parseJsonBigInt.position = 0;
|
||||||
|
+parseJsonBigInt.code = 'require("ajv/dist/runtime/parseJson").parseJsonBigInt';
|
||||||
|
+
|
||||||
|
+
|
||||||
|
const escapedChars = {
|
||||||
|
b: "\b",
|
||||||
|
f: "\f",
|
||||||
|
diff --git a/node_modules/ajv/dist/vocabularies/jtd/type.js b/node_modules/ajv/dist/vocabularies/jtd/type.js
|
||||||
|
index 428bddb..fbc3070 100644
|
||||||
|
--- a/node_modules/ajv/dist/vocabularies/jtd/type.js
|
||||||
|
+++ b/node_modules/ajv/dist/vocabularies/jtd/type.js
|
||||||
|
@@ -45,6 +45,9 @@ const def = {
|
||||||
|
cond = timestampCode(cxt);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
+ case "bigint":
|
||||||
|
+ cond = codegen_1._`typeof ${data} == "bigint" || typeof ${data} == "string"`
|
||||||
|
+ break
|
||||||
|
case "float32":
|
||||||
|
case "float64":
|
||||||
|
cond = codegen_1._ `typeof ${data} == "number"`;
|
137
api/scripts/generate_openapi.js
Normal file
137
api/scripts/generate_openapi.js
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
// https://mermade.github.io/openapi-gui/#
|
||||||
|
// https://editor.swagger.io/
|
||||||
|
const getRouteDescriptions = require("../jest/getRouteDescriptions");
|
||||||
|
const path = require("path");
|
||||||
|
const fs = require("fs");
|
||||||
|
require("missing-native-js-functions");
|
||||||
|
|
||||||
|
const openapiPath = path.join(__dirname, "..", "assets", "openapi.json");
|
||||||
|
const SchemaPath = path.join(__dirname, "..", "assets", "schemas.json");
|
||||||
|
const schemas = JSON.parse(fs.readFileSync(SchemaPath, { encoding: "utf8" }));
|
||||||
|
const specification = JSON.parse(fs.readFileSync(openapiPath, { encoding: "utf8" }));
|
||||||
|
|
||||||
|
function combineSchemas(schemas) {
|
||||||
|
var definitions = {};
|
||||||
|
|
||||||
|
for (const name in schemas) {
|
||||||
|
definitions = {
|
||||||
|
...definitions,
|
||||||
|
...schemas[name].definitions,
|
||||||
|
[name]: { ...schemas[name], definitions: undefined, $schema: undefined }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const key in definitions) {
|
||||||
|
specification.components.schemas[key] = definitions[key];
|
||||||
|
delete definitions[key].additionalProperties;
|
||||||
|
delete definitions[key].$schema;
|
||||||
|
const definition = definitions[key];
|
||||||
|
|
||||||
|
if (typeof definition.properties === "object") {
|
||||||
|
for (const property of Object.values(definition.properties)) {
|
||||||
|
if (Array.isArray(property.type)) {
|
||||||
|
if (property.type.includes("null")) {
|
||||||
|
property.type = property.type.find((x) => x !== "null");
|
||||||
|
property.nullable = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return definitions;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTag(key) {
|
||||||
|
return key.match(/\/([\w-]+)/)[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
function apiRoutes() {
|
||||||
|
const routes = getRouteDescriptions();
|
||||||
|
|
||||||
|
const tags = Array.from(routes.keys()).map((x) => getTag(x));
|
||||||
|
specification.tags = [...specification.tags.map((x) => x.name), ...tags].unique().map((x) => ({ name: x }));
|
||||||
|
|
||||||
|
routes.forEach((route, pathAndMethod) => {
|
||||||
|
const [p, method] = pathAndMethod.split("|");
|
||||||
|
const path = p.replace(/:(\w+)/g, "{$1}");
|
||||||
|
|
||||||
|
let obj = specification.paths[path]?.[method] || {};
|
||||||
|
if (!obj.description) {
|
||||||
|
const permission = route.permission ? `##### Requires the \`\`${route.permission}\`\` permission\n` : "";
|
||||||
|
const event = route.test?.event ? `##### Fires a \`\`${route.test?.event}\`\` event\n` : "";
|
||||||
|
obj.description = permission + event;
|
||||||
|
}
|
||||||
|
if (route.body) {
|
||||||
|
obj.requestBody = {
|
||||||
|
required: true,
|
||||||
|
content: {
|
||||||
|
"application/json": {
|
||||||
|
schema: { $ref: `#/components/schemas/${route.body}` }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.merge(obj.requestBody);
|
||||||
|
}
|
||||||
|
if (!obj.responses) {
|
||||||
|
obj.responses = {
|
||||||
|
default: {
|
||||||
|
description: "not documented"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (route.test?.response) {
|
||||||
|
const status = route.test.response.status || 200;
|
||||||
|
let schema = {
|
||||||
|
allOf: [
|
||||||
|
{
|
||||||
|
$ref: `#/components/schemas/${route.test.response.body}`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
example: route.test.body
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
if (!route.test.body) schema = schema.allOf[0];
|
||||||
|
|
||||||
|
obj.responses = {
|
||||||
|
[status]: {
|
||||||
|
...(route.test.response.body
|
||||||
|
? {
|
||||||
|
description: obj.responses[status].description || "",
|
||||||
|
content: {
|
||||||
|
"application/json": {
|
||||||
|
schema: schema
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
: {})
|
||||||
|
}
|
||||||
|
}.merge(obj.responses);
|
||||||
|
delete obj.responses.default;
|
||||||
|
}
|
||||||
|
if (p.includes(":")) {
|
||||||
|
obj.parameters = p.match(/:\w+/g)?.map((x) => ({
|
||||||
|
name: x.replace(":", ""),
|
||||||
|
in: "path",
|
||||||
|
required: true,
|
||||||
|
schema: { type: "string" },
|
||||||
|
description: x.replace(":", "")
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
obj.tags = [...(obj.tags || []), getTag(p)].unique();
|
||||||
|
|
||||||
|
specification.paths[path] = { ...specification.paths[path], [method]: obj };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function main() {
|
||||||
|
combineSchemas(schemas);
|
||||||
|
apiRoutes();
|
||||||
|
|
||||||
|
fs.writeFileSync(
|
||||||
|
openapiPath,
|
||||||
|
JSON.stringify(specification, null, 4).replaceAll("#/definitions", "#/components/schemas").replaceAll("bigint", "number")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
@ -1,99 +0,0 @@
|
|||||||
// https://mermade.github.io/openapi-gui/#
|
|
||||||
// https://editor.swagger.io/
|
|
||||||
import path from "path";
|
|
||||||
import fs from "fs";
|
|
||||||
import * as TJS from "typescript-json-schema";
|
|
||||||
import "missing-native-js-functions";
|
|
||||||
|
|
||||||
const settings: TJS.PartialArgs = {
|
|
||||||
required: true,
|
|
||||||
ignoreErrors: true,
|
|
||||||
excludePrivate: true,
|
|
||||||
defaultNumberType: "integer",
|
|
||||||
noExtraProps: true,
|
|
||||||
defaultProps: false
|
|
||||||
};
|
|
||||||
const compilerOptions: TJS.CompilerOptions = {
|
|
||||||
strictNullChecks: false
|
|
||||||
};
|
|
||||||
const openapiPath = path.join(__dirname, "..", "assets", "openapi.json");
|
|
||||||
var specification = JSON.parse(fs.readFileSync(openapiPath, { encoding: "utf8" }));
|
|
||||||
|
|
||||||
async function utilSchemas() {
|
|
||||||
const program = TJS.getProgramFromFiles([path.join(__dirname, "..", "..", "util", "src", "index.ts")], compilerOptions);
|
|
||||||
const generator = TJS.buildGenerator(program, settings);
|
|
||||||
|
|
||||||
const schemas = ["UserPublic", "UserPrivate", "PublicConnectedAccount"];
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
combineSchemas({ schemas, generator, program });
|
|
||||||
}
|
|
||||||
|
|
||||||
function combineSchemas(opts: { program: TJS.Program; generator: TJS.JsonSchemaGenerator; schemas: string[] }) {
|
|
||||||
var definitions: any = {};
|
|
||||||
|
|
||||||
for (const name of opts.schemas) {
|
|
||||||
const part = TJS.generateSchema(opts.program, name, settings, [], opts.generator as TJS.JsonSchemaGenerator);
|
|
||||||
if (!part) continue;
|
|
||||||
|
|
||||||
definitions = { ...definitions, [name]: { ...part, definitions: undefined, $schema: undefined } };
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const key in definitions) {
|
|
||||||
specification.components.schemas[key] = definitions[key];
|
|
||||||
delete definitions[key].additionalProperties;
|
|
||||||
delete definitions[key].$schema;
|
|
||||||
}
|
|
||||||
|
|
||||||
return definitions;
|
|
||||||
}
|
|
||||||
|
|
||||||
function apiSchemas() {
|
|
||||||
const program = TJS.getProgramFromFiles([path.join(__dirname, "..", "src", "schema", "index.ts")], compilerOptions);
|
|
||||||
const generator = TJS.buildGenerator(program, settings);
|
|
||||||
|
|
||||||
const schemas = [
|
|
||||||
"BanCreateSchema",
|
|
||||||
"DmChannelCreateSchema",
|
|
||||||
"ChannelModifySchema",
|
|
||||||
"ChannelGuildPositionUpdateSchema",
|
|
||||||
"ChannelGuildPositionUpdateSchema",
|
|
||||||
"EmojiCreateSchema",
|
|
||||||
"GuildCreateSchema",
|
|
||||||
"GuildUpdateSchema",
|
|
||||||
"GuildTemplateCreateSchema",
|
|
||||||
"GuildUpdateWelcomeScreenSchema",
|
|
||||||
"InviteCreateSchema",
|
|
||||||
"MemberCreateSchema",
|
|
||||||
"MemberNickChangeSchema",
|
|
||||||
"MemberChangeSchema",
|
|
||||||
"MessageCreateSchema",
|
|
||||||
"RoleModifySchema",
|
|
||||||
"TemplateCreateSchema",
|
|
||||||
"TemplateModifySchema",
|
|
||||||
"UserModifySchema",
|
|
||||||
"UserSettingsSchema",
|
|
||||||
"WidgetModifySchema",
|
|
||||||
""
|
|
||||||
];
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
combineSchemas({ schemas, generator, program });
|
|
||||||
}
|
|
||||||
|
|
||||||
function addDefaultResponses() {
|
|
||||||
Object.values(specification.paths).forEach((path: any) => Object.values(path).forEach((request: any) => {}));
|
|
||||||
}
|
|
||||||
|
|
||||||
function main() {
|
|
||||||
addDefaultResponses();
|
|
||||||
utilSchemas();
|
|
||||||
apiSchemas();
|
|
||||||
|
|
||||||
fs.writeFileSync(
|
|
||||||
openapiPath,
|
|
||||||
JSON.stringify(specification, null, 4).replaceAll("#/definitions", "#/components/schemas").replaceAll("bigint", "number")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
main();
|
|
70
api/scripts/generate_schema.js
Normal file
70
api/scripts/generate_schema.js
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
// https://mermade.github.io/openapi-gui/#
|
||||||
|
// https://editor.swagger.io/
|
||||||
|
import path from "path";
|
||||||
|
import fs from "fs";
|
||||||
|
import * as TJS from "typescript-json-schema";
|
||||||
|
import "missing-native-js-functions";
|
||||||
|
const schemaPath = path.join(__dirname, "..", "assets", "schemas.json");
|
||||||
|
|
||||||
|
const settings = {
|
||||||
|
required: true,
|
||||||
|
ignoreErrors: true,
|
||||||
|
excludePrivate: true,
|
||||||
|
defaultNumberType: "integer",
|
||||||
|
noExtraProps: true,
|
||||||
|
defaultProps: false
|
||||||
|
};
|
||||||
|
const compilerOptions = {
|
||||||
|
strictNullChecks: true
|
||||||
|
};
|
||||||
|
const Excluded = [
|
||||||
|
"DefaultSchema",
|
||||||
|
"Schema",
|
||||||
|
"EntitySchema",
|
||||||
|
"ServerResponse",
|
||||||
|
"Http2ServerResponse",
|
||||||
|
"global.Express.Response",
|
||||||
|
"Response",
|
||||||
|
"e.Response",
|
||||||
|
"request.Response",
|
||||||
|
"supertest.Response"
|
||||||
|
];
|
||||||
|
|
||||||
|
function main() {
|
||||||
|
const program = TJS.getProgramFromFiles(walk(path.join(__dirname, "..", "src", "routes")), compilerOptions);
|
||||||
|
const generator = TJS.buildGenerator(program, settings);
|
||||||
|
if (!generator || !program) return;
|
||||||
|
|
||||||
|
const schemas = generator.getUserSymbols().filter((x) => (x.endsWith("Schema") || x.endsWith("Response")) && !Excluded.includes(x));
|
||||||
|
console.log(schemas);
|
||||||
|
|
||||||
|
var definitions = {};
|
||||||
|
|
||||||
|
for (const name of schemas) {
|
||||||
|
const part = TJS.generateSchema(program, name, settings, [], generator);
|
||||||
|
if (!part) continue;
|
||||||
|
|
||||||
|
definitions = { ...definitions, [name]: { ...part } };
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.writeFileSync(schemaPath, JSON.stringify(definitions, null, 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
|
|
||||||
|
function walk(dir) {
|
||||||
|
var results = [];
|
||||||
|
var list = fs.readdirSync(dir);
|
||||||
|
list.forEach(function (file) {
|
||||||
|
file = dir + "/" + file;
|
||||||
|
var stat = fs.statSync(file);
|
||||||
|
if (stat && stat.isDirectory()) {
|
||||||
|
/* Recurse into a subdirectory */
|
||||||
|
results = results.concat(walk(file));
|
||||||
|
} else {
|
||||||
|
if (!file.endsWith(".ts")) return;
|
||||||
|
results.push(file);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return results;
|
||||||
|
}
|
@ -1,3 +1,4 @@
|
|||||||
|
import { OptionsJson } from 'body-parser';
|
||||||
import "missing-native-js-functions";
|
import "missing-native-js-functions";
|
||||||
import { Connection } from "mongoose";
|
import { Connection } from "mongoose";
|
||||||
import { Server, ServerOptions } from "lambert-server";
|
import { Server, ServerOptions } from "lambert-server";
|
||||||
@ -11,6 +12,7 @@ import path from "path";
|
|||||||
import { initRateLimits } from "./middlewares/RateLimit";
|
import { initRateLimits } from "./middlewares/RateLimit";
|
||||||
import TestClient from "./middlewares/TestClient";
|
import TestClient from "./middlewares/TestClient";
|
||||||
import { initTranslation } from "./middlewares/Translation";
|
import { initTranslation } from "./middlewares/Translation";
|
||||||
|
import morgan from "morgan";
|
||||||
|
|
||||||
export interface FosscordServerOptions extends ServerOptions {}
|
export interface FosscordServerOptions extends ServerOptions {}
|
||||||
|
|
||||||
@ -36,8 +38,31 @@ export class FosscordServer extends Server {
|
|||||||
await Config.init();
|
await Config.init();
|
||||||
await initEvent();
|
await initEvent();
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
DOCUMENTATION: uses LOG_REQUESTS environment variable
|
||||||
|
|
||||||
|
# only log 200 and 204
|
||||||
|
LOG_REQUESTS=200 204
|
||||||
|
# log everything except 200 and 204
|
||||||
|
LOG_REQUESTS=-200 204
|
||||||
|
# log all requests
|
||||||
|
LOG_REQUESTS=-
|
||||||
|
*/
|
||||||
|
|
||||||
|
let logRequests = process.env["LOG_REQUESTS"] != undefined;
|
||||||
|
if(logRequests) {
|
||||||
|
this.app.use(morgan("combined", {
|
||||||
|
skip: (req, res) => {
|
||||||
|
var skip = !(process.env["LOG_REQUESTS"]?.includes(res.statusCode.toString()) ?? false);
|
||||||
|
if(process.env["LOG_REQUESTS"]?.charAt(0) == '-') skip = !skip;
|
||||||
|
return skip;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
this.app.use(CORS);
|
this.app.use(CORS);
|
||||||
this.app.use(BodyParser({ inflate: true, limit: 1024 * 1024 * 10 })); // 10MB
|
this.app.use(BodyParser({ inflate: true, limit: "10mb" }));
|
||||||
|
|
||||||
const app = this.app;
|
const app = this.app;
|
||||||
const api = Router(); // @ts-ignore
|
const api = Router(); // @ts-ignore
|
||||||
@ -65,6 +90,9 @@ export class FosscordServer extends Server {
|
|||||||
this.app.use(ErrorHandler);
|
this.app.use(ErrorHandler);
|
||||||
TestClient(this.app);
|
TestClient(this.app);
|
||||||
|
|
||||||
|
if(logRequests){
|
||||||
|
console.log("Warning: Request logging is enabled! This will spam your console!\nTo disable this, unset the 'LOG_REQUESTS' environment variable!");
|
||||||
|
}
|
||||||
return super.start();
|
return super.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,3 @@
|
|||||||
export * from "./Server";
|
export * from "./Server";
|
||||||
export * from "./middlewares/";
|
export * from "./middlewares/";
|
||||||
export * from "./schema/Ban";
|
export * from "./util/";
|
||||||
export * from "./schema/Channel";
|
|
||||||
export * from "./schema/Guild";
|
|
||||||
export * from "./schema/Invite";
|
|
||||||
export * from "./schema/Message";
|
|
||||||
export * from "./util/instanceOf";
|
|
||||||
export * from "./util/instanceOf";
|
|
||||||
export * from "./util/RandomInviteID";
|
|
||||||
export * from "./util/String";
|
|
||||||
export { check as checkPassword } from "./util/passwordStrength";
|
|
||||||
|
@ -6,6 +6,8 @@ export function BodyParser(opts?: OptionsJson) {
|
|||||||
const jsonParser = bodyParser.json(opts);
|
const jsonParser = bodyParser.json(opts);
|
||||||
|
|
||||||
return (req: Request, res: Response, next: NextFunction) => {
|
return (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
if (!req.headers["content-type"]) req.headers["content-type"] = "application/json";
|
||||||
|
|
||||||
jsonParser(req, res, (err) => {
|
jsonParser(req, res, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
// TODO: different errors for body parser (request size limit, wrong body type, invalid body, ...)
|
// TODO: different errors for body parser (request size limit, wrong body type, invalid body, ...)
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import { NextFunction, Request, Response } from "express";
|
import { NextFunction, Request, Response } from "express";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { EntityNotFoundError } from "typeorm";
|
import { EntityNotFoundError } from "typeorm";
|
||||||
import { FieldError } from "../util/instanceOf";
|
import { FieldError } from "@fosscord/api";
|
||||||
import { ApiError } from "@fosscord/util";
|
import { ApiError } from "@fosscord/util";
|
||||||
|
const EntityNotFoundErrorRegex = /"(\w+)"/;
|
||||||
|
|
||||||
export function ErrorHandler(error: Error, req: Request, res: Response, next: NextFunction) {
|
export function ErrorHandler(error: Error, req: Request, res: Response, next: NextFunction) {
|
||||||
if (!error) return next();
|
if (!error) return next();
|
||||||
@ -18,9 +19,9 @@ export function ErrorHandler(error: Error, req: Request, res: Response, next: Ne
|
|||||||
code = error.code;
|
code = error.code;
|
||||||
message = error.message;
|
message = error.message;
|
||||||
httpcode = error.httpStatus;
|
httpcode = error.httpStatus;
|
||||||
} else if (error instanceof EntityNotFoundError) {
|
} else if (error.name === "EntityNotFoundError") {
|
||||||
message = `${(error as any).stringifyTarget || "Item"} could not be found`;
|
message = `${error.message.match(EntityNotFoundErrorRegex)?.[1] || "Item"} could not be found`;
|
||||||
code = 404;
|
code = httpcode = 404;
|
||||||
} else if (error instanceof FieldError) {
|
} else if (error instanceof FieldError) {
|
||||||
code = Number(error.code);
|
code = Number(error.code);
|
||||||
message = error.message;
|
message = error.message;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Config, listenEvent } from "@fosscord/util";
|
import { Config, listenEvent } from "@fosscord/util";
|
||||||
import { NextFunction, Request, Response, Router } from "express";
|
import { NextFunction, Request, Response, Router } from "express";
|
||||||
import { getIpAdress } from "../util/ipAddress";
|
import { getIpAdress } from "@fosscord/api";
|
||||||
import { API_PREFIX_TRAILING_SLASH } from "./Authentication";
|
import { API_PREFIX_TRAILING_SLASH } from "./Authentication";
|
||||||
|
|
||||||
// Docs: https://discord.com/developers/docs/topics/rate-limits
|
// Docs: https://discord.com/developers/docs/topics/rate-limits
|
||||||
@ -107,7 +107,8 @@ export default function rateLimit(opts: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function initRateLimits(app: Router) {
|
export async function initRateLimits(app: Router) {
|
||||||
const { routes, global, ip, error } = Config.get().limits.rate;
|
const { routes, global, ip, error, disabled } = Config.get().limits.rate;
|
||||||
|
if (disabled) return;
|
||||||
await listenEvent(EventRateLimit, (event) => {
|
await listenEvent(EventRateLimit, (event) => {
|
||||||
Cache.set(event.channel_id as string, event.data);
|
Cache.set(event.channel_id as string, event.data);
|
||||||
event.acknowledge?.();
|
event.acknowledge?.();
|
||||||
|
@ -67,6 +67,8 @@ export default function TestClient(app: Application) {
|
|||||||
res.set("Cache-Control", "public, max-age=" + 60 * 60 * 24);
|
res.set("Cache-Control", "public, max-age=" + 60 * 60 * 24);
|
||||||
res.set("content-type", "text/html");
|
res.set("content-type", "text/html");
|
||||||
|
|
||||||
|
if (req.url.startsWith("/invite")) return res.send(html.replace("9b2b7f0632acd0c5e781", "9f24f709a3de09b67c49"));
|
||||||
|
|
||||||
res.send(html);
|
res.send(html);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
11
api/src/routes/applications/detectable.ts
Normal file
11
api/src/routes/applications/detectable.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { Request, Response, Router } from "express";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
|
const router: Router = Router();
|
||||||
|
|
||||||
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
|
//TODO
|
||||||
|
res.json([]).status(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
@ -1,25 +1,22 @@
|
|||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
import { check, FieldErrors, Length } from "../../util/instanceOf";
|
import { FieldErrors, route } from "@fosscord/api";
|
||||||
import bcrypt from "bcrypt";
|
import bcrypt from "bcrypt";
|
||||||
import jwt from "jsonwebtoken";
|
import { Config, User, generateToken, adjustEmail } from "@fosscord/util";
|
||||||
import { Config, User } from "@fosscord/util";
|
|
||||||
import { adjustEmail } from "./register";
|
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
export default router;
|
export default router;
|
||||||
|
|
||||||
router.post(
|
export interface LoginSchema {
|
||||||
"/",
|
login: string;
|
||||||
check({
|
password: string;
|
||||||
login: new Length(String, 2, 100), // email or telephone
|
undelete?: boolean;
|
||||||
password: new Length(String, 8, 72),
|
captcha_key?: string;
|
||||||
$undelete: Boolean,
|
login_source?: string;
|
||||||
$captcha_key: String,
|
gift_code_sku_id?: string;
|
||||||
$login_source: String,
|
}
|
||||||
$gift_code_sku_id: String
|
|
||||||
}),
|
router.post("/", route({ body: "LoginSchema" }), async (req: Request, res: Response) => {
|
||||||
async (req: Request, res: Response) => {
|
const { login, password, captcha_key, undelete } = req.body as LoginSchema;
|
||||||
const { login, password, captcha_key, undelete } = req.body;
|
|
||||||
const email = adjustEmail(login);
|
const email = adjustEmail(login);
|
||||||
console.log("login", email);
|
console.log("login", email);
|
||||||
|
|
||||||
@ -67,27 +64,7 @@ router.post(
|
|||||||
// https://user-images.githubusercontent.com/6506416/81051916-dd8c9900-8ec2-11ea-8794-daf12d6f31f0.png
|
// https://user-images.githubusercontent.com/6506416/81051916-dd8c9900-8ec2-11ea-8794-daf12d6f31f0.png
|
||||||
|
|
||||||
res.json({ token, settings: user.settings });
|
res.json({ token, settings: user.settings });
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
export async function generateToken(id: string) {
|
|
||||||
const iat = Math.floor(Date.now() / 1000);
|
|
||||||
const algorithm = "HS256";
|
|
||||||
|
|
||||||
return new Promise((res, rej) => {
|
|
||||||
jwt.sign(
|
|
||||||
{ id: id, iat },
|
|
||||||
Config.get().security.jwtSecret,
|
|
||||||
{
|
|
||||||
algorithm
|
|
||||||
},
|
|
||||||
(err, token) => {
|
|
||||||
if (err) return rej(err);
|
|
||||||
return res(token);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* POST /auth/login
|
* POST /auth/login
|
||||||
|
@ -1,32 +1,40 @@
|
|||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
import { trimSpecial, User, Snowflake, Config, defaultSettings } from "@fosscord/util";
|
import { trimSpecial, User, Snowflake, Config, defaultSettings, generateToken, Invite, adjustEmail } from "@fosscord/util";
|
||||||
import bcrypt from "bcrypt";
|
import bcrypt from "bcrypt";
|
||||||
import { check, Email, EMAIL_REGEX, FieldErrors, Length } from "../../util/instanceOf";
|
import { FieldErrors, route, getIpAdress, IPAnalysis, isProxy } from "@fosscord/api";
|
||||||
import "missing-native-js-functions";
|
import "missing-native-js-functions";
|
||||||
import { generateToken } from "./login";
|
|
||||||
import { getIpAdress, IPAnalysis, isProxy } from "../../util/ipAddress";
|
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { In } from "typeorm";
|
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
router.post(
|
export interface RegisterSchema {
|
||||||
"/",
|
/**
|
||||||
check({
|
* @minLength 2
|
||||||
username: new Length(String, 2, 32),
|
* @maxLength 32
|
||||||
// TODO: check min password length in config
|
*/
|
||||||
// prevent Denial of Service with max length of 72 chars
|
username: string;
|
||||||
password: new Length(String, 8, 72),
|
/**
|
||||||
consent: Boolean,
|
* @minLength 1
|
||||||
$email: new Length(Email, 5, 100),
|
* @maxLength 72
|
||||||
$fingerprint: String,
|
*/
|
||||||
$invite: String,
|
password?: string;
|
||||||
$date_of_birth: Date, // "2000-04-03"
|
consent: boolean;
|
||||||
$gift_code_sku_id: String,
|
/**
|
||||||
$captcha_key: String
|
* @TJS-format email
|
||||||
}),
|
*/
|
||||||
async (req: Request, res: Response) => {
|
email?: string;
|
||||||
const {
|
fingerprint?: string;
|
||||||
|
invite?: string;
|
||||||
|
/**
|
||||||
|
* @TJS-type string
|
||||||
|
*/
|
||||||
|
date_of_birth?: Date; // "2000-04-03"
|
||||||
|
gift_code_sku_id?: string;
|
||||||
|
captcha_key?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
router.post("/", route({ body: "RegisterSchema" }), async (req: Request, res: Response) => {
|
||||||
|
let {
|
||||||
email,
|
email,
|
||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
@ -50,18 +58,14 @@ router.post(
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log("register", req.body.email, req.body.username, ip);
|
console.log("register", req.body.email, req.body.username, ip);
|
||||||
// TODO: automatically join invite
|
|
||||||
// TODO: gift_code_sku_id?
|
// TODO: gift_code_sku_id?
|
||||||
// TODO: check password strength
|
// TODO: check password strength
|
||||||
|
|
||||||
// adjusted_email will be slightly modified version of the user supplied email -> e.g. protection against GMail Trick
|
// email will be slightly modified version of the user supplied email -> e.g. protection against GMail Trick
|
||||||
let adjusted_email = adjustEmail(email);
|
email = adjustEmail(email);
|
||||||
|
|
||||||
// adjusted_password will be the hash of the password
|
|
||||||
let adjusted_password = "";
|
|
||||||
|
|
||||||
// trim special uf8 control characters -> Backspace, Newline, ...
|
// trim special uf8 control characters -> Backspace, Newline, ...
|
||||||
let adjusted_username = trimSpecial(username);
|
username = trimSpecial(username);
|
||||||
|
|
||||||
// discriminator will be randomly generated
|
// discriminator will be randomly generated
|
||||||
let discriminator = "";
|
let discriminator = "";
|
||||||
@ -80,19 +84,12 @@ router.post(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// require invite to register -> e.g. for organizations to send invites to their employees
|
|
||||||
if (register.requireInvite && !invite) {
|
|
||||||
throw FieldErrors({
|
|
||||||
email: { code: "INVITE_ONLY", message: req.t("auth:register.INVITE_ONLY") }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (email) {
|
if (email) {
|
||||||
// replace all dots and chars after +, if its a gmail.com email
|
// replace all dots and chars after +, if its a gmail.com email
|
||||||
if (!adjusted_email) throw FieldErrors({ email: { code: "INVALID_EMAIL", message: req.t("auth:register.INVALID_EMAIL") } });
|
if (!email) throw FieldErrors({ email: { code: "INVALID_EMAIL", message: req.t("auth:register.INVALID_EMAIL") } });
|
||||||
|
|
||||||
// check if there is already an account with this email
|
// check if there is already an account with this email
|
||||||
const exists = await User.findOneOrFail({ email: adjusted_email }).catch((e) => {});
|
const exists = await User.findOneOrFail({ email: email }).catch((e) => {});
|
||||||
|
|
||||||
if (exists) {
|
if (exists) {
|
||||||
throw FieldErrors({
|
throw FieldErrors({
|
||||||
@ -102,19 +99,20 @@ router.post(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (register.email.necessary) {
|
} else if (register.email.required) {
|
||||||
throw FieldErrors({
|
throw FieldErrors({
|
||||||
email: { code: "BASE_TYPE_REQUIRED", message: req.t("common:field.BASE_TYPE_REQUIRED") }
|
email: { code: "BASE_TYPE_REQUIRED", message: req.t("common:field.BASE_TYPE_REQUIRED") }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (register.dateOfBirth.necessary && !date_of_birth) {
|
if (register.dateOfBirth.required && !date_of_birth) {
|
||||||
throw FieldErrors({
|
throw FieldErrors({
|
||||||
date_of_birth: { code: "BASE_TYPE_REQUIRED", message: req.t("common:field.BASE_TYPE_REQUIRED") }
|
date_of_birth: { code: "BASE_TYPE_REQUIRED", message: req.t("common:field.BASE_TYPE_REQUIRED") }
|
||||||
});
|
});
|
||||||
} else if (register.dateOfBirth.minimum) {
|
} else if (register.dateOfBirth.minimum) {
|
||||||
const minimum = new Date();
|
const minimum = new Date();
|
||||||
minimum.setFullYear(minimum.getFullYear() - register.dateOfBirth.minimum);
|
minimum.setFullYear(minimum.getFullYear() - register.dateOfBirth.minimum);
|
||||||
|
date_of_birth = new Date(date_of_birth);
|
||||||
|
|
||||||
// higher is younger
|
// higher is younger
|
||||||
if (date_of_birth > minimum) {
|
if (date_of_birth > minimum) {
|
||||||
@ -129,7 +127,7 @@ router.post(
|
|||||||
|
|
||||||
if (!register.allowMultipleAccounts) {
|
if (!register.allowMultipleAccounts) {
|
||||||
// TODO: check if fingerprint was eligible generated
|
// TODO: check if fingerprint was eligible generated
|
||||||
const exists = await User.findOne({ where: { fingerprints: In(fingerprint) } });
|
const exists = await User.findOne({ where: { fingerprints: fingerprint } });
|
||||||
|
|
||||||
if (exists) {
|
if (exists) {
|
||||||
throw FieldErrors({
|
throw FieldErrors({
|
||||||
@ -154,8 +152,14 @@ router.post(
|
|||||||
// TODO: check captcha
|
// TODO: check captcha
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (password) {
|
||||||
// the salt is saved in the password refer to bcrypt docs
|
// the salt is saved in the password refer to bcrypt docs
|
||||||
adjusted_password = await bcrypt.hash(password, 12);
|
password = await bcrypt.hash(password, 12);
|
||||||
|
} else if (register.password.required) {
|
||||||
|
throw FieldErrors({
|
||||||
|
password: { code: "BASE_TYPE_REQUIRED", message: req.t("common:field.BASE_TYPE_REQUIRED") }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let exists;
|
let exists;
|
||||||
// randomly generates a discriminator between 1 and 9999 and checks max five times if it already exists
|
// randomly generates a discriminator between 1 and 9999 and checks max five times if it already exists
|
||||||
@ -164,7 +168,7 @@ router.post(
|
|||||||
// TODO: is there any better way to generate a random discriminator only once, without checking if it already exists in the mongodb database?
|
// TODO: is there any better way to generate a random discriminator only once, without checking if it already exists in the mongodb database?
|
||||||
for (let tries = 0; tries < 5; tries++) {
|
for (let tries = 0; tries < 5; tries++) {
|
||||||
discriminator = Math.randomIntBetween(1, 9999).toString().padStart(4, "0");
|
discriminator = Math.randomIntBetween(1, 9999).toString().padStart(4, "0");
|
||||||
exists = await User.findOne({ where: { discriminator, username: adjusted_username }, select: ["id"] });
|
exists = await User.findOne({ where: { discriminator, username: username }, select: ["id"] });
|
||||||
if (!exists) break;
|
if (!exists) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,7 +187,7 @@ router.post(
|
|||||||
|
|
||||||
const user = await new User({
|
const user = await new User({
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
username: adjusted_username,
|
username: username,
|
||||||
discriminator,
|
discriminator,
|
||||||
id: Snowflake.generate(),
|
id: Snowflake.generate(),
|
||||||
bot: false,
|
bot: false,
|
||||||
@ -194,41 +198,33 @@ router.post(
|
|||||||
premium_type: 2,
|
premium_type: 2,
|
||||||
bio: "",
|
bio: "",
|
||||||
mfa_enabled: false,
|
mfa_enabled: false,
|
||||||
verified: false,
|
verified: true,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
deleted: false,
|
deleted: false,
|
||||||
email: adjusted_email,
|
email: email,
|
||||||
nsfw_allowed: true, // TODO: depending on age
|
nsfw_allowed: true, // TODO: depending on age
|
||||||
public_flags: "0",
|
public_flags: "0",
|
||||||
flags: "0", // TODO: generate
|
flags: "0", // TODO: generate
|
||||||
data: {
|
data: {
|
||||||
hash: adjusted_password,
|
hash: password,
|
||||||
valid_tokens_since: new Date()
|
valid_tokens_since: new Date()
|
||||||
},
|
},
|
||||||
settings: { ...defaultSettings, locale: req.language || "en-US" },
|
settings: { ...defaultSettings, locale: req.language || "en-US" },
|
||||||
fingerprints: []
|
fingerprints: []
|
||||||
}).save();
|
}).save();
|
||||||
|
|
||||||
|
if (invite) {
|
||||||
|
// await to fail if the invite doesn't exist (necessary for requireInvite to work properly) (username only signups are possible)
|
||||||
|
await Invite.joinGuild(user.id, invite);
|
||||||
|
} else if (register.requireInvite) {
|
||||||
|
// require invite to register -> e.g. for organizations to send invites to their employees
|
||||||
|
throw FieldErrors({
|
||||||
|
email: { code: "INVITE_ONLY", message: req.t("auth:register.INVITE_ONLY") }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return res.json({ token: await generateToken(user.id) });
|
return res.json({ token: await generateToken(user.id) });
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
export function adjustEmail(email: string): string | undefined {
|
|
||||||
// body parser already checked if it is a valid email
|
|
||||||
const parts = <RegExpMatchArray>email.match(EMAIL_REGEX);
|
|
||||||
// @ts-ignore
|
|
||||||
if (!parts || parts.length < 5) return undefined;
|
|
||||||
const domain = parts[5];
|
|
||||||
const user = parts[1];
|
|
||||||
|
|
||||||
// TODO: check accounts with uncommon email domains
|
|
||||||
if (domain === "gmail.com" || domain === "googlemail.com") {
|
|
||||||
// replace .dots and +alternatives -> Gmail Dot Trick https://support.google.com/mail/answer/7436150 and https://generator.email/blog/gmail-generator
|
|
||||||
return user.replace(/[.]|(\+.*)/g, "") + "@gmail.com";
|
|
||||||
}
|
|
||||||
|
|
||||||
return email;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|
||||||
|
@ -1,47 +1,81 @@
|
|||||||
import { ChannelDeleteEvent, Channel, ChannelUpdateEvent, emitEvent, getPermission } from "@fosscord/util";
|
import {
|
||||||
import { Router, Response, Request } from "express";
|
Channel,
|
||||||
import { HTTPError } from "lambert-server";
|
ChannelDeleteEvent,
|
||||||
import { ChannelModifySchema } from "../../../schema/Channel";
|
ChannelPermissionOverwriteType,
|
||||||
import { check } from "../../../util/instanceOf";
|
ChannelType,
|
||||||
|
ChannelUpdateEvent,
|
||||||
|
emitEvent,
|
||||||
|
Recipient,
|
||||||
|
handleFile
|
||||||
|
} from "@fosscord/util";
|
||||||
|
import { Request, Response, Router } from "express";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
// TODO: delete channel
|
// TODO: delete channel
|
||||||
// TODO: Get channel
|
// TODO: Get channel
|
||||||
|
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
router.get("/", route({ permission: "VIEW_CHANNEL" }), async (req: Request, res: Response) => {
|
||||||
const { channel_id } = req.params;
|
const { channel_id } = req.params;
|
||||||
|
|
||||||
const channel = await Channel.findOneOrFail({ id: channel_id });
|
const channel = await Channel.findOneOrFail({ id: channel_id });
|
||||||
|
|
||||||
const permission = await getPermission(req.user_id, channel.guild_id, channel_id);
|
|
||||||
permission.hasThrow("VIEW_CHANNEL");
|
|
||||||
|
|
||||||
return res.send(channel);
|
return res.send(channel);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.delete("/", async (req: Request, res: Response) => {
|
router.delete("/", route({ permission: "MANAGE_CHANNELS" }), async (req: Request, res: Response) => {
|
||||||
const { channel_id } = req.params;
|
const { channel_id } = req.params;
|
||||||
|
|
||||||
const channel = await Channel.findOneOrFail({ id: channel_id });
|
const channel = await Channel.findOneOrFail({ where: { id: channel_id }, relations: ["recipients"] });
|
||||||
|
|
||||||
const permission = await getPermission(req.user_id, channel?.guild_id, channel_id);
|
if (channel.type === ChannelType.DM) {
|
||||||
permission.hasThrow("MANAGE_CHANNELS");
|
const recipient = await Recipient.findOneOrFail({ where: { channel_id: channel_id, user_id: req.user_id } });
|
||||||
|
recipient.closed = true;
|
||||||
|
await Promise.all([
|
||||||
|
recipient.save(),
|
||||||
|
emitEvent({ event: "CHANNEL_DELETE", data: channel, user_id: req.user_id } as ChannelDeleteEvent)
|
||||||
|
]);
|
||||||
|
} else if (channel.type === ChannelType.GROUP_DM) {
|
||||||
|
await Channel.removeRecipientFromChannel(channel, req.user_id);
|
||||||
|
} else {
|
||||||
|
await Promise.all([
|
||||||
|
Channel.delete({ id: channel_id }),
|
||||||
|
emitEvent({ event: "CHANNEL_DELETE", data: channel, channel_id } as ChannelDeleteEvent)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Dm channel "close" not delete
|
res.send(channel);
|
||||||
const data = channel;
|
|
||||||
|
|
||||||
await emitEvent({ event: "CHANNEL_DELETE", data, channel_id } as ChannelDeleteEvent);
|
|
||||||
|
|
||||||
await Channel.delete({ id: channel_id });
|
|
||||||
|
|
||||||
res.send(data);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.patch("/", check(ChannelModifySchema), async (req: Request, res: Response) => {
|
export interface ChannelModifySchema {
|
||||||
|
/**
|
||||||
|
* @maxLength 100
|
||||||
|
*/
|
||||||
|
name?: string;
|
||||||
|
type?: ChannelType;
|
||||||
|
topic?: string;
|
||||||
|
icon?: string | null;
|
||||||
|
bitrate?: number;
|
||||||
|
user_limit?: number;
|
||||||
|
rate_limit_per_user?: number;
|
||||||
|
position?: number;
|
||||||
|
permission_overwrites?: {
|
||||||
|
id: string;
|
||||||
|
type: ChannelPermissionOverwriteType;
|
||||||
|
allow: bigint;
|
||||||
|
deny: bigint;
|
||||||
|
}[];
|
||||||
|
parent_id?: string;
|
||||||
|
id?: string; // is not used (only for guild create)
|
||||||
|
nsfw?: boolean;
|
||||||
|
rtc_region?: string;
|
||||||
|
default_auto_archive_duration?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
router.patch("/", route({ body: "ChannelModifySchema", permission: "MANAGE_CHANNELS" }), async (req: Request, res: Response) => {
|
||||||
var payload = req.body as ChannelModifySchema;
|
var payload = req.body as ChannelModifySchema;
|
||||||
const { channel_id } = req.params;
|
const { channel_id } = req.params;
|
||||||
|
if (payload.icon) payload.icon = await handleFile(`/channel-icons/${channel_id}`, payload.icon);
|
||||||
const permission = await getPermission(req.user_id, undefined, channel_id);
|
|
||||||
permission.hasThrow("MANAGE_CHANNELS");
|
|
||||||
|
|
||||||
const channel = await Channel.findOneOrFail({ id: channel_id });
|
const channel = await Channel.findOneOrFail({ id: channel_id });
|
||||||
channel.assign(payload);
|
channel.assign(payload);
|
||||||
|
@ -1,14 +1,25 @@
|
|||||||
import { Router, Request, Response } from "express";
|
import { Router, Request, Response } from "express";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { check } from "../../../util/instanceOf";
|
import { route } from "@fosscord/api";
|
||||||
import { random } from "../../../util/RandomInviteID";
|
import { random } from "@fosscord/api";
|
||||||
import { InviteCreateSchema } from "../../../schema/Invite";
|
|
||||||
import { getPermission, Channel, Invite, InviteCreateEvent, emitEvent, User, Guild, PublicInviteRelation } from "@fosscord/util";
|
import { getPermission, Channel, Invite, InviteCreateEvent, emitEvent, User, Guild, PublicInviteRelation } from "@fosscord/util";
|
||||||
import { isTextChannel } from "./messages";
|
import { isTextChannel } from "./messages";
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
router.post("/", check(InviteCreateSchema), async (req: Request, res: Response) => {
|
export interface InviteCreateSchema {
|
||||||
|
target_user_id?: string;
|
||||||
|
target_type?: string;
|
||||||
|
validate?: string; // ? what is this
|
||||||
|
max_age?: number;
|
||||||
|
max_uses?: number;
|
||||||
|
temporary?: boolean;
|
||||||
|
unique?: boolean;
|
||||||
|
target_user?: string;
|
||||||
|
target_user_type?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
router.post("/", route({ body: "InviteCreateSchema", permission: "CREATE_INSTANT_INVITE" }), async (req: Request, res: Response) => {
|
||||||
const { user_id } = req;
|
const { user_id } = req;
|
||||||
const { channel_id } = req.params;
|
const { channel_id } = req.params;
|
||||||
const channel = await Channel.findOneOrFail({ where: { id: channel_id }, select: ["id", "name", "type", "guild_id"] });
|
const channel = await Channel.findOneOrFail({ where: { id: channel_id }, select: ["id", "name", "type", "guild_id"] });
|
||||||
@ -19,23 +30,6 @@ router.post("/", check(InviteCreateSchema), async (req: Request, res: Response)
|
|||||||
}
|
}
|
||||||
const { guild_id } = channel;
|
const { guild_id } = channel;
|
||||||
|
|
||||||
const permission = await getPermission(user_id, guild_id, undefined, {
|
|
||||||
guild_select: [
|
|
||||||
"banner",
|
|
||||||
"description",
|
|
||||||
"features",
|
|
||||||
"icon",
|
|
||||||
"id",
|
|
||||||
"name",
|
|
||||||
"nsfw",
|
|
||||||
"nsfw_level",
|
|
||||||
"splash",
|
|
||||||
"vanity_url_code",
|
|
||||||
"verification_level"
|
|
||||||
] as (keyof Guild)[]
|
|
||||||
});
|
|
||||||
permission.hasThrow("CREATE_INSTANT_INVITE");
|
|
||||||
|
|
||||||
const expires_at = new Date(req.body.max_age * 1000 + Date.now());
|
const expires_at = new Date(req.body.max_age * 1000 + Date.now());
|
||||||
|
|
||||||
const invite = await new Invite({
|
const invite = await new Invite({
|
||||||
@ -52,14 +46,14 @@ router.post("/", check(InviteCreateSchema), async (req: Request, res: Response)
|
|||||||
}).save();
|
}).save();
|
||||||
const data = invite.toJSON();
|
const data = invite.toJSON();
|
||||||
data.inviter = await User.getPublicUser(req.user_id);
|
data.inviter = await User.getPublicUser(req.user_id);
|
||||||
data.guild = permission.cache.guild;
|
data.guild = await Guild.findOne({ id: guild_id });
|
||||||
data.channel = channel;
|
data.channel = channel;
|
||||||
|
|
||||||
await emitEvent({ event: "INVITE_CREATE", data, guild_id } as InviteCreateEvent);
|
await emitEvent({ event: "INVITE_CREATE", data, guild_id } as InviteCreateEvent);
|
||||||
res.status(201).send(data);
|
res.status(201).send(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
router.get("/", route({ permission: "MANAGE_CHANNELS" }), async (req: Request, res: Response) => {
|
||||||
const { user_id } = req;
|
const { user_id } = req;
|
||||||
const { channel_id } = req.params;
|
const { channel_id } = req.params;
|
||||||
const channel = await Channel.findOneOrFail({ id: channel_id });
|
const channel = await Channel.findOneOrFail({ id: channel_id });
|
||||||
@ -68,8 +62,6 @@ router.get("/", async (req: Request, res: Response) => {
|
|||||||
throw new HTTPError("This channel doesn't exist", 404);
|
throw new HTTPError("This channel doesn't exist", 404);
|
||||||
}
|
}
|
||||||
const { guild_id } = channel;
|
const { guild_id } = channel;
|
||||||
const permission = await getPermission(user_id, guild_id);
|
|
||||||
permission.hasThrow("MANAGE_CHANNELS");
|
|
||||||
|
|
||||||
const invites = await Invite.find({ where: { guild_id }, relations: PublicInviteRelation });
|
const invites = await Invite.find({ where: { guild_id }, relations: PublicInviteRelation });
|
||||||
|
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
import { emitEvent, getPermission, MessageAckEvent, ReadState } from "@fosscord/util";
|
import { emitEvent, getPermission, MessageAckEvent, ReadState } from "@fosscord/util";
|
||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
import { check } from "../../../../../util/instanceOf";
|
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
// TODO: check if message exists
|
// TODO: check if message exists
|
||||||
// TODO: send read state event to all channel members
|
// TODO: send read state event to all channel members
|
||||||
|
|
||||||
router.post("/", check({ $manual: Boolean, $mention_count: Number }), async (req: Request, res: Response) => {
|
export interface MessageAcknowledgeSchema {
|
||||||
|
manual?: boolean;
|
||||||
|
mention_count?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
router.post("/", route({ body: "MessageAcknowledgeSchema" }), async (req: Request, res: Response) => {
|
||||||
const { channel_id, message_id } = req.params;
|
const { channel_id, message_id } = req.params;
|
||||||
|
|
||||||
const permission = await getPermission(req.user_id, undefined, channel_id);
|
const permission = await getPermission(req.user_id, undefined, channel_id);
|
||||||
@ -22,7 +26,7 @@ router.post("/", check({ $manual: Boolean, $mention_count: Number }), async (req
|
|||||||
data: {
|
data: {
|
||||||
channel_id,
|
channel_id,
|
||||||
message_id,
|
message_id,
|
||||||
version: 496
|
version: 3763
|
||||||
}
|
}
|
||||||
} as MessageAckEvent);
|
} as MessageAckEvent);
|
||||||
|
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
import { Channel, emitEvent, getPermission, MessageDeleteEvent, Message, MessageUpdateEvent } from "@fosscord/util";
|
import { Channel, emitEvent, getPermission, MessageDeleteEvent, Message, MessageUpdateEvent } from "@fosscord/util";
|
||||||
import { Router, Response, Request } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
import { MessageCreateSchema } from "../../../../../schema/Message";
|
import { route } from "@fosscord/api";
|
||||||
import { check } from "../../../../../util/instanceOf";
|
import { handleMessage, postHandleMessage } from "@fosscord/api";
|
||||||
import { handleMessage, postHandleMessage } from "../../../../../util/Message";
|
import { MessageCreateSchema } from "../index";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
// TODO: message content/embed string length limit
|
||||||
|
|
||||||
router.patch("/", check(MessageCreateSchema), async (req: Request, res: Response) => {
|
router.patch("/", route({ body: "MessageCreateSchema", permission: "SEND_MESSAGES" }), async (req: Request, res: Response) => {
|
||||||
const { message_id, channel_id } = req.params;
|
const { message_id, channel_id } = req.params;
|
||||||
var body = req.body as MessageCreateSchema;
|
var body = req.body as MessageCreateSchema;
|
||||||
|
|
||||||
const message = await Message.findOneOrFail({ id: message_id, channel_id });
|
const message = await Message.findOneOrFail({ where: { id: message_id, channel_id }, relations: ["attachments"] });
|
||||||
|
|
||||||
const permissions = await getPermission(req.user_id, undefined, channel_id);
|
const permissions = await getPermission(req.user_id, undefined, channel_id);
|
||||||
|
|
||||||
@ -45,16 +46,17 @@ router.patch("/", check(MessageCreateSchema), async (req: Request, res: Response
|
|||||||
return res.json(message);
|
return res.json(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: delete attachments in message
|
// permission check only if deletes messagr from other user
|
||||||
|
router.delete("/", route({}), async (req: Request, res: Response) => {
|
||||||
router.delete("/", async (req: Request, res: Response) => {
|
|
||||||
const { message_id, channel_id } = req.params;
|
const { message_id, channel_id } = req.params;
|
||||||
|
|
||||||
const channel = await Channel.findOneOrFail({ id: channel_id });
|
const channel = await Channel.findOneOrFail({ id: channel_id });
|
||||||
const message = await Message.findOneOrFail({ id: message_id });
|
const message = await Message.findOneOrFail({ id: message_id });
|
||||||
|
|
||||||
|
if (message.author_id !== req.user_id) {
|
||||||
const permission = await getPermission(req.user_id, channel.guild_id, channel_id);
|
const permission = await getPermission(req.user_id, channel.guild_id, channel_id);
|
||||||
if (message.author_id !== req.user_id) permission.hasThrow("MANAGE_MESSAGES");
|
permission.hasThrow("MANAGE_MESSAGES");
|
||||||
|
}
|
||||||
|
|
||||||
await Message.delete({ id: message_id });
|
await Message.delete({ id: message_id });
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ import {
|
|||||||
PublicUserProjection,
|
PublicUserProjection,
|
||||||
User
|
User
|
||||||
} from "@fosscord/util";
|
} from "@fosscord/util";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
import { Router, Response, Request } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { In } from "typeorm";
|
import { In } from "typeorm";
|
||||||
@ -35,14 +36,11 @@ function getEmoji(emoji: string): PartialEmoji {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
router.delete("/", async (req: Request, res: Response) => {
|
router.delete("/", route({ permission: "MANAGE_MESSAGES" }), async (req: Request, res: Response) => {
|
||||||
const { message_id, channel_id } = req.params;
|
const { message_id, channel_id } = req.params;
|
||||||
|
|
||||||
const channel = await Channel.findOneOrFail({ id: channel_id });
|
const channel = await Channel.findOneOrFail({ id: channel_id });
|
||||||
|
|
||||||
const permissions = await getPermission(req.user_id, undefined, channel_id);
|
|
||||||
permissions.hasThrow("MANAGE_MESSAGES");
|
|
||||||
|
|
||||||
await Message.update({ id: message_id, channel_id }, { reactions: [] });
|
await Message.update({ id: message_id, channel_id }, { reactions: [] });
|
||||||
|
|
||||||
await emitEvent({
|
await emitEvent({
|
||||||
@ -58,13 +56,10 @@ router.delete("/", async (req: Request, res: Response) => {
|
|||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.delete("/:emoji", async (req: Request, res: Response) => {
|
router.delete("/:emoji", route({ permission: "MANAGE_MESSAGES" }), async (req: Request, res: Response) => {
|
||||||
const { message_id, channel_id } = req.params;
|
const { message_id, channel_id } = req.params;
|
||||||
const emoji = getEmoji(req.params.emoji);
|
const emoji = getEmoji(req.params.emoji);
|
||||||
|
|
||||||
const permissions = await getPermission(req.user_id, undefined, channel_id);
|
|
||||||
permissions.hasThrow("MANAGE_MESSAGES");
|
|
||||||
|
|
||||||
const message = await Message.findOneOrFail({ id: message_id, channel_id });
|
const message = await Message.findOneOrFail({ id: message_id, channel_id });
|
||||||
|
|
||||||
const already_added = message.reactions.find((x) => (x.emoji.id === emoji.id && emoji.id) || x.emoji.name === emoji.name);
|
const already_added = message.reactions.find((x) => (x.emoji.id === emoji.id && emoji.id) || x.emoji.name === emoji.name);
|
||||||
@ -88,7 +83,7 @@ router.delete("/:emoji", async (req: Request, res: Response) => {
|
|||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get("/:emoji", async (req: Request, res: Response) => {
|
router.get("/:emoji", route({ permission: "VIEW_CHANNEL" }), async (req: Request, res: Response) => {
|
||||||
const { message_id, channel_id } = req.params;
|
const { message_id, channel_id } = req.params;
|
||||||
const emoji = getEmoji(req.params.emoji);
|
const emoji = getEmoji(req.params.emoji);
|
||||||
|
|
||||||
@ -96,9 +91,6 @@ router.get("/:emoji", async (req: Request, res: Response) => {
|
|||||||
const reaction = message.reactions.find((x) => (x.emoji.id === emoji.id && emoji.id) || x.emoji.name === emoji.name);
|
const reaction = message.reactions.find((x) => (x.emoji.id === emoji.id && emoji.id) || x.emoji.name === emoji.name);
|
||||||
if (!reaction) throw new HTTPError("Reaction not found", 404);
|
if (!reaction) throw new HTTPError("Reaction not found", 404);
|
||||||
|
|
||||||
const permissions = await getPermission(req.user_id, undefined, channel_id);
|
|
||||||
permissions.hasThrow("VIEW_CHANNEL");
|
|
||||||
|
|
||||||
const users = await User.find({
|
const users = await User.find({
|
||||||
where: {
|
where: {
|
||||||
id: In(reaction.user_ids)
|
id: In(reaction.user_ids)
|
||||||
@ -109,7 +101,7 @@ router.get("/:emoji", async (req: Request, res: Response) => {
|
|||||||
res.json(users);
|
res.json(users);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.put("/:emoji/:user_id", async (req: Request, res: Response) => {
|
router.put("/:emoji/:user_id", route({ permission: "READ_MESSAGE_HISTORY" }), async (req: Request, res: Response) => {
|
||||||
const { message_id, channel_id, user_id } = req.params;
|
const { message_id, channel_id, user_id } = req.params;
|
||||||
if (user_id !== "@me") throw new HTTPError("Invalid user");
|
if (user_id !== "@me") throw new HTTPError("Invalid user");
|
||||||
const emoji = getEmoji(req.params.emoji);
|
const emoji = getEmoji(req.params.emoji);
|
||||||
@ -118,13 +110,11 @@ router.put("/:emoji/:user_id", async (req: Request, res: Response) => {
|
|||||||
const message = await Message.findOneOrFail({ id: message_id, channel_id });
|
const message = await Message.findOneOrFail({ id: message_id, channel_id });
|
||||||
const already_added = message.reactions.find((x) => (x.emoji.id === emoji.id && emoji.id) || x.emoji.name === emoji.name);
|
const already_added = message.reactions.find((x) => (x.emoji.id === emoji.id && emoji.id) || x.emoji.name === emoji.name);
|
||||||
|
|
||||||
const permissions = await getPermission(req.user_id, undefined, channel_id);
|
if (!already_added) req.permission!.hasThrow("ADD_REACTIONS");
|
||||||
permissions.hasThrow("READ_MESSAGE_HISTORY");
|
|
||||||
if (!already_added) permissions.hasThrow("ADD_REACTIONS");
|
|
||||||
|
|
||||||
if (emoji.id) {
|
if (emoji.id) {
|
||||||
const external_emoji = await Emoji.findOneOrFail({ id: emoji.id });
|
const external_emoji = await Emoji.findOneOrFail({ id: emoji.id });
|
||||||
if (!already_added) permissions.hasThrow("USE_EXTERNAL_EMOJIS");
|
if (!already_added) req.permission!.hasThrow("USE_EXTERNAL_EMOJIS");
|
||||||
emoji.animated = external_emoji.animated;
|
emoji.animated = external_emoji.animated;
|
||||||
emoji.name = external_emoji.name;
|
emoji.name = external_emoji.name;
|
||||||
}
|
}
|
||||||
@ -154,7 +144,7 @@ router.put("/:emoji/:user_id", async (req: Request, res: Response) => {
|
|||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.delete("/:emoji/:user_id", async (req: Request, res: Response) => {
|
router.delete("/:emoji/:user_id", route({}), async (req: Request, res: Response) => {
|
||||||
var { message_id, channel_id, user_id } = req.params;
|
var { message_id, channel_id, user_id } = req.params;
|
||||||
|
|
||||||
const emoji = getEmoji(req.params.emoji);
|
const emoji = getEmoji(req.params.emoji);
|
||||||
@ -162,10 +152,11 @@ router.delete("/:emoji/:user_id", async (req: Request, res: Response) => {
|
|||||||
const channel = await Channel.findOneOrFail({ id: channel_id });
|
const channel = await Channel.findOneOrFail({ id: channel_id });
|
||||||
const message = await Message.findOneOrFail({ id: message_id, channel_id });
|
const message = await Message.findOneOrFail({ id: message_id, channel_id });
|
||||||
|
|
||||||
const permissions = await getPermission(req.user_id, undefined, channel_id);
|
|
||||||
|
|
||||||
if (user_id === "@me") user_id = req.user_id;
|
if (user_id === "@me") user_id = req.user_id;
|
||||||
else permissions.hasThrow("MANAGE_MESSAGES");
|
else {
|
||||||
|
const permissions = await getPermission(req.user_id, undefined, channel_id);
|
||||||
|
permissions.hasThrow("MANAGE_MESSAGES");
|
||||||
|
}
|
||||||
|
|
||||||
const already_added = message.reactions.find((x) => (x.emoji.id === emoji.id && emoji.id) || x.emoji.name === emoji.name);
|
const already_added = message.reactions.find((x) => (x.emoji.id === emoji.id && emoji.id) || x.emoji.name === emoji.name);
|
||||||
if (!already_added || !already_added.user_ids.includes(user_id)) throw new HTTPError("Reaction not found", 404);
|
if (!already_added || !already_added.user_ids.includes(user_id)) throw new HTTPError("Reaction not found", 404);
|
||||||
|
@ -1,18 +1,21 @@
|
|||||||
import { Router, Response, Request } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
import { Channel, Config, emitEvent, getPermission, MessageDeleteBulkEvent, Message } from "@fosscord/util";
|
import { Channel, Config, emitEvent, getPermission, MessageDeleteBulkEvent, Message } from "@fosscord/util";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
import { check } from "../../../../util/instanceOf";
|
|
||||||
import { In } from "typeorm";
|
import { In } from "typeorm";
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|
||||||
|
export interface BulkDeleteSchema {
|
||||||
|
messages: string[];
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: should users be able to bulk delete messages or only bots?
|
// TODO: should users be able to bulk delete messages or only bots?
|
||||||
// TODO: should this request fail, if you provide messages older than 14 days/invalid ids?
|
// TODO: should this request fail, if you provide messages older than 14 days/invalid ids?
|
||||||
// https://discord.com/developers/docs/resources/channel#bulk-delete-messages
|
// https://discord.com/developers/docs/resources/channel#bulk-delete-messages
|
||||||
router.post("/", check({ messages: [String] }), async (req: Request, res: Response) => {
|
router.post("/", route({ body: "BulkDeleteSchema" }), async (req: Request, res: Response) => {
|
||||||
const { channel_id } = req.params;
|
const { channel_id } = req.params;
|
||||||
const channel = await Channel.findOneOrFail({ id: channel_id });
|
const channel = await Channel.findOneOrFail({ id: channel_id });
|
||||||
if (!channel.guild_id) throw new HTTPError("Can't bulk delete dm channel messages", 400);
|
if (!channel.guild_id) throw new HTTPError("Can't bulk delete dm channel messages", 400);
|
||||||
|
@ -1,12 +1,19 @@
|
|||||||
import { Router, Response, Request } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
import { Attachment, Channel, ChannelType, getPermission, Message } from "@fosscord/util";
|
import {
|
||||||
|
Attachment,
|
||||||
|
Channel,
|
||||||
|
ChannelType,
|
||||||
|
DmChannelDTO,
|
||||||
|
Embed,
|
||||||
|
emitEvent,
|
||||||
|
getPermission,
|
||||||
|
Message,
|
||||||
|
MessageCreateEvent,
|
||||||
|
uploadFile
|
||||||
|
} from "@fosscord/util";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { MessageCreateSchema } from "../../../../schema/Message";
|
import { handleMessage, postHandleMessage, route } from "@fosscord/api";
|
||||||
import { check, instanceOf, Length } from "../../../../util/instanceOf";
|
|
||||||
import multer from "multer";
|
import multer from "multer";
|
||||||
import { Query } from "mongoose";
|
|
||||||
import { sendMessage } from "../../../../util/Message";
|
|
||||||
import { uploadFile } from "../../../../util/cdn";
|
|
||||||
import { FindManyOptions, LessThan, MoreThan } from "typeorm";
|
import { FindManyOptions, LessThan, MoreThan } from "typeorm";
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
@ -31,6 +38,31 @@ export function isTextChannel(type: ChannelType): boolean {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface MessageCreateSchema {
|
||||||
|
content?: string;
|
||||||
|
nonce?: string;
|
||||||
|
tts?: boolean;
|
||||||
|
flags?: string;
|
||||||
|
embeds?: Embed[];
|
||||||
|
embed?: Embed;
|
||||||
|
// TODO: ^ embed is deprecated in favor of embeds (https://discord.com/developers/docs/resources/channel#message-object)
|
||||||
|
allowed_mentions?: {
|
||||||
|
parse?: string[];
|
||||||
|
roles?: string[];
|
||||||
|
users?: string[];
|
||||||
|
replied_user?: boolean;
|
||||||
|
};
|
||||||
|
message_reference?: {
|
||||||
|
message_id: string;
|
||||||
|
channel_id: string;
|
||||||
|
guild_id?: string;
|
||||||
|
fail_if_not_exists?: boolean;
|
||||||
|
};
|
||||||
|
payload_json?: string;
|
||||||
|
file?: any;
|
||||||
|
attachments?: any[]; //TODO we should create an interface for attachments
|
||||||
|
}
|
||||||
|
|
||||||
// https://discord.com/developers/docs/resources/channel#create-message
|
// https://discord.com/developers/docs/resources/channel#create-message
|
||||||
// get messages
|
// get messages
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
router.get("/", async (req: Request, res: Response) => {
|
||||||
@ -39,17 +71,12 @@ router.get("/", async (req: Request, res: Response) => {
|
|||||||
if (!channel) throw new HTTPError("Channel not found", 404);
|
if (!channel) throw new HTTPError("Channel not found", 404);
|
||||||
|
|
||||||
isTextChannel(channel.type);
|
isTextChannel(channel.type);
|
||||||
|
const around = req.query.around ? `${req.query.around}` : undefined;
|
||||||
|
const before = req.query.before ? `${req.query.before}` : undefined;
|
||||||
|
const after = req.query.after ? `${req.query.after}` : undefined;
|
||||||
|
const limit = Number(req.query.limit) || 50;
|
||||||
|
if (limit < 1 || limit > 100) throw new HTTPError("limit must be between 1 and 100");
|
||||||
|
|
||||||
try {
|
|
||||||
instanceOf({ $around: String, $after: String, $before: String, $limit: new Length(Number, 1, 100) }, req.query, {
|
|
||||||
path: "query",
|
|
||||||
req
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
return res.status(400).json({ code: 50035, message: "Invalid Query", success: false, errors: error });
|
|
||||||
}
|
|
||||||
var { around, after, before, limit }: { around?: string; after?: string; before?: string; limit?: number } = req.query;
|
|
||||||
if (!limit) limit = 50;
|
|
||||||
var halfLimit = Math.floor(limit / 2);
|
var halfLimit = Math.floor(limit / 2);
|
||||||
|
|
||||||
const permissions = await getPermission(req.user_id, channel.guild_id, channel_id);
|
const permissions = await getPermission(req.user_id, channel.guild_id, channel_id);
|
||||||
@ -109,30 +136,35 @@ const messageUpload = multer({
|
|||||||
// TODO: check allowed_mentions
|
// TODO: check allowed_mentions
|
||||||
|
|
||||||
// Send message
|
// Send message
|
||||||
router.post("/", messageUpload.single("file"), async (req: Request, res: Response) => {
|
router.post(
|
||||||
|
"/",
|
||||||
|
messageUpload.single("file"),
|
||||||
|
async (req, res, next) => {
|
||||||
|
if (req.body.payload_json) {
|
||||||
|
req.body = JSON.parse(req.body.payload_json);
|
||||||
|
}
|
||||||
|
|
||||||
|
next();
|
||||||
|
},
|
||||||
|
route({ body: "MessageCreateSchema", permission: "SEND_MESSAGES" }),
|
||||||
|
async (req: Request, res: Response) => {
|
||||||
const { channel_id } = req.params;
|
const { channel_id } = req.params;
|
||||||
var body = req.body as MessageCreateSchema;
|
var body = req.body as MessageCreateSchema;
|
||||||
const attachments: Attachment[] = [];
|
const attachments: Attachment[] = [];
|
||||||
|
|
||||||
if (req.file) {
|
if (req.file) {
|
||||||
try {
|
try {
|
||||||
const file = await uploadFile(`/attachments/${channel_id}`, req.file);
|
const file = await uploadFile(`/attachments/${req.params.channel_id}`, req.file);
|
||||||
attachments.push({ ...file, proxy_url: file.url });
|
attachments.push({ ...file, proxy_url: file.url });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return res.status(400).json(error);
|
return res.status(400).json(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const channel = await Channel.findOneOrFail({ where: { id: channel_id }, relations: ["recipients", "recipients.user"] });
|
||||||
if (body.payload_json) {
|
|
||||||
body = JSON.parse(body.payload_json);
|
|
||||||
}
|
|
||||||
|
|
||||||
const errors = instanceOf(MessageCreateSchema, body, { req });
|
|
||||||
if (errors !== true) throw errors;
|
|
||||||
|
|
||||||
const embeds = [];
|
const embeds = [];
|
||||||
if (body.embed) embeds.push(body.embed);
|
if (body.embed) embeds.push(body.embed);
|
||||||
const data = await sendMessage({
|
let message = await handleMessage({
|
||||||
...body,
|
...body,
|
||||||
type: 0,
|
type: 0,
|
||||||
pinned: false,
|
pinned: false,
|
||||||
@ -140,8 +172,41 @@ router.post("/", messageUpload.single("file"), async (req: Request, res: Respons
|
|||||||
embeds,
|
embeds,
|
||||||
channel_id,
|
channel_id,
|
||||||
attachments,
|
attachments,
|
||||||
edited_timestamp: undefined
|
edited_timestamp: undefined,
|
||||||
|
timestamp: new Date()
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.json(data);
|
message = await message.save();
|
||||||
});
|
|
||||||
|
await channel.assign({ last_message_id: message.id }).save();
|
||||||
|
|
||||||
|
if (channel.isDm()) {
|
||||||
|
const channel_dto = await DmChannelDTO.from(channel);
|
||||||
|
|
||||||
|
for (let recipient of channel.recipients!) {
|
||||||
|
if (recipient.closed) {
|
||||||
|
await emitEvent({
|
||||||
|
event: "CHANNEL_CREATE",
|
||||||
|
data: channel_dto.excludedRecipients([recipient.user_id]),
|
||||||
|
user_id: recipient.user_id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Only one recipients should be closed here, since in group DMs the recipient is deleted not closed
|
||||||
|
await Promise.all(
|
||||||
|
channel
|
||||||
|
.recipients!.filter((r) => r.closed)
|
||||||
|
.map(async (r) => {
|
||||||
|
r.closed = false;
|
||||||
|
return await r.save();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await emitEvent({ event: "MESSAGE_CREATE", channel_id: channel_id, data: message } as MessageCreateEvent);
|
||||||
|
postHandleMessage(message).catch((e) => {}); // no await as it shouldnt block the message send function and silently catch error
|
||||||
|
|
||||||
|
return res.json(message);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
@ -2,21 +2,23 @@ import { Channel, ChannelPermissionOverwrite, ChannelUpdateEvent, emitEvent, get
|
|||||||
import { Router, Response, Request } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
|
|
||||||
import { check } from "../../../util/instanceOf";
|
import { route } from "@fosscord/api";
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
// TODO: Only permissions your bot has in the guild or channel can be allowed/denied (unless your bot has a MANAGE_ROLES overwrite in the channel)
|
// TODO: Only permissions your bot has in the guild or channel can be allowed/denied (unless your bot has a MANAGE_ROLES overwrite in the channel)
|
||||||
|
|
||||||
router.put("/:overwrite_id", check({ allow: String, deny: String, type: Number, id: String }), async (req: Request, res: Response) => {
|
export interface ChannelPermissionOverwriteSchema extends ChannelPermissionOverwrite {}
|
||||||
|
|
||||||
|
router.put(
|
||||||
|
"/:overwrite_id",
|
||||||
|
route({ body: "ChannelPermissionOverwriteSchema", permission: "MANAGE_ROLES" }),
|
||||||
|
async (req: Request, res: Response) => {
|
||||||
const { channel_id, overwrite_id } = req.params;
|
const { channel_id, overwrite_id } = req.params;
|
||||||
const body = req.body as { allow: bigint; deny: bigint; type: number; id: string };
|
const body = req.body as { allow: bigint; deny: bigint; type: number; id: string };
|
||||||
|
|
||||||
var channel = await Channel.findOneOrFail({ id: channel_id });
|
var channel = await Channel.findOneOrFail({ id: channel_id });
|
||||||
if (!channel.guild_id) throw new HTTPError("Channel not found", 404);
|
if (!channel.guild_id) throw new HTTPError("Channel not found", 404);
|
||||||
|
|
||||||
const permissions = await getPermission(req.user_id, channel.guild_id, channel_id);
|
|
||||||
permissions.hasThrow("MANAGE_ROLES");
|
|
||||||
|
|
||||||
if (body.type === 0) {
|
if (body.type === 0) {
|
||||||
if (!(await Role.count({ id: overwrite_id }))) throw new HTTPError("role not found", 404);
|
if (!(await Role.count({ id: overwrite_id }))) throw new HTTPError("role not found", 404);
|
||||||
} else if (body.type === 1) {
|
} else if (body.type === 1) {
|
||||||
@ -33,34 +35,32 @@ router.put("/:overwrite_id", check({ allow: String, deny: String, type: Number,
|
|||||||
allow: body.allow,
|
allow: body.allow,
|
||||||
deny: body.deny
|
deny: body.deny
|
||||||
};
|
};
|
||||||
channel.permission_overwrites.push(overwrite);
|
channel.permission_overwrites!.push(overwrite);
|
||||||
}
|
}
|
||||||
overwrite.allow = body.allow;
|
overwrite.allow = body.allow;
|
||||||
overwrite.deny = body.deny;
|
overwrite.deny = body.deny;
|
||||||
|
|
||||||
// @ts-ignore
|
await Promise.all([
|
||||||
channel = await Channel.findOneOrFailAndUpdate({ id: channel_id }, channel, { new: true });
|
channel.save(),
|
||||||
|
emitEvent({
|
||||||
await emitEvent({
|
|
||||||
event: "CHANNEL_UPDATE",
|
event: "CHANNEL_UPDATE",
|
||||||
channel_id,
|
channel_id,
|
||||||
data: channel
|
data: channel
|
||||||
} as ChannelUpdateEvent);
|
} as ChannelUpdateEvent)
|
||||||
|
]);
|
||||||
|
|
||||||
return res.sendStatus(204);
|
return res.sendStatus(204);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// TODO: check permission hierarchy
|
// TODO: check permission hierarchy
|
||||||
router.delete("/:overwrite_id", async (req: Request, res: Response) => {
|
router.delete("/:overwrite_id", route({ permission: "MANAGE_ROLES" }), async (req: Request, res: Response) => {
|
||||||
const { channel_id, overwrite_id } = req.params;
|
const { channel_id, overwrite_id } = req.params;
|
||||||
|
|
||||||
const permissions = await getPermission(req.user_id, undefined, channel_id);
|
|
||||||
permissions.hasThrow("MANAGE_ROLES");
|
|
||||||
|
|
||||||
const channel = await Channel.findOneOrFail({ id: channel_id });
|
const channel = await Channel.findOneOrFail({ id: channel_id });
|
||||||
if (!channel.guild_id) throw new HTTPError("Channel not found", 404);
|
if (!channel.guild_id) throw new HTTPError("Channel not found", 404);
|
||||||
|
|
||||||
channel.permission_overwrites = channel.permission_overwrites.filter((x) => x.id === overwrite_id);
|
channel.permission_overwrites = channel.permission_overwrites!.filter((x) => x.id === overwrite_id);
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
channel.save(),
|
channel.save(),
|
||||||
|
@ -1,19 +1,26 @@
|
|||||||
import { Channel, ChannelPinsUpdateEvent, Config, emitEvent, getPermission, Message, MessageUpdateEvent } from "@fosscord/util";
|
import {
|
||||||
|
Channel,
|
||||||
|
ChannelPinsUpdateEvent,
|
||||||
|
Config,
|
||||||
|
emitEvent,
|
||||||
|
getPermission,
|
||||||
|
Message,
|
||||||
|
MessageUpdateEvent,
|
||||||
|
DiscordApiErrors
|
||||||
|
} from "@fosscord/util";
|
||||||
import { Router, Request, Response } from "express";
|
import { Router, Request, Response } from "express";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { DiscordApiErrors } from "@fosscord/util";
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
router.put("/:message_id", async (req: Request, res: Response) => {
|
router.put("/:message_id", route({ permission: "VIEW_CHANNEL" }), async (req: Request, res: Response) => {
|
||||||
const { channel_id, message_id } = req.params;
|
const { channel_id, message_id } = req.params;
|
||||||
|
|
||||||
const message = await Message.findOneOrFail({ id: message_id });
|
const message = await Message.findOneOrFail({ id: message_id });
|
||||||
const permission = await getPermission(req.user_id, message.guild_id, channel_id);
|
|
||||||
permission.hasThrow("VIEW_CHANNEL");
|
|
||||||
|
|
||||||
// * in dm channels anyone can pin messages -> only check for guilds
|
// * in dm channels anyone can pin messages -> only check for guilds
|
||||||
if (message.guild_id) permission.hasThrow("MANAGE_MESSAGES");
|
if (message.guild_id) req.permission!.hasThrow("MANAGE_MESSAGES");
|
||||||
|
|
||||||
const pinned_count = await Message.count({ channel: { id: channel_id }, pinned: true });
|
const pinned_count = await Message.count({ channel: { id: channel_id }, pinned: true });
|
||||||
const { maxPins } = Config.get().limits.channel;
|
const { maxPins } = Config.get().limits.channel;
|
||||||
@ -26,7 +33,6 @@ router.put("/:message_id", async (req: Request, res: Response) => {
|
|||||||
channel_id,
|
channel_id,
|
||||||
data: message
|
data: message
|
||||||
} as MessageUpdateEvent),
|
} as MessageUpdateEvent),
|
||||||
|
|
||||||
emitEvent({
|
emitEvent({
|
||||||
event: "CHANNEL_PINS_UPDATE",
|
event: "CHANNEL_PINS_UPDATE",
|
||||||
channel_id,
|
channel_id,
|
||||||
@ -41,14 +47,11 @@ router.put("/:message_id", async (req: Request, res: Response) => {
|
|||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.delete("/:message_id", async (req: Request, res: Response) => {
|
router.delete("/:message_id", route({ permission: "VIEW_CHANNEL" }), async (req: Request, res: Response) => {
|
||||||
const { channel_id, message_id } = req.params;
|
const { channel_id, message_id } = req.params;
|
||||||
|
|
||||||
const channel = await Channel.findOneOrFail({ id: channel_id });
|
const channel = await Channel.findOneOrFail({ id: channel_id });
|
||||||
|
if (channel.guild_id) req.permission!.hasThrow("MANAGE_MESSAGES");
|
||||||
const permission = await getPermission(req.user_id, channel.guild_id, channel_id);
|
|
||||||
permission.hasThrow("VIEW_CHANNEL");
|
|
||||||
if (channel.guild_id) permission.hasThrow("MANAGE_MESSAGES");
|
|
||||||
|
|
||||||
const message = await Message.findOneOrFail({ id: message_id });
|
const message = await Message.findOneOrFail({ id: message_id });
|
||||||
message.pinned = false;
|
message.pinned = false;
|
||||||
@ -76,13 +79,9 @@ router.delete("/:message_id", async (req: Request, res: Response) => {
|
|||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
router.get("/", route({ permission: ["READ_MESSAGE_HISTORY"] }), async (req: Request, res: Response) => {
|
||||||
const { channel_id } = req.params;
|
const { channel_id } = req.params;
|
||||||
|
|
||||||
const channel = await Channel.findOneOrFail({ id: channel_id });
|
|
||||||
const permission = await getPermission(req.user_id, channel.guild_id, channel_id);
|
|
||||||
permission.hasThrow("VIEW_CHANNEL");
|
|
||||||
|
|
||||||
let pins = await Message.find({ channel_id: channel_id, pinned: true });
|
let pins = await Message.find({ channel_id: channel_id, pinned: true });
|
||||||
|
|
||||||
res.send(pins);
|
res.send(pins);
|
||||||
|
@ -1,5 +1,58 @@
|
|||||||
import { Router, Response, Request } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
|
import { Channel, ChannelRecipientAddEvent, ChannelType, DiscordApiErrors, DmChannelDTO, emitEvent, PublicUserProjection, Recipient, User } from "@fosscord/util";
|
||||||
|
import { route } from "@fosscord/api"
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
// TODO:
|
|
||||||
|
router.put("/:user_id", route({}), async (req: Request, res: Response) => {
|
||||||
|
const { channel_id, user_id } = req.params;
|
||||||
|
const channel = await Channel.findOneOrFail({ where: { id: channel_id }, relations: ["recipients"] });
|
||||||
|
|
||||||
|
if (channel.type !== ChannelType.GROUP_DM) {
|
||||||
|
const recipients = [
|
||||||
|
...channel.recipients!.map(r => r.user_id),
|
||||||
|
user_id
|
||||||
|
].unique()
|
||||||
|
|
||||||
|
const new_channel = await Channel.createDMChannel(recipients, req.user_id)
|
||||||
|
return res.status(201).json(new_channel);
|
||||||
|
} else {
|
||||||
|
if (channel.recipients!.map(r => r.user_id).includes(user_id)) {
|
||||||
|
throw DiscordApiErrors.INVALID_RECIPIENT //TODO is this the right error?
|
||||||
|
}
|
||||||
|
|
||||||
|
channel.recipients!.push(new Recipient({ channel_id: channel_id, user_id: user_id }));
|
||||||
|
await channel.save()
|
||||||
|
|
||||||
|
await emitEvent({
|
||||||
|
event: "CHANNEL_CREATE",
|
||||||
|
data: await DmChannelDTO.from(channel, [user_id]),
|
||||||
|
user_id: user_id
|
||||||
|
});
|
||||||
|
|
||||||
|
await emitEvent({
|
||||||
|
event: "CHANNEL_RECIPIENT_ADD", data: {
|
||||||
|
channel_id: channel_id,
|
||||||
|
user: await User.findOneOrFail({ where: { id: user_id }, select: PublicUserProjection })
|
||||||
|
}, channel_id: channel_id
|
||||||
|
} as ChannelRecipientAddEvent);
|
||||||
|
return res.sendStatus(204);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
router.delete("/:user_id", route({}), async (req: Request, res: Response) => {
|
||||||
|
const { channel_id, user_id } = req.params;
|
||||||
|
const channel = await Channel.findOneOrFail({ where: { id: channel_id }, relations: ["recipients"] });
|
||||||
|
if (!(channel.type === ChannelType.GROUP_DM && (channel.owner_id === req.user_id || user_id === req.user_id)))
|
||||||
|
throw DiscordApiErrors.MISSING_PERMISSIONS
|
||||||
|
|
||||||
|
if (!channel.recipients!.map(r => r.user_id).includes(user_id)) {
|
||||||
|
throw DiscordApiErrors.INVALID_RECIPIENT //TODO is this the right error?
|
||||||
|
}
|
||||||
|
|
||||||
|
await Channel.removeRecipientFromChannel(channel, user_id)
|
||||||
|
|
||||||
|
return res.sendStatus(204);
|
||||||
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@ -1,29 +1,29 @@
|
|||||||
import { Channel, emitEvent, Member, TypingStartEvent } from "@fosscord/util";
|
import { Channel, emitEvent, Member, TypingStartEvent } from "@fosscord/util";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
import { Router, Request, Response } from "express";
|
import { Router, Request, Response } from "express";
|
||||||
|
|
||||||
import { HTTPError } from "lambert-server";
|
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
router.post("/", async (req: Request, res: Response) => {
|
router.post("/", route({ permission: "SEND_MESSAGES" }), async (req: Request, res: Response) => {
|
||||||
const { channel_id } = req.params;
|
const { channel_id } = req.params;
|
||||||
const user_id = req.user_id;
|
const user_id = req.user_id;
|
||||||
const timestamp = Date.now();
|
const timestamp = Date.now();
|
||||||
const channel = await Channel.findOneOrFail({ id: channel_id });
|
const channel = await Channel.findOneOrFail({ id: channel_id });
|
||||||
const member = await Member.findOneOrFail({ id: user_id });
|
const member = await Member.findOneOrFail({ where: { id: user_id }, relations: ["roles"] });
|
||||||
|
|
||||||
await emitEvent({
|
await emitEvent({
|
||||||
event: "TYPING_START",
|
event: "TYPING_START",
|
||||||
channel_id: channel_id,
|
channel_id: channel_id,
|
||||||
data: {
|
data: {
|
||||||
// this is the paylod
|
// this is the paylod
|
||||||
member: { ...member, roles: member.roles.map((x) => x.id) },
|
member: { ...member, roles: member.roles?.map((x) => x.id) },
|
||||||
channel_id,
|
channel_id,
|
||||||
timestamp,
|
timestamp,
|
||||||
user_id,
|
user_id,
|
||||||
guild_id: channel.guild_id
|
guild_id: channel.guild_id
|
||||||
}
|
}
|
||||||
} as TypingStartEvent);
|
} as TypingStartEvent);
|
||||||
|
|
||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Router, Response, Request } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
import { check, Length } from "../../../util/instanceOf";
|
import { route } from "@fosscord/api";
|
||||||
import { Channel, Config, getPermission, trimSpecial, Webhook } from "@fosscord/util";
|
import { Channel, Config, getPermission, trimSpecial, Webhook } from "@fosscord/util";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { isTextChannel } from "./messages/index";
|
import { isTextChannel } from "./messages/index";
|
||||||
@ -7,9 +7,16 @@ import { DiscordApiErrors } from "@fosscord/util";
|
|||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
// TODO: webhooks
|
// TODO: webhooks
|
||||||
|
export interface WebhookCreateSchema {
|
||||||
|
/**
|
||||||
|
* @maxLength 80
|
||||||
|
*/
|
||||||
|
name: string;
|
||||||
|
avatar: string;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: use Image Data Type for avatar instead of String
|
// TODO: use Image Data Type for avatar instead of String
|
||||||
router.post("/", check({ name: new Length(String, 1, 80), $avatar: String }), async (req: Request, res: Response) => {
|
router.post("/", route({ body: "WebhookCreateSchema", permission: "MANAGE_WEBHOOKS" }), async (req: Request, res: Response) => {
|
||||||
const channel_id = req.params.channel_id;
|
const channel_id = req.params.channel_id;
|
||||||
const channel = await Channel.findOneOrFail({ id: channel_id });
|
const channel = await Channel.findOneOrFail({ id: channel_id });
|
||||||
|
|
||||||
@ -20,12 +27,11 @@ router.post("/", check({ name: new Length(String, 1, 80), $avatar: String }), as
|
|||||||
const { maxWebhooks } = Config.get().limits.channel;
|
const { maxWebhooks } = Config.get().limits.channel;
|
||||||
if (webhook_count > maxWebhooks) throw DiscordApiErrors.MAXIMUM_WEBHOOKS.withParams(maxWebhooks);
|
if (webhook_count > maxWebhooks) throw DiscordApiErrors.MAXIMUM_WEBHOOKS.withParams(maxWebhooks);
|
||||||
|
|
||||||
const permission = await getPermission(req.user_id, channel.guild_id);
|
|
||||||
permission.hasThrow("MANAGE_WEBHOOKS");
|
|
||||||
|
|
||||||
var { avatar, name } = req.body as { name: string; avatar?: string };
|
var { avatar, name } = req.body as { name: string; avatar?: string };
|
||||||
name = trimSpecial(name);
|
name = trimSpecial(name);
|
||||||
if (name === "clyde") throw new HTTPError("Invalid name", 400);
|
if (name === "clyde") throw new HTTPError("Invalid name", 400);
|
||||||
|
|
||||||
|
// TODO: save webhook in database and send response
|
||||||
});
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { Guild } from "@fosscord/util";
|
import { Guild } from "@fosscord/util";
|
||||||
import { Router, Request, Response } from "express";
|
import { Router, Request, Response } from "express";
|
||||||
import { In } from "typeorm";
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
const { limit } = req.params;
|
const { limit } = req.params;
|
||||||
|
|
||||||
// ! this only works using SQL querys
|
// ! this only works using SQL querys
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import { Router, Response, Request } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", (req: Request, res: Response) => {
|
router.get("/", route({}), (req: Request, res: Response) => {
|
||||||
// TODO:
|
// TODO:
|
||||||
res.send({ fingerprint: "", assignments: [] });
|
res.send({ fingerprint: "", assignments: [] });
|
||||||
});
|
});
|
||||||
|
@ -1,11 +1,26 @@
|
|||||||
import { Config } from "@fosscord/util";
|
import { Config } from "@fosscord/util";
|
||||||
import { Router, Response, Request } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", (req: Request, res: Response) => {
|
router.get("/", route({}), (req: Request, res: Response) => {
|
||||||
const { endpoint } = Config.get().gateway;
|
const { endpoint } = Config.get().gateway;
|
||||||
res.json({ url: endpoint || process.env.GATEWAY || "ws://localhost:3002" });
|
res.json({ url: endpoint || process.env.GATEWAY || "ws://localhost:3002" });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get("/bot", route({}), (req: Request, res: Response) => {
|
||||||
|
const { endpoint } = Config.get().gateway;
|
||||||
|
res.json({
|
||||||
|
url: endpoint || process.env.GATEWAY || "ws://localhost:3002",
|
||||||
|
shards: 1,
|
||||||
|
session_start_limit: {
|
||||||
|
total: 1000,
|
||||||
|
remaining: 999,
|
||||||
|
reset_after: 14400000,
|
||||||
|
max_concurrency: 1
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@ -1,20 +1,22 @@
|
|||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
import { emitEvent, getPermission, GuildBanAddEvent, GuildBanRemoveEvent, Guild, Ban, User, Member } from "@fosscord/util";
|
import { emitEvent, getPermission, GuildBanAddEvent, GuildBanRemoveEvent, Guild, Ban, User, Member } from "@fosscord/util";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { getIpAdress } from "../../../util/ipAddress";
|
import { getIpAdress, route } from "@fosscord/api";
|
||||||
import { BanCreateSchema } from "../../../schema/Ban";
|
|
||||||
import { check } from "../../../util/instanceOf";
|
export interface BanCreateSchema {
|
||||||
|
delete_message_days?: string;
|
||||||
|
reason?: string;
|
||||||
|
}
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
router.get("/", route({ permission: "BAN_MEMBERS" }), async (req: Request, res: Response) => {
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
|
|
||||||
var bans = await Ban.find({ guild_id: guild_id });
|
var bans = await Ban.find({ guild_id: guild_id });
|
||||||
return res.json(bans);
|
return res.json(bans);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get("/:user", async (req: Request, res: Response) => {
|
router.get("/:user", route({ permission: "BAN_MEMBERS" }), async (req: Request, res: Response) => {
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
const user_id = req.params.ban;
|
const user_id = req.params.ban;
|
||||||
|
|
||||||
@ -22,15 +24,14 @@ router.get("/:user", async (req: Request, res: Response) => {
|
|||||||
return res.json(ban);
|
return res.json(ban);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.put("/:user_id", check(BanCreateSchema), async (req: Request, res: Response) => {
|
router.put("/:user_id", route({ body: "BanCreateSchema", permission: "BAN_MEMBERS" }), async (req: Request, res: Response) => {
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
const banned_user_id = req.params.user_id;
|
const banned_user_id = req.params.user_id;
|
||||||
|
|
||||||
const banned_user = await User.getPublicUser(banned_user_id);
|
const banned_user = await User.getPublicUser(banned_user_id);
|
||||||
const perms = await getPermission(req.user_id, guild_id);
|
|
||||||
perms.hasThrow("BAN_MEMBERS");
|
|
||||||
if (req.user_id === banned_user_id) throw new HTTPError("You can't ban yourself", 400);
|
if (req.user_id === banned_user_id) throw new HTTPError("You can't ban yourself", 400);
|
||||||
if (perms.cache.guild?.owner_id === banned_user_id) throw new HTTPError("You can't ban the owner", 400);
|
if (req.permission!.cache.guild?.owner_id === banned_user_id) throw new HTTPError("You can't ban the owner", 400);
|
||||||
|
|
||||||
const ban = new Ban({
|
const ban = new Ban({
|
||||||
user_id: banned_user_id,
|
user_id: banned_user_id,
|
||||||
@ -56,17 +57,14 @@ router.put("/:user_id", check(BanCreateSchema), async (req: Request, res: Respon
|
|||||||
return res.json(ban);
|
return res.json(ban);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.delete("/:user_id", async (req: Request, res: Response) => {
|
router.delete("/:user_id", route({ permission: "BAN_MEMBERS" }), async (req: Request, res: Response) => {
|
||||||
var { guild_id } = req.params;
|
const { guild_id, user_id } = req.params;
|
||||||
var banned_user_id = req.params.user_id;
|
|
||||||
|
|
||||||
const banned_user = await User.getPublicUser(banned_user_id);
|
const banned_user = await User.getPublicUser(user_id);
|
||||||
const perms = await getPermission(req.user_id, guild_id);
|
|
||||||
perms.hasThrow("BAN_MEMBERS");
|
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
Ban.delete({
|
Ban.delete({
|
||||||
user_id: banned_user_id,
|
user_id: user_id,
|
||||||
guild_id
|
guild_id
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
@ -1,22 +1,18 @@
|
|||||||
import { Router, Response, Request } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
import { Channel, ChannelUpdateEvent, getPermission, emitEvent } from "@fosscord/util";
|
import { Channel, ChannelUpdateEvent, getPermission, emitEvent } from "@fosscord/util";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { ChannelModifySchema } from "../../../schema/Channel";
|
import { route } from "@fosscord/api";
|
||||||
|
import { ChannelModifySchema } from "../../channels/#channel_id";
|
||||||
import { check } from "../../../util/instanceOf";
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
const channels = await Channel.find({ guild_id });
|
const channels = await Channel.find({ guild_id });
|
||||||
|
|
||||||
res.json(channels);
|
res.json(channels);
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: check if channel type is permitted
|
router.post("/", route({ body: "ChannelModifySchema", permission: "MANAGE_CHANNELS" }), async (req: Request, res: Response) => {
|
||||||
// TODO: check if parent_id exists
|
|
||||||
|
|
||||||
router.post("/", check(ChannelModifySchema), async (req: Request, res: Response) => {
|
|
||||||
// creates a new guild channel https://discord.com/developers/docs/resources/guild#create-guild-channel
|
// creates a new guild channel https://discord.com/developers/docs/resources/guild#create-guild-channel
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
const body = req.body as ChannelModifySchema;
|
const body = req.body as ChannelModifySchema;
|
||||||
@ -26,17 +22,12 @@ router.post("/", check(ChannelModifySchema), async (req: Request, res: Response)
|
|||||||
res.status(201).json(channel);
|
res.status(201).json(channel);
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: check if parent_id exists
|
export type ChannelReorderSchema = { id: string; position?: number; lock_permissions?: boolean; parent_id?: string }[];
|
||||||
router.patch(
|
|
||||||
"/",
|
router.patch("/", route({ body: "ChannelReorderSchema", permission: "MANAGE_CHANNELS" }), async (req: Request, res: Response) => {
|
||||||
check([{ id: String, $position: Number, $lock_permissions: Boolean, $parent_id: String }]),
|
|
||||||
async (req: Request, res: Response) => {
|
|
||||||
// changes guild channel position
|
// changes guild channel position
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
const body = req.body as { id: string; position?: number; lock_permissions?: boolean; parent_id?: string }[];
|
const body = req.body as ChannelReorderSchema;
|
||||||
|
|
||||||
const permission = await getPermission(req.user_id, guild_id);
|
|
||||||
permission.hasThrow("MANAGE_CHANNELS");
|
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
body.map(async (x) => {
|
body.map(async (x) => {
|
||||||
@ -64,7 +55,6 @@ router.patch(
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@ -1,26 +1,20 @@
|
|||||||
import { Channel, emitEvent, GuildDeleteEvent, Guild, Member, Message, Role, Invite, Emoji } from "@fosscord/util";
|
import { Channel, emitEvent, GuildDeleteEvent, Guild, Member, Message, Role, Invite, Emoji } from "@fosscord/util";
|
||||||
import { Router, Request, Response } from "express";
|
import { Router, Request, Response } from "express";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
// discord prefixes this route with /delete instead of using the delete method
|
// discord prefixes this route with /delete instead of using the delete method
|
||||||
// docs are wrong https://discord.com/developers/docs/resources/guild#delete-guild
|
// docs are wrong https://discord.com/developers/docs/resources/guild#delete-guild
|
||||||
router.post("/", async (req: Request, res: Response) => {
|
router.post("/", route({}), async (req: Request, res: Response) => {
|
||||||
var { guild_id } = req.params;
|
var { guild_id } = req.params;
|
||||||
|
|
||||||
const guild = await Guild.findOneOrFail({ where: { id: guild_id }, select: ["owner_id"] });
|
const guild = await Guild.findOneOrFail({ where: { id: guild_id }, select: ["owner_id"] });
|
||||||
if (guild.owner_id !== req.user_id) throw new HTTPError("You are not the owner of this guild", 401);
|
if (guild.owner_id !== req.user_id) throw new HTTPError("You are not the owner of this guild", 401);
|
||||||
|
|
||||||
// do not put everything into promise all, because of "QueryFailedError: SQLITE_CONSTRAINT: FOREIGN KEY constraint failed"
|
|
||||||
|
|
||||||
await Message.delete({ guild_id }); // messages must be deleted before channel
|
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
Role.delete({ guild_id }),
|
Guild.delete({ id: guild_id }), // this will also delete all guild related data
|
||||||
Channel.delete({ guild_id }),
|
|
||||||
Emoji.delete({ guild_id }),
|
|
||||||
Member.delete({ guild_id }),
|
|
||||||
emitEvent({
|
emitEvent({
|
||||||
event: "GUILD_DELETE",
|
event: "GUILD_DELETE",
|
||||||
data: {
|
data: {
|
||||||
@ -30,9 +24,6 @@ router.post("/", async (req: Request, res: Response) => {
|
|||||||
} as GuildDeleteEvent)
|
} as GuildDeleteEvent)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
await Invite.delete({ guild_id }); // invite must be deleted after channel
|
|
||||||
await Guild.delete({ id: guild_id }); // guild must be deleted after everything else
|
|
||||||
|
|
||||||
return res.sendStatus(204);
|
return res.sendStatus(204);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,23 +1,35 @@
|
|||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
import { emitEvent, getPermission, Guild, GuildUpdateEvent, Member } from "@fosscord/util";
|
import { emitEvent, getPermission, Guild, GuildUpdateEvent, handleFile, Member } from "@fosscord/util";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { GuildUpdateSchema } from "../../../schema/Guild";
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
import { check } from "../../../util/instanceOf";
|
|
||||||
import { handleFile } from "../../../util/cdn";
|
|
||||||
import "missing-native-js-functions";
|
import "missing-native-js-functions";
|
||||||
|
import { GuildCreateSchema } from "../index";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
export interface GuildUpdateSchema extends Omit<GuildCreateSchema, "channels"> {
|
||||||
|
banner?: string | null;
|
||||||
|
splash?: string | null;
|
||||||
|
description?: string;
|
||||||
|
features?: string[];
|
||||||
|
verification_level?: number;
|
||||||
|
default_message_notifications?: number;
|
||||||
|
system_channel_flags?: number;
|
||||||
|
explicit_content_filter?: number;
|
||||||
|
public_updates_channel_id?: string;
|
||||||
|
afk_timeout?: number;
|
||||||
|
afk_channel_id?: string;
|
||||||
|
preferred_locale?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
|
|
||||||
const [guild, member_count, member] = await Promise.all([
|
const [guild, member] = await Promise.all([
|
||||||
Guild.findOneOrFail({ id: guild_id }),
|
Guild.findOneOrFail({ id: guild_id }),
|
||||||
Member.count({ guild_id: guild_id, id: req.user_id }),
|
Member.findOne({ guild_id: guild_id, id: req.user_id })
|
||||||
Member.findOneOrFail({ id: req.user_id })
|
|
||||||
]);
|
]);
|
||||||
if (!member_count) throw new HTTPError("You are not a member of the guild you are trying to access", 401);
|
if (!member) throw new HTTPError("You are not a member of the guild you are trying to access", 401);
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
guild.joined_at = member?.joined_at;
|
guild.joined_at = member?.joined_at;
|
||||||
@ -25,14 +37,11 @@ router.get("/", async (req: Request, res: Response) => {
|
|||||||
return res.json(guild);
|
return res.json(guild);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.patch("/", check(GuildUpdateSchema), async (req: Request, res: Response) => {
|
router.patch("/", route({ body: "GuildUpdateSchema", permission: "MANAGE_GUILD" }), async (req: Request, res: Response) => {
|
||||||
const body = req.body as GuildUpdateSchema;
|
const body = req.body as GuildUpdateSchema;
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
// TODO: guild update check image
|
// TODO: guild update check image
|
||||||
|
|
||||||
const perms = await getPermission(req.user_id, guild_id);
|
|
||||||
perms.hasThrow("MANAGE_GUILD");
|
|
||||||
|
|
||||||
if (body.icon) body.icon = await handleFile(`/icons/${guild_id}`, body.icon);
|
if (body.icon) body.icon = await handleFile(`/icons/${guild_id}`, body.icon);
|
||||||
if (body.banner) body.banner = await handleFile(`/banners/${guild_id}`, body.banner);
|
if (body.banner) body.banner = await handleFile(`/banners/${guild_id}`, body.banner);
|
||||||
if (body.splash) body.splash = await handleFile(`/splashes/${guild_id}`, body.splash);
|
if (body.splash) body.splash = await handleFile(`/splashes/${guild_id}`, body.splash);
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
import { getPermission, Invite, PublicInviteRelation } from "@fosscord/util";
|
import { getPermission, Invite, PublicInviteRelation } from "@fosscord/util";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
router.get("/", route({ permission: "MANAGE_GUILD" }), async (req: Request, res: Response) => {
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
|
|
||||||
const permissions = await getPermission(req.user_id, guild_id);
|
|
||||||
permissions.hasThrow("MANAGE_GUILD");
|
|
||||||
|
|
||||||
const invites = await Invite.find({ where: { guild_id }, relations: PublicInviteRelation });
|
const invites = await Invite.find({ where: { guild_id }, relations: PublicInviteRelation });
|
||||||
|
|
||||||
return res.json(invites);
|
return res.json(invites);
|
||||||
|
@ -1,23 +1,15 @@
|
|||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
import {
|
import { Member, getPermission, Role, GuildMemberUpdateEvent, emitEvent } from "@fosscord/util";
|
||||||
Guild,
|
|
||||||
Member,
|
|
||||||
User,
|
|
||||||
GuildMemberAddEvent,
|
|
||||||
getPermission,
|
|
||||||
PermissionResolvable,
|
|
||||||
Role,
|
|
||||||
GuildMemberUpdateEvent,
|
|
||||||
emitEvent
|
|
||||||
} from "@fosscord/util";
|
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { check } from "../../../../../util/instanceOf";
|
import { route } from "@fosscord/api";
|
||||||
import { MemberChangeSchema } from "../../../../../schema/Member";
|
|
||||||
import { In } from "typeorm";
|
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
export interface MemberChangeSchema {
|
||||||
|
roles?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
const { guild_id, member_id } = req.params;
|
const { guild_id, member_id } = req.params;
|
||||||
await Member.IsInGuildOrFail(req.user_id, guild_id);
|
await Member.IsInGuildOrFail(req.user_id, guild_id);
|
||||||
|
|
||||||
@ -26,8 +18,9 @@ router.get("/", async (req: Request, res: Response) => {
|
|||||||
return res.json(member);
|
return res.json(member);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.patch("/", check(MemberChangeSchema), async (req: Request, res: Response) => {
|
router.patch("/", route({ body: "MemberChangeSchema" }), async (req: Request, res: Response) => {
|
||||||
const { guild_id, member_id } = req.params;
|
let { guild_id, member_id } = req.params;
|
||||||
|
if (member_id === "@me") member_id = req.user_id;
|
||||||
const body = req.body as MemberChangeSchema;
|
const body = req.body as MemberChangeSchema;
|
||||||
|
|
||||||
const member = await Member.findOneOrFail({ where: { id: member_id, guild_id }, relations: ["roles", "user"] });
|
const member = await Member.findOneOrFail({ where: { id: member_id, guild_id }, relations: ["roles", "user"] });
|
||||||
@ -39,7 +32,7 @@ router.patch("/", check(MemberChangeSchema), async (req: Request, res: Response)
|
|||||||
}
|
}
|
||||||
|
|
||||||
await member.save();
|
await member.save();
|
||||||
// do not use promise.all as we have to first write to db before emitting the event
|
// do not use promise.all as we have to first write to db before emitting the event to catch errors
|
||||||
await emitEvent({
|
await emitEvent({
|
||||||
event: "GUILD_MEMBER_UPDATE",
|
event: "GUILD_MEMBER_UPDATE",
|
||||||
guild_id,
|
guild_id,
|
||||||
@ -49,7 +42,7 @@ router.patch("/", check(MemberChangeSchema), async (req: Request, res: Response)
|
|||||||
res.json(member);
|
res.json(member);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.put("/", async (req: Request, res: Response) => {
|
router.put("/", route({}), async (req: Request, res: Response) => {
|
||||||
let { guild_id, member_id } = req.params;
|
let { guild_id, member_id } = req.params;
|
||||||
if (member_id === "@me") member_id = req.user_id;
|
if (member_id === "@me") member_id = req.user_id;
|
||||||
|
|
||||||
@ -59,12 +52,9 @@ router.put("/", async (req: Request, res: Response) => {
|
|||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.delete("/", async (req: Request, res: Response) => {
|
router.delete("/", route({ permission: "KICK_MEMBERS" }), async (req: Request, res: Response) => {
|
||||||
const { guild_id, member_id } = req.params;
|
const { guild_id, member_id } = req.params;
|
||||||
|
|
||||||
const perms = await getPermission(req.user_id, guild_id);
|
|
||||||
perms.hasThrow("KICK_MEMBERS");
|
|
||||||
|
|
||||||
await Member.removeFromGuild(member_id, guild_id);
|
await Member.removeFromGuild(member_id, guild_id);
|
||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
});
|
});
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
import { getPermission, Member, PermissionResolvable } from "@fosscord/util";
|
import { getPermission, Member, PermissionResolvable } from "@fosscord/util";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
import { check } from "lambert-server";
|
|
||||||
import { MemberNickChangeSchema } from "../../../../../schema/Member";
|
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.patch("/", check(MemberNickChangeSchema), async (req: Request, res: Response) => {
|
export interface MemberNickChangeSchema {
|
||||||
|
nick: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
router.patch("/", route({ body: "MemberNickChangeSchema" }), async (req: Request, res: Response) => {
|
||||||
var { guild_id, member_id } = req.params;
|
var { guild_id, member_id } = req.params;
|
||||||
var permissionString: PermissionResolvable = "MANAGE_NICKNAMES";
|
var permissionString: PermissionResolvable = "MANAGE_NICKNAMES";
|
||||||
if (member_id === "@me") {
|
if (member_id === "@me") {
|
||||||
|
@ -1,24 +1,19 @@
|
|||||||
import { getPermission, Member } from "@fosscord/util";
|
import { getPermission, Member } from "@fosscord/util";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.delete("/:member_id/roles/:role_id", async (req: Request, res: Response) => {
|
router.delete("/", route({ permission: "MANAGE_ROLES" }), async (req: Request, res: Response) => {
|
||||||
const { guild_id, role_id, member_id } = req.params;
|
const { guild_id, role_id, member_id } = req.params;
|
||||||
|
|
||||||
const perms = await getPermission(req.user_id, guild_id);
|
|
||||||
perms.hasThrow("MANAGE_ROLES");
|
|
||||||
|
|
||||||
await Member.removeRole(member_id, guild_id, role_id);
|
await Member.removeRole(member_id, guild_id, role_id);
|
||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.put("/:member_id/roles/:role_id", async (req: Request, res: Response) => {
|
router.put("/", route({ permission: "MANAGE_ROLES" }), async (req: Request, res: Response) => {
|
||||||
const { guild_id, role_id, member_id } = req.params;
|
const { guild_id, role_id, member_id } = req.params;
|
||||||
|
|
||||||
const perms = await getPermission(req.user_id, guild_id);
|
|
||||||
perms.hasThrow("MANAGE_ROLES");
|
|
||||||
|
|
||||||
await Member.addRole(member_id, guild_id, role_id);
|
await Member.addRole(member_id, guild_id, role_id);
|
||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
});
|
});
|
||||||
|
@ -1,34 +1,28 @@
|
|||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
import { Guild, Member, PublicMemberProjection } from "@fosscord/util";
|
import { Guild, Member, PublicMemberProjection } from "@fosscord/util";
|
||||||
import { instanceOf, Length } from "../../../../util/instanceOf";
|
import { route } from "@fosscord/api";
|
||||||
import { MoreThan } from "typeorm";
|
import { MoreThan } from "typeorm";
|
||||||
|
import { HTTPError } from "lambert-server";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
// TODO: not allowed for user -> only allowed for bots with privileged intents
|
// TODO: not allowed for user -> only allowed for bots with privileged intents
|
||||||
// TODO: send over websocket
|
// TODO: send over websocket
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
// TODO: check for GUILD_MEMBERS intent
|
||||||
|
|
||||||
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
const guild = await Guild.findOneOrFail({ id: guild_id });
|
const limit = Number(req.query.limit) || 1;
|
||||||
await Member.IsInGuildOrFail(req.user_id, guild_id);
|
if (limit > 1000 || limit < 1) throw new HTTPError("Limit must be between 1 and 1000");
|
||||||
|
const after = `${req.query.after}`;
|
||||||
try {
|
|
||||||
instanceOf({ $limit: new Length(Number, 1, 1000), $after: String }, req.query, {
|
|
||||||
path: "query",
|
|
||||||
req,
|
|
||||||
ref: { obj: null, key: "" }
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
return res.status(400).json({ code: 50035, message: "Invalid Query", success: false, errors: error });
|
|
||||||
}
|
|
||||||
|
|
||||||
const { limit, after } = (<unknown>req.query) as { limit?: number; after?: string };
|
|
||||||
const query = after ? { id: MoreThan(after) } : {};
|
const query = after ? { id: MoreThan(after) } : {};
|
||||||
|
|
||||||
|
await Member.IsInGuildOrFail(req.user_id, guild_id);
|
||||||
|
|
||||||
const members = await Member.find({
|
const members = await Member.find({
|
||||||
where: { guild_id, ...query },
|
where: { guild_id, ...query },
|
||||||
select: PublicMemberProjection,
|
select: PublicMemberProjection,
|
||||||
take: limit || 1,
|
take: limit,
|
||||||
order: { id: "ASC" }
|
order: { id: "ASC" }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import {Config, Guild, Member} from "@fosscord/util";
|
import { Config, Guild, Member } from "@fosscord/util";
|
||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
import {getVoiceRegions} from "../../../util/Voice";
|
import { getVoiceRegions, route } from "@fosscord/api";
|
||||||
import {getIpAdress} from "../../../util/ipAddress";
|
import { getIpAdress } from "@fosscord/api";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
const guild = await Guild.findOneOrFail({ id: guild_id });
|
const guild = await Guild.findOneOrFail({ id: guild_id });
|
||||||
//TODO we should use an enum for guild's features and not hardcoded strings
|
//TODO we should use an enum for guild's features and not hardcoded strings
|
||||||
|
@ -2,24 +2,34 @@ import { Request, Response, Router } from "express";
|
|||||||
import {
|
import {
|
||||||
Role,
|
Role,
|
||||||
getPermission,
|
getPermission,
|
||||||
Snowflake,
|
|
||||||
Member,
|
Member,
|
||||||
GuildRoleCreateEvent,
|
GuildRoleCreateEvent,
|
||||||
GuildRoleUpdateEvent,
|
GuildRoleUpdateEvent,
|
||||||
GuildRoleDeleteEvent,
|
GuildRoleDeleteEvent,
|
||||||
emitEvent,
|
emitEvent,
|
||||||
Config
|
Config,
|
||||||
|
DiscordApiErrors
|
||||||
} from "@fosscord/util";
|
} from "@fosscord/util";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
import { check } from "../../../util/instanceOf";
|
|
||||||
import { RoleModifySchema, RolePositionUpdateSchema } from "../../../schema/Roles";
|
|
||||||
import { DiscordApiErrors } from "@fosscord/util";
|
|
||||||
import { In } from "typeorm";
|
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
export interface RoleModifySchema {
|
||||||
|
name?: string;
|
||||||
|
permissions?: bigint;
|
||||||
|
color?: number;
|
||||||
|
hoist?: boolean; // whether the role should be displayed separately in the sidebar
|
||||||
|
mentionable?: boolean; // whether the role should be mentionable
|
||||||
|
position?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type RolePositionUpdateSchema = {
|
||||||
|
id: string;
|
||||||
|
position: number;
|
||||||
|
}[];
|
||||||
|
|
||||||
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
const guild_id = req.params.guild_id;
|
const guild_id = req.params.guild_id;
|
||||||
|
|
||||||
await Member.IsInGuildOrFail(req.user_id, guild_id);
|
await Member.IsInGuildOrFail(req.user_id, guild_id);
|
||||||
@ -29,13 +39,10 @@ router.get("/", async (req: Request, res: Response) => {
|
|||||||
return res.json(roles);
|
return res.json(roles);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post("/", check(RoleModifySchema), async (req: Request, res: Response) => {
|
router.post("/", route({ body: "RoleModifySchema", permission: "MANAGE_ROLES" }), async (req: Request, res: Response) => {
|
||||||
const guild_id = req.params.guild_id;
|
const guild_id = req.params.guild_id;
|
||||||
const body = req.body as RoleModifySchema;
|
const body = req.body as RoleModifySchema;
|
||||||
|
|
||||||
const perms = await getPermission(req.user_id, guild_id);
|
|
||||||
perms.hasThrow("MANAGE_ROLES");
|
|
||||||
|
|
||||||
const role_count = await Role.count({ guild_id });
|
const role_count = await Role.count({ guild_id });
|
||||||
const { maxRoles } = Config.get().limits.guild;
|
const { maxRoles } = Config.get().limits.guild;
|
||||||
|
|
||||||
@ -50,7 +57,7 @@ router.post("/", check(RoleModifySchema), async (req: Request, res: Response) =>
|
|||||||
...body,
|
...body,
|
||||||
guild_id: guild_id,
|
guild_id: guild_id,
|
||||||
managed: false,
|
managed: false,
|
||||||
permissions: String(perms.bitfield & (body.permissions || 0n)),
|
permissions: String(req.permission!.bitfield & (body.permissions || 0n)),
|
||||||
tags: undefined
|
tags: undefined
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -69,14 +76,11 @@ router.post("/", check(RoleModifySchema), async (req: Request, res: Response) =>
|
|||||||
res.json(role);
|
res.json(role);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.delete("/:role_id", async (req: Request, res: Response) => {
|
router.delete("/:role_id", route({ permission: "MANAGE_ROLES" }), async (req: Request, res: Response) => {
|
||||||
const guild_id = req.params.guild_id;
|
const guild_id = req.params.guild_id;
|
||||||
const { role_id } = req.params;
|
const { role_id } = req.params;
|
||||||
if (role_id === guild_id) throw new HTTPError("You can't delete the @everyone role");
|
if (role_id === guild_id) throw new HTTPError("You can't delete the @everyone role");
|
||||||
|
|
||||||
const permissions = await getPermission(req.user_id, guild_id);
|
|
||||||
permissions.hasThrow("MANAGE_ROLES");
|
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
Role.delete({
|
Role.delete({
|
||||||
id: role_id,
|
id: role_id,
|
||||||
@ -97,14 +101,11 @@ router.delete("/:role_id", async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
// TODO: check role hierarchy
|
// TODO: check role hierarchy
|
||||||
|
|
||||||
router.patch("/:role_id", check(RoleModifySchema), async (req: Request, res: Response) => {
|
router.patch("/:role_id", route({ body: "RoleModifySchema", permission: "MANAGE_ROLES" }), async (req: Request, res: Response) => {
|
||||||
const { role_id, guild_id } = req.params;
|
const { role_id, guild_id } = req.params;
|
||||||
const body = req.body as RoleModifySchema;
|
const body = req.body as RoleModifySchema;
|
||||||
|
|
||||||
const perms = await getPermission(req.user_id, guild_id);
|
const role = new Role({ ...body, id: role_id, guild_id, permissions: String(req.permission!.bitfield & (body.permissions || 0n)) });
|
||||||
perms.hasThrow("MANAGE_ROLES");
|
|
||||||
|
|
||||||
const role = new Role({ ...body, id: role_id, guild_id, permissions: String(perms.bitfield & (body.permissions || 0n)) });
|
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
role.save(),
|
role.save(),
|
||||||
@ -121,7 +122,7 @@ router.patch("/:role_id", check(RoleModifySchema), async (req: Request, res: Res
|
|||||||
res.json(role);
|
res.json(role);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.patch("/", check(RolePositionUpdateSchema), async (req: Request, res: Response) => {
|
router.patch("/", route({ body: "RolePositionUpdateSchema" }), async (req: Request, res: Response) => {
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
const body = req.body as RolePositionUpdateSchema;
|
const body = req.body as RolePositionUpdateSchema;
|
||||||
|
|
||||||
@ -130,7 +131,7 @@ router.patch("/", check(RolePositionUpdateSchema), async (req: Request, res: Res
|
|||||||
|
|
||||||
await Promise.all(body.map(async (x) => Role.update({ guild_id, id: x.id }, { position: x.position })));
|
await Promise.all(body.map(async (x) => Role.update({ guild_id, id: x.id }, { position: x.position })));
|
||||||
|
|
||||||
const roles = await Role.find({ guild_id, id: In(body.map((x) => x.id)) });
|
const roles = await Role.find({ where: body.map((x) => ({ id: x.id, guild_id })) });
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
roles.map((x) =>
|
roles.map((x) =>
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
import { Guild, getPermission, Template } from "@fosscord/util";
|
import { Guild, Template } from "@fosscord/util";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { TemplateCreateSchema, TemplateModifySchema } from "../../../schema/Template";
|
import { route } from "@fosscord/api";
|
||||||
import { check } from "../../../util/instanceOf";
|
import { generateCode } from "@fosscord/api";
|
||||||
import { generateCode } from "../../../util/String";
|
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
@ -24,7 +23,17 @@ const TemplateGuildProjection: (keyof Guild)[] = [
|
|||||||
"icon"
|
"icon"
|
||||||
];
|
];
|
||||||
|
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
export interface TemplateCreateSchema {
|
||||||
|
name: string;
|
||||||
|
description?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TemplateModifySchema {
|
||||||
|
name: string;
|
||||||
|
description?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
|
|
||||||
var templates = await Template.find({ source_guild_id: guild_id });
|
var templates = await Template.find({ source_guild_id: guild_id });
|
||||||
@ -32,12 +41,9 @@ router.get("/", async (req: Request, res: Response) => {
|
|||||||
return res.json(templates);
|
return res.json(templates);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post("/", check(TemplateCreateSchema), async (req: Request, res: Response) => {
|
router.post("/", route({ body: "TemplateCreateSchema", permission: "MANAGE_GUILD" }), async (req: Request, res: Response) => {
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
const guild = await Guild.findOneOrFail({ where: { id: guild_id }, select: TemplateGuildProjection });
|
const guild = await Guild.findOneOrFail({ where: { id: guild_id }, select: TemplateGuildProjection });
|
||||||
const perms = await getPermission(req.user_id, guild_id);
|
|
||||||
perms.hasThrow("MANAGE_GUILD");
|
|
||||||
|
|
||||||
const exists = await Template.findOneOrFail({ id: guild_id }).catch((e) => {});
|
const exists = await Template.findOneOrFail({ id: guild_id }).catch((e) => {});
|
||||||
if (exists) throw new HTTPError("Template already exists", 400);
|
if (exists) throw new HTTPError("Template already exists", 400);
|
||||||
|
|
||||||
@ -54,44 +60,31 @@ router.post("/", check(TemplateCreateSchema), async (req: Request, res: Response
|
|||||||
res.json(template);
|
res.json(template);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.delete("/:code", async (req: Request, res: Response) => {
|
router.delete("/:code", route({ permission: "MANAGE_GUILD" }), async (req: Request, res: Response) => {
|
||||||
const guild_id = req.params.guild_id;
|
const { code, guild_id } = req.params;
|
||||||
const { code } = req.params;
|
|
||||||
|
|
||||||
const perms = await getPermission(req.user_id, guild_id);
|
|
||||||
perms.hasThrow("MANAGE_GUILD");
|
|
||||||
|
|
||||||
const template = await Template.delete({
|
const template = await Template.delete({
|
||||||
code
|
code,
|
||||||
|
source_guild_id: guild_id
|
||||||
});
|
});
|
||||||
|
|
||||||
res.json(template);
|
res.json(template);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.put("/:code", async (req: Request, res: Response) => {
|
router.put("/:code", route({ permission: "MANAGE_GUILD" }), async (req: Request, res: Response) => {
|
||||||
// synchronizes the template
|
|
||||||
const { code, guild_id } = req.params;
|
const { code, guild_id } = req.params;
|
||||||
|
|
||||||
const guild = await Guild.findOneOrFail({ where: { id: guild_id }, select: TemplateGuildProjection });
|
const guild = await Guild.findOneOrFail({ where: { id: guild_id }, select: TemplateGuildProjection });
|
||||||
|
|
||||||
const perms = await getPermission(req.user_id, guild_id);
|
|
||||||
perms.hasThrow("MANAGE_GUILD");
|
|
||||||
|
|
||||||
const template = await new Template({ code, serialized_source_guild: guild }).save();
|
const template = await new Template({ code, serialized_source_guild: guild }).save();
|
||||||
|
|
||||||
res.json(template);
|
res.json(template);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.patch("/:code", check(TemplateModifySchema), async (req: Request, res: Response) => {
|
router.patch("/:code", route({ body: "TemplateModifySchema", permission: "MANAGE_GUILD" }), async (req: Request, res: Response) => {
|
||||||
// updates the template description
|
const { code, guild_id } = req.params;
|
||||||
const { guild_id } = req.params;
|
|
||||||
const { code } = req.params;
|
|
||||||
const { name, description } = req.body;
|
const { name, description } = req.body;
|
||||||
|
|
||||||
const perms = await getPermission(req.user_id, guild_id);
|
const template = await new Template({ code, name: name, description: description, source_guild_id: guild_id }).save();
|
||||||
perms.hasThrow("MANAGE_GUILD");
|
|
||||||
|
|
||||||
const template = await new Template({ code, name: name, description: description }).save();
|
|
||||||
|
|
||||||
res.json(template);
|
res.json(template);
|
||||||
});
|
});
|
||||||
|
@ -1,40 +1,43 @@
|
|||||||
import { Channel, ChannelType, getPermission, Guild, Invite, trimSpecial } from "@fosscord/util";
|
import { Channel, ChannelType, getPermission, Guild, Invite, trimSpecial } from "@fosscord/util";
|
||||||
import { Router, Request, Response } from "express";
|
import { Router, Request, Response } from "express";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { check, Length } from "../../../util/instanceOf";
|
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
const InviteRegex = /\W/g;
|
const InviteRegex = /\W/g;
|
||||||
|
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
router.get("/", route({ permission: "MANAGE_GUILD" }), async (req: Request, res: Response) => {
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
|
|
||||||
const permission = await getPermission(req.user_id, guild_id);
|
|
||||||
permission.hasThrow("MANAGE_GUILD");
|
|
||||||
|
|
||||||
const guild = await Guild.findOneOrFail({ where: { id: guild_id }, relations: ["vanity_url"] });
|
const guild = await Guild.findOneOrFail({ where: { id: guild_id }, relations: ["vanity_url"] });
|
||||||
if (!guild.vanity_url) return res.json({ code: null });
|
if (!guild.vanity_url) return res.json({ code: null });
|
||||||
|
|
||||||
return res.json({ code: guild.vanity_url_code, uses: guild.vanity_url.uses });
|
return res.json({ code: guild.vanity_url_code, uses: guild.vanity_url.uses });
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: check if guild is elgible for vanity url
|
export interface VanityUrlSchema {
|
||||||
router.patch("/", check({ code: new Length(String, 0, 20) }), async (req: Request, res: Response) => {
|
/**
|
||||||
const { guild_id } = req.params;
|
* @minLength 1
|
||||||
const code = req.body.code.replace(InviteRegex);
|
* @maxLength 20
|
||||||
|
*/
|
||||||
|
code?: string;
|
||||||
|
}
|
||||||
|
|
||||||
await Invite.findOneOrFail({ code });
|
// TODO: check if guild is elgible for vanity url
|
||||||
|
router.patch("/", route({ body: "VanityUrlSchema", permission: "MANAGE_GUILD" }), async (req: Request, res: Response) => {
|
||||||
|
const { guild_id } = req.params;
|
||||||
|
const body = req.body as VanityUrlSchema;
|
||||||
|
const code = body.code?.replace(InviteRegex, "");
|
||||||
|
|
||||||
|
const invite = await Invite.findOne({ code });
|
||||||
|
if (invite) throw new HTTPError("Invite already exists");
|
||||||
|
|
||||||
const guild = await Guild.findOneOrFail({ id: guild_id });
|
const guild = await Guild.findOneOrFail({ id: guild_id });
|
||||||
const permission = await getPermission(req.user_id, guild_id);
|
|
||||||
permission.hasThrow("MANAGE_GUILD");
|
|
||||||
|
|
||||||
const { id } = await Channel.findOneOrFail({ guild_id, type: ChannelType.GUILD_TEXT });
|
const { id } = await Channel.findOneOrFail({ guild_id, type: ChannelType.GUILD_TEXT });
|
||||||
guild.vanity_url_code = code;
|
|
||||||
|
|
||||||
Promise.all([
|
Promise.all([
|
||||||
guild.save(),
|
Guild.update({ id: guild_id }, { vanity_url_code: code }),
|
||||||
Invite.delete({ code: guild.vanity_url_code }),
|
Invite.delete({ code: guild.vanity_url_code }),
|
||||||
new Invite({
|
new Invite({
|
||||||
code: code,
|
code: code,
|
||||||
|
@ -1,14 +1,59 @@
|
|||||||
import { check } from "../../../../../util/instanceOf";
|
import { Channel, ChannelType, DiscordApiErrors, emitEvent, getPermission, VoiceState, VoiceStateUpdateEvent } from "@fosscord/util";
|
||||||
import { VoiceStateUpdateSchema } from "../../../../../schema";
|
import { route } from "@fosscord/api";
|
||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
import { updateVoiceState } from "../../../../../util/VoiceState";
|
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
//TODO need more testing when community guild and voice stage channel are working
|
||||||
|
|
||||||
router.patch("/", check(VoiceStateUpdateSchema), async (req: Request, res: Response) => {
|
export interface VoiceStateUpdateSchema {
|
||||||
|
channel_id: string;
|
||||||
|
guild_id?: string;
|
||||||
|
suppress?: boolean;
|
||||||
|
request_to_speak_timestamp?: Date;
|
||||||
|
self_mute?: boolean;
|
||||||
|
self_deaf?: boolean;
|
||||||
|
self_video?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
router.patch("/", route({ body: "VoiceStateUpdateSchema" }), async (req: Request, res: Response) => {
|
||||||
const body = req.body as VoiceStateUpdateSchema;
|
const body = req.body as VoiceStateUpdateSchema;
|
||||||
const { guild_id, user_id } = req.params;
|
var { guild_id, user_id } = req.params;
|
||||||
await updateVoiceState(body, guild_id, req.user_id, user_id)
|
if (user_id === "@me") user_id = req.user_id;
|
||||||
|
|
||||||
|
const perms = await getPermission(req.user_id, guild_id, body.channel_id);
|
||||||
|
|
||||||
|
/*
|
||||||
|
From https://discord.com/developers/docs/resources/guild#modify-current-user-voice-state
|
||||||
|
You must have the MUTE_MEMBERS permission to unsuppress others. You can always suppress yourself.
|
||||||
|
You must have the REQUEST_TO_SPEAK permission to request to speak. You can always clear your own request to speak.
|
||||||
|
*/
|
||||||
|
if (body.suppress && user_id !== req.user_id) {
|
||||||
|
perms.hasThrow("MUTE_MEMBERS");
|
||||||
|
}
|
||||||
|
if (!body.suppress) body.request_to_speak_timestamp = new Date();
|
||||||
|
if (body.request_to_speak_timestamp) perms.hasThrow("REQUEST_TO_SPEAK");
|
||||||
|
|
||||||
|
const voice_state = await VoiceState.findOne({
|
||||||
|
guild_id,
|
||||||
|
channel_id: body.channel_id,
|
||||||
|
user_id
|
||||||
|
});
|
||||||
|
if (!voice_state) throw DiscordApiErrors.UNKNOWN_VOICE_STATE;
|
||||||
|
|
||||||
|
voice_state.assign(body);
|
||||||
|
const channel = await Channel.findOneOrFail({ guild_id, id: body.channel_id });
|
||||||
|
if (channel.type !== ChannelType.GUILD_STAGE_VOICE) {
|
||||||
|
throw DiscordApiErrors.CANNOT_EXECUTE_ON_THIS_CHANNEL_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
voice_state.save(),
|
||||||
|
emitEvent({
|
||||||
|
event: "VOICE_STATE_UPDATE",
|
||||||
|
data: voice_state,
|
||||||
|
guild_id
|
||||||
|
} as VoiceStateUpdateEvent)
|
||||||
|
]);
|
||||||
return res.sendStatus(204);
|
return res.sendStatus(204);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
import { check } from "../../../../../util/instanceOf";
|
|
||||||
import { VoiceStateUpdateSchema } from "../../../../../schema";
|
|
||||||
import { Request, Response, Router } from "express";
|
|
||||||
import { updateVoiceState } from "../../../../../util/VoiceState";
|
|
||||||
|
|
||||||
const router = Router();
|
|
||||||
|
|
||||||
router.patch("/", check(VoiceStateUpdateSchema), async (req: Request, res: Response) => {
|
|
||||||
const body = req.body as VoiceStateUpdateSchema;
|
|
||||||
const { guild_id } = req.params;
|
|
||||||
await updateVoiceState(body, guild_id, req.user_id)
|
|
||||||
return res.sendStatus(204);
|
|
||||||
});
|
|
||||||
|
|
||||||
export default router;
|
|
@ -1,31 +1,36 @@
|
|||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
import { Guild, getPermission, Snowflake, Member } from "@fosscord/util";
|
import { Guild, getPermission, Snowflake, Member } from "@fosscord/util";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
import { check } from "../../../util/instanceOf";
|
|
||||||
import { GuildUpdateWelcomeScreenSchema } from "../../../schema/Guild";
|
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
export interface GuildUpdateWelcomeScreenSchema {
|
||||||
|
welcome_channels?: {
|
||||||
|
channel_id: string;
|
||||||
|
description: string;
|
||||||
|
emoji_id?: string;
|
||||||
|
emoji_name: string;
|
||||||
|
}[];
|
||||||
|
enabled?: boolean;
|
||||||
|
description?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
const guild_id = req.params.guild_id;
|
const guild_id = req.params.guild_id;
|
||||||
|
|
||||||
const guild = await Guild.findOneOrFail({ id: guild_id });
|
const guild = await Guild.findOneOrFail({ id: guild_id });
|
||||||
|
|
||||||
await Member.IsInGuildOrFail(req.user_id, guild_id);
|
await Member.IsInGuildOrFail(req.user_id, guild_id);
|
||||||
|
|
||||||
res.json(guild.welcome_screen);
|
res.json(guild.welcome_screen);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.patch("/", check(GuildUpdateWelcomeScreenSchema), async (req: Request, res: Response) => {
|
router.patch("/", route({ body: "GuildUpdateWelcomeScreenSchema", permission: "MANAGE_GUILD" }), async (req: Request, res: Response) => {
|
||||||
const guild_id = req.params.guild_id;
|
const guild_id = req.params.guild_id;
|
||||||
const body = req.body as GuildUpdateWelcomeScreenSchema;
|
const body = req.body as GuildUpdateWelcomeScreenSchema;
|
||||||
|
|
||||||
const guild = await Guild.findOneOrFail({ id: guild_id });
|
const guild = await Guild.findOneOrFail({ id: guild_id });
|
||||||
|
|
||||||
const perms = await getPermission(req.user_id, guild_id);
|
|
||||||
perms.hasThrow("MANAGE_GUILD");
|
|
||||||
|
|
||||||
if (!guild.welcome_screen.enabled) throw new HTTPError("Welcome screen disabled", 400);
|
if (!guild.welcome_screen.enabled) throw new HTTPError("Welcome screen disabled", 400);
|
||||||
if (body.welcome_channels) guild.welcome_screen.welcome_channels = body.welcome_channels; // TODO: check if they exist and are valid
|
if (body.welcome_channels) guild.welcome_screen.welcome_channels = body.welcome_channels; // TODO: check if they exist and are valid
|
||||||
if (body.description) guild.welcome_screen.description = body.description;
|
if (body.description) guild.welcome_screen.description = body.description;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
import { Config, Permissions, Guild, Invite, Channel, Member } from "@fosscord/util";
|
import { Config, Permissions, Guild, Invite, Channel, Member } from "@fosscord/util";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { random } from "../../../util/RandomInviteID";
|
import { random, route } from "@fosscord/api";
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ const router: Router = Router();
|
|||||||
|
|
||||||
// https://discord.com/developers/docs/resources/guild#get-guild-widget
|
// https://discord.com/developers/docs/resources/guild#get-guild-widget
|
||||||
// TODO: Cache the response for a guild for 5 minutes regardless of response
|
// TODO: Cache the response for a guild for 5 minutes regardless of response
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
|
|
||||||
const guild = await Guild.findOneOrFail({ id: guild_id });
|
const guild = await Guild.findOneOrFail({ id: guild_id });
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
import { Guild } from "@fosscord/util";
|
import { Guild } from "@fosscord/util";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
@ -10,7 +11,7 @@ const router: Router = Router();
|
|||||||
|
|
||||||
// https://discord.com/developers/docs/resources/guild#get-guild-widget-image
|
// https://discord.com/developers/docs/resources/guild#get-guild-widget-image
|
||||||
// TODO: Cache the response
|
// TODO: Cache the response
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
|
|
||||||
const guild = await Guild.findOneOrFail({ id: guild_id });
|
const guild = await Guild.findOneOrFail({ id: guild_id });
|
||||||
|
@ -1,31 +1,28 @@
|
|||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
import { getPermission, Guild } from "@fosscord/util";
|
import { Guild } from "@fosscord/util";
|
||||||
import { HTTPError } from "lambert-server";
|
import { route } from "@fosscord/api";
|
||||||
import { check } from "../../../util/instanceOf";
|
|
||||||
import { WidgetModifySchema } from "../../../schema/Widget";
|
export interface WidgetModifySchema {
|
||||||
|
enabled: boolean; // whether the widget is enabled
|
||||||
|
channel_id: string; // the widget channel id
|
||||||
|
}
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
// https://discord.com/developers/docs/resources/guild#get-guild-widget-settings
|
// https://discord.com/developers/docs/resources/guild#get-guild-widget-settings
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
|
|
||||||
const perms = await getPermission(req.user_id, guild_id);
|
|
||||||
perms.hasThrow("MANAGE_GUILD");
|
|
||||||
|
|
||||||
const guild = await Guild.findOneOrFail({ id: guild_id });
|
const guild = await Guild.findOneOrFail({ id: guild_id });
|
||||||
|
|
||||||
return res.json({ enabled: guild.widget_enabled || false, channel_id: guild.widget_channel_id || null });
|
return res.json({ enabled: guild.widget_enabled || false, channel_id: guild.widget_channel_id || null });
|
||||||
});
|
});
|
||||||
|
|
||||||
// https://discord.com/developers/docs/resources/guild#modify-guild-widget
|
// https://discord.com/developers/docs/resources/guild#modify-guild-widget
|
||||||
router.patch("/", check(WidgetModifySchema), async (req: Request, res: Response) => {
|
router.patch("/", route({ body: "WidgetModifySchema", permission: "MANAGE_GUILD" }), async (req: Request, res: Response) => {
|
||||||
const body = req.body as WidgetModifySchema;
|
const body = req.body as WidgetModifySchema;
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
|
|
||||||
const perms = await getPermission(req.user_id, guild_id);
|
|
||||||
perms.hasThrow("MANAGE_GUILD");
|
|
||||||
|
|
||||||
await Guild.update({ id: guild_id }, { widget_enabled: body.enabled, widget_channel_id: body.channel_id });
|
await Guild.update({ id: guild_id }, { widget_enabled: body.enabled, widget_channel_id: body.channel_id });
|
||||||
// Widget invite for the widget_channel_id gets created as part of the /guilds/{guild.id}/widget.json request
|
// Widget invite for the widget_channel_id gets created as part of the /guilds/{guild.id}/widget.json request
|
||||||
|
|
||||||
|
@ -1,15 +1,26 @@
|
|||||||
import { Router, Request, Response } from "express";
|
import { Router, Request, Response } from "express";
|
||||||
import { Role, Guild, Snowflake, Config, User, Member, Channel } from "@fosscord/util";
|
import { Role, Guild, Snowflake, Config, Member, Channel, DiscordApiErrors, handleFile } from "@fosscord/util";
|
||||||
import { HTTPError } from "lambert-server";
|
import { route } from "@fosscord/api";
|
||||||
import { check } from "./../../util/instanceOf";
|
import { ChannelModifySchema } from "../channels/#channel_id";
|
||||||
import { GuildCreateSchema } from "../../schema/Guild";
|
|
||||||
import { DiscordApiErrors } from "@fosscord/util";
|
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
|
export interface GuildCreateSchema {
|
||||||
|
/**
|
||||||
|
* @maxLength 100
|
||||||
|
*/
|
||||||
|
name: string;
|
||||||
|
region?: string;
|
||||||
|
icon?: string | null;
|
||||||
|
channels?: ChannelModifySchema[];
|
||||||
|
guild_template_code?: string;
|
||||||
|
system_channel_id?: string;
|
||||||
|
rules_channel_id?: string;
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: create default channel
|
//TODO: create default channel
|
||||||
|
|
||||||
router.post("/", check(GuildCreateSchema), async (req: Request, res: Response) => {
|
router.post("/", route({ body: "GuildCreateSchema" }), async (req: Request, res: Response) => {
|
||||||
const body = req.body as GuildCreateSchema;
|
const body = req.body as GuildCreateSchema;
|
||||||
|
|
||||||
const { maxGuilds } = Config.get().limits.user;
|
const { maxGuilds } = Config.get().limits.user;
|
||||||
@ -22,6 +33,7 @@ router.post("/", check(GuildCreateSchema), async (req: Request, res: Response) =
|
|||||||
|
|
||||||
await Guild.insert({
|
await Guild.insert({
|
||||||
name: body.name,
|
name: body.name,
|
||||||
|
icon: await handleFile(`/icons/${guild_id}`, body.icon as string),
|
||||||
region: Config.get().regions.default,
|
region: Config.get().regions.default,
|
||||||
owner_id: req.user_id,
|
owner_id: req.user_id,
|
||||||
afk_timeout: 300,
|
afk_timeout: 300,
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
import { Template, Guild, Role, Snowflake, Config, User, Member } from "@fosscord/util";
|
import { Template, Guild, Role, Snowflake, Config, User, Member } from "@fosscord/util";
|
||||||
import { HTTPError } from "lambert-server";
|
import { route } from "@fosscord/api";
|
||||||
import { GuildTemplateCreateSchema } from "../../../schema/Guild";
|
|
||||||
import { check } from "../../../util/instanceOf";
|
|
||||||
import { DiscordApiErrors } from "@fosscord/util";
|
import { DiscordApiErrors } from "@fosscord/util";
|
||||||
|
|
||||||
router.get("/:code", async (req: Request, res: Response) => {
|
export interface GuildTemplateCreateSchema {
|
||||||
|
name: string;
|
||||||
|
avatar?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
router.get("/:code", route({}), async (req: Request, res: Response) => {
|
||||||
const { code } = req.params;
|
const { code } = req.params;
|
||||||
|
|
||||||
const template = await Template.findOneOrFail({ code: code });
|
const template = await Template.findOneOrFail({ code: code });
|
||||||
@ -14,7 +17,7 @@ router.get("/:code", async (req: Request, res: Response) => {
|
|||||||
res.json(template);
|
res.json(template);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post("/:code", check(GuildTemplateCreateSchema), async (req: Request, res: Response) => {
|
router.post("/:code", route({ body: "GuildTemplateCreateSchema" }), async (req: Request, res: Response) => {
|
||||||
const { code } = req.params;
|
const { code } = req.params;
|
||||||
const body = req.body as GuildTemplateCreateSchema;
|
const body = req.body as GuildTemplateCreateSchema;
|
||||||
|
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
import { Router, Request, Response } from "express";
|
import { Router, Request, Response } from "express";
|
||||||
import { getPermission, Guild, Invite, Member, PublicInviteRelation } from "@fosscord/util";
|
import { emitEvent, getPermission, Guild, Invite, InviteDeleteEvent, Member, PublicInviteRelation } from "@fosscord/util";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
router.get("/:code", async (req: Request, res: Response) => {
|
router.get("/:code", route({}), async (req: Request, res: Response) => {
|
||||||
const { code } = req.params;
|
const { code } = req.params;
|
||||||
|
|
||||||
const invite = await Invite.findOneOrFail({ where: { code }, relations: PublicInviteRelation });
|
const invite = await Invite.findOneOrFail({ where: { code }, relations: PublicInviteRelation });
|
||||||
@ -11,19 +13,15 @@ router.get("/:code", async (req: Request, res: Response) => {
|
|||||||
res.status(200).send(invite);
|
res.status(200).send(invite);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post("/:code", async (req: Request, res: Response) => {
|
router.post("/:code", route({}), async (req: Request, res: Response) => {
|
||||||
const { code } = req.params;
|
const { code } = req.params;
|
||||||
|
const invite = await Invite.joinGuild(req.user_id, code);
|
||||||
|
|
||||||
const invite = await Invite.findOneOrFail({ code });
|
res.json(invite);
|
||||||
if (invite.uses++ >= invite.max_uses) await Invite.delete({ code });
|
|
||||||
else await invite.save();
|
|
||||||
|
|
||||||
await Member.addToGuild(req.user_id, invite.guild_id);
|
|
||||||
|
|
||||||
res.status(200).send(invite);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.delete("/:code", async (req: Request, res: Response) => {
|
// * cant use permission of route() function because path doesn't have guild_id/channel_id
|
||||||
|
router.delete("/:code", route({}), async (req: Request, res: Response) => {
|
||||||
const { code } = req.params;
|
const { code } = req.params;
|
||||||
const invite = await Invite.findOneOrFail({ code });
|
const invite = await Invite.findOneOrFail({ code });
|
||||||
const { guild_id, channel_id } = invite;
|
const { guild_id, channel_id } = invite;
|
||||||
@ -33,7 +31,19 @@ router.delete("/:code", async (req: Request, res: Response) => {
|
|||||||
if (!permission.has("MANAGE_GUILD") && !permission.has("MANAGE_CHANNELS"))
|
if (!permission.has("MANAGE_GUILD") && !permission.has("MANAGE_CHANNELS"))
|
||||||
throw new HTTPError("You missing the MANAGE_GUILD or MANAGE_CHANNELS permission", 401);
|
throw new HTTPError("You missing the MANAGE_GUILD or MANAGE_CHANNELS permission", 401);
|
||||||
|
|
||||||
await Promise.all([Invite.delete({ code }), Guild.update({ vanity_url_code: code }, { vanity_url_code: undefined })]);
|
await Promise.all([
|
||||||
|
Invite.delete({ code }),
|
||||||
|
Guild.update({ vanity_url_code: code }, { vanity_url_code: undefined }),
|
||||||
|
emitEvent({
|
||||||
|
event: "INVITE_DELETE",
|
||||||
|
guild_id: guild_id,
|
||||||
|
data: {
|
||||||
|
channel_id: channel_id,
|
||||||
|
guild_id: guild_id,
|
||||||
|
code: code
|
||||||
|
}
|
||||||
|
} as InviteDeleteEvent)
|
||||||
|
]);
|
||||||
|
|
||||||
res.json({ invite: invite });
|
res.json({ invite: invite });
|
||||||
});
|
});
|
||||||
|
11
api/src/routes/outbound-promotions.ts
Normal file
11
api/src/routes/outbound-promotions.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { Request, Response, Router } from "express";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
|
const router: Router = Router();
|
||||||
|
|
||||||
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
|
//TODO
|
||||||
|
res.json([]).status(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
@ -1,8 +1,9 @@
|
|||||||
import { Router, Response, Request } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", (req: Request, res: Response) => {
|
router.get("/", route({}), (req: Request, res: Response) => {
|
||||||
res.send("pong");
|
res.send("pong");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import { Router, Response, Request } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.post("/", (req: Request, res: Response) => {
|
router.post("/", route({}), (req: Request, res: Response) => {
|
||||||
// TODO:
|
// TODO:
|
||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
});
|
});
|
||||||
|
19
api/src/routes/sticker-packs/#id/index.ts
Normal file
19
api/src/routes/sticker-packs/#id/index.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { Request, Response, Router } from "express";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
|
const router: Router = Router();
|
||||||
|
|
||||||
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
|
//TODO
|
||||||
|
res.json({
|
||||||
|
id: "",
|
||||||
|
stickers: [],
|
||||||
|
name: "",
|
||||||
|
sku_id: "",
|
||||||
|
cover_sticker_id: "",
|
||||||
|
description: "",
|
||||||
|
banner_asset_id: ""
|
||||||
|
}).status(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
11
api/src/routes/sticker-packs/index.ts
Normal file
11
api/src/routes/sticker-packs/index.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { Request, Response, Router } from "express";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
|
const router: Router = Router();
|
||||||
|
|
||||||
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
|
//TODO
|
||||||
|
res.json({ sticker_packs: [] }).status(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
12
api/src/routes/store/applications.ts
Normal file
12
api/src/routes/store/applications.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { Request, Response, Router } from "express";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
|
const router: Router = Router();
|
||||||
|
|
||||||
|
router.get("/applications/:id", route({}), async (req: Request, res: Response) => {
|
||||||
|
//TODO
|
||||||
|
const { id } = req.params;
|
||||||
|
res.json([]).status(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
12
api/src/routes/store/skus.ts
Normal file
12
api/src/routes/store/skus.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { Request, Response, Router } from "express";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
|
const router: Router = Router();
|
||||||
|
|
||||||
|
router.get("/skus/:id", route({}), async (req: Request, res: Response) => {
|
||||||
|
//TODO
|
||||||
|
const { id } = req.params;
|
||||||
|
res.json([]).status(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
@ -1,9 +1,10 @@
|
|||||||
import { Router, Request, Response } from "express";
|
import { Router, Request, Response } from "express";
|
||||||
import { User } from "../../../../../util/dist";
|
import { User } from "@fosscord/util";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
|
|
||||||
res.json(await User.getPublicUser(id));
|
res.json(await User.getPublicUser(id));
|
||||||
|
@ -1,9 +1,17 @@
|
|||||||
import { Router, Request, Response } from "express";
|
import { Router, Request, Response } from "express";
|
||||||
import { PublicConnectedAccount, PublicUser, User, UserPublic } from "../../../../../util/dist";
|
import { PublicConnectedAccount, PublicUser, User, UserPublic } from "@fosscord/util";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
export interface UserProfileResponse {
|
||||||
|
user: UserPublic;
|
||||||
|
connected_accounts: PublicConnectedAccount;
|
||||||
|
premium_guild_since?: Date;
|
||||||
|
premium_since?: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
router.get("/", route({ test: { response: { body: "UserProfileResponse" } } }), async (req: Request, res: Response) => {
|
||||||
if (req.params.id === "@me") req.params.id = req.user_id;
|
if (req.params.id === "@me") req.params.id = req.user_id;
|
||||||
const user = await User.getPublicUser(req.params.id, { relations: ["connected_accounts"] });
|
const user = await User.getPublicUser(req.params.id, { relations: ["connected_accounts"] });
|
||||||
|
|
||||||
@ -11,6 +19,7 @@ router.get("/", async (req: Request, res: Response) => {
|
|||||||
connected_accounts: user.connected_accounts,
|
connected_accounts: user.connected_accounts,
|
||||||
premium_guild_since: null, // TODO
|
premium_guild_since: null, // TODO
|
||||||
premium_since: null, // TODO
|
premium_since: null, // TODO
|
||||||
|
mutual_guilds: [], // TODO {id: "", nick: null} when ?with_mutual_guilds=true
|
||||||
user: {
|
user: {
|
||||||
username: user.username,
|
username: user.username,
|
||||||
discriminator: user.discriminator,
|
discriminator: user.discriminator,
|
||||||
@ -25,11 +34,4 @@ router.get("/", async (req: Request, res: Response) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
export interface UserProfileResponse {
|
|
||||||
user: UserPublic;
|
|
||||||
connected_accounts: PublicConnectedAccount;
|
|
||||||
premium_guild_since?: Date;
|
|
||||||
premium_since?: Date;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import { Router, Response, Request } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", (req: Request, res: Response) => {
|
router.get("/", route({}), (req: Request, res: Response) => {
|
||||||
// TODO:
|
// TODO:
|
||||||
res.status(200).send({ guild_affinities: [] });
|
res.status(200).send({ guild_affinities: [] });
|
||||||
});
|
});
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import { Router, Response, Request } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", (req: Request, res: Response) => {
|
router.get("/", route({}), (req: Request, res: Response) => {
|
||||||
// TODO:
|
// TODO:
|
||||||
res.status(200).send({ user_affinities: [], inverse_user_affinities: [] });
|
res.status(200).send({ user_affinities: [], inverse_user_affinities: [] });
|
||||||
});
|
});
|
@ -0,0 +1,11 @@
|
|||||||
|
import { Request, Response, Router } from "express";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
|
const router: Router = Router();
|
||||||
|
|
||||||
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
|
//TODO
|
||||||
|
res.json([]).status(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
11
api/src/routes/users/@me/billing/country-code.ts
Normal file
11
api/src/routes/users/@me/billing/country-code.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { Request, Response, Router } from "express";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
|
const router: Router = Router();
|
||||||
|
|
||||||
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
|
//TODO
|
||||||
|
res.json({ country_code: "US" }).status(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
11
api/src/routes/users/@me/billing/subscriptions.ts
Normal file
11
api/src/routes/users/@me/billing/subscriptions.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { Request, Response, Router } from "express";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
|
const router: Router = Router();
|
||||||
|
|
||||||
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
|
//TODO
|
||||||
|
res.json([]).status(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
@ -1,46 +1,22 @@
|
|||||||
import { Router, Request, Response } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
import { Channel, ChannelCreateEvent, ChannelType, Snowflake, trimSpecial, User, emitEvent } from "@fosscord/util";
|
import { Recipient, DmChannelDTO, Channel } from "@fosscord/util";
|
||||||
import { HTTPError } from "lambert-server";
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
import { DmChannelCreateSchema } from "../../../schema/Channel";
|
|
||||||
import { check } from "../../../util/instanceOf";
|
|
||||||
import { In } from "typeorm";
|
|
||||||
import { Recipient } from "../../../../../util/dist/entities/Recipient";
|
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
const recipients = await Recipient.find({ where: { user_id: req.user_id }, relations: ["channel"] });
|
const recipients = await Recipient.find({ where: { user_id: req.user_id, closed: false }, relations: ["channel", "channel.recipients"] });
|
||||||
|
res.json(await Promise.all(recipients.map(r => DmChannelDTO.from(r.channel, [req.user_id]))));
|
||||||
res.json(recipients.map((x) => x.channel));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post("/", check(DmChannelCreateSchema), async (req: Request, res: Response) => {
|
export interface DmChannelCreateSchema {
|
||||||
|
name?: string;
|
||||||
|
recipients: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
router.post("/", route({ body: "DmChannelCreateSchema" }), async (req: Request, res: Response) => {
|
||||||
const body = req.body as DmChannelCreateSchema;
|
const body = req.body as DmChannelCreateSchema;
|
||||||
|
res.json(await Channel.createDMChannel(body.recipients, req.user_id, body.name));
|
||||||
body.recipients = body.recipients.filter((x) => x !== req.user_id).unique();
|
|
||||||
|
|
||||||
const recipients = await User.find({ id: In(body.recipients) });
|
|
||||||
|
|
||||||
if (recipients.length !== body.recipients.length) {
|
|
||||||
throw new HTTPError("Recipient/s not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
const type = body.recipients.length === 1 ? ChannelType.DM : ChannelType.GROUP_DM;
|
|
||||||
const name = trimSpecial(body.name);
|
|
||||||
|
|
||||||
const channel = await new Channel({
|
|
||||||
name,
|
|
||||||
type,
|
|
||||||
owner_id: req.user_id,
|
|
||||||
created_at: new Date(),
|
|
||||||
last_message_id: null,
|
|
||||||
recipients: [...body.recipients.map((x) => new Recipient({ id: x })), new Recipient({ id: req.user_id })]
|
|
||||||
}).save();
|
|
||||||
|
|
||||||
await emitEvent({ event: "CHANNEL_CREATE", data: channel, user_id: req.user_id } as ChannelCreateEvent);
|
|
||||||
|
|
||||||
res.json(channel);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
11
api/src/routes/users/@me/connections.ts
Normal file
11
api/src/routes/users/@me/connections.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { Request, Response, Router } from "express";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
|
const router: Router = Router();
|
||||||
|
|
||||||
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
|
//TODO
|
||||||
|
res.json([]).status(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
@ -1,10 +1,12 @@
|
|||||||
import { Router, Request, Response } from "express";
|
import { Router, Request, Response } from "express";
|
||||||
import { Guild, Member, User } from "@fosscord/util";
|
import { Guild, Member, User } from "@fosscord/util";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
import bcrypt from "bcrypt";
|
import bcrypt from "bcrypt";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.post("/", async (req: Request, res: Response) => {
|
router.post("/", route({}), async (req: Request, res: Response) => {
|
||||||
const user = await User.findOneOrFail({ id: req.user_id }); //User object
|
const user = await User.findOneOrFail({ id: req.user_id }); //User object
|
||||||
let correctpass = true;
|
let correctpass = true;
|
||||||
|
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import { Router, Response, Request } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.post("/", (req: Request, res: Response) => {
|
router.post("/", route({}), (req: Request, res: Response) => {
|
||||||
// TODO:
|
// TODO:
|
||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
});
|
});
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import { User } from "@fosscord/util";
|
import { User } from "@fosscord/util";
|
||||||
import { Router, Response, Request } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
import bcrypt from "bcrypt";
|
import bcrypt from "bcrypt";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.post("/", async (req: Request, res: Response) => {
|
router.post("/", route({}), async (req: Request, res: Response) => {
|
||||||
const user = await User.findOneOrFail({ id: req.user_id }); //User object
|
const user = await User.findOneOrFail({ id: req.user_id }); //User object
|
||||||
let correctpass = true;
|
let correctpass = true;
|
||||||
|
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
import { Router, Request, Response } from "express";
|
import { Router, Request, Response } from "express";
|
||||||
import { Guild, Member, User, GuildDeleteEvent, GuildMemberRemoveEvent, emitEvent } from "@fosscord/util";
|
import { Guild, Member, User, GuildDeleteEvent, GuildMemberRemoveEvent, emitEvent } from "@fosscord/util";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { In } from "typeorm";
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
const members = await Member.find({ relations: ["guild"], where: { id: req.user_id } });
|
const members = await Member.find({ relations: ["guild"], where: { id: req.user_id } });
|
||||||
|
|
||||||
res.json(members.map((x) => x.guild));
|
res.json(members.map((x) => x.guild));
|
||||||
});
|
});
|
||||||
|
|
||||||
// user send to leave a certain guild
|
// user send to leave a certain guild
|
||||||
router.delete("/:id", async (req: Request, res: Response) => {
|
router.delete("/:id", route({}), async (req: Request, res: Response) => {
|
||||||
const guild_id = req.params.id;
|
const guild_id = req.params.id;
|
||||||
const guild = await Guild.findOneOrFail({ where: { id: guild_id }, select: ["owner_id"] });
|
const guild = await Guild.findOneOrFail({ where: { id: guild_id }, select: ["owner_id"] });
|
||||||
|
|
||||||
|
@ -1,23 +1,47 @@
|
|||||||
import { Router, Request, Response } from "express";
|
import { Router, Request, Response } from "express";
|
||||||
import { User, PrivateUserProjection } from "@fosscord/util";
|
import { User, PrivateUserProjection, emitEvent, UserUpdateEvent, handleFile } from "@fosscord/util";
|
||||||
import { UserModifySchema } from "../../../schema/User";
|
import { route } from "@fosscord/api";
|
||||||
import { check } from "../../../util/instanceOf";
|
|
||||||
import { handleFile } from "../../../util/cdn";
|
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
export interface UserModifySchema {
|
||||||
res.json(await User.getPublicUser(req.user_id, { select: PrivateUserProjection }));
|
/**
|
||||||
|
* @minLength 1
|
||||||
|
* @maxLength 100
|
||||||
|
*/
|
||||||
|
username?: string;
|
||||||
|
avatar?: string | null;
|
||||||
|
/**
|
||||||
|
* @maxLength 1024
|
||||||
|
*/
|
||||||
|
bio?: string;
|
||||||
|
accent_color?: number;
|
||||||
|
banner?: string | null;
|
||||||
|
password?: string;
|
||||||
|
new_password?: string;
|
||||||
|
code?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
|
res.json(await User.findOne({ select: PrivateUserProjection, where: { id: req.user_id } }));
|
||||||
});
|
});
|
||||||
|
|
||||||
router.patch("/", check(UserModifySchema), async (req: Request, res: Response) => {
|
router.patch("/", route({ body: "UserModifySchema" }), async (req: Request, res: Response) => {
|
||||||
const body = req.body as UserModifySchema;
|
const body = req.body as UserModifySchema;
|
||||||
|
|
||||||
if (body.avatar) body.avatar = await handleFile(`/avatars/${req.user_id}`, body.avatar as string);
|
if (body.avatar) body.avatar = await handleFile(`/avatars/${req.user_id}`, body.avatar as string);
|
||||||
if (body.banner) body.banner = await handleFile(`/banners/${req.user_id}`, body.banner as string);
|
if (body.banner) body.banner = await handleFile(`/banners/${req.user_id}`, body.banner as string);
|
||||||
|
|
||||||
const user = await new User({ ...body, id: req.user_id }).save();
|
await new User({ ...body, id: req.user_id }).save();
|
||||||
// TODO: dispatch user update event
|
|
||||||
|
//Need to reload user from db due to https://github.com/typeorm/typeorm/issues/3490
|
||||||
|
const user = await User.findOneOrFail({ where: { id: req.user_id }, select: PrivateUserProjection });
|
||||||
|
// TODO: send update member list event in gateway
|
||||||
|
await emitEvent({
|
||||||
|
event: "USER_UPDATE",
|
||||||
|
user_id: req.user_id,
|
||||||
|
data: user
|
||||||
|
} as UserUpdateEvent);
|
||||||
|
|
||||||
res.json(user);
|
res.json(user);
|
||||||
});
|
});
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import { Router, Response, Request } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", (req: Request, res: Response) => {
|
router.get("/", route({}), (req: Request, res: Response) => {
|
||||||
// TODO:
|
// TODO:
|
||||||
res.status(200).send([]);
|
res.status(200).send([]);
|
||||||
});
|
});
|
||||||
|
@ -11,170 +11,103 @@ import {
|
|||||||
import { Router, Response, Request } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { DiscordApiErrors } from "@fosscord/util";
|
import { DiscordApiErrors } from "@fosscord/util";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
import { check, Length } from "../../../util/instanceOf";
|
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
const userProjection: (keyof User)[] = ["relationships", ...PublicUserProjection];
|
const userProjection: (keyof User)[] = ["relationships", ...PublicUserProjection];
|
||||||
|
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
const user = await User.findOneOrFail({ where: { id: req.user_id }, select: ["relationships"] });
|
const user = await User.findOneOrFail({ where: { id: req.user_id }, relations: ["relationships", "relationships.to"] });
|
||||||
|
|
||||||
return res.json(user.relationships);
|
//TODO DTO
|
||||||
|
const related_users = user.relationships.map((r) => {
|
||||||
|
return {
|
||||||
|
id: r.to.id,
|
||||||
|
type: r.type,
|
||||||
|
nickname: null,
|
||||||
|
user: r.to.toPublicUser()
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return res.json(related_users);
|
||||||
});
|
});
|
||||||
|
|
||||||
async function updateRelationship(req: Request, res: Response, friend: User, type: RelationshipType) {
|
export interface RelationshipPutSchema {
|
||||||
const id = friend.id;
|
type?: RelationshipType;
|
||||||
if (id === req.user_id) throw new HTTPError("You can't add yourself as a friend");
|
|
||||||
|
|
||||||
const user = await User.findOneOrFail({ id: req.user_id }, { relations: ["relationships"], select: userProjection });
|
|
||||||
|
|
||||||
var relationship = user.relationships.find((x) => x.id === id);
|
|
||||||
const friendRequest = friend.relationships.find((x) => x.id === req.user_id);
|
|
||||||
|
|
||||||
// TODO: you can add infinitely many blocked users (should this be prevented?)
|
|
||||||
if (type === RelationshipType.blocked) {
|
|
||||||
if (relationship) {
|
|
||||||
if (relationship.type === RelationshipType.blocked) throw new HTTPError("You already blocked the user");
|
|
||||||
relationship.type = RelationshipType.blocked;
|
|
||||||
} else {
|
|
||||||
relationship = new Relationship({ id, type: RelationshipType.blocked });
|
|
||||||
user.relationships.push(relationship);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (friendRequest && friendRequest.type !== RelationshipType.blocked) {
|
|
||||||
friend.relationships.remove(friendRequest);
|
|
||||||
await Promise.all([
|
|
||||||
user.save(),
|
|
||||||
emitEvent({
|
|
||||||
event: "RELATIONSHIP_REMOVE",
|
|
||||||
data: friendRequest,
|
|
||||||
user_id: id
|
|
||||||
} as RelationshipRemoveEvent)
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
await Promise.all([
|
|
||||||
user.save(),
|
|
||||||
emitEvent({
|
|
||||||
event: "RELATIONSHIP_ADD",
|
|
||||||
data: {
|
|
||||||
...relationship,
|
|
||||||
user: { ...friend }
|
|
||||||
},
|
|
||||||
user_id: req.user_id
|
|
||||||
} as RelationshipAddEvent)
|
|
||||||
]);
|
|
||||||
|
|
||||||
return res.sendStatus(204);
|
|
||||||
}
|
|
||||||
|
|
||||||
const { maxFriends } = Config.get().limits.user;
|
|
||||||
if (user.relationships.length >= maxFriends) throw DiscordApiErrors.MAXIMUM_FRIENDS.withParams(maxFriends);
|
|
||||||
|
|
||||||
var incoming_relationship = new Relationship({ nickname: undefined, type: RelationshipType.incoming, id: req.user_id });
|
|
||||||
var outgoing_relationship = new Relationship({ nickname: undefined, type: RelationshipType.outgoing, id });
|
|
||||||
|
|
||||||
if (friendRequest) {
|
|
||||||
if (friendRequest.type === RelationshipType.blocked) throw new HTTPError("The user blocked you");
|
|
||||||
// accept friend request
|
|
||||||
incoming_relationship = friendRequest;
|
|
||||||
incoming_relationship.type = RelationshipType.friends;
|
|
||||||
outgoing_relationship.type = RelationshipType.friends;
|
|
||||||
} else friend.relationships.push(incoming_relationship);
|
|
||||||
|
|
||||||
if (relationship) {
|
|
||||||
if (relationship.type === RelationshipType.outgoing) throw new HTTPError("You already sent a friend request");
|
|
||||||
if (relationship.type === RelationshipType.blocked) throw new HTTPError("Unblock the user before sending a friend request");
|
|
||||||
if (relationship.type === RelationshipType.friends) throw new HTTPError("You are already friends with the user");
|
|
||||||
} else user.relationships.push(outgoing_relationship);
|
|
||||||
|
|
||||||
await Promise.all([
|
|
||||||
user.save(),
|
|
||||||
friend.save(),
|
|
||||||
emitEvent({
|
|
||||||
event: "RELATIONSHIP_ADD",
|
|
||||||
data: {
|
|
||||||
...outgoing_relationship,
|
|
||||||
user: { ...friend }
|
|
||||||
},
|
|
||||||
user_id: req.user_id
|
|
||||||
} as RelationshipAddEvent),
|
|
||||||
emitEvent({
|
|
||||||
event: "RELATIONSHIP_ADD",
|
|
||||||
data: {
|
|
||||||
...incoming_relationship,
|
|
||||||
should_notify: true,
|
|
||||||
user: { ...user }
|
|
||||||
},
|
|
||||||
user_id: id
|
|
||||||
} as RelationshipAddEvent)
|
|
||||||
]);
|
|
||||||
|
|
||||||
return res.sendStatus(204);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
router.put("/:id", check({ $type: new Length(Number, 1, 4) }), async (req: Request, res: Response) => {
|
router.put("/:id", route({ body: "RelationshipPutSchema" }), async (req: Request, res: Response) => {
|
||||||
return await updateRelationship(
|
return await updateRelationship(
|
||||||
req,
|
req,
|
||||||
res,
|
res,
|
||||||
await User.findOneOrFail({ id: req.params.id }, { relations: ["relationships"], select: userProjection }),
|
await User.findOneOrFail({ id: req.params.id }, { relations: ["relationships", "relationships.to"], select: userProjection }),
|
||||||
req.body.type
|
req.body.type ?? RelationshipType.friends
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post("/", check({ discriminator: String, username: String }), async (req: Request, res: Response) => {
|
export interface RelationshipPostSchema {
|
||||||
|
discriminator: string;
|
||||||
|
username: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
router.post("/", route({ body: "RelationshipPostSchema" }), async (req: Request, res: Response) => {
|
||||||
return await updateRelationship(
|
return await updateRelationship(
|
||||||
req,
|
req,
|
||||||
res,
|
res,
|
||||||
await User.findOneOrFail({
|
await User.findOneOrFail({
|
||||||
relations: ["relationships"],
|
relations: ["relationships", "relationships.to"],
|
||||||
select: userProjection,
|
select: userProjection,
|
||||||
where: req.body as { discriminator: string; username: string }
|
where: {
|
||||||
|
discriminator: String(req.body.discriminator).padStart(4, "0"), //Discord send the discriminator as integer, we need to add leading zeroes
|
||||||
|
username: req.body.username
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
req.body.type
|
req.body.type
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.delete("/:id", async (req: Request, res: Response) => {
|
router.delete("/:id", route({}), async (req: Request, res: Response) => {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
if (id === req.user_id) throw new HTTPError("You can't remove yourself as a friend");
|
if (id === req.user_id) throw new HTTPError("You can't remove yourself as a friend");
|
||||||
|
|
||||||
const user = await User.findOneOrFail({ id: req.user_id }, { select: userProjection, relations: ["relationships"] });
|
const user = await User.findOneOrFail({ id: req.user_id }, { select: userProjection, relations: ["relationships"] });
|
||||||
const friend = await User.findOneOrFail({ id: id }, { select: userProjection, relations: ["relationships"] });
|
const friend = await User.findOneOrFail({ id: id }, { select: userProjection, relations: ["relationships"] });
|
||||||
|
|
||||||
const relationship = user.relationships.find((x) => x.id === id);
|
const relationship = user.relationships.find((x) => x.to_id === id);
|
||||||
const friendRequest = friend.relationships.find((x) => x.id === req.user_id);
|
const friendRequest = friend.relationships.find((x) => x.to_id === req.user_id);
|
||||||
|
|
||||||
|
if (!relationship) throw new HTTPError("You are not friends with the user", 404);
|
||||||
if (relationship?.type === RelationshipType.blocked) {
|
if (relationship?.type === RelationshipType.blocked) {
|
||||||
// unblock user
|
// unblock user
|
||||||
user.relationships.remove(relationship);
|
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
user.save(),
|
Relationship.delete({ id: relationship.id }),
|
||||||
emitEvent({ event: "RELATIONSHIP_REMOVE", user_id: req.user_id, data: relationship } as RelationshipRemoveEvent)
|
emitEvent({
|
||||||
|
event: "RELATIONSHIP_REMOVE",
|
||||||
|
user_id: req.user_id,
|
||||||
|
data: relationship.toPublicRelationship()
|
||||||
|
} as RelationshipRemoveEvent)
|
||||||
]);
|
]);
|
||||||
return res.sendStatus(204);
|
return res.sendStatus(204);
|
||||||
}
|
}
|
||||||
if (!relationship || !friendRequest) throw new HTTPError("You are not friends with the user", 404);
|
if (friendRequest && friendRequest.type !== RelationshipType.blocked) {
|
||||||
if (friendRequest.type === RelationshipType.blocked) throw new HTTPError("The user blocked you");
|
await Promise.all([
|
||||||
|
Relationship.delete({ id: friendRequest.id }),
|
||||||
user.relationships.remove(relationship);
|
await emitEvent({
|
||||||
friend.relationships.remove(friendRequest);
|
event: "RELATIONSHIP_REMOVE",
|
||||||
|
data: friendRequest.toPublicRelationship(),
|
||||||
|
user_id: id
|
||||||
|
} as RelationshipRemoveEvent)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
user.save(),
|
Relationship.delete({ id: relationship.id }),
|
||||||
friend.save(),
|
|
||||||
emitEvent({
|
emitEvent({
|
||||||
event: "RELATIONSHIP_REMOVE",
|
event: "RELATIONSHIP_REMOVE",
|
||||||
data: relationship,
|
data: relationship.toPublicRelationship(),
|
||||||
user_id: req.user_id
|
user_id: req.user_id
|
||||||
} as RelationshipRemoveEvent),
|
|
||||||
emitEvent({
|
|
||||||
event: "RELATIONSHIP_REMOVE",
|
|
||||||
data: friendRequest,
|
|
||||||
user_id: id
|
|
||||||
} as RelationshipRemoveEvent)
|
} as RelationshipRemoveEvent)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -182,3 +115,93 @@ router.delete("/:id", async (req: Request, res: Response) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|
||||||
|
async function updateRelationship(req: Request, res: Response, friend: User, type: RelationshipType) {
|
||||||
|
const id = friend.id;
|
||||||
|
if (id === req.user_id) throw new HTTPError("You can't add yourself as a friend");
|
||||||
|
|
||||||
|
const user = await User.findOneOrFail(
|
||||||
|
{ id: req.user_id },
|
||||||
|
{ relations: ["relationships", "relationships.to"], select: userProjection }
|
||||||
|
);
|
||||||
|
|
||||||
|
var relationship = user.relationships.find((x) => x.to_id === id);
|
||||||
|
const friendRequest = friend.relationships.find((x) => x.to_id === req.user_id);
|
||||||
|
|
||||||
|
// TODO: you can add infinitely many blocked users (should this be prevented?)
|
||||||
|
if (type === RelationshipType.blocked) {
|
||||||
|
if (relationship) {
|
||||||
|
if (relationship.type === RelationshipType.blocked) throw new HTTPError("You already blocked the user");
|
||||||
|
relationship.type = RelationshipType.blocked;
|
||||||
|
await relationship.save();
|
||||||
|
} else {
|
||||||
|
relationship = await new Relationship({ to_id: id, type: RelationshipType.blocked, from_id: req.user_id }).save();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (friendRequest && friendRequest.type !== RelationshipType.blocked) {
|
||||||
|
await Promise.all([
|
||||||
|
Relationship.delete({ id: friendRequest.id }),
|
||||||
|
emitEvent({
|
||||||
|
event: "RELATIONSHIP_REMOVE",
|
||||||
|
data: friendRequest.toPublicRelationship(),
|
||||||
|
user_id: id
|
||||||
|
} as RelationshipRemoveEvent)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
await emitEvent({
|
||||||
|
event: "RELATIONSHIP_ADD",
|
||||||
|
data: relationship.toPublicRelationship(),
|
||||||
|
user_id: req.user_id
|
||||||
|
} as RelationshipAddEvent);
|
||||||
|
|
||||||
|
return res.sendStatus(204);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { maxFriends } = Config.get().limits.user;
|
||||||
|
if (user.relationships.length >= maxFriends) throw DiscordApiErrors.MAXIMUM_FRIENDS.withParams(maxFriends);
|
||||||
|
|
||||||
|
var incoming_relationship = new Relationship({ nickname: undefined, type: RelationshipType.incoming, to: user, from: friend });
|
||||||
|
var outgoing_relationship = new Relationship({
|
||||||
|
nickname: undefined,
|
||||||
|
type: RelationshipType.outgoing,
|
||||||
|
to: friend,
|
||||||
|
from: user
|
||||||
|
});
|
||||||
|
|
||||||
|
if (friendRequest) {
|
||||||
|
if (friendRequest.type === RelationshipType.blocked) throw new HTTPError("The user blocked you");
|
||||||
|
if (friendRequest.type === RelationshipType.friends) throw new HTTPError("You are already friends with the user");
|
||||||
|
// accept friend request
|
||||||
|
incoming_relationship = friendRequest;
|
||||||
|
incoming_relationship.type = RelationshipType.friends;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (relationship) {
|
||||||
|
if (relationship.type === RelationshipType.outgoing) throw new HTTPError("You already sent a friend request");
|
||||||
|
if (relationship.type === RelationshipType.blocked) throw new HTTPError("Unblock the user before sending a friend request");
|
||||||
|
if (relationship.type === RelationshipType.friends) throw new HTTPError("You are already friends with the user");
|
||||||
|
outgoing_relationship = relationship;
|
||||||
|
outgoing_relationship.type = RelationshipType.friends;
|
||||||
|
}
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
incoming_relationship.save(),
|
||||||
|
outgoing_relationship.save(),
|
||||||
|
emitEvent({
|
||||||
|
event: "RELATIONSHIP_ADD",
|
||||||
|
data: outgoing_relationship.toPublicRelationship(),
|
||||||
|
user_id: req.user_id
|
||||||
|
} as RelationshipAddEvent),
|
||||||
|
emitEvent({
|
||||||
|
event: "RELATIONSHIP_ADD",
|
||||||
|
data: {
|
||||||
|
...incoming_relationship.toPublicRelationship(),
|
||||||
|
should_notify: true
|
||||||
|
},
|
||||||
|
user_id: id
|
||||||
|
} as RelationshipAddEvent)
|
||||||
|
]);
|
||||||
|
|
||||||
|
return res.sendStatus(204);
|
||||||
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import { Router, Response, Request } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
import { User, UserSettings } from "@fosscord/util";
|
import { User, UserSettings } from "@fosscord/util";
|
||||||
import { check } from "../../../util/instanceOf";
|
import { route } from "@fosscord/api";
|
||||||
import { UserSettingsSchema } from "../../../schema/User";
|
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.patch("/", check(UserSettingsSchema), async (req: Request, res: Response) => {
|
export interface UserSettingsSchema extends UserSettings {}
|
||||||
|
|
||||||
|
router.patch("/", route({ body: "UserSettingsSchema" }), async (req: Request, res: Response) => {
|
||||||
const body = req.body as UserSettings;
|
const body = req.body as UserSettings;
|
||||||
|
|
||||||
// only users can update user settings
|
// only users can update user settings
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { Router, Request, Response } from "express";
|
import { Router, Request, Response } from "express";
|
||||||
import {getIpAdress} from "../../util/ipAddress";
|
import { getIpAdress, route } from "@fosscord/api";
|
||||||
import {getVoiceRegions} from "../../util/Voice";
|
import { getVoiceRegions } from "@fosscord/api";
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
res.json(await getVoiceRegions(getIpAdress(req), true))//vip true?
|
res.json(await getVoiceRegions(getIpAdress(req), true)); //vip true?
|
||||||
});
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
export const BanCreateSchema = {
|
|
||||||
$delete_message_days: String,
|
|
||||||
$reason: String,
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface BanCreateSchema {
|
|
||||||
delete_message_days?: string;
|
|
||||||
reason?: string;
|
|
||||||
}
|
|
@ -1,68 +0,0 @@
|
|||||||
import { ChannelType } from "@fosscord/util";
|
|
||||||
import { Length } from "../util/instanceOf";
|
|
||||||
|
|
||||||
export const ChannelModifySchema = {
|
|
||||||
name: new Length(String, 2, 100),
|
|
||||||
type: new Length(Number, 0, 13),
|
|
||||||
$topic: new Length(String, 0, 1024),
|
|
||||||
$bitrate: Number,
|
|
||||||
$user_limit: Number,
|
|
||||||
$rate_limit_per_user: new Length(Number, 0, 21600),
|
|
||||||
$position: Number,
|
|
||||||
$permission_overwrites: [
|
|
||||||
{
|
|
||||||
id: String,
|
|
||||||
type: new Length(Number, 0, 1), // either 0 (role) or 1 (member)
|
|
||||||
allow: BigInt,
|
|
||||||
deny: BigInt
|
|
||||||
}
|
|
||||||
],
|
|
||||||
$parent_id: String,
|
|
||||||
$rtc_region: String,
|
|
||||||
$default_auto_archive_duration: Number,
|
|
||||||
$id: String, // kept for backwards compatibility does nothing (need for guild create)
|
|
||||||
$nsfw: Boolean
|
|
||||||
};
|
|
||||||
|
|
||||||
export const DmChannelCreateSchema = {
|
|
||||||
$name: String,
|
|
||||||
recipients: new Length([String], 1, 10)
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface DmChannelCreateSchema {
|
|
||||||
name?: string;
|
|
||||||
recipients: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ChannelModifySchema {
|
|
||||||
name: string;
|
|
||||||
type: number;
|
|
||||||
topic?: string;
|
|
||||||
bitrate?: number;
|
|
||||||
user_limit?: number;
|
|
||||||
rate_limit_per_user?: number;
|
|
||||||
position?: number;
|
|
||||||
permission_overwrites?: {
|
|
||||||
id: string;
|
|
||||||
type: number;
|
|
||||||
allow: bigint;
|
|
||||||
deny: bigint;
|
|
||||||
}[];
|
|
||||||
parent_id?: string;
|
|
||||||
id?: string; // is not used (only for guild create)
|
|
||||||
nsfw?: boolean;
|
|
||||||
rtc_region?: string;
|
|
||||||
default_auto_archive_duration?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const ChannelGuildPositionUpdateSchema = [
|
|
||||||
{
|
|
||||||
id: String,
|
|
||||||
$position: Number
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
export type ChannelGuildPositionUpdateSchema = {
|
|
||||||
id: string;
|
|
||||||
position?: number;
|
|
||||||
}[];
|
|
@ -1,13 +0,0 @@
|
|||||||
// https://discord.com/developers/docs/resources/emoji
|
|
||||||
|
|
||||||
export const EmojiCreateSchema = {
|
|
||||||
name: String, //name of the emoji
|
|
||||||
image: String, // image data the 128x128 emoji image uri
|
|
||||||
$roles: Array //roles allowed to use this emoji
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface EmojiCreateSchema {
|
|
||||||
name: string; // name of the emoji
|
|
||||||
image: string; // image data the 128x128 emoji image uri
|
|
||||||
roles?: string[]; //roles allowed to use this emoji
|
|
||||||
}
|
|
@ -1,106 +0,0 @@
|
|||||||
import { Channel } from "@fosscord/util";
|
|
||||||
import { Length } from "../util/instanceOf";
|
|
||||||
import { ChannelModifySchema } from "./Channel";
|
|
||||||
|
|
||||||
export const GuildCreateSchema = {
|
|
||||||
name: new Length(String, 2, 100),
|
|
||||||
$region: String, // auto complete voice region of the user
|
|
||||||
$icon: String,
|
|
||||||
$channels: [ChannelModifySchema],
|
|
||||||
$guild_template_code: String,
|
|
||||||
$system_channel_id: String,
|
|
||||||
$rules_channel_id: String
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface GuildCreateSchema {
|
|
||||||
name: string;
|
|
||||||
region?: string;
|
|
||||||
icon?: string;
|
|
||||||
channels?: ChannelModifySchema[];
|
|
||||||
guild_template_code?: string;
|
|
||||||
system_channel_id?: string;
|
|
||||||
rules_channel_id?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const GuildUpdateSchema = {
|
|
||||||
...GuildCreateSchema,
|
|
||||||
name: undefined,
|
|
||||||
$name: new Length(String, 2, 100),
|
|
||||||
$banner: String,
|
|
||||||
$splash: String,
|
|
||||||
$description: String,
|
|
||||||
$features: [String],
|
|
||||||
$icon: String,
|
|
||||||
$verification_level: Number,
|
|
||||||
$default_message_notifications: Number,
|
|
||||||
$system_channel_flags: Number,
|
|
||||||
$system_channel_id: String,
|
|
||||||
$explicit_content_filter: Number,
|
|
||||||
$public_updates_channel_id: String,
|
|
||||||
$afk_timeout: Number,
|
|
||||||
$afk_channel_id: String,
|
|
||||||
$preferred_locale: String
|
|
||||||
};
|
|
||||||
// @ts-ignore
|
|
||||||
delete GuildUpdateSchema.$channels;
|
|
||||||
|
|
||||||
export interface GuildUpdateSchema extends Omit<GuildCreateSchema, "channels"> {
|
|
||||||
banner?: string;
|
|
||||||
splash?: string;
|
|
||||||
description?: string;
|
|
||||||
features?: string[];
|
|
||||||
verification_level?: number;
|
|
||||||
default_message_notifications?: number;
|
|
||||||
system_channel_flags?: number;
|
|
||||||
explicit_content_filter?: number;
|
|
||||||
public_updates_channel_id?: string;
|
|
||||||
afk_timeout?: number;
|
|
||||||
afk_channel_id?: string;
|
|
||||||
preferred_locale?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const GuildTemplateCreateSchema = {
|
|
||||||
name: String,
|
|
||||||
$avatar: String
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface GuildTemplateCreateSchema {
|
|
||||||
name: string;
|
|
||||||
avatar?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const GuildUpdateWelcomeScreenSchema = {
|
|
||||||
$welcome_channels: [
|
|
||||||
{
|
|
||||||
channel_id: String,
|
|
||||||
description: String,
|
|
||||||
$emoji_id: String,
|
|
||||||
emoji_name: String
|
|
||||||
}
|
|
||||||
],
|
|
||||||
$enabled: Boolean,
|
|
||||||
$description: new Length(String, 0, 140)
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface GuildUpdateWelcomeScreenSchema {
|
|
||||||
welcome_channels?: {
|
|
||||||
channel_id: string;
|
|
||||||
description: string;
|
|
||||||
emoji_id?: string;
|
|
||||||
emoji_name: string;
|
|
||||||
}[];
|
|
||||||
enabled?: boolean;
|
|
||||||
description?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const VoiceStateUpdateSchema = {
|
|
||||||
channel_id: String, // Snowflake
|
|
||||||
$suppress: Boolean,
|
|
||||||
$request_to_speak_timestamp: String // ISO8601 timestamp
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface VoiceStateUpdateSchema {
|
|
||||||
channel_id: string; // Snowflake
|
|
||||||
suppress?: boolean;
|
|
||||||
request_to_speak_timestamp?: string // ISO8601 timestamp
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
export const InviteCreateSchema = {
|
|
||||||
$target_user_id: String,
|
|
||||||
$target_type: String,
|
|
||||||
$validate: String, //? wtf is this
|
|
||||||
$max_age: Number,
|
|
||||||
$max_uses: Number,
|
|
||||||
$temporary: Boolean,
|
|
||||||
$unique: Boolean,
|
|
||||||
$target_user: String,
|
|
||||||
$target_user_type: Number
|
|
||||||
};
|
|
||||||
export interface InviteCreateSchema {
|
|
||||||
target_user_id?: string;
|
|
||||||
target_type?: string;
|
|
||||||
validate?: string; //? wtf is this
|
|
||||||
max_age?: number;
|
|
||||||
max_uses?: number;
|
|
||||||
temporary?: boolean;
|
|
||||||
unique?: boolean;
|
|
||||||
target_user?: string;
|
|
||||||
target_user_type?: number;
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
export const MemberCreateSchema = {
|
|
||||||
id: String,
|
|
||||||
nick: String,
|
|
||||||
guild_id: String,
|
|
||||||
joined_at: Date
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface MemberCreateSchema {
|
|
||||||
id: string;
|
|
||||||
nick: string;
|
|
||||||
guild_id: string;
|
|
||||||
joined_at: Date;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const MemberNickChangeSchema = {
|
|
||||||
nick: String
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface MemberNickChangeSchema {
|
|
||||||
nick: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const MemberChangeSchema = {
|
|
||||||
$roles: [String]
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface MemberChangeSchema {
|
|
||||||
roles?: string[];
|
|
||||||
}
|
|
@ -1,92 +0,0 @@
|
|||||||
import { Embed } from "@fosscord/util";
|
|
||||||
import { Length } from "../util/instanceOf";
|
|
||||||
|
|
||||||
export const EmbedImage = {
|
|
||||||
$url: String,
|
|
||||||
$width: Number,
|
|
||||||
$height: Number
|
|
||||||
};
|
|
||||||
|
|
||||||
const embed = {
|
|
||||||
$title: new Length(String, 0, 256), //title of embed
|
|
||||||
$type: String, // type of embed (always "rich" for webhook embeds)
|
|
||||||
$description: new Length(String, 0, 2048), // description of embed
|
|
||||||
$url: String, // url of embed
|
|
||||||
$timestamp: String, // ISO8601 timestamp
|
|
||||||
$color: Number, // color code of the embed
|
|
||||||
$footer: {
|
|
||||||
text: new Length(String, 0, 2048),
|
|
||||||
icon_url: String,
|
|
||||||
proxy_icon_url: String
|
|
||||||
}, // footer object footer information
|
|
||||||
$image: EmbedImage, // image object image information
|
|
||||||
$thumbnail: EmbedImage, // thumbnail object thumbnail information
|
|
||||||
$video: EmbedImage, // video object video information
|
|
||||||
$provider: {
|
|
||||||
name: String,
|
|
||||||
url: String
|
|
||||||
}, // provider object provider information
|
|
||||||
$author: {
|
|
||||||
name: new Length(String, 0, 256),
|
|
||||||
url: String,
|
|
||||||
icon_url: String,
|
|
||||||
proxy_icon_url: String
|
|
||||||
}, // author object author information
|
|
||||||
$fields: new Length(
|
|
||||||
[
|
|
||||||
{
|
|
||||||
name: new Length(String, 0, 256),
|
|
||||||
value: new Length(String, 0, 1024),
|
|
||||||
$inline: Boolean
|
|
||||||
}
|
|
||||||
],
|
|
||||||
0,
|
|
||||||
25
|
|
||||||
)
|
|
||||||
};
|
|
||||||
|
|
||||||
export const MessageCreateSchema = {
|
|
||||||
$content: new Length(String, 0, 2000),
|
|
||||||
$nonce: String,
|
|
||||||
$tts: Boolean,
|
|
||||||
$flags: String,
|
|
||||||
$embed: embed,
|
|
||||||
// TODO: ^ embed is deprecated in favor of embeds (https://discord.com/developers/docs/resources/channel#message-object)
|
|
||||||
// $embeds: [embed],
|
|
||||||
$allowed_mentions: {
|
|
||||||
$parse: [String],
|
|
||||||
$roles: [String],
|
|
||||||
$users: [String],
|
|
||||||
$replied_user: Boolean
|
|
||||||
},
|
|
||||||
$message_reference: {
|
|
||||||
message_id: String,
|
|
||||||
channel_id: String,
|
|
||||||
$guild_id: String,
|
|
||||||
$fail_if_not_exists: Boolean
|
|
||||||
},
|
|
||||||
$payload_json: String,
|
|
||||||
$file: Object
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface MessageCreateSchema {
|
|
||||||
content?: string;
|
|
||||||
nonce?: string;
|
|
||||||
tts?: boolean;
|
|
||||||
flags?: string;
|
|
||||||
embed?: Embed & { timestamp?: string };
|
|
||||||
allowed_mentions?: {
|
|
||||||
parse?: string[];
|
|
||||||
roles?: string[];
|
|
||||||
users?: string[];
|
|
||||||
replied_user?: boolean;
|
|
||||||
};
|
|
||||||
message_reference?: {
|
|
||||||
message_id: string;
|
|
||||||
channel_id: string;
|
|
||||||
guild_id?: string;
|
|
||||||
fail_if_not_exists?: boolean;
|
|
||||||
};
|
|
||||||
payload_json?: string;
|
|
||||||
file?: any;
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
export const RoleModifySchema = {
|
|
||||||
$name: String,
|
|
||||||
$permissions: BigInt,
|
|
||||||
$color: Number,
|
|
||||||
$hoist: Boolean, // whether the role should be displayed separately in the sidebar
|
|
||||||
$mentionable: Boolean, // whether the role should be mentionable
|
|
||||||
$position: Number
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface RoleModifySchema {
|
|
||||||
name?: string;
|
|
||||||
permissions?: bigint;
|
|
||||||
color?: number;
|
|
||||||
hoist?: boolean; // whether the role should be displayed separately in the sidebar
|
|
||||||
mentionable?: boolean; // whether the role should be mentionable
|
|
||||||
position?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const RolePositionUpdateSchema = [
|
|
||||||
{
|
|
||||||
id: String,
|
|
||||||
position: Number
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
export type RolePositionUpdateSchema = {
|
|
||||||
id: string;
|
|
||||||
position: number;
|
|
||||||
}[];
|
|
@ -1,19 +0,0 @@
|
|||||||
export const TemplateCreateSchema = {
|
|
||||||
name: String,
|
|
||||||
$description: String,
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface TemplateCreateSchema {
|
|
||||||
name: string;
|
|
||||||
description?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const TemplateModifySchema = {
|
|
||||||
name: String,
|
|
||||||
$description: String,
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface TemplateModifySchema {
|
|
||||||
name: string;
|
|
||||||
description?: string;
|
|
||||||
}
|
|
@ -1,74 +0,0 @@
|
|||||||
import { UserSettings } from "../../../util/dist";
|
|
||||||
import { Length } from "../util/instanceOf";
|
|
||||||
|
|
||||||
export const UserModifySchema = {
|
|
||||||
$username: new Length(String, 2, 32),
|
|
||||||
$avatar: String,
|
|
||||||
$bio: new Length(String, 0, 190),
|
|
||||||
$accent_color: Number,
|
|
||||||
$banner: String,
|
|
||||||
$password: String,
|
|
||||||
$new_password: String,
|
|
||||||
$code: String // 2fa code
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface UserModifySchema {
|
|
||||||
username?: string;
|
|
||||||
avatar?: string | null;
|
|
||||||
bio?: string;
|
|
||||||
accent_color?: number | null;
|
|
||||||
banner?: string | null;
|
|
||||||
password?: string;
|
|
||||||
new_password?: string;
|
|
||||||
code?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const UserSettingsSchema = {
|
|
||||||
$afk_timeout: Number,
|
|
||||||
$allow_accessibility_detection: Boolean,
|
|
||||||
$animate_emoji: Boolean,
|
|
||||||
$animate_stickers: Number,
|
|
||||||
$contact_sync_enabled: Boolean,
|
|
||||||
$convert_emoticons: Boolean,
|
|
||||||
$custom_status: {
|
|
||||||
$emoji_id: String,
|
|
||||||
$emoji_name: String,
|
|
||||||
$expires_at: Number,
|
|
||||||
$text: String
|
|
||||||
},
|
|
||||||
$default_guilds_restricted: Boolean,
|
|
||||||
$detect_platform_accounts: Boolean,
|
|
||||||
$developer_mode: Boolean,
|
|
||||||
$disable_games_tab: Boolean,
|
|
||||||
$enable_tts_command: Boolean,
|
|
||||||
$explicit_content_filter: Number,
|
|
||||||
$friend_source_flags: {
|
|
||||||
all: Boolean
|
|
||||||
},
|
|
||||||
$gateway_connected: Boolean,
|
|
||||||
$gif_auto_play: Boolean,
|
|
||||||
$guild_folders: [
|
|
||||||
{
|
|
||||||
color: Number,
|
|
||||||
guild_ids: [String],
|
|
||||||
id: Number,
|
|
||||||
name: String
|
|
||||||
}
|
|
||||||
],
|
|
||||||
$guild_positions: [String],
|
|
||||||
$inline_attachment_media: Boolean,
|
|
||||||
$inline_embed_media: Boolean,
|
|
||||||
$locale: String,
|
|
||||||
$message_display_compact: Boolean,
|
|
||||||
$native_phone_integration_enabled: Boolean,
|
|
||||||
$render_embeds: Boolean,
|
|
||||||
$render_reactions: Boolean,
|
|
||||||
$restricted_guilds: [String],
|
|
||||||
$show_current_game: Boolean,
|
|
||||||
$status: String,
|
|
||||||
$stream_notifications_enabled: Boolean,
|
|
||||||
$theme: String,
|
|
||||||
$timezone_offset: Number
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface UserSettingsSchema extends UserSettings {}
|
|
@ -1,10 +0,0 @@
|
|||||||
// https://discord.com/developers/docs/resources/guild#guild-widget-object
|
|
||||||
export const WidgetModifySchema = {
|
|
||||||
enabled: Boolean, // whether the widget is enabled
|
|
||||||
channel_id: String // the widget channel id
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface WidgetModifySchema {
|
|
||||||
enabled: boolean; // whether the widget is enabled
|
|
||||||
channel_id: string; // the widget channel id
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
export * from "./Ban";
|
|
||||||
export * from "./Channel";
|
|
||||||
export * from "./Emoji";
|
|
||||||
export * from "./Guild";
|
|
||||||
export * from "./Invite";
|
|
||||||
export * from "./Member";
|
|
||||||
export * from "./Message";
|
|
||||||
export * from "./Roles";
|
|
||||||
export * from "./Template";
|
|
||||||
export * from "./User";
|
|
||||||
export * from "./Widget";
|
|
@ -1,12 +1,12 @@
|
|||||||
import { check } from "./../util/passwordStrength";
|
import { checkPassword } from "@fosscord/api";
|
||||||
|
|
||||||
console.log(check("123456789012345"));
|
console.log(checkPassword("123456789012345"));
|
||||||
// -> 0.25
|
// -> 0.25
|
||||||
console.log(check("ABCDEFGHIJKLMOPQ"));
|
console.log(checkPassword("ABCDEFGHIJKLMOPQ"));
|
||||||
// -> 0.25
|
// -> 0.25
|
||||||
console.log(check("ABC123___...123"));
|
console.log(checkPassword("ABC123___...123"));
|
||||||
// ->
|
// ->
|
||||||
console.log(check(""));
|
console.log(checkPassword(""));
|
||||||
// ->
|
// ->
|
||||||
// console.log(check(""));
|
// console.log(checkPassword(""));
|
||||||
// // ->
|
// // ->
|
||||||
|
25
api/src/util/FieldError.ts
Normal file
25
api/src/util/FieldError.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import "missing-native-js-functions";
|
||||||
|
|
||||||
|
export function FieldErrors(fields: Record<string, { code?: string; message: string }>) {
|
||||||
|
return new FieldError(
|
||||||
|
50035,
|
||||||
|
"Invalid Form Body",
|
||||||
|
fields.map(({ message, code }) => ({
|
||||||
|
_errors: [
|
||||||
|
{
|
||||||
|
message,
|
||||||
|
code: code || "BASE_TYPE_INVALID"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: implement Image data type: Data URI scheme that supports JPG, GIF, and PNG formats. An example Data URI format is: data:image/jpeg;base64,BASE64_ENCODED_JPEG_IMAGE_DATA
|
||||||
|
// Ensure you use the proper content type (image/jpeg, image/png, image/gif) that matches the image data being provided.
|
||||||
|
|
||||||
|
export class FieldError extends Error {
|
||||||
|
constructor(public code: string | number, public message: string, public errors?: any) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
@ -22,7 +22,7 @@ import {
|
|||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
import cheerio from "cheerio";
|
import cheerio from "cheerio";
|
||||||
import { MessageCreateSchema } from "../schema/Message";
|
import { MessageCreateSchema } from "../routes/channels/#channel_id/messages";
|
||||||
|
|
||||||
// TODO: check webhook, application, system author
|
// TODO: check webhook, application, system author
|
||||||
|
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user