Compare commits
12
Commits
640745925a
..
v0.1.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e222a7dcd7
|
||
|
|
d9a2abb44f
|
||
|
|
3cce2158e9
|
||
|
|
92b1681241
|
||
|
|
440cbbb671
|
||
|
|
dc1b9e9cc0
|
||
|
|
dbd9a4ddb0
|
||
|
|
0958bd365b
|
||
|
|
5fbf30a70b
|
||
|
|
5b4936903a
|
||
|
|
680db7dce0
|
||
|
|
0751ee5588
|
@@ -23,6 +23,8 @@ FRONTEND_ORIGINS=https://localhost,https://127.0.0.1
|
|||||||
# Keep false unless you intentionally want fail-open rate limits / captcha.
|
# Keep false unless you intentionally want fail-open rate limits / captcha.
|
||||||
DEV_MODE=false
|
DEV_MODE=false
|
||||||
SEED_CURRICULUM=false
|
SEED_CURRICULUM=false
|
||||||
|
# One registration per client IP. Keep false behind NAT / shared egress (default).
|
||||||
|
REGISTRATION_ENFORCE_IP=false
|
||||||
# METRICS_TOKEN=
|
# METRICS_TOKEN=
|
||||||
# TRUSTED_PROXY_CIDRS=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,127.0.0.0/8,::1/128
|
# TRUSTED_PROXY_CIDRS=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,127.0.0.0/8,::1/128
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ FRONTEND_ORIGINS=https://app.example.com
|
|||||||
|
|
||||||
DEV_MODE=false
|
DEV_MODE=false
|
||||||
SEED_CURRICULUM=false
|
SEED_CURRICULUM=false
|
||||||
|
# Keep false behind NAT until the edge forwards real client IPs.
|
||||||
|
REGISTRATION_ENFORCE_IP=false
|
||||||
METRICS_TOKEN=replace-with-metrics-scrape-token
|
METRICS_TOKEN=replace-with-metrics-scrape-token
|
||||||
# TRUSTED_PROXY_CIDRS=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
|
# TRUSTED_PROXY_CIDRS=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,235 @@
|
|||||||
|
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 19 November 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <http://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 <http://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 <http://www.gnu.org/licenses/>.
|
||||||
+15
-15
@@ -12,10 +12,10 @@ require (
|
|||||||
github.com/jackc/pgx/v5 v5.11.0
|
github.com/jackc/pgx/v5 v5.11.0
|
||||||
github.com/redis/go-redis/v9 v9.22.0
|
github.com/redis/go-redis/v9 v9.22.0
|
||||||
github.com/rs/cors v1.11.1
|
github.com/rs/cors v1.11.1
|
||||||
go.opentelemetry.io/otel v1.35.0
|
go.opentelemetry.io/otel v1.45.0
|
||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.35.0
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.45.0
|
||||||
go.opentelemetry.io/otel/sdk v1.35.0
|
go.opentelemetry.io/otel/sdk v1.45.0
|
||||||
go.opentelemetry.io/otel/trace v1.35.0
|
go.opentelemetry.io/otel/trace v1.45.0
|
||||||
golang.org/x/crypto v0.57.0
|
golang.org/x/crypto v0.57.0
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -34,26 +34,26 @@ require (
|
|||||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.43.1 // indirect
|
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.43.1 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/service/sts v1.51.1 // indirect
|
github.com/aws/aws-sdk-go-v2/service/sts v1.51.1 // indirect
|
||||||
github.com/aws/smithy-go v1.28.1 // indirect
|
github.com/aws/smithy-go v1.28.1 // indirect
|
||||||
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
|
||||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||||
github.com/go-logr/logr v1.4.2 // indirect
|
github.com/go-logr/logr v1.4.4 // indirect
|
||||||
github.com/go-logr/stdr v1.2.2 // indirect
|
github.com/go-logr/stdr v1.2.2 // indirect
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.1 // indirect
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 // indirect
|
||||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||||
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
|
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
|
||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.35.0 // indirect
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.45.0 // indirect
|
||||||
go.opentelemetry.io/otel/metric v1.35.0 // indirect
|
go.opentelemetry.io/otel/metric v1.45.0 // indirect
|
||||||
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
|
go.opentelemetry.io/proto/otlp v1.11.0 // indirect
|
||||||
go.uber.org/atomic v1.11.0 // indirect
|
go.uber.org/atomic v1.11.0 // indirect
|
||||||
golang.org/x/net v0.58.0 // indirect
|
golang.org/x/net v0.58.0 // indirect
|
||||||
golang.org/x/sync v0.23.0 // indirect
|
golang.org/x/sync v0.23.0 // indirect
|
||||||
golang.org/x/sys v0.48.0 // indirect
|
golang.org/x/sys v0.48.0 // indirect
|
||||||
golang.org/x/text v0.42.0 // indirect
|
golang.org/x/text v0.42.0 // indirect
|
||||||
google.golang.org/genproto/googleapis/api v0.0.0-20250218202821-56aae31c358a // indirect
|
google.golang.org/genproto/googleapis/api v0.0.0-20260803160001-6ac0973c030d // indirect
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a // indirect
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20260803160001-6ac0973c030d // indirect
|
||||||
google.golang.org/grpc v1.71.0 // indirect
|
google.golang.org/grpc v1.83.2 // indirect
|
||||||
google.golang.org/protobuf v1.36.5 // indirect
|
google.golang.org/protobuf v1.36.11 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
+34
-32
@@ -38,16 +38,16 @@ github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
|||||||
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
|
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
|
||||||
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
||||||
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
|
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
|
||||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
|
||||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
|
||||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
github.com/go-logr/logr v1.4.4 h1:tG4xh9yMsRCAiodLVTxyrkzSZ9+o0L1Kg/+cPVcbP/8=
|
||||||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
github.com/go-logr/logr v1.4.4/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||||
github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY=
|
github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY=
|
||||||
@@ -60,8 +60,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
|||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
||||||
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.1 h1:e9Rjr40Z98/clHv5Yg79Is0NtosR5LXRvdr7o/6NwbA=
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 h1:5VipnvEpbqr2gA2VbM+nYVbkIF28c5ZQfqCBQ5g2xfk=
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.1/go.mod h1:tIxuGz/9mpox++sgp9fJjHO0+q1X9/UOWd798aAm22M=
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0/go.mod h1:Hyl3n6Twe1hvtd9XUXDec4pTvgMSEixRuQKPTMH2bNs=
|
||||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||||
@@ -85,24 +85,24 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu
|
|||||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||||
github.com/zeebo/xxh3 v1.1.0 h1:s7DLGDK45Dyfg7++yxI0khrfwq9661w9EN78eP/UZVs=
|
github.com/zeebo/xxh3 v1.1.0 h1:s7DLGDK45Dyfg7++yxI0khrfwq9661w9EN78eP/UZVs=
|
||||||
github.com/zeebo/xxh3 v1.1.0/go.mod h1:IisAie1LELR4xhVinxWS5+zf1lA4p0MW4T+w+W07F5s=
|
github.com/zeebo/xxh3 v1.1.0/go.mod h1:IisAie1LELR4xhVinxWS5+zf1lA4p0MW4T+w+W07F5s=
|
||||||
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
|
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||||
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
|
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||||
go.opentelemetry.io/otel v1.35.0 h1:xKWKPxrxB6OtMCbmMY021CqC45J+3Onta9MqjhnusiQ=
|
go.opentelemetry.io/otel v1.45.0 h1:pdrWmLHofpubmArBv1LgFSv1Z0Ie/ppdZzu+kUN5EeU=
|
||||||
go.opentelemetry.io/otel v1.35.0/go.mod h1:UEqy8Zp11hpkUrL73gSlELM0DupHoiq72dR+Zqel/+Y=
|
go.opentelemetry.io/otel v1.45.0/go.mod h1:XZxIqPapzEYnhNSScF5DIqXhm/rYi0FzCe2XddAwZfQ=
|
||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.35.0 h1:1fTNlAIJZGWLP5FVu0fikVry1IsiUnXjf7QFvoNN3Xw=
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.45.0 h1:QRefszxJmfPdjXUUm3j6iDzY03mTPXMjqErFqQ67vUg=
|
||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.35.0/go.mod h1:zjPK58DtkqQFn+YUMbx0M2XV3QgKU0gS9LeGohREyK4=
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.45.0/go.mod h1:Tiz03lTBVBrm7eWZBOidzEaYaJa8tjwGUGv6d8mlTyk=
|
||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.35.0 h1:xJ2qHD0C1BeYVTLLR9sX12+Qb95kfeD/byKj6Ky1pXg=
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.45.0 h1:QBajQ2SrwQijzHyZbQlPsuIzpl/ll8DY6wPWsajeGcI=
|
||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.35.0/go.mod h1:u5BF1xyjstDowA1R5QAO9JHzqK+ublenEW/dyqTjBVk=
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.45.0/go.mod h1:08ZQLjrPLQ6R4kAXvuOvODEer5Yh4CoFvll5qB2BCI8=
|
||||||
go.opentelemetry.io/otel/metric v1.35.0 h1:0znxYu2SNyuMSQT4Y9WDWej0VpcsxkuklLa4/siN90M=
|
go.opentelemetry.io/otel/metric v1.45.0 h1:7Eg1uH7CJ5cXv9is6tnBe1FI6rj1nwUdbFypRm3br/M=
|
||||||
go.opentelemetry.io/otel/metric v1.35.0/go.mod h1:nKVFgxBZ2fReX6IlyW28MgZojkoAkJGaE8CpgeAU3oE=
|
go.opentelemetry.io/otel/metric v1.45.0/go.mod h1:HAPbm1nd3p1PmFH7v2dR+6BjXxw+Lq4a2+pndMAm08s=
|
||||||
go.opentelemetry.io/otel/sdk v1.35.0 h1:iPctf8iprVySXSKJffSS79eOjl9pvxV9ZqOWT0QejKY=
|
go.opentelemetry.io/otel/sdk v1.45.0 h1:4VVSMgQ83dUgW2aoX5f6JgLvHwIvzcuLnF9lUdCSpCw=
|
||||||
go.opentelemetry.io/otel/sdk v1.35.0/go.mod h1:+ga1bZliga3DxJ3CQGg3updiaAJoNECOgJREo9KHGQg=
|
go.opentelemetry.io/otel/sdk v1.45.0/go.mod h1:Sr40LgXV7DsKMMJMKOhUWOgMWTfAaqvm2kF0g7ilwuA=
|
||||||
go.opentelemetry.io/otel/sdk/metric v1.34.0 h1:5CeK9ujjbFVL5c1PhLuStg1wxA7vQv7ce1EK0Gyvahk=
|
go.opentelemetry.io/otel/sdk/metric v1.45.0 h1:oVFszMfyj1Am6s24Vtc7wBb8BKLcwepJjNEYILuiE3o=
|
||||||
go.opentelemetry.io/otel/sdk/metric v1.34.0/go.mod h1:jQ/r8Ze28zRKoNRdkjCZxfs6YvBTG1+YIqyFVFYec5w=
|
go.opentelemetry.io/otel/sdk/metric v1.45.0/go.mod h1:vUWUxDZvu1WVRj8JA8S0AdhsPrZoDpA2DdZauIh4mDA=
|
||||||
go.opentelemetry.io/otel/trace v1.35.0 h1:dPpEfJu1sDIqruz7BHFG3c7528f6ddfSWfFDVt/xgMs=
|
go.opentelemetry.io/otel/trace v1.45.0 h1:l/mP6Uv7oNO7/TblbhpbgMidxhq1uO/rPsikOyVhxag=
|
||||||
go.opentelemetry.io/otel/trace v1.35.0/go.mod h1:WUk7DtFp1Aw2MkvqGdwiXYDZZNvA/1J8o6xRXLrIkyc=
|
go.opentelemetry.io/otel/trace v1.45.0/go.mod h1:qoJJA2xNMnxRrdISU/kLtfUH2wNeQbiv+jhs/CxI8bc=
|
||||||
go.opentelemetry.io/proto/otlp v1.5.0 h1:xJvq7gMzB31/d406fB8U5CBdyQGw4P399D1aQWU/3i4=
|
go.opentelemetry.io/proto/otlp v1.11.0 h1:5rrYs0Ykyj50sdU/JU0x8etU+LubXWb+gED6TbEdMIk=
|
||||||
go.opentelemetry.io/proto/otlp v1.5.0/go.mod h1:keN8WnHxOy8PG0rQZjJJ5A2ebUoafqWp0eVQ4yIXvJ4=
|
go.opentelemetry.io/proto/otlp v1.11.0/go.mod h1:SmVizdCOAm3XBtG1g1NnOdhW6jtddT72hLMhv8VwA8E=
|
||||||
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
|
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
|
||||||
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
|
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
|
||||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||||
@@ -117,14 +117,16 @@ golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo=
|
|||||||
golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
|
golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
|
||||||
golang.org/x/text v0.42.0 h1:JbOZXgfeCPU9gacVtYliJqOhD+zhrEqK4LfdpmlUZqI=
|
golang.org/x/text v0.42.0 h1:JbOZXgfeCPU9gacVtYliJqOhD+zhrEqK4LfdpmlUZqI=
|
||||||
golang.org/x/text v0.42.0/go.mod h1:ojzP1Z+2QtioaF8DTtO8K5q7JWVVYwZKenzujK0Zd0E=
|
golang.org/x/text v0.42.0/go.mod h1:ojzP1Z+2QtioaF8DTtO8K5q7JWVVYwZKenzujK0Zd0E=
|
||||||
google.golang.org/genproto/googleapis/api v0.0.0-20250218202821-56aae31c358a h1:nwKuGPlUAt+aR+pcrkfFRrTU1BVrSmYyYMxYbUIVHr0=
|
gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4=
|
||||||
google.golang.org/genproto/googleapis/api v0.0.0-20250218202821-56aae31c358a/go.mod h1:3kWAYMk1I75K4vykHtKt2ycnOgpA6974V7bREqbsenU=
|
gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E=
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a h1:51aaUVRocpvUOSQKM6Q7VuoaktNIaMCLuhZB6DKksq4=
|
google.golang.org/genproto/googleapis/api v0.0.0-20260803160001-6ac0973c030d h1:FarXi840EJWSHYTN3ERkADbPWjl307+FGrA22KAVjjc=
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a/go.mod h1:uRxBH1mhmO8PGhU89cMcHaXKZqO+OfakD8QQO0oYwlQ=
|
google.golang.org/genproto/googleapis/api v0.0.0-20260803160001-6ac0973c030d/go.mod h1:K/+WGbmBY7aNW1HDw1fJnKYo10i0DkAX6pows00dLig=
|
||||||
google.golang.org/grpc v1.71.0 h1:kF77BGdPTQ4/JZWMlb9VpJ5pa25aqvVqogsxNHHdeBg=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20260803160001-6ac0973c030d h1:IL4hdHzcUv2l/gcg98/Rj3FbtE6axwqslOW8SW0C+S0=
|
||||||
google.golang.org/grpc v1.71.0/go.mod h1:H0GRtasmQOh9LkFoCPDu3ZrwUtD1YGE+b2vYBYd/8Ec=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20260803160001-6ac0973c030d/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
|
||||||
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
|
google.golang.org/grpc v1.83.2 h1:EManeRomTObA0BU7I8vXgg/78uE5MJ9M8B39EX2WscU=
|
||||||
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
google.golang.org/grpc v1.83.2/go.mod h1:YPI1hK3kDked6iHvgX3tR0y+nX/qpMFKhPgFsokw1S8=
|
||||||
|
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
|
||||||
|
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
|||||||
@@ -22,6 +22,20 @@ func (s *Server) handleAdminStats(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeJSON(w, http.StatusOK, map[string]any{"stats": stats})
|
writeJSON(w, http.StatusOK, map[string]any{"stats": stats})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) handleAdminGetUser(w http.ResponseWriter, r *http.Request) {
|
||||||
|
id := routeID(r, "id")
|
||||||
|
if id <= 0 {
|
||||||
|
writeErr(w, http.StatusNotFound, "کاربر پیدا نشد")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
u, err := s.store.GetUserByID(r.Context(), id)
|
||||||
|
if err != nil {
|
||||||
|
writeErr(w, http.StatusNotFound, "کاربر پیدا نشد")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
writeJSON(w, http.StatusOK, map[string]any{"user": u})
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) handleAdminListUsers(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleAdminListUsers(w http.ResponseWriter, r *http.Request) {
|
||||||
query := r.URL.Query().Get("q")
|
query := r.URL.Query().Get("q")
|
||||||
role := r.URL.Query().Get("role")
|
role := r.URL.Query().Get("role")
|
||||||
@@ -389,27 +403,17 @@ func (s *Server) handleAdminResetPassword(w http.ResponseWriter, r *http.Request
|
|||||||
writeErr(w, http.StatusForbidden, "دسترسی کافی ندارید")
|
writeErr(w, http.StatusForbidden, "دسترسی کافی ندارید")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
target, err := s.store.GetUserByID(r.Context(), id)
|
if _, err := s.store.GetUserByID(r.Context(), id); err != nil {
|
||||||
if err != nil {
|
|
||||||
writeErr(w, http.StatusNotFound, "کاربر پیدا نشد")
|
writeErr(w, http.StatusNotFound, "کاربر پیدا نشد")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var req struct {
|
var req struct {
|
||||||
SecurityAnswer string `json:"securityAnswer"`
|
NewPassword string `json:"newPassword"`
|
||||||
NewPassword string `json:"newPassword"`
|
|
||||||
}
|
}
|
||||||
if err := bodyJSON(r, &req); err != nil {
|
if err := bodyJSON(r, &req); err != nil {
|
||||||
writeErr(w, http.StatusBadRequest, "دادهٔ ارسالی نامعتبر است")
|
writeErr(w, http.StatusBadRequest, "دادهٔ ارسالی نامعتبر است")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if target.SecurityAnswerHash == "" {
|
|
||||||
writeErr(w, http.StatusBadRequest, "برای این کاربر سوال امنیتی تعریف نشده است")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if !s.auth.CheckPassword(target.SecurityAnswerHash, strings.ToLower(strings.TrimSpace(req.SecurityAnswer))) {
|
|
||||||
writeErr(w, http.StatusForbidden, "جواب سوال امنیتی نادرست است")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if msg := validatePasswordOnly(req.NewPassword); msg != "" {
|
if msg := validatePasswordOnly(req.NewPassword); msg != "" {
|
||||||
writeErr(w, http.StatusBadRequest, msg)
|
writeErr(w, http.StatusBadRequest, msg)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -306,6 +306,7 @@ func (s *Server) handlePutAvatar(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeErr(w, http.StatusInternalServerError, "بهروزرسانی آواتار ممکن نشد")
|
writeErr(w, http.StatusInternalServerError, "بهروزرسانی آواتار ممکن نشد")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
s.signUserMedia(user)
|
||||||
writeJSON(w, http.StatusOK, map[string]any{"user": user})
|
writeJSON(w, http.StatusOK, map[string]any{"user": user})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
captchaTTL = 5 * time.Minute
|
captchaTTL = 2 * time.Minute
|
||||||
captchaKeyPrefix = "pargar:captcha:"
|
captchaKeyPrefix = "pargar:captcha:"
|
||||||
captchaRateLimit int64 = 60
|
captchaRateLimit int64 = 60
|
||||||
captchaCharset = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"
|
captchaCharset = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"
|
||||||
@@ -260,6 +260,7 @@ func (s *Server) handleCaptcha(w http.ResponseWriter, r *http.Request) {
|
|||||||
resp := map[string]any{
|
resp := map[string]any{
|
||||||
"challengeId": "dev",
|
"challengeId": "dev",
|
||||||
"imageBase64": img,
|
"imageBase64": img,
|
||||||
|
"expiresIn": int(captchaTTL.Seconds()),
|
||||||
}
|
}
|
||||||
if s.cfg.CaptchaExposeAnswer {
|
if s.cfg.CaptchaExposeAnswer {
|
||||||
resp["answer"] = "A2B3"
|
resp["answer"] = "A2B3"
|
||||||
@@ -297,6 +298,7 @@ func (s *Server) handleCaptcha(w http.ResponseWriter, r *http.Request) {
|
|||||||
resp := map[string]any{
|
resp := map[string]any{
|
||||||
"challengeId": id,
|
"challengeId": id,
|
||||||
"imageBase64": img,
|
"imageBase64": img,
|
||||||
|
"expiresIn": int(captchaTTL.Seconds()),
|
||||||
}
|
}
|
||||||
// Never expose plaintext answers in production. Local tests may opt in via
|
// Never expose plaintext answers in production. Local tests may opt in via
|
||||||
// CAPTCHA_EXPOSE_ANSWER=true combined with DEV_MODE=true.
|
// CAPTCHA_EXPOSE_ANSWER=true combined with DEV_MODE=true.
|
||||||
|
|||||||
@@ -30,6 +30,10 @@ func TestCaptchaImageChallenge(t *testing.T) {
|
|||||||
if id == "" || img == "" || answer == "" {
|
if id == "" || img == "" || answer == "" {
|
||||||
t.Fatalf("captcha missing fields: %v", body)
|
t.Fatalf("captcha missing fields: %v", body)
|
||||||
}
|
}
|
||||||
|
exp, ok := body["expiresIn"].(float64)
|
||||||
|
if !ok || exp < 60 || exp > 180 {
|
||||||
|
t.Fatalf("expiresIn should be a short window: %v", body["expiresIn"])
|
||||||
|
}
|
||||||
if _, ok := body["question"]; ok {
|
if _, ok := body["question"]; ok {
|
||||||
t.Fatalf("legacy question field should be gone: %v", body)
|
t.Fatalf("legacy question field should be gone: %v", body)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -228,12 +228,22 @@ func (s *Server) handleRequestPhysicalCertificate(w http.ResponseWriter, r *http
|
|||||||
|
|
||||||
func (s *Server) handleAdminListPhysicalOrders(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleAdminListPhysicalOrders(w http.ResponseWriter, r *http.Request) {
|
||||||
status := r.URL.Query().Get("status")
|
status := r.URL.Query().Get("status")
|
||||||
orders, err := s.store.ListPhysicalOrders(r.Context(), status)
|
p := parsePageParams(r)
|
||||||
|
orders, total, err := s.store.ListPhysicalOrders(r.Context(), status, p.PageSize, p.Offset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErr(w, http.StatusInternalServerError, "بارگذاری سفارشها ممکن نشد")
|
writeErr(w, http.StatusInternalServerError, "بارگذاری سفارشها ممکن نشد")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
writeJSON(w, http.StatusOK, map[string]any{"orders": orders, "physical": s.physicalSettings(r.Context())})
|
if orders == nil {
|
||||||
|
orders = []models.CertificatePhysicalOrder{}
|
||||||
|
}
|
||||||
|
writeJSON(w, http.StatusOK, map[string]any{
|
||||||
|
"orders": orders,
|
||||||
|
"total": total,
|
||||||
|
"page": p.Page,
|
||||||
|
"pageSize": p.PageSize,
|
||||||
|
"physical": s.physicalSettings(r.Context()),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) handleAdminUpdatePhysicalOrder(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleAdminUpdatePhysicalOrder(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ func (s *Server) handleListMentors(w http.ResponseWriter, r *http.Request) {
|
|||||||
if actor.Role == models.RoleStudent && m.Role != models.RoleMentor && m.Role != models.RoleAdmin {
|
if actor.Role == models.RoleStudent && m.Role != models.RoleMentor && m.Role != models.RoleAdmin {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
s.signUserMedia(&m)
|
||||||
safe = append(safe, map[string]any{
|
safe = append(safe, map[string]any{
|
||||||
"id": m.ID, "name": m.Name, "email": m.Email, "role": m.Role,
|
"id": m.ID, "name": m.Name, "email": m.Email, "role": m.Role,
|
||||||
"avatarVariant": m.AvatarVariant, "avatarPalette": m.AvatarPalette, "avatarPhoto": m.AvatarPhoto,
|
"avatarVariant": m.AvatarVariant, "avatarPalette": m.AvatarPalette, "avatarPhoto": m.AvatarPhoto,
|
||||||
@@ -111,10 +112,16 @@ func (s *Server) handleConversations(w http.ResponseWriter, r *http.Request) {
|
|||||||
unread++
|
unread++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
photo := p.AvatarPhoto
|
||||||
|
if photo != "" {
|
||||||
|
tmp := &models.User{ID: p.ID, AvatarPhoto: photo}
|
||||||
|
s.signUserMedia(tmp)
|
||||||
|
photo = tmp.AvatarPhoto
|
||||||
|
}
|
||||||
conv := conversation{
|
conv := conversation{
|
||||||
Partner: map[string]any{
|
Partner: map[string]any{
|
||||||
"id": p.ID, "name": p.Name, "email": p.Email, "role": p.Role,
|
"id": p.ID, "name": p.Name, "email": p.Email, "role": p.Role,
|
||||||
"avatarVariant": p.AvatarVariant, "avatarPalette": p.AvatarPalette, "avatarPhoto": p.AvatarPhoto,
|
"avatarVariant": p.AvatarVariant, "avatarPalette": p.AvatarPalette, "avatarPhoto": photo,
|
||||||
"online": s.hub.Online(p.ID),
|
"online": s.hub.Online(p.ID),
|
||||||
},
|
},
|
||||||
UnreadCount: unread,
|
UnreadCount: unread,
|
||||||
@@ -137,6 +144,7 @@ func (s *Server) handleChatMessages(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeErr(w, http.StatusForbidden, "شما اجازهٔ گفتگو با این کاربر را ندارید")
|
writeErr(w, http.StatusForbidden, "شما اجازهٔ گفتگو با این کاربر را ندارید")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
_ = s.markIncomingChatRead(r.Context(), u, partner)
|
||||||
|
|
||||||
if raw := r.URL.Query().Get("around"); raw != "" {
|
if raw := r.URL.Query().Get("around"); raw != "" {
|
||||||
aroundID, err := strconv.ParseInt(raw, 10, 64)
|
aroundID, err := strconv.ParseInt(raw, 10, 64)
|
||||||
@@ -156,7 +164,6 @@ func (s *Server) handleChatMessages(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
_ = s.store.FillReactions(r.Context(), u.ID, msgs)
|
_ = s.store.FillReactions(r.Context(), u.ID, msgs)
|
||||||
_ = s.store.MarkChatRead(r.Context(), u.ID, partner)
|
|
||||||
s.resignChatMessages(msgs)
|
s.resignChatMessages(msgs)
|
||||||
pinned, _ := s.store.ListPinnedChatMessages(r.Context(), u.ID, partner)
|
pinned, _ := s.store.ListPinnedChatMessages(r.Context(), u.ID, partner)
|
||||||
if pinned == nil {
|
if pinned == nil {
|
||||||
@@ -197,7 +204,6 @@ func (s *Server) handleChatMessages(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ = s.store.FillReactions(r.Context(), u.ID, msgs)
|
_ = s.store.FillReactions(r.Context(), u.ID, msgs)
|
||||||
_ = s.store.MarkChatRead(r.Context(), u.ID, partner)
|
|
||||||
s.resignChatMessages(msgs)
|
s.resignChatMessages(msgs)
|
||||||
pinned, _ := s.store.ListPinnedChatMessages(r.Context(), u.ID, partner)
|
pinned, _ := s.store.ListPinnedChatMessages(r.Context(), u.ID, partner)
|
||||||
if pinned == nil {
|
if pinned == nil {
|
||||||
@@ -337,6 +343,73 @@ func (s *Server) handleChatReact(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "emoji": emoji, "reactions": reactions})
|
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "emoji": emoji, "reactions": reactions})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) handleChatEdit(w http.ResponseWriter, r *http.Request) {
|
||||||
|
u := currentUser(r)
|
||||||
|
partner := routeID(r, "partner")
|
||||||
|
if !s.canChatWith(r.Context(), u, partner) {
|
||||||
|
writeErr(w, http.StatusForbidden, "شما اجازهٔ گفتگو با این کاربر را ندارید")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
msgID := routeID(r, "id")
|
||||||
|
var req struct {
|
||||||
|
Body string `json:"body"`
|
||||||
|
Attachment *models.Attachment `json:"attachment,omitempty"`
|
||||||
|
}
|
||||||
|
if err := bodyJSON(r, &req); err != nil {
|
||||||
|
writeErr(w, http.StatusBadRequest, "دادهٔ ارسالی نامعتبر است")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
req.Body = strings.TrimSpace(req.Body)
|
||||||
|
if len(req.Body) > 4000 {
|
||||||
|
writeErr(w, http.StatusBadRequest, "پیام باید بین ۱ تا ۴۰۰۰ نویسه باشد")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
msg *models.ChatMessage
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
if req.Attachment != nil {
|
||||||
|
att := req.Attachment
|
||||||
|
att.Type = strings.ToLower(strings.TrimSpace(att.Type))
|
||||||
|
if att.Type != "image" && att.Type != "video" && att.Type != "audio" {
|
||||||
|
writeErr(w, http.StatusBadRequest, "فقط عکس، ویدیو یا صدا را میتوان جایگزین کرد")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
key := mediaKeyFromURL(att.URL)
|
||||||
|
if key == "" || !mediaKeyOwnedByUser(key, u.ID) {
|
||||||
|
writeErr(w, http.StatusBadRequest, "پیوست متعلق به شما نیست")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if q := strings.Index(att.URL, "?"); q >= 0 {
|
||||||
|
att.URL = att.URL[:q]
|
||||||
|
}
|
||||||
|
if att.Name == "" {
|
||||||
|
att.Name = "file"
|
||||||
|
}
|
||||||
|
msg, err = s.store.ReplaceChatAttachment(r.Context(), u.ID, partner, msgID, u.Role, req.Body, att.Type, att.URL, att.Name, att.Size)
|
||||||
|
} else {
|
||||||
|
if req.Body == "" {
|
||||||
|
writeErr(w, http.StatusBadRequest, "پیام باید بین ۱ تا ۴۰۰۰ نویسه باشد")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
msg, err = s.store.EditChatMessage(r.Context(), u.ID, partner, msgID, u.Role, req.Body)
|
||||||
|
}
|
||||||
|
if errors.Is(err, store.ErrNotFound) {
|
||||||
|
writeErr(w, http.StatusNotFound, "پیام پیدا نشد")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
writeErr(w, http.StatusInternalServerError, "ویرایش پیام ممکن نشد")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.resignChatMessage(msg)
|
||||||
|
event := map[string]any{"type": "chat_edit", "item": msg, "from": u.ID}
|
||||||
|
s.hub.Push(u.ID, event)
|
||||||
|
s.hub.Push(partner, event)
|
||||||
|
writeJSON(w, http.StatusOK, map[string]any{"message": msg})
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) handleChatDelete(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleChatDelete(w http.ResponseWriter, r *http.Request) {
|
||||||
u := currentUser(r)
|
u := currentUser(r)
|
||||||
partner := routeID(r, "partner")
|
partner := routeID(r, "partner")
|
||||||
@@ -473,13 +546,25 @@ func (s *Server) handleChatRead(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeErr(w, http.StatusForbidden, "شما اجازهٔ گفتگو با این کاربر را ندارید")
|
writeErr(w, http.StatusForbidden, "شما اجازهٔ گفتگو با این کاربر را ندارید")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := s.store.MarkChatRead(r.Context(), u.ID, partner); err != nil {
|
if err := s.markIncomingChatRead(r.Context(), u, partner); err != nil {
|
||||||
writeErr(w, http.StatusInternalServerError, "بهروزرسانی وضعیت خواندهشدن ممکن نشد")
|
writeErr(w, http.StatusInternalServerError, "بهروزرسانی وضعیت خواندهشدن ممکن نشد")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
writeJSON(w, http.StatusOK, map[string]any{"ok": true})
|
writeJSON(w, http.StatusOK, map[string]any{"ok": true})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) markIncomingChatRead(ctx context.Context, reader *models.User, partnerID int64) error {
|
||||||
|
if reader == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
n, err := s.store.MarkChatRead(ctx, reader.ID, partnerID, reader.Role)
|
||||||
|
if err != nil || n == 0 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
s.hub.Push(partnerID, map[string]any{"type": "chat_read", "from": reader.ID})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) canChatWith(ctx context.Context, actor *models.User, partnerID int64) bool {
|
func (s *Server) canChatWith(ctx context.Context, actor *models.User, partnerID int64) bool {
|
||||||
if actor == nil || partnerID <= 0 || actor.ID == partnerID {
|
if actor == nil || partnerID <= 0 || actor.ID == partnerID {
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ type chatExportMessage struct {
|
|||||||
ReplyTo *int64 `json:"replyTo,omitempty"`
|
ReplyTo *int64 `json:"replyTo,omitempty"`
|
||||||
Pinned bool `json:"pinned"`
|
Pinned bool `json:"pinned"`
|
||||||
PinnedAt *time.Time `json:"pinnedAt,omitempty"`
|
PinnedAt *time.Time `json:"pinnedAt,omitempty"`
|
||||||
|
EditedAt *time.Time `json:"editedAt,omitempty"`
|
||||||
Attachment *chatExportAttachment `json:"attachment,omitempty"`
|
Attachment *chatExportAttachment `json:"attachment,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,6 +184,7 @@ func (s *Server) buildProjectChatExport(r *http.Request) (*chatExportPayload, []
|
|||||||
ReplyTo: m.ReplyTo,
|
ReplyTo: m.ReplyTo,
|
||||||
Pinned: m.PinnedAt != nil,
|
Pinned: m.PinnedAt != nil,
|
||||||
PinnedAt: m.PinnedAt,
|
PinnedAt: m.PinnedAt,
|
||||||
|
EditedAt: m.EditedAt,
|
||||||
}
|
}
|
||||||
if m.Attachment != nil {
|
if m.Attachment != nil {
|
||||||
att := &chatExportAttachment{
|
att := &chatExportAttachment{
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ func TestUniquePhone(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAdminResetPasswordRequiresSecurityAnswer(t *testing.T) {
|
func TestAdminResetPassword(t *testing.T) {
|
||||||
e := setup(t)
|
e := setup(t)
|
||||||
admin := login(t, e, bootstrapAdminEmail)
|
admin := login(t, e, bootstrapAdminEmail)
|
||||||
code, body := e.do(t, "POST", "/api/admin/users", admin, map[string]any{
|
code, body := e.do(t, "POST", "/api/admin/users", admin, map[string]any{
|
||||||
@@ -59,14 +59,14 @@ func TestAdminResetPasswordRequiresSecurityAnswer(t *testing.T) {
|
|||||||
uid := int64(body["user"].(map[string]any)["id"].(float64))
|
uid := int64(body["user"].(map[string]any)["id"].(float64))
|
||||||
|
|
||||||
code, _ = e.do(t, "POST", "/api/admin/users/"+itoa(uid)+"/reset-password", admin, map[string]any{
|
code, _ = e.do(t, "POST", "/api/admin/users/"+itoa(uid)+"/reset-password", admin, map[string]any{
|
||||||
"securityAnswer": "اشتباه", "newPassword": "newpass123",
|
"newPassword": "short",
|
||||||
})
|
})
|
||||||
if code != http.StatusForbidden {
|
if code != http.StatusBadRequest {
|
||||||
t.Fatalf("wrong answer should 403, got %d", code)
|
t.Fatalf("short password: %d", code)
|
||||||
}
|
}
|
||||||
|
|
||||||
code, body = e.do(t, "POST", "/api/admin/users/"+itoa(uid)+"/reset-password", admin, map[string]any{
|
code, body = e.do(t, "POST", "/api/admin/users/"+itoa(uid)+"/reset-password", admin, map[string]any{
|
||||||
"securityAnswer": "تهران", "newPassword": "newpass123",
|
"newPassword": "newpass123",
|
||||||
})
|
})
|
||||||
if code != http.StatusOK {
|
if code != http.StatusOK {
|
||||||
t.Fatalf("reset: %d %v", code, body)
|
t.Fatalf("reset: %d %v", code, body)
|
||||||
|
|||||||
@@ -130,16 +130,8 @@ func (s *Server) handleRegisterInvite(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ip := clientAddress(r)
|
ip, ok := s.registrationClientIP(w, r)
|
||||||
if ip == "" || ip == "unknown" {
|
if !ok {
|
||||||
writeErr(w, http.StatusBadRequest, "آدرس شبکه شناسایی نشد")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if taken, err := s.store.HasRegistrationIP(r.Context(), ip); err != nil {
|
|
||||||
writeErr(w, http.StatusInternalServerError, "بررسی محدودیت ثبتنام ممکن نشد")
|
|
||||||
return
|
|
||||||
} else if taken {
|
|
||||||
writeErr(w, http.StatusConflict, "از این شبکه قبلاً ثبتنام انجام شده است")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,8 +284,15 @@ func (s *Server) handleAdminCreateInvite(w http.ResponseWriter, r *http.Request)
|
|||||||
|
|
||||||
func (s *Server) handleAdminListInvites(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleAdminListInvites(w http.ResponseWriter, r *http.Request) {
|
||||||
q := strings.TrimSpace(r.URL.Query().Get("q"))
|
q := strings.TrimSpace(r.URL.Query().Get("q"))
|
||||||
|
status := strings.TrimSpace(r.URL.Query().Get("status"))
|
||||||
|
switch models.InviteStatus(status) {
|
||||||
|
case "", models.InviteActive, models.InvitePaused, models.InviteRevoked, models.InviteExhausted:
|
||||||
|
default:
|
||||||
|
writeErr(w, http.StatusBadRequest, "وضعیت نامعتبر است")
|
||||||
|
return
|
||||||
|
}
|
||||||
p := parsePageParams(r)
|
p := parsePageParams(r)
|
||||||
invites, total, err := s.store.ListRegistrationInvites(r.Context(), q, p.PageSize, p.Offset)
|
invites, total, err := s.store.ListRegistrationInvites(r.Context(), q, status, p.PageSize, p.Offset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErr(w, http.StatusInternalServerError, "بارگذاری لینکهای عضویت ممکن نشد")
|
writeErr(w, http.StatusInternalServerError, "بارگذاری لینکهای عضویت ممکن نشد")
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -130,6 +130,7 @@ func TestInviteRevoke(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestInviteDuplicatePhoneAndIP(t *testing.T) {
|
func TestInviteDuplicatePhoneAndIP(t *testing.T) {
|
||||||
|
t.Setenv("REGISTRATION_ENFORCE_IP", "true")
|
||||||
e := setup(t)
|
e := setup(t)
|
||||||
inv := createInvite(t, e, 5, "", nil)
|
inv := createInvite(t, e, 5, "", nil)
|
||||||
token := inv["token"].(string)
|
token := inv["token"].(string)
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ func (s *Server) handleWeeklyLeaderboard(w http.ResponseWriter, r *http.Request)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
s.signUserMedia(usr)
|
||||||
entries = append(entries, lbEntry{
|
entries = append(entries, lbEntry{
|
||||||
UserID: sc.userID, Name: usr.Name, Email: usr.Email, XP: sc.xp, Rank: i + 1,
|
UserID: sc.userID, Name: usr.Name, Email: usr.Email, XP: sc.xp, Rank: i + 1,
|
||||||
AvatarVariant: usr.AvatarVariant, AvatarPalette: usr.AvatarPalette, AvatarPhoto: usr.AvatarPhoto,
|
AvatarVariant: usr.AvatarVariant, AvatarPalette: usr.AvatarPalette, AvatarPhoto: usr.AvatarPhoto,
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"pargar/backend/internal/observability"
|
"pargar/backend/internal/observability"
|
||||||
|
"pargar/backend/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Server) handleLearningOverview(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleLearningOverview(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -21,12 +23,25 @@ func (s *Server) handleLearningStudents(w http.ResponseWriter, r *http.Request)
|
|||||||
ctx, span := observability.StartSpan(r.Context(), "admin.learning.students")
|
ctx, span := observability.StartSpan(r.Context(), "admin.learning.students")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
q := r.URL.Query().Get("q")
|
q := r.URL.Query().Get("q")
|
||||||
rows, err := s.store.ListStudentLearning(ctx, q)
|
filter := r.URL.Query().Get("filter")
|
||||||
|
switch filter {
|
||||||
|
case "active", "locked":
|
||||||
|
default:
|
||||||
|
filter = ""
|
||||||
|
}
|
||||||
|
sort := r.URL.Query().Get("sort")
|
||||||
|
switch sort {
|
||||||
|
case "progress", "streak", "activity":
|
||||||
|
default:
|
||||||
|
sort = "xp"
|
||||||
|
}
|
||||||
|
p := parsePageParams(r)
|
||||||
|
rows, total, err := s.store.ListStudentLearning(ctx, q, filter, sort, p.PageSize, p.Offset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErr(w, http.StatusInternalServerError, "بارگذاری فهرست هنرجویان ممکن نشد")
|
writeErr(w, http.StatusInternalServerError, "بارگذاری فهرست هنرجویان ممکن نشد")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
writeJSON(w, http.StatusOK, map[string]any{"students": rows})
|
writePage(w, rows, total, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) handleUserLearning(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleUserLearning(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -34,9 +49,13 @@ func (s *Server) handleUserLearning(w http.ResponseWriter, r *http.Request) {
|
|||||||
defer span.End()
|
defer span.End()
|
||||||
id := routeID(r, "id")
|
id := routeID(r, "id")
|
||||||
detail, err := s.store.UserLearningDetail(ctx, id)
|
detail, err := s.store.UserLearningDetail(ctx, id)
|
||||||
if err != nil {
|
if errors.Is(err, store.ErrNotFound) {
|
||||||
writeErr(w, http.StatusNotFound, "کاربر پیدا نشد")
|
writeErr(w, http.StatusNotFound, "کاربر پیدا نشد")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if err != nil {
|
||||||
|
writeErr(w, http.StatusInternalServerError, "بارگذاری جزئیات یادگیری ممکن نشد")
|
||||||
|
return
|
||||||
|
}
|
||||||
writeJSON(w, http.StatusOK, map[string]any{"learning": detail})
|
writeJSON(w, http.StatusOK, map[string]any{"learning": detail})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,28 @@ import (
|
|||||||
"pargar/backend/internal/models"
|
"pargar/backend/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// mediaSignWindow keeps one signature for a stretch of time. The same object
|
||||||
|
// then keeps the same URL, so clients do not reload a photo that did not change.
|
||||||
|
const mediaSignWindow = 15 * time.Minute
|
||||||
|
|
||||||
|
func stableMediaExpiry(now time.Time, ttl, window time.Duration) int64 {
|
||||||
|
if window <= 0 {
|
||||||
|
window = mediaSignWindow
|
||||||
|
}
|
||||||
|
if ttl < window {
|
||||||
|
ttl = window
|
||||||
|
}
|
||||||
|
w := int64(window.Seconds())
|
||||||
|
slot := now.Unix() / w
|
||||||
|
return (slot+1)*w + int64(ttl.Seconds())
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) signMediaURL(key string) string {
|
func (s *Server) signMediaURL(key string) string {
|
||||||
key = strings.TrimPrefix(strings.TrimSpace(key), "/")
|
key = strings.TrimPrefix(strings.TrimSpace(key), "/")
|
||||||
if key == "" {
|
if key == "" {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
exp := time.Now().Add(s.cfg.MediaURLTTL).Unix()
|
exp := stableMediaExpiry(time.Now(), s.cfg.MediaURLTTL, mediaSignWindow)
|
||||||
sig := mediaHMAC(s.cfg.JWTSecret, key, exp)
|
sig := mediaHMAC(s.cfg.JWTSecret, key, exp)
|
||||||
return fmt.Sprintf("%s/media/%s?exp=%d&sig=%s",
|
return fmt.Sprintf("%s/media/%s?exp=%d&sig=%s",
|
||||||
s.cfg.PublicURL,
|
s.cfg.PublicURL,
|
||||||
|
|||||||
@@ -7,6 +7,24 @@ import (
|
|||||||
"pargar/backend/internal/config"
|
"pargar/backend/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestStableMediaExpiryHoldsInsideWindow(t *testing.T) {
|
||||||
|
start := time.Unix((1_700_000_000/900)*900, 0)
|
||||||
|
ttl := time.Hour
|
||||||
|
window := 15 * time.Minute
|
||||||
|
a := stableMediaExpiry(start, ttl, window)
|
||||||
|
b := stableMediaExpiry(start.Add(14*time.Minute), ttl, window)
|
||||||
|
if a != b {
|
||||||
|
t.Fatalf("same window should keep one expiry: %d vs %d", a, b)
|
||||||
|
}
|
||||||
|
c := stableMediaExpiry(start.Add(15*time.Minute), ttl, window)
|
||||||
|
if c == a {
|
||||||
|
t.Fatal("next window should mint a new expiry")
|
||||||
|
}
|
||||||
|
if c < a {
|
||||||
|
t.Fatal("expiry should move forward")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestMediaSignatureRoundTrip(t *testing.T) {
|
func TestMediaSignatureRoundTrip(t *testing.T) {
|
||||||
s := &Server{cfg: &config.Config{JWTSecret: "test-secret-at-least-32-chars-long!!", PublicURL: "http://localhost", MediaURLTTL: time.Hour}}
|
s := &Server{cfg: &config.Config{JWTSecret: "test-secret-at-least-32-chars-long!!", PublicURL: "http://localhost", MediaURLTTL: time.Hour}}
|
||||||
url := s.signMediaURL("videos/lesson-1.mp4")
|
url := s.signMediaURL("videos/lesson-1.mp4")
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"pargar/backend/internal/store"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *Server) handlePublicProfile(w http.ResponseWriter, r *http.Request) {
|
||||||
|
id := routeID(r, "id")
|
||||||
|
if id <= 0 {
|
||||||
|
writeErr(w, http.StatusNotFound, "کاربر پیدا نشد")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
u, err := s.store.GetUserByID(r.Context(), id)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, store.ErrNotFound) {
|
||||||
|
writeErr(w, http.StatusNotFound, "کاربر پیدا نشد")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
writeErr(w, http.StatusInternalServerError, "بارگذاری پروفایل ممکن نشد")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.signUserMedia(u)
|
||||||
|
writeJSON(w, http.StatusOK, map[string]any{
|
||||||
|
"user": map[string]any{
|
||||||
|
"id": u.ID,
|
||||||
|
"name": u.Name,
|
||||||
|
"username": u.Username,
|
||||||
|
"role": u.Role,
|
||||||
|
"xp": u.XP,
|
||||||
|
"hearts": u.Hearts,
|
||||||
|
"streakCurrent": u.StreakCurrent,
|
||||||
|
"streakLongest": u.StreakLongest,
|
||||||
|
"avatarVariant": u.AvatarVariant,
|
||||||
|
"avatarPalette": u.AvatarPalette,
|
||||||
|
"avatarPhoto": u.AvatarPhoto,
|
||||||
|
"isLocked": u.IsLocked,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Public self-service password recovery is disabled for students.
|
// Public self-service password recovery is disabled for students.
|
||||||
// Staff reset passwords from the admin panel (requires the account security answer).
|
// Staff set a new password from the admin profile. Public recovery stays off.
|
||||||
|
|
||||||
func (s *Server) handleRecoveryChallenge(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleRecoveryChallenge(w http.ResponseWriter, r *http.Request) {
|
||||||
writeErr(w, http.StatusNotFound, "بازیابی رمز عمومی غیرفعال است")
|
writeErr(w, http.StatusNotFound, "بازیابی رمز عمومی غیرفعال است")
|
||||||
|
|||||||
@@ -27,6 +27,29 @@ func (s *Server) registrationRequireWhitelist(r *http.Request) bool {
|
|||||||
return s.settingTruthy(r, "registration_require_whitelist", true)
|
return s.settingTruthy(r, "registration_require_whitelist", true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// registrationClientIP returns the IP to bind to a registration when enforcement is on.
|
||||||
|
// When REGISTRATION_ENFORCE_IP is false (default), returns "" so NAT / shared egress is ignored.
|
||||||
|
func (s *Server) registrationClientIP(w http.ResponseWriter, r *http.Request) (string, bool) {
|
||||||
|
if s.cfg == nil || !s.cfg.RegistrationEnforceIP {
|
||||||
|
return "", true
|
||||||
|
}
|
||||||
|
ip := clientAddress(r)
|
||||||
|
if ip == "" || ip == "unknown" {
|
||||||
|
writeErr(w, http.StatusBadRequest, "آدرس شبکه شناسایی نشد")
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
taken, err := s.store.HasRegistrationIP(r.Context(), ip)
|
||||||
|
if err != nil {
|
||||||
|
writeErr(w, http.StatusInternalServerError, "بررسی محدودیت ثبتنام ممکن نشد")
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
if taken {
|
||||||
|
writeErr(w, http.StatusConflict, "از این شبکه قبلاً ثبتنام انجام شده است")
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
return ip, true
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) handleRegisterStatus(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleRegisterStatus(w http.ResponseWriter, r *http.Request) {
|
||||||
writeJSON(w, http.StatusOK, map[string]any{
|
writeJSON(w, http.StatusOK, map[string]any{
|
||||||
"enabled": s.registrationEnabled(r),
|
"enabled": s.registrationEnabled(r),
|
||||||
@@ -83,16 +106,8 @@ func (s *Server) handleRegister(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ip := clientAddress(r)
|
ip, ok := s.registrationClientIP(w, r)
|
||||||
if ip == "" || ip == "unknown" {
|
if !ok {
|
||||||
writeErr(w, http.StatusBadRequest, "آدرس شبکه شناسایی نشد")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if taken, err := s.store.HasRegistrationIP(r.Context(), ip); err != nil {
|
|
||||||
writeErr(w, http.StatusInternalServerError, "بررسی محدودیت ثبتنام ممکن نشد")
|
|
||||||
return
|
|
||||||
} else if taken {
|
|
||||||
writeErr(w, http.StatusConflict, "از این شبکه قبلاً ثبتنام انجام شده است")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -261,6 +261,7 @@ func TestRegisterDuplicatePhone(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRegisterSameIPRejected(t *testing.T) {
|
func TestRegisterSameIPRejected(t *testing.T) {
|
||||||
|
t.Setenv("REGISTRATION_ENFORCE_IP", "true")
|
||||||
e := setup(t)
|
e := setup(t)
|
||||||
enableRegistration(t, e)
|
enableRegistration(t, e)
|
||||||
whitelistPhones(t, e, "09121110007", "09121110008")
|
whitelistPhones(t, e, "09121110007", "09121110008")
|
||||||
@@ -278,7 +279,27 @@ func TestRegisterSameIPRejected(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRegisterSameIPAllowedWhenEnforcementOff(t *testing.T) {
|
||||||
|
t.Setenv("REGISTRATION_ENFORCE_IP", "false")
|
||||||
|
e := setup(t)
|
||||||
|
enableRegistration(t, e)
|
||||||
|
whitelistPhones(t, e, "09121110007", "09121110008")
|
||||||
|
|
||||||
|
headers := map[string]string{"X-Forwarded-For": "203.0.113.40"}
|
||||||
|
code, body := e.doHeaders(t, "POST", "/api/auth/register", "", headers,
|
||||||
|
registerBody(t, e, "09121110007", "reg-ipoff1@test.dev", "regipoff1"))
|
||||||
|
if code != http.StatusCreated {
|
||||||
|
t.Fatalf("first: %d %v", code, body)
|
||||||
|
}
|
||||||
|
code, body = e.doHeaders(t, "POST", "/api/auth/register", "", headers,
|
||||||
|
registerBody(t, e, "09121110008", "reg-ipoff2@test.dev", "regipoff2"))
|
||||||
|
if code != http.StatusCreated {
|
||||||
|
t.Fatalf("same IP must be allowed when REGISTRATION_ENFORCE_IP=false: %d %v", code, body)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestRegisterUsesForwardedIP(t *testing.T) {
|
func TestRegisterUsesForwardedIP(t *testing.T) {
|
||||||
|
t.Setenv("REGISTRATION_ENFORCE_IP", "true")
|
||||||
e := setup(t)
|
e := setup(t)
|
||||||
enableRegistration(t, e)
|
enableRegistration(t, e)
|
||||||
whitelistPhones(t, e, "09121110009", "09121110010", "09121110011")
|
whitelistPhones(t, e, "09121110009", "09121110010", "09121110011")
|
||||||
|
|||||||
@@ -56,7 +56,9 @@ func newRouter(s *Server) http.Handler {
|
|||||||
mux.HandleFunc("GET /api/chats/conversations", s.requireAuth(s.handleConversations))
|
mux.HandleFunc("GET /api/chats/conversations", s.requireAuth(s.handleConversations))
|
||||||
mux.HandleFunc("GET /api/chats/{partner}/messages", s.requireAuth(s.handleChatMessages))
|
mux.HandleFunc("GET /api/chats/{partner}/messages", s.requireAuth(s.handleChatMessages))
|
||||||
mux.HandleFunc("POST /api/chats/{partner}/messages", s.requireAuth(s.handleChatSend))
|
mux.HandleFunc("POST /api/chats/{partner}/messages", s.requireAuth(s.handleChatSend))
|
||||||
|
mux.HandleFunc("PUT /api/chats/{partner}/messages/{id}", s.requireAuth(s.handleChatEdit))
|
||||||
mux.HandleFunc("DELETE /api/chats/{partner}/messages/{id}", s.requireAuth(s.handleChatDelete))
|
mux.HandleFunc("DELETE /api/chats/{partner}/messages/{id}", s.requireAuth(s.handleChatDelete))
|
||||||
|
mux.HandleFunc("GET /api/users/{id}", s.requireAuth(s.handlePublicProfile))
|
||||||
mux.HandleFunc("POST /api/chats/{partner}/messages/{id}/reaction", s.requireAuth(s.handleChatReact))
|
mux.HandleFunc("POST /api/chats/{partner}/messages/{id}/reaction", s.requireAuth(s.handleChatReact))
|
||||||
mux.HandleFunc("POST /api/chats/{partner}/messages/{id}/pin", s.requireAuth(s.handleChatPin))
|
mux.HandleFunc("POST /api/chats/{partner}/messages/{id}/pin", s.requireAuth(s.handleChatPin))
|
||||||
mux.HandleFunc("POST /api/chats/upload", s.requireAuth(s.perUserRateLimit(uploadRateLimit, "upload", s.handleChatUpload)))
|
mux.HandleFunc("POST /api/chats/upload", s.requireAuth(s.perUserRateLimit(uploadRateLimit, "upload", s.handleChatUpload)))
|
||||||
@@ -89,6 +91,7 @@ func newRouter(s *Server) http.Handler {
|
|||||||
mux.HandleFunc("GET /api/admin/users/{id}/learning", staff(s.handleUserLearning))
|
mux.HandleFunc("GET /api/admin/users/{id}/learning", staff(s.handleUserLearning))
|
||||||
// Account administration is admin-only; mentors may unlock locked students only.
|
// Account administration is admin-only; mentors may unlock locked students only.
|
||||||
mux.HandleFunc("GET /api/admin/users", admin(s.handleAdminListUsers))
|
mux.HandleFunc("GET /api/admin/users", admin(s.handleAdminListUsers))
|
||||||
|
mux.HandleFunc("GET /api/admin/users/{id}", admin(s.handleAdminGetUser))
|
||||||
mux.HandleFunc("POST /api/admin/users", admin(s.handleAdminCreateUser))
|
mux.HandleFunc("POST /api/admin/users", admin(s.handleAdminCreateUser))
|
||||||
mux.HandleFunc("POST /api/admin/users/{id}/lock", admin(s.handleAdminLockUser))
|
mux.HandleFunc("POST /api/admin/users/{id}/lock", admin(s.handleAdminLockUser))
|
||||||
mux.HandleFunc("POST /api/admin/users/{id}/unlock", staff(s.handleAdminUnlockUser))
|
mux.HandleFunc("POST /api/admin/users/{id}/unlock", staff(s.handleAdminUnlockUser))
|
||||||
|
|||||||
@@ -0,0 +1,330 @@
|
|||||||
|
package api_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestChatEditOwnMessage(t *testing.T) {
|
||||||
|
e := setup(t)
|
||||||
|
student, studentID := register(t, e, "Chat Editor", "chat-editor@test.dev")
|
||||||
|
admin := login(t, e, bootstrapAdminEmail)
|
||||||
|
code, me := e.do(t, "GET", "/api/auth/me", admin, nil)
|
||||||
|
if code != 200 {
|
||||||
|
t.Fatalf("me: %d %v", code, me)
|
||||||
|
}
|
||||||
|
adminID := int64(me["user"].(map[string]any)["id"].(float64))
|
||||||
|
|
||||||
|
code, body := e.do(t, "POST", "/api/chats/"+itoa(adminID)+"/messages", student, map[string]any{"body": "سلام"})
|
||||||
|
if code != 201 {
|
||||||
|
t.Fatalf("send: %d %v", code, body)
|
||||||
|
}
|
||||||
|
msg := body["message"].(map[string]any)
|
||||||
|
msgID := int64(msg["id"].(float64))
|
||||||
|
|
||||||
|
code, body = e.do(t, "PUT", "/api/chats/"+itoa(adminID)+"/messages/"+itoa(msgID), student, map[string]any{"body": "سلام ویرایش"})
|
||||||
|
if code != 200 {
|
||||||
|
t.Fatalf("edit: %d %v", code, body)
|
||||||
|
}
|
||||||
|
edited := body["message"].(map[string]any)
|
||||||
|
if edited["body"] != "سلام ویرایش" || edited["editedAt"] == nil {
|
||||||
|
t.Fatalf("expected edited body, got %v", edited)
|
||||||
|
}
|
||||||
|
|
||||||
|
code, _ = e.do(t, "PUT", "/api/chats/"+itoa(studentID)+"/messages/"+itoa(msgID), admin, map[string]any{"body": "نه"})
|
||||||
|
if code != 404 {
|
||||||
|
t.Fatalf("partner edit should be rejected: %d", code)
|
||||||
|
}
|
||||||
|
|
||||||
|
code, _ = e.do(t, "PUT", "/api/chats/"+itoa(adminID)+"/messages/"+itoa(msgID), student, map[string]any{"body": " "})
|
||||||
|
if code != 400 {
|
||||||
|
t.Fatalf("empty edit: %d", code)
|
||||||
|
}
|
||||||
|
|
||||||
|
code, body = e.do(t, "GET", "/api/chats/"+itoa(adminID)+"/messages", student, nil)
|
||||||
|
if code != 200 {
|
||||||
|
t.Fatalf("list: %d %v", code, body)
|
||||||
|
}
|
||||||
|
msgs := body["messages"].([]any)
|
||||||
|
last := msgs[len(msgs)-1].(map[string]any)
|
||||||
|
if last["body"] != "سلام ویرایش" || last["editedAt"] == nil {
|
||||||
|
t.Fatalf("listed message not edited: %v", last)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestChatReplaceAttachment(t *testing.T) {
|
||||||
|
e := setup(t)
|
||||||
|
student, studentID := register(t, e, "Media Editor", "media-editor@test.dev")
|
||||||
|
admin := login(t, e, bootstrapAdminEmail)
|
||||||
|
code, me := e.do(t, "GET", "/api/auth/me", admin, nil)
|
||||||
|
if code != 200 {
|
||||||
|
t.Fatalf("me: %d %v", code, me)
|
||||||
|
}
|
||||||
|
adminID := int64(me["user"].(map[string]any)["id"].(float64))
|
||||||
|
|
||||||
|
png := []byte{0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00}
|
||||||
|
code, up := uploadChatFile(t, e, student, "one.png", png)
|
||||||
|
if code != 201 {
|
||||||
|
t.Fatalf("upload: %d %v", code, up)
|
||||||
|
}
|
||||||
|
first := up["attachment"].(map[string]any)
|
||||||
|
|
||||||
|
code, body := e.do(t, "POST", "/api/chats/"+itoa(adminID)+"/messages", student, map[string]any{
|
||||||
|
"body": "",
|
||||||
|
"attachment": first,
|
||||||
|
})
|
||||||
|
if code != 201 {
|
||||||
|
t.Fatalf("send: %d %v", code, body)
|
||||||
|
}
|
||||||
|
msg := body["message"].(map[string]any)
|
||||||
|
msgID := int64(msg["id"].(float64))
|
||||||
|
oldPath := mediaPath(msg["attachment"].(map[string]any)["url"])
|
||||||
|
|
||||||
|
png[8] = 0x01
|
||||||
|
code, up = uploadChatFile(t, e, student, "two.png", png)
|
||||||
|
if code != 201 {
|
||||||
|
t.Fatalf("upload replacement: %d %v", code, up)
|
||||||
|
}
|
||||||
|
next := up["attachment"].(map[string]any)
|
||||||
|
|
||||||
|
code, body = e.do(t, "PUT", "/api/chats/"+itoa(adminID)+"/messages/"+itoa(msgID), student, map[string]any{
|
||||||
|
"body": "",
|
||||||
|
"attachment": next,
|
||||||
|
})
|
||||||
|
if code != 200 {
|
||||||
|
t.Fatalf("replace: %d %v", code, body)
|
||||||
|
}
|
||||||
|
edited := body["message"].(map[string]any)
|
||||||
|
newPath := mediaPath(edited["attachment"].(map[string]any)["url"])
|
||||||
|
if edited["editedAt"] == nil || newPath == "" || newPath == oldPath {
|
||||||
|
t.Fatalf("expected a replaced attachment, old %s new %v", oldPath, edited)
|
||||||
|
}
|
||||||
|
if edited["attachment"].(map[string]any)["type"] != "image" {
|
||||||
|
t.Fatalf("type: %v", edited["attachment"])
|
||||||
|
}
|
||||||
|
|
||||||
|
wrong := map[string]any{"type": "video", "url": next["url"], "name": "clip.mp4", "size": next["size"]}
|
||||||
|
code, _ = e.do(t, "PUT", "/api/chats/"+itoa(adminID)+"/messages/"+itoa(msgID), student, map[string]any{
|
||||||
|
"body": "",
|
||||||
|
"attachment": wrong,
|
||||||
|
})
|
||||||
|
if code != 404 {
|
||||||
|
t.Fatalf("different kind should miss: %d", code)
|
||||||
|
}
|
||||||
|
|
||||||
|
code, _ = e.do(t, "PUT", "/api/chats/"+itoa(adminID)+"/messages/"+itoa(msgID), student, map[string]any{
|
||||||
|
"body": "",
|
||||||
|
"attachment": map[string]any{"type": "file", "url": next["url"], "name": "x.pdf", "size": 1},
|
||||||
|
})
|
||||||
|
if code != 400 {
|
||||||
|
t.Fatalf("file replace: %d", code)
|
||||||
|
}
|
||||||
|
|
||||||
|
code, _ = e.do(t, "PUT", "/api/chats/"+itoa(studentID)+"/messages/"+itoa(msgID), admin, map[string]any{
|
||||||
|
"body": "",
|
||||||
|
"attachment": next,
|
||||||
|
})
|
||||||
|
if code != 400 {
|
||||||
|
t.Fatalf("partner replace: %d", code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestChatReadMarksOnlyIncoming(t *testing.T) {
|
||||||
|
e := setup(t)
|
||||||
|
student, studentID := register(t, e, "Seen Student", "seen-student@test.dev")
|
||||||
|
admin := login(t, e, bootstrapAdminEmail)
|
||||||
|
code, me := e.do(t, "GET", "/api/auth/me", admin, nil)
|
||||||
|
if code != 200 {
|
||||||
|
t.Fatalf("me: %d %v", code, me)
|
||||||
|
}
|
||||||
|
adminID := int64(me["user"].(map[string]any)["id"].(float64))
|
||||||
|
|
||||||
|
code, body := e.do(t, "POST", "/api/chats/"+itoa(adminID)+"/messages", student, map[string]any{"body": "از هنرجو"})
|
||||||
|
if code != 201 {
|
||||||
|
t.Fatalf("student send: %d %v", code, body)
|
||||||
|
}
|
||||||
|
studentMsg := int64(body["message"].(map[string]any)["id"].(float64))
|
||||||
|
|
||||||
|
code, body = e.do(t, "GET", "/api/chats/"+itoa(adminID)+"/messages", student, nil)
|
||||||
|
if code != 200 {
|
||||||
|
t.Fatalf("student list: %d %v", code, body)
|
||||||
|
}
|
||||||
|
if chatMsg(t, body, studentMsg)["readAt"] != nil {
|
||||||
|
t.Fatalf("opening my own thread marked it seen: %v", chatMsg(t, body, studentMsg))
|
||||||
|
}
|
||||||
|
|
||||||
|
code, body = e.do(t, "GET", "/api/chats/"+itoa(studentID)+"/messages", admin, nil)
|
||||||
|
if code != 200 {
|
||||||
|
t.Fatalf("admin list: %d %v", code, body)
|
||||||
|
}
|
||||||
|
if chatMsg(t, body, studentMsg)["readAt"] == nil {
|
||||||
|
t.Fatalf("partner open should mark the incoming message seen")
|
||||||
|
}
|
||||||
|
|
||||||
|
code, body = e.do(t, "POST", "/api/chats/"+itoa(studentID)+"/messages", admin, map[string]any{"body": "از ادمین"})
|
||||||
|
if code != 201 {
|
||||||
|
t.Fatalf("admin send: %d %v", code, body)
|
||||||
|
}
|
||||||
|
adminMsg := int64(body["message"].(map[string]any)["id"].(float64))
|
||||||
|
|
||||||
|
code, body = e.do(t, "GET", "/api/chats/"+itoa(studentID)+"/messages", admin, nil)
|
||||||
|
if code != 200 {
|
||||||
|
t.Fatalf("admin list again: %d %v", code, body)
|
||||||
|
}
|
||||||
|
if chatMsg(t, body, adminMsg)["readAt"] != nil {
|
||||||
|
t.Fatalf("admin own message was marked seen: %v", chatMsg(t, body, adminMsg))
|
||||||
|
}
|
||||||
|
if chatMsg(t, body, studentMsg)["readAt"] == nil {
|
||||||
|
t.Fatalf("already seen incoming message lost its receipt")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func chatMsg(t *testing.T, body map[string]any, id int64) map[string]any {
|
||||||
|
t.Helper()
|
||||||
|
for _, raw := range body["messages"].([]any) {
|
||||||
|
msg := raw.(map[string]any)
|
||||||
|
if int64(msg["id"].(float64)) == id {
|
||||||
|
return msg
|
||||||
|
}
|
||||||
|
}
|
||||||
|
t.Fatalf("message %d missing in %v", id, body["messages"])
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func mediaPath(raw any) string {
|
||||||
|
s, _ := raw.(string)
|
||||||
|
if i := strings.IndexByte(s, '?'); i >= 0 {
|
||||||
|
return s[:i]
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLearningDetailMatchesActiveStudents(t *testing.T) {
|
||||||
|
e := setup(t)
|
||||||
|
admin := login(t, e, bootstrapAdminEmail)
|
||||||
|
|
||||||
|
code, body := e.do(t, "GET", "/api/admin/stats", admin, nil)
|
||||||
|
if code != 200 {
|
||||||
|
t.Fatalf("stats: %d %v", code, body)
|
||||||
|
}
|
||||||
|
if body["stats"].(map[string]any)["users"].(float64) != 0 {
|
||||||
|
t.Fatalf("overview should ignore staff, got %v", body["stats"])
|
||||||
|
}
|
||||||
|
|
||||||
|
_, uid := register(t, e, "Active Student", "active-student@test.dev")
|
||||||
|
|
||||||
|
code, body = e.do(t, "GET", "/api/admin/stats", admin, nil)
|
||||||
|
if code != 200 {
|
||||||
|
t.Fatalf("stats after student: %d %v", code, body)
|
||||||
|
}
|
||||||
|
if body["stats"].(map[string]any)["users"].(float64) != 1 {
|
||||||
|
t.Fatalf("expected 1 active student, got %v", body["stats"])
|
||||||
|
}
|
||||||
|
|
||||||
|
code, body = e.do(t, "GET", "/api/admin/learning/overview", admin, nil)
|
||||||
|
if code != 200 {
|
||||||
|
t.Fatalf("overview: %d %v", code, body)
|
||||||
|
}
|
||||||
|
if body["overview"].(map[string]any)["studentsActive"].(float64) != 1 {
|
||||||
|
t.Fatalf("learning active mismatch: %v", body["overview"])
|
||||||
|
}
|
||||||
|
|
||||||
|
code, body = e.do(t, "GET", "/api/admin/users/"+itoa(uid)+"/learning", admin, nil)
|
||||||
|
if code != 200 {
|
||||||
|
t.Fatalf("learning detail: %d %v", code, body)
|
||||||
|
}
|
||||||
|
user := body["learning"].(map[string]any)["user"].(map[string]any)
|
||||||
|
if user["name"] != "Active Student" {
|
||||||
|
t.Fatalf("detail user: %v", user)
|
||||||
|
}
|
||||||
|
|
||||||
|
code, body = e.do(t, "GET", "/api/admin/users/999999/learning", admin, nil)
|
||||||
|
if code != 404 {
|
||||||
|
t.Fatalf("missing user: %d %v", code, body)
|
||||||
|
}
|
||||||
|
|
||||||
|
code, body = e.do(t, "GET", "/api/admin/learning/students?page=1&pageSize=10", admin, nil)
|
||||||
|
if code != 200 {
|
||||||
|
t.Fatalf("students page: %d %v", code, body)
|
||||||
|
}
|
||||||
|
if body["total"].(float64) != 1 || len(body["items"].([]any)) != 1 {
|
||||||
|
t.Fatalf("expected one page row, got %v", body)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInviteStatusFilter(t *testing.T) {
|
||||||
|
e := setup(t)
|
||||||
|
admin := login(t, e, bootstrapAdminEmail)
|
||||||
|
code, body := e.do(t, "POST", "/api/admin/invites", admin, map[string]any{"maxUses": 2, "label": "مهر"})
|
||||||
|
if code != 201 {
|
||||||
|
t.Fatalf("create invite: %d %v", code, body)
|
||||||
|
}
|
||||||
|
code, body = e.do(t, "GET", "/api/admin/invites?status=active", admin, nil)
|
||||||
|
if code != 200 {
|
||||||
|
t.Fatalf("active filter: %d %v", code, body)
|
||||||
|
}
|
||||||
|
if body["total"].(float64) < 1 {
|
||||||
|
t.Fatalf("expected active invites, got %v", body)
|
||||||
|
}
|
||||||
|
code, body = e.do(t, "GET", "/api/admin/invites?status=revoked", admin, nil)
|
||||||
|
if code != 200 {
|
||||||
|
t.Fatalf("revoked filter: %d %v", code, body)
|
||||||
|
}
|
||||||
|
if body["total"].(float64) != 0 {
|
||||||
|
t.Fatalf("expected no revoked invites, got %v", body)
|
||||||
|
}
|
||||||
|
code, body = e.do(t, "GET", "/api/admin/invites?status=nope", admin, nil)
|
||||||
|
if code != 400 {
|
||||||
|
t.Fatalf("bad status: %d %v", code, body)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPublicProfileOmitsPrivateFields(t *testing.T) {
|
||||||
|
e := setup(t)
|
||||||
|
student, studentID := register(t, e, "Public Name", "public-name@test.dev")
|
||||||
|
admin := login(t, e, bootstrapAdminEmail)
|
||||||
|
code, me := e.do(t, "GET", "/api/auth/me", admin, nil)
|
||||||
|
if code != 200 {
|
||||||
|
t.Fatalf("me: %d %v", code, me)
|
||||||
|
}
|
||||||
|
adminID := int64(me["user"].(map[string]any)["id"].(float64))
|
||||||
|
|
||||||
|
code, body := e.do(t, "GET", "/api/users/"+itoa(adminID), student, nil)
|
||||||
|
if code != 200 {
|
||||||
|
t.Fatalf("profile: %d %v", code, body)
|
||||||
|
}
|
||||||
|
user := body["user"].(map[string]any)
|
||||||
|
if user["name"] == nil || user["name"] == "" {
|
||||||
|
t.Fatalf("missing name: %v", user)
|
||||||
|
}
|
||||||
|
if _, ok := user["email"]; ok {
|
||||||
|
t.Fatalf("email must not be public: %v", user)
|
||||||
|
}
|
||||||
|
if _, ok := user["phone"]; ok {
|
||||||
|
t.Fatalf("phone must not be public: %v", user)
|
||||||
|
}
|
||||||
|
|
||||||
|
code, adminView := e.do(t, "GET", "/api/admin/users/"+itoa(studentID), admin, nil)
|
||||||
|
if code != 200 {
|
||||||
|
t.Fatalf("admin user: %d %v", code, adminView)
|
||||||
|
}
|
||||||
|
managed := adminView["user"].(map[string]any)
|
||||||
|
if managed["email"] != "public-name@test.dev" {
|
||||||
|
t.Fatalf("admin should see email: %v", managed)
|
||||||
|
}
|
||||||
|
if _, ok := managed["passwordHash"]; ok {
|
||||||
|
t.Fatalf("password hash must stay hidden: %v", managed)
|
||||||
|
}
|
||||||
|
code, hidden := e.do(t, "GET", "/api/admin/users/"+itoa(adminID), student, nil)
|
||||||
|
if code != 403 {
|
||||||
|
t.Fatalf("student must not open admin user: %d %v", code, hidden)
|
||||||
|
}
|
||||||
|
|
||||||
|
code, body = e.do(t, "GET", "/api/users/"+itoa(studentID), admin, nil)
|
||||||
|
if code != 200 {
|
||||||
|
t.Fatalf("student profile: %d %v", code, body)
|
||||||
|
}
|
||||||
|
if body["user"].(map[string]any)["username"] != "public-name" {
|
||||||
|
t.Fatalf("username: %v", body["user"])
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -46,6 +46,9 @@ type Config struct {
|
|||||||
PhysicalCertEnabled bool
|
PhysicalCertEnabled bool
|
||||||
PhysicalCertPriceIRR int
|
PhysicalCertPriceIRR int
|
||||||
PhysicalCertWindowDays int
|
PhysicalCertWindowDays int
|
||||||
|
// RegistrationEnforceIP limits one successful registration per client IP.
|
||||||
|
// Default false: behind NAT / shared egress the peer IP is not a real client identity.
|
||||||
|
RegistrationEnforceIP bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func getEnv(key, fallback string) string {
|
func getEnv(key, fallback string) string {
|
||||||
@@ -140,6 +143,7 @@ func Load() *Config {
|
|||||||
PhysicalCertEnabled: getEnv("PHYSICAL_CERT_ENABLED", "false") == "true",
|
PhysicalCertEnabled: getEnv("PHYSICAL_CERT_ENABLED", "false") == "true",
|
||||||
PhysicalCertPriceIRR: getEnvInt("PHYSICAL_CERT_PRICE_IRR", 2_500_000),
|
PhysicalCertPriceIRR: getEnvInt("PHYSICAL_CERT_PRICE_IRR", 2_500_000),
|
||||||
PhysicalCertWindowDays: getEnvInt("PHYSICAL_CERT_WINDOW_DAYS", 30),
|
PhysicalCertWindowDays: getEnvInt("PHYSICAL_CERT_WINDOW_DAYS", 30),
|
||||||
|
RegistrationEnforceIP: getEnv("REGISTRATION_ENFORCE_IP", "false") == "true",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
-- Own-message edits. Nullable so existing rows stay unedited.
|
||||||
|
ALTER TABLE chat_messages
|
||||||
|
ADD COLUMN IF NOT EXISTS edited_at TIMESTAMPTZ;
|
||||||
@@ -219,6 +219,7 @@ type ChatMessage struct {
|
|||||||
ReplyTo *int64 `json:"replyTo,omitempty"`
|
ReplyTo *int64 `json:"replyTo,omitempty"`
|
||||||
PinnedAt *time.Time `json:"pinnedAt,omitempty"`
|
PinnedAt *time.Time `json:"pinnedAt,omitempty"`
|
||||||
Pinned bool `json:"pinned"`
|
Pinned bool `json:"pinned"`
|
||||||
|
EditedAt *time.Time `json:"editedAt,omitempty"`
|
||||||
Attachment *Attachment `json:"attachment,omitempty"`
|
Attachment *Attachment `json:"attachment,omitempty"`
|
||||||
Reactions []ChatReaction `json:"reactions,omitempty"`
|
Reactions []ChatReaction `json:"reactions,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package storage
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestVoiceNoteContentType(t *testing.T) {
|
||||||
|
if got := mimeType("chats/2-1.weba"); got != "audio/webm" {
|
||||||
|
t.Fatalf("weba: %s", got)
|
||||||
|
}
|
||||||
|
if got := mediaContentType("chats/2-1.weba", "application/octet-stream"); got != "audio/webm" {
|
||||||
|
t.Fatalf("generic store type must not hide the voice type: %s", got)
|
||||||
|
}
|
||||||
|
if got := mediaContentType("chats/2-1.bin", "application/pdf"); got != "application/pdf" {
|
||||||
|
t.Fatalf("unknown extension keeps the stored type: %s", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -243,10 +243,11 @@ func (s *S3) Serve(w http.ResponseWriter, r *http.Request, key string) error {
|
|||||||
}
|
}
|
||||||
defer result.Body.Close()
|
defer result.Body.Close()
|
||||||
|
|
||||||
ct := mimeType(key)
|
stored := ""
|
||||||
if result.ContentType != nil && *result.ContentType != "" {
|
if result.ContentType != nil {
|
||||||
ct = *result.ContentType
|
stored = *result.ContentType
|
||||||
}
|
}
|
||||||
|
ct := mediaContentType(key, stored)
|
||||||
w.Header().Set("Content-Type", ct)
|
w.Header().Set("Content-Type", ct)
|
||||||
setInlineMediaHeaders(w, ct)
|
setInlineMediaHeaders(w, ct)
|
||||||
w.Header().Set("Accept-Ranges", "bytes")
|
w.Header().Set("Accept-Ranges", "bytes")
|
||||||
@@ -290,8 +291,20 @@ func mimeType(key string) string {
|
|||||||
return "video/mp4"
|
return "video/mp4"
|
||||||
case ".webm":
|
case ".webm":
|
||||||
return "video/webm"
|
return "video/webm"
|
||||||
|
case ".weba":
|
||||||
|
return "audio/webm"
|
||||||
case ".mp3":
|
case ".mp3":
|
||||||
return "audio/mpeg"
|
return "audio/mpeg"
|
||||||
|
case ".wav":
|
||||||
|
return "audio/wav"
|
||||||
|
case ".ogg", ".opus":
|
||||||
|
return "audio/ogg"
|
||||||
|
case ".m4a", ".aac":
|
||||||
|
return "audio/mp4"
|
||||||
|
case ".mov":
|
||||||
|
return "video/quicktime"
|
||||||
|
case ".m4v":
|
||||||
|
return "video/mp4"
|
||||||
case ".pdf":
|
case ".pdf":
|
||||||
return "application/pdf"
|
return "application/pdf"
|
||||||
default:
|
default:
|
||||||
@@ -299,6 +312,23 @@ func mimeType(key string) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mediaContentType keeps a known extension ahead of a generic object-store type.
|
||||||
|
// Voice notes are stored as .weba; a default octet-stream plus nosniff stops playback.
|
||||||
|
func mediaContentType(key, stored string) string {
|
||||||
|
guessed := mimeType(key)
|
||||||
|
if guessed != "application/octet-stream" {
|
||||||
|
return guessed
|
||||||
|
}
|
||||||
|
stored = strings.TrimSpace(stored)
|
||||||
|
if i := strings.Index(stored, ";"); i >= 0 {
|
||||||
|
stored = strings.TrimSpace(stored[:i])
|
||||||
|
}
|
||||||
|
if stored != "" {
|
||||||
|
return stored
|
||||||
|
}
|
||||||
|
return guessed
|
||||||
|
}
|
||||||
|
|
||||||
// setInlineMediaHeaders discourages "Save as" download UX while keeping streaming/Range intact.
|
// setInlineMediaHeaders discourages "Save as" download UX while keeping streaming/Range intact.
|
||||||
func setInlineMediaHeaders(w http.ResponseWriter, contentType string) {
|
func setInlineMediaHeaders(w http.ResponseWriter, contentType string) {
|
||||||
if contentType != "" {
|
if contentType != "" {
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ func (s *Store) CreateRegistrationInvite(
|
|||||||
return scanInvite(row)
|
return scanInvite(row)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) ListRegistrationInvites(ctx context.Context, query string, limit, offset int) ([]models.RegistrationInvite, int64, error) {
|
func (s *Store) ListRegistrationInvites(ctx context.Context, query, status string, limit, offset int) ([]models.RegistrationInvite, int64, error) {
|
||||||
if limit <= 0 {
|
if limit <= 0 {
|
||||||
limit = 10
|
limit = 10
|
||||||
}
|
}
|
||||||
@@ -157,18 +157,21 @@ func (s *Store) ListRegistrationInvites(ctx context.Context, query string, limit
|
|||||||
offset = 0
|
offset = 0
|
||||||
}
|
}
|
||||||
query = strings.TrimSpace(query)
|
query = strings.TrimSpace(query)
|
||||||
|
status = strings.TrimSpace(status)
|
||||||
var total int64
|
var total int64
|
||||||
if err := s.pool.QueryRow(ctx, `
|
if err := s.pool.QueryRow(ctx, `
|
||||||
SELECT COUNT(*) FROM registration_invites
|
SELECT COUNT(*) FROM registration_invites
|
||||||
WHERE ($1 = '' OR COALESCE(label, '') ILIKE '%'||$1||'%')`, query).Scan(&total); err != nil {
|
WHERE ($1 = '' OR COALESCE(label, '') ILIKE '%'||$1||'%')
|
||||||
|
AND ($2 = '' OR status = $2)`, query, status).Scan(&total); err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
rows, err := s.pool.Query(ctx, `
|
rows, err := s.pool.Query(ctx, `
|
||||||
SELECT `+inviteCols+`
|
SELECT `+inviteCols+`
|
||||||
FROM registration_invites
|
FROM registration_invites
|
||||||
WHERE ($1 = '' OR COALESCE(label, '') ILIKE '%'||$1||'%')
|
WHERE ($1 = '' OR COALESCE(label, '') ILIKE '%'||$1||'%')
|
||||||
|
AND ($2 = '' OR status = $2)
|
||||||
ORDER BY created_at DESC
|
ORDER BY created_at DESC
|
||||||
LIMIT $2 OFFSET $3`, query, limit, offset)
|
LIMIT $3 OFFSET $4`, query, status, limit, offset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
@@ -344,16 +347,14 @@ func EvaluateInviteAvailability(inv *models.RegistrationInvite, now time.Time) e
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterInviteStudent creates a student, consumes the IP, and atomically consumes one invite seat.
|
// RegisterInviteStudent creates a student, optionally records the client IP, and consumes one invite seat.
|
||||||
|
// Empty ip skips one-registration-per-IP enforcement (NAT / shared egress).
|
||||||
func (s *Store) RegisterInviteStudent(
|
func (s *Store) RegisterInviteStudent(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
inviteID int64,
|
inviteID int64,
|
||||||
name, email, username, passwordHash, phone, securityQuestion, securityAnswerHash, ip string,
|
name, email, username, passwordHash, phone, securityQuestion, securityAnswerHash, ip string,
|
||||||
) (*models.User, error) {
|
) (*models.User, error) {
|
||||||
ip = strings.TrimSpace(ip)
|
ip = strings.TrimSpace(ip)
|
||||||
if ip == "" {
|
|
||||||
return nil, errors.New("empty registration ip")
|
|
||||||
}
|
|
||||||
tx, err := s.pool.Begin(ctx)
|
tx, err := s.pool.Begin(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -366,12 +367,14 @@ func (s *Store) RegisterInviteStudent(
|
|||||||
return nil, ErrPhoneBlacklisted
|
return nil, ErrPhoneBlacklisted
|
||||||
}
|
}
|
||||||
|
|
||||||
var taken bool
|
if ip != "" {
|
||||||
if err := tx.QueryRow(ctx, `SELECT EXISTS(SELECT 1 FROM registration_ips WHERE ip=$1)`, ip).Scan(&taken); err != nil {
|
var taken bool
|
||||||
return nil, err
|
if err := tx.QueryRow(ctx, `SELECT EXISTS(SELECT 1 FROM registration_ips WHERE ip=$1)`, ip).Scan(&taken); err != nil {
|
||||||
}
|
return nil, err
|
||||||
if taken {
|
}
|
||||||
return nil, ErrRegistrationIPTaken
|
if taken {
|
||||||
|
return nil, ErrRegistrationIPTaken
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tag, err := tx.Exec(ctx, `
|
tag, err := tx.Exec(ctx, `
|
||||||
@@ -436,12 +439,14 @@ func (s *Store) RegisterInviteStudent(
|
|||||||
ON CONFLICT (user_id) DO NOTHING`, u.ID); err != nil {
|
ON CONFLICT (user_id) DO NOTHING`, u.ID); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if _, err := tx.Exec(ctx, `
|
if ip != "" {
|
||||||
INSERT INTO registration_ips (ip, user_id) VALUES ($1, $2)`, ip, u.ID); err != nil {
|
if _, err := tx.Exec(ctx, `
|
||||||
if isUniqueViolation(err) {
|
INSERT INTO registration_ips (ip, user_id) VALUES ($1, $2)`, ip, u.ID); err != nil {
|
||||||
return nil, ErrRegistrationIPTaken
|
if isUniqueViolation(err) {
|
||||||
|
return nil, ErrRegistrationIPTaken
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
if err := tx.Commit(ctx); err != nil {
|
if err := tx.Commit(ctx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -7,17 +7,17 @@ import (
|
|||||||
|
|
||||||
// LearningOverview is cohort-level learning analytics for staff.
|
// LearningOverview is cohort-level learning analytics for staff.
|
||||||
type LearningOverview struct {
|
type LearningOverview struct {
|
||||||
StudentsActive int64 `json:"studentsActive"`
|
StudentsActive int64 `json:"studentsActive"`
|
||||||
StudentsLocked int64 `json:"studentsLocked"`
|
StudentsLocked int64 `json:"studentsLocked"`
|
||||||
StudentsTotal int64 `json:"studentsTotal"`
|
StudentsTotal int64 `json:"studentsTotal"`
|
||||||
LessonsTotal int64 `json:"lessonsTotal"`
|
LessonsTotal int64 `json:"lessonsTotal"`
|
||||||
Completions int64 `json:"completions"`
|
Completions int64 `json:"completions"`
|
||||||
Attempts7d int64 `json:"attempts7d"`
|
Attempts7d int64 `json:"attempts7d"`
|
||||||
Passes7d int64 `json:"passes7d"`
|
Passes7d int64 `json:"passes7d"`
|
||||||
PassRate7d float64 `json:"passRate7d"`
|
PassRate7d float64 `json:"passRate7d"`
|
||||||
AvgWatchPct float64 `json:"avgWatchPct"`
|
AvgWatchPct float64 `json:"avgWatchPct"`
|
||||||
XPAwarded7d int64 `json:"xpAwarded7d"`
|
XPAwarded7d int64 `json:"xpAwarded7d"`
|
||||||
StudentsStreaking int64 `json:"studentsStreaking"`
|
StudentsStreaking int64 `json:"studentsStreaking"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) LearningOverview(ctx context.Context) (*LearningOverview, error) {
|
func (s *Store) LearningOverview(ctx context.Context) (*LearningOverview, error) {
|
||||||
@@ -81,10 +81,40 @@ type StudentLearningRow struct {
|
|||||||
LastActivityAt *time.Time `json:"lastActivityAt,omitempty"`
|
LastActivityAt *time.Time `json:"lastActivityAt,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) ListStudentLearning(ctx context.Context, q string) ([]StudentLearningRow, error) {
|
func (s *Store) ListStudentLearning(ctx context.Context, q, filter, sort string, limit, offset int) ([]StudentLearningRow, int64, error) {
|
||||||
|
if limit <= 0 {
|
||||||
|
limit = 10
|
||||||
|
}
|
||||||
|
if limit > 100 {
|
||||||
|
limit = 100
|
||||||
|
}
|
||||||
|
if offset < 0 {
|
||||||
|
offset = 0
|
||||||
|
}
|
||||||
var lessonsTotal int64
|
var lessonsTotal int64
|
||||||
if err := s.pool.QueryRow(ctx, `SELECT count(*) FROM lessons WHERE is_active`).Scan(&lessonsTotal); err != nil {
|
if err := s.pool.QueryRow(ctx, `SELECT count(*) FROM lessons WHERE is_active`).Scan(&lessonsTotal); err != nil {
|
||||||
return nil, err
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
where := `u.role = 'student'
|
||||||
|
AND ($1 = '' OR u.name ILIKE '%'||$1||'%' OR u.username ILIKE '%'||$1||'%' OR u.email ILIKE '%'||$1||'%')`
|
||||||
|
switch filter {
|
||||||
|
case "active":
|
||||||
|
where += ` AND u.is_active AND NOT u.is_locked`
|
||||||
|
case "locked":
|
||||||
|
where += ` AND u.is_locked`
|
||||||
|
}
|
||||||
|
order := `u.xp DESC, u.id ASC`
|
||||||
|
switch sort {
|
||||||
|
case "progress":
|
||||||
|
order = `COALESCE(p.passed, 0) DESC, u.id ASC`
|
||||||
|
case "streak":
|
||||||
|
order = `u.streak_current DESC, u.id ASC`
|
||||||
|
case "activity":
|
||||||
|
order = `u.last_activity_date DESC NULLS LAST, u.id ASC`
|
||||||
|
}
|
||||||
|
var total int64
|
||||||
|
if err := s.pool.QueryRow(ctx, `SELECT COUNT(*) FROM users u WHERE `+where, q).Scan(&total); err != nil {
|
||||||
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
rows, err := s.pool.Query(ctx, `
|
rows, err := s.pool.Query(ctx, `
|
||||||
SELECT u.id, u.name, u.username, u.email, u.xp, u.hearts, u.streak_current,
|
SELECT u.id, u.name, u.username, u.email, u.xp, u.hearts, u.streak_current,
|
||||||
@@ -105,12 +135,11 @@ func (s *Store) ListStudentLearning(ctx context.Context, q string) ([]StudentLea
|
|||||||
WHERE created_at >= now() - interval '7 days'
|
WHERE created_at >= now() - interval '7 days'
|
||||||
GROUP BY user_id
|
GROUP BY user_id
|
||||||
) a ON a.user_id = u.id
|
) a ON a.user_id = u.id
|
||||||
WHERE u.role = 'student'
|
WHERE `+where+`
|
||||||
AND ($1 = '' OR u.name ILIKE '%'||$1||'%' OR u.username ILIKE '%'||$1||'%' OR u.email ILIKE '%'||$1||'%')
|
ORDER BY `+order+`
|
||||||
ORDER BY u.xp DESC, u.id ASC
|
LIMIT $2 OFFSET $3`, q, limit, offset)
|
||||||
LIMIT 500`, q)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
out := make([]StudentLearningRow, 0)
|
out := make([]StudentLearningRow, 0)
|
||||||
@@ -122,7 +151,7 @@ func (s *Store) ListStudentLearning(ctx context.Context, q string) ([]StudentLea
|
|||||||
&r.IsLocked, &r.IsActive, &r.LastActivityAt,
|
&r.IsLocked, &r.IsActive, &r.LastActivityAt,
|
||||||
&r.LessonsPassed, &r.Attempts7d, &r.Passes7d,
|
&r.LessonsPassed, &r.Attempts7d, &r.Passes7d,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
if r.LessonsTotal > 0 {
|
if r.LessonsTotal > 0 {
|
||||||
r.ProgressPct = float64(r.LessonsPassed) / float64(r.LessonsTotal) * 100
|
r.ProgressPct = float64(r.LessonsPassed) / float64(r.LessonsTotal) * 100
|
||||||
@@ -132,21 +161,21 @@ func (s *Store) ListStudentLearning(ctx context.Context, q string) ([]StudentLea
|
|||||||
}
|
}
|
||||||
out = append(out, r)
|
out = append(out, r)
|
||||||
}
|
}
|
||||||
return out, rows.Err()
|
return out, total, rows.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
type LessonLearningDetail struct {
|
type LessonLearningDetail struct {
|
||||||
LessonID int64 `json:"lessonId"`
|
LessonID int64 `json:"lessonId"`
|
||||||
ChapterID int64 `json:"chapterId"`
|
ChapterID int64 `json:"chapterId"`
|
||||||
ChapterTitle string `json:"chapterTitle"`
|
ChapterTitle string `json:"chapterTitle"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
SortOrder int `json:"sortOrder"`
|
SortOrder int `json:"sortOrder"`
|
||||||
WatchedPct float64 `json:"watchedPct"`
|
WatchedPct float64 `json:"watchedPct"`
|
||||||
QuizUnlocked bool `json:"quizUnlocked"`
|
QuizUnlocked bool `json:"quizUnlocked"`
|
||||||
PassedQuiz bool `json:"passedQuiz"`
|
PassedQuiz bool `json:"passedQuiz"`
|
||||||
QuizCompletedAt *time.Time `json:"quizCompletedAt,omitempty"`
|
QuizCompletedAt *time.Time `json:"quizCompletedAt,omitempty"`
|
||||||
LastAttemptStatus string `json:"lastAttemptStatus,omitempty"`
|
LastAttemptStatus string `json:"lastAttemptStatus,omitempty"`
|
||||||
LastAttemptScore float64 `json:"lastAttemptScore,omitempty"`
|
LastAttemptScore float64 `json:"lastAttemptScore,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AttemptLearningDetail struct {
|
type AttemptLearningDetail struct {
|
||||||
@@ -178,11 +207,11 @@ type WatchSessionDetail struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type UserLearningDetail struct {
|
type UserLearningDetail struct {
|
||||||
User StudentLearningRow `json:"user"`
|
User StudentLearningRow `json:"user"`
|
||||||
Lessons []LessonLearningDetail `json:"lessons"`
|
Lessons []LessonLearningDetail `json:"lessons"`
|
||||||
Attempts []AttemptLearningDetail `json:"attempts"`
|
Attempts []AttemptLearningDetail `json:"attempts"`
|
||||||
XPEvents []XPEventDetail `json:"xpEvents"`
|
XPEvents []XPEventDetail `json:"xpEvents"`
|
||||||
Sessions []WatchSessionDetail `json:"sessions"`
|
Sessions []WatchSessionDetail `json:"sessions"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) UserLearningDetail(ctx context.Context, userID int64) (*UserLearningDetail, error) {
|
func (s *Store) UserLearningDetail(ctx context.Context, userID int64) (*UserLearningDetail, error) {
|
||||||
@@ -190,30 +219,28 @@ func (s *Store) UserLearningDetail(ctx context.Context, userID int64) (*UserLear
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
list, err := s.ListStudentLearning(ctx, "")
|
row := StudentLearningRow{
|
||||||
if err != nil {
|
ID: u.ID, Name: u.Name, Username: u.Username, Email: u.Email,
|
||||||
|
XP: u.XP, Hearts: u.Hearts, StreakCurrent: u.StreakCurrent,
|
||||||
|
IsLocked: u.IsLocked, IsActive: u.IsActive, LastActivityAt: u.LastActivityDate,
|
||||||
|
}
|
||||||
|
if err := s.pool.QueryRow(ctx, `SELECT count(*) FROM lessons WHERE is_active`).Scan(&row.LessonsTotal); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var row StudentLearningRow
|
if err := s.pool.QueryRow(ctx, `SELECT count(*) FROM lesson_progress WHERE user_id=$1 AND passed_quiz`, userID).Scan(&row.LessonsPassed); err != nil {
|
||||||
found := false
|
return nil, err
|
||||||
for _, r := range list {
|
|
||||||
if r.ID == userID {
|
|
||||||
row = r
|
|
||||||
found = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if !found {
|
if row.LessonsTotal > 0 {
|
||||||
row = StudentLearningRow{
|
row.ProgressPct = float64(row.LessonsPassed) / float64(row.LessonsTotal) * 100
|
||||||
ID: u.ID, Name: u.Name, Username: u.Username, Email: u.Email,
|
}
|
||||||
XP: u.XP, Hearts: u.Hearts, StreakCurrent: u.StreakCurrent,
|
if err := s.pool.QueryRow(ctx, `
|
||||||
IsLocked: u.IsLocked, IsActive: u.IsActive, LastActivityAt: u.LastActivityDate,
|
SELECT COUNT(*), COUNT(*) FILTER (WHERE status='passed')
|
||||||
}
|
FROM quiz_attempts
|
||||||
_ = s.pool.QueryRow(ctx, `SELECT count(*) FROM lessons WHERE is_active`).Scan(&row.LessonsTotal)
|
WHERE user_id=$1 AND created_at >= now() - interval '7 days'`, userID).Scan(&row.Attempts7d, &row.Passes7d); err != nil {
|
||||||
_ = s.pool.QueryRow(ctx, `SELECT count(*) FROM lesson_progress WHERE user_id=$1 AND passed_quiz`, userID).Scan(&row.LessonsPassed)
|
return nil, err
|
||||||
if row.LessonsTotal > 0 {
|
}
|
||||||
row.ProgressPct = float64(row.LessonsPassed) / float64(row.LessonsTotal) * 100
|
if row.Attempts7d > 0 {
|
||||||
}
|
row.PassRate7d = float64(row.Passes7d) / float64(row.Attempts7d) * 100
|
||||||
}
|
}
|
||||||
|
|
||||||
detail := &UserLearningDetail{User: row, Lessons: []LessonLearningDetail{}, Attempts: []AttemptLearningDetail{}, XPEvents: []XPEventDetail{}, Sessions: []WatchSessionDetail{}}
|
detail := &UserLearningDetail{User: row, Lessons: []LessonLearningDetail{}, Attempts: []AttemptLearningDetail{}, XPEvents: []XPEventDetail{}, Sessions: []WatchSessionDetail{}}
|
||||||
@@ -221,7 +248,7 @@ func (s *Store) UserLearningDetail(ctx context.Context, userID int64) (*UserLear
|
|||||||
lrows, err := s.pool.Query(ctx, `
|
lrows, err := s.pool.Query(ctx, `
|
||||||
SELECT l.id, l.chapter_id, c.title, l.title, l.sort_order,
|
SELECT l.id, l.chapter_id, c.title, l.title, l.sort_order,
|
||||||
COALESCE(p.watched_pct, 0), COALESCE(p.quiz_unlocked, false), COALESCE(p.passed_quiz, false), p.quiz_completed_at,
|
COALESCE(p.watched_pct, 0), COALESCE(p.quiz_unlocked, false), COALESCE(p.passed_quiz, false), p.quiz_completed_at,
|
||||||
COALESCE(la.status, ''), COALESCE(la.score_pct, 0)
|
COALESCE(la.status::text, ''), COALESCE(la.score_pct, 0)
|
||||||
FROM lessons l
|
FROM lessons l
|
||||||
JOIN chapters c ON c.id = l.chapter_id
|
JOIN chapters c ON c.id = l.chapter_id
|
||||||
LEFT JOIN lesson_progress p ON p.lesson_id = l.id AND p.user_id = $1
|
LEFT JOIN lesson_progress p ON p.lesson_id = l.id AND p.user_id = $1
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func TestLearningOverviewSmoke(t *testing.T) {
|
|||||||
if o == nil {
|
if o == nil {
|
||||||
t.Fatal("nil overview")
|
t.Fatal("nil overview")
|
||||||
}
|
}
|
||||||
students, err := st.ListStudentLearning(ctx, "")
|
students, _, err := st.ListStudentLearning(ctx, "", "", "xp", 10, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
+108
-42
@@ -331,18 +331,15 @@ func (s *Store) HasRegistrationIP(ctx context.Context, ip string) (bool, error)
|
|||||||
return exists, err
|
return exists, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterPublicStudent creates a student and consumes the IP atomically.
|
// RegisterPublicStudent creates a student and optionally records the client IP.
|
||||||
// When requireWhitelist is true, the phone must be an available whitelist entry.
|
// When requireWhitelist is true, the phone must be an available whitelist entry.
|
||||||
// Concurrent same-IP registrations: one commits; the other rolls back on unique IP conflict.
|
// Empty ip skips one-registration-per-IP enforcement (NAT / shared egress).
|
||||||
func (s *Store) RegisterPublicStudent(
|
func (s *Store) RegisterPublicStudent(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
name, email, username, passwordHash, phone, securityQuestion, securityAnswerHash, ip string,
|
name, email, username, passwordHash, phone, securityQuestion, securityAnswerHash, ip string,
|
||||||
requireWhitelist bool,
|
requireWhitelist bool,
|
||||||
) (*models.User, error) {
|
) (*models.User, error) {
|
||||||
ip = strings.TrimSpace(ip)
|
ip = strings.TrimSpace(ip)
|
||||||
if ip == "" {
|
|
||||||
return nil, errors.New("empty registration ip")
|
|
||||||
}
|
|
||||||
tx, err := s.pool.Begin(ctx)
|
tx, err := s.pool.Begin(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -355,12 +352,14 @@ func (s *Store) RegisterPublicStudent(
|
|||||||
return nil, ErrPhoneBlacklisted
|
return nil, ErrPhoneBlacklisted
|
||||||
}
|
}
|
||||||
|
|
||||||
var taken bool
|
if ip != "" {
|
||||||
if err := tx.QueryRow(ctx, `SELECT EXISTS(SELECT 1 FROM registration_ips WHERE ip=$1)`, ip).Scan(&taken); err != nil {
|
var taken bool
|
||||||
return nil, err
|
if err := tx.QueryRow(ctx, `SELECT EXISTS(SELECT 1 FROM registration_ips WHERE ip=$1)`, ip).Scan(&taken); err != nil {
|
||||||
}
|
return nil, err
|
||||||
if taken {
|
}
|
||||||
return nil, ErrRegistrationIPTaken
|
if taken {
|
||||||
|
return nil, ErrRegistrationIPTaken
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
row := tx.QueryRow(ctx, `
|
row := tx.QueryRow(ctx, `
|
||||||
@@ -380,12 +379,14 @@ func (s *Store) RegisterPublicStudent(
|
|||||||
ON CONFLICT (user_id) DO NOTHING`, u.ID); err != nil {
|
ON CONFLICT (user_id) DO NOTHING`, u.ID); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if _, err := tx.Exec(ctx, `
|
if ip != "" {
|
||||||
INSERT INTO registration_ips (ip, user_id) VALUES ($1, $2)`, ip, u.ID); err != nil {
|
if _, err := tx.Exec(ctx, `
|
||||||
if isUniqueViolation(err) {
|
INSERT INTO registration_ips (ip, user_id) VALUES ($1, $2)`, ip, u.ID); err != nil {
|
||||||
return nil, ErrRegistrationIPTaken
|
if isUniqueViolation(err) {
|
||||||
|
return nil, ErrRegistrationIPTaken
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
if err := tx.Commit(ctx); err != nil {
|
if err := tx.Commit(ctx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -503,7 +504,26 @@ func (s *Store) GetPhysicalOrder(ctx context.Context, id int64) (*models.Certifi
|
|||||||
return scanPhysicalOrder(row)
|
return scanPhysicalOrder(row)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) ListPhysicalOrders(ctx context.Context, status string) ([]models.CertificatePhysicalOrder, error) {
|
func (s *Store) ListPhysicalOrders(ctx context.Context, status string, limit, offset int) ([]models.CertificatePhysicalOrder, int64, error) {
|
||||||
|
if limit <= 0 {
|
||||||
|
limit = 10
|
||||||
|
}
|
||||||
|
if limit > 100 {
|
||||||
|
limit = 100
|
||||||
|
}
|
||||||
|
if offset < 0 {
|
||||||
|
offset = 0
|
||||||
|
}
|
||||||
|
where := ""
|
||||||
|
args := []any{}
|
||||||
|
if status != "" {
|
||||||
|
where = ` WHERE o.status=$1`
|
||||||
|
args = append(args, status)
|
||||||
|
}
|
||||||
|
var total int64
|
||||||
|
if err := s.pool.QueryRow(ctx, `SELECT COUNT(*) FROM certificate_physical_orders o`+where, args...).Scan(&total); err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
q := `
|
q := `
|
||||||
SELECT o.id, o.certificate_id, o.user_id, o.status, o.note,
|
SELECT o.id, o.certificate_id, o.user_id, o.status, o.note,
|
||||||
o.recipient_name, o.phone, o.address, o.city, o.postal_code, o.tracking_code,
|
o.recipient_name, o.phone, o.address, o.city, o.postal_code, o.tracking_code,
|
||||||
@@ -511,16 +531,11 @@ func (s *Store) ListPhysicalOrders(ctx context.Context, status string) ([]models
|
|||||||
u.name, c.public_id
|
u.name, c.public_id
|
||||||
FROM certificate_physical_orders o
|
FROM certificate_physical_orders o
|
||||||
JOIN users u ON u.id = o.user_id
|
JOIN users u ON u.id = o.user_id
|
||||||
JOIN certificates c ON c.id = o.certificate_id`
|
JOIN certificates c ON c.id = o.certificate_id` + where + ` ORDER BY o.created_at DESC LIMIT $` + strconv.Itoa(len(args)+1) + ` OFFSET $` + strconv.Itoa(len(args)+2)
|
||||||
args := []any{}
|
args = append(args, limit, offset)
|
||||||
if status != "" {
|
|
||||||
q += ` WHERE o.status=$1`
|
|
||||||
args = append(args, status)
|
|
||||||
}
|
|
||||||
q += ` ORDER BY o.created_at DESC LIMIT 200`
|
|
||||||
rows, err := s.pool.Query(ctx, q, args...)
|
rows, err := s.pool.Query(ctx, q, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
out := make([]models.CertificatePhysicalOrder, 0)
|
out := make([]models.CertificatePhysicalOrder, 0)
|
||||||
@@ -529,11 +544,11 @@ func (s *Store) ListPhysicalOrders(ctx context.Context, status string) ([]models
|
|||||||
if err := rows.Scan(&o.ID, &o.CertificateID, &o.UserID, &o.Status, &o.Note,
|
if err := rows.Scan(&o.ID, &o.CertificateID, &o.UserID, &o.Status, &o.Note,
|
||||||
&o.RecipientName, &o.Phone, &o.Address, &o.City, &o.PostalCode, &o.TrackingCode,
|
&o.RecipientName, &o.Phone, &o.Address, &o.City, &o.PostalCode, &o.TrackingCode,
|
||||||
&o.WindowEndsAt, &o.CreatedAt, &o.UpdatedAt, &o.UserName, &o.PublicID); err != nil {
|
&o.WindowEndsAt, &o.CreatedAt, &o.UpdatedAt, &o.UserName, &o.PublicID); err != nil {
|
||||||
return nil, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
out = append(out, o)
|
out = append(out, o)
|
||||||
}
|
}
|
||||||
return out, rows.Err()
|
return out, total, rows.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) UpdatePhysicalOrder(ctx context.Context, id int64, status models.PhysicalOrderStatus, note, tracking string) (*models.CertificatePhysicalOrder, error) {
|
func (s *Store) UpdatePhysicalOrder(ctx context.Context, id int64, status models.PhysicalOrderStatus, note, tracking string) (*models.CertificatePhysicalOrder, error) {
|
||||||
@@ -1068,7 +1083,7 @@ func (s *Store) AddChatMessage(ctx context.Context, userID, mentorID int64, send
|
|||||||
INSERT INTO chat_messages (user_id, mentor_id, sender_role, body, reply_to, attachment_type, attachment_url, attachment_name, attachment_size)
|
INSERT INTO chat_messages (user_id, mentor_id, sender_role, body, reply_to, attachment_type, attachment_url, attachment_name, attachment_size)
|
||||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9)
|
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9)
|
||||||
RETURNING id, user_id, mentor_id, sender_role, body, read_at, created_at, reply_to,
|
RETURNING id, user_id, mentor_id, sender_role, body, read_at, created_at, reply_to,
|
||||||
attachment_type, attachment_url, attachment_name, attachment_size, pinned_at`,
|
attachment_type, attachment_url, attachment_name, attachment_size, pinned_at, edited_at`,
|
||||||
userID, mentorID, senderRole.String(), body, replyTo, attType, attURL, attName, attSize)
|
userID, mentorID, senderRole.String(), body, replyTo, attType, attURL, attName, attSize)
|
||||||
return scanMessage(row)
|
return scanMessage(row)
|
||||||
}
|
}
|
||||||
@@ -1093,7 +1108,7 @@ func (s *Store) ImportChatMessage(ctx context.Context, userID, mentorID int64, s
|
|||||||
INSERT INTO chat_messages (user_id, mentor_id, sender_role, body, attachment_type, attachment_url, attachment_name, attachment_size, created_at, pinned_at)
|
INSERT INTO chat_messages (user_id, mentor_id, sender_role, body, attachment_type, attachment_url, attachment_name, attachment_size, created_at, pinned_at)
|
||||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)
|
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)
|
||||||
RETURNING id, user_id, mentor_id, sender_role, body, read_at, created_at, reply_to,
|
RETURNING id, user_id, mentor_id, sender_role, body, read_at, created_at, reply_to,
|
||||||
attachment_type, attachment_url, attachment_name, attachment_size, pinned_at`,
|
attachment_type, attachment_url, attachment_name, attachment_size, pinned_at, edited_at`,
|
||||||
userID, mentorID, senderRole.String(), body, attType, attURL, attName, attSize, createdAt, pinnedAt)
|
userID, mentorID, senderRole.String(), body, attType, attURL, attName, attSize, createdAt, pinnedAt)
|
||||||
return scanMessage(row)
|
return scanMessage(row)
|
||||||
}
|
}
|
||||||
@@ -1137,6 +1152,48 @@ func (s *Store) DeleteChatMessage(ctx context.Context, meID, partnerID, msgID in
|
|||||||
return tag.RowsAffected() > 0, nil
|
return tag.RowsAffected() > 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReplaceChatAttachment swaps the photo, video, or voice on one of my messages and marks it edited.
|
||||||
|
// The new type must match the current attachment.
|
||||||
|
func (s *Store) ReplaceChatAttachment(ctx context.Context, meID, partnerID, msgID int64, meRole models.Role, body, attType, attURL, attName string, attSize int64) (*models.ChatMessage, error) {
|
||||||
|
row := s.pool.QueryRow(ctx, `
|
||||||
|
UPDATE chat_messages
|
||||||
|
SET body=$1, edited_at=now(),
|
||||||
|
attachment_type=$2, attachment_url=$3, attachment_name=$4, attachment_size=$5
|
||||||
|
WHERE id=$6
|
||||||
|
AND ((user_id=$7 AND mentor_id=$8) OR (user_id=$8 AND mentor_id=$7))
|
||||||
|
AND sender_role=$9
|
||||||
|
AND (user_id=$7 OR mentor_id=$7)
|
||||||
|
AND attachment_type=$2
|
||||||
|
RETURNING id, user_id, mentor_id, sender_role, body, read_at, created_at, reply_to,
|
||||||
|
attachment_type, attachment_url, attachment_name, attachment_size, pinned_at, edited_at`,
|
||||||
|
body, attType, attURL, attName, attSize, msgID, meID, partnerID, meRole.String())
|
||||||
|
m, err := scanMessage(row)
|
||||||
|
if errors.Is(err, pgx.ErrNoRows) {
|
||||||
|
return nil, ErrNotFound
|
||||||
|
}
|
||||||
|
return m, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditChatMessage replaces the body of one of my own messages in this conversation.
|
||||||
|
func (s *Store) EditChatMessage(ctx context.Context, meID, partnerID, msgID int64, meRole models.Role, body string) (*models.ChatMessage, error) {
|
||||||
|
row := s.pool.QueryRow(ctx, `
|
||||||
|
UPDATE chat_messages
|
||||||
|
SET body=$1, edited_at=now()
|
||||||
|
WHERE id=$2
|
||||||
|
AND ((user_id=$3 AND mentor_id=$4) OR (user_id=$4 AND mentor_id=$3))
|
||||||
|
AND sender_role=$5
|
||||||
|
AND (user_id=$3 OR mentor_id=$3)
|
||||||
|
AND ($1 <> '' OR attachment_url IS NOT NULL)
|
||||||
|
RETURNING id, user_id, mentor_id, sender_role, body, read_at, created_at, reply_to,
|
||||||
|
attachment_type, attachment_url, attachment_name, attachment_size, pinned_at, edited_at`,
|
||||||
|
body, msgID, meID, partnerID, meRole.String())
|
||||||
|
m, err := scanMessage(row)
|
||||||
|
if errors.Is(err, pgx.ErrNoRows) {
|
||||||
|
return nil, ErrNotFound
|
||||||
|
}
|
||||||
|
return m, err
|
||||||
|
}
|
||||||
|
|
||||||
const maxPinnedMessages = 3
|
const maxPinnedMessages = 3
|
||||||
|
|
||||||
// TogglePinChatMessage pins or unpins a message. If already at the pin limit,
|
// TogglePinChatMessage pins or unpins a message. If already at the pin limit,
|
||||||
@@ -1159,7 +1216,7 @@ func (s *Store) TogglePinChatMessage(ctx context.Context, meID, partnerID, msgID
|
|||||||
out := s.pool.QueryRow(ctx, `
|
out := s.pool.QueryRow(ctx, `
|
||||||
UPDATE chat_messages SET pinned_at=NULL WHERE id=$1
|
UPDATE chat_messages SET pinned_at=NULL WHERE id=$1
|
||||||
RETURNING id, user_id, mentor_id, sender_role, body, read_at, created_at, reply_to,
|
RETURNING id, user_id, mentor_id, sender_role, body, read_at, created_at, reply_to,
|
||||||
attachment_type, attachment_url, attachment_name, attachment_size, pinned_at`, msgID)
|
attachment_type, attachment_url, attachment_name, attachment_size, pinned_at, edited_at`, msgID)
|
||||||
return scanMessage(out)
|
return scanMessage(out)
|
||||||
}
|
}
|
||||||
var n int
|
var n int
|
||||||
@@ -1187,7 +1244,7 @@ func (s *Store) TogglePinChatMessage(ctx context.Context, meID, partnerID, msgID
|
|||||||
out := s.pool.QueryRow(ctx, `
|
out := s.pool.QueryRow(ctx, `
|
||||||
UPDATE chat_messages SET pinned_at=now() WHERE id=$1
|
UPDATE chat_messages SET pinned_at=now() WHERE id=$1
|
||||||
RETURNING id, user_id, mentor_id, sender_role, body, read_at, created_at, reply_to,
|
RETURNING id, user_id, mentor_id, sender_role, body, read_at, created_at, reply_to,
|
||||||
attachment_type, attachment_url, attachment_name, attachment_size, pinned_at`, msgID)
|
attachment_type, attachment_url, attachment_name, attachment_size, pinned_at, edited_at`, msgID)
|
||||||
return scanMessage(out)
|
return scanMessage(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1195,7 +1252,7 @@ func (s *Store) TogglePinChatMessage(ctx context.Context, meID, partnerID, msgID
|
|||||||
func (s *Store) ListPinnedChatMessages(ctx context.Context, userID, mentorID int64) ([]models.ChatMessage, error) {
|
func (s *Store) ListPinnedChatMessages(ctx context.Context, userID, mentorID int64) ([]models.ChatMessage, error) {
|
||||||
rows, err := s.pool.Query(ctx, `
|
rows, err := s.pool.Query(ctx, `
|
||||||
SELECT id, user_id, mentor_id, sender_role, body, read_at, created_at, reply_to,
|
SELECT id, user_id, mentor_id, sender_role, body, read_at, created_at, reply_to,
|
||||||
attachment_type, attachment_url, attachment_name, attachment_size, pinned_at
|
attachment_type, attachment_url, attachment_name, attachment_size, pinned_at, edited_at
|
||||||
FROM chat_messages
|
FROM chat_messages
|
||||||
WHERE pinned_at IS NOT NULL
|
WHERE pinned_at IS NOT NULL
|
||||||
AND ((user_id=$1 AND mentor_id=$2) OR (user_id=$2 AND mentor_id=$1))
|
AND ((user_id=$1 AND mentor_id=$2) OR (user_id=$2 AND mentor_id=$1))
|
||||||
@@ -1221,7 +1278,7 @@ func (s *Store) ListPinnedChatMessages(ctx context.Context, userID, mentorID int
|
|||||||
func (s *Store) ListChatMessages(ctx context.Context, userID, mentorID, before, limit int64) ([]models.ChatMessage, error) {
|
func (s *Store) ListChatMessages(ctx context.Context, userID, mentorID, before, limit int64) ([]models.ChatMessage, error) {
|
||||||
rows, err := s.pool.Query(ctx, `
|
rows, err := s.pool.Query(ctx, `
|
||||||
SELECT id, user_id, mentor_id, sender_role, body, read_at, created_at, reply_to,
|
SELECT id, user_id, mentor_id, sender_role, body, read_at, created_at, reply_to,
|
||||||
attachment_type, attachment_url, attachment_name, attachment_size, pinned_at
|
attachment_type, attachment_url, attachment_name, attachment_size, pinned_at, edited_at
|
||||||
FROM chat_messages
|
FROM chat_messages
|
||||||
WHERE ((user_id=$1 AND mentor_id=$2) OR (user_id=$2 AND mentor_id=$1))
|
WHERE ((user_id=$1 AND mentor_id=$2) OR (user_id=$2 AND mentor_id=$1))
|
||||||
AND ($3 = 0 OR id < $3)
|
AND ($3 = 0 OR id < $3)
|
||||||
@@ -1269,7 +1326,7 @@ func (s *Store) ListChatMessagesAround(ctx context.Context, userID, partnerID, a
|
|||||||
|
|
||||||
older, err := s.pool.Query(ctx, `
|
older, err := s.pool.Query(ctx, `
|
||||||
SELECT id, user_id, mentor_id, sender_role, body, read_at, created_at, reply_to,
|
SELECT id, user_id, mentor_id, sender_role, body, read_at, created_at, reply_to,
|
||||||
attachment_type, attachment_url, attachment_name, attachment_size, pinned_at
|
attachment_type, attachment_url, attachment_name, attachment_size, pinned_at, edited_at
|
||||||
FROM chat_messages
|
FROM chat_messages
|
||||||
WHERE ((user_id=$1 AND mentor_id=$2) OR (user_id=$2 AND mentor_id=$1))
|
WHERE ((user_id=$1 AND mentor_id=$2) OR (user_id=$2 AND mentor_id=$1))
|
||||||
AND id <= $3
|
AND id <= $3
|
||||||
@@ -1301,7 +1358,7 @@ func (s *Store) ListChatMessagesAround(ctx context.Context, userID, partnerID, a
|
|||||||
|
|
||||||
newer, err := s.pool.Query(ctx, `
|
newer, err := s.pool.Query(ctx, `
|
||||||
SELECT id, user_id, mentor_id, sender_role, body, read_at, created_at, reply_to,
|
SELECT id, user_id, mentor_id, sender_role, body, read_at, created_at, reply_to,
|
||||||
attachment_type, attachment_url, attachment_name, attachment_size, pinned_at
|
attachment_type, attachment_url, attachment_name, attachment_size, pinned_at, edited_at
|
||||||
FROM chat_messages
|
FROM chat_messages
|
||||||
WHERE ((user_id=$1 AND mentor_id=$2) OR (user_id=$2 AND mentor_id=$1))
|
WHERE ((user_id=$1 AND mentor_id=$2) OR (user_id=$2 AND mentor_id=$1))
|
||||||
AND id > $3
|
AND id > $3
|
||||||
@@ -1344,7 +1401,7 @@ func scanMessage(row messageScanner) (*models.ChatMessage, error) {
|
|||||||
var attSize *int64
|
var attSize *int64
|
||||||
if err := row.Scan(
|
if err := row.Scan(
|
||||||
&m.ID, &m.UserID, &m.MentorID, &m.SenderRole, &m.Body, &m.ReadAt, &m.CreatedAt, &m.ReplyTo,
|
&m.ID, &m.UserID, &m.MentorID, &m.SenderRole, &m.Body, &m.ReadAt, &m.CreatedAt, &m.ReplyTo,
|
||||||
&attType, &attURL, &attName, &attSize, &m.PinnedAt,
|
&attType, &attURL, &attName, &attSize, &m.PinnedAt, &m.EditedAt,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1371,11 +1428,20 @@ func derefInt(p *int64) int64 {
|
|||||||
return *p
|
return *p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) MarkChatRead(ctx context.Context, userID, mentorID int64) error {
|
// MarkChatRead stamps messages the other person sent. Opening the thread must not
|
||||||
_, err := s.pool.Exec(ctx, `
|
// mark my own messages as seen.
|
||||||
UPDATE chat_messages SET read_at=now() WHERE (user_id=$1 AND mentor_id=$2) OR (user_id=$2 AND mentor_id=$1)`,
|
func (s *Store) MarkChatRead(ctx context.Context, meID, partnerID int64, meRole models.Role) (int64, error) {
|
||||||
userID, mentorID)
|
tag, err := s.pool.Exec(ctx, `
|
||||||
return err
|
UPDATE chat_messages
|
||||||
|
SET read_at=now()
|
||||||
|
WHERE read_at IS NULL
|
||||||
|
AND sender_role <> $3
|
||||||
|
AND ((user_id=$1 AND mentor_id=$2) OR (user_id=$2 AND mentor_id=$1))`,
|
||||||
|
meID, partnerID, meRole.String())
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return tag.RowsAffected(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MessageInConversation reports whether a message belongs to a given pair.
|
// MessageInConversation reports whether a message belongs to a given pair.
|
||||||
@@ -1742,7 +1808,7 @@ func (s *Store) AllActiveUserIDs(ctx context.Context) ([]int64, error) {
|
|||||||
|
|
||||||
func (s *Store) Stats(ctx context.Context) (map[string]any, error) {
|
func (s *Store) Stats(ctx context.Context) (map[string]any, error) {
|
||||||
var users, lessons, questions, events, completions int64
|
var users, lessons, questions, events, completions int64
|
||||||
if err := s.pool.QueryRow(ctx, `SELECT count(*) FROM users`).Scan(&users); err != nil {
|
if err := s.pool.QueryRow(ctx, `SELECT count(*) FROM users WHERE role='student' AND is_active`).Scan(&users); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := s.pool.QueryRow(ctx, `SELECT count(*) FROM lessons`).Scan(&lessons); err != nil {
|
if err := s.pool.QueryRow(ctx, `SELECT count(*) FROM lessons`).Scan(&lessons); err != nil {
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
# Pargar deploy
|
||||||
|
|
||||||
|
Full deployment guide and production checklist: **[`docs/deployment.md`](../docs/deployment.md)**
|
||||||
|
Security & secrets: [`docs/security.md`](../docs/security.md) · Ops / backup: [`docs/operations.md`](../docs/operations.md)
|
||||||
|
|
||||||
|
Edge: **Traefik v3.7** (Compose needs Traefik ≥3.6.1 on Docker Engine 29+).
|
||||||
|
|
||||||
|
## Layout
|
||||||
|
|
||||||
|
```text
|
||||||
|
deploy/
|
||||||
|
compose/
|
||||||
|
compose.yaml # shared app + data + Traefik labels
|
||||||
|
compose.dev.yaml # laptop TLS default, DB ports on 127.0.0.1
|
||||||
|
compose.prod.yaml # Let's Encrypt, no host DB ports
|
||||||
|
traefik/dynamic/ # middlewares
|
||||||
|
helm/pargar/ # chart + values-k3s / values-prod
|
||||||
|
scripts/
|
||||||
|
compose-dev.sh compose-prod.sh k3s-load-images.sh helm-k3s.sh backup.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## Compose — development
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp .env.example .env
|
||||||
|
./scripts/compose-dev.sh up -d --build
|
||||||
|
```
|
||||||
|
|
||||||
|
- App: https://localhost
|
||||||
|
- Traefik dashboard: http://127.0.0.1:8088
|
||||||
|
|
||||||
|
## Compose — production
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp .env.prod.example .env.prod
|
||||||
|
./scripts/compose-prod.sh up -d --build
|
||||||
|
```
|
||||||
|
|
||||||
|
## k3s + Helm
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./scripts/k3s-load-images.sh
|
||||||
|
./scripts/helm-k3s.sh
|
||||||
|
curl -k https://pargar.local/api/health
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl -n pargar get secret pargar-app -o jsonpath='{.data.admin-password}' | base64 -d; echo
|
||||||
|
```
|
||||||
|
|
||||||
|
Values: `values.yaml` · `values-k3s.yaml` · `values-prod.yaml`
|
||||||
|
Lint: `helm lint ./deploy/helm/pargar -f ./deploy/helm/pargar/values-k3s.yaml`
|
||||||
|
|
||||||
|
## Routing
|
||||||
|
|
||||||
|
| Path | Service |
|
||||||
|
|------|---------|
|
||||||
|
| `/api/*`, `/media/*` | backend |
|
||||||
|
| `/api/certificates/*`, `/c/*` | backend + noindex |
|
||||||
|
| else | frontend |
|
||||||
|
|
||||||
|
WS: `/api/ws` via Traefik.
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
# Local / staging-on-laptop overlay (Traefik + published data ports + mild limits).
|
||||||
|
# Usage: see compose.yaml header or scripts/compose-dev.sh
|
||||||
|
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:5432:5432"
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
memory: 512M
|
||||||
|
|
||||||
|
redis:
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:6379:6379"
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
memory: 256M
|
||||||
|
|
||||||
|
rustfs:
|
||||||
|
environment:
|
||||||
|
RUSTFS_CONSOLE_ENABLE: "true"
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:9000:9000"
|
||||||
|
- "127.0.0.1:9001:9001"
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
memory: 512M
|
||||||
|
|
||||||
|
backend:
|
||||||
|
environment:
|
||||||
|
DEV_MODE: ${DEV_MODE:-false}
|
||||||
|
SEED_CURRICULUM: ${SEED_CURRICULUM:-false}
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
memory: 512M
|
||||||
|
|
||||||
|
frontend:
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
memory: 512M
|
||||||
|
|
||||||
|
traefik:
|
||||||
|
# v3.6.1+ required for Docker Engine 29+ API negotiation
|
||||||
|
image: traefik@sha256:24841fe2de7304c149343d877d2923b4c8800a38ba015dea9174c23b20e344a0
|
||||||
|
restart: unless-stopped
|
||||||
|
security_opt:
|
||||||
|
- no-new-privileges:true
|
||||||
|
command:
|
||||||
|
- --providers.docker=true
|
||||||
|
- --providers.docker.exposedbydefault=false
|
||||||
|
- --providers.docker.network=pargar_pargar
|
||||||
|
- --providers.file.directory=/etc/traefik/dynamic
|
||||||
|
- --providers.file.watch=true
|
||||||
|
- --entrypoints.web.address=:80
|
||||||
|
- --entrypoints.websecure.address=:443
|
||||||
|
- --entrypoints.web.http.redirections.entrypoint.to=websecure
|
||||||
|
- --entrypoints.web.http.redirections.entrypoint.scheme=https
|
||||||
|
- --entrypoints.web.http.redirections.entrypoint.permanent=true
|
||||||
|
- --entrypoints.web.http.aliasHeadersStrategy=delete
|
||||||
|
- --entrypoints.websecure.http.aliasHeadersStrategy=delete
|
||||||
|
# Dev: Traefik default certificate (browser warning expected on localhost).
|
||||||
|
- --api.dashboard=true
|
||||||
|
- --api.insecure=true
|
||||||
|
- --log.level=INFO
|
||||||
|
- --accesslog=true
|
||||||
|
- --ping=true
|
||||||
|
- --global.checkNewVersion=false
|
||||||
|
ports:
|
||||||
|
- "80:80"
|
||||||
|
- "443:443"
|
||||||
|
# Dashboard only on loopback
|
||||||
|
- "127.0.0.1:8088:8080"
|
||||||
|
volumes:
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock:ro
|
||||||
|
- ../traefik/dynamic:/etc/traefik/dynamic:ro
|
||||||
|
depends_on:
|
||||||
|
backend:
|
||||||
|
condition: service_healthy
|
||||||
|
frontend:
|
||||||
|
condition: service_healthy
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "traefik", "healthcheck", "--ping"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 3s
|
||||||
|
retries: 10
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
memory: 256M
|
||||||
|
networks:
|
||||||
|
- pargar
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
# Internet-facing production overlay (Traefik + Let's Encrypt, no host DB ports).
|
||||||
|
# Usage:
|
||||||
|
# docker compose -f deploy/compose/compose.yaml -f deploy/compose/compose.prod.yaml \
|
||||||
|
# --env-file .env.prod up -d --build
|
||||||
|
#
|
||||||
|
# Requires: DOMAIN (public DNS), ACME_EMAIL, PUBLIC_URL=https://$DOMAIN, strong secrets.
|
||||||
|
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
# No host ports — only reachable on the compose network.
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
memory: 1G
|
||||||
|
|
||||||
|
redis:
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
memory: 512M
|
||||||
|
|
||||||
|
rustfs:
|
||||||
|
environment:
|
||||||
|
RUSTFS_CONSOLE_ENABLE: "false"
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
memory: 1G
|
||||||
|
|
||||||
|
backend:
|
||||||
|
environment:
|
||||||
|
DEV_MODE: "false"
|
||||||
|
SEED_CURRICULUM: "false"
|
||||||
|
labels:
|
||||||
|
- traefik.http.routers.pargar-api.tls.certresolver=le
|
||||||
|
- traefik.http.routers.pargar-cert-api.tls.certresolver=le
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
memory: 1G
|
||||||
|
reservations:
|
||||||
|
memory: 256M
|
||||||
|
|
||||||
|
frontend:
|
||||||
|
labels:
|
||||||
|
- traefik.http.routers.pargar-web.tls.certresolver=le
|
||||||
|
- traefik.http.routers.pargar-cert-web.tls.certresolver=le
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
memory: 1G
|
||||||
|
reservations:
|
||||||
|
memory: 256M
|
||||||
|
|
||||||
|
traefik:
|
||||||
|
# v3.6.1+ required for Docker Engine 29+ API negotiation
|
||||||
|
image: traefik@sha256:24841fe2de7304c149343d877d2923b4c8800a38ba015dea9174c23b20e344a0
|
||||||
|
restart: unless-stopped
|
||||||
|
security_opt:
|
||||||
|
- no-new-privileges:true
|
||||||
|
command:
|
||||||
|
- --providers.docker=true
|
||||||
|
- --providers.docker.exposedbydefault=false
|
||||||
|
- --providers.docker.network=pargar_pargar
|
||||||
|
- --providers.file.directory=/etc/traefik/dynamic
|
||||||
|
- --providers.file.watch=true
|
||||||
|
- --entrypoints.web.address=:80
|
||||||
|
- --entrypoints.websecure.address=:443
|
||||||
|
- --entrypoints.web.http.redirections.entrypoint.to=websecure
|
||||||
|
- --entrypoints.web.http.redirections.entrypoint.scheme=https
|
||||||
|
- --entrypoints.web.http.redirections.entrypoint.permanent=true
|
||||||
|
- --entrypoints.web.http.aliasHeadersStrategy=delete
|
||||||
|
- --entrypoints.websecure.http.aliasHeadersStrategy=delete
|
||||||
|
- --certificatesresolvers.le.acme.email=${ACME_EMAIL:?ACME_EMAIL must be set}
|
||||||
|
- --certificatesresolvers.le.acme.storage=/data/acme.json
|
||||||
|
- --certificatesresolvers.le.acme.httpchallenge=true
|
||||||
|
- --certificatesresolvers.le.acme.httpchallenge.entrypoint=web
|
||||||
|
- --api.dashboard=false
|
||||||
|
- --log.level=WARN
|
||||||
|
- --accesslog=true
|
||||||
|
- --ping=true
|
||||||
|
- --global.checkNewVersion=false
|
||||||
|
- --serversTransport.forwardingTimeouts.dialTimeout=10s
|
||||||
|
- --serversTransport.forwardingTimeouts.responseHeaderTimeout=60s
|
||||||
|
ports:
|
||||||
|
- "80:80"
|
||||||
|
- "[::]:80:80"
|
||||||
|
- "443:443"
|
||||||
|
- "[::]:443:443"
|
||||||
|
volumes:
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock:ro
|
||||||
|
- ../traefik/dynamic:/etc/traefik/dynamic:ro
|
||||||
|
- traefik_data:/data
|
||||||
|
depends_on:
|
||||||
|
backend:
|
||||||
|
condition: service_healthy
|
||||||
|
frontend:
|
||||||
|
condition: service_healthy
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "traefik", "healthcheck", "--ping"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 3s
|
||||||
|
retries: 10
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
memory: 256M
|
||||||
|
networks:
|
||||||
|
- pargar
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
traefik_data:
|
||||||
@@ -0,0 +1,184 @@
|
|||||||
|
# Shared services — always combine with compose.dev.yaml or compose.prod.yaml:
|
||||||
|
#
|
||||||
|
# Dev: docker compose -f deploy/compose/compose.yaml -f deploy/compose/compose.dev.yaml up -d --build
|
||||||
|
# Prod: docker compose -f deploy/compose/compose.yaml -f deploy/compose/compose.prod.yaml --env-file .env.prod up -d --build
|
||||||
|
#
|
||||||
|
# Or use scripts/compose-dev.sh / scripts/compose-prod.sh / root docker-compose.yml (dev default).
|
||||||
|
|
||||||
|
name: pargar
|
||||||
|
|
||||||
|
x-backend-env: &backend-env
|
||||||
|
PORT: "8080"
|
||||||
|
DATABASE_URL: postgres://${POSTGRES_USER:-pargar}:${POSTGRES_PASSWORD:?POSTGRES_PASSWORD must be set}@postgres:5432/${POSTGRES_DB:-pargar}?sslmode=disable
|
||||||
|
REDIS_URL: redis://:${REDIS_PASSWORD:?REDIS_PASSWORD must be set}@redis:6379
|
||||||
|
JWT_SECRET: ${JWT_SECRET:?JWT_SECRET must be set}
|
||||||
|
PUBLIC_URL: ${PUBLIC_URL:?PUBLIC_URL must be set}
|
||||||
|
FRONTEND_ORIGINS: ${FRONTEND_ORIGINS:?FRONTEND_ORIGINS must be set}
|
||||||
|
METRICS_TOKEN: ${METRICS_TOKEN:-}
|
||||||
|
TRUSTED_PROXY_CIDRS: ${TRUSTED_PROXY_CIDRS:-}
|
||||||
|
STORAGE_DRIVER: s3
|
||||||
|
STORAGE_ENDPOINT: http://rustfs:9000
|
||||||
|
STORAGE_REGION: ${STORAGE_REGION:-us-east-1}
|
||||||
|
STORAGE_ACCESS_KEY: ${RUSTFS_ACCESS_KEY:?RUSTFS_ACCESS_KEY must be set}
|
||||||
|
STORAGE_SECRET_KEY: ${RUSTFS_SECRET_KEY:?RUSTFS_SECRET_KEY must be set}
|
||||||
|
STORAGE_BUCKET: ${STORAGE_BUCKET:-pargar}
|
||||||
|
SEED_CURRICULUM: ${SEED_CURRICULUM:-false}
|
||||||
|
REGISTRATION_ENFORCE_IP: ${REGISTRATION_ENFORCE_IP:-false}
|
||||||
|
ADMIN_NAME: ${ADMIN_NAME:-Admin}
|
||||||
|
ADMIN_USERNAME: ${ADMIN_USERNAME:-admin}
|
||||||
|
ADMIN_EMAIL: ${ADMIN_EMAIL:-admin@example.com}
|
||||||
|
ADMIN_PASSWORD: ${ADMIN_PASSWORD:?ADMIN_PASSWORD must be set}
|
||||||
|
OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT:-}
|
||||||
|
OTEL_SERVICE_NAME: ${OTEL_SERVICE_NAME:-pargar-api}
|
||||||
|
DONATION_ENABLED: ${DONATION_ENABLED:-true}
|
||||||
|
DONATION_NOTE: ${DONATION_NOTE:-}
|
||||||
|
PHYSICAL_CERT_ENABLED: ${PHYSICAL_CERT_ENABLED:-true}
|
||||||
|
PHYSICAL_CERT_PRICE_IRR: ${PHYSICAL_CERT_PRICE_IRR:-2500000}
|
||||||
|
PHYSICAL_CERT_WINDOW_DAYS: ${PHYSICAL_CERT_WINDOW_DAYS:-30}
|
||||||
|
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
image: postgres:16.4-alpine
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
POSTGRES_USER: ${POSTGRES_USER:-pargar}
|
||||||
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD must be set}
|
||||||
|
POSTGRES_DB: ${POSTGRES_DB:-pargar}
|
||||||
|
volumes:
|
||||||
|
- pgdata:/var/lib/postgresql/data
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U \"$$POSTGRES_USER\" -d \"$$POSTGRES_DB\""]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 3s
|
||||||
|
retries: 20
|
||||||
|
networks:
|
||||||
|
- pargar
|
||||||
|
|
||||||
|
redis:
|
||||||
|
image: redis@sha256:858f009f9709ce576febc734aa78b8f6d624b82571f9ddb6bda4377c833b3499
|
||||||
|
restart: unless-stopped
|
||||||
|
command: ["redis-server", "--requirepass", "${REDIS_PASSWORD:?REDIS_PASSWORD must be set}", "--appendonly", "yes"]
|
||||||
|
volumes:
|
||||||
|
- redis_data:/data
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "redis-cli", "-a", "${REDIS_PASSWORD:?REDIS_PASSWORD must be set}", "ping"]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 3s
|
||||||
|
retries: 20
|
||||||
|
networks:
|
||||||
|
- pargar
|
||||||
|
|
||||||
|
rustfs:
|
||||||
|
image: rustfs/rustfs@sha256:1803faef57627e2d9c2e7d89d655d712ddded5389040054987163043fecb6a3c
|
||||||
|
restart: unless-stopped
|
||||||
|
command: /data
|
||||||
|
environment:
|
||||||
|
RUSTFS_ACCESS_KEY: ${RUSTFS_ACCESS_KEY:?RUSTFS_ACCESS_KEY must be set}
|
||||||
|
RUSTFS_SECRET_KEY: ${RUSTFS_SECRET_KEY:?RUSTFS_SECRET_KEY must be set}
|
||||||
|
RUSTFS_ADDRESS: ":9000"
|
||||||
|
RUSTFS_CONSOLE_ADDRESS: ":9001"
|
||||||
|
RUSTFS_CONSOLE_ENABLE: ${RUSTFS_CONSOLE_ENABLE:-false}
|
||||||
|
volumes:
|
||||||
|
- rustfs_data:/data
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "wget", "--spider", "--quiet", "http://localhost:9000/health"]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 3s
|
||||||
|
retries: 20
|
||||||
|
start_period: 10s
|
||||||
|
networks:
|
||||||
|
- pargar
|
||||||
|
|
||||||
|
backend:
|
||||||
|
build:
|
||||||
|
context: ../../backend
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
image: ${BACKEND_IMAGE:-pargar-backend:local}
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
<<: *backend-env
|
||||||
|
DEV_MODE: ${DEV_MODE:-false}
|
||||||
|
depends_on:
|
||||||
|
postgres:
|
||||||
|
condition: service_healthy
|
||||||
|
redis:
|
||||||
|
condition: service_healthy
|
||||||
|
rustfs:
|
||||||
|
condition: service_healthy
|
||||||
|
expose:
|
||||||
|
- "8080"
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "wget", "--spider", "--quiet", "http://127.0.0.1:8080/api/health"]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 3s
|
||||||
|
retries: 20
|
||||||
|
networks:
|
||||||
|
- pargar
|
||||||
|
labels:
|
||||||
|
- traefik.enable=true
|
||||||
|
- traefik.docker.network=pargar_pargar
|
||||||
|
# API + media (higher priority than frontend catch-all)
|
||||||
|
- traefik.http.routers.pargar-api.rule=Host(`${DOMAIN:-localhost}`) && (PathPrefix(`/api`) || PathPrefix(`/media`))
|
||||||
|
- traefik.http.routers.pargar-api.entrypoints=websecure
|
||||||
|
- traefik.http.routers.pargar-api.priority=100
|
||||||
|
- traefik.http.routers.pargar-api.tls=true
|
||||||
|
- traefik.http.routers.pargar-api.middlewares=security-headers@file,compress@file
|
||||||
|
- traefik.http.routers.pargar-api.service=pargar-api
|
||||||
|
- traefik.http.services.pargar-api.loadbalancer.server.port=8080
|
||||||
|
# Certificate public API — noindex
|
||||||
|
- traefik.http.routers.pargar-cert-api.rule=Host(`${DOMAIN:-localhost}`) && PathPrefix(`/api/certificates`)
|
||||||
|
- traefik.http.routers.pargar-cert-api.entrypoints=websecure
|
||||||
|
- traefik.http.routers.pargar-cert-api.priority=110
|
||||||
|
- traefik.http.routers.pargar-cert-api.tls=true
|
||||||
|
- traefik.http.routers.pargar-cert-api.middlewares=security-headers@file,compress@file,noindex@file
|
||||||
|
- traefik.http.routers.pargar-cert-api.service=pargar-api
|
||||||
|
|
||||||
|
frontend:
|
||||||
|
build:
|
||||||
|
context: ../../frontend
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
args:
|
||||||
|
NEXT_PUBLIC_API_URL: ""
|
||||||
|
NEXT_PUBLIC_WS_URL: ""
|
||||||
|
image: ${FRONTEND_IMAGE:-pargar-frontend:local}
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
NODE_ENV: production
|
||||||
|
depends_on:
|
||||||
|
backend:
|
||||||
|
condition: service_healthy
|
||||||
|
expose:
|
||||||
|
- "3000"
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "wget", "--spider", "--quiet", "http://127.0.0.1:3000"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 3s
|
||||||
|
retries: 10
|
||||||
|
networks:
|
||||||
|
- pargar
|
||||||
|
labels:
|
||||||
|
- traefik.enable=true
|
||||||
|
- traefik.docker.network=pargar_pargar
|
||||||
|
- traefik.http.routers.pargar-web.rule=Host(`${DOMAIN:-localhost}`)
|
||||||
|
- traefik.http.routers.pargar-web.entrypoints=websecure
|
||||||
|
- traefik.http.routers.pargar-web.priority=1
|
||||||
|
- traefik.http.routers.pargar-web.tls=true
|
||||||
|
- traefik.http.routers.pargar-web.middlewares=security-headers@file,compress@file
|
||||||
|
- traefik.http.routers.pargar-web.service=pargar-web
|
||||||
|
- traefik.http.services.pargar-web.loadbalancer.server.port=3000
|
||||||
|
# Unlisted certificate pages
|
||||||
|
- traefik.http.routers.pargar-cert-web.rule=Host(`${DOMAIN:-localhost}`) && PathPrefix(`/c`)
|
||||||
|
- traefik.http.routers.pargar-cert-web.entrypoints=websecure
|
||||||
|
- traefik.http.routers.pargar-cert-web.priority=50
|
||||||
|
- traefik.http.routers.pargar-cert-web.tls=true
|
||||||
|
- traefik.http.routers.pargar-cert-web.middlewares=security-headers@file,compress@file,noindex@file
|
||||||
|
- traefik.http.routers.pargar-cert-web.service=pargar-web
|
||||||
|
|
||||||
|
networks:
|
||||||
|
pargar:
|
||||||
|
name: pargar_pargar
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
pgdata:
|
||||||
|
redis_data:
|
||||||
|
rustfs_data:
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
.DS_Store
|
||||||
|
.git
|
||||||
|
*.md
|
||||||
|
*.tgz
|
||||||
|
secrets*.yaml
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
apiVersion: v2
|
||||||
|
name: pargar
|
||||||
|
description: Pargar gated LMS - Go API, Next.js frontend, Postgres, Redis, S3-compatible storage
|
||||||
|
type: application
|
||||||
|
version: 0.2.1
|
||||||
|
appVersion: "0.1.3"
|
||||||
|
keywords:
|
||||||
|
- lms
|
||||||
|
- pargar
|
||||||
|
- traefik
|
||||||
|
maintainers:
|
||||||
|
- name: Pargar
|
||||||
|
home: https://github.com/example/pargar
|
||||||
|
sources:
|
||||||
|
- https://github.com/example/pargar
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
Pargar {{ .Chart.AppVersion }} installed as release "{{ .Release.Name }}" in namespace "{{ .Release.Namespace }}".
|
||||||
|
|
||||||
|
Public URL: {{ .Values.global.publicUrl }}
|
||||||
|
Domain: {{ .Values.global.domain }}
|
||||||
|
|
||||||
|
1) Ensure DNS /hosts points to your Traefik entrypoint:
|
||||||
|
{{ .Values.global.domain }} → Traefik LoadBalancer / node IP
|
||||||
|
|
||||||
|
2) Images must exist on the cluster nodes (k3s local):
|
||||||
|
docker compose -f deploy/compose/compose.yaml -f deploy/compose/compose.dev.yaml build
|
||||||
|
docker save pargar-backend:local pargar-frontend:local | sudo k3s ctr images import -
|
||||||
|
|
||||||
|
3) Upgrade / install:
|
||||||
|
helm upgrade --install {{ .Release.Name }} ./deploy/helm/pargar \
|
||||||
|
-n {{ .Release.Namespace }} --create-namespace \
|
||||||
|
-f deploy/helm/pargar/values-k3s.yaml
|
||||||
|
|
||||||
|
4) Health:
|
||||||
|
kubectl -n {{ .Release.Namespace }} get pods,ingressroute,svc
|
||||||
|
curl -k {{ .Values.global.publicUrl }}/api/health
|
||||||
|
|
||||||
|
{{- if not .Values.ingress.tls.existingSecret }}
|
||||||
|
|
||||||
|
TLS: chart-managed self-signed certificate (browser warning expected).
|
||||||
|
For production set ingress.tls.existingSecret (cert-manager).
|
||||||
|
{{- end }}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
{{/*
|
||||||
|
Expand the name of the chart.
|
||||||
|
*/}}
|
||||||
|
{{- define "pargar.name" -}}
|
||||||
|
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{- define "pargar.fullname" -}}
|
||||||
|
{{- if .Values.fullnameOverride }}
|
||||||
|
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
|
||||||
|
{{- else }}
|
||||||
|
{{- $name := default .Chart.Name .Values.nameOverride }}
|
||||||
|
{{- if contains $name .Release.Name }}
|
||||||
|
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
|
||||||
|
{{- else }}
|
||||||
|
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{- define "pargar.chart" -}}
|
||||||
|
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{- define "pargar.labels" -}}
|
||||||
|
helm.sh/chart: {{ include "pargar.chart" . }}
|
||||||
|
{{ include "pargar.selectorLabels" . }}
|
||||||
|
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
|
||||||
|
app.kubernetes.io/managed-by: {{ .Release.Service }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{- define "pargar.selectorLabels" -}}
|
||||||
|
app.kubernetes.io/name: {{ include "pargar.name" . }}
|
||||||
|
app.kubernetes.io/instance: {{ .Release.Name }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{- define "pargar.serviceAccountName" -}}
|
||||||
|
{{- if .Values.serviceAccount.create }}
|
||||||
|
{{- default (include "pargar.fullname" .) .Values.serviceAccount.name }}
|
||||||
|
{{- else }}
|
||||||
|
{{- default "default" .Values.serviceAccount.name }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{- define "pargar.appSecretName" -}}
|
||||||
|
{{- if .Values.backend.existingSecret }}
|
||||||
|
{{- .Values.backend.existingSecret }}
|
||||||
|
{{- else }}
|
||||||
|
{{- printf "%s-app" (include "pargar.fullname" .) }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{- define "pargar.postgresSecretName" -}}
|
||||||
|
{{- if .Values.postgres.existingSecret }}
|
||||||
|
{{- .Values.postgres.existingSecret }}
|
||||||
|
{{- else }}
|
||||||
|
{{- printf "%s-postgres" (include "pargar.fullname" .) }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{- define "pargar.redisSecretName" -}}
|
||||||
|
{{- if .Values.redis.existingSecret }}
|
||||||
|
{{- .Values.redis.existingSecret }}
|
||||||
|
{{- else }}
|
||||||
|
{{- printf "%s-redis" (include "pargar.fullname" .) }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{- define "pargar.rustfsSecretName" -}}
|
||||||
|
{{- if .Values.rustfs.existingSecret }}
|
||||||
|
{{- .Values.rustfs.existingSecret }}
|
||||||
|
{{- else }}
|
||||||
|
{{- printf "%s-rustfs" (include "pargar.fullname" .) }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{- define "pargar.tlsSecretName" -}}
|
||||||
|
{{- if .Values.ingress.tls.existingSecret }}
|
||||||
|
{{- .Values.ingress.tls.existingSecret }}
|
||||||
|
{{- else }}
|
||||||
|
{{- printf "%s-tls" (include "pargar.fullname" .) }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{- define "pargar.postgresHost" -}}
|
||||||
|
{{- printf "%s-postgres" (include "pargar.fullname" .) }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{- define "pargar.redisHost" -}}
|
||||||
|
{{- printf "%s-redis" (include "pargar.fullname" .) }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{- define "pargar.rustfsHost" -}}
|
||||||
|
{{- printf "%s-rustfs" (include "pargar.fullname" .) }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{/*
|
||||||
|
Resolve container image: optional global.imageRegistry + repository:tag
|
||||||
|
Usage: {{ include "pargar.image" (dict "root" . "image" .Values.backend.image) }}
|
||||||
|
*/}}
|
||||||
|
{{- define "pargar.image" -}}
|
||||||
|
{{- $registry := .root.Values.global.imageRegistry | default "" -}}
|
||||||
|
{{- $repo := .image.repository -}}
|
||||||
|
{{- $tag := .image.tag | default .root.Chart.AppVersion | toString -}}
|
||||||
|
{{- if $registry -}}
|
||||||
|
{{- printf "%s/%s:%s" (trimSuffix "/" $registry) $repo $tag -}}
|
||||||
|
{{- else -}}
|
||||||
|
{{- printf "%s:%s" $repo $tag -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end }}
|
||||||
@@ -0,0 +1,206 @@
|
|||||||
|
{{- if .Values.backend.enabled }}
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: {{ include "pargar.fullname" . }}-backend
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
app.kubernetes.io/component: backend
|
||||||
|
spec:
|
||||||
|
type: ClusterIP
|
||||||
|
ports:
|
||||||
|
- name: http
|
||||||
|
port: {{ .Values.backend.service.port }}
|
||||||
|
targetPort: http
|
||||||
|
selector:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 4 }}
|
||||||
|
app.kubernetes.io/component: backend
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: {{ include "pargar.fullname" . }}-backend
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
app.kubernetes.io/component: backend
|
||||||
|
spec:
|
||||||
|
{{- if not .Values.backend.autoscaling.enabled }}
|
||||||
|
replicas: {{ .Values.backend.replicaCount }}
|
||||||
|
{{- end }}
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 6 }}
|
||||||
|
app.kubernetes.io/component: backend
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 8 }}
|
||||||
|
app.kubernetes.io/component: backend
|
||||||
|
spec:
|
||||||
|
serviceAccountName: {{ include "pargar.serviceAccountName" . }}
|
||||||
|
{{- with .Values.imagePullSecrets }}
|
||||||
|
imagePullSecrets:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
|
securityContext:
|
||||||
|
{{- toYaml .Values.podSecurityContext | nindent 8 }}
|
||||||
|
containers:
|
||||||
|
- name: backend
|
||||||
|
image: {{ include "pargar.image" (dict "root" . "image" .Values.backend.image) | quote }}
|
||||||
|
imagePullPolicy: {{ .Values.backend.image.pullPolicy }}
|
||||||
|
securityContext:
|
||||||
|
{{- toYaml .Values.securityContext | nindent 12 }}
|
||||||
|
ports:
|
||||||
|
- name: http
|
||||||
|
containerPort: {{ .Values.backend.service.port }}
|
||||||
|
env:
|
||||||
|
- name: PORT
|
||||||
|
value: {{ .Values.backend.service.port | quote }}
|
||||||
|
- name: PUBLIC_URL
|
||||||
|
value: {{ .Values.global.publicUrl | quote }}
|
||||||
|
- name: FRONTEND_ORIGINS
|
||||||
|
value: {{ .Values.global.frontendOrigins | quote }}
|
||||||
|
- name: TRUSTED_PROXY_CIDRS
|
||||||
|
value: {{ .Values.global.trustedProxyCIDRs | quote }}
|
||||||
|
- name: DEV_MODE
|
||||||
|
value: {{ .Values.backend.env.devMode | quote }}
|
||||||
|
- name: SEED_CURRICULUM
|
||||||
|
value: {{ .Values.backend.env.seedCurriculum | quote }}
|
||||||
|
- name: REGISTRATION_ENFORCE_IP
|
||||||
|
value: {{ .Values.backend.env.registrationEnforceIP | quote }}
|
||||||
|
- name: ADMIN_NAME
|
||||||
|
value: {{ .Values.backend.admin.name | quote }}
|
||||||
|
- name: ADMIN_USERNAME
|
||||||
|
value: {{ .Values.backend.admin.username | quote }}
|
||||||
|
- name: ADMIN_EMAIL
|
||||||
|
value: {{ .Values.backend.admin.email | quote }}
|
||||||
|
- name: JWT_SECRET
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ include "pargar.appSecretName" . }}
|
||||||
|
key: jwt-secret
|
||||||
|
- name: ADMIN_PASSWORD
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ include "pargar.appSecretName" . }}
|
||||||
|
key: admin-password
|
||||||
|
- name: METRICS_TOKEN
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ include "pargar.appSecretName" . }}
|
||||||
|
key: metrics-token
|
||||||
|
optional: true
|
||||||
|
- name: DONATION_ENABLED
|
||||||
|
value: {{ .Values.backend.env.donationEnabled | quote }}
|
||||||
|
- name: PHYSICAL_CERT_ENABLED
|
||||||
|
value: {{ .Values.backend.env.physicalCertEnabled | quote }}
|
||||||
|
- name: PHYSICAL_CERT_PRICE_IRR
|
||||||
|
value: {{ .Values.backend.env.physicalCertPriceIrr | quote }}
|
||||||
|
- name: PHYSICAL_CERT_WINDOW_DAYS
|
||||||
|
value: {{ .Values.backend.env.physicalCertWindowDays | quote }}
|
||||||
|
- name: OTEL_EXPORTER_OTLP_ENDPOINT
|
||||||
|
value: {{ .Values.backend.env.otelEndpoint | quote }}
|
||||||
|
- name: OTEL_SERVICE_NAME
|
||||||
|
value: {{ .Values.backend.env.otelServiceName | quote }}
|
||||||
|
- name: STORAGE_DRIVER
|
||||||
|
value: s3
|
||||||
|
- name: STORAGE_REGION
|
||||||
|
value: {{ .Values.rustfs.region | quote }}
|
||||||
|
- name: STORAGE_BUCKET
|
||||||
|
value: {{ .Values.rustfs.bucket | quote }}
|
||||||
|
{{- if .Values.postgres.enabled }}
|
||||||
|
- name: POSTGRES_USER
|
||||||
|
value: {{ .Values.postgres.auth.username | quote }}
|
||||||
|
- name: POSTGRES_DB
|
||||||
|
value: {{ .Values.postgres.auth.database | quote }}
|
||||||
|
- name: POSTGRES_HOST
|
||||||
|
value: {{ include "pargar.postgresHost" . | quote }}
|
||||||
|
- name: POSTGRES_PORT
|
||||||
|
value: "5432"
|
||||||
|
- name: POSTGRES_SSLMODE
|
||||||
|
value: "disable"
|
||||||
|
- name: POSTGRES_PASSWORD
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ include "pargar.postgresSecretName" . }}
|
||||||
|
key: postgres-password
|
||||||
|
{{- else }}
|
||||||
|
- name: DATABASE_URL
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ include "pargar.appSecretName" . }}
|
||||||
|
key: database-url
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Values.redis.enabled }}
|
||||||
|
- name: REDIS_HOST
|
||||||
|
value: {{ include "pargar.redisHost" . | quote }}
|
||||||
|
- name: REDIS_PORT
|
||||||
|
value: "6379"
|
||||||
|
- name: REDIS_PASSWORD
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ include "pargar.redisSecretName" . }}
|
||||||
|
key: redis-password
|
||||||
|
{{- else }}
|
||||||
|
- name: REDIS_URL
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ include "pargar.appSecretName" . }}
|
||||||
|
key: redis-url
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Values.rustfs.enabled }}
|
||||||
|
- name: STORAGE_ENDPOINT
|
||||||
|
value: {{ printf "http://%s:9000" (include "pargar.rustfsHost" .) | quote }}
|
||||||
|
- name: STORAGE_ACCESS_KEY
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ include "pargar.rustfsSecretName" . }}
|
||||||
|
key: access-key
|
||||||
|
- name: STORAGE_SECRET_KEY
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ include "pargar.rustfsSecretName" . }}
|
||||||
|
key: secret-key
|
||||||
|
{{- else }}
|
||||||
|
- name: STORAGE_ENDPOINT
|
||||||
|
value: {{ required "external.storageEndpoint required when rustfs.enabled=false" .Values.external.storageEndpoint | quote }}
|
||||||
|
- name: STORAGE_ACCESS_KEY
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ include "pargar.appSecretName" . }}
|
||||||
|
key: storage-access-key
|
||||||
|
- name: STORAGE_SECRET_KEY
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ include "pargar.appSecretName" . }}
|
||||||
|
key: storage-secret-key
|
||||||
|
{{- end }}
|
||||||
|
readinessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /api/health
|
||||||
|
port: http
|
||||||
|
initialDelaySeconds: 5
|
||||||
|
periodSeconds: 5
|
||||||
|
livenessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /api/health
|
||||||
|
port: http
|
||||||
|
initialDelaySeconds: 15
|
||||||
|
periodSeconds: 10
|
||||||
|
{{- with .Values.backend.resources }}
|
||||||
|
resources:
|
||||||
|
{{- toYaml . | nindent 12 }}
|
||||||
|
{{- end }}
|
||||||
|
{{- with .Values.nodeSelector }}
|
||||||
|
nodeSelector:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
|
{{- with .Values.affinity }}
|
||||||
|
affinity:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
|
{{- with .Values.tolerations }}
|
||||||
|
tolerations:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
{{- if and .Values.postgres.enabled .Values.backup.enabled }}
|
||||||
|
apiVersion: v1
|
||||||
|
kind: PersistentVolumeClaim
|
||||||
|
metadata:
|
||||||
|
name: {{ include "pargar.fullname" . }}-backups
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
app.kubernetes.io/component: backup
|
||||||
|
spec:
|
||||||
|
accessModes: ["ReadWriteOnce"]
|
||||||
|
{{- if .Values.backup.persistence.storageClass }}
|
||||||
|
storageClassName: {{ .Values.backup.persistence.storageClass | quote }}
|
||||||
|
{{- end }}
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: {{ .Values.backup.persistence.size | quote }}
|
||||||
|
---
|
||||||
|
apiVersion: batch/v1
|
||||||
|
kind: CronJob
|
||||||
|
metadata:
|
||||||
|
name: {{ include "pargar.fullname" . }}-pg-backup
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
app.kubernetes.io/component: backup
|
||||||
|
spec:
|
||||||
|
schedule: {{ .Values.backup.schedule | quote }}
|
||||||
|
concurrencyPolicy: Forbid
|
||||||
|
successfulJobsHistoryLimit: 3
|
||||||
|
failedJobsHistoryLimit: 3
|
||||||
|
jobTemplate:
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 12 }}
|
||||||
|
app.kubernetes.io/component: backup
|
||||||
|
spec:
|
||||||
|
restartPolicy: OnFailure
|
||||||
|
securityContext:
|
||||||
|
fsGroup: 999
|
||||||
|
containers:
|
||||||
|
- name: pg-dump
|
||||||
|
image: {{ .Values.backup.image | quote }}
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
env:
|
||||||
|
- name: PGHOST
|
||||||
|
value: {{ include "pargar.postgresHost" . | quote }}
|
||||||
|
- name: PGPORT
|
||||||
|
value: "5432"
|
||||||
|
- name: PGUSER
|
||||||
|
value: {{ .Values.postgres.auth.username | quote }}
|
||||||
|
- name: PGDATABASE
|
||||||
|
value: {{ .Values.postgres.auth.database | quote }}
|
||||||
|
- name: RETENTION_DAYS
|
||||||
|
value: {{ .Values.backup.retentionDays | quote }}
|
||||||
|
- name: PGPASSWORD
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ include "pargar.postgresSecretName" . }}
|
||||||
|
key: postgres-password
|
||||||
|
command:
|
||||||
|
- /bin/sh
|
||||||
|
- -ec
|
||||||
|
- |
|
||||||
|
set -euo pipefail
|
||||||
|
STAMP="$(date -u +%Y%m%dT%H%M%SZ)"
|
||||||
|
OUT="/backups/pargar-${STAMP}.sql.gz"
|
||||||
|
echo "Writing ${OUT}"
|
||||||
|
pg_dump --no-owner --no-acl | gzip -c > "${OUT}"
|
||||||
|
find /backups -type f -name 'pargar-*.sql.gz' -mtime +"${RETENTION_DAYS}" -print -delete || true
|
||||||
|
ls -lh /backups || true
|
||||||
|
volumeMounts:
|
||||||
|
- name: backups
|
||||||
|
mountPath: /backups
|
||||||
|
volumes:
|
||||||
|
- name: backups
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: {{ include "pargar.fullname" . }}-backups
|
||||||
|
{{- end }}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
{{- if and .Values.ingress.enabled .Values.ingress.tls.enabled .Values.certManager.enabled }}
|
||||||
|
apiVersion: cert-manager.io/v1
|
||||||
|
kind: Certificate
|
||||||
|
metadata:
|
||||||
|
name: {{ include "pargar.fullname" . }}-tls
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
spec:
|
||||||
|
secretName: {{ include "pargar.tlsSecretName" . }}
|
||||||
|
duration: {{ .Values.certManager.duration | default "2160h" | quote }}
|
||||||
|
renewBefore: {{ .Values.certManager.renewBefore | default "360h" | quote }}
|
||||||
|
issuerRef:
|
||||||
|
name: {{ required "certManager.issuerRef.name required when certManager.enabled" .Values.certManager.issuerRef.name | quote }}
|
||||||
|
kind: {{ .Values.certManager.issuerRef.kind | default "ClusterIssuer" | quote }}
|
||||||
|
{{- if .Values.certManager.issuerRef.group }}
|
||||||
|
group: {{ .Values.certManager.issuerRef.group | quote }}
|
||||||
|
{{- end }}
|
||||||
|
dnsNames:
|
||||||
|
- {{ .Values.global.domain | quote }}
|
||||||
|
{{- range .Values.certManager.extraDnsNames }}
|
||||||
|
- {{ . | quote }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
{{- if .Values.frontend.enabled }}
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: {{ include "pargar.fullname" . }}-frontend
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
app.kubernetes.io/component: frontend
|
||||||
|
spec:
|
||||||
|
type: ClusterIP
|
||||||
|
ports:
|
||||||
|
- name: http
|
||||||
|
port: {{ .Values.frontend.service.port }}
|
||||||
|
targetPort: http
|
||||||
|
selector:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 4 }}
|
||||||
|
app.kubernetes.io/component: frontend
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: {{ include "pargar.fullname" . }}-frontend
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
app.kubernetes.io/component: frontend
|
||||||
|
spec:
|
||||||
|
{{- if not .Values.frontend.autoscaling.enabled }}
|
||||||
|
replicas: {{ .Values.frontend.replicaCount }}
|
||||||
|
{{- end }}
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 6 }}
|
||||||
|
app.kubernetes.io/component: frontend
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 8 }}
|
||||||
|
app.kubernetes.io/component: frontend
|
||||||
|
spec:
|
||||||
|
serviceAccountName: {{ include "pargar.serviceAccountName" . }}
|
||||||
|
{{- with .Values.imagePullSecrets }}
|
||||||
|
imagePullSecrets:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
|
containers:
|
||||||
|
- name: frontend
|
||||||
|
image: {{ include "pargar.image" (dict "root" . "image" .Values.frontend.image) | quote }}
|
||||||
|
imagePullPolicy: {{ .Values.frontend.image.pullPolicy }}
|
||||||
|
env:
|
||||||
|
- name: NODE_ENV
|
||||||
|
value: production
|
||||||
|
ports:
|
||||||
|
- name: http
|
||||||
|
containerPort: {{ .Values.frontend.service.port }}
|
||||||
|
readinessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /
|
||||||
|
port: http
|
||||||
|
initialDelaySeconds: 5
|
||||||
|
periodSeconds: 5
|
||||||
|
livenessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /
|
||||||
|
port: http
|
||||||
|
initialDelaySeconds: 15
|
||||||
|
periodSeconds: 10
|
||||||
|
{{- with .Values.frontend.resources }}
|
||||||
|
resources:
|
||||||
|
{{- toYaml . | nindent 12 }}
|
||||||
|
{{- end }}
|
||||||
|
{{- with .Values.nodeSelector }}
|
||||||
|
nodeSelector:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
|
{{- with .Values.affinity }}
|
||||||
|
affinity:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
|
{{- with .Values.tolerations }}
|
||||||
|
tolerations:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
{{- if and .Values.backend.enabled .Values.backend.autoscaling.enabled }}
|
||||||
|
apiVersion: autoscaling/v2
|
||||||
|
kind: HorizontalPodAutoscaler
|
||||||
|
metadata:
|
||||||
|
name: {{ include "pargar.fullname" . }}-backend
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
app.kubernetes.io/component: backend
|
||||||
|
spec:
|
||||||
|
scaleTargetRef:
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
name: {{ include "pargar.fullname" . }}-backend
|
||||||
|
minReplicas: {{ .Values.backend.autoscaling.minReplicas }}
|
||||||
|
maxReplicas: {{ .Values.backend.autoscaling.maxReplicas }}
|
||||||
|
metrics:
|
||||||
|
{{- if .Values.backend.autoscaling.targetCPUUtilizationPercentage }}
|
||||||
|
- type: Resource
|
||||||
|
resource:
|
||||||
|
name: cpu
|
||||||
|
target:
|
||||||
|
type: Utilization
|
||||||
|
averageUtilization: {{ .Values.backend.autoscaling.targetCPUUtilizationPercentage }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Values.backend.autoscaling.targetMemoryUtilizationPercentage }}
|
||||||
|
- type: Resource
|
||||||
|
resource:
|
||||||
|
name: memory
|
||||||
|
target:
|
||||||
|
type: Utilization
|
||||||
|
averageUtilization: {{ .Values.backend.autoscaling.targetMemoryUtilizationPercentage }}
|
||||||
|
{{- end }}
|
||||||
|
---
|
||||||
|
{{- end }}
|
||||||
|
{{- if and .Values.frontend.enabled .Values.frontend.autoscaling.enabled }}
|
||||||
|
apiVersion: autoscaling/v2
|
||||||
|
kind: HorizontalPodAutoscaler
|
||||||
|
metadata:
|
||||||
|
name: {{ include "pargar.fullname" . }}-frontend
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
app.kubernetes.io/component: frontend
|
||||||
|
spec:
|
||||||
|
scaleTargetRef:
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
name: {{ include "pargar.fullname" . }}-frontend
|
||||||
|
minReplicas: {{ .Values.frontend.autoscaling.minReplicas }}
|
||||||
|
maxReplicas: {{ .Values.frontend.autoscaling.maxReplicas }}
|
||||||
|
metrics:
|
||||||
|
{{- if .Values.frontend.autoscaling.targetCPUUtilizationPercentage }}
|
||||||
|
- type: Resource
|
||||||
|
resource:
|
||||||
|
name: cpu
|
||||||
|
target:
|
||||||
|
type: Utilization
|
||||||
|
averageUtilization: {{ .Values.frontend.autoscaling.targetCPUUtilizationPercentage }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Values.frontend.autoscaling.targetMemoryUtilizationPercentage }}
|
||||||
|
- type: Resource
|
||||||
|
resource:
|
||||||
|
name: memory
|
||||||
|
target:
|
||||||
|
type: Utilization
|
||||||
|
averageUtilization: {{ .Values.frontend.autoscaling.targetMemoryUtilizationPercentage }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
{{- if and .Values.ingress.enabled (not .Values.ingress.useIngressRoute) }}
|
||||||
|
{{- $fullName := include "pargar.fullname" . }}
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
name: {{ $fullName }}
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
annotations:
|
||||||
|
traefik.ingress.kubernetes.io/router.middlewares: {{ .Release.Namespace }}-{{ $fullName }}-security-headers@kubernetescrd,{{ .Release.Namespace }}-{{ $fullName }}-compress@kubernetescrd
|
||||||
|
{{- if .Values.ingress.tls.clusterIssuer }}
|
||||||
|
cert-manager.io/cluster-issuer: {{ .Values.ingress.tls.clusterIssuer | quote }}
|
||||||
|
{{- end }}
|
||||||
|
{{- with .Values.ingress.annotations }}
|
||||||
|
{{- toYaml . | nindent 4 }}
|
||||||
|
{{- end }}
|
||||||
|
spec:
|
||||||
|
ingressClassName: {{ .Values.ingress.className | quote }}
|
||||||
|
{{- if .Values.ingress.tls.enabled }}
|
||||||
|
tls:
|
||||||
|
- hosts:
|
||||||
|
- {{ .Values.global.domain | quote }}
|
||||||
|
secretName: {{ include "pargar.tlsSecretName" . }}
|
||||||
|
{{- end }}
|
||||||
|
rules:
|
||||||
|
- host: {{ .Values.global.domain | quote }}
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- path: /api
|
||||||
|
pathType: Prefix
|
||||||
|
backend:
|
||||||
|
service:
|
||||||
|
name: {{ $fullName }}-backend
|
||||||
|
port:
|
||||||
|
number: {{ .Values.backend.service.port }}
|
||||||
|
- path: /media
|
||||||
|
pathType: Prefix
|
||||||
|
backend:
|
||||||
|
service:
|
||||||
|
name: {{ $fullName }}-backend
|
||||||
|
port:
|
||||||
|
number: {{ .Values.backend.service.port }}
|
||||||
|
- path: /
|
||||||
|
pathType: Prefix
|
||||||
|
backend:
|
||||||
|
service:
|
||||||
|
name: {{ $fullName }}-frontend
|
||||||
|
port:
|
||||||
|
number: {{ .Values.frontend.service.port }}
|
||||||
|
{{- end }}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
{{- if and .Values.ingress.enabled .Values.ingress.useIngressRoute }}
|
||||||
|
{{- $fullName := include "pargar.fullname" . }}
|
||||||
|
{{- $domain := .Values.global.domain }}
|
||||||
|
{{- $tlsSecret := include "pargar.tlsSecretName" . }}
|
||||||
|
apiVersion: traefik.io/v1alpha1
|
||||||
|
kind: IngressRoute
|
||||||
|
metadata:
|
||||||
|
name: {{ $fullName }}-http
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
spec:
|
||||||
|
entryPoints:
|
||||||
|
- web
|
||||||
|
routes:
|
||||||
|
- match: Host(`{{ $domain }}`)
|
||||||
|
kind: Rule
|
||||||
|
{{- if .Values.middlewares.redirectHttps }}
|
||||||
|
middlewares:
|
||||||
|
- name: {{ $fullName }}-redirect-https
|
||||||
|
{{- end }}
|
||||||
|
services:
|
||||||
|
- name: {{ $fullName }}-frontend
|
||||||
|
port: {{ .Values.frontend.service.port }}
|
||||||
|
---
|
||||||
|
apiVersion: traefik.io/v1alpha1
|
||||||
|
kind: IngressRoute
|
||||||
|
metadata:
|
||||||
|
name: {{ $fullName }}-https
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
spec:
|
||||||
|
entryPoints:
|
||||||
|
- websecure
|
||||||
|
routes:
|
||||||
|
# Certificate public API — highest priority + noindex
|
||||||
|
- match: Host(`{{ $domain }}`) && PathPrefix(`/api/certificates`)
|
||||||
|
kind: Rule
|
||||||
|
priority: 110
|
||||||
|
middlewares:
|
||||||
|
{{- if .Values.middlewares.securityHeaders }}
|
||||||
|
- name: {{ $fullName }}-security-headers
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Values.middlewares.compress }}
|
||||||
|
- name: {{ $fullName }}-compress
|
||||||
|
{{- end }}
|
||||||
|
- name: {{ $fullName }}-noindex
|
||||||
|
services:
|
||||||
|
- name: {{ $fullName }}-backend
|
||||||
|
port: {{ .Values.backend.service.port }}
|
||||||
|
# API + media (+ WebSocket /api/ws)
|
||||||
|
- match: Host(`{{ $domain }}`) && (PathPrefix(`/api`) || PathPrefix(`/media`))
|
||||||
|
kind: Rule
|
||||||
|
priority: 100
|
||||||
|
middlewares:
|
||||||
|
{{- if .Values.middlewares.securityHeaders }}
|
||||||
|
- name: {{ $fullName }}-security-headers
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Values.middlewares.compress }}
|
||||||
|
- name: {{ $fullName }}-compress
|
||||||
|
{{- end }}
|
||||||
|
services:
|
||||||
|
- name: {{ $fullName }}-backend
|
||||||
|
port: {{ .Values.backend.service.port }}
|
||||||
|
# Unlisted certificate pages
|
||||||
|
- match: Host(`{{ $domain }}`) && PathPrefix(`/c`)
|
||||||
|
kind: Rule
|
||||||
|
priority: 50
|
||||||
|
middlewares:
|
||||||
|
{{- if .Values.middlewares.securityHeaders }}
|
||||||
|
- name: {{ $fullName }}-security-headers
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Values.middlewares.compress }}
|
||||||
|
- name: {{ $fullName }}-compress
|
||||||
|
{{- end }}
|
||||||
|
- name: {{ $fullName }}-noindex
|
||||||
|
services:
|
||||||
|
- name: {{ $fullName }}-frontend
|
||||||
|
port: {{ .Values.frontend.service.port }}
|
||||||
|
# Frontend catch-all
|
||||||
|
- match: Host(`{{ $domain }}`)
|
||||||
|
kind: Rule
|
||||||
|
priority: 1
|
||||||
|
middlewares:
|
||||||
|
{{- if .Values.middlewares.securityHeaders }}
|
||||||
|
- name: {{ $fullName }}-security-headers
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Values.middlewares.compress }}
|
||||||
|
- name: {{ $fullName }}-compress
|
||||||
|
{{- end }}
|
||||||
|
services:
|
||||||
|
- name: {{ $fullName }}-frontend
|
||||||
|
port: {{ .Values.frontend.service.port }}
|
||||||
|
{{- if .Values.ingress.tls.enabled }}
|
||||||
|
tls:
|
||||||
|
secretName: {{ $tlsSecret }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
{{- if .Values.ingress.enabled }}
|
||||||
|
{{- if .Values.middlewares.securityHeaders }}
|
||||||
|
apiVersion: traefik.io/v1alpha1
|
||||||
|
kind: Middleware
|
||||||
|
metadata:
|
||||||
|
name: {{ include "pargar.fullname" . }}-security-headers
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
spec:
|
||||||
|
headers:
|
||||||
|
stsSeconds: 31536000
|
||||||
|
stsIncludeSubdomains: true
|
||||||
|
contentTypeNosniff: true
|
||||||
|
browserXssFilter: true
|
||||||
|
frameDeny: true
|
||||||
|
referrerPolicy: strict-origin-when-cross-origin
|
||||||
|
permissionsPolicy: "camera=(), microphone=(), geolocation=()"
|
||||||
|
customResponseHeaders:
|
||||||
|
Server: ""
|
||||||
|
Content-Security-Policy: >-
|
||||||
|
default-src 'self'; base-uri 'self'; form-action 'self';
|
||||||
|
frame-ancestors 'none'; object-src 'none';
|
||||||
|
script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline';
|
||||||
|
img-src 'self' data: blob:; font-src 'self' data:;
|
||||||
|
media-src 'self' blob:; connect-src 'self' ws: wss:;
|
||||||
|
worker-src 'self' blob:
|
||||||
|
---
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Values.middlewares.compress }}
|
||||||
|
apiVersion: traefik.io/v1alpha1
|
||||||
|
kind: Middleware
|
||||||
|
metadata:
|
||||||
|
name: {{ include "pargar.fullname" . }}-compress
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
spec:
|
||||||
|
compress: {}
|
||||||
|
---
|
||||||
|
{{- end }}
|
||||||
|
apiVersion: traefik.io/v1alpha1
|
||||||
|
kind: Middleware
|
||||||
|
metadata:
|
||||||
|
name: {{ include "pargar.fullname" . }}-noindex
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
spec:
|
||||||
|
headers:
|
||||||
|
customResponseHeaders:
|
||||||
|
X-Robots-Tag: "noindex, nofollow, noarchive"
|
||||||
|
---
|
||||||
|
{{- if and .Values.ingress.useIngressRoute .Values.middlewares.redirectHttps }}
|
||||||
|
apiVersion: traefik.io/v1alpha1
|
||||||
|
kind: Middleware
|
||||||
|
metadata:
|
||||||
|
name: {{ include "pargar.fullname" . }}-redirect-https
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
spec:
|
||||||
|
redirectScheme:
|
||||||
|
scheme: https
|
||||||
|
permanent: true
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
@@ -0,0 +1,229 @@
|
|||||||
|
{{- if .Values.networkPolicy.enabled }}
|
||||||
|
{{- $fullName := include "pargar.fullname" . }}
|
||||||
|
# Default deny all ingress/egress in the release namespace, then allow required paths.
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: NetworkPolicy
|
||||||
|
metadata:
|
||||||
|
name: {{ $fullName }}-default-deny
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
spec:
|
||||||
|
podSelector: {}
|
||||||
|
policyTypes:
|
||||||
|
- Ingress
|
||||||
|
- Egress
|
||||||
|
---
|
||||||
|
{{- if .Values.backend.enabled }}
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: NetworkPolicy
|
||||||
|
metadata:
|
||||||
|
name: {{ $fullName }}-backend
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
app.kubernetes.io/component: backend
|
||||||
|
spec:
|
||||||
|
podSelector:
|
||||||
|
matchLabels:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 6 }}
|
||||||
|
app.kubernetes.io/component: backend
|
||||||
|
policyTypes:
|
||||||
|
- Ingress
|
||||||
|
- Egress
|
||||||
|
ingress:
|
||||||
|
- from:
|
||||||
|
{{- range .Values.networkPolicy.ingressNamespaces }}
|
||||||
|
- namespaceSelector:
|
||||||
|
matchLabels:
|
||||||
|
kubernetes.io/metadata.name: {{ . | quote }}
|
||||||
|
podSelector:
|
||||||
|
matchLabels:
|
||||||
|
{{- toYaml $.Values.networkPolicy.ingressPodLabels | nindent 14 }}
|
||||||
|
{{- end }}
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: {{ .Values.backend.service.port }}
|
||||||
|
egress:
|
||||||
|
# DNS
|
||||||
|
- to:
|
||||||
|
- namespaceSelector:
|
||||||
|
matchLabels:
|
||||||
|
kubernetes.io/metadata.name: kube-system
|
||||||
|
ports:
|
||||||
|
- protocol: UDP
|
||||||
|
port: 53
|
||||||
|
- protocol: TCP
|
||||||
|
port: 53
|
||||||
|
{{- if .Values.postgres.enabled }}
|
||||||
|
- to:
|
||||||
|
- podSelector:
|
||||||
|
matchLabels:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 14 }}
|
||||||
|
app.kubernetes.io/component: postgres
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 5432
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Values.redis.enabled }}
|
||||||
|
- to:
|
||||||
|
- podSelector:
|
||||||
|
matchLabels:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 14 }}
|
||||||
|
app.kubernetes.io/component: redis
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 6379
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Values.rustfs.enabled }}
|
||||||
|
- to:
|
||||||
|
- podSelector:
|
||||||
|
matchLabels:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 14 }}
|
||||||
|
app.kubernetes.io/component: rustfs
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 9000
|
||||||
|
{{- else }}
|
||||||
|
# External S3 / managed data when in-cluster rustfs is off
|
||||||
|
- to:
|
||||||
|
- ipBlock:
|
||||||
|
cidr: 0.0.0.0/0
|
||||||
|
except:
|
||||||
|
- 10.0.0.0/8
|
||||||
|
- 172.16.0.0/12
|
||||||
|
- 192.168.0.0/16
|
||||||
|
- 169.254.0.0/16
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 443
|
||||||
|
- protocol: TCP
|
||||||
|
port: 5432
|
||||||
|
- protocol: TCP
|
||||||
|
port: 6379
|
||||||
|
{{- end }}
|
||||||
|
---
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Values.frontend.enabled }}
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: NetworkPolicy
|
||||||
|
metadata:
|
||||||
|
name: {{ $fullName }}-frontend
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
app.kubernetes.io/component: frontend
|
||||||
|
spec:
|
||||||
|
podSelector:
|
||||||
|
matchLabels:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 6 }}
|
||||||
|
app.kubernetes.io/component: frontend
|
||||||
|
policyTypes:
|
||||||
|
- Ingress
|
||||||
|
- Egress
|
||||||
|
ingress:
|
||||||
|
- from:
|
||||||
|
{{- range .Values.networkPolicy.ingressNamespaces }}
|
||||||
|
- namespaceSelector:
|
||||||
|
matchLabels:
|
||||||
|
kubernetes.io/metadata.name: {{ . | quote }}
|
||||||
|
podSelector:
|
||||||
|
matchLabels:
|
||||||
|
{{- toYaml $.Values.networkPolicy.ingressPodLabels | nindent 14 }}
|
||||||
|
{{- end }}
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: {{ .Values.frontend.service.port }}
|
||||||
|
egress:
|
||||||
|
- to:
|
||||||
|
- namespaceSelector:
|
||||||
|
matchLabels:
|
||||||
|
kubernetes.io/metadata.name: kube-system
|
||||||
|
ports:
|
||||||
|
- protocol: UDP
|
||||||
|
port: 53
|
||||||
|
- protocol: TCP
|
||||||
|
port: 53
|
||||||
|
---
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Values.postgres.enabled }}
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: NetworkPolicy
|
||||||
|
metadata:
|
||||||
|
name: {{ $fullName }}-postgres
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
app.kubernetes.io/component: postgres
|
||||||
|
spec:
|
||||||
|
podSelector:
|
||||||
|
matchLabels:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 6 }}
|
||||||
|
app.kubernetes.io/component: postgres
|
||||||
|
policyTypes:
|
||||||
|
- Ingress
|
||||||
|
- Egress
|
||||||
|
ingress:
|
||||||
|
- from:
|
||||||
|
- podSelector:
|
||||||
|
matchLabels:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 14 }}
|
||||||
|
app.kubernetes.io/component: backend
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 5432
|
||||||
|
egress: []
|
||||||
|
---
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Values.redis.enabled }}
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: NetworkPolicy
|
||||||
|
metadata:
|
||||||
|
name: {{ $fullName }}-redis
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
app.kubernetes.io/component: redis
|
||||||
|
spec:
|
||||||
|
podSelector:
|
||||||
|
matchLabels:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 6 }}
|
||||||
|
app.kubernetes.io/component: redis
|
||||||
|
policyTypes:
|
||||||
|
- Ingress
|
||||||
|
- Egress
|
||||||
|
ingress:
|
||||||
|
- from:
|
||||||
|
- podSelector:
|
||||||
|
matchLabels:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 14 }}
|
||||||
|
app.kubernetes.io/component: backend
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 6379
|
||||||
|
egress: []
|
||||||
|
---
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Values.rustfs.enabled }}
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: NetworkPolicy
|
||||||
|
metadata:
|
||||||
|
name: {{ $fullName }}-rustfs
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
app.kubernetes.io/component: rustfs
|
||||||
|
spec:
|
||||||
|
podSelector:
|
||||||
|
matchLabels:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 6 }}
|
||||||
|
app.kubernetes.io/component: rustfs
|
||||||
|
policyTypes:
|
||||||
|
- Ingress
|
||||||
|
- Egress
|
||||||
|
ingress:
|
||||||
|
- from:
|
||||||
|
- podSelector:
|
||||||
|
matchLabels:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 14 }}
|
||||||
|
app.kubernetes.io/component: backend
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 9000
|
||||||
|
egress: []
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
{{- if and .Values.backend.enabled .Values.backend.podDisruptionBudget.enabled }}
|
||||||
|
apiVersion: policy/v1
|
||||||
|
kind: PodDisruptionBudget
|
||||||
|
metadata:
|
||||||
|
name: {{ include "pargar.fullname" . }}-backend
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
app.kubernetes.io/component: backend
|
||||||
|
spec:
|
||||||
|
{{- if .Values.backend.podDisruptionBudget.minAvailable }}
|
||||||
|
minAvailable: {{ .Values.backend.podDisruptionBudget.minAvailable }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Values.backend.podDisruptionBudget.maxUnavailable }}
|
||||||
|
maxUnavailable: {{ .Values.backend.podDisruptionBudget.maxUnavailable }}
|
||||||
|
{{- end }}
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 6 }}
|
||||||
|
app.kubernetes.io/component: backend
|
||||||
|
---
|
||||||
|
{{- end }}
|
||||||
|
{{- if and .Values.frontend.enabled .Values.frontend.podDisruptionBudget.enabled }}
|
||||||
|
apiVersion: policy/v1
|
||||||
|
kind: PodDisruptionBudget
|
||||||
|
metadata:
|
||||||
|
name: {{ include "pargar.fullname" . }}-frontend
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
app.kubernetes.io/component: frontend
|
||||||
|
spec:
|
||||||
|
{{- if .Values.frontend.podDisruptionBudget.minAvailable }}
|
||||||
|
minAvailable: {{ .Values.frontend.podDisruptionBudget.minAvailable }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Values.frontend.podDisruptionBudget.maxUnavailable }}
|
||||||
|
maxUnavailable: {{ .Values.frontend.podDisruptionBudget.maxUnavailable }}
|
||||||
|
{{- end }}
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 6 }}
|
||||||
|
app.kubernetes.io/component: frontend
|
||||||
|
{{- end }}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
{{- if .Values.postgres.enabled }}
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: {{ include "pargar.postgresHost" . }}
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
app.kubernetes.io/component: postgres
|
||||||
|
spec:
|
||||||
|
type: ClusterIP
|
||||||
|
ports:
|
||||||
|
- name: postgres
|
||||||
|
port: 5432
|
||||||
|
targetPort: postgres
|
||||||
|
selector:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 4 }}
|
||||||
|
app.kubernetes.io/component: postgres
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: StatefulSet
|
||||||
|
metadata:
|
||||||
|
name: {{ include "pargar.fullname" . }}-postgres
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
app.kubernetes.io/component: postgres
|
||||||
|
spec:
|
||||||
|
serviceName: {{ include "pargar.postgresHost" . }}
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 6 }}
|
||||||
|
app.kubernetes.io/component: postgres
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 8 }}
|
||||||
|
app.kubernetes.io/component: postgres
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: postgres
|
||||||
|
image: {{ .Values.postgres.image }}
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
ports:
|
||||||
|
- name: postgres
|
||||||
|
containerPort: 5432
|
||||||
|
env:
|
||||||
|
- name: POSTGRES_USER
|
||||||
|
value: {{ .Values.postgres.auth.username | quote }}
|
||||||
|
- name: POSTGRES_DB
|
||||||
|
value: {{ .Values.postgres.auth.database | quote }}
|
||||||
|
- name: POSTGRES_PASSWORD
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ include "pargar.postgresSecretName" . }}
|
||||||
|
key: postgres-password
|
||||||
|
- name: PGDATA
|
||||||
|
value: /var/lib/postgresql/data/pgdata
|
||||||
|
readinessProbe:
|
||||||
|
exec:
|
||||||
|
command: ["pg_isready", "-U", {{ .Values.postgres.auth.username | quote }}, "-d", {{ .Values.postgres.auth.database | quote }}]
|
||||||
|
initialDelaySeconds: 5
|
||||||
|
periodSeconds: 5
|
||||||
|
livenessProbe:
|
||||||
|
exec:
|
||||||
|
command: ["pg_isready", "-U", {{ .Values.postgres.auth.username | quote }}, "-d", {{ .Values.postgres.auth.database | quote }}]
|
||||||
|
initialDelaySeconds: 15
|
||||||
|
periodSeconds: 10
|
||||||
|
{{- with .Values.postgres.resources }}
|
||||||
|
resources:
|
||||||
|
{{- toYaml . | nindent 12 }}
|
||||||
|
{{- end }}
|
||||||
|
volumeMounts:
|
||||||
|
- name: data
|
||||||
|
mountPath: /var/lib/postgresql/data
|
||||||
|
{{- if not .Values.postgres.persistence.enabled }}
|
||||||
|
volumes:
|
||||||
|
- name: data
|
||||||
|
emptyDir: {}
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Values.postgres.persistence.enabled }}
|
||||||
|
volumeClaimTemplates:
|
||||||
|
- metadata:
|
||||||
|
name: data
|
||||||
|
spec:
|
||||||
|
accessModes: ["ReadWriteOnce"]
|
||||||
|
{{- if .Values.postgres.persistence.storageClass }}
|
||||||
|
storageClassName: {{ .Values.postgres.persistence.storageClass | quote }}
|
||||||
|
{{- end }}
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: {{ .Values.postgres.persistence.size }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
{{- if .Values.redis.enabled }}
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: {{ include "pargar.redisHost" . }}
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
app.kubernetes.io/component: redis
|
||||||
|
spec:
|
||||||
|
type: ClusterIP
|
||||||
|
ports:
|
||||||
|
- name: redis
|
||||||
|
port: 6379
|
||||||
|
targetPort: redis
|
||||||
|
selector:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 4 }}
|
||||||
|
app.kubernetes.io/component: redis
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: StatefulSet
|
||||||
|
metadata:
|
||||||
|
name: {{ include "pargar.fullname" . }}-redis
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
app.kubernetes.io/component: redis
|
||||||
|
spec:
|
||||||
|
serviceName: {{ include "pargar.redisHost" . }}
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 6 }}
|
||||||
|
app.kubernetes.io/component: redis
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 8 }}
|
||||||
|
app.kubernetes.io/component: redis
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: redis
|
||||||
|
image: {{ .Values.redis.image }}
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
command: ["sh", "-c", "exec redis-server --requirepass \"$REDIS_PASSWORD\" --appendonly yes"]
|
||||||
|
ports:
|
||||||
|
- name: redis
|
||||||
|
containerPort: 6379
|
||||||
|
env:
|
||||||
|
- name: REDIS_PASSWORD
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ include "pargar.redisSecretName" . }}
|
||||||
|
key: redis-password
|
||||||
|
readinessProbe:
|
||||||
|
exec:
|
||||||
|
command: ["sh", "-c", "redis-cli -a \"$REDIS_PASSWORD\" ping | grep -q PONG"]
|
||||||
|
initialDelaySeconds: 5
|
||||||
|
periodSeconds: 5
|
||||||
|
livenessProbe:
|
||||||
|
exec:
|
||||||
|
command: ["sh", "-c", "redis-cli -a \"$REDIS_PASSWORD\" ping | grep -q PONG"]
|
||||||
|
initialDelaySeconds: 15
|
||||||
|
periodSeconds: 10
|
||||||
|
{{- with .Values.redis.resources }}
|
||||||
|
resources:
|
||||||
|
{{- toYaml . | nindent 12 }}
|
||||||
|
{{- end }}
|
||||||
|
volumeMounts:
|
||||||
|
- name: data
|
||||||
|
mountPath: /data
|
||||||
|
{{- if not .Values.redis.persistence.enabled }}
|
||||||
|
volumes:
|
||||||
|
- name: data
|
||||||
|
emptyDir: {}
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Values.redis.persistence.enabled }}
|
||||||
|
volumeClaimTemplates:
|
||||||
|
- metadata:
|
||||||
|
name: data
|
||||||
|
spec:
|
||||||
|
accessModes: ["ReadWriteOnce"]
|
||||||
|
{{- if .Values.redis.persistence.storageClass }}
|
||||||
|
storageClassName: {{ .Values.redis.persistence.storageClass | quote }}
|
||||||
|
{{- end }}
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: {{ .Values.redis.persistence.size }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
{{- if .Values.rustfs.enabled }}
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: {{ include "pargar.rustfsHost" . }}
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
app.kubernetes.io/component: rustfs
|
||||||
|
spec:
|
||||||
|
type: ClusterIP
|
||||||
|
ports:
|
||||||
|
- name: s3
|
||||||
|
port: 9000
|
||||||
|
targetPort: s3
|
||||||
|
selector:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 4 }}
|
||||||
|
app.kubernetes.io/component: rustfs
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: StatefulSet
|
||||||
|
metadata:
|
||||||
|
name: {{ include "pargar.fullname" . }}-rustfs
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
app.kubernetes.io/component: rustfs
|
||||||
|
spec:
|
||||||
|
serviceName: {{ include "pargar.rustfsHost" . }}
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 6 }}
|
||||||
|
app.kubernetes.io/component: rustfs
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.selectorLabels" . | nindent 8 }}
|
||||||
|
app.kubernetes.io/component: rustfs
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: rustfs
|
||||||
|
image: {{ .Values.rustfs.image }}
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
args: ["/data"]
|
||||||
|
ports:
|
||||||
|
- name: s3
|
||||||
|
containerPort: 9000
|
||||||
|
env:
|
||||||
|
- name: RUSTFS_ACCESS_KEY
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ include "pargar.rustfsSecretName" . }}
|
||||||
|
key: access-key
|
||||||
|
- name: RUSTFS_SECRET_KEY
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ include "pargar.rustfsSecretName" . }}
|
||||||
|
key: secret-key
|
||||||
|
- name: RUSTFS_ADDRESS
|
||||||
|
value: ":9000"
|
||||||
|
- name: RUSTFS_CONSOLE_ADDRESS
|
||||||
|
value: ":9001"
|
||||||
|
- name: RUSTFS_CONSOLE_ENABLE
|
||||||
|
value: {{ .Values.rustfs.consoleEnable | ternary "true" "false" | quote }}
|
||||||
|
readinessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /health
|
||||||
|
port: s3
|
||||||
|
initialDelaySeconds: 10
|
||||||
|
periodSeconds: 5
|
||||||
|
livenessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /health
|
||||||
|
port: s3
|
||||||
|
initialDelaySeconds: 20
|
||||||
|
periodSeconds: 10
|
||||||
|
{{- with .Values.rustfs.resources }}
|
||||||
|
resources:
|
||||||
|
{{- toYaml . | nindent 12 }}
|
||||||
|
{{- end }}
|
||||||
|
volumeMounts:
|
||||||
|
- name: data
|
||||||
|
mountPath: /data
|
||||||
|
{{- if not .Values.rustfs.persistence.enabled }}
|
||||||
|
volumes:
|
||||||
|
- name: data
|
||||||
|
emptyDir: {}
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Values.rustfs.persistence.enabled }}
|
||||||
|
volumeClaimTemplates:
|
||||||
|
- metadata:
|
||||||
|
name: data
|
||||||
|
spec:
|
||||||
|
accessModes: ["ReadWriteOnce"]
|
||||||
|
{{- if .Values.rustfs.persistence.storageClass }}
|
||||||
|
storageClassName: {{ .Values.rustfs.persistence.storageClass | quote }}
|
||||||
|
{{- end }}
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: {{ .Values.rustfs.persistence.size }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
{{- if and .Values.backend.enabled (not .Values.backend.existingSecret) }}
|
||||||
|
{{- $name := include "pargar.appSecretName" . }}
|
||||||
|
{{- $existing := lookup "v1" "Secret" .Release.Namespace $name }}
|
||||||
|
{{- $jwt := "" }}
|
||||||
|
{{- $admin := "" }}
|
||||||
|
{{- $metrics := .Values.backend.secrets.metricsToken | default "" }}
|
||||||
|
{{- if and $existing $existing.data }}
|
||||||
|
{{- /* Reuse existing secrets so upgrades do not invalidate sessions / bootstrap. */}}
|
||||||
|
{{- if index $existing.data "jwt-secret" }}
|
||||||
|
{{- $jwt = index $existing.data "jwt-secret" | b64dec }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if index $existing.data "admin-password" }}
|
||||||
|
{{- $admin = index $existing.data "admin-password" | b64dec }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if and (not $metrics) (index $existing.data "metrics-token") }}
|
||||||
|
{{- $metrics = index $existing.data "metrics-token" | b64dec }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if not $jwt }}
|
||||||
|
{{- if and .Values.backend.secrets.jwtSecret (not (hasPrefix "change-me" .Values.backend.secrets.jwtSecret)) (ne .Values.backend.secrets.jwtSecret "") }}
|
||||||
|
{{- $jwt = .Values.backend.secrets.jwtSecret }}
|
||||||
|
{{- else }}
|
||||||
|
{{- $jwt = randAlphaNum 48 }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if not $admin }}
|
||||||
|
{{- if and .Values.backend.secrets.adminPassword (not (hasPrefix "change-me" .Values.backend.secrets.adminPassword)) (ne .Values.backend.secrets.adminPassword "") }}
|
||||||
|
{{- $admin = .Values.backend.secrets.adminPassword }}
|
||||||
|
{{- else }}
|
||||||
|
{{- $admin = randAlphaNum 24 }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: {{ $name }}
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
annotations:
|
||||||
|
pargar.io/secret-source: generated-or-values
|
||||||
|
type: Opaque
|
||||||
|
stringData:
|
||||||
|
jwt-secret: {{ $jwt | quote }}
|
||||||
|
admin-password: {{ $admin | quote }}
|
||||||
|
metrics-token: {{ $metrics | quote }}
|
||||||
|
{{- if not .Values.postgres.enabled }}
|
||||||
|
database-url: {{ required "external.databaseUrl required when postgres.enabled=false and existingSecret is empty" .Values.external.databaseUrl | quote }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if not .Values.redis.enabled }}
|
||||||
|
redis-url: {{ required "external.redisUrl required when redis.enabled=false and existingSecret is empty" .Values.external.redisUrl | quote }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if not .Values.rustfs.enabled }}
|
||||||
|
storage-access-key: {{ required "external.storageAccessKey required when rustfs.enabled=false and existingSecret is empty" .Values.external.storageAccessKey | quote }}
|
||||||
|
storage-secret-key: {{ required "external.storageSecretKey required when rustfs.enabled=false and existingSecret is empty" .Values.external.storageSecretKey | quote }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
{{- if and .Values.postgres.enabled (not .Values.postgres.existingSecret) }}
|
||||||
|
{{- $pgName := include "pargar.postgresSecretName" . }}
|
||||||
|
{{- $pgExisting := lookup "v1" "Secret" .Release.Namespace $pgName }}
|
||||||
|
{{- $pgPass := "" }}
|
||||||
|
{{- if and $pgExisting $pgExisting.data (index $pgExisting.data "postgres-password") }}
|
||||||
|
{{- /* Never rotate an existing DB password — Postgres data dir is bound to it. */}}
|
||||||
|
{{- $pgPass = index $pgExisting.data "postgres-password" | b64dec }}
|
||||||
|
{{- else if and .Values.postgres.auth.password (not (hasPrefix "change-me" .Values.postgres.auth.password)) (ne .Values.postgres.auth.password "") }}
|
||||||
|
{{- $pgPass = .Values.postgres.auth.password }}
|
||||||
|
{{- else }}
|
||||||
|
{{- $pgPass = randAlphaNum 32 }}
|
||||||
|
{{- end }}
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: {{ $pgName }}
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
type: Opaque
|
||||||
|
stringData:
|
||||||
|
postgres-password: {{ $pgPass | quote }}
|
||||||
|
---
|
||||||
|
{{- end }}
|
||||||
|
{{- if and .Values.redis.enabled (not .Values.redis.existingSecret) }}
|
||||||
|
{{- $rdName := include "pargar.redisSecretName" . }}
|
||||||
|
{{- $rdExisting := lookup "v1" "Secret" .Release.Namespace $rdName }}
|
||||||
|
{{- $rdPass := "" }}
|
||||||
|
{{- if and $rdExisting $rdExisting.data (index $rdExisting.data "redis-password") }}
|
||||||
|
{{- $rdPass = index $rdExisting.data "redis-password" | b64dec }}
|
||||||
|
{{- else if and .Values.redis.auth.password (not (hasPrefix "change-me" .Values.redis.auth.password)) (ne .Values.redis.auth.password "") }}
|
||||||
|
{{- $rdPass = .Values.redis.auth.password }}
|
||||||
|
{{- else }}
|
||||||
|
{{- $rdPass = randAlphaNum 32 }}
|
||||||
|
{{- end }}
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: {{ $rdName }}
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
type: Opaque
|
||||||
|
stringData:
|
||||||
|
redis-password: {{ $rdPass | quote }}
|
||||||
|
---
|
||||||
|
{{- end }}
|
||||||
|
{{- if and .Values.rustfs.enabled (not .Values.rustfs.existingSecret) }}
|
||||||
|
{{- $rsName := include "pargar.rustfsSecretName" . }}
|
||||||
|
{{- $rsExisting := lookup "v1" "Secret" .Release.Namespace $rsName }}
|
||||||
|
{{- $access := .Values.rustfs.auth.accessKey | default "pargar" }}
|
||||||
|
{{- $secret := "" }}
|
||||||
|
{{- if and $rsExisting $rsExisting.data (index $rsExisting.data "secret-key") }}
|
||||||
|
{{- $secret = index $rsExisting.data "secret-key" | b64dec }}
|
||||||
|
{{- if index $rsExisting.data "access-key" }}
|
||||||
|
{{- $access = index $rsExisting.data "access-key" | b64dec }}
|
||||||
|
{{- end }}
|
||||||
|
{{- else if and .Values.rustfs.auth.secretKey (not (hasPrefix "change-me" .Values.rustfs.auth.secretKey)) (ne .Values.rustfs.auth.secretKey "") }}
|
||||||
|
{{- $secret = .Values.rustfs.auth.secretKey }}
|
||||||
|
{{- else }}
|
||||||
|
{{- $secret = randAlphaNum 40 }}
|
||||||
|
{{- end }}
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: {{ $rsName }}
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
type: Opaque
|
||||||
|
stringData:
|
||||||
|
access-key: {{ $access | quote }}
|
||||||
|
secret-key: {{ $secret | quote }}
|
||||||
|
{{- end }}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
{{- if .Values.serviceAccount.create }}
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
name: {{ include "pargar.serviceAccountName" . }}
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
{{- with .Values.serviceAccount.annotations }}
|
||||||
|
annotations:
|
||||||
|
{{- toYaml . | nindent 4 }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
{{- if and .Values.ingress.enabled .Values.ingress.tls.enabled (not .Values.ingress.tls.existingSecret) (not .Values.certManager.enabled) }}
|
||||||
|
{{- $secretName := include "pargar.tlsSecretName" . }}
|
||||||
|
{{- $existing := lookup "v1" "Secret" .Release.Namespace $secretName }}
|
||||||
|
{{- $cn := .Values.global.domain }}
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: {{ $secretName }}
|
||||||
|
labels:
|
||||||
|
{{- include "pargar.labels" . | nindent 4 }}
|
||||||
|
type: kubernetes.tls
|
||||||
|
data:
|
||||||
|
{{- if $existing }}
|
||||||
|
tls.crt: {{ index $existing.data "tls.crt" }}
|
||||||
|
tls.key: {{ index $existing.data "tls.key" }}
|
||||||
|
{{- else }}
|
||||||
|
{{- $cert := genSelfSignedCert $cn nil (list $cn) 3650 }}
|
||||||
|
tls.crt: {{ $cert.Cert | b64enc }}
|
||||||
|
tls.key: {{ $cert.Key | b64enc }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
# Local k3s profile — self-signed TLS, in-cluster data, single replicas.
|
||||||
|
# helm upgrade --install pargar ./deploy/helm/pargar -n pargar --create-namespace -f deploy/helm/pargar/values-k3s.yaml
|
||||||
|
#
|
||||||
|
# After install, add to /etc/hosts: <NODE_IP> pargar.local
|
||||||
|
|
||||||
|
global:
|
||||||
|
domain: pargar.local
|
||||||
|
publicUrl: https://pargar.local
|
||||||
|
frontendOrigins: "https://pargar.local"
|
||||||
|
|
||||||
|
backend:
|
||||||
|
replicaCount: 1
|
||||||
|
image:
|
||||||
|
repository: pargar-backend
|
||||||
|
tag: local
|
||||||
|
pullPolicy: IfNotPresent
|
||||||
|
env:
|
||||||
|
seedCurriculum: "true"
|
||||||
|
|
||||||
|
frontend:
|
||||||
|
replicaCount: 1
|
||||||
|
image:
|
||||||
|
repository: pargar-frontend
|
||||||
|
tag: local
|
||||||
|
pullPolicy: IfNotPresent
|
||||||
|
|
||||||
|
postgres:
|
||||||
|
enabled: true
|
||||||
|
persistence:
|
||||||
|
size: 5Gi
|
||||||
|
|
||||||
|
redis:
|
||||||
|
enabled: true
|
||||||
|
persistence:
|
||||||
|
size: 1Gi
|
||||||
|
|
||||||
|
rustfs:
|
||||||
|
enabled: true
|
||||||
|
persistence:
|
||||||
|
size: 10Gi
|
||||||
|
consoleEnable: false
|
||||||
|
|
||||||
|
backup:
|
||||||
|
enabled: true
|
||||||
|
schedule: "0 3 * * *"
|
||||||
|
retentionDays: 7
|
||||||
|
persistence:
|
||||||
|
size: 2Gi
|
||||||
|
|
||||||
|
ingress:
|
||||||
|
enabled: true
|
||||||
|
useIngressRoute: true
|
||||||
|
tls:
|
||||||
|
enabled: true
|
||||||
|
existingSecret: "" # chart generates self-signed for pargar.local
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
# Production profile — external data plane, registry images, HPA/PDB/NetworkPolicy, cert-manager.
|
||||||
|
# helm upgrade --install pargar ./deploy/helm/pargar -n pargar --create-namespace \
|
||||||
|
# -f deploy/helm/pargar/values-prod.yaml
|
||||||
|
#
|
||||||
|
# Prerequisites:
|
||||||
|
# - images pushed to ghcr.io/pargar/{backend,frontend}:<tag>
|
||||||
|
# - Secret pargar-app (jwt-secret, admin-password, metrics-token, database-url, redis-url,
|
||||||
|
# storage-access-key, storage-secret-key)
|
||||||
|
# - cert-manager ClusterIssuer letsencrypt-prod
|
||||||
|
# - imagePullSecrets if the registry is private
|
||||||
|
|
||||||
|
global:
|
||||||
|
domain: app.example.com
|
||||||
|
publicUrl: https://app.example.com
|
||||||
|
frontendOrigins: "https://app.example.com"
|
||||||
|
imageRegistry: ghcr.io/pargar
|
||||||
|
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: ghcr-pull
|
||||||
|
|
||||||
|
backend:
|
||||||
|
replicaCount: 2
|
||||||
|
image:
|
||||||
|
repository: backend
|
||||||
|
tag: "0.1.3"
|
||||||
|
pullPolicy: IfNotPresent
|
||||||
|
existingSecret: pargar-app
|
||||||
|
env:
|
||||||
|
devMode: "false"
|
||||||
|
seedCurriculum: "false"
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 100m
|
||||||
|
memory: 256Mi
|
||||||
|
limits:
|
||||||
|
cpu: "2"
|
||||||
|
memory: 1Gi
|
||||||
|
autoscaling:
|
||||||
|
enabled: true
|
||||||
|
minReplicas: 2
|
||||||
|
maxReplicas: 8
|
||||||
|
targetCPUUtilizationPercentage: 70
|
||||||
|
targetMemoryUtilizationPercentage: 80
|
||||||
|
podDisruptionBudget:
|
||||||
|
enabled: true
|
||||||
|
minAvailable: 1
|
||||||
|
|
||||||
|
frontend:
|
||||||
|
replicaCount: 2
|
||||||
|
image:
|
||||||
|
repository: frontend
|
||||||
|
tag: "0.1.3"
|
||||||
|
pullPolicy: IfNotPresent
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 100m
|
||||||
|
memory: 256Mi
|
||||||
|
limits:
|
||||||
|
cpu: "2"
|
||||||
|
memory: 1Gi
|
||||||
|
autoscaling:
|
||||||
|
enabled: true
|
||||||
|
minReplicas: 2
|
||||||
|
maxReplicas: 8
|
||||||
|
targetCPUUtilizationPercentage: 70
|
||||||
|
targetMemoryUtilizationPercentage: 80
|
||||||
|
podDisruptionBudget:
|
||||||
|
enabled: true
|
||||||
|
minAvailable: 1
|
||||||
|
|
||||||
|
# Prefer managed Postgres / Redis / object storage in real prod.
|
||||||
|
postgres:
|
||||||
|
enabled: false
|
||||||
|
redis:
|
||||||
|
enabled: false
|
||||||
|
rustfs:
|
||||||
|
enabled: false
|
||||||
|
|
||||||
|
external:
|
||||||
|
databaseUrl: "" # prefer secret key database-url on pargar-app
|
||||||
|
redisUrl: ""
|
||||||
|
storageEndpoint: "https://s3.example.com"
|
||||||
|
|
||||||
|
ingress:
|
||||||
|
enabled: true
|
||||||
|
useIngressRoute: true
|
||||||
|
tls:
|
||||||
|
enabled: true
|
||||||
|
existingSecret: "" # Certificate CR owns the secret below
|
||||||
|
clusterIssuer: letsencrypt-prod
|
||||||
|
|
||||||
|
certManager:
|
||||||
|
enabled: true
|
||||||
|
issuerRef:
|
||||||
|
name: letsencrypt-prod
|
||||||
|
kind: ClusterIssuer
|
||||||
|
|
||||||
|
networkPolicy:
|
||||||
|
enabled: true
|
||||||
|
ingressNamespaces:
|
||||||
|
- kube-system
|
||||||
|
ingressPodLabels:
|
||||||
|
app.kubernetes.io/name: traefik
|
||||||
@@ -0,0 +1,231 @@
|
|||||||
|
# Default values — safe for local k3s. Override with values-k3s.yaml / values-prod.yaml.
|
||||||
|
|
||||||
|
nameOverride: ""
|
||||||
|
fullnameOverride: ""
|
||||||
|
|
||||||
|
global:
|
||||||
|
# Public hostname (Ingress / TLS / PUBLIC_URL)
|
||||||
|
domain: pargar.local
|
||||||
|
# Full public origin browsers use (must match Ingress TLS host)
|
||||||
|
publicUrl: https://pargar.local
|
||||||
|
frontendOrigins: "https://pargar.local"
|
||||||
|
# Docker/k8s pod+service CIDRs — Traefik peer is trusted for X-Forwarded-*
|
||||||
|
trustedProxyCIDRs: "10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,127.0.0.0/8,::1/128"
|
||||||
|
# Optional registry prefix, e.g. ghcr.io/pargar → images become ghcr.io/pargar/<repository>:<tag>
|
||||||
|
imageRegistry: ""
|
||||||
|
|
||||||
|
imagePullSecrets: []
|
||||||
|
|
||||||
|
backend:
|
||||||
|
enabled: true
|
||||||
|
replicaCount: 1
|
||||||
|
image:
|
||||||
|
repository: pargar-backend
|
||||||
|
tag: local
|
||||||
|
pullPolicy: IfNotPresent
|
||||||
|
service:
|
||||||
|
port: 8080
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 50m
|
||||||
|
memory: 128Mi
|
||||||
|
limits:
|
||||||
|
cpu: "1"
|
||||||
|
memory: 512Mi
|
||||||
|
autoscaling:
|
||||||
|
enabled: false
|
||||||
|
minReplicas: 2
|
||||||
|
maxReplicas: 6
|
||||||
|
targetCPUUtilizationPercentage: 70
|
||||||
|
targetMemoryUtilizationPercentage: 80
|
||||||
|
podDisruptionBudget:
|
||||||
|
enabled: false
|
||||||
|
minAvailable: 1
|
||||||
|
env:
|
||||||
|
devMode: "false"
|
||||||
|
seedCurriculum: "false"
|
||||||
|
# false behind NAT / shared egress (peer IP is not a real client).
|
||||||
|
registrationEnforceIP: "false"
|
||||||
|
donationEnabled: "true"
|
||||||
|
# Offline payment only — leave off until ops process is ready; enable in admin settings.
|
||||||
|
physicalCertEnabled: "false"
|
||||||
|
physicalCertPriceIrr: "2500000"
|
||||||
|
physicalCertWindowDays: "30"
|
||||||
|
otelEndpoint: ""
|
||||||
|
otelServiceName: pargar-api
|
||||||
|
# Created only when admin user is missing (see seed.ensureBootstrapAdmin)
|
||||||
|
admin:
|
||||||
|
name: Admin
|
||||||
|
username: admin
|
||||||
|
email: admin@example.com
|
||||||
|
# Prefer existingSecret in production. When empty, chart generate-once (lookup + rand).
|
||||||
|
existingSecret: ""
|
||||||
|
# Optional overrides; leave empty to auto-generate strong values (placeholders like change-me-* are ignored).
|
||||||
|
secrets:
|
||||||
|
jwtSecret: ""
|
||||||
|
adminPassword: ""
|
||||||
|
metricsToken: ""
|
||||||
|
|
||||||
|
frontend:
|
||||||
|
enabled: true
|
||||||
|
replicaCount: 1
|
||||||
|
image:
|
||||||
|
repository: pargar-frontend
|
||||||
|
tag: local
|
||||||
|
pullPolicy: IfNotPresent
|
||||||
|
service:
|
||||||
|
port: 3000
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 50m
|
||||||
|
memory: 128Mi
|
||||||
|
limits:
|
||||||
|
cpu: "1"
|
||||||
|
memory: 512Mi
|
||||||
|
autoscaling:
|
||||||
|
enabled: false
|
||||||
|
minReplicas: 2
|
||||||
|
maxReplicas: 6
|
||||||
|
targetCPUUtilizationPercentage: 70
|
||||||
|
targetMemoryUtilizationPercentage: 80
|
||||||
|
podDisruptionBudget:
|
||||||
|
enabled: false
|
||||||
|
minAvailable: 1
|
||||||
|
|
||||||
|
# In-cluster data plane (k3s / small clusters). Disable and point to managed services in prod.
|
||||||
|
postgres:
|
||||||
|
enabled: true
|
||||||
|
image: postgres:16.4-alpine
|
||||||
|
persistence:
|
||||||
|
enabled: true
|
||||||
|
size: 10Gi
|
||||||
|
storageClass: ""
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 50m
|
||||||
|
memory: 128Mi
|
||||||
|
limits:
|
||||||
|
memory: 512Mi
|
||||||
|
auth:
|
||||||
|
username: pargar
|
||||||
|
database: pargar
|
||||||
|
# Empty → chart generate-once; placeholders change-me-* are ignored.
|
||||||
|
password: ""
|
||||||
|
existingSecret: ""
|
||||||
|
|
||||||
|
redis:
|
||||||
|
enabled: true
|
||||||
|
image: redis@sha256:858f009f9709ce576febc734aa78b8f6d624b82571f9ddb6bda4377c833b3499
|
||||||
|
persistence:
|
||||||
|
enabled: true
|
||||||
|
size: 2Gi
|
||||||
|
storageClass: ""
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 25m
|
||||||
|
memory: 64Mi
|
||||||
|
limits:
|
||||||
|
memory: 256Mi
|
||||||
|
auth:
|
||||||
|
password: ""
|
||||||
|
existingSecret: ""
|
||||||
|
|
||||||
|
rustfs:
|
||||||
|
enabled: true
|
||||||
|
image: rustfs/rustfs@sha256:1803faef57627e2d9c2e7d89d655d712ddded5389040054987163043fecb6a3c
|
||||||
|
persistence:
|
||||||
|
enabled: true
|
||||||
|
size: 20Gi
|
||||||
|
storageClass: ""
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 50m
|
||||||
|
memory: 128Mi
|
||||||
|
limits:
|
||||||
|
memory: 512Mi
|
||||||
|
auth:
|
||||||
|
accessKey: "pargar-rustfs"
|
||||||
|
secretKey: ""
|
||||||
|
bucket: pargar
|
||||||
|
region: us-east-1
|
||||||
|
consoleEnable: false
|
||||||
|
existingSecret: ""
|
||||||
|
|
||||||
|
# Postgres dump CronJob (in-cluster postgres only).
|
||||||
|
backup:
|
||||||
|
enabled: false
|
||||||
|
schedule: "0 3 * * *"
|
||||||
|
retentionDays: 7
|
||||||
|
persistence:
|
||||||
|
size: 5Gi
|
||||||
|
storageClass: ""
|
||||||
|
image: postgres:16.4-alpine
|
||||||
|
|
||||||
|
# External endpoints when in-cluster postgres/redis/rustfs are disabled.
|
||||||
|
# Prefer putting these in backend.existingSecret in production.
|
||||||
|
external:
|
||||||
|
databaseUrl: ""
|
||||||
|
redisUrl: ""
|
||||||
|
storageEndpoint: ""
|
||||||
|
storageAccessKey: ""
|
||||||
|
storageSecretKey: ""
|
||||||
|
|
||||||
|
ingress:
|
||||||
|
enabled: true
|
||||||
|
# k3s ships Traefik; use IngressRoute CRDs (recommended) or standard Ingress
|
||||||
|
className: traefik
|
||||||
|
# Use Traefik IngressRoute + Middleware CRDs (true) vs networking.k8s.io/Ingress (false)
|
||||||
|
useIngressRoute: true
|
||||||
|
annotations: {}
|
||||||
|
tls:
|
||||||
|
enabled: true
|
||||||
|
# When empty and certManager.enabled=false, chart creates a self-signed Secret for k3s/dev.
|
||||||
|
# Prefer certManager.enabled=true in prod, or set existingSecret to a pre-created TLS secret.
|
||||||
|
existingSecret: ""
|
||||||
|
# cert-manager ClusterIssuer name (annotation helper when useIngressRoute=false)
|
||||||
|
clusterIssuer: ""
|
||||||
|
|
||||||
|
# cert-manager Certificate CR (writes TLS secret used by IngressRoute)
|
||||||
|
certManager:
|
||||||
|
enabled: false
|
||||||
|
duration: 2160h
|
||||||
|
renewBefore: 360h
|
||||||
|
issuerRef:
|
||||||
|
name: letsencrypt-prod
|
||||||
|
kind: ClusterIssuer
|
||||||
|
group: ""
|
||||||
|
extraDnsNames: []
|
||||||
|
|
||||||
|
# Restrict pod traffic (off for local k3s; on in values-prod.yaml)
|
||||||
|
networkPolicy:
|
||||||
|
enabled: false
|
||||||
|
# Namespaces whose pods may reach frontend/backend (Traefik)
|
||||||
|
ingressNamespaces:
|
||||||
|
- kube-system
|
||||||
|
ingressPodLabels:
|
||||||
|
app.kubernetes.io/name: traefik
|
||||||
|
|
||||||
|
middlewares:
|
||||||
|
securityHeaders: true
|
||||||
|
compress: true
|
||||||
|
redirectHttps: true
|
||||||
|
|
||||||
|
serviceAccount:
|
||||||
|
create: true
|
||||||
|
name: ""
|
||||||
|
annotations: {}
|
||||||
|
|
||||||
|
podSecurityContext:
|
||||||
|
fsGroup: 10001
|
||||||
|
|
||||||
|
securityContext:
|
||||||
|
runAsNonRoot: true
|
||||||
|
runAsUser: 10001
|
||||||
|
allowPrivilegeEscalation: false
|
||||||
|
readOnlyRootFilesystem: false
|
||||||
|
capabilities:
|
||||||
|
drop: ["ALL"]
|
||||||
|
|
||||||
|
nodeSelector: {}
|
||||||
|
tolerations: []
|
||||||
|
affinity: {}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
# Shared Traefik middlewares (file provider).
|
||||||
|
# Applied via Docker labels / IngressRoute references.
|
||||||
|
|
||||||
|
http:
|
||||||
|
middlewares:
|
||||||
|
redirect-https:
|
||||||
|
redirectScheme:
|
||||||
|
scheme: https
|
||||||
|
permanent: true
|
||||||
|
|
||||||
|
security-headers:
|
||||||
|
headers:
|
||||||
|
stsSeconds: 31536000
|
||||||
|
stsIncludeSubdomains: true
|
||||||
|
stsPreload: false
|
||||||
|
contentTypeNosniff: true
|
||||||
|
browserXssFilter: true
|
||||||
|
frameDeny: true
|
||||||
|
referrerPolicy: strict-origin-when-cross-origin
|
||||||
|
permissionsPolicy: "camera=(), microphone=(), geolocation=()"
|
||||||
|
customResponseHeaders:
|
||||||
|
Server: ""
|
||||||
|
Content-Security-Policy: >-
|
||||||
|
default-src 'self'; base-uri 'self'; form-action 'self';
|
||||||
|
frame-ancestors 'none'; object-src 'none';
|
||||||
|
script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline';
|
||||||
|
img-src 'self' data: blob:; font-src 'self' data:;
|
||||||
|
media-src 'self' blob:; connect-src 'self' ws: wss:;
|
||||||
|
worker-src 'self' blob:
|
||||||
|
|
||||||
|
compress:
|
||||||
|
compress: {}
|
||||||
|
|
||||||
|
noindex:
|
||||||
|
headers:
|
||||||
|
customResponseHeaders:
|
||||||
|
X-Robots-Tag: "noindex, nofollow, noarchive"
|
||||||
|
|
||||||
|
# Strip client-supplied forwarding headers before Traefik re-adds trusted ones.
|
||||||
|
# Backend trusts X-Forwarded-* only from TRUSTED_PROXY_CIDRS (Docker/k8s nets).
|
||||||
|
strip-forwarded:
|
||||||
|
headers:
|
||||||
|
customRequestHeaders:
|
||||||
|
X-Real-IP: ""
|
||||||
|
X-Forwarded-For: ""
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# Default local stack = base + Traefik (dev).
|
||||||
|
# Prefer explicit scripts for clarity:
|
||||||
|
# ./scripts/compose-dev.sh up -d --build
|
||||||
|
# ./scripts/compose-prod.sh up -d --build
|
||||||
|
#
|
||||||
|
# Equivalent:
|
||||||
|
# docker compose -f deploy/compose/compose.yaml -f deploy/compose/compose.dev.yaml up -d --build
|
||||||
|
|
||||||
|
include:
|
||||||
|
- path: deploy/compose/compose.yaml
|
||||||
|
- path: deploy/compose/compose.dev.yaml
|
||||||
@@ -63,6 +63,7 @@ One of two patterns:
|
|||||||
|----------|-----------------|--------|
|
|----------|-----------------|--------|
|
||||||
| `DEV_MODE` | false | Open metrics without token, limited fail-open behavior |
|
| `DEV_MODE` | false | Open metrics without token, limited fail-open behavior |
|
||||||
| `SEED_CURRICULUM` | false (empty in DevMode → true) | Seed lessons/events |
|
| `SEED_CURRICULUM` | false (empty in DevMode → true) | Seed lessons/events |
|
||||||
|
| `REGISTRATION_ENFORCE_IP` | false | One registration per client IP; keep off behind NAT |
|
||||||
| `CAPTCHA_EXPOSE_ANSWER` | DevMode only | For tests; never in production |
|
| `CAPTCHA_EXPOSE_ANSWER` | DevMode only | For tests; never in production |
|
||||||
| `DONATION_ENABLED` | true | Support card |
|
| `DONATION_ENABLED` | true | Support card |
|
||||||
| `DONATION_NOTE` | Copy text | |
|
| `DONATION_NOTE` | Copy text | |
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
- Whitelist and blacklist are **mutually exclusive**; import resolves conflicts.
|
- Whitelist and blacklist are **mutually exclusive**; import resolves conflicts.
|
||||||
- A phone already tied to an account cannot re-enter either list as a fresh entry.
|
- A phone already tied to an account cannot re-enter either list as a fresh entry.
|
||||||
- One account per phone and per IP on registration paths.
|
- One account per phone. Optional one-account-per-IP (`REGISTRATION_ENFORCE_IP`, default off — unsuitable behind NAT).
|
||||||
- Blacklist blocks all registration paths (public + invite) and keeps a failed-attempt history tab.
|
- Blacklist blocks all registration paths (public + invite) and keeps a failed-attempt history tab.
|
||||||
|
|
||||||
## Certificates
|
## Certificates
|
||||||
|
|||||||
+5
-1
@@ -25,6 +25,10 @@ Public password recovery (`/api/auth/recovery/*` and `/recovery`) is disabled fo
|
|||||||
- Only peers in `TRUSTED_PROXY_CIDRS` are trusted for `X-Forwarded-*` / `X-Real-IP`.
|
- Only peers in `TRUSTED_PROXY_CIDRS` are trusted for `X-Forwarded-*` / `X-Real-IP`.
|
||||||
- CORS: `FRONTEND_ORIGINS` + `PUBLIC_URL` with `AllowCredentials: true`.
|
- CORS: `FRONTEND_ORIGINS` + `PUBLIC_URL` with `AllowCredentials: true`.
|
||||||
|
|
||||||
|
## Registration IP binding
|
||||||
|
|
||||||
|
`REGISTRATION_ENFORCE_IP` (default **false**) optionally limits one successful public/invite registration per client IP. Leave it off when the app sits behind NAT or shared egress and cannot see real client addresses. Enable only after the edge forwards trustworthy `X-Forwarded-For` / `X-Real-IP` via `TRUSTED_PROXY_CIDRS`.
|
||||||
|
|
||||||
## Rate limiting
|
## Rate limiting
|
||||||
|
|
||||||
| Scope | Approximate behavior |
|
| Scope | Approximate behavior |
|
||||||
@@ -34,7 +38,7 @@ Public password recovery (`/api/auth/recovery/*` and `/recovery`) is disabled fo
|
|||||||
| External chat export | ~10/min/IP |
|
| External chat export | ~10/min/IP |
|
||||||
| Per-user uploads | Separately limited |
|
| Per-user uploads | Separately limited |
|
||||||
|
|
||||||
`/api/health` is excluded from the global ceiling.
|
`/api/health` is excluded from the global ceiling. Note: per-IP rate limits still use the peer/forwarded address — configure trusted proxies when you need per-client fairness behind NAT.
|
||||||
|
|
||||||
## Uploads
|
## Uploads
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
.git
|
||||||
|
.next
|
||||||
|
node_modules
|
||||||
|
*.log
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# Local `npm run dev` (API on :8080 without Traefik). Leave empty when behind reverse proxy.
|
||||||
|
NEXT_PUBLIC_API_URL=http://localhost:8080
|
||||||
|
NEXT_PUBLIC_WS_URL=ws://localhost:8080/api/ws
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# deps
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# next
|
||||||
|
.next/
|
||||||
|
out/
|
||||||
|
|
||||||
|
# env
|
||||||
|
.env*.local
|
||||||
|
|
||||||
|
# misc
|
||||||
|
*.log
|
||||||
|
.DS_Store
|
||||||
|
npm-debug.log*
|
||||||
|
|
||||||
|
# vendored at install/build from emoji-datasource-apple (~27MB)
|
||||||
|
/public/emoji/
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
FROM node:22-alpine AS deps
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY package.json package-lock.json ./
|
||||||
|
# Ignore lifecycle scripts here — vendor script is only present after full COPY.
|
||||||
|
RUN npm ci --ignore-scripts
|
||||||
|
|
||||||
|
FROM node:22-alpine AS builder
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Empty = same-origin (Traefik reverse proxy). For direct API access set build args.
|
||||||
|
ARG NEXT_PUBLIC_API_URL=
|
||||||
|
ARG NEXT_PUBLIC_WS_URL=
|
||||||
|
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
|
||||||
|
ENV NEXT_PUBLIC_WS_URL=$NEXT_PUBLIC_WS_URL
|
||||||
|
|
||||||
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
|
COPY . .
|
||||||
|
# Vendor Apple emoji PNGs into public/ (external CDNs are often blocked).
|
||||||
|
RUN node scripts/vendor-apple-emoji.mjs && npm run build
|
||||||
|
|
||||||
|
FROM node:22-alpine AS runner
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
|
RUN addgroup -S app && adduser -S app -G app
|
||||||
|
|
||||||
|
COPY --from=builder --chown=app:app /app/public ./public
|
||||||
|
COPY --from=builder --chown=app:app /app/.next ./.next
|
||||||
|
COPY --from=builder --chown=app:app /app/package.json ./package.json
|
||||||
|
COPY --from=builder --chown=app:app /app/next.config.mjs ./next.config.mjs
|
||||||
|
COPY --from=builder --chown=app:app /app/node_modules ./node_modules
|
||||||
|
|
||||||
|
# Public assets are required at runtime for /logo.png and for the
|
||||||
|
# /_next/image optimizer's internal fetch of local paths.
|
||||||
|
# next.config.mjs is required at runtime so images.contentDispositionType
|
||||||
|
# and other config overrides are applied (not only baked into manifests).
|
||||||
|
USER app
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
CMD ["npm", "run", "start"]
|
||||||
Vendored
+6
@@ -0,0 +1,6 @@
|
|||||||
|
/// <reference types="next" />
|
||||||
|
/// <reference types="next/image-types/global" />
|
||||||
|
/// <reference path="./.next/types/routes.d.ts" />
|
||||||
|
|
||||||
|
// NOTE: This file should not be edited
|
||||||
|
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
/** @type {import('next').NextConfig} */
|
||||||
|
const nextConfig = {
|
||||||
|
reactStrictMode: true,
|
||||||
|
eslint: { ignoreDuringBuilds: true },
|
||||||
|
images: {
|
||||||
|
// Default "attachment" can prevent some clients from rendering /_next/image in <img>.
|
||||||
|
contentDispositionType: "inline",
|
||||||
|
},
|
||||||
|
async redirects() {
|
||||||
|
return [
|
||||||
|
// Student self-service password recovery is disabled.
|
||||||
|
{ source: "/recovery", destination: "/login", permanent: false },
|
||||||
|
];
|
||||||
|
},
|
||||||
|
async headers() {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
source: "/c/:path*",
|
||||||
|
headers: [{ key: "X-Robots-Tag", value: "noindex, nofollow, noarchive" }],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default nextConfig;
|
||||||
Generated
+2760
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,53 @@
|
|||||||
|
{
|
||||||
|
"name": "pargar-frontend",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"dev": "next dev -p 3000",
|
||||||
|
"prebuild": "node scripts/vendor-apple-emoji.mjs",
|
||||||
|
"vendor:emoji": "node scripts/vendor-apple-emoji.mjs",
|
||||||
|
"build": "next build",
|
||||||
|
"start": "next start -p 3000",
|
||||||
|
"lint": "next lint",
|
||||||
|
"typecheck": "tsc --noEmit"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@radix-ui/react-avatar": "^1.1.2",
|
||||||
|
"@radix-ui/react-dialog": "^1.1.4",
|
||||||
|
"@radix-ui/react-dropdown-menu": "^2.1.4",
|
||||||
|
"@radix-ui/react-label": "^2.1.1",
|
||||||
|
"@radix-ui/react-slot": "^1.1.1",
|
||||||
|
"@radix-ui/react-switch": "^1.1.2",
|
||||||
|
"@radix-ui/react-tabs": "^1.1.2",
|
||||||
|
"@tanstack/react-query": "^5.62.0",
|
||||||
|
"boring-avatars": "^2.0.4",
|
||||||
|
"class-variance-authority": "^0.7.1",
|
||||||
|
"clsx": "^2.1.1",
|
||||||
|
"date-fns": "^4.1.0",
|
||||||
|
"emoji-datasource-apple": "^15.1.2",
|
||||||
|
"framer-motion": "^12.0.0",
|
||||||
|
"lucide-react": "^0.468.0",
|
||||||
|
"next": "15.5.27",
|
||||||
|
"next-themes": "^0.4.4",
|
||||||
|
"react": "^19.0.0",
|
||||||
|
"react-dom": "^19.0.0",
|
||||||
|
"react-multi-date-picker": "^4.5.2",
|
||||||
|
"sonner": "^1.7.1",
|
||||||
|
"tailwind-merge": "^2.6.0",
|
||||||
|
"tw-animate-css": "^1.4.0",
|
||||||
|
"zustand": "^5.0.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@tailwindcss/postcss": "^4.0.0",
|
||||||
|
"@types/node": "^22.10.0",
|
||||||
|
"@types/react": "^19.0.0",
|
||||||
|
"@types/react-dom": "^19.0.0",
|
||||||
|
"tailwindcss": "^4.0.0",
|
||||||
|
"typescript": "^5.7.0"
|
||||||
|
},
|
||||||
|
"overrides": {
|
||||||
|
"postcss": "8.5.28",
|
||||||
|
"sharp": "0.35.5",
|
||||||
|
"source-map-js": "1.2.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
const config = {
|
||||||
|
plugins: {
|
||||||
|
"@tailwindcss/postcss": {},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default config;
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 31 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 149 KiB |
@@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
/**
|
||||||
|
* Copy Apple Color Emoji 64px PNGs into public/ so chat never depends on
|
||||||
|
* external CDNs (often blocked). Source: emoji-datasource-apple.
|
||||||
|
*/
|
||||||
|
import { cpSync, existsSync, mkdirSync, rmSync } from "node:fs";
|
||||||
|
import { dirname, join } from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
|
||||||
|
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
||||||
|
const src = join(root, "node_modules/emoji-datasource-apple/img/apple/64");
|
||||||
|
const dest = join(root, "public/emoji/apple/64");
|
||||||
|
|
||||||
|
if (!existsSync(src)) {
|
||||||
|
console.warn("[vendor-apple-emoji] skip: emoji-datasource-apple not installed");
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
mkdirSync(dirname(dest), { recursive: true });
|
||||||
|
rmSync(dest, { recursive: true, force: true });
|
||||||
|
cpSync(src, dest, { recursive: true });
|
||||||
|
console.log("[vendor-apple-emoji] copied → public/emoji/apple/64");
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { Suspense } from "react";
|
||||||
|
import { AdminStudio } from "@/components/admin-studio";
|
||||||
|
|
||||||
|
export default function AdminPage() {
|
||||||
|
return (
|
||||||
|
<Suspense fallback={null}>
|
||||||
|
<AdminStudio />
|
||||||
|
</Suspense>
|
||||||
|
);
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
@@ -0,0 +1,219 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { useParams } from "next/navigation";
|
||||||
|
import { Loader2, Package } from "lucide-react";
|
||||||
|
import { CertificateCard } from "@/components/certificate-card";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { http, toUserError } from "@/lib/api";
|
||||||
|
import { useAuth } from "@/lib/auth-store";
|
||||||
|
import type { Certificate, CertificatePhysicalOrder, PhysicalCertSettings } from "@/lib/types";
|
||||||
|
import { toast } from "@/components/providers";
|
||||||
|
import { formatFaNumber } from "@/lib/utils";
|
||||||
|
import { clampPhoneInput, normalizePhone, PHONE_INPUT_MAX_LEN } from "@/lib/validation";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
|
type PublicCertResponse = {
|
||||||
|
certificate: { publicId: string; fullName: string; issuedAt: string };
|
||||||
|
course: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const STATUS_LABEL: Record<string, string> = {
|
||||||
|
requested: "درخواستشده — منتظر تأیید پرداخت",
|
||||||
|
paid: "پرداخت تأیید شد — در صف ارسال",
|
||||||
|
shipped: "ارسال شد",
|
||||||
|
cancelled: "لغو شده",
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function CertificatePage() {
|
||||||
|
const params = useParams<{ id: string }>();
|
||||||
|
const publicId = params?.id ?? "";
|
||||||
|
const authUser = useAuth((s) => s.user);
|
||||||
|
const qc = useQueryClient();
|
||||||
|
const [requesting, setRequesting] = useState(false);
|
||||||
|
const [form, setForm] = useState({
|
||||||
|
recipientName: "",
|
||||||
|
phone: "",
|
||||||
|
address: "",
|
||||||
|
city: "",
|
||||||
|
postalCode: "",
|
||||||
|
});
|
||||||
|
|
||||||
|
const { data, isLoading, error } = useQuery({
|
||||||
|
queryKey: ["certificate", publicId],
|
||||||
|
queryFn: () => http.get<PublicCertResponse>(`/api/certificates/${publicId}`),
|
||||||
|
enabled: !!publicId,
|
||||||
|
meta: { silentError: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
const { data: mine } = useQuery({
|
||||||
|
queryKey: ["me", "certificate"],
|
||||||
|
queryFn: () =>
|
||||||
|
http.get<{
|
||||||
|
certificate: Certificate | null;
|
||||||
|
physicalOrder: CertificatePhysicalOrder | null;
|
||||||
|
physical: PhysicalCertSettings;
|
||||||
|
}>("/api/me/certificate"),
|
||||||
|
enabled: !!authUser,
|
||||||
|
});
|
||||||
|
|
||||||
|
const isOwner = !!authUser && mine?.certificate?.publicId === publicId;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isOwner || !authUser) return;
|
||||||
|
setForm((f) => ({
|
||||||
|
...f,
|
||||||
|
recipientName: f.recipientName || authUser.name || "",
|
||||||
|
phone: f.phone || authUser.phone || "",
|
||||||
|
}));
|
||||||
|
}, [isOwner, authUser]);
|
||||||
|
|
||||||
|
const requestPhysical = async () => {
|
||||||
|
setRequesting(true);
|
||||||
|
try {
|
||||||
|
await http.post("/api/me/certificate/physical", {
|
||||||
|
...form,
|
||||||
|
phone: normalizePhone(form.phone),
|
||||||
|
});
|
||||||
|
toast.success("درخواست ثبت شد — پس از واریز با ادمین هماهنگ کنید");
|
||||||
|
qc.invalidateQueries({ queryKey: ["me", "certificate"] });
|
||||||
|
} catch (e) {
|
||||||
|
toast.error(toUserError(e));
|
||||||
|
} finally {
|
||||||
|
setRequesting(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return (
|
||||||
|
<div className="flex min-h-[60vh] items-center justify-center">
|
||||||
|
<Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error || !data?.certificate) {
|
||||||
|
return (
|
||||||
|
<div className="mx-auto max-w-lg px-4 py-16 text-center">
|
||||||
|
<p className="text-lg font-bold">گواهینامه پیدا نشد</p>
|
||||||
|
<Button asChild className="mt-4" variant="outline">
|
||||||
|
<Link href="/">بازگشت</Link>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const cert = data.certificate;
|
||||||
|
const order = isOwner ? mine?.physicalOrder : null;
|
||||||
|
const physical = isOwner ? mine?.physical : null;
|
||||||
|
const windowEndsAt = mine?.certificate?.issuedAt
|
||||||
|
? new Date(mine.certificate.issuedAt).getTime() + (physical?.windowDays ?? 30) * 86400000
|
||||||
|
: 0;
|
||||||
|
const windowStillOpen = !windowEndsAt || Date.now() < windowEndsAt;
|
||||||
|
const windowOpen =
|
||||||
|
physical?.enabled &&
|
||||||
|
windowStillOpen &&
|
||||||
|
(!order || order.status === "cancelled") &&
|
||||||
|
!!mine?.certificate;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<CertificateCard
|
||||||
|
cert={{
|
||||||
|
publicId: cert.publicId,
|
||||||
|
fullName: cert.fullName,
|
||||||
|
issuedAt: cert.issuedAt,
|
||||||
|
course: data.course,
|
||||||
|
}}
|
||||||
|
showOwnerLinks={!!authUser}
|
||||||
|
>
|
||||||
|
{isOwner && physical?.enabled && (
|
||||||
|
<div className="mt-8 space-y-3 border-t border-border pt-6">
|
||||||
|
<p className="flex items-center gap-2 text-sm font-bold">
|
||||||
|
<Package className="h-4 w-4" /> نسخه فیزیکی
|
||||||
|
</p>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
قیمت حدودی {formatFaNumber(physical.priceIrr)} ریال · مهلت درخواست{" "}
|
||||||
|
{formatFaNumber(physical.windowDays)} روز از صدور
|
||||||
|
{windowEndsAt ? ` (تا ${new Date(windowEndsAt).toLocaleDateString("fa-IR")})` : ""}.
|
||||||
|
پرداخت آنلاین در سامانه نداریم. پس از واریز بیرونی با ادمین هماهنگ کنید تا وضعیت سفارش بهروز شود.
|
||||||
|
</p>
|
||||||
|
{order && order.status !== "cancelled" ? (
|
||||||
|
<div className="space-y-2 rounded-xl border border-border bg-muted/30 p-3 text-sm">
|
||||||
|
<p>
|
||||||
|
وضعیت: <span className="font-medium">{STATUS_LABEL[order.status] ?? order.status}</span>
|
||||||
|
</p>
|
||||||
|
{order.trackingCode && (
|
||||||
|
<p className="font-mono text-xs" dir="ltr">
|
||||||
|
کد پیگیری: {order.trackingCode}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
{order.city && (
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
ارسال به {order.recipientName || "—"} · {order.city}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
{order.note && <p className="text-xs text-muted-foreground">یادداشت ادمین: {order.note}</p>}
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() =>
|
||||||
|
window.dispatchEvent(new CustomEvent("pargar:chat", { detail: { open: true } }))
|
||||||
|
}
|
||||||
|
>
|
||||||
|
هماهنگی با تیم
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
) : windowOpen ? (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<div className="grid gap-2 sm:grid-cols-2">
|
||||||
|
<Input
|
||||||
|
placeholder="نام گیرنده"
|
||||||
|
value={form.recipientName}
|
||||||
|
onChange={(e) => setForm((f) => ({ ...f, recipientName: e.target.value }))}
|
||||||
|
/>
|
||||||
|
<Input
|
||||||
|
placeholder="موبایل"
|
||||||
|
value={form.phone}
|
||||||
|
onChange={(e) => setForm((f) => ({ ...f, phone: clampPhoneInput(e.target.value) }))}
|
||||||
|
dir="ltr"
|
||||||
|
inputMode="tel"
|
||||||
|
maxLength={PHONE_INPUT_MAX_LEN}
|
||||||
|
className="text-left"
|
||||||
|
/>
|
||||||
|
<Input
|
||||||
|
placeholder="شهر"
|
||||||
|
value={form.city}
|
||||||
|
onChange={(e) => setForm((f) => ({ ...f, city: e.target.value }))}
|
||||||
|
/>
|
||||||
|
<Input
|
||||||
|
placeholder="کد پستی"
|
||||||
|
value={form.postalCode}
|
||||||
|
onChange={(e) => setForm((f) => ({ ...f, postalCode: e.target.value }))}
|
||||||
|
dir="ltr"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<textarea
|
||||||
|
className="min-h-[72px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm"
|
||||||
|
placeholder="آدرس کامل پستی"
|
||||||
|
value={form.address}
|
||||||
|
onChange={(e) => setForm((f) => ({ ...f, address: e.target.value }))}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
disabled={requesting || !form.address.trim() || !form.city.trim()}
|
||||||
|
onClick={() => void requestPhysical()}
|
||||||
|
>
|
||||||
|
{requesting ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : <Package className="h-3.5 w-3.5" />}
|
||||||
|
ثبت درخواست نسخه فیزیکی
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
) : !windowStillOpen ? (
|
||||||
|
<p className="text-sm text-muted-foreground">مهلت درخواست نسخه فیزیکی به پایان رسیده است.</p>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</CertificateCard>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import type { Metadata } from "next";
|
||||||
|
|
||||||
|
/** Certificate share links are unlisted — never index or follow. */
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
robots: {
|
||||||
|
index: false,
|
||||||
|
follow: false,
|
||||||
|
nocache: true,
|
||||||
|
noarchive: true,
|
||||||
|
nosnippet: true,
|
||||||
|
googleBot: {
|
||||||
|
index: false,
|
||||||
|
follow: false,
|
||||||
|
noimageindex: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function CertificateLayout({ children }: { children: React.ReactNode }) {
|
||||||
|
return children;
|
||||||
|
}
|
||||||
@@ -0,0 +1,459 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useRouter, useSearchParams } from "next/navigation";
|
||||||
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { Suspense, useEffect, useRef } from "react";
|
||||||
|
import {
|
||||||
|
Award,
|
||||||
|
ArrowLeft,
|
||||||
|
BookOpenCheck,
|
||||||
|
CheckCircle2,
|
||||||
|
CalendarDays,
|
||||||
|
Flame,
|
||||||
|
Heart,
|
||||||
|
Lock,
|
||||||
|
MessageSquare,
|
||||||
|
Package,
|
||||||
|
PlayCircle,
|
||||||
|
Sparkles,
|
||||||
|
TrendingUp,
|
||||||
|
AlertTriangle,
|
||||||
|
} from "lucide-react";
|
||||||
|
import { SkillTree } from "@/components/skill-tree";
|
||||||
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
|
import { http, toUserError } from "@/lib/api";
|
||||||
|
import type { Certificate, CertificatePhysicalOrder, MeetingEvent, PhysicalCertSettings, TreeData, TreeLesson } from "@/lib/types";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { useAuth } from "@/lib/auth-store";
|
||||||
|
import { cn, formatFaNumber, formatStreakLabel } from "@/lib/utils";
|
||||||
|
import { clampHearts, hasInfiniteHearts, INFINITE_HEARTS_LABEL, MAX_HEARTS } from "@/lib/hearts";
|
||||||
|
import { toast } from "@/components/providers";
|
||||||
|
|
||||||
|
export default function CapPage() {
|
||||||
|
return (
|
||||||
|
<Suspense fallback={<CapSkeleton />}>
|
||||||
|
<CapPageInner />
|
||||||
|
</Suspense>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function CapPageInner() {
|
||||||
|
const router = useRouter();
|
||||||
|
const params = useSearchParams();
|
||||||
|
const rootRef = useRef<HTMLDivElement>(null);
|
||||||
|
const user = useAuth((s) => s.user);
|
||||||
|
const qc = useQueryClient();
|
||||||
|
|
||||||
|
const { data, isLoading } = useQuery({
|
||||||
|
queryKey: ["tree"],
|
||||||
|
queryFn: () => http.get<TreeData>("/api/tree"),
|
||||||
|
refetchInterval: 60_000,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { data: eventsData } = useQuery({
|
||||||
|
queryKey: ["events", "upcoming-cap"],
|
||||||
|
queryFn: () => http.get<{ events: MeetingEvent[] }>("/api/events"),
|
||||||
|
staleTime: 60_000,
|
||||||
|
});
|
||||||
|
|
||||||
|
const allLessons = (data?.chapters ?? []).flatMap((ch) => ch.lessons ?? []);
|
||||||
|
const completedCount = allLessons.filter((l) => l.progress?.passedQuiz).length;
|
||||||
|
const curriculumDone = allLessons.length > 0 && completedCount === allLessons.length;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const lesson = params.get("lesson");
|
||||||
|
if (lesson && rootRef.current) {
|
||||||
|
rootRef.current.scrollIntoView({ behavior: "smooth" });
|
||||||
|
}
|
||||||
|
}, [params]);
|
||||||
|
|
||||||
|
const { data: certData } = useQuery({
|
||||||
|
queryKey: ["me", "certificate"],
|
||||||
|
queryFn: () =>
|
||||||
|
http.get<{
|
||||||
|
certificate: Certificate | null;
|
||||||
|
physicalOrder: CertificatePhysicalOrder | null;
|
||||||
|
physical: PhysicalCertSettings;
|
||||||
|
}>("/api/me/certificate"),
|
||||||
|
enabled: !!user && curriculumDone,
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!curriculumDone || !user) return;
|
||||||
|
void http
|
||||||
|
.post("/api/me/certificate/issue", {})
|
||||||
|
.then(() => qc.invalidateQueries({ queryKey: ["me", "certificate"] }))
|
||||||
|
.catch((e) => toast.error(toUserError(e, "صدور گواهینامه ممکن نشد")));
|
||||||
|
}, [curriculumDone, user, qc]);
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return <CapSkeleton />;
|
||||||
|
}
|
||||||
|
|
||||||
|
const me = data?.me;
|
||||||
|
const all = allLessons;
|
||||||
|
const lockedCount = all.filter((l) => l.locked).length;
|
||||||
|
const inProgress = all.filter(
|
||||||
|
(l) => !l.locked && !l.progress?.passedQuiz && (l.progress?.watchedPct ?? 0) > 0 && !l.progress?.quizUnlocked,
|
||||||
|
);
|
||||||
|
const readyQuiz = all.filter((l) => !l.locked && !l.progress?.passedQuiz && !!l.progress?.quizUnlocked);
|
||||||
|
const openAndNew = all.filter((l) => !l.locked && !l.progress?.passedQuiz);
|
||||||
|
const firstLocked = all.find((l) => l.locked);
|
||||||
|
const done = curriculumDone;
|
||||||
|
|
||||||
|
const pct = all.length ? Math.round((completedCount / all.length) * 100) : 0;
|
||||||
|
const hearts = clampHearts(me?.hearts ?? user?.hearts ?? MAX_HEARTS);
|
||||||
|
const lowHearts = !hasInfiniteHearts(user?.role) && hearts > 0 && hearts <= 1;
|
||||||
|
const nextEvent = (eventsData?.events ?? [])[0];
|
||||||
|
const physicalOpen =
|
||||||
|
done &&
|
||||||
|
certData?.physical?.enabled &&
|
||||||
|
!!certData.certificate &&
|
||||||
|
(!certData.physicalOrder || certData.physicalOrder.status === "cancelled") &&
|
||||||
|
(!certData.certificate.issuedAt ||
|
||||||
|
Date.now() <
|
||||||
|
new Date(certData.certificate.issuedAt).getTime() +
|
||||||
|
(certData.physical.windowDays || 30) * 24 * 60 * 60 * 1000);
|
||||||
|
|
||||||
|
const next = nextAction(inProgress, readyQuiz, openAndNew, firstLocked, done);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-8" ref={rootRef}>
|
||||||
|
<div className="flex flex-wrap items-end justify-between gap-4">
|
||||||
|
<div>
|
||||||
|
<p className="section-kicker">مسیر شما</p>
|
||||||
|
<h1 className="mt-2 text-3xl font-black tracking-tight sm:text-5xl">
|
||||||
|
درخت <span className="text-primary">مهارت</span>
|
||||||
|
</h1>
|
||||||
|
<p className="mt-2 max-w-xl text-sm text-muted-foreground">
|
||||||
|
الان روی گام بعدی تمرکز کنید — تماشا، آزمون، رویداد یا گواهینامه.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span className="inline-flex items-center gap-1.5 rounded-full bg-accent/10 px-3 py-1.5 text-sm font-bold text-accent">
|
||||||
|
<Flame className="h-4 w-4" /> {formatStreakLabel(me?.streak ?? user?.streakCurrent ?? 0)}
|
||||||
|
</span>
|
||||||
|
<span className="inline-flex items-center gap-1.5 rounded-full bg-gold/10 px-3 py-1.5 text-sm font-bold text-gold">
|
||||||
|
<Sparkles className="h-4 w-4" /> {formatFaNumber(me?.xp ?? user?.xp ?? 0)} امتیاز
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
"inline-flex items-center gap-1.5 rounded-full px-3 py-1.5 text-sm font-bold",
|
||||||
|
lowHearts ? "bg-destructive/15 text-destructive" : "bg-primary/10 text-primary",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Heart className="h-4 w-4 fill-current" />{" "}
|
||||||
|
{hasInfiniteHearts(user?.role)
|
||||||
|
? `${INFINITE_HEARTS_LABEL} جان`
|
||||||
|
: `${formatFaNumber(hearts)} جان`}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{lowHearts && (
|
||||||
|
<div className="flex flex-wrap items-center justify-between gap-3 rounded-2xl border-2 border-destructive/30 bg-destructive/5 px-5 py-4">
|
||||||
|
<div className="flex items-start gap-3">
|
||||||
|
<AlertTriangle className="mt-0.5 h-5 w-5 shrink-0 text-destructive" />
|
||||||
|
<div>
|
||||||
|
<p className="text-sm font-extrabold text-destructive">فقط {formatFaNumber(hearts)} جان مانده</p>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
یک اشتباه دیگر حساب را قفل میکند. قبل از آزمون مطمئن شوید؛ اگر گیر کردید با منتور حرف بزنید.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() =>
|
||||||
|
window.dispatchEvent(new CustomEvent("pargar:chat", { detail: { open: true } }))
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<MessageSquare className="h-4 w-4" /> منتور
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{done && (
|
||||||
|
<div className="flex flex-wrap items-center justify-between gap-3 rounded-2xl border-2 border-primary/30 bg-primary/5 px-5 py-4">
|
||||||
|
<div>
|
||||||
|
<p className="text-sm font-extrabold">دوره را تمام کردید</p>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
گواهینامه دیجیتال آماده است
|
||||||
|
{physicalOpen ? " — میتوانید نسخه فیزیکی هم درخواست کنید." : "."}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-wrap gap-2">
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
const id = certData?.certificate?.publicId;
|
||||||
|
if (id) router.push(`/c/${id}`);
|
||||||
|
else {
|
||||||
|
void http
|
||||||
|
.post<{ certificate: { publicId: string } }>("/api/me/certificate/issue", {})
|
||||||
|
.then((r) => {
|
||||||
|
if (r.certificate?.publicId) router.push(`/c/${r.certificate.publicId}`);
|
||||||
|
})
|
||||||
|
.catch((e) => toast.error(toUserError(e, "صدور گواهینامه ممکن نشد")));
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Award className="h-4 w-4" /> مشاهده گواهینامه
|
||||||
|
</Button>
|
||||||
|
{physicalOpen && certData?.certificate?.publicId && (
|
||||||
|
<Button variant="outline" onClick={() => router.push(`/c/${certData.certificate!.publicId}`)}>
|
||||||
|
<Package className="h-4 w-4" /> نسخه فیزیکی
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="grid gap-5 md:grid-cols-5">
|
||||||
|
<div className="rounded-2xl border-2 border-border bg-card p-5 shadow-offset-sm md:col-span-2">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<p className="flex items-center gap-2 text-sm font-extrabold">
|
||||||
|
<TrendingUp className="h-4 w-4 text-primary" /> پیشرفت کل
|
||||||
|
</p>
|
||||||
|
<span className="text-2xl font-black tabular-nums text-primary">{pct}٪</span>
|
||||||
|
</div>
|
||||||
|
<div className="mt-3 h-3.5 w-full overflow-hidden rounded-full bg-muted">
|
||||||
|
<div className="h-full rounded-full bg-primary transition-all" style={{ width: `${Math.max(pct, 3)}%` }} />
|
||||||
|
</div>
|
||||||
|
<div className="mt-4 grid grid-cols-3 gap-2 text-center">
|
||||||
|
<div className="rounded-xl bg-success/10 px-2 py-2.5">
|
||||||
|
<p className="text-lg font-black text-success">{completedCount}</p>
|
||||||
|
<p className="text-[11px] font-bold text-muted-foreground">تکمیلشده</p>
|
||||||
|
</div>
|
||||||
|
<div className="rounded-xl bg-primary/10 px-2 py-2.5">
|
||||||
|
<p className="text-lg font-black text-primary">{inProgress.length}</p>
|
||||||
|
<p className="text-[11px] font-bold text-muted-foreground">در جریان</p>
|
||||||
|
</div>
|
||||||
|
<div className="rounded-xl bg-muted px-2 py-2.5">
|
||||||
|
<p className="text-lg font-black text-muted-foreground">{lockedCount}</p>
|
||||||
|
<p className="text-[11px] font-bold text-muted-foreground">قفلشده</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="mt-4 space-y-1.5">
|
||||||
|
{(data?.chapters ?? []).map((ch) => {
|
||||||
|
const chDone = ch.lessons.filter((l) => l.progress?.passedQuiz).length;
|
||||||
|
return (
|
||||||
|
<div key={ch.id} className="flex items-center justify-between text-xs">
|
||||||
|
<span className="font-bold text-muted-foreground">{ch.title}</span>
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
"font-black tabular-nums",
|
||||||
|
chDone === ch.lessons.length ? "text-success" : "text-foreground",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{chDone}/{ch.lessons.length}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
{nextEvent && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => router.push("/unwrap?tab=events")}
|
||||||
|
className="mt-4 flex w-full items-start gap-2 rounded-xl border border-border/70 bg-muted/40 px-3 py-2.5 text-start transition hover:border-primary/40"
|
||||||
|
>
|
||||||
|
<CalendarDays className="mt-0.5 h-4 w-4 shrink-0 text-primary" />
|
||||||
|
<span className="min-w-0">
|
||||||
|
<span className="block text-[10px] font-extrabold text-primary">رویداد نزدیک</span>
|
||||||
|
<span className="block truncate text-xs font-bold">{nextEvent.title}</span>
|
||||||
|
<span className="block text-[10px] text-muted-foreground">
|
||||||
|
{new Date(nextEvent.startsAt).toLocaleString("fa-IR")}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"flex flex-col justify-between rounded-2xl border-2 p-5 md:col-span-3",
|
||||||
|
next.locked
|
||||||
|
? "border-border bg-muted/40"
|
||||||
|
: "border-primary/40 bg-primary/5"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<p
|
||||||
|
className={cn(
|
||||||
|
"flex items-center gap-2 text-xs font-extrabold tracking-wider",
|
||||||
|
next.locked ? "text-muted-foreground" : "text-primary"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{next.locked ? <Lock className="h-4 w-4" /> : <ZapIcon className="h-4 w-4" />}
|
||||||
|
{next.locked ? "هنوز قفل است" : "گام بعدی شما"}
|
||||||
|
</p>
|
||||||
|
<div className="mt-3 flex flex-1 flex-col items-start justify-center">
|
||||||
|
<h2 className="text-xl font-black leading-snug sm:text-2xl">{next.title}</h2>
|
||||||
|
<p className="mt-1.5 text-sm leading-relaxed text-muted-foreground">{next.desc}</p>
|
||||||
|
</div>
|
||||||
|
<div className="mt-4 flex flex-wrap gap-2">
|
||||||
|
{next.cta ? (
|
||||||
|
<Button size="lg" onClick={() => router.push(next.cta!)} className="gap-2">
|
||||||
|
{next.icon} {next.label}
|
||||||
|
</Button>
|
||||||
|
) : next.prereqId ? (
|
||||||
|
<Button size="lg" variant="secondary" onClick={() => router.push(`/player/${next.prereqId}`)} className="gap-2">
|
||||||
|
<PlayCircle className="h-5 w-5" /> رفتن به پیشنیاز
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
|
<div className="inline-flex items-center gap-2 rounded-xl bg-muted px-3.5 py-2.5 text-sm font-bold text-muted-foreground">
|
||||||
|
<Lock className="h-4 w-4" /> ابتدا درس پیشنیاز را کامل کنید
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<Button
|
||||||
|
size="lg"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() =>
|
||||||
|
window.dispatchEvent(new CustomEvent("pargar:chat", { detail: { open: true } }))
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<MessageSquare className="h-5 w-5" /> منتور
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{data && <SkillTree data={data} onSelect={(id) => router.push(`/player/${id}`)} />}
|
||||||
|
|
||||||
|
<div className="flex flex-wrap items-center gap-x-5 gap-y-2 text-xs font-bold text-muted-foreground">
|
||||||
|
<span className="inline-flex items-center gap-1.5">
|
||||||
|
<CheckCircle2 className="h-4 w-4 text-success" /> تکمیلشده
|
||||||
|
</span>
|
||||||
|
<span className="inline-flex items-center gap-1.5">
|
||||||
|
<PlayCircle className="h-4 w-4 text-primary" /> در دسترس
|
||||||
|
</span>
|
||||||
|
<span className="inline-flex items-center gap-1.5">
|
||||||
|
<BookOpenCheck className="h-4 w-4 text-gold" /> آمادهٔ آزمون
|
||||||
|
</span>
|
||||||
|
<span className="inline-flex items-center gap-1.5">
|
||||||
|
<Lock className="h-4 w-4 text-muted-foreground" /> قفلشده
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function nextAction(
|
||||||
|
inProgress: TreeLesson[],
|
||||||
|
readyQuiz: TreeLesson[],
|
||||||
|
openAndNew: TreeLesson[],
|
||||||
|
firstLocked: TreeLesson | undefined,
|
||||||
|
done: boolean,
|
||||||
|
) {
|
||||||
|
if (readyQuiz[0]) {
|
||||||
|
const lesson = readyQuiz[0];
|
||||||
|
return {
|
||||||
|
title: `آزمون «${lesson.title}» منتظر شماست`,
|
||||||
|
desc: "آموختههایتان را محک بزنید؛ هر پاسخ اشتباه یک جان کم میکند.",
|
||||||
|
label: "شروع آزمون",
|
||||||
|
cta: `/quiz/${lesson.id}`,
|
||||||
|
icon: <BookOpenCheck className="h-5 w-5" />,
|
||||||
|
locked: false,
|
||||||
|
prereqId: null as number | null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (inProgress[0]) {
|
||||||
|
const lesson = inProgress[0];
|
||||||
|
const pct = Math.round(lesson.progress?.watchedPct ?? 0);
|
||||||
|
return {
|
||||||
|
title: `ادامهٔ تماشای «${lesson.title}»`,
|
||||||
|
desc: `${formatFaNumber(pct)}٪ تماشا شده — با رسیدن به آستانه، آزمون باز میشود.`,
|
||||||
|
label: "ادامهٔ تماشا",
|
||||||
|
cta: `/player/${lesson.id}`,
|
||||||
|
icon: <PlayCircle className="h-5 w-5" />,
|
||||||
|
locked: false,
|
||||||
|
prereqId: null as number | null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (openAndNew[0]) {
|
||||||
|
const lesson = openAndNew[0];
|
||||||
|
return {
|
||||||
|
title: `شروع «${lesson.title}»`,
|
||||||
|
desc: `${formatFaNumber(lesson.durationSeconds)} ثانیه تماشای تأییدشده · ${formatFaNumber(lesson.xpReward)} امتیاز پاداش در صورت تکمیل.`,
|
||||||
|
label: "شروع درس",
|
||||||
|
cta: `/player/${lesson.id}`,
|
||||||
|
icon: <PlayCircle className="h-5 w-5" />,
|
||||||
|
locked: false,
|
||||||
|
prereqId: null as number | null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (firstLocked) {
|
||||||
|
return {
|
||||||
|
title: `«${firstLocked.title}» قفل است`,
|
||||||
|
desc: "بعد از تکمیل صادقانهٔ درس پیشنیاز و قبولی در آزمونش، این شاخه باز میشود.",
|
||||||
|
label: "",
|
||||||
|
cta: null as string | null,
|
||||||
|
icon: null,
|
||||||
|
locked: true,
|
||||||
|
prereqId: firstLocked.requiresLessonId ?? null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (done) {
|
||||||
|
return {
|
||||||
|
title: "همهٔ شاخهها را آزاد کردید",
|
||||||
|
desc: "تمام دروس تکمیلشدهاند. گواهینامه را ببینید یا لیگ این هفته را فتح کنید.",
|
||||||
|
label: "رفتن به لیگها",
|
||||||
|
cta: "/leaderboard",
|
||||||
|
icon: <ArrowLeft className="h-5 w-5" />,
|
||||||
|
locked: false,
|
||||||
|
prereqId: null as number | null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
title: "مسیر آماده است",
|
||||||
|
desc: "دادهای برای نمایش نیست.",
|
||||||
|
label: "",
|
||||||
|
cta: null as string | null,
|
||||||
|
icon: null,
|
||||||
|
locked: false,
|
||||||
|
prereqId: null as number | null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function CapSkeleton() {
|
||||||
|
return (
|
||||||
|
<div className="space-y-8">
|
||||||
|
<div className="flex flex-wrap items-end justify-between gap-4">
|
||||||
|
<div className="space-y-2.5">
|
||||||
|
<Skeleton className="h-3.5 w-36" />
|
||||||
|
<Skeleton className="h-10 w-64" />
|
||||||
|
<Skeleton className="h-4 w-96 max-w-full" />
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Skeleton className="h-8 w-24 rounded-full" />
|
||||||
|
<Skeleton className="h-8 w-24 rounded-full" />
|
||||||
|
<Skeleton className="h-8 w-24 rounded-full" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="grid gap-5 md:grid-cols-5">
|
||||||
|
<div className="space-y-4 rounded-2xl border-2 border-border bg-card p-5 shadow-offset-sm md:col-span-2">
|
||||||
|
<Skeleton className="h-5 w-32" />
|
||||||
|
<Skeleton className="h-3.5 w-full rounded-full" />
|
||||||
|
<div className="grid grid-cols-3 gap-2">
|
||||||
|
{Array.from({ length: 3 }).map((_, i) => (
|
||||||
|
<Skeleton key={i} className="h-16 rounded-xl" />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="rounded-2xl border-2 border-primary/40 bg-primary/5 p-5 md:col-span-3">
|
||||||
|
<Skeleton className="h-4 w-28" />
|
||||||
|
<Skeleton className="mt-3 h-7 w-3/4" />
|
||||||
|
<Skeleton className="mt-2 h-4 w-1/2" />
|
||||||
|
<Skeleton className="mt-6 h-11 w-40 rounded-xl" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ZapIcon(props: { className?: string }) {
|
||||||
|
return (
|
||||||
|
<svg viewBox="0 0 24 24" fill="currentColor" {...props}>
|
||||||
|
<path d="M13 2 4.5 13.5H11l-.8 8.5L18.5 10H12l1-8z" />
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect } from "react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
|
||||||
|
/** Shortcut so /community never 404s. */
|
||||||
|
export default function CommunityRedirectPage() {
|
||||||
|
const router = useRouter();
|
||||||
|
useEffect(() => {
|
||||||
|
router.replace("/unwrap?tab=community");
|
||||||
|
}, [router]);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 31 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,647 @@
|
|||||||
|
@import "tailwindcss";
|
||||||
|
@import "tw-animate-css";
|
||||||
|
|
||||||
|
/* enable dark-variant & class-based theming */
|
||||||
|
@custom-variant dark (&:is(.dark *));
|
||||||
|
|
||||||
|
/* ============================================================
|
||||||
|
Pargar design system — soft pastel, a touch of glass,
|
||||||
|
calm shadows, gentle motion.
|
||||||
|
============================================================ */
|
||||||
|
:root {
|
||||||
|
--background: #f4f5fb;
|
||||||
|
--foreground: #2a2745;
|
||||||
|
--card: #ffffff;
|
||||||
|
--card-foreground: #2a2745;
|
||||||
|
--popover: #ffffff;
|
||||||
|
--popover-foreground: #2a2745;
|
||||||
|
--primary: #6d63f0;
|
||||||
|
--primary-foreground: #ffffff;
|
||||||
|
--secondary: #5a6380;
|
||||||
|
--secondary-foreground: #ffffff;
|
||||||
|
--muted: #edeef7;
|
||||||
|
--muted-foreground: #6b6c8a;
|
||||||
|
--accent: #ec6fa9;
|
||||||
|
--accent-foreground: #ffffff;
|
||||||
|
--destructive: #e05c70;
|
||||||
|
--destructive-foreground: #ffffff;
|
||||||
|
--success: #3ec98a;
|
||||||
|
--success-foreground: #ffffff;
|
||||||
|
--gold: #f2a437;
|
||||||
|
--gold-foreground: #3f2a04;
|
||||||
|
--border: #d9dbe9;
|
||||||
|
--input: #c9cbdf;
|
||||||
|
--ring: #6d63f0;
|
||||||
|
--radius: 0.5rem;
|
||||||
|
/* inverted editorial band (dark in light mode, light in dark mode) */
|
||||||
|
--invert-bg: #211f3e;
|
||||||
|
--invert-fg: #f6f5fb;
|
||||||
|
/* soft motion tokens */
|
||||||
|
--ease-soft: cubic-bezier(0.22, 1, 0.36, 1);
|
||||||
|
--ease-soft-in-out: cubic-bezier(0.45, 0.05, 0.25, 1);
|
||||||
|
--dur-fast: 280ms;
|
||||||
|
--dur-med: 420ms;
|
||||||
|
--dur-slow: 700ms;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark {
|
||||||
|
--background: #12111d;
|
||||||
|
--foreground: #ecebf6;
|
||||||
|
--card: #191830;
|
||||||
|
--card-foreground: #ecebf6;
|
||||||
|
--popover: #201f3a;
|
||||||
|
--popover-foreground: #ecebf6;
|
||||||
|
--primary: #9189fb;
|
||||||
|
--primary-foreground: #161129;
|
||||||
|
--secondary: #8d95ab;
|
||||||
|
--secondary-foreground: #10131e;
|
||||||
|
--muted: #262442;
|
||||||
|
--muted-foreground: #a7a8c9;
|
||||||
|
--accent: #f095c4;
|
||||||
|
--accent-foreground: #2a0f1f;
|
||||||
|
--destructive: #f47b8c;
|
||||||
|
--destructive-foreground: #2a0a0f;
|
||||||
|
--success: #63e0a5;
|
||||||
|
--success-foreground: #06210f;
|
||||||
|
--gold: #fab653;
|
||||||
|
--gold-foreground: #2a1a02;
|
||||||
|
--border: #353360;
|
||||||
|
--input: #4d4a7e;
|
||||||
|
--ring: #9189fb;
|
||||||
|
--radius: 0.25rem;
|
||||||
|
--invert-bg: #f0eff8;
|
||||||
|
--invert-fg: #18162e;
|
||||||
|
}
|
||||||
|
|
||||||
|
@theme inline {
|
||||||
|
/* next/font: FD default + plain Latin face for English-only fields */
|
||||||
|
/* Prefer Apple Color Emoji first; chat also renders Apple PNGs for Linux hosts. */
|
||||||
|
--font-sans: var(--font-vazirmatn), "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji",
|
||||||
|
sans-serif;
|
||||||
|
--font-emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
|
||||||
|
--font-latin: var(--font-vazirmatn-latin), var(--font-vazirmatn), Tahoma, "Segoe UI", Arial,
|
||||||
|
sans-serif;
|
||||||
|
/* Technical / English strings keep Latin digits */
|
||||||
|
--font-mono: var(--font-vazirmatn-latin), ui-monospace, "Cascadia Code", "Source Code Pro", Menlo,
|
||||||
|
Consolas, monospace;
|
||||||
|
--color-background: var(--background);
|
||||||
|
--color-foreground: var(--foreground);
|
||||||
|
--color-card: var(--card);
|
||||||
|
--color-card-foreground: var(--card-foreground);
|
||||||
|
--color-popover: var(--popover);
|
||||||
|
--color-popover-foreground: var(--popover-foreground);
|
||||||
|
--color-primary: var(--primary);
|
||||||
|
--color-primary-foreground: var(--primary-foreground);
|
||||||
|
--color-secondary: var(--secondary);
|
||||||
|
--color-secondary-foreground: var(--secondary-foreground);
|
||||||
|
--color-muted: var(--muted);
|
||||||
|
--color-muted-foreground: var(--muted-foreground);
|
||||||
|
--color-accent: var(--accent);
|
||||||
|
--color-accent-foreground: var(--accent-foreground);
|
||||||
|
--color-destructive: var(--destructive);
|
||||||
|
--color-destructive-foreground: var(--destructive-foreground);
|
||||||
|
--color-success: var(--success);
|
||||||
|
--color-success-foreground: var(--success-foreground);
|
||||||
|
--color-gold: var(--gold);
|
||||||
|
--color-gold-foreground: var(--gold-foreground);
|
||||||
|
--color-border: var(--border);
|
||||||
|
--color-input: var(--input);
|
||||||
|
--color-ring: var(--ring);
|
||||||
|
--radius-sm: 6px;
|
||||||
|
--radius-md: 8px;
|
||||||
|
--radius-lg: 10px;
|
||||||
|
--radius-xl: 14px;
|
||||||
|
--radius-2xl: 20px;
|
||||||
|
--ease-soft: cubic-bezier(0.22, 1, 0.36, 1);
|
||||||
|
--default-transition-duration: 350ms;
|
||||||
|
--default-transition-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@layer base {
|
||||||
|
* {
|
||||||
|
border-color: var(--color-border);
|
||||||
|
}
|
||||||
|
html {
|
||||||
|
color-scheme: light;
|
||||||
|
scroll-behavior: smooth;
|
||||||
|
font-family: var(--font-sans);
|
||||||
|
}
|
||||||
|
html.dark {
|
||||||
|
color-scheme: dark;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
background-color: var(--background);
|
||||||
|
background-image:
|
||||||
|
radial-gradient(1100px 540px at 85% -8%, color-mix(in srgb, var(--color-accent) 11%, transparent), transparent 62%),
|
||||||
|
radial-gradient(1000px 520px at -8% 26%, color-mix(in srgb, var(--color-primary) 9%, transparent), transparent 60%),
|
||||||
|
radial-gradient(800px 420px at 50% 110%, color-mix(in srgb, var(--color-gold) 7%, transparent), transparent 60%);
|
||||||
|
background-attachment: fixed;
|
||||||
|
color: var(--foreground);
|
||||||
|
font-family: var(--font-sans);
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
text-rendering: optimizeLegibility;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Form controls: UA + Tailwind preflight use `font: inherit`, which is flaky.
|
||||||
|
* Pin family so Vazirmatn FD (Persian digits) paints the same as surrounding UI.
|
||||||
|
*/
|
||||||
|
input,
|
||||||
|
textarea,
|
||||||
|
select,
|
||||||
|
button {
|
||||||
|
font-family: var(--font-sans) !important;
|
||||||
|
font-feature-settings: normal !important;
|
||||||
|
}
|
||||||
|
input::placeholder,
|
||||||
|
textarea::placeholder,
|
||||||
|
input::-webkit-input-placeholder,
|
||||||
|
textarea::-webkit-input-placeholder {
|
||||||
|
font-family: var(--font-sans) !important;
|
||||||
|
font-feature-settings: normal !important;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* English-only typing surfaces: passwords, usernames, email, captcha, URLs, codes.
|
||||||
|
* Use plain Vazirmatn (non-FD) so Latin digits stay Latin.
|
||||||
|
*/
|
||||||
|
.font-latin,
|
||||||
|
input.font-latin,
|
||||||
|
textarea.font-latin,
|
||||||
|
input[type="password"],
|
||||||
|
input[type="email"],
|
||||||
|
input[type="url"],
|
||||||
|
input[type="tel"],
|
||||||
|
input[dir="ltr"],
|
||||||
|
textarea[dir="ltr"],
|
||||||
|
input[autocomplete="username"],
|
||||||
|
input[autocomplete="email"],
|
||||||
|
input[autocomplete="current-password"],
|
||||||
|
input[autocomplete="new-password"],
|
||||||
|
input[autocomplete="one-time-code"],
|
||||||
|
input[id*="captcha" i],
|
||||||
|
input[name*="captcha" i],
|
||||||
|
input[id*="password" i],
|
||||||
|
input[name*="password" i],
|
||||||
|
input[id*="username" i],
|
||||||
|
input[name*="username" i] {
|
||||||
|
font-family: var(--font-latin) !important;
|
||||||
|
font-feature-settings: normal !important;
|
||||||
|
font-variant-numeric: lining-nums !important;
|
||||||
|
}
|
||||||
|
.font-latin::placeholder,
|
||||||
|
input.font-latin::placeholder,
|
||||||
|
textarea.font-latin::placeholder,
|
||||||
|
input[type="password"]::placeholder,
|
||||||
|
input[type="email"]::placeholder,
|
||||||
|
input[type="url"]::placeholder,
|
||||||
|
input[type="tel"]::placeholder,
|
||||||
|
input[dir="ltr"]::placeholder,
|
||||||
|
textarea[dir="ltr"]::placeholder {
|
||||||
|
font-family: var(--font-latin) !important;
|
||||||
|
}
|
||||||
|
input:-webkit-autofill,
|
||||||
|
input:-webkit-autofill:hover,
|
||||||
|
input:-webkit-autofill:focus,
|
||||||
|
textarea:-webkit-autofill,
|
||||||
|
select:-webkit-autofill {
|
||||||
|
font-family: var(--font-sans) !important;
|
||||||
|
}
|
||||||
|
h1,
|
||||||
|
h2,
|
||||||
|
h3,
|
||||||
|
h4,
|
||||||
|
h5,
|
||||||
|
h6 {
|
||||||
|
font-weight: 800;
|
||||||
|
letter-spacing: -0.01em;
|
||||||
|
text-wrap: balance;
|
||||||
|
}
|
||||||
|
::selection {
|
||||||
|
background: color-mix(in srgb, var(--color-primary) 22%, transparent);
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
:focus-visible {
|
||||||
|
outline: 2px solid var(--color-ring);
|
||||||
|
outline-offset: 2px;
|
||||||
|
}
|
||||||
|
code {
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 0.875em;
|
||||||
|
}
|
||||||
|
::-webkit-scrollbar {
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
}
|
||||||
|
::-webkit-scrollbar-thumb {
|
||||||
|
background: color-mix(in srgb, var(--color-muted-foreground) 30%, transparent);
|
||||||
|
border-radius: 999px;
|
||||||
|
border: 2px solid var(--color-background);
|
||||||
|
}
|
||||||
|
::-webkit-scrollbar-track {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@layer components {
|
||||||
|
.chat-scroll {
|
||||||
|
scrollbar-width: thin;
|
||||||
|
scrollbar-color: color-mix(in srgb, var(--color-muted-foreground) 35%, transparent) transparent;
|
||||||
|
}
|
||||||
|
.chat-scroll::-webkit-scrollbar {
|
||||||
|
width: 6px;
|
||||||
|
}
|
||||||
|
.chat-scroll::-webkit-scrollbar-thumb {
|
||||||
|
background: color-mix(in srgb, var(--color-muted-foreground) 35%, transparent);
|
||||||
|
border-radius: 999px;
|
||||||
|
border-width: 0;
|
||||||
|
}
|
||||||
|
.section-kicker {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
font-size: 0.6875rem;
|
||||||
|
font-weight: 800;
|
||||||
|
letter-spacing: 0.1em;
|
||||||
|
color: var(--color-primary);
|
||||||
|
}
|
||||||
|
.section-kicker::before {
|
||||||
|
content: "";
|
||||||
|
display: inline-block;
|
||||||
|
width: 1.75rem;
|
||||||
|
height: 3px;
|
||||||
|
border-radius: 2px;
|
||||||
|
background: var(--color-primary);
|
||||||
|
}
|
||||||
|
/* kicker sitting on a solid primary panel — bar & text follow the opposing tone */
|
||||||
|
.section-kicker.on-primary {
|
||||||
|
color: var(--color-primary-foreground);
|
||||||
|
}
|
||||||
|
.section-kicker.on-primary::before {
|
||||||
|
background: var(--color-primary-foreground);
|
||||||
|
}
|
||||||
|
.card-hover {
|
||||||
|
transition:
|
||||||
|
border-color 150ms ease,
|
||||||
|
box-shadow 250ms ease,
|
||||||
|
transform 250ms cubic-bezier(0.16, 1, 0.3, 1);
|
||||||
|
}
|
||||||
|
.card-hover:hover {
|
||||||
|
border-color: color-mix(in srgb, var(--color-primary) 45%, transparent);
|
||||||
|
box-shadow:
|
||||||
|
0 2px 6px rgba(41, 39, 70, 0.05),
|
||||||
|
0 22px 44px -18px rgba(75, 66, 200, 0.22);
|
||||||
|
transform: translateY(-3px);
|
||||||
|
}
|
||||||
|
.dark .card-hover:hover {
|
||||||
|
border-color: color-mix(in srgb, var(--color-primary) 60%, transparent);
|
||||||
|
box-shadow:
|
||||||
|
0 2px 10px rgba(0, 0, 0, 0.4),
|
||||||
|
0 22px 44px -18px color-mix(in srgb, var(--color-primary) 40%, transparent);
|
||||||
|
}
|
||||||
|
.shadow-soft {
|
||||||
|
box-shadow:
|
||||||
|
0 2px 6px rgba(41, 39, 70, 0.05),
|
||||||
|
0 20px 44px -22px rgba(41, 39, 70, 0.2);
|
||||||
|
}
|
||||||
|
.dark .shadow-soft {
|
||||||
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4), 0 22px 48px -22px rgba(0, 0, 0, 0.55);
|
||||||
|
}
|
||||||
|
/* signature offset shadow — softened for the pastel identity */
|
||||||
|
.shadow-offset {
|
||||||
|
box-shadow: 5px 5px 0 0 var(--invert-fg);
|
||||||
|
}
|
||||||
|
.shadow-offset-sm {
|
||||||
|
box-shadow: 4px 4px 0 0 var(--invert-fg);
|
||||||
|
}
|
||||||
|
/* in dark mode the offset shadow must stay visible against the dark canvas */
|
||||||
|
.dark .shadow-offset {
|
||||||
|
box-shadow: 5px 5px 0 0 rgba(255, 255, 255, 0.16);
|
||||||
|
}
|
||||||
|
.dark .shadow-offset-sm {
|
||||||
|
box-shadow: 4px 4px 0 0 rgba(255, 255, 255, 0.14);
|
||||||
|
}
|
||||||
|
/* inverted editorial band */
|
||||||
|
.band-invert {
|
||||||
|
background:
|
||||||
|
radial-gradient(900px 400px at 90% -20%, color-mix(in srgb, var(--color-accent) 26%, transparent), transparent 60%),
|
||||||
|
var(--invert-bg);
|
||||||
|
color: var(--invert-fg);
|
||||||
|
}
|
||||||
|
.chip-outline {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.4rem;
|
||||||
|
border: 2px solid currentColor;
|
||||||
|
border-radius: 999px;
|
||||||
|
padding: 0.35rem 0.8rem;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
font-weight: 800;
|
||||||
|
letter-spacing: 0.04em;
|
||||||
|
}
|
||||||
|
.dot-grid {
|
||||||
|
background-image: radial-gradient(
|
||||||
|
color-mix(in srgb, currentColor 16%, transparent) 1px,
|
||||||
|
transparent 1px
|
||||||
|
);
|
||||||
|
background-size: 18px 18px;
|
||||||
|
}
|
||||||
|
.dot-grid-primary {
|
||||||
|
color: var(--color-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* frosted glass — a touch: soft, restrained */
|
||||||
|
.glass {
|
||||||
|
background: linear-gradient(150deg, rgba(255, 255, 255, 0.52), rgba(255, 255, 255, 0.28));
|
||||||
|
-webkit-backdrop-filter: blur(14px) saturate(1.3);
|
||||||
|
backdrop-filter: blur(14px) saturate(1.3);
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.5);
|
||||||
|
box-shadow:
|
||||||
|
inset 0 1px 0 rgba(255, 255, 255, 0.6),
|
||||||
|
0 16px 36px -22px rgba(41, 39, 70, 0.3);
|
||||||
|
}
|
||||||
|
.dark .glass {
|
||||||
|
background: linear-gradient(150deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.03));
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||||
|
box-shadow:
|
||||||
|
inset 0 1px 0 rgba(255, 255, 255, 0.09),
|
||||||
|
0 16px 36px -22px rgba(0, 0, 0, 0.6);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* frosted glow variants per status (colored ambience) */
|
||||||
|
.glass-glow-primary,
|
||||||
|
.glass-glow-accent,
|
||||||
|
.glass-glow-gold,
|
||||||
|
.glass-glow-success,
|
||||||
|
.glass-glow-neutral {
|
||||||
|
box-shadow:
|
||||||
|
inset 0 1px 0 rgba(255, 255, 255, 0.55),
|
||||||
|
0 14px 34px -12px rgba(41, 39, 70, 0.3);
|
||||||
|
}
|
||||||
|
.glass-glow-primary {
|
||||||
|
box-shadow:
|
||||||
|
inset 0 1px 0 rgba(255, 255, 255, 0.55),
|
||||||
|
0 14px 34px -12px color-mix(in srgb, var(--color-primary) 42%, transparent);
|
||||||
|
}
|
||||||
|
.glass-glow-accent {
|
||||||
|
box-shadow:
|
||||||
|
inset 0 1px 0 rgba(255, 255, 255, 0.55),
|
||||||
|
0 14px 34px -12px color-mix(in srgb, var(--color-accent) 40%, transparent);
|
||||||
|
}
|
||||||
|
.glass-glow-gold {
|
||||||
|
box-shadow:
|
||||||
|
inset 0 1px 0 rgba(255, 255, 255, 0.55),
|
||||||
|
0 14px 34px -12px color-mix(in srgb, var(--color-gold) 40%, transparent);
|
||||||
|
}
|
||||||
|
.glass-glow-success {
|
||||||
|
box-shadow:
|
||||||
|
inset 0 1px 0 rgba(255, 255, 255, 0.55),
|
||||||
|
0 14px 34px -12px color-mix(in srgb, var(--color-success) 40%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* glass navigation bar */
|
||||||
|
.nav-glass {
|
||||||
|
background: color-mix(in srgb, var(--color-background) 82%, transparent);
|
||||||
|
-webkit-backdrop-filter: blur(16px) saturate(1.5);
|
||||||
|
backdrop-filter: blur(16px) saturate(1.5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@layer utilities {
|
||||||
|
/* legacy aliases now render soft + calm */
|
||||||
|
.bg-gradient-brand {
|
||||||
|
background-color: var(--color-primary);
|
||||||
|
background-image: none;
|
||||||
|
}
|
||||||
|
.text-gradient-brand {
|
||||||
|
color: var(--color-primary);
|
||||||
|
-webkit-background-clip: initial;
|
||||||
|
background-clip: initial;
|
||||||
|
}
|
||||||
|
.shadow-glow,
|
||||||
|
.shadow-glow-cyan {
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------- motion system (soft by default) ---------- */
|
||||||
|
.reveal {
|
||||||
|
opacity: 0;
|
||||||
|
animation: fadeUp 0.85s var(--ease-soft) forwards;
|
||||||
|
}
|
||||||
|
.reveal-1 { animation-delay: 0.08s; }
|
||||||
|
.reveal-2 { animation-delay: 0.16s; }
|
||||||
|
.reveal-3 { animation-delay: 0.24s; }
|
||||||
|
.reveal-4 { animation-delay: 0.32s; }
|
||||||
|
.reveal-5 { animation-delay: 0.4s; }
|
||||||
|
.reveal-scale {
|
||||||
|
opacity: 0;
|
||||||
|
animation: scaleIn 0.7s var(--ease-soft) forwards;
|
||||||
|
}
|
||||||
|
.hover-lift {
|
||||||
|
transition:
|
||||||
|
transform var(--dur-med) var(--ease-soft),
|
||||||
|
box-shadow var(--dur-med) var(--ease-soft);
|
||||||
|
}
|
||||||
|
.hover-lift:hover {
|
||||||
|
transform: translateY(-3px);
|
||||||
|
box-shadow:
|
||||||
|
0 2px 6px rgba(41, 39, 70, 0.05),
|
||||||
|
0 20px 40px -18px color-mix(in srgb, var(--color-primary) 26%, transparent);
|
||||||
|
}
|
||||||
|
.dark .hover-lift:hover {
|
||||||
|
box-shadow:
|
||||||
|
0 2px 10px rgba(0, 0, 0, 0.35),
|
||||||
|
0 20px 40px -18px color-mix(in srgb, var(--color-primary) 32%, transparent);
|
||||||
|
}
|
||||||
|
.press {
|
||||||
|
transition: transform var(--dur-fast) var(--ease-soft);
|
||||||
|
}
|
||||||
|
.press:active {
|
||||||
|
transform: translateY(1px) scale(0.985);
|
||||||
|
}
|
||||||
|
.press-flat:active {
|
||||||
|
transform: translateY(0.5px) scale(0.99);
|
||||||
|
}
|
||||||
|
.float-slow {
|
||||||
|
animation: floatY 9s var(--ease-soft-in-out) infinite;
|
||||||
|
}
|
||||||
|
.animate-pulse-soft {
|
||||||
|
animation: pulseSoft 3s var(--ease-soft-in-out) infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Soften common Tailwind transition utilities */
|
||||||
|
.transition,
|
||||||
|
.transition-all,
|
||||||
|
.transition-colors,
|
||||||
|
.transition-opacity,
|
||||||
|
.transition-shadow,
|
||||||
|
.transition-transform {
|
||||||
|
transition-timing-function: var(--ease-soft);
|
||||||
|
}
|
||||||
|
.duration-75 { transition-duration: 180ms; }
|
||||||
|
.duration-100 { transition-duration: 220ms; }
|
||||||
|
.duration-150 { transition-duration: 280ms; }
|
||||||
|
.duration-200 { transition-duration: 350ms; }
|
||||||
|
.duration-300 { transition-duration: 420ms; }
|
||||||
|
.ease-out { transition-timing-function: var(--ease-soft); }
|
||||||
|
.ease-in-out { transition-timing-function: var(--ease-soft-in-out); }
|
||||||
|
|
||||||
|
/* Soften snappy active scales */
|
||||||
|
.active\:scale-90:active {
|
||||||
|
transform: scale(0.96);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
.reveal,
|
||||||
|
.reveal-scale {
|
||||||
|
opacity: 1;
|
||||||
|
animation: none;
|
||||||
|
}
|
||||||
|
.float-slow,
|
||||||
|
.hover-lift,
|
||||||
|
.press,
|
||||||
|
.animate-pulse-soft,
|
||||||
|
.chat-msg-glow {
|
||||||
|
transition: none;
|
||||||
|
animation: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* keyframes live at root so they always exist regardless of layers */
|
||||||
|
@keyframes fadeUp {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateY(12px);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
transform: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@keyframes scaleIn {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
transform: scale(0.985);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
transform: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@keyframes floatY {
|
||||||
|
0%,
|
||||||
|
100% {
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
transform: translateY(-6px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@keyframes pulseSoft {
|
||||||
|
0%,
|
||||||
|
100% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes chatMsgGlow {
|
||||||
|
0% {
|
||||||
|
filter: drop-shadow(0 0 0 transparent);
|
||||||
|
}
|
||||||
|
35% {
|
||||||
|
filter: drop-shadow(0 0 12px color-mix(in srgb, var(--color-gold) 55%, transparent))
|
||||||
|
drop-shadow(0 0 28px color-mix(in srgb, var(--color-gold) 28%, transparent));
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
filter: drop-shadow(0 0 0 transparent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-msg-glow {
|
||||||
|
animation: chatMsgGlow 1.85s var(--ease-soft) forwards;
|
||||||
|
will-change: filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes metaprog {
|
||||||
|
0% {
|
||||||
|
transform: translateX(-120%);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: translateX(420%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Soften Tailwind ping / pulse defaults for this app */
|
||||||
|
@keyframes softPing {
|
||||||
|
0% {
|
||||||
|
transform: scale(1);
|
||||||
|
opacity: 0.55;
|
||||||
|
}
|
||||||
|
75%,
|
||||||
|
100% {
|
||||||
|
transform: scale(1.45);
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.animate-ping {
|
||||||
|
animation: softPing 1.6s var(--ease-soft-in-out) infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes softPulse {
|
||||||
|
0%,
|
||||||
|
100% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
opacity: 0.72;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.animate-pulse {
|
||||||
|
animation: softPulse 2.8s var(--ease-soft-in-out) infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---- skeleton shimmer ------------------------------------------------ */
|
||||||
|
.skeleton {
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
background-color: var(--color-muted);
|
||||||
|
border-radius: 0.75rem;
|
||||||
|
}
|
||||||
|
.skeleton::after {
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
transform: translateX(-100%);
|
||||||
|
background: linear-gradient(
|
||||||
|
90deg,
|
||||||
|
transparent,
|
||||||
|
color-mix(in srgb, var(--color-foreground) 8%, transparent),
|
||||||
|
transparent
|
||||||
|
);
|
||||||
|
animation: skeletonShimmer 2s var(--ease-soft-in-out) infinite;
|
||||||
|
}
|
||||||
|
@keyframes skeletonShimmer {
|
||||||
|
100% {
|
||||||
|
transform: translateX(100%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---- global motion safety --------------------------------------------- */
|
||||||
|
@media (prefers-reduced-motion: no-preference) {
|
||||||
|
html {
|
||||||
|
scroll-behavior: smooth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
*,
|
||||||
|
*::before,
|
||||||
|
*::after {
|
||||||
|
animation-duration: 0.01ms !important;
|
||||||
|
animation-iteration-count: 1 !important;
|
||||||
|
transition-duration: 0.01ms !important;
|
||||||
|
scroll-behavior: auto !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 49 KiB |
@@ -0,0 +1,59 @@
|
|||||||
|
import type { Metadata } from "next";
|
||||||
|
import localFont from "next/font/local";
|
||||||
|
import "./globals.css";
|
||||||
|
import { Providers } from "@/components/providers";
|
||||||
|
import { AppShell } from "@/components/app-shell";
|
||||||
|
import { PageTransition } from "@/components/page-transition";
|
||||||
|
|
||||||
|
/** Vazirmatn FD — default UI; Latin digits render as Persian glyphs. */
|
||||||
|
const vazirmatnFd = localFont({
|
||||||
|
src: [
|
||||||
|
{ path: "./fonts/Vazirmatn-FD-Thin.woff2", weight: "100", style: "normal" },
|
||||||
|
{ path: "./fonts/Vazirmatn-FD-ExtraLight.woff2", weight: "200", style: "normal" },
|
||||||
|
{ path: "./fonts/Vazirmatn-FD-Light.woff2", weight: "300", style: "normal" },
|
||||||
|
{ path: "./fonts/Vazirmatn-FD-Regular.woff2", weight: "400", style: "normal" },
|
||||||
|
{ path: "./fonts/Vazirmatn-FD-Medium.woff2", weight: "500", style: "normal" },
|
||||||
|
{ path: "./fonts/Vazirmatn-FD-SemiBold.woff2", weight: "600", style: "normal" },
|
||||||
|
{ path: "./fonts/Vazirmatn-FD-Bold.woff2", weight: "700", style: "normal" },
|
||||||
|
{ path: "./fonts/Vazirmatn-FD-ExtraBold.woff2", weight: "800", style: "normal" },
|
||||||
|
{ path: "./fonts/Vazirmatn-FD-Black.woff2", weight: "900", style: "normal" },
|
||||||
|
],
|
||||||
|
display: "swap",
|
||||||
|
variable: "--font-vazirmatn",
|
||||||
|
fallback: ["Tahoma", "Segoe UI", "Arial", "sans-serif"],
|
||||||
|
});
|
||||||
|
|
||||||
|
/** Plain Vazirmatn — Latin digits stay Latin (passwords, usernames, captcha, URLs…). */
|
||||||
|
const vazirmatnLatin = localFont({
|
||||||
|
src: "./fonts/Vazirmatn-Variable.woff2",
|
||||||
|
weight: "100 900",
|
||||||
|
display: "swap",
|
||||||
|
variable: "--font-vazirmatn-latin",
|
||||||
|
fallback: ["Tahoma", "Segoe UI", "Arial", "sans-serif"],
|
||||||
|
});
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: "پرگار",
|
||||||
|
description: "مسیر یادگیری واقعی پرگار",
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
||||||
|
return (
|
||||||
|
<html
|
||||||
|
lang="fa"
|
||||||
|
dir="rtl"
|
||||||
|
className={`${vazirmatnFd.variable} ${vazirmatnLatin.variable}`}
|
||||||
|
suppressHydrationWarning
|
||||||
|
>
|
||||||
|
<body
|
||||||
|
className={`${vazirmatnFd.className} min-h-screen bg-background font-sans text-foreground antialiased`}
|
||||||
|
>
|
||||||
|
<Providers>
|
||||||
|
<AppShell>
|
||||||
|
<PageTransition>{children}</PageTransition>
|
||||||
|
</AppShell>
|
||||||
|
</Providers>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { Suspense } from "react";
|
||||||
|
import { Trophy } from "lucide-react";
|
||||||
|
import { LeaderboardPanel } from "@/components/leaderboard-panel";
|
||||||
|
import { PageHeader } from "@/components/page-header";
|
||||||
|
|
||||||
|
export default function LeaderboardPage() {
|
||||||
|
return (
|
||||||
|
<div className="space-y-8">
|
||||||
|
<PageHeader
|
||||||
|
align="center"
|
||||||
|
kicker="رقابت هفتگی"
|
||||||
|
title={
|
||||||
|
<>
|
||||||
|
لیگ <span className="text-gradient-brand">هفتگی</span>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
description="با تکمیل صادقانه دروس امتیاز بگیرید. لیگ هر دوشنبه صفر میشود — استمرار از شدت مهمتر است."
|
||||||
|
actions={
|
||||||
|
<span className="flex h-12 w-12 items-center justify-center rounded-xl bg-primary/10 text-primary">
|
||||||
|
<Trophy className="h-6 w-6" />
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Suspense fallback={null}>
|
||||||
|
<LeaderboardPanel />
|
||||||
|
</Suspense>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user