mirror of
https://github.com/fccview/cronmaster.git
synced 2026-01-05 20:39:10 -05:00
Compare commits
45 Commits
feature/re
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b89a9ef97 | ||
|
|
0ed4942a30 | ||
|
|
aeab383116 | ||
|
|
f098ded0c4 | ||
|
|
3ac9a5ca30 | ||
|
|
c708c013f3 | ||
|
|
fb6531d00d | ||
|
|
46e0838792 | ||
|
|
72f1c0a66d | ||
|
|
1adad49020 | ||
|
|
c2d17e4c04 | ||
|
|
02866c8ea5 | ||
|
|
e58c1070d6 | ||
|
|
6fe92ef3fa | ||
|
|
ebce8f698b | ||
|
|
b2dc0a3cb3 | ||
|
|
e40b0c0f63 | ||
|
|
79fd223416 | ||
|
|
eaca3fe44a | ||
|
|
e033caacf6 | ||
|
|
4beb7053f7 | ||
|
|
d26ce0e810 | ||
|
|
d6b6aff44e | ||
|
|
7954111d05 | ||
|
|
0ab3358e28 | ||
|
|
f53905c002 | ||
|
|
90775cac7c | ||
|
|
54188eb1c0 | ||
|
|
bf208e3075 | ||
|
|
a5fb5ff484 | ||
|
|
25190f3154 | ||
|
|
437bdbd81f | ||
|
|
d8ab3839c6 | ||
|
|
13fe6c5f3d | ||
|
|
9fb904d68a | ||
|
|
b95cd79239 | ||
|
|
7a4a22f8e9 | ||
|
|
df6ab8774d | ||
|
|
feeb56ece8 | ||
|
|
1b6f5b6e34 | ||
|
|
1f2379db59 | ||
|
|
ef5153ce54 | ||
|
|
8faf4d26d0 | ||
|
|
1fd2689296 | ||
|
|
01c87ab82f |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -14,4 +14,5 @@ node_modules
|
||||
.idea
|
||||
tsconfig.tsbuildinfo
|
||||
docker-compose.test.yml
|
||||
/data
|
||||
/data
|
||||
claude.md
|
||||
37
CONTRIBUTING.md
Normal file
37
CONTRIBUTING.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# How to contribute
|
||||
|
||||
Hi, it's amazing having a community willing to push new feature to the app, and I am VERY open to contributors pushing their idea, it's what makes open source amazing.
|
||||
|
||||
That said for the sake of sanity let's all follow the same structure:
|
||||
|
||||
- When creating a new branch, do off from the develop branch, this will always be ahead of main and it's what gets released
|
||||
- When creating a pull request, direct it back into develop, I'll then review it and merge it. Your code will end up in the next release that way and we all avoid conflicts!
|
||||
- Please bear with on reviews, it may take a bit of time for me to go through it all on top of life/work/hobbies :)
|
||||
|
||||
## Some best practices
|
||||
|
||||
### Code Quality
|
||||
|
||||
- Follow the existing code style and structure
|
||||
- Keep files modular and under 250-300 (split into smaller components if needed) lines unless it's a major server action, these can get intense I know
|
||||
- Avoid code duplication - reuse existing functions and UI components, don't hardcode html when a component already exists (e.g. <button> vs <Button>)
|
||||
- All imports should be at the top of the file unless it's for specific server actions
|
||||
- Avoid using `any`
|
||||
- Don't hardcode colors! Use the theme variables to make sure light/dark mode keep working well
|
||||
- Make sure the UI is consistent with the current one, look for spacing issues, consistent spacing really makes a difference
|
||||
|
||||
### Pull Requests
|
||||
|
||||
- Keep PRs focused on a single feature or fix
|
||||
- Update documentation if your changes affect user-facing features
|
||||
- Test your changes locally before submitting
|
||||
|
||||
### Getting Started
|
||||
|
||||
1. Fork the repository
|
||||
2. Create a feature branch from `develop`
|
||||
3. Make your changes
|
||||
4. Test thoroughly
|
||||
5. Submit a pull request to `develop`
|
||||
|
||||
Thank you for contributing! <3
|
||||
44
Dockerfile
44
Dockerfile
@@ -1,22 +1,7 @@
|
||||
FROM node:20-slim AS base
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
pciutils \
|
||||
curl \
|
||||
iputils-ping \
|
||||
util-linux \
|
||||
ca-certificates \
|
||||
gnupg \
|
||||
lsb-release \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg \
|
||||
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null \
|
||||
&& apt-get update \
|
||||
&& apt-get install -y docker-ce-cli \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
FROM node:20-alpine AS base
|
||||
|
||||
FROM base AS deps
|
||||
RUN apk add --no-cache libc6-compat
|
||||
WORKDIR /app
|
||||
|
||||
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
|
||||
@@ -42,26 +27,27 @@ WORKDIR /app
|
||||
ENV NODE_ENV=production
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
|
||||
RUN groupadd --system --gid 1001 nodejs
|
||||
RUN useradd --system --uid 1001 nextjs
|
||||
RUN apk add --no-cache su-exec docker-cli pciutils curl iputils util-linux ca-certificates
|
||||
|
||||
RUN addgroup --system --gid 1001 nodejs
|
||||
RUN adduser --system --uid 1001 nextjs
|
||||
|
||||
RUN mkdir -p /app/scripts /app/data /app/snippets && \
|
||||
chown -R nextjs:nodejs /app/scripts /app/data /app/snippets
|
||||
|
||||
RUN mkdir -p /app/.next/cache && \
|
||||
chown -R nextjs:nodejs /app/.next
|
||||
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||
|
||||
COPY --from=builder /app/public ./public
|
||||
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
|
||||
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/app ./app
|
||||
|
||||
COPY --from=builder /app/package.json ./package.json
|
||||
COPY --from=builder /app/yarn.lock ./yarn.lock
|
||||
|
||||
COPY --from=deps --chown=nextjs:nodejs /app/node_modules ./node_modules
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
ENV PORT=3000
|
||||
ENV HOSTNAME="0.0.0.0"
|
||||
|
||||
CMD ["yarn", "start"]
|
||||
USER nextjs
|
||||
|
||||
CMD ["node", "server.js"]
|
||||
|
||||
661
LICENSE
Normal file
661
LICENSE
Normal file
@@ -0,0 +1,661 @@
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
280
README.md
280
README.md
@@ -1,33 +1,38 @@
|
||||
<p align="center">
|
||||
<img src="public/heading.png" width="400px">
|
||||
<img src="public/heading.png">
|
||||
</p>
|
||||
|
||||
## Table of Contents
|
||||
## Quick links
|
||||
|
||||
- [Features](#features)
|
||||
- [Quick Start](#quick-start)
|
||||
- [Using Docker (Recommended)](#using-docker-recommended)
|
||||
- [API](#api)
|
||||
- [Single Sign-On (SSO) with OIDC](#single-sign-on-sso-with-oidc)
|
||||
- [Localization](#localization)
|
||||
- [Local Development](#local-development)
|
||||
- [Environment Variables](howto/ENV_VARIABLES.md)
|
||||
- [Authentication](#authentication)
|
||||
- [REST API](#rest-api)
|
||||
- [Usage](#usage)
|
||||
- [Viewing System Information](#viewing-system-information)
|
||||
- [Managing Cron Jobs](#managing-cron-jobs)
|
||||
- [Job Execution Logging](#job-execution-logging)
|
||||
- [Managing Scripts](#managing-scripts)
|
||||
- [Technologies Used](#technologies-used)
|
||||
- [Contributing](#contributing)
|
||||
- [License](#license)
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
|
||||
| Desktop | Mobile |
|
||||
|---------|--------|
|
||||
|  |  |
|
||||
|  |  |
|
||||
|
||||
</div>
|
||||
|
||||
## Features
|
||||
|
||||
- **Modern UI**: Beautiful, responsive interface with dark/light mode.
|
||||
- **System Information**: Display hostname, IP address, uptime, memory, network and CPU info.
|
||||
- **System Information**: Display uptime, memory, network, CPU, and GPU info.
|
||||
- **Cron Job Management**: View, create, and delete cron jobs with comments.
|
||||
- **Script management**: View, create, and delete bash scripts on the go to use within your cron jobs.
|
||||
- **Job Execution Logging**: Optional logging for cronjobs with automatic cleanup, capturing stdout, stderr, exit codes, and timestamps.
|
||||
@@ -51,26 +56,13 @@
|
||||
<br />
|
||||
</p>
|
||||
|
||||
---
|
||||
|
||||
<br />
|
||||
|
||||
## Before we start
|
||||
|
||||
Hey there! 👋 Just a friendly heads-up: I'm a big believer in open source and love sharing my work with the community. Everything you find in my GitHub repos is and always will be 100% free. If someone tries to sell you a "premium" version of any of my projects while claiming to be me, please know that this is not legitimate. 🚫
|
||||
|
||||
If you find my projects helpful and want to fuel my late-night coding sessions with caffeine, I'd be super grateful for any support! ☕
|
||||
|
||||
<p align="center">
|
||||
<a href="https://www.buymeacoffee.com/fccview">
|
||||
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy me a coffee" width="150">
|
||||
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy me a coffee" width="120">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<div align="center">
|
||||
<img width="500px" src="screenshots/jobs-view.png">
|
||||
<img width="500px" src="screenshots/scripts-view.png" />
|
||||
</div>
|
||||
---
|
||||
|
||||
<a id="quick-start"></a>
|
||||
|
||||
@@ -93,7 +85,6 @@ services:
|
||||
- "40123:3000"
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- DOCKER=true
|
||||
- NEXT_PUBLIC_CLOCK_UPDATE_INTERVAL=30000
|
||||
- AUTH_PASSWORD=very_strong_password
|
||||
- HOST_CRONTAB_USER=root
|
||||
@@ -108,13 +99,13 @@ services:
|
||||
init: true
|
||||
```
|
||||
|
||||
**📖 For all available configuration options, see [`howto/DOCKER.md`](howto/DOCKER.md)**
|
||||
📖 **For all available configuration options, see [`howto/DOCKER.md`](howto/DOCKER.md)**
|
||||
|
||||
<a id="api"></a>
|
||||
|
||||
## API
|
||||
|
||||
`cr*nmaster` includes a REST API for programmatic access to your checklists and notes. This is perfect for integrations.
|
||||
`cr*nmaster` includes a REST API for programmatic access to your cron jobs and system information. This is perfect for integrations.
|
||||
|
||||
📖 **For the complete API documentation, see [howto/API.md](howto/API.md)**
|
||||
|
||||
@@ -126,6 +117,14 @@ services:
|
||||
|
||||
📖 **For the complete SSO documentation, see [howto/SSO.md](howto/SSO.md)**
|
||||
|
||||
<a id="localization"></a>
|
||||
|
||||
## Localization
|
||||
|
||||
`cr*nmaster` officially support [some languages](app/_translations) and allows you to create your custom translations locally on your own machine.
|
||||
|
||||
📖 **For the complete Translations documentation, see [howto/TRANSLATIONS.md](howto/TRANSLATIONS.md)**
|
||||
|
||||
### ARM64 Support
|
||||
|
||||
The application supports both AMD64 and ARM64 architectures:
|
||||
@@ -220,82 +219,11 @@ Cr\*nMaster supports SSO via OIDC (OpenID Connect), compatible with providers li
|
||||
- Entra ID (Azure AD)
|
||||
- And many more!
|
||||
|
||||
For detailed setup instructions, see **[README_SSO.md](README_SSO.md)**
|
||||
|
||||
Quick example:
|
||||
|
||||
```yaml
|
||||
environment:
|
||||
- SSO_MODE=oidc
|
||||
- OIDC_ISSUER=https://your-sso-provider.com
|
||||
- OIDC_CLIENT_ID=your_client_id
|
||||
- APP_URL=https://your-cronmaster-domain.com
|
||||
```
|
||||
|
||||
### Combined Authentication
|
||||
|
||||
You can enable **both** password and SSO authentication simultaneously:
|
||||
|
||||
```yaml
|
||||
environment:
|
||||
- AUTH_PASSWORD=your_password
|
||||
- SSO_MODE=oidc
|
||||
- OIDC_ISSUER=https://your-sso-provider.com
|
||||
- OIDC_CLIENT_ID=your_client_id
|
||||
```
|
||||
|
||||
The login page will display both options, allowing users to choose their preferred method.
|
||||
|
||||
### Security Features
|
||||
|
||||
- ✅ **Secure session management** with cryptographically random session IDs
|
||||
- ✅ **30-day session expiration** with automatic cleanup
|
||||
- ✅ **HTTP-only cookies** to prevent XSS attacks
|
||||
- ✅ **Proper JWT verification** for OIDC tokens using provider's public keys (JWKS)
|
||||
- ✅ **PKCE support** for OIDC authentication (or confidential client mode)
|
||||
|
||||
<a id="rest-api"></a>
|
||||
|
||||
## REST API
|
||||
|
||||
Cr\*nMaster provides a full REST API for programmatic access. Perfect for:
|
||||
|
||||
- External monitoring tools
|
||||
- Automation scripts
|
||||
- CI/CD integrations
|
||||
- Custom dashboards
|
||||
|
||||
### API Authentication
|
||||
|
||||
Protect your API with an optional API key:
|
||||
|
||||
```yaml
|
||||
environment:
|
||||
- API_KEY=your-secret-api-key-here
|
||||
```
|
||||
|
||||
Use the API key in your requests:
|
||||
|
||||
```bash
|
||||
curl -H "Authorization: Bearer YOUR_API_KEY" \
|
||||
https://your-domain.com/api/cronjobs
|
||||
```
|
||||
|
||||
For complete API documentation with examples, see **[README_API.md](README_API.md)**
|
||||
|
||||
### Available Endpoints
|
||||
|
||||
- `GET /api/cronjobs` - List all cron jobs
|
||||
- `POST /api/cronjobs` - Create a new cron job
|
||||
- `GET /api/cronjobs/:id` - Get a specific cron job
|
||||
- `PATCH /api/cronjobs/:id` - Update a cron job
|
||||
- `DELETE /api/cronjobs/:id` - Delete a cron job
|
||||
- `POST /api/cronjobs/:id/execute` - Manually execute a job
|
||||
- `GET /api/scripts` - List all scripts
|
||||
- `POST /api/scripts` - Create a new script
|
||||
- `GET /api/system-stats` - Get system statistics
|
||||
- `GET /api/logs/stream?runId=xxx` - Stream job logs
|
||||
- `GET /api/events` - SSE stream for real-time updates
|
||||
**For detailed setup instructions, see **[howto/SSO.md](howto/SSO.md)**
|
||||
|
||||
<a id="usage"></a>
|
||||
|
||||
@@ -328,125 +256,7 @@ The application automatically detects your operating system and displays:
|
||||
|
||||
### Job Execution Logging
|
||||
|
||||
CronMaster includes an optional logging feature that captures detailed execution information for your cronjobs:
|
||||
|
||||
#### How It Works
|
||||
|
||||
When you enable logging for a cronjob, CronMaster automatically wraps your command with a log wrapper script. This wrapper:
|
||||
|
||||
- Captures **stdout** and **stderr** output
|
||||
- Records the **exit code** of your command
|
||||
- Timestamps the **start and end** of execution
|
||||
- Calculates **execution duration**
|
||||
- Stores all this information in organized log files
|
||||
|
||||
#### Enabling Logs
|
||||
|
||||
1. When creating or editing a cronjob, check the "Enable Logging" checkbox
|
||||
2. The wrapper is automatically added to your crontab entry
|
||||
3. Jobs run independently - they continue to work even if CronMaster is offline
|
||||
|
||||
#### Log Storage
|
||||
|
||||
Logs are stored in the `./data/logs/` directory with descriptive folder names:
|
||||
|
||||
- If a job has a **description/comment**: `{sanitized-description}_{jobId}/`
|
||||
- If a job has **no description**: `{jobId}/`
|
||||
|
||||
Example structure:
|
||||
|
||||
```
|
||||
./data/logs/
|
||||
├── backup-database_root-0/
|
||||
│ ├── 2025-11-10_14-30-00.log
|
||||
│ ├── 2025-11-10_15-30-00.log
|
||||
│ └── 2025-11-10_16-30-00.log
|
||||
├── daily-cleanup_root-1/
|
||||
│ └── 2025-11-10_14-35-00.log
|
||||
├── root-2/ (no description provided)
|
||||
│ └── 2025-11-10_14-40-00.log
|
||||
```
|
||||
|
||||
**Note**: Folder names are sanitized to be filesystem-safe (lowercase, alphanumeric with hyphens, max 50 chars for the description part).
|
||||
|
||||
#### Log Format
|
||||
|
||||
Each log file includes:
|
||||
|
||||
```
|
||||
==========================================
|
||||
=== CronMaster Job Execution Log ===
|
||||
==========================================
|
||||
Log Folder: backup-database_root-0
|
||||
Command: bash /app/scripts/backup.sh
|
||||
Started: 2025-11-10 14:30:00
|
||||
==========================================
|
||||
|
||||
[command output here]
|
||||
|
||||
==========================================
|
||||
=== Execution Summary ===
|
||||
==========================================
|
||||
Completed: 2025-11-10 14:30:45
|
||||
Duration: 45 seconds
|
||||
Exit code: 0
|
||||
==========================================
|
||||
```
|
||||
|
||||
#### Automatic Cleanup
|
||||
|
||||
Logs are automatically cleaned up to prevent disk space issues:
|
||||
|
||||
- **Maximum logs per job**: 50 log files
|
||||
- **Maximum age**: 30 days
|
||||
- **Cleanup trigger**: When viewing logs or after manual execution
|
||||
- **Method**: Oldest logs are deleted first when limits are exceeded
|
||||
|
||||
#### Custom Wrapper Script
|
||||
|
||||
You can override the default log wrapper by creating your own at `./data/wrapper-override.sh`. This allows you to:
|
||||
|
||||
- Customize log format
|
||||
- Add additional metadata
|
||||
- Integrate with external logging services
|
||||
- Implement custom retention policies
|
||||
|
||||
**Example custom wrapper**:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
JOB_ID="$1"
|
||||
shift
|
||||
|
||||
# Your custom logic here
|
||||
LOG_FILE="/custom/path/${JOB_ID}_$(date '+%Y%m%d').log"
|
||||
|
||||
{
|
||||
echo "=== Custom Log Format ==="
|
||||
echo "Job: $JOB_ID"
|
||||
"$@"
|
||||
echo "Exit: $?"
|
||||
} >> "$LOG_FILE" 2>&1
|
||||
```
|
||||
|
||||
#### Docker Considerations
|
||||
|
||||
- Mount the `./data` directory to persist logs on the host
|
||||
- The wrapper script location: `./data/cron-log-wrapper.sh`. This will be generated automatically the first time you enable logging.
|
||||
|
||||
#### Non-Docker Considerations
|
||||
|
||||
- Logs are stored at `./data/logs/` relative to the project directory
|
||||
- The codebase wrapper script location: `./app/_scripts/cron-log-wrapper.sh`
|
||||
- The running wrapper script location: `./data/cron-log-wrapper.sh`
|
||||
|
||||
#### Important Notes
|
||||
|
||||
- Logging is **optional** and disabled by default
|
||||
- Jobs with logging enabled are marked with a blue "Logged" badge in the UI
|
||||
- Logs are captured for both scheduled runs and manual executions
|
||||
- Commands with file redirections (>, >>) may conflict with logging
|
||||
- The crontab stores the **wrapped command**, so jobs run independently of CronMaster
|
||||
📖 **For complete logging documentation, see [howto/LOGS.md](howto/LOGS.md)**
|
||||
|
||||
### Cron Schedule Format
|
||||
|
||||
@@ -468,27 +278,6 @@ The application uses standard cron format: `* * * * *`
|
||||
4. **Delete Scripts**: Remove unwanted scripts (this won't delete the cronjob, you will need to manually remove these yourself)
|
||||
5. **Clone Scripts**: Clone scripts to quickly edit them in case they are similar to one another.
|
||||
|
||||
<a id="technologies-used"></a>
|
||||
|
||||
## Technologies Used
|
||||
|
||||
- **Next.js 14**: React framework with App Router
|
||||
- **TypeScript**: Type-safe JavaScript
|
||||
- **Tailwind CSS**: Utility-first CSS framework
|
||||
- **Lucide React**: Beautiful icons
|
||||
- **next-themes**: Dark/light mode support
|
||||
- **Docker**: Containerization
|
||||
|
||||
<a id="contributing"></a>
|
||||
|
||||
## Contributing
|
||||
|
||||
1. Fork the repository
|
||||
2. Create a feature branch
|
||||
3. Make your changes
|
||||
4. Add tests if applicable
|
||||
5. Submit a pull request
|
||||
|
||||
## Community shouts
|
||||
|
||||
I would like to thank the following members for raising issues and help test/debug them!
|
||||
@@ -529,19 +318,14 @@ I would like to thank the following members for raising issues and help test/deb
|
||||
<a href="https://github.com/Navino16"><img width="100" height="100" src="https://avatars.githubusercontent.com/u/22234867?v=4&size=100"><br />Navino16</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" valign="top" width="20%">
|
||||
<a href="https://github.com/ShadowTox"><img width="100" height="100" src="https://avatars.githubusercontent.com/u/558536?v=4&size=100"><br />ShadowTox</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<a id="license"></a>
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the MIT License.
|
||||
|
||||
## Support
|
||||
|
||||
For issues and questions, please open an issue on the GitHub repository.
|
||||
|
||||
## Star History
|
||||
|
||||
[](https://www.star-history.com/#fccview/cronmaster&Date)
|
||||
|
||||
@@ -1,22 +1,49 @@
|
||||
"use client";
|
||||
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/app/_components/GlobalComponents/Cards/Card";
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "@/app/_components/GlobalComponents/Cards/Card";
|
||||
import { Button } from "@/app/_components/GlobalComponents/UIElements/Button";
|
||||
import { Clock, Plus } from "lucide-react";
|
||||
import { Switch } from "@/app/_components/GlobalComponents/UIElements/Switch";
|
||||
import {
|
||||
ClockIcon,
|
||||
PlusIcon,
|
||||
Archive,
|
||||
CaretDownIcon,
|
||||
CodeIcon,
|
||||
ChatTextIcon,
|
||||
GearIcon,
|
||||
CircleNotchIcon,
|
||||
FunnelIcon,
|
||||
} from "@phosphor-icons/react";
|
||||
import { CronJob } from "@/app/_utils/cronjob-utils";
|
||||
import { Script } from "@/app/_utils/scripts-utils";
|
||||
import { UserFilter } from "@/app/_components/FeatureComponents/User/UserFilter";
|
||||
|
||||
import { useCronJobState } from "@/app/_hooks/useCronJobState";
|
||||
import { CronJobItem } from "@/app/_components/FeatureComponents/Cronjobs/Parts/CronJobItem";
|
||||
import { MinimalCronJobItem } from "@/app/_components/FeatureComponents/Cronjobs/Parts/MinimalCronJobItem";
|
||||
import { CronJobEmptyState } from "@/app/_components/FeatureComponents/Cronjobs/Parts/CronJobEmptyState";
|
||||
import { CronJobListModals } from "@/app/_components/FeatureComponents/Modals/CronJobListsModals";
|
||||
import { LogsModal } from "@/app/_components/FeatureComponents/Modals/LogsModal";
|
||||
import { LiveLogModal } from "@/app/_components/FeatureComponents/Modals/LiveLogModal";
|
||||
import { RestoreBackupModal } from "@/app/_components/FeatureComponents/Modals/RestoreBackupModal";
|
||||
import { FiltersModal } from "@/app/_components/FeatureComponents/Modals/FiltersModal";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { useSSEContext } from "@/app/_contexts/SSEContext";
|
||||
import { useEffect } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import {
|
||||
fetchBackupFiles,
|
||||
restoreCronJob,
|
||||
deleteBackup,
|
||||
backupAllCronJobs,
|
||||
restoreAllCronJobs,
|
||||
} from "@/app/_server/actions/cronjobs";
|
||||
import { showToast } from "@/app/_components/GlobalComponents/UIElements/Toast";
|
||||
|
||||
interface CronJobListProps {
|
||||
cronJobs: CronJob[];
|
||||
@@ -27,6 +54,47 @@ export const CronJobList = ({ cronJobs, scripts }: CronJobListProps) => {
|
||||
const t = useTranslations();
|
||||
const router = useRouter();
|
||||
const { subscribe } = useSSEContext();
|
||||
const [isBackupModalOpen, setIsBackupModalOpen] = useState(false);
|
||||
const [backupFiles, setBackupFiles] = useState<
|
||||
Array<{
|
||||
filename: string;
|
||||
job: CronJob;
|
||||
backedUpAt: string;
|
||||
}>
|
||||
>([]);
|
||||
const [scheduleDisplayMode, setScheduleDisplayMode] = useState<
|
||||
"cron" | "human" | "both"
|
||||
>("both");
|
||||
const [loadedSettings, setLoadedSettings] = useState<boolean>(false);
|
||||
const [isFiltersModalOpen, setIsFiltersModalOpen] = useState(false);
|
||||
const [minimalMode, setMinimalMode] = useState(false);
|
||||
const [isClient, setIsClient] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setIsClient(true);
|
||||
|
||||
try {
|
||||
const savedScheduleMode = localStorage.getItem(
|
||||
"cronjob-schedule-display-mode"
|
||||
);
|
||||
if (
|
||||
savedScheduleMode === "cron" ||
|
||||
savedScheduleMode === "human" ||
|
||||
savedScheduleMode === "both"
|
||||
) {
|
||||
setScheduleDisplayMode(savedScheduleMode);
|
||||
}
|
||||
|
||||
const savedMinimalMode = localStorage.getItem("cronjob-minimal-mode");
|
||||
if (savedMinimalMode === "true") {
|
||||
setMinimalMode(true);
|
||||
}
|
||||
|
||||
setLoadedSettings(true);
|
||||
} catch (error) {
|
||||
console.warn("Failed to load settings from localStorage:", error);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const unsubscribe = subscribe((event) => {
|
||||
@@ -38,6 +106,79 @@ export const CronJobList = ({ cronJobs, scripts }: CronJobListProps) => {
|
||||
return unsubscribe;
|
||||
}, [subscribe, router]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isClient) return;
|
||||
|
||||
try {
|
||||
localStorage.setItem(
|
||||
"cronjob-schedule-display-mode",
|
||||
scheduleDisplayMode
|
||||
);
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
"Failed to save schedule display mode to localStorage:",
|
||||
error
|
||||
);
|
||||
}
|
||||
}, [scheduleDisplayMode, isClient]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isClient) return;
|
||||
|
||||
try {
|
||||
localStorage.setItem("cronjob-minimal-mode", minimalMode.toString());
|
||||
} catch (error) {
|
||||
console.warn("Failed to save minimal mode to localStorage:", error);
|
||||
}
|
||||
}, [minimalMode, isClient]);
|
||||
|
||||
const loadBackupFiles = async () => {
|
||||
const backups = await fetchBackupFiles();
|
||||
setBackupFiles(backups);
|
||||
};
|
||||
|
||||
const handleRestore = async (filename: string) => {
|
||||
const result = await restoreCronJob(filename);
|
||||
if (result.success) {
|
||||
showToast("success", t("cronjobs.restoreJobSuccess"));
|
||||
router.refresh();
|
||||
loadBackupFiles();
|
||||
} else {
|
||||
showToast("error", t("cronjobs.restoreJobFailed"), result.message);
|
||||
}
|
||||
};
|
||||
|
||||
const handleRestoreAll = async () => {
|
||||
const result = await restoreAllCronJobs();
|
||||
if (result.success) {
|
||||
showToast("success", result.message);
|
||||
router.refresh();
|
||||
setIsBackupModalOpen(false);
|
||||
} else {
|
||||
showToast("error", "Failed to restore all jobs", result.message);
|
||||
}
|
||||
};
|
||||
|
||||
const handleBackupAll = async () => {
|
||||
const result = await backupAllCronJobs();
|
||||
if (result.success) {
|
||||
showToast("success", result.message);
|
||||
loadBackupFiles();
|
||||
} else {
|
||||
showToast("error", t("cronjobs.backupAllFailed"), result.message);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDeleteBackup = async (filename: string) => {
|
||||
const result = await deleteBackup(filename);
|
||||
if (result.success) {
|
||||
showToast("success", t("cronjobs.backupDeleted"));
|
||||
loadBackupFiles();
|
||||
} else {
|
||||
showToast("error", "Failed to delete backup", result.message);
|
||||
}
|
||||
};
|
||||
|
||||
const {
|
||||
deletingId,
|
||||
runningJobId,
|
||||
@@ -86,6 +227,7 @@ export const CronJobList = ({ cronJobs, scripts }: CronJobListProps) => {
|
||||
handleEdit,
|
||||
handleEditSubmitLocal,
|
||||
handleNewCronSubmitLocal,
|
||||
handleBackupLocal,
|
||||
} = useCronJobState({ cronJobs, scripts });
|
||||
|
||||
return (
|
||||
@@ -94,36 +236,63 @@ export const CronJobList = ({ cronJobs, scripts }: CronJobListProps) => {
|
||||
<CardHeader>
|
||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="p-2 bg-primary/10 rounded-lg">
|
||||
<Clock className="h-5 w-5 text-primary" />
|
||||
<div className="p-2 bg-primary/10 ascii-border">
|
||||
<ClockIcon className="h-5 w-5 text-primary" />
|
||||
</div>
|
||||
<div>
|
||||
<CardTitle className="text-xl brand-gradient">
|
||||
{t("cronjobs.scheduledTasks")}
|
||||
</CardTitle>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t("cronjobs.nOfNJObs", { filtered: filteredJobs.length, total: cronJobs.length })}
|
||||
{" "}
|
||||
{selectedUser && t("cronjobs.forUser", { user: selectedUser })}
|
||||
{t("cronjobs.nOfNJObs", {
|
||||
filtered: filteredJobs.length,
|
||||
total: cronJobs.length,
|
||||
})}{" "}
|
||||
{selectedUser &&
|
||||
t("cronjobs.forUser", { user: selectedUser })}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<Button
|
||||
onClick={() => setIsNewCronModalOpen(true)}
|
||||
className="btn-primary glow-primary"
|
||||
>
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
{t("cronjobs.newTask")}
|
||||
</Button>
|
||||
<div className="flex gap-2 w-full justify-between sm:w-auto">
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
onClick={() => setIsFiltersModalOpen(true)}
|
||||
variant="outline"
|
||||
className="btn-outline"
|
||||
title={t("cronjobs.filters")}
|
||||
>
|
||||
<FunnelIcon className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => setIsBackupModalOpen(true)}
|
||||
variant="outline"
|
||||
className="btn-outline"
|
||||
title={t("cronjobs.backups")}
|
||||
>
|
||||
<Archive className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
<Button
|
||||
onClick={() => setIsNewCronModalOpen(true)}
|
||||
className="btn-primary glow-primary"
|
||||
>
|
||||
<PlusIcon className="h-4 w-4 mr-2" />
|
||||
{t("cronjobs.newTask")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="mb-4">
|
||||
<UserFilter
|
||||
selectedUser={selectedUser}
|
||||
onUserChange={setSelectedUser}
|
||||
className="w-full sm:w-64"
|
||||
/>
|
||||
<div className="mb-4 flex items-center justify-between">
|
||||
<div className="flex items-center gap-3">
|
||||
<label
|
||||
className="text-sm font-medium text-foreground cursor-pointer"
|
||||
onClick={() => setMinimalMode(!minimalMode)}
|
||||
>
|
||||
{t("cronjobs.minimalMode")}
|
||||
</label>
|
||||
<Switch checked={minimalMode} onCheckedChange={setMinimalMode} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{filteredJobs.length === 0 ? (
|
||||
@@ -132,26 +301,55 @@ export const CronJobList = ({ cronJobs, scripts }: CronJobListProps) => {
|
||||
onNewTaskClick={() => setIsNewCronModalOpen(true)}
|
||||
/>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
{filteredJobs.map((job) => (
|
||||
<CronJobItem
|
||||
key={job.id}
|
||||
job={job}
|
||||
errors={jobErrors[job.id] || []}
|
||||
runningJobId={runningJobId}
|
||||
deletingId={deletingId}
|
||||
onRun={handleRunLocal}
|
||||
onEdit={handleEdit}
|
||||
onClone={confirmClone}
|
||||
onResume={handleResumeLocal}
|
||||
onPause={handlePauseLocal}
|
||||
onToggleLogging={handleToggleLoggingLocal}
|
||||
onViewLogs={handleViewLogs}
|
||||
onDelete={confirmDelete}
|
||||
onErrorClick={handleErrorClickLocal}
|
||||
onErrorDismiss={refreshJobErrorsLocal}
|
||||
/>
|
||||
))}
|
||||
<div className="space-y-4 max-h-[55vh] min-h-[55vh] overflow-y-auto tui-scrollbar pr-1">
|
||||
{loadedSettings ? (
|
||||
filteredJobs.map((job) =>
|
||||
minimalMode ? (
|
||||
<MinimalCronJobItem
|
||||
key={job.id}
|
||||
job={job}
|
||||
errors={jobErrors[job.id] || []}
|
||||
runningJobId={runningJobId}
|
||||
deletingId={deletingId}
|
||||
scheduleDisplayMode={scheduleDisplayMode}
|
||||
onRun={handleRunLocal}
|
||||
onEdit={handleEdit}
|
||||
onClone={confirmClone}
|
||||
onResume={handleResumeLocal}
|
||||
onPause={handlePauseLocal}
|
||||
onToggleLogging={handleToggleLoggingLocal}
|
||||
onViewLogs={handleViewLogs}
|
||||
onDelete={confirmDelete}
|
||||
onBackup={handleBackupLocal}
|
||||
onErrorClick={handleErrorClickLocal}
|
||||
/>
|
||||
) : (
|
||||
<CronJobItem
|
||||
key={job.id}
|
||||
job={job}
|
||||
errors={jobErrors[job.id] || []}
|
||||
runningJobId={runningJobId}
|
||||
deletingId={deletingId}
|
||||
scheduleDisplayMode={scheduleDisplayMode}
|
||||
onRun={handleRunLocal}
|
||||
onEdit={handleEdit}
|
||||
onClone={confirmClone}
|
||||
onResume={handleResumeLocal}
|
||||
onPause={handlePauseLocal}
|
||||
onToggleLogging={handleToggleLoggingLocal}
|
||||
onViewLogs={handleViewLogs}
|
||||
onDelete={confirmDelete}
|
||||
onBackup={handleBackupLocal}
|
||||
onErrorClick={handleErrorClickLocal}
|
||||
onErrorDismiss={refreshJobErrorsLocal}
|
||||
/>
|
||||
)
|
||||
)
|
||||
) : (
|
||||
<div className="flex items-center justify-center h-full min-h-[55vh]">
|
||||
<CircleNotchIcon className="h-8 w-8 animate-spin text-primary" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
@@ -160,7 +358,6 @@ export const CronJobList = ({ cronJobs, scripts }: CronJobListProps) => {
|
||||
<CronJobListModals
|
||||
cronJobs={cronJobs}
|
||||
scripts={scripts}
|
||||
|
||||
isNewCronModalOpen={isNewCronModalOpen}
|
||||
onNewCronModalClose={() => setIsNewCronModalOpen(false)}
|
||||
onNewCronSubmit={handleNewCronSubmitLocal}
|
||||
@@ -168,7 +365,6 @@ export const CronJobList = ({ cronJobs, scripts }: CronJobListProps) => {
|
||||
onNewCronFormChange={(updates) =>
|
||||
setNewCronForm((prev) => ({ ...prev, ...updates }))
|
||||
}
|
||||
|
||||
isEditModalOpen={isEditModalOpen}
|
||||
onEditModalClose={() => setIsEditModalOpen(false)}
|
||||
onEditSubmit={handleEditSubmitLocal}
|
||||
@@ -176,20 +372,17 @@ export const CronJobList = ({ cronJobs, scripts }: CronJobListProps) => {
|
||||
onEditFormChange={(updates) =>
|
||||
setEditForm((prev) => ({ ...prev, ...updates }))
|
||||
}
|
||||
|
||||
isDeleteModalOpen={isDeleteModalOpen}
|
||||
onDeleteModalClose={() => setIsDeleteModalOpen(false)}
|
||||
onDeleteConfirm={() =>
|
||||
jobToDelete ? handleDeleteLocal(jobToDelete.id) : undefined
|
||||
}
|
||||
jobToDelete={jobToDelete}
|
||||
|
||||
isCloneModalOpen={isCloneModalOpen}
|
||||
onCloneModalClose={() => setIsCloneModalOpen(false)}
|
||||
onCloneConfirm={handleCloneLocal}
|
||||
jobToClone={jobToClone}
|
||||
isCloning={isCloning}
|
||||
|
||||
isErrorModalOpen={errorModalOpen}
|
||||
onErrorModalClose={() => {
|
||||
setErrorModalOpen(false);
|
||||
@@ -215,6 +408,26 @@ export const CronJobList = ({ cronJobs, scripts }: CronJobListProps) => {
|
||||
jobId={liveLogJobId}
|
||||
jobComment={liveLogJobComment}
|
||||
/>
|
||||
|
||||
<RestoreBackupModal
|
||||
isOpen={isBackupModalOpen}
|
||||
onClose={() => setIsBackupModalOpen(false)}
|
||||
backups={backupFiles}
|
||||
onRestore={handleRestore}
|
||||
onRestoreAll={handleRestoreAll}
|
||||
onBackupAll={handleBackupAll}
|
||||
onDelete={handleDeleteBackup}
|
||||
onRefresh={loadBackupFiles}
|
||||
/>
|
||||
|
||||
<FiltersModal
|
||||
isOpen={isFiltersModalOpen}
|
||||
onClose={() => setIsFiltersModalOpen(false)}
|
||||
selectedUser={selectedUser}
|
||||
onUserChange={setSelectedUser}
|
||||
scheduleDisplayMode={scheduleDisplayMode}
|
||||
onScheduleDisplayModeChange={setScheduleDisplayMode}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { Button } from "@/app/_components/GlobalComponents/UIElements/Button";
|
||||
import { Clock, Plus } from "lucide-react";
|
||||
import { ClockIcon, PlusIcon } from "@phosphor-icons/react";
|
||||
|
||||
interface CronJobEmptyStateProps {
|
||||
selectedUser: string | null;
|
||||
@@ -15,7 +15,7 @@ export const CronJobEmptyState = ({
|
||||
return (
|
||||
<div className="text-center py-16">
|
||||
<div className="mx-auto w-20 h-20 bg-gradient-to-br from-primary/20 to-blue-500/20 rounded-full flex items-center justify-center mb-6">
|
||||
<Clock className="h-10 w-10 text-primary" />
|
||||
<ClockIcon className="h-10 w-10 text-primary" />
|
||||
</div>
|
||||
<h3 className="text-xl font-semibold mb-3 brand-gradient">
|
||||
{selectedUser
|
||||
@@ -32,7 +32,7 @@ export const CronJobEmptyState = ({
|
||||
className="btn-primary glow-primary"
|
||||
size="lg"
|
||||
>
|
||||
<Plus className="h-5 w-5 mr-2" />
|
||||
<PlusIcon className="h-5 w-5 mr-2" />
|
||||
Create Your First Task
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -2,22 +2,26 @@
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { Button } from "@/app/_components/GlobalComponents/UIElements/Button";
|
||||
import { DropdownMenu } from "@/app/_components/GlobalComponents/UIElements/DropdownMenu";
|
||||
import {
|
||||
Trash2,
|
||||
Edit,
|
||||
Files,
|
||||
User,
|
||||
Play,
|
||||
Pause,
|
||||
Code,
|
||||
Info,
|
||||
FileOutput,
|
||||
FileX,
|
||||
FileText,
|
||||
AlertCircle,
|
||||
CheckCircle,
|
||||
AlertTriangle,
|
||||
} from "lucide-react";
|
||||
TrashIcon,
|
||||
PencilSimpleIcon,
|
||||
FilesIcon,
|
||||
UserIcon,
|
||||
PlayIcon,
|
||||
PauseIcon,
|
||||
CodeIcon,
|
||||
InfoIcon,
|
||||
FileArrowDownIcon,
|
||||
FileXIcon,
|
||||
FileTextIcon,
|
||||
WarningCircleIcon,
|
||||
CheckCircleIcon,
|
||||
WarningIcon,
|
||||
DownloadIcon,
|
||||
HashIcon,
|
||||
CheckIcon,
|
||||
} from "@phosphor-icons/react";
|
||||
import { CronJob } from "@/app/_utils/cronjob-utils";
|
||||
import { JobError } from "@/app/_utils/error-utils";
|
||||
import { ErrorBadge } from "@/app/_components/GlobalComponents/Badges/ErrorBadge";
|
||||
@@ -28,12 +32,14 @@ import {
|
||||
import { unwrapCommand } from "@/app/_utils/wrapper-utils-client";
|
||||
import { useLocale } from "next-intl";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { copyToClipboard } from "@/app/_utils/global-utils";
|
||||
|
||||
interface CronJobItemProps {
|
||||
job: CronJob;
|
||||
errors: JobError[];
|
||||
runningJobId: string | null;
|
||||
deletingId: string | null;
|
||||
scheduleDisplayMode: "cron" | "human" | "both";
|
||||
onRun: (id: string) => void;
|
||||
onEdit: (job: CronJob) => void;
|
||||
onClone: (job: CronJob) => void;
|
||||
@@ -42,6 +48,7 @@ interface CronJobItemProps {
|
||||
onDelete: (job: CronJob) => void;
|
||||
onToggleLogging: (id: string) => void;
|
||||
onViewLogs: (job: CronJob) => void;
|
||||
onBackup: (id: string) => void;
|
||||
onErrorClick: (error: JobError) => void;
|
||||
onErrorDismiss: () => void;
|
||||
}
|
||||
@@ -51,6 +58,7 @@ export const CronJobItem = ({
|
||||
errors,
|
||||
runningJobId,
|
||||
deletingId,
|
||||
scheduleDisplayMode,
|
||||
onRun,
|
||||
onEdit,
|
||||
onClone,
|
||||
@@ -59,14 +67,18 @@ export const CronJobItem = ({
|
||||
onDelete,
|
||||
onToggleLogging,
|
||||
onViewLogs,
|
||||
onBackup,
|
||||
onErrorClick,
|
||||
onErrorDismiss,
|
||||
}: CronJobItemProps) => {
|
||||
const [cronExplanation, setCronExplanation] =
|
||||
useState<CronExplanation | null>(null);
|
||||
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
|
||||
const [showCopyConfirmation, setShowCopyConfirmation] = useState(false);
|
||||
const locale = useLocale();
|
||||
const t = useTranslations();
|
||||
const displayCommand = unwrapCommand(job.command);
|
||||
const [commandCopied, setCommandCopied] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (job.schedule) {
|
||||
@@ -76,51 +88,160 @@ export const CronJobItem = ({
|
||||
setCronExplanation(null);
|
||||
}
|
||||
}, [job.schedule]);
|
||||
|
||||
const dropdownMenuItems = [
|
||||
{
|
||||
label: t("cronjobs.editCronJob"),
|
||||
icon: <PencilSimpleIcon className="h-3 w-3" />,
|
||||
onClick: () => onEdit(job),
|
||||
},
|
||||
{
|
||||
label: job.logsEnabled
|
||||
? t("cronjobs.disableLogging")
|
||||
: t("cronjobs.enableLogging"),
|
||||
icon: job.logsEnabled ? (
|
||||
<FileXIcon className="h-3 w-3" />
|
||||
) : (
|
||||
<FileArrowDownIcon className="h-3 w-3" />
|
||||
),
|
||||
onClick: () => onToggleLogging(job.id),
|
||||
},
|
||||
...(job.logsEnabled
|
||||
? [
|
||||
{
|
||||
label: t("cronjobs.viewLogs"),
|
||||
icon: <FileTextIcon className="h-3 w-3" />,
|
||||
onClick: () => onViewLogs(job),
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
label: job.paused
|
||||
? t("cronjobs.resumeCronJob")
|
||||
: t("cronjobs.pauseCronJob"),
|
||||
icon: job.paused ? (
|
||||
<PlayIcon className="h-3 w-3" />
|
||||
) : (
|
||||
<PauseIcon className="h-3 w-3" />
|
||||
),
|
||||
onClick: () => (job.paused ? onResume(job.id) : onPause(job.id)),
|
||||
},
|
||||
{
|
||||
label: t("cronjobs.cloneCronJob"),
|
||||
icon: <FilesIcon className="h-3 w-3" />,
|
||||
onClick: () => onClone(job),
|
||||
},
|
||||
{
|
||||
label: t("cronjobs.backupJob"),
|
||||
icon: <DownloadIcon className="h-3 w-3" />,
|
||||
onClick: () => onBackup(job.id),
|
||||
},
|
||||
{
|
||||
label: t("cronjobs.deleteCronJob"),
|
||||
icon: <TrashIcon className="h-3 w-3" />,
|
||||
onClick: () => onDelete(job),
|
||||
variant: "destructive" as const,
|
||||
disabled: deletingId === job.id,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div
|
||||
key={job.id}
|
||||
className="glass-card p-4 border border-border/50 rounded-lg hover:bg-accent/30 transition-colors"
|
||||
className={`border border-border lg:tui-card p-4 terminal-font transition-colors ${isDropdownOpen ? "relative z-10" : ""
|
||||
}`}
|
||||
>
|
||||
<div className="flex flex-col sm:flex-row sm:items-start gap-4">
|
||||
<div className="flex-1 min-w-0 order-2 lg:order-1">
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-3 mb-2">
|
||||
<code className="text-sm bg-purple-500/10 text-purple-600 dark:text-purple-400 px-2 py-1 rounded font-mono border border-purple-500/20">
|
||||
{job.schedule}
|
||||
</code>
|
||||
{(scheduleDisplayMode === "cron" ||
|
||||
scheduleDisplayMode === "both") && (
|
||||
<code className="text-sm bg-background0 text-status-warning px-2 py-1 terminal-font ascii-border">
|
||||
{job.schedule}
|
||||
</code>
|
||||
)}
|
||||
{scheduleDisplayMode === "human" && cronExplanation?.isValid && (
|
||||
<div className="flex items-start gap-1.5 ascii-border bg-background2 px-2 py-0.5">
|
||||
<InfoIcon className="h-3 w-3 mt-0.5 flex-shrink-0" />
|
||||
<p className="text-sm italic">
|
||||
{cronExplanation.humanReadable}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex-1 min-w-0">
|
||||
<pre
|
||||
className="text-sm font-medium text-foreground truncate bg-muted/30 px-2 py-1 rounded border border-border/30"
|
||||
title={displayCommand}
|
||||
>
|
||||
{displayCommand}
|
||||
</pre>
|
||||
<div className="flex items-center gap-2 min-w-0 w-full">
|
||||
{commandCopied === job.id && (
|
||||
<CheckIcon className="h-3 w-3 text-status-success" />
|
||||
)}
|
||||
<pre
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
copyToClipboard(unwrapCommand(job.command));
|
||||
setCommandCopied(job.id);
|
||||
setTimeout(() => setCommandCopied(null), 3000);
|
||||
}}
|
||||
className="w-full cursor-pointer overflow-x-auto text-sm font-medium terminal-font bg-background1 px-2 py-1 ascii-border hide-scrollbar"
|
||||
>
|
||||
{unwrapCommand(displayCommand)}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{cronExplanation?.isValid && (
|
||||
<div className="flex items-start gap-1.5 mb-1">
|
||||
<Info className="h-3 w-3 text-primary mt-0.5 flex-shrink-0" />
|
||||
<p className="text-xs text-muted-foreground italic">
|
||||
{cronExplanation.humanReadable}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex items-center gap-2 pb-2 pt-4">
|
||||
{scheduleDisplayMode === "both" && cronExplanation?.isValid && (
|
||||
<div className="flex items-start gap-1.5 ascii-border bg-background2 px-2 py-0.5">
|
||||
<InfoIcon className="h-3 w-3 mt-0.5 flex-shrink-0" />
|
||||
<p className="text-xs italic">
|
||||
{cronExplanation.humanReadable}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<div className="flex items-center gap-1 text-xs text-muted-foreground">
|
||||
<User className="h-3 w-3" />
|
||||
{job.comment && (
|
||||
<p
|
||||
className="text-xs italic truncate"
|
||||
title={job.comment}
|
||||
>
|
||||
{job.comment}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-2 py-3">
|
||||
<div className="flex items-center gap-1 text-xs bg-background0 px-2 py-0.5 ascii-border cursor-pointer hover:bg-background2 transition-colors relative terminal-font">
|
||||
<UserIcon className="h-3 w-3" />
|
||||
<span>{job.user}</span>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className="flex items-center gap-1 text-xs bg-background0 px-2 py-0.5 ascii-border cursor-pointer hover:bg-background2 transition-colors relative terminal-font"
|
||||
title="Click to copy Job UUID"
|
||||
onClick={async () => {
|
||||
const success = await copyToClipboard(job.id);
|
||||
if (success) {
|
||||
setShowCopyConfirmation(true);
|
||||
setTimeout(() => setShowCopyConfirmation(false), 3000);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{showCopyConfirmation ? (
|
||||
<CheckIcon className="h-3 w-3 text-status-success" />
|
||||
) : (
|
||||
<HashIcon className="h-3 w-3" />
|
||||
)}
|
||||
<span className="font-mono">{job.id}</span>
|
||||
</div>
|
||||
|
||||
{job.paused && (
|
||||
<span className="text-xs bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 px-2 py-0.5 rounded border border-yellow-500/20">
|
||||
{t("cronjobs.paused")}
|
||||
<span className="text-xs bg-background2 px-2 py-0.5 ascii-border terminal-font">
|
||||
<span className="text-status-warning">{t("cronjobs.paused")}</span>
|
||||
</span>
|
||||
)}
|
||||
|
||||
{job.logsEnabled && (
|
||||
<span className="text-xs bg-blue-500/10 text-blue-600 dark:text-blue-400 px-2 py-0.5 rounded border border-blue-500/20">
|
||||
{t("cronjobs.logged")}
|
||||
<span className="text-xs bg-background0 px-2 py-0.5 ascii-border terminal-font">
|
||||
<span className="text-status-info">{t("cronjobs.logged")}</span>
|
||||
</span>
|
||||
)}
|
||||
|
||||
@@ -130,35 +251,44 @@ export const CronJobItem = ({
|
||||
e.stopPropagation();
|
||||
onViewLogs(job);
|
||||
}}
|
||||
className="flex items-center gap-1 text-xs bg-red-500/10 text-red-600 dark:text-red-400 px-2 py-0.5 rounded border border-red-500/30 hover:bg-red-500/20 transition-colors cursor-pointer"
|
||||
className="flex items-center gap-1 text-xs bg-background0 px-2 py-0.5 ascii-border hover:bg-background1 transition-colors cursor-pointer terminal-font"
|
||||
title="Latest execution failed - Click to view error log"
|
||||
>
|
||||
<AlertCircle className="h-3 w-3" />
|
||||
<span>{t("cronjobs.failed", { exitCode: job.logError?.exitCode?.toString() ?? "" })}</span>
|
||||
<WarningCircleIcon className="h-3 w-3 text-status-error" />
|
||||
<span className="text-status-error">
|
||||
{t("cronjobs.failed", {
|
||||
exitCode: job.logError?.exitCode?.toString() ?? "",
|
||||
})}
|
||||
</span>
|
||||
</button>
|
||||
)}
|
||||
|
||||
{job.logsEnabled && !job.logError?.hasError && job.logError?.hasHistoricalFailures && (
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onViewLogs(job);
|
||||
}}
|
||||
className="flex items-center gap-1 text-xs bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 px-2 py-0.5 rounded border border-yellow-500/30 hover:bg-yellow-500/20 transition-colors cursor-pointer"
|
||||
title="Latest execution succeeded, but has historical failures - Click to view logs"
|
||||
>
|
||||
<CheckCircle className="h-3 w-3" />
|
||||
<span>{t("cronjobs.healthy")}</span>
|
||||
<AlertTriangle className="h-3 w-3" />
|
||||
</button>
|
||||
)}
|
||||
{job.logsEnabled &&
|
||||
!job.logError?.hasError &&
|
||||
job.logError?.hasHistoricalFailures && (
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onViewLogs(job);
|
||||
}}
|
||||
className="flex items-center gap-1 text-xs bg-background0 px-2 py-0.5 ascii-border hover:bg-background1 transition-colors cursor-pointer terminal-font"
|
||||
title="Latest execution succeeded, but has historical failures - Click to view logs"
|
||||
>
|
||||
<CheckCircleIcon className="h-3 w-3 text-status-success" />
|
||||
<span className="text-status-warning">{t("cronjobs.healthy")}</span>
|
||||
<WarningIcon className="h-3 w-3 text-status-warning" />
|
||||
</button>
|
||||
)}
|
||||
|
||||
{job.logsEnabled && !job.logError?.hasError && !job.logError?.hasHistoricalFailures && job.logError?.latestExitCode === 0 && (
|
||||
<div className="flex items-center gap-1 text-xs bg-green-500/10 text-green-600 dark:text-green-400 px-2 py-0.5 rounded border border-green-500/30">
|
||||
<CheckCircle className="h-3 w-3" />
|
||||
<span>{t("cronjobs.healthy")}</span>
|
||||
</div>
|
||||
)}
|
||||
{job.logsEnabled &&
|
||||
!job.logError?.hasError &&
|
||||
!job.logError?.hasHistoricalFailures &&
|
||||
job.logError?.latestExitCode === 0 && (
|
||||
<div className="flex items-center gap-1 text-xs bg-background0 px-2 py-0.5 ascii-border terminal-font">
|
||||
<CheckCircleIcon className="h-3 w-3 text-status-success" />
|
||||
<span className="text-status-success">{t("cronjobs.healthy")}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!job.logsEnabled && (
|
||||
<ErrorBadge
|
||||
@@ -168,128 +298,81 @@ export const CronJobItem = ({
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{job.comment && (
|
||||
<p
|
||||
className="text-xs text-muted-foreground italic truncate"
|
||||
title={job.comment}
|
||||
>
|
||||
{job.comment}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2 flex-shrink-0 order-1 lg:order-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onRun(job.id)}
|
||||
disabled={runningJobId === job.id || job.paused}
|
||||
className="btn-outline h-8 px-3"
|
||||
title={t("cronjobs.runCronManually")}
|
||||
aria-label={t("cronjobs.runCronManually")}
|
||||
>
|
||||
{runningJobId === job.id ? (
|
||||
<div className="h-3 w-3 animate-spin rounded-full border-2 border-current border-t-transparent" />
|
||||
) : (
|
||||
<Code className="h-3 w-3" />
|
||||
)}
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onEdit(job)}
|
||||
className="btn-outline h-8 px-3"
|
||||
title={t("cronjobs.editCronJob")}
|
||||
aria-label={t("cronjobs.editCronJob")}
|
||||
>
|
||||
<Edit className="h-3 w-3" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onClone(job)}
|
||||
className="btn-outline h-8 px-3"
|
||||
title={t("cronjobs.cloneCronJob")}
|
||||
aria-label={t("cronjobs.cloneCronJob")}
|
||||
>
|
||||
<Files className="h-3 w-3" />
|
||||
</Button>
|
||||
{job.paused ? (
|
||||
<div className="flex items-center gap-2 justify-between sm:justify-end">
|
||||
<div className="flex items-center gap-2 flex-shrink-0">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onResume(job.id)}
|
||||
onClick={() => onRun(job.id)}
|
||||
disabled={runningJobId === job.id || job.paused}
|
||||
className="btn-outline h-8 px-3"
|
||||
title={t("cronjobs.resumeCronJob")}
|
||||
aria-label={t("cronjobs.resumeCronJob")}
|
||||
title={t("cronjobs.runCronManually")}
|
||||
aria-label={t("cronjobs.runCronManually")}
|
||||
>
|
||||
<Play className="h-3 w-3" />
|
||||
{runningJobId === job.id ? (
|
||||
<div className="h-3 w-3 animate-spin rounded-full border-2 border-current border-t-transparent" />
|
||||
) : (
|
||||
<CodeIcon className="h-3 w-3" />
|
||||
)}
|
||||
</Button>
|
||||
) : (
|
||||
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onPause(job.id)}
|
||||
onClick={() => {
|
||||
if (job.paused) {
|
||||
onResume(job.id);
|
||||
} else {
|
||||
onPause(job.id);
|
||||
}
|
||||
}}
|
||||
className="btn-outline h-8 px-3"
|
||||
title={t("cronjobs.pauseCronJob")}
|
||||
aria-label={t("cronjobs.pauseCronJob")}
|
||||
>
|
||||
<Pause className="h-3 w-3" />
|
||||
{job.paused ? (
|
||||
<PlayIcon className="h-3 w-3" />
|
||||
) : (
|
||||
<PauseIcon className="h-3 w-3" />
|
||||
)}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onToggleLogging(job.id)}
|
||||
className={`h-8 px-3 ${job.logsEnabled
|
||||
? "btn-outline border-blue-500/50 text-blue-600 dark:text-blue-400 hover:bg-blue-500/10"
|
||||
: "btn-outline"
|
||||
}`}
|
||||
title={
|
||||
job.logsEnabled
|
||||
? t("cronjobs.disableLogging")
|
||||
: t("cronjobs.enableLogging")
|
||||
}
|
||||
aria-label={
|
||||
job.logsEnabled
|
||||
? t("cronjobs.disableLogging")
|
||||
: t("cronjobs.enableLogging")
|
||||
}
|
||||
>
|
||||
{job.logsEnabled ? (
|
||||
<FileOutput className="h-3 w-3" />
|
||||
) : (
|
||||
<FileX className="h-3 w-3" />
|
||||
)}
|
||||
</Button>
|
||||
{job.logsEnabled && (
|
||||
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onViewLogs(job)}
|
||||
onClick={() => {
|
||||
if (job.logsEnabled) {
|
||||
onViewLogs(job);
|
||||
} else {
|
||||
onToggleLogging(job.id);
|
||||
}
|
||||
}}
|
||||
className="btn-outline h-8 px-3"
|
||||
title={t("cronjobs.viewLogs")}
|
||||
aria-label={t("cronjobs.viewLogs")}
|
||||
title={
|
||||
job.logsEnabled
|
||||
? t("cronjobs.viewLogs")
|
||||
: t("cronjobs.enableLogging")
|
||||
}
|
||||
aria-label={
|
||||
job.logsEnabled
|
||||
? t("cronjobs.viewLogs")
|
||||
: t("cronjobs.enableLogging")
|
||||
}
|
||||
>
|
||||
<FileText className="h-3 w-3" />
|
||||
{job.logsEnabled ? (
|
||||
<FileTextIcon className="h-3 w-3" />
|
||||
) : (
|
||||
<FileArrowDownIcon className="h-3 w-3" />
|
||||
)}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="destructive"
|
||||
size="sm"
|
||||
onClick={() => onDelete(job)}
|
||||
disabled={deletingId === job.id}
|
||||
className="btn-destructive h-8 px-3"
|
||||
title={t("cronjobs.deleteCronJob")}
|
||||
aria-label={t("cronjobs.deleteCronJob")}
|
||||
>
|
||||
{deletingId === job.id ? (
|
||||
<div className="h-3 w-3 animate-spin rounded-full border-2 border-current border-t-transparent" />
|
||||
) : (
|
||||
<Trash2 className="h-3 w-3" />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<DropdownMenu
|
||||
items={dropdownMenuItems}
|
||||
onOpenChange={setIsDropdownOpen}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,310 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { Button } from "@/app/_components/GlobalComponents/UIElements/Button";
|
||||
import { DropdownMenu } from "@/app/_components/GlobalComponents/UIElements/DropdownMenu";
|
||||
import {
|
||||
TrashIcon,
|
||||
PencilSimpleIcon,
|
||||
FilesIcon,
|
||||
PlayIcon,
|
||||
PauseIcon,
|
||||
CodeIcon,
|
||||
InfoIcon,
|
||||
DownloadIcon,
|
||||
CheckIcon,
|
||||
FileXIcon,
|
||||
FileTextIcon,
|
||||
FileArrowDownIcon,
|
||||
} from "@phosphor-icons/react";
|
||||
import { CronJob } from "@/app/_utils/cronjob-utils";
|
||||
import { JobError } from "@/app/_utils/error-utils";
|
||||
import {
|
||||
parseCronExpression,
|
||||
type CronExplanation,
|
||||
} from "@/app/_utils/parser-utils";
|
||||
import { unwrapCommand } from "@/app/_utils/wrapper-utils-client";
|
||||
import { useLocale } from "next-intl";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { copyToClipboard } from "@/app/_utils/global-utils";
|
||||
|
||||
interface MinimalCronJobItemProps {
|
||||
job: CronJob;
|
||||
errors: JobError[];
|
||||
runningJobId: string | null;
|
||||
deletingId: string | null;
|
||||
scheduleDisplayMode: "cron" | "human" | "both";
|
||||
onRun: (id: string) => void;
|
||||
onEdit: (job: CronJob) => void;
|
||||
onClone: (job: CronJob) => void;
|
||||
onResume: (id: string) => void;
|
||||
onPause: (id: string) => void;
|
||||
onDelete: (job: CronJob) => void;
|
||||
onToggleLogging: (id: string) => void;
|
||||
onViewLogs: (job: CronJob) => void;
|
||||
onBackup: (id: string) => void;
|
||||
onErrorClick: (error: JobError) => void;
|
||||
}
|
||||
|
||||
export const MinimalCronJobItem = ({
|
||||
job,
|
||||
errors,
|
||||
runningJobId,
|
||||
deletingId,
|
||||
scheduleDisplayMode,
|
||||
onRun,
|
||||
onEdit,
|
||||
onClone,
|
||||
onResume,
|
||||
onPause,
|
||||
onDelete,
|
||||
onToggleLogging,
|
||||
onViewLogs,
|
||||
onBackup,
|
||||
onErrorClick,
|
||||
}: MinimalCronJobItemProps) => {
|
||||
const [cronExplanation, setCronExplanation] =
|
||||
useState<CronExplanation | null>(null);
|
||||
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
|
||||
const [commandCopied, setCommandCopied] = useState<string | null>(null);
|
||||
const locale = useLocale();
|
||||
const t = useTranslations();
|
||||
const displayCommand = unwrapCommand(job.command);
|
||||
|
||||
useEffect(() => {
|
||||
if (job.schedule) {
|
||||
const explanation = parseCronExpression(job.schedule, locale);
|
||||
setCronExplanation(explanation);
|
||||
} else {
|
||||
setCronExplanation(null);
|
||||
}
|
||||
}, [job.schedule]);
|
||||
|
||||
const dropdownMenuItems = [
|
||||
{
|
||||
label: t("cronjobs.editCronJob"),
|
||||
icon: <PencilSimpleIcon className="h-3 w-3" />,
|
||||
onClick: () => onEdit(job),
|
||||
},
|
||||
{
|
||||
label: job.logsEnabled
|
||||
? t("cronjobs.disableLogging")
|
||||
: t("cronjobs.enableLogging"),
|
||||
icon: job.logsEnabled ? (
|
||||
<FileXIcon className="h-3 w-3" />
|
||||
) : (
|
||||
<CodeIcon className="h-3 w-3" />
|
||||
),
|
||||
onClick: () => onToggleLogging(job.id),
|
||||
},
|
||||
...(job.logsEnabled
|
||||
? [
|
||||
{
|
||||
label: t("cronjobs.viewLogs"),
|
||||
icon: <CodeIcon className="h-3 w-3" />,
|
||||
onClick: () => onViewLogs(job),
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
label: job.paused
|
||||
? t("cronjobs.resumeCronJob")
|
||||
: t("cronjobs.pauseCronJob"),
|
||||
icon: job.paused ? (
|
||||
<PlayIcon className="h-3 w-3" />
|
||||
) : (
|
||||
<PauseIcon className="h-3 w-3" />
|
||||
),
|
||||
onClick: () => (job.paused ? onResume(job.id) : onPause(job.id)),
|
||||
},
|
||||
{
|
||||
label: t("cronjobs.cloneCronJob"),
|
||||
icon: <FilesIcon className="h-3 w-3" />,
|
||||
onClick: () => onClone(job),
|
||||
},
|
||||
{
|
||||
label: t("cronjobs.backupJob"),
|
||||
icon: <DownloadIcon className="h-3 w-3" />,
|
||||
onClick: () => onBackup(job.id),
|
||||
},
|
||||
{
|
||||
label: t("cronjobs.deleteCronJob"),
|
||||
icon: <TrashIcon className="h-3 w-3" />,
|
||||
onClick: () => onDelete(job),
|
||||
variant: "destructive" as const,
|
||||
disabled: deletingId === job.id,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div
|
||||
key={job.id}
|
||||
className={`border border-border lg:tui-card p-3 terminal-font transition-colors ${isDropdownOpen ? "relative z-10" : ""
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="flex items-center gap-1 flex-shrink-0">
|
||||
{scheduleDisplayMode === "cron" && (
|
||||
<code className="text-xs bg-background0 text-status-warning px-1.5 py-0.5 terminal-font ascii-border">
|
||||
{job.schedule}
|
||||
</code>
|
||||
)}
|
||||
{scheduleDisplayMode === "human" && cronExplanation?.isValid && (
|
||||
<div className="flex items-center gap-1 ascii-border bg-background2 px-1.5 py-0.5">
|
||||
<InfoIcon className="h-3 w-3 flex-shrink-0" />
|
||||
<span className="text-xs italic truncate max-w-32">
|
||||
{cronExplanation.humanReadable}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{scheduleDisplayMode === "both" && (
|
||||
<div className="flex items-center gap-1">
|
||||
<code className="text-xs bg-background0 text-status-warning px-1 py-0.5 terminal-font ascii-border">
|
||||
{job.schedule}
|
||||
</code>
|
||||
{cronExplanation?.isValid && (
|
||||
<div
|
||||
className="flex items-center gap-1 ascii-border bg-background0 px-1 py-0.5 cursor-help"
|
||||
title={cronExplanation.humanReadable}
|
||||
>
|
||||
<InfoIcon className="h-2.5 w-2.5 flex-shrink-0" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2">
|
||||
{commandCopied === job.id && (
|
||||
<CheckIcon className="h-3 w-3 text-status-success flex-shrink-0" />
|
||||
)}
|
||||
<pre
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
copyToClipboard(unwrapCommand(job.command));
|
||||
setCommandCopied(job.id);
|
||||
setTimeout(() => setCommandCopied(null), 3000);
|
||||
}}
|
||||
className="flex-1 cursor-pointer overflow-hidden text-sm font-medium terminal-font bg-background1 px-2 py-1 ascii-border truncate"
|
||||
title={unwrapCommand(job.command)}
|
||||
>
|
||||
{unwrapCommand(displayCommand)}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-1 flex-shrink-0">
|
||||
{job.logsEnabled && (
|
||||
<div
|
||||
className="w-2 h-2 bg-status-info ascii-border"
|
||||
title={t("cronjobs.logged")}
|
||||
/>
|
||||
)}
|
||||
{job.paused && (
|
||||
<div
|
||||
className="w-2 h-2 bg-status-warning ascii-border"
|
||||
title={t("cronjobs.paused")}
|
||||
/>
|
||||
)}
|
||||
{!job.logError?.hasError && job.logsEnabled && (
|
||||
<div
|
||||
className="w-2 h-2 bg-status-success ascii-border"
|
||||
title={t("cronjobs.healthy")}
|
||||
/>
|
||||
)}
|
||||
{job.logsEnabled && job.logError?.hasError && (
|
||||
<div
|
||||
className="w-2 h-2 bg-status-error ascii-border cursor-pointer"
|
||||
title="Latest execution failed - Click to view error log"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onViewLogs(job);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{!job.logsEnabled && errors.length > 0 && (
|
||||
<div
|
||||
className="w-2 h-2 bg-status-warning ascii-border cursor-pointer"
|
||||
title={`${errors.length} error(s)`}
|
||||
onClick={(e) => onErrorClick(errors[0])}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2 flex-shrink-0">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onRun(job.id)}
|
||||
disabled={runningJobId === job.id || job.paused}
|
||||
className="btn-outline h-8 px-3 hidden md:flex"
|
||||
title={t("cronjobs.runCronManually")}
|
||||
aria-label={t("cronjobs.runCronManually")}
|
||||
>
|
||||
{runningJobId === job.id ? (
|
||||
<div className="h-3 w-3 animate-spin rounded-full border-2 border-current border-t-transparent" />
|
||||
) : (
|
||||
<CodeIcon className="h-3 w-3" />
|
||||
)}
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
if (job.paused) {
|
||||
onResume(job.id);
|
||||
} else {
|
||||
onPause(job.id);
|
||||
}
|
||||
}}
|
||||
className="btn-outline h-8 px-3 hidden md:flex"
|
||||
title={t("cronjobs.pauseCronJob")}
|
||||
aria-label={t("cronjobs.pauseCronJob")}
|
||||
>
|
||||
{job.paused ? (
|
||||
<PlayIcon className="h-3 w-3" />
|
||||
) : (
|
||||
<PauseIcon className="h-3 w-3" />
|
||||
)}
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
if (job.logsEnabled) {
|
||||
onViewLogs(job);
|
||||
} else {
|
||||
onToggleLogging(job.id);
|
||||
}
|
||||
}}
|
||||
className="btn-outline h-8 px-3 hidden md:flex"
|
||||
title={
|
||||
job.logsEnabled
|
||||
? t("cronjobs.viewLogs")
|
||||
: t("cronjobs.enableLogging")
|
||||
}
|
||||
aria-label={
|
||||
job.logsEnabled
|
||||
? t("cronjobs.viewLogs")
|
||||
: t("cronjobs.enableLogging")
|
||||
}
|
||||
>
|
||||
{job.logsEnabled ? (
|
||||
<FileTextIcon className="h-3 w-3" />
|
||||
) : (
|
||||
<FileArrowDownIcon className="h-3 w-3" />
|
||||
)}
|
||||
</Button>
|
||||
|
||||
<DropdownMenu
|
||||
items={dropdownMenuItems}
|
||||
onOpenChange={setIsDropdownOpen}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
resumeCronJobAction,
|
||||
runCronJob,
|
||||
toggleCronJobLogging,
|
||||
backupCronJob,
|
||||
} from "@/app/_server/actions/cronjobs";
|
||||
import { CronJob } from "@/app/_utils/cronjob-utils";
|
||||
|
||||
@@ -68,7 +69,7 @@ export const refreshJobErrors = (
|
||||
setJobErrors(errors);
|
||||
};
|
||||
|
||||
export const handleDelete = async (id: string, props: HandlerProps) => {
|
||||
export const handleDelete = async (job: CronJob, props: HandlerProps) => {
|
||||
const {
|
||||
setDeletingId,
|
||||
setIsDeleteModalOpen,
|
||||
@@ -76,19 +77,25 @@ export const handleDelete = async (id: string, props: HandlerProps) => {
|
||||
refreshJobErrors,
|
||||
} = props;
|
||||
|
||||
setDeletingId(id);
|
||||
setDeletingId(job.id);
|
||||
try {
|
||||
const result = await removeCronJob(id);
|
||||
const result = await removeCronJob({
|
||||
id: job.id,
|
||||
schedule: job.schedule,
|
||||
command: job.command,
|
||||
comment: job.comment,
|
||||
user: job.user,
|
||||
});
|
||||
if (result.success) {
|
||||
showToast("success", "Cron job deleted successfully");
|
||||
} else {
|
||||
const errorId = `delete-${id}-${Date.now()}`;
|
||||
const errorId = `delete-${job.id}-${Date.now()}`;
|
||||
const jobError: JobError = {
|
||||
id: errorId,
|
||||
title: "Failed to delete cron job",
|
||||
message: result.message,
|
||||
timestamp: new Date().toISOString(),
|
||||
jobId: id,
|
||||
jobId: job.id,
|
||||
};
|
||||
setJobError(jobError);
|
||||
refreshJobErrors();
|
||||
@@ -106,14 +113,14 @@ export const handleDelete = async (id: string, props: HandlerProps) => {
|
||||
);
|
||||
}
|
||||
} catch (error: any) {
|
||||
const errorId = `delete-${id}-${Date.now()}`;
|
||||
const errorId = `delete-${job.id}-${Date.now()}`;
|
||||
const jobError: JobError = {
|
||||
id: errorId,
|
||||
title: "Failed to delete cron job",
|
||||
message: error.message || "Please try again later.",
|
||||
details: error.stack,
|
||||
timestamp: new Date().toISOString(),
|
||||
jobId: id,
|
||||
jobId: job.id,
|
||||
};
|
||||
setJobError(jobError);
|
||||
showToast(
|
||||
@@ -157,9 +164,15 @@ export const handleClone = async (newComment: string, props: HandlerProps) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const handlePause = async (id: string) => {
|
||||
export const handlePause = async (job: any) => {
|
||||
try {
|
||||
const result = await pauseCronJobAction(id);
|
||||
const result = await pauseCronJobAction({
|
||||
id: job.id,
|
||||
schedule: job.schedule,
|
||||
command: job.command,
|
||||
comment: job.comment,
|
||||
user: job.user,
|
||||
});
|
||||
if (result.success) {
|
||||
showToast("success", "Cron job paused successfully");
|
||||
} else {
|
||||
@@ -170,9 +183,16 @@ export const handlePause = async (id: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const handleToggleLogging = async (id: string) => {
|
||||
export const handleToggleLogging = async (job: any) => {
|
||||
try {
|
||||
const result = await toggleCronJobLogging(id);
|
||||
const result = await toggleCronJobLogging({
|
||||
id: job.id,
|
||||
schedule: job.schedule,
|
||||
command: job.command,
|
||||
comment: job.comment,
|
||||
user: job.user,
|
||||
logsEnabled: job.logsEnabled,
|
||||
});
|
||||
if (result.success) {
|
||||
showToast("success", result.message);
|
||||
} else {
|
||||
@@ -184,9 +204,15 @@ export const handleToggleLogging = async (id: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const handleResume = async (id: string) => {
|
||||
export const handleResume = async (job: any) => {
|
||||
try {
|
||||
const result = await resumeCronJobAction(id);
|
||||
const result = await resumeCronJobAction({
|
||||
id: job.id,
|
||||
schedule: job.schedule,
|
||||
command: job.command,
|
||||
comment: job.comment,
|
||||
user: job.user,
|
||||
});
|
||||
if (result.success) {
|
||||
showToast("success", "Cron job resumed successfully");
|
||||
} else {
|
||||
@@ -399,3 +425,17 @@ export const handleNewCronSubmit = async (
|
||||
showToast("error", "Failed to create cron job", "Please try again later.");
|
||||
}
|
||||
};
|
||||
|
||||
export const handleBackup = async (job: any) => {
|
||||
try {
|
||||
const result = await backupCronJob(job);
|
||||
if (result.success) {
|
||||
showToast("success", "Job backed up successfully");
|
||||
} else {
|
||||
showToast("error", "Failed to backup job", result.message);
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error("Error backing up job:", error);
|
||||
showToast("error", "Error backing up job", error.message);
|
||||
}
|
||||
};
|
||||
|
||||
431
app/_components/FeatureComponents/Games/SnakeGame.tsx
Normal file
431
app/_components/FeatureComponents/Games/SnakeGame.tsx
Normal file
@@ -0,0 +1,431 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef, useState, useCallback } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { ArrowUpIcon, ArrowDownIcon, ArrowLeftIcon, ArrowRightIcon, ArrowClockwiseIcon, PlayIcon, PauseIcon } from "@phosphor-icons/react";
|
||||
|
||||
interface Position {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
type Direction = "UP" | "DOWN" | "LEFT" | "RIGHT";
|
||||
|
||||
const GRID_SIZE = 20;
|
||||
const INITIAL_SNAKE: Position[] = [
|
||||
{ x: 10, y: 10 },
|
||||
{ x: 9, y: 10 },
|
||||
{ x: 8, y: 10 },
|
||||
];
|
||||
const INITIAL_DIRECTION: Direction = "RIGHT";
|
||||
const GAME_SPEED = 150;
|
||||
|
||||
export const SnakeGame = () => {
|
||||
const t = useTranslations("notFound");
|
||||
const canvasRef = useRef<HTMLCanvasElement>(null);
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const [snake, setSnake] = useState<Position[]>(INITIAL_SNAKE);
|
||||
const [direction, setDirection] = useState<Direction>(INITIAL_DIRECTION);
|
||||
const [food, setFood] = useState<Position>({ x: 15, y: 15 });
|
||||
const [gameOver, setGameOver] = useState(false);
|
||||
const [gameStarted, setGameStarted] = useState(false);
|
||||
const [score, setScore] = useState(0);
|
||||
const [highScore, setHighScore] = useState(0);
|
||||
const [isPaused, setIsPaused] = useState(false);
|
||||
const [colors, setColors] = useState({ snake: "#00ff00", food: "#ff0000", grid: "#333333" });
|
||||
const [cellSize, setCellSize] = useState(20);
|
||||
|
||||
const directionRef = useRef<Direction>(INITIAL_DIRECTION);
|
||||
const gameLoopRef = useRef<NodeJS.Timeout | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const savedHighScore = localStorage.getItem("snakeHighScore");
|
||||
if (savedHighScore) {
|
||||
setHighScore(parseInt(savedHighScore));
|
||||
}
|
||||
|
||||
const updateColors = () => {
|
||||
const theme = document.documentElement.getAttribute("data-webtui-theme");
|
||||
if (theme === "catppuccin-mocha") {
|
||||
setColors({
|
||||
snake: "#9ca0b0",
|
||||
food: "#f38ba8",
|
||||
grid: "#313244",
|
||||
});
|
||||
} else {
|
||||
setColors({
|
||||
snake: "#313244",
|
||||
food: "#d20f39",
|
||||
grid: "#9ca0b0",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
updateColors();
|
||||
|
||||
const observer = new MutationObserver(updateColors);
|
||||
observer.observe(document.documentElement, {
|
||||
attributes: true,
|
||||
attributeFilter: ["data-webtui-theme"],
|
||||
});
|
||||
|
||||
const updateCellSize = () => {
|
||||
if (containerRef.current) {
|
||||
const containerWidth = containerRef.current.offsetWidth;
|
||||
const maxCanvasSize = Math.min(containerWidth - 32, 400);
|
||||
const newCellSize = Math.floor(maxCanvasSize / GRID_SIZE);
|
||||
setCellSize(newCellSize);
|
||||
}
|
||||
};
|
||||
|
||||
updateCellSize();
|
||||
window.addEventListener("resize", updateCellSize);
|
||||
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
window.removeEventListener("resize", updateCellSize);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const generateFood = useCallback((): Position => {
|
||||
let newFood: Position;
|
||||
do {
|
||||
newFood = {
|
||||
x: Math.floor(Math.random() * GRID_SIZE),
|
||||
y: Math.floor(Math.random() * GRID_SIZE),
|
||||
};
|
||||
} while (snake.some((segment) => segment.x === newFood.x && segment.y === newFood.y));
|
||||
return newFood;
|
||||
}, [snake]);
|
||||
|
||||
const resetGame = useCallback(() => {
|
||||
setSnake(INITIAL_SNAKE);
|
||||
setDirection(INITIAL_DIRECTION);
|
||||
directionRef.current = INITIAL_DIRECTION;
|
||||
setFood(generateFood());
|
||||
setGameOver(false);
|
||||
setGameStarted(true);
|
||||
setScore(0);
|
||||
setIsPaused(false);
|
||||
}, [generateFood]);
|
||||
|
||||
const draw = useCallback(() => {
|
||||
const canvas = canvasRef.current;
|
||||
if (!canvas) return;
|
||||
|
||||
const ctx = canvas.getContext("2d");
|
||||
if (!ctx) return;
|
||||
|
||||
const theme = document.documentElement.getAttribute("data-webtui-theme");
|
||||
const bgColor = theme === "catppuccin-mocha" ? "#1e1e2e" : "#eff1f5";
|
||||
|
||||
ctx.fillStyle = bgColor;
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
ctx.strokeStyle = colors.grid;
|
||||
ctx.lineWidth = 1;
|
||||
for (let i = 0; i <= GRID_SIZE; i++) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(i * cellSize, 0);
|
||||
ctx.lineTo(i * cellSize, GRID_SIZE * cellSize);
|
||||
ctx.stroke();
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(0, i * cellSize);
|
||||
ctx.lineTo(GRID_SIZE * cellSize, i * cellSize);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
snake.forEach((segment) => {
|
||||
ctx.fillStyle = colors.snake;
|
||||
ctx.fillRect(
|
||||
segment.x * cellSize + 1,
|
||||
segment.y * cellSize + 1,
|
||||
cellSize - 2,
|
||||
cellSize - 2
|
||||
);
|
||||
});
|
||||
|
||||
ctx.fillStyle = colors.food;
|
||||
ctx.fillRect(
|
||||
food.x * cellSize + 1,
|
||||
food.y * cellSize + 1,
|
||||
cellSize - 2,
|
||||
cellSize - 2
|
||||
);
|
||||
}, [snake, food, colors, cellSize]);
|
||||
|
||||
useEffect(() => {
|
||||
draw();
|
||||
}, [draw]);
|
||||
|
||||
const moveSnake = useCallback(() => {
|
||||
if (gameOver || !gameStarted || isPaused) return;
|
||||
|
||||
setSnake((prevSnake) => {
|
||||
const head = prevSnake[0];
|
||||
const newHead: Position = { ...head };
|
||||
|
||||
switch (directionRef.current) {
|
||||
case "UP":
|
||||
newHead.y -= 1;
|
||||
break;
|
||||
case "DOWN":
|
||||
newHead.y += 1;
|
||||
break;
|
||||
case "LEFT":
|
||||
newHead.x -= 1;
|
||||
break;
|
||||
case "RIGHT":
|
||||
newHead.x += 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (
|
||||
newHead.x < 0 ||
|
||||
newHead.x >= GRID_SIZE ||
|
||||
newHead.y < 0 ||
|
||||
newHead.y >= GRID_SIZE ||
|
||||
prevSnake.some((segment) => segment.x === newHead.x && segment.y === newHead.y)
|
||||
) {
|
||||
setGameOver(true);
|
||||
setGameStarted(false);
|
||||
return prevSnake;
|
||||
}
|
||||
|
||||
const newSnake = [newHead, ...prevSnake];
|
||||
|
||||
if (newHead.x === food.x && newHead.y === food.y) {
|
||||
setScore((prev) => {
|
||||
const newScore = prev + 10;
|
||||
if (newScore > highScore) {
|
||||
setHighScore(newScore);
|
||||
localStorage.setItem("snakeHighScore", newScore.toString());
|
||||
}
|
||||
return newScore;
|
||||
});
|
||||
setFood(generateFood());
|
||||
} else {
|
||||
newSnake.pop();
|
||||
}
|
||||
|
||||
return newSnake;
|
||||
});
|
||||
}, [gameOver, gameStarted, isPaused, food, highScore, generateFood]);
|
||||
|
||||
useEffect(() => {
|
||||
if (gameStarted && !gameOver && !isPaused) {
|
||||
gameLoopRef.current = setInterval(moveSnake, GAME_SPEED);
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (gameLoopRef.current) {
|
||||
clearInterval(gameLoopRef.current);
|
||||
}
|
||||
};
|
||||
}, [gameStarted, gameOver, isPaused, moveSnake]);
|
||||
|
||||
useEffect(() => {
|
||||
const handleKeyPress = (e: KeyboardEvent) => {
|
||||
if (e.code === "Space") {
|
||||
e.preventDefault();
|
||||
if (gameOver) {
|
||||
resetGame();
|
||||
} else if (!gameStarted) {
|
||||
setGameStarted(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.code === "KeyP") {
|
||||
e.preventDefault();
|
||||
if (gameStarted && !gameOver) {
|
||||
setIsPaused((prev) => !prev);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!gameStarted || gameOver || isPaused) return;
|
||||
|
||||
let newDirection: Direction | null = null;
|
||||
|
||||
switch (e.key) {
|
||||
case "ArrowUp":
|
||||
if (directionRef.current !== "DOWN") {
|
||||
newDirection = "UP";
|
||||
}
|
||||
break;
|
||||
case "ArrowDown":
|
||||
if (directionRef.current !== "UP") {
|
||||
newDirection = "DOWN";
|
||||
}
|
||||
break;
|
||||
case "ArrowLeft":
|
||||
if (directionRef.current !== "RIGHT") {
|
||||
newDirection = "LEFT";
|
||||
}
|
||||
break;
|
||||
case "ArrowRight":
|
||||
if (directionRef.current !== "LEFT") {
|
||||
newDirection = "RIGHT";
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (newDirection) {
|
||||
e.preventDefault();
|
||||
directionRef.current = newDirection;
|
||||
setDirection(newDirection);
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener("keydown", handleKeyPress);
|
||||
return () => window.removeEventListener("keydown", handleKeyPress);
|
||||
}, [gameOver, gameStarted, isPaused, resetGame]);
|
||||
|
||||
const handleTouchMove = (dir: Direction) => {
|
||||
if (!gameStarted) {
|
||||
setGameStarted(true);
|
||||
directionRef.current = dir;
|
||||
setDirection(dir);
|
||||
return;
|
||||
}
|
||||
if (gameOver || isPaused) return;
|
||||
|
||||
let canMove = false;
|
||||
|
||||
switch (dir) {
|
||||
case "UP":
|
||||
canMove = directionRef.current !== "DOWN";
|
||||
break;
|
||||
case "DOWN":
|
||||
canMove = directionRef.current !== "UP";
|
||||
break;
|
||||
case "LEFT":
|
||||
canMove = directionRef.current !== "RIGHT";
|
||||
break;
|
||||
case "RIGHT":
|
||||
canMove = directionRef.current !== "LEFT";
|
||||
break;
|
||||
}
|
||||
|
||||
if (canMove) {
|
||||
directionRef.current = dir;
|
||||
setDirection(dir);
|
||||
}
|
||||
};
|
||||
|
||||
const handleCanvasClick = () => {
|
||||
if (gameOver) {
|
||||
resetGame();
|
||||
} else if (!gameStarted) {
|
||||
setGameStarted(true);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div ref={containerRef} className="flex flex-col items-center gap-4 w-full">
|
||||
<div className="tui-card p-4 w-full max-w-md">
|
||||
<div className="flex justify-between items-center mb-4 terminal-font">
|
||||
<div className="text-sm">
|
||||
<span className="text-status-success">{t("score")}:</span> {score}
|
||||
</div>
|
||||
<div className="text-sm">
|
||||
<span className="text-status-info">{t("highScore")}:</span> {highScore}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="relative">
|
||||
<canvas
|
||||
ref={canvasRef}
|
||||
width={GRID_SIZE * cellSize}
|
||||
height={GRID_SIZE * cellSize}
|
||||
className="ascii-border mx-auto cursor-pointer bg-background0"
|
||||
onClick={handleCanvasClick}
|
||||
/>
|
||||
|
||||
{!gameStarted && !gameOver && (
|
||||
<div
|
||||
className="absolute inset-0 flex items-center justify-center bg-background0 bg-opacity-90 ascii-border cursor-pointer"
|
||||
onClick={handleCanvasClick}
|
||||
>
|
||||
<div className="text-center terminal-font">
|
||||
<p className="text-lg font-bold uppercase mb-2">{t("pressToStart")}</p>
|
||||
<p className="text-xs text-foreground0 opacity-70">{t("pauseGame")}</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{gameOver && (
|
||||
<div
|
||||
className="absolute inset-0 flex items-center justify-center bg-background0 bg-opacity-90 ascii-border cursor-pointer"
|
||||
onClick={handleCanvasClick}
|
||||
>
|
||||
<div className="text-center terminal-font">
|
||||
<p className="text-2xl font-bold uppercase text-status-error mb-2">
|
||||
{t("gameOver")}
|
||||
</p>
|
||||
<p className="text-lg mb-1">
|
||||
{t("score")}: {score}
|
||||
</p>
|
||||
<p className="text-sm text-foreground0 opacity-70">{t("pressToRestart")}</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{isPaused && (
|
||||
<div className="absolute inset-0 flex items-center justify-center bg-background0 bg-opacity-90 ascii-border">
|
||||
<div className="text-center terminal-font">
|
||||
<p className="text-2xl font-bold uppercase text-status-warning">
|
||||
{t("paused")}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="mt-4 grid grid-cols-3 gap-2 md:hidden">
|
||||
<div></div>
|
||||
<button
|
||||
onClick={() => handleTouchMove("UP")}
|
||||
className="ascii-border bg-background1 p-3 active:bg-background2 terminal-font flex items-center justify-center"
|
||||
>
|
||||
<ArrowUpIcon size={20} weight="bold" />
|
||||
</button>
|
||||
<div></div>
|
||||
<button
|
||||
onClick={() => handleTouchMove("LEFT")}
|
||||
className="ascii-border bg-background1 p-3 active:bg-background2 terminal-font flex items-center justify-center"
|
||||
>
|
||||
<ArrowLeftIcon size={20} weight="bold" />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => (gameStarted && !gameOver ? setIsPaused(!isPaused) : resetGame())}
|
||||
className="ascii-border bg-background1 p-3 active:bg-background2 terminal-font flex items-center justify-center"
|
||||
>
|
||||
{gameOver ? <ArrowClockwiseIcon size={20} weight="bold" /> : isPaused ? <PlayIcon size={20} weight="fill" /> : <PauseIcon size={20} weight="fill" />}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => handleTouchMove("RIGHT")}
|
||||
className="ascii-border bg-background1 p-3 active:bg-background2 terminal-font flex items-center justify-center"
|
||||
>
|
||||
<ArrowRightIcon size={20} weight="bold" />
|
||||
</button>
|
||||
<div></div>
|
||||
<button
|
||||
onClick={() => handleTouchMove("DOWN")}
|
||||
className="ascii-border bg-background1 p-3 active:bg-background2 terminal-font flex items-center justify-center"
|
||||
>
|
||||
<ArrowDownIcon size={20} weight="bold" />
|
||||
</button>
|
||||
<div></div>
|
||||
</div>
|
||||
|
||||
<div className="mt-4 terminal-font text-xs text-center text-foreground0 opacity-70">
|
||||
<p className="hidden md:block">{t("useArrowKeys")}</p>
|
||||
<p className="md:hidden">{t("tapToMove")}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -2,15 +2,15 @@ import { cn } from "@/app/_utils/global-utils";
|
||||
import { HTMLAttributes, forwardRef, useState, useEffect } from "react";
|
||||
import React from "react";
|
||||
import {
|
||||
ChevronLeft,
|
||||
ChevronRight,
|
||||
Server,
|
||||
Menu,
|
||||
X,
|
||||
Cpu,
|
||||
HardDrive,
|
||||
Wifi,
|
||||
} from "lucide-react";
|
||||
CaretLeftIcon,
|
||||
CaretRightIcon,
|
||||
HardDrivesIcon,
|
||||
ListIcon,
|
||||
XIcon,
|
||||
CpuIcon,
|
||||
HardDriveIcon,
|
||||
WifiHighIcon,
|
||||
} from "@phosphor-icons/react";
|
||||
import { useTranslations } from "next-intl";
|
||||
|
||||
export interface SidebarProps extends HTMLAttributes<HTMLDivElement> {
|
||||
@@ -54,18 +54,18 @@ export const Sidebar = forwardRef<HTMLDivElement, SidebarProps>(
|
||||
<>
|
||||
<button
|
||||
onClick={() => setIsMobileOpen(!isMobileOpen)}
|
||||
className="fixed bottom-4 right-4 z-50 lg:hidden p-2 bg-background/80 backdrop-blur-md border border-border/50 rounded-lg hover:bg-accent transition-colors"
|
||||
className="fixed bottom-4 right-4 z-50 lg:hidden p-2 bg-background0 ascii-border transition-colors terminal-font"
|
||||
>
|
||||
{isMobileOpen ? (
|
||||
<X className="h-5 w-5" />
|
||||
<XIcon className="h-5 w-5" />
|
||||
) : (
|
||||
<Menu className="h-5 w-5" />
|
||||
<ListIcon className="h-5 w-5" />
|
||||
)}
|
||||
</button>
|
||||
|
||||
<div
|
||||
className={cn(
|
||||
"fixed inset-0 bg-black/50 z-20 lg:hidden transition-opacity duration-300",
|
||||
"fixed inset-0 bg-background0 z-20 lg:hidden transition-opacity duration-300",
|
||||
isMobileOpen ? "opacity-100" : "opacity-0 pointer-events-none"
|
||||
)}
|
||||
onClick={() => setIsMobileOpen(false)}
|
||||
@@ -74,7 +74,7 @@ export const Sidebar = forwardRef<HTMLDivElement, SidebarProps>(
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"bg-background/95 backdrop-blur-md border-r border-border/50 transition-all duration-300 ease-in-out glass-card",
|
||||
"bg-background0 ascii-border transition-all duration-300 ease-in-out terminal-font",
|
||||
isMobileOpen
|
||||
? "fixed left-0 top-0 h-full w-80 z-30 translate-x-0"
|
||||
: "fixed left-0 top-0 h-full w-80 z-30 -translate-x-full lg:translate-x-0",
|
||||
@@ -92,38 +92,20 @@ export const Sidebar = forwardRef<HTMLDivElement, SidebarProps>(
|
||||
>
|
||||
<button
|
||||
onClick={() => setIsCollapsed(!isCollapsed)}
|
||||
className="absolute -right-3 top-[21.5vh] w-6 h-6 bg-background border border-border rounded-full items-center justify-center hover:bg-accent transition-colors z-40 hidden lg:flex"
|
||||
className="absolute -right-3 top-[21.5vh] w-6 h-6 bg-background0 ascii-border items-center justify-center transition-colors z-40 hidden lg:flex"
|
||||
>
|
||||
{isCollapsed ? (
|
||||
<ChevronRight className="h-3 w-3" />
|
||||
<CaretRightIcon className="h-3 w-3" />
|
||||
) : (
|
||||
<ChevronLeft className="h-3 w-3" />
|
||||
<CaretLeftIcon className="h-3 w-3" />
|
||||
)}
|
||||
</button>
|
||||
|
||||
<div className="p-4 border-b border-border/50 bg-background/95 backdrop-blur-md">
|
||||
<div
|
||||
className={cn(
|
||||
"flex items-center gap-3",
|
||||
isCollapsed && "lg:justify-center"
|
||||
)}
|
||||
>
|
||||
<div className="p-2 bg-gradient-to-br from-cyan-500/20 to-blue-500/20 rounded-lg flex-shrink-0">
|
||||
<Server className="h-4 w-4 text-cyan-500" />
|
||||
</div>
|
||||
{(!isCollapsed || !isCollapsed) && (
|
||||
<h2 className="text-sm font-semibold text-foreground truncate">
|
||||
{t("sidebar.systemOverview")}
|
||||
</h2>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className={cn(
|
||||
"overflow-y-auto custom-scrollbar",
|
||||
"overflow-y-auto tui-scrollbar",
|
||||
isCollapsed ? "lg:p-2" : "p-4",
|
||||
"h-full lg:h-[calc(100vh-88px-80px)]"
|
||||
"h-full lg:h-[calc(100vh-88px)]"
|
||||
)}
|
||||
>
|
||||
{isCollapsed ? (
|
||||
@@ -131,22 +113,22 @@ export const Sidebar = forwardRef<HTMLDivElement, SidebarProps>(
|
||||
<div className="flex flex-col items-center space-y-4">
|
||||
{quickStats ? (
|
||||
<>
|
||||
<div className="w-12 h-12 bg-card/50 border border-border/30 rounded-lg flex flex-col items-center justify-center p-1">
|
||||
<Cpu className="h-3 w-3 text-pink-500 mb-1" />
|
||||
<div className="w-12 h-12 bg-background0 ascii-border flex flex-col items-center justify-center p-1">
|
||||
<CpuIcon className="h-3 w-3 mb-1" />
|
||||
<span className="text-xs font-bold text-foreground">
|
||||
{quickStats.cpu}%
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="w-12 h-12 bg-card/50 border border-border/30 rounded-lg flex flex-col items-center justify-center p-1">
|
||||
<HardDrive className="h-3 w-3 text-cyan-500 mb-1" />
|
||||
<div className="w-12 h-12 bg-background0 ascii-border flex flex-col items-center justify-center p-1">
|
||||
<HardDriveIcon className="h-3 w-3 mb-1" />
|
||||
<span className="text-xs font-bold text-foreground">
|
||||
{quickStats.memory}%
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="w-12 h-12 bg-card/50 border border-border/30 rounded-lg flex flex-col items-center justify-center p-1">
|
||||
<Wifi className="h-3 w-3 text-teal-500 mb-1" />
|
||||
<div className="w-12 h-12 bg-background0 ascii-border flex flex-col items-center justify-center p-1">
|
||||
<WifiHighIcon className="h-3 w-3 mb-1" />
|
||||
<div className="flex flex-col items-center">
|
||||
<span className="text-xs font-bold text-foreground leading-none">
|
||||
{quickStats.network}
|
||||
@@ -163,9 +145,9 @@ export const Sidebar = forwardRef<HTMLDivElement, SidebarProps>(
|
||||
return (
|
||||
<div
|
||||
key={index}
|
||||
className="w-8 h-8 bg-card/50 border border-border/30 rounded-lg flex items-center justify-center"
|
||||
className="w-8 h-8 bg-background2 ascii-border flex items-center justify-center"
|
||||
>
|
||||
<Server className="h-4 w-4 text-muted-foreground" />
|
||||
<HardDrivesIcon className="h-4 w-4 text-muted-foreground" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { CronJobList } from "@/app/_components/FeatureComponents/Cronjobs/CronJo
|
||||
import { ScriptsManager } from "@/app/_components/FeatureComponents/Scripts/ScriptsManager";
|
||||
import { CronJob } from "@/app/_utils/cronjob-utils";
|
||||
import { Script } from "@/app/_utils/scripts-utils";
|
||||
import { Clock, FileText } from "lucide-react";
|
||||
import { ClockIcon, FileTextIcon } from "@phosphor-icons/react";
|
||||
import { useTranslations } from "next-intl";
|
||||
|
||||
interface TabbedInterfaceProps {
|
||||
@@ -24,38 +24,38 @@ export const TabbedInterface = ({
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="bg-background/80 backdrop-blur-md border border-border/50 rounded-lg p-1 glass-card">
|
||||
<div className="flex">
|
||||
<div className="tui-card p-1 terminal-font">
|
||||
<div className="flex gap-2">
|
||||
<button
|
||||
onClick={() => setActiveTab("cronjobs")}
|
||||
className={`flex items-center gap-2 px-4 py-2 text-sm font-medium transition-all duration-200 rounded-md flex-1 justify-center ${activeTab === "cronjobs"
|
||||
? "bg-primary/10 text-primary shadow-sm border border-primary/20"
|
||||
: "text-muted-foreground hover:text-foreground hover:bg-muted/50"
|
||||
className={`flex items-center gap-2 px-4 py-2 border border-transparent text-sm font-medium flex-1 justify-center terminal-font ${activeTab === "cronjobs"
|
||||
? "bg-background0 ascii-border"
|
||||
: "hover:ascii-border"
|
||||
}`}
|
||||
>
|
||||
<Clock className="h-4 w-4" />
|
||||
<ClockIcon className="h-4 w-4" />
|
||||
{t("cronjobs.cronJobs")}
|
||||
<span className="ml-1 text-xs bg-primary/20 text-primary px-2 py-0.5 rounded-full font-medium">
|
||||
<span className="ml-1 text-xs bg-background0 px-2 py-0.5 ascii-border font-medium">
|
||||
{cronJobs.length}
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setActiveTab("scripts")}
|
||||
className={`flex items-center gap-2 px-4 py-2 text-sm font-medium transition-all duration-200 rounded-md flex-1 justify-center ${activeTab === "scripts"
|
||||
? "bg-primary/10 text-primary shadow-sm border border-primary/20"
|
||||
: "text-muted-foreground hover:text-foreground hover:bg-muted/50"
|
||||
className={`flex items-center gap-2 px-4 py-2 border border-transparent text-sm font-medium flex-1 justify-center terminal-font ${activeTab === "scripts"
|
||||
? "bg-background0 ascii-border"
|
||||
: "hover:ascii-border"
|
||||
}`}
|
||||
>
|
||||
<FileText className="h-4 w-4" />
|
||||
<FileTextIcon className="h-4 w-4" />
|
||||
{t("scripts.scripts")}
|
||||
<span className="ml-1 text-xs bg-primary/20 text-primary px-2 py-0.5 rounded-full font-medium">
|
||||
<span className="ml-1 text-xs bg-background0 px-2 py-0.5 ascii-border font-medium">
|
||||
{scripts.length}
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="min-h-[400px]">
|
||||
<div className="min-h-[60vh]">
|
||||
{activeTab === "cronjobs" ? (
|
||||
<CronJobList cronJobs={cronJobs} scripts={scripts} />
|
||||
) : (
|
||||
|
||||
@@ -1,23 +1,54 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState, useEffect } from "react";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Button } from "@/app/_components/GlobalComponents/UIElements/Button";
|
||||
import { Input } from "@/app/_components/GlobalComponents/FormElements/Input";
|
||||
import { Card, CardHeader, CardTitle, CardDescription, CardContent } from "@/app/_components/GlobalComponents/Cards/Card";
|
||||
import { Lock, Eye, EyeOff, Shield } from "lucide-react";
|
||||
import {
|
||||
Card,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
CardDescription,
|
||||
CardContent,
|
||||
} from "@/app/_components/GlobalComponents/Cards/Card";
|
||||
import { LockIcon, EyeIcon, EyeSlashIcon, ShieldIcon, WarningIcon, CircleNotchIcon } from "@phosphor-icons/react";
|
||||
|
||||
interface LoginFormProps {
|
||||
hasPassword?: boolean;
|
||||
hasOIDC?: boolean;
|
||||
oidcAutoRedirect?: boolean;
|
||||
version?: string;
|
||||
}
|
||||
|
||||
export const LoginForm = ({ hasPassword = false, hasOIDC = false }: LoginFormProps) => {
|
||||
export const LoginForm = ({
|
||||
hasPassword = false,
|
||||
hasOIDC = false,
|
||||
oidcAutoRedirect = false,
|
||||
version,
|
||||
}: LoginFormProps) => {
|
||||
const [password, setPassword] = useState("");
|
||||
const [showPassword, setShowPassword] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
const [isRedirecting, setIsRedirecting] = useState(false);
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const t = useTranslations();
|
||||
|
||||
useEffect(() => {
|
||||
const errorParam = searchParams.get("error");
|
||||
|
||||
if (errorParam) {
|
||||
setError(decodeURIComponent(errorParam));
|
||||
return;
|
||||
}
|
||||
|
||||
if (oidcAutoRedirect && !hasPassword && hasOIDC) {
|
||||
setIsRedirecting(true);
|
||||
window.location.href = "/api/oidc/login";
|
||||
}
|
||||
}, [oidcAutoRedirect, hasPassword, hasOIDC, searchParams]);
|
||||
|
||||
const handlePasswordSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
@@ -38,10 +69,10 @@ export const LoginForm = ({ hasPassword = false, hasOIDC = false }: LoginFormPro
|
||||
if (result.success) {
|
||||
router.push("/");
|
||||
} else {
|
||||
setError(result.message || "Login failed");
|
||||
setError(result.message || t("login.loginFailed"));
|
||||
}
|
||||
} catch (error) {
|
||||
setError("An error occurred. Please try again.");
|
||||
setError(t("login.genericError"));
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
@@ -52,23 +83,55 @@ export const LoginForm = ({ hasPassword = false, hasOIDC = false }: LoginFormPro
|
||||
window.location.href = "/api/oidc/login";
|
||||
};
|
||||
|
||||
if (isRedirecting) {
|
||||
return (
|
||||
<Card className="w-full max-w-md shadow-xl">
|
||||
<CardContent className="pt-6">
|
||||
<div className="flex flex-col items-center justify-center py-8 space-y-4">
|
||||
<CircleNotchIcon className="w-12 h-12 text-primary animate-spin" />
|
||||
<div className="text-center">
|
||||
<p className="text-lg font-medium">{t("login.redirectingToOIDC")}</p>
|
||||
<p className="text-sm text-muted-foreground mt-1">
|
||||
{t("login.pleaseWait")}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Card className="w-full max-w-md shadow-xl">
|
||||
<CardHeader className="text-center">
|
||||
<div className="mx-auto w-16 h-16 bg-primary/10 rounded-full flex items-center justify-center mb-4">
|
||||
<Lock className="w-8 h-8 text-primary" />
|
||||
<LockIcon className="w-8 h-8 text-primary" />
|
||||
</div>
|
||||
<CardTitle>Welcome to Cr*nMaster</CardTitle>
|
||||
<CardTitle>{t("login.welcomeTitle")}</CardTitle>
|
||||
<CardDescription>
|
||||
{hasPassword && hasOIDC
|
||||
? "Sign in with password or SSO"
|
||||
? t("login.signInWithPasswordOrSSO")
|
||||
: hasOIDC
|
||||
? "Sign in with SSO"
|
||||
: "Enter your password to continue"}
|
||||
? t("login.signInWithSSO")
|
||||
: t("login.enterPasswordToContinue")}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent>
|
||||
{!hasPassword && !hasOIDC && (
|
||||
<div className="mb-4 p-3 bg-amber-500/10 border border-amber-500/20 rounded-md">
|
||||
<div className="flex items-start space-x-2">
|
||||
<WarningIcon className="w-4 h-4 text-amber-500 mt-0.5 flex-shrink-0" />
|
||||
<div className="text-sm text-amber-700 dark:text-amber-400">
|
||||
<div className="font-medium">
|
||||
{t("login.authenticationNotConfigured")}
|
||||
</div>
|
||||
<div className="mt-1">{t("login.noAuthMethodsEnabled")}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="space-y-4">
|
||||
{hasPassword && (
|
||||
<form onSubmit={handlePasswordSubmit} className="space-y-4">
|
||||
@@ -77,7 +140,7 @@ export const LoginForm = ({ hasPassword = false, hasOIDC = false }: LoginFormPro
|
||||
type={showPassword ? "text" : "password"}
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
placeholder="Enter password"
|
||||
placeholder={t("login.enterPassword")}
|
||||
className="pr-10"
|
||||
required
|
||||
disabled={isLoading}
|
||||
@@ -89,9 +152,9 @@ export const LoginForm = ({ hasPassword = false, hasOIDC = false }: LoginFormPro
|
||||
disabled={isLoading}
|
||||
>
|
||||
{showPassword ? (
|
||||
<EyeOff className="w-4 h-4" />
|
||||
<EyeSlashIcon className="w-4 h-4" />
|
||||
) : (
|
||||
<Eye className="w-4 h-4" />
|
||||
<EyeIcon className="w-4 h-4" />
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
@@ -101,7 +164,7 @@ export const LoginForm = ({ hasPassword = false, hasOIDC = false }: LoginFormPro
|
||||
className="w-full"
|
||||
disabled={isLoading || !password.trim()}
|
||||
>
|
||||
{isLoading ? "Signing in..." : "Sign In"}
|
||||
{isLoading ? t("login.signingIn") : t("login.signIn")}
|
||||
</Button>
|
||||
</form>
|
||||
)}
|
||||
@@ -112,8 +175,8 @@ export const LoginForm = ({ hasPassword = false, hasOIDC = false }: LoginFormPro
|
||||
<span className="w-full border-t" />
|
||||
</div>
|
||||
<div className="relative flex justify-center text-xs uppercase">
|
||||
<span className="bg-background px-2 text-muted-foreground">
|
||||
Or continue with
|
||||
<span className="bg-background0 px-2 text-muted-foreground">
|
||||
{t("login.orContinueWith")}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -127,8 +190,8 @@ export const LoginForm = ({ hasPassword = false, hasOIDC = false }: LoginFormPro
|
||||
onClick={handleOIDCLogin}
|
||||
disabled={isLoading}
|
||||
>
|
||||
<Shield className="w-4 h-4 mr-2" />
|
||||
{isLoading ? "Redirecting..." : "Sign in with SSO"}
|
||||
<ShieldIcon className="w-4 h-4 mr-2" />
|
||||
{isLoading ? t("login.redirecting") : t("login.signInWithSSO")}
|
||||
</Button>
|
||||
)}
|
||||
|
||||
@@ -138,6 +201,14 @@ export const LoginForm = ({ hasPassword = false, hasOIDC = false }: LoginFormPro
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{version && (
|
||||
<div className="mt-6 pt-4 border-t border-border">
|
||||
<div className="text-center text-xs text-muted-foreground">
|
||||
Cr*nMaster {t("common.version", { version })}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
|
||||
@@ -3,41 +3,40 @@
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Button } from "@/app/_components/GlobalComponents/UIElements/Button";
|
||||
import { LogOut } from "lucide-react";
|
||||
|
||||
import { SignOutIcon } from "@phosphor-icons/react";
|
||||
|
||||
export const LogoutButton = () => {
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const router = useRouter();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const router = useRouter();
|
||||
|
||||
const handleLogout = async () => {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
const response = await fetch("/api/auth/logout", {
|
||||
method: "POST",
|
||||
});
|
||||
const handleLogout = async () => {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
const response = await fetch("/api/auth/logout", {
|
||||
method: "POST",
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
router.push("/login");
|
||||
router.refresh();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Logout error:", error);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
if (response.ok) {
|
||||
router.push("/login");
|
||||
router.refresh();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Logout error:", error);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={handleLogout}
|
||||
disabled={isLoading}
|
||||
title="Logout"
|
||||
>
|
||||
<LogOut className="h-[1.2rem] w-[1.2rem]" />
|
||||
<span className="sr-only">Logout</span>
|
||||
</Button>
|
||||
);
|
||||
return (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={handleLogout}
|
||||
disabled={isLoading}
|
||||
title="Logout"
|
||||
>
|
||||
<SignOutIcon className="h-[1.2rem] w-[1.2rem]" />
|
||||
<span className="sr-only">Logout</span>
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Copy } from "lucide-react";
|
||||
import { CopyIcon } from "@phosphor-icons/react";
|
||||
import { Button } from "@/app/_components/GlobalComponents/UIElements/Button";
|
||||
import { Modal } from "@/app/_components/GlobalComponents/UIElements/Modal";
|
||||
import { Input } from "@/app/_components/GlobalComponents/FormElements/Input";
|
||||
@@ -89,7 +89,7 @@ export const CloneScriptModal = ({
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Copy className="h-4 w-4 mr-2" />
|
||||
<CopyIcon className="h-4 w-4 mr-2" />
|
||||
Clone Script
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Copy } from "lucide-react";
|
||||
import { CopyIcon } from "@phosphor-icons/react";
|
||||
import { Button } from "@/app/_components/GlobalComponents/UIElements/Button";
|
||||
import { Modal } from "@/app/_components/GlobalComponents/UIElements/Modal";
|
||||
import { Input } from "@/app/_components/GlobalComponents/FormElements/Input";
|
||||
@@ -89,7 +89,7 @@ export const CloneTaskModal = ({
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Copy className="h-4 w-4 mr-2" />
|
||||
<CopyIcon className="h-4 w-4 mr-2" />
|
||||
Clone Cron Job
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { Plus } from "lucide-react";
|
||||
import { PlusIcon } from "@phosphor-icons/react";
|
||||
import { ScriptModal } from "@/app/_components/FeatureComponents/Modals/ScriptModal";
|
||||
|
||||
interface CreateScriptModalProps {
|
||||
@@ -15,6 +15,8 @@ interface CreateScriptModalProps {
|
||||
content: string;
|
||||
};
|
||||
onFormChange: (updates: Partial<CreateScriptModalProps["form"]>) => void;
|
||||
isDraft?: boolean;
|
||||
onClearDraft?: () => void;
|
||||
}
|
||||
|
||||
export const CreateScriptModal = ({
|
||||
@@ -23,6 +25,8 @@ export const CreateScriptModal = ({
|
||||
onSubmit,
|
||||
form,
|
||||
onFormChange,
|
||||
isDraft,
|
||||
onClearDraft,
|
||||
}: CreateScriptModalProps) => {
|
||||
return (
|
||||
<ScriptModal
|
||||
@@ -31,9 +35,11 @@ export const CreateScriptModal = ({
|
||||
onSubmit={onSubmit}
|
||||
title="Create New Script"
|
||||
submitButtonText="Create Script"
|
||||
submitButtonIcon={<Plus className="h-4 w-4 mr-2" />}
|
||||
submitButtonIcon={<PlusIcon className="h-4 w-4 mr-2" />}
|
||||
form={form}
|
||||
onFormChange={onFormChange}
|
||||
isDraft={isDraft}
|
||||
onClearDraft={onClearDraft}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,10 +4,11 @@ import { useState, useEffect } from "react";
|
||||
import { Modal } from "@/app/_components/GlobalComponents/UIElements/Modal";
|
||||
import { Button } from "@/app/_components/GlobalComponents/UIElements/Button";
|
||||
import { Input } from "@/app/_components/GlobalComponents/FormElements/Input";
|
||||
import { Switch } from "@/app/_components/GlobalComponents/UIElements/Switch";
|
||||
import { CronExpressionHelper } from "@/app/_components/FeatureComponents/Scripts/CronExpressionHelper";
|
||||
import { SelectScriptModal } from "@/app/_components/FeatureComponents/Modals/SelectScriptModal";
|
||||
import { UserSwitcher } from "@/app/_components/FeatureComponents/User/UserSwitcher";
|
||||
import { Plus, Terminal, FileText, X, FileOutput } from "lucide-react";
|
||||
import { PlusIcon, TerminalIcon, FileTextIcon, XIcon, FileArrowDownIcon } from "@phosphor-icons/react";
|
||||
import { getScriptContent } from "@/app/_server/actions/scripts";
|
||||
import { getHostScriptPath } from "@/app/_server/actions/scripts";
|
||||
import { useTranslations } from "next-intl";
|
||||
@@ -64,9 +65,10 @@ export const CreateTaskModal = ({
|
||||
}, [selectedScript]);
|
||||
|
||||
const handleScriptSelect = async (script: Script) => {
|
||||
const scriptPath = await getHostScriptPath(script.filename);
|
||||
onFormChange({
|
||||
selectedScriptId: script.id,
|
||||
command: await getHostScriptPath(script.filename),
|
||||
command: scriptPath,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -99,7 +101,7 @@ export const CreateTaskModal = ({
|
||||
</label>
|
||||
<UserSwitcher
|
||||
selectedUser={form.user}
|
||||
onUserChange={(user) => onFormChange({ user })}
|
||||
onUserChange={(user: string) => onFormChange({ user })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -123,14 +125,13 @@ export const CreateTaskModal = ({
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleCustomCommand}
|
||||
className={`p-4 rounded-lg border-2 transition-all ${
|
||||
!form.selectedScriptId
|
||||
? "border-primary bg-primary/5 text-primary"
|
||||
: "border-border bg-muted/30 text-muted-foreground hover:border-border/60"
|
||||
}`}
|
||||
className={`p-4 rounded-lg transition-all ${!form.selectedScriptId
|
||||
? "border-border border-2"
|
||||
: "border-border border"
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
<Terminal className="h-5 w-5" />
|
||||
<TerminalIcon className="h-5 w-5" />
|
||||
<div className="text-left">
|
||||
<div className="font-medium">
|
||||
{t("cronjobs.customCommand")}
|
||||
@@ -145,14 +146,13 @@ export const CreateTaskModal = ({
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setIsSelectScriptModalOpen(true)}
|
||||
className={`p-4 rounded-lg border-2 transition-all ${
|
||||
form.selectedScriptId
|
||||
? "border-primary bg-primary/5 text-primary"
|
||||
: "border-border bg-muted/30 text-muted-foreground hover:border-border/60"
|
||||
}`}
|
||||
className={`p-4 rounded-lg transition-all ${form.selectedScriptId
|
||||
? "border-border border-2"
|
||||
: "border-border border"
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
<FileText className="h-5 w-5" />
|
||||
<FileTextIcon className="h-5 w-5" />
|
||||
<div className="text-left">
|
||||
<div className="font-medium">
|
||||
{t("scripts.savedScript")}
|
||||
@@ -171,7 +171,7 @@ export const CreateTaskModal = ({
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="flex-1">
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<FileText className="h-4 w-4 text-primary" />
|
||||
<FileTextIcon className="h-4 w-4 text-primary" />
|
||||
<h4 className="font-medium text-foreground">
|
||||
{selectedScript.name}
|
||||
</h4>
|
||||
@@ -179,7 +179,7 @@ export const CreateTaskModal = ({
|
||||
<p className="text-sm text-muted-foreground mb-2">
|
||||
{selectedScript.description}
|
||||
</p>
|
||||
<div className="bg-muted/30 p-2 rounded border border-border/30">
|
||||
<div className="bg-muted/30 p-2 rounded border border-border">
|
||||
<code className="text-xs font-mono text-foreground break-all">
|
||||
{form.command}
|
||||
</code>
|
||||
@@ -202,7 +202,7 @@ export const CreateTaskModal = ({
|
||||
onClick={handleClearScript}
|
||||
className="h-8 w-8 p-0 text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
<XIcon className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -223,12 +223,12 @@ export const CreateTaskModal = ({
|
||||
? "/app/scripts/script_name.sh"
|
||||
: "/usr/bin/command"
|
||||
}
|
||||
className="w-full h-24 p-2 border border-border rounded bg-background text-foreground font-mono text-sm resize-none focus:outline-none focus:ring-1 focus:ring-primary/20"
|
||||
className="w-full h-24 p-2 border border-border rounded bg-background0 text-foreground font-mono text-sm resize-none focus:outline-none focus:ring-1 focus:ring-primary/20"
|
||||
required
|
||||
readOnly={!!form.selectedScriptId}
|
||||
/>
|
||||
<div className="absolute right-3 top-2">
|
||||
<Terminal className="h-4 w-4 text-muted-foreground" />
|
||||
<TerminalIcon className="h-4 w-4 text-muted-foreground" />
|
||||
</div>
|
||||
</div>
|
||||
{form.selectedScriptId && (
|
||||
@@ -250,29 +250,28 @@ export const CreateTaskModal = ({
|
||||
value={form.comment}
|
||||
onChange={(e) => onFormChange({ comment: e.target.value })}
|
||||
placeholder={t("cronjobs.whatDoesThisTaskDo")}
|
||||
className="bg-muted/30 border-border/50 focus:border-primary/50"
|
||||
className="bg-muted/30 border-border focus:border-primary/50"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="border border-border/30 bg-muted/10 rounded-lg p-4">
|
||||
<div className="flex items-start gap-3">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="logsEnabled"
|
||||
|
||||
<div className="border border-border bg-muted/10 rounded-lg p-4">
|
||||
<div
|
||||
className="flex items-start gap-3 cursor-pointer"
|
||||
onClick={() => onFormChange({ logsEnabled: !form.logsEnabled })}
|
||||
>
|
||||
<Switch
|
||||
checked={form.logsEnabled}
|
||||
onChange={(e) =>
|
||||
onFormChange({ logsEnabled: e.target.checked })
|
||||
onCheckedChange={(checked) =>
|
||||
onFormChange({ logsEnabled: checked })
|
||||
}
|
||||
className="mt-1 h-4 w-4 rounded border-border text-primary focus:ring-primary/20 cursor-pointer"
|
||||
className="mt-1"
|
||||
/>
|
||||
<div className="flex-1">
|
||||
<label
|
||||
htmlFor="logsEnabled"
|
||||
className="flex items-center gap-2 text-sm font-medium text-foreground cursor-pointer"
|
||||
>
|
||||
<FileOutput className="h-4 w-4 text-primary" />
|
||||
<div className="flex items-center gap-2 text-sm font-medium text-foreground">
|
||||
<FileArrowDownIcon className="h-4 w-4 text-primary" />
|
||||
{t("cronjobs.enableLogging")}
|
||||
</label>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
{t("cronjobs.loggingDescription")}
|
||||
</p>
|
||||
@@ -280,7 +279,8 @@ export const CreateTaskModal = ({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-2 pt-3 border-t border-border/50">
|
||||
|
||||
<div className="flex justify-end gap-2 pt-3 border-t border-border">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
@@ -290,7 +290,7 @@ export const CreateTaskModal = ({
|
||||
{t("common.cancel")}
|
||||
</Button>
|
||||
<Button type="submit" className="btn-primary glow-primary">
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
<PlusIcon className="h-4 w-4 mr-2" />
|
||||
{t("cronjobs.createTask")}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { Modal } from "@/app/_components/GlobalComponents/UIElements/Modal";
|
||||
import { Button } from "@/app/_components/GlobalComponents/UIElements/Button";
|
||||
import { FileText, AlertCircle, Trash2 } from "lucide-react";
|
||||
import { FileTextIcon, WarningCircleIcon, TrashIcon } from "@phosphor-icons/react";
|
||||
import { Script } from "@/app/_utils/scripts-utils";
|
||||
|
||||
interface DeleteScriptModalProps {
|
||||
@@ -25,10 +25,10 @@ export const DeleteScriptModal = ({
|
||||
return (
|
||||
<Modal isOpen={isOpen} onClose={onClose} title="Delete Script" size="sm">
|
||||
<div className="space-y-3">
|
||||
<div className="bg-muted/30 rounded p-2 border border-border/50">
|
||||
<div className="bg-muted/30 rounded p-2 border border-border">
|
||||
<div className="space-y-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<FileText className="h-3 w-3 text-muted-foreground" />
|
||||
<FileTextIcon className="h-3 w-3 text-muted-foreground" />
|
||||
<span className="text-xs font-medium text-foreground">
|
||||
{script.name}
|
||||
</span>
|
||||
@@ -36,7 +36,7 @@ export const DeleteScriptModal = ({
|
||||
|
||||
{script.description && (
|
||||
<div className="flex items-start gap-2">
|
||||
<FileText className="h-3 w-3 text-muted-foreground mt-0.5 flex-shrink-0" />
|
||||
<FileTextIcon className="h-3 w-3 text-muted-foreground mt-0.5 flex-shrink-0" />
|
||||
<p className="text-xs text-muted-foreground break-words italic">
|
||||
{script.description}
|
||||
</p>
|
||||
@@ -44,8 +44,8 @@ export const DeleteScriptModal = ({
|
||||
)}
|
||||
|
||||
<div className="flex items-start gap-2">
|
||||
<FileText className="h-3 w-3 text-muted-foreground mt-0.5 flex-shrink-0" />
|
||||
<code className="text-xs font-mono bg-muted/30 px-1 py-0.5 rounded border border-border/30">
|
||||
<FileTextIcon className="h-3 w-3 text-muted-foreground mt-0.5 flex-shrink-0" />
|
||||
<code className="text-xs font-mono bg-muted/30 px-1 py-0.5 rounded border border-border">
|
||||
{script.filename}
|
||||
</code>
|
||||
</div>
|
||||
@@ -54,7 +54,7 @@ export const DeleteScriptModal = ({
|
||||
|
||||
<div className="bg-destructive/5 border border-destructive/20 rounded p-2">
|
||||
<div className="flex items-start gap-2">
|
||||
<AlertCircle className="h-4 w-4 text-destructive mt-0.5 flex-shrink-0" />
|
||||
<WarningCircleIcon className="h-4 w-4 text-destructive mt-0.5 flex-shrink-0" />
|
||||
<div>
|
||||
<p className="text-xs font-medium text-destructive mb-0.5">
|
||||
This action cannot be undone
|
||||
@@ -66,7 +66,7 @@ export const DeleteScriptModal = ({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-2 pt-2 border-t border-border/50">
|
||||
<div className="flex justify-end gap-2 pt-2 border-t border-border">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={onClose}
|
||||
@@ -78,7 +78,6 @@ export const DeleteScriptModal = ({
|
||||
<Button
|
||||
variant="destructive"
|
||||
onClick={onConfirm}
|
||||
className="btn-destructive"
|
||||
disabled={isDeleting}
|
||||
>
|
||||
{isDeleting ? (
|
||||
@@ -88,7 +87,7 @@ export const DeleteScriptModal = ({
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Trash2 className="h-4 w-4 mr-2" />
|
||||
<TrashIcon className="h-4 w-4 mr-2" />
|
||||
Delete Script
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -4,11 +4,11 @@ import { Modal } from "@/app/_components/GlobalComponents/UIElements/Modal";
|
||||
import { Button } from "@/app/_components/GlobalComponents/UIElements/Button";
|
||||
import {
|
||||
Calendar,
|
||||
Terminal,
|
||||
MessageSquare,
|
||||
AlertCircle,
|
||||
Trash2,
|
||||
} from "lucide-react";
|
||||
TerminalIcon,
|
||||
ChatTextIcon,
|
||||
WarningCircleIcon,
|
||||
TrashIcon,
|
||||
} from "@phosphor-icons/react";
|
||||
import { CronJob } from "@/app/_utils/cronjob-utils";
|
||||
|
||||
interface DeleteTaskModalProps {
|
||||
@@ -34,7 +34,7 @@ export const DeleteTaskModal = ({
|
||||
size="sm"
|
||||
>
|
||||
<div className="space-y-3">
|
||||
<div className="bg-muted/30 rounded p-2 border border-border/50">
|
||||
<div className="bg-muted/30 rounded p-2 border border-border">
|
||||
<div className="space-y-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<Calendar className="h-3 w-3 text-muted-foreground" />
|
||||
@@ -44,15 +44,15 @@ export const DeleteTaskModal = ({
|
||||
</div>
|
||||
|
||||
<div className="flex items-start gap-2">
|
||||
<Terminal className="h-3 w-3 text-muted-foreground mt-0.5 flex-shrink-0" />
|
||||
<pre className="text-xs font-medium text-foreground break-words bg-muted/30 px-1 py-0.5 rounded border border-border/30 flex-1">
|
||||
<TerminalIcon className="h-3 w-3 text-muted-foreground mt-0.5 flex-shrink-0" />
|
||||
<pre className="max-w-full overflow-x-auto text-xs font-medium text-foreground break-words bg-muted/30 px-1 py-0.5 rounded border border-border flex-1 hide-scrollbar">
|
||||
{job.command}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
{job.comment && (
|
||||
<div className="flex items-start gap-2">
|
||||
<MessageSquare className="h-3 w-3 text-muted-foreground mt-0.5 flex-shrink-0" />
|
||||
<ChatTextIcon className="h-3 w-3 text-muted-foreground mt-0.5 flex-shrink-0" />
|
||||
<p className="text-xs text-muted-foreground break-words italic">
|
||||
{job.comment}
|
||||
</p>
|
||||
@@ -63,7 +63,7 @@ export const DeleteTaskModal = ({
|
||||
|
||||
<div className="bg-destructive/5 border border-destructive/20 rounded p-2">
|
||||
<div className="flex items-start gap-2">
|
||||
<AlertCircle className="h-4 w-4 text-destructive mt-0.5 flex-shrink-0" />
|
||||
<WarningCircleIcon className="h-4 w-4 text-destructive mt-0.5 flex-shrink-0" />
|
||||
<div>
|
||||
<p className="text-xs font-medium text-destructive mb-0.5">
|
||||
This action cannot be undone
|
||||
@@ -75,20 +75,19 @@ export const DeleteTaskModal = ({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-2 pt-2 border-t border-border/50">
|
||||
<div className="flex justify-end gap-2 pt-2 border-t border-border">
|
||||
<Button variant="outline" onClick={onClose} className="btn-outline">
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
onClick={onConfirm}
|
||||
className="btn-destructive"
|
||||
>
|
||||
<Trash2 className="h-4 w-4 mr-2" />
|
||||
<TrashIcon className="h-4 w-4 mr-2" />
|
||||
Delete Task
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { Edit } from "lucide-react";
|
||||
import { PencilSimpleIcon } from "@phosphor-icons/react";
|
||||
import { Script } from "@/app/_utils/scripts-utils";
|
||||
import { ScriptModal } from "@/app/_components/FeatureComponents/Modals/ScriptModal";
|
||||
|
||||
@@ -36,7 +36,7 @@ export const EditScriptModal = ({
|
||||
onSubmit={onSubmit}
|
||||
title="Edit Script"
|
||||
submitButtonText="Update Script"
|
||||
submitButtonIcon={<Edit className="h-4 w-4 mr-2" />}
|
||||
submitButtonIcon={<PencilSimpleIcon className="h-4 w-4 mr-2" />}
|
||||
form={form}
|
||||
onFormChange={onFormChange}
|
||||
additionalFormData={{ id: script.id }}
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
import { Modal } from "@/app/_components/GlobalComponents/UIElements/Modal";
|
||||
import { Button } from "@/app/_components/GlobalComponents/UIElements/Button";
|
||||
import { Input } from "@/app/_components/GlobalComponents/FormElements/Input";
|
||||
import { Switch } from "@/app/_components/GlobalComponents/UIElements/Switch";
|
||||
import { CronExpressionHelper } from "@/app/_components/FeatureComponents/Scripts/CronExpressionHelper";
|
||||
import { Edit, Terminal, FileOutput } from "lucide-react";
|
||||
import { PencilSimpleIcon, TerminalIcon, FileArrowDownIcon } from "@phosphor-icons/react";
|
||||
import { useTranslations } from "next-intl";
|
||||
|
||||
interface EditTaskModalProps {
|
||||
@@ -59,11 +60,11 @@ export const EditTaskModal = ({
|
||||
value={form.command}
|
||||
onChange={(e) => onFormChange({ command: e.target.value })}
|
||||
placeholder="/usr/bin/command"
|
||||
className="font-mono bg-muted/30 border-border/50 focus:border-primary/50"
|
||||
className="font-mono bg-muted/30 border-border focus:border-primary/50"
|
||||
required
|
||||
/>
|
||||
<div className="absolute right-3 top-1/2 -translate-y-1/2">
|
||||
<Terminal className="h-4 w-4 text-muted-foreground" />
|
||||
<TerminalIcon className="h-4 w-4 text-muted-foreground" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -80,27 +81,26 @@ export const EditTaskModal = ({
|
||||
value={form.comment}
|
||||
onChange={(e) => onFormChange({ comment: e.target.value })}
|
||||
placeholder={t("cronjobs.whatDoesThisTaskDo")}
|
||||
className="bg-muted/30 border-border/50 focus:border-primary/50"
|
||||
className="bg-muted/30 border-border focus:border-primary/50"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="border border-border/30 bg-muted/10 rounded-lg p-4">
|
||||
<div className="flex items-start gap-3">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="logsEnabled"
|
||||
|
||||
<div className="border border-border bg-muted/10 rounded-lg p-4">
|
||||
<div
|
||||
className="flex items-start gap-3 cursor-pointer"
|
||||
onClick={() => onFormChange({ logsEnabled: !form.logsEnabled })}
|
||||
>
|
||||
<Switch
|
||||
checked={form.logsEnabled}
|
||||
onChange={(e) => onFormChange({ logsEnabled: e.target.checked })}
|
||||
className="mt-1 h-4 w-4 rounded border-border text-primary focus:ring-primary/20 cursor-pointer"
|
||||
onCheckedChange={(checked) => onFormChange({ logsEnabled: checked })}
|
||||
className="mt-1"
|
||||
/>
|
||||
<div className="flex-1">
|
||||
<label
|
||||
htmlFor="logsEnabled"
|
||||
className="flex items-center gap-2 text-sm font-medium text-foreground cursor-pointer"
|
||||
>
|
||||
<FileOutput className="h-4 w-4 text-primary" />
|
||||
<div className="flex items-center gap-2 text-sm font-medium text-foreground">
|
||||
<FileArrowDownIcon className="h-4 w-4 text-primary" />
|
||||
{t("cronjobs.enableLogging")}
|
||||
</label>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
{t("cronjobs.loggingDescription")}
|
||||
</p>
|
||||
@@ -108,7 +108,8 @@ export const EditTaskModal = ({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-2 pt-3 border-t border-border/50">
|
||||
|
||||
<div className="flex justify-end gap-2 pt-3 border-t border-border">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
@@ -118,7 +119,7 @@ export const EditTaskModal = ({
|
||||
Cancel
|
||||
</Button>
|
||||
<Button type="submit" className="btn-primary glow-primary">
|
||||
<Edit className="h-4 w-4 mr-2" />
|
||||
<PencilSimpleIcon className="h-4 w-4 mr-2" />
|
||||
Update Task
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { Modal } from "@/app/_components/GlobalComponents/UIElements/Modal";
|
||||
import { Button } from "@/app/_components/GlobalComponents/UIElements/Button";
|
||||
import { AlertCircle, Copy, X } from "lucide-react";
|
||||
import { WarningCircleIcon, CopyIcon, XIcon } from "@phosphor-icons/react";
|
||||
import { showToast } from "@/app/_components/GlobalComponents/UIElements/Toast";
|
||||
|
||||
interface ErrorDetails {
|
||||
@@ -54,7 +54,7 @@ Timestamp: ${error.timestamp}
|
||||
<div className="space-y-4">
|
||||
<div className="bg-destructive/5 border border-destructive/20 rounded-lg p-4">
|
||||
<div className="flex items-start gap-3">
|
||||
<AlertCircle className="h-5 w-5 text-destructive mt-0.5 flex-shrink-0" />
|
||||
<WarningCircleIcon className="h-5 w-5 text-destructive mt-0.5 flex-shrink-0" />
|
||||
<div className="flex-1">
|
||||
<h3 className="font-medium text-destructive mb-1">
|
||||
{error.title}
|
||||
@@ -69,7 +69,7 @@ Timestamp: ${error.timestamp}
|
||||
<h4 className="text-sm font-medium text-foreground mb-2">
|
||||
Details
|
||||
</h4>
|
||||
<div className="bg-muted/30 p-3 rounded border border-border/30">
|
||||
<div className="bg-muted/30 p-3 rounded border border-border">
|
||||
<pre className="text-sm font-mono text-foreground whitespace-pre-wrap break-words">
|
||||
{error.details}
|
||||
</pre>
|
||||
@@ -82,7 +82,7 @@ Timestamp: ${error.timestamp}
|
||||
<h4 className="text-sm font-medium text-foreground mb-2">
|
||||
Command
|
||||
</h4>
|
||||
<div className="bg-muted/30 p-3 rounded border border-border/30">
|
||||
<div className="bg-muted/30 p-3 rounded border border-border">
|
||||
<code className="text-sm font-mono text-foreground break-all">
|
||||
{error.command}
|
||||
</code>
|
||||
@@ -93,7 +93,7 @@ Timestamp: ${error.timestamp}
|
||||
{error.output && (
|
||||
<div>
|
||||
<h4 className="text-sm font-medium text-foreground mb-2">Output</h4>
|
||||
<div className="bg-muted/30 p-3 rounded border border-border/30 max-h-32 overflow-y-auto">
|
||||
<div className="bg-muted/30 p-3 rounded border border-border max-h-32 overflow-y-auto tui-scrollbar">
|
||||
<pre className="text-sm font-mono text-foreground whitespace-pre-wrap">
|
||||
{error.output}
|
||||
</pre>
|
||||
@@ -106,7 +106,7 @@ Timestamp: ${error.timestamp}
|
||||
<h4 className="text-sm font-medium text-foreground mb-2">
|
||||
Error Output
|
||||
</h4>
|
||||
<div className="bg-destructive/5 p-3 rounded border border-destructive/20 max-h-32 overflow-y-auto">
|
||||
<div className="bg-destructive/5 p-3 rounded border border-destructive/20 max-h-32 overflow-y-auto tui-scrollbar">
|
||||
<pre className="text-sm font-mono text-destructive whitespace-pre-wrap">
|
||||
{error.stderr}
|
||||
</pre>
|
||||
@@ -118,14 +118,14 @@ Timestamp: ${error.timestamp}
|
||||
Timestamp: {error.timestamp}
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-2 pt-3 border-t border-border/50">
|
||||
<div className="flex justify-end gap-2 pt-3 border-t border-border">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={handleCopyDetails}
|
||||
className="btn-outline"
|
||||
>
|
||||
<Copy className="h-4 w-4 mr-2" />
|
||||
Copy Details
|
||||
<CopyIcon className="h-4 w-4 mr-2" />
|
||||
CopyIcon Details
|
||||
</Button>
|
||||
<Button onClick={onClose} className="btn-primary">
|
||||
Close
|
||||
|
||||
155
app/_components/FeatureComponents/Modals/FiltersModal.tsx
Normal file
155
app/_components/FeatureComponents/Modals/FiltersModal.tsx
Normal file
@@ -0,0 +1,155 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { Modal } from "@/app/_components/GlobalComponents/UIElements/Modal";
|
||||
import { Button } from "@/app/_components/GlobalComponents/UIElements/Button";
|
||||
import { CaretDownIcon, CodeIcon, ChatTextIcon } from "@phosphor-icons/react";
|
||||
import { UserFilter } from "@/app/_components/FeatureComponents/User/UserFilter";
|
||||
import { useTranslations } from "next-intl";
|
||||
|
||||
interface FiltersModalProps {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
selectedUser: string | null;
|
||||
onUserChange: (user: string | null) => void;
|
||||
scheduleDisplayMode: "cron" | "human" | "both";
|
||||
onScheduleDisplayModeChange: (mode: "cron" | "human" | "both") => void;
|
||||
}
|
||||
|
||||
export const FiltersModal = ({
|
||||
isOpen,
|
||||
onClose,
|
||||
selectedUser,
|
||||
onUserChange,
|
||||
scheduleDisplayMode,
|
||||
onScheduleDisplayModeChange,
|
||||
}: FiltersModalProps) => {
|
||||
const t = useTranslations();
|
||||
const [localScheduleMode, setLocalScheduleMode] =
|
||||
useState(scheduleDisplayMode);
|
||||
const [isScheduleDropdownOpen, setIsScheduleDropdownOpen] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setLocalScheduleMode(scheduleDisplayMode);
|
||||
}, [scheduleDisplayMode]);
|
||||
|
||||
const handleSave = () => {
|
||||
onScheduleDisplayModeChange(localScheduleMode);
|
||||
onClose();
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
isOpen={isOpen}
|
||||
onClose={onClose}
|
||||
title={t("cronjobs.filtersAndDisplay")}
|
||||
size="md"
|
||||
>
|
||||
<div className="space-y-6">
|
||||
<div className="space-y-4 min-h-[200px]">
|
||||
<div>
|
||||
<label className="text-sm font-medium text-foreground mb-2 block">
|
||||
{t("cronjobs.filterByUser")}
|
||||
</label>
|
||||
<UserFilter
|
||||
selectedUser={selectedUser}
|
||||
onUserChange={onUserChange}
|
||||
className="w-full"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="text-sm font-medium text-foreground mb-2 block">
|
||||
{t("cronjobs.scheduleDisplay")}
|
||||
</label>
|
||||
<div className="relative">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() =>
|
||||
setIsScheduleDropdownOpen(!isScheduleDropdownOpen)
|
||||
}
|
||||
className="btn-outline w-full justify-between"
|
||||
>
|
||||
<div className="flex items-center">
|
||||
{localScheduleMode === "cron" && (
|
||||
<CodeIcon className="h-4 w-4 mr-2" />
|
||||
)}
|
||||
{localScheduleMode === "human" && (
|
||||
<ChatTextIcon className="h-4 w-4 mr-2" />
|
||||
)}
|
||||
{localScheduleMode === "both" && (
|
||||
<>
|
||||
<CodeIcon className="h-4 w-4 mr-1" />
|
||||
<ChatTextIcon className="h-4 w-4 mr-2" />
|
||||
</>
|
||||
)}
|
||||
<span>
|
||||
{localScheduleMode === "cron" && t("cronjobs.cronSyntax")}
|
||||
{localScheduleMode === "human" &&
|
||||
t("cronjobs.humanReadable")}
|
||||
{localScheduleMode === "both" && t("cronjobs.both")}
|
||||
</span>
|
||||
</div>
|
||||
<CaretDownIcon className="h-4 w-4 ml-2" />
|
||||
</Button>
|
||||
|
||||
{isScheduleDropdownOpen && (
|
||||
<div className="absolute top-full left-0 p-1 right-0 mt-1 bg-background0 border border-border rounded-md shadow-lg z-50 min-w-[140px]">
|
||||
<button
|
||||
onClick={() => {
|
||||
setLocalScheduleMode("cron");
|
||||
setIsScheduleDropdownOpen(false);
|
||||
}}
|
||||
className={`w-full text-left px-3 border py-2 text-sm hover:border-border border-transparent transition-colors flex items-center gap-2 ${localScheduleMode === "cron"
|
||||
? "border-border"
|
||||
: ""
|
||||
}`}
|
||||
>
|
||||
<CodeIcon className="h-3 w-3" />
|
||||
{t("cronjobs.cronSyntax")}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => {
|
||||
setLocalScheduleMode("human");
|
||||
setIsScheduleDropdownOpen(false);
|
||||
}}
|
||||
className={`w-full text-left px-3 py-2 border text-sm hover:border-border border-transparent transition-colors flex items-center gap-2 ${localScheduleMode === "human"
|
||||
? "border-border"
|
||||
: ""
|
||||
}`}
|
||||
>
|
||||
<ChatTextIcon className="h-3 w-3" />
|
||||
{t("cronjobs.humanReadable")}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => {
|
||||
setLocalScheduleMode("both");
|
||||
setIsScheduleDropdownOpen(false);
|
||||
}}
|
||||
className={`w-full text-left px-3 py-2 border text-sm hover:border-border border-transparent transition-colors flex items-center gap-2 ${localScheduleMode === "both"
|
||||
? "border-border"
|
||||
: ""
|
||||
}`}
|
||||
>
|
||||
<CodeIcon className="h-3 w-3" />
|
||||
<ChatTextIcon className="h-3 w-3" />
|
||||
{t("cronjobs.both")}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-2 pt-4">
|
||||
<Button variant="outline" onClick={onClose}>
|
||||
{t("common.cancel")}
|
||||
</Button>
|
||||
<Button className="btn-primary" onClick={handleSave}>
|
||||
{t("cronjobs.applyFilters")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
@@ -1,10 +1,13 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect, useRef } from "react";
|
||||
import { Loader2, CheckCircle2, XCircle } from "lucide-react";
|
||||
import { useState, useEffect, useRef, useCallback } from "react";
|
||||
import { CircleNotchIcon, CheckCircleIcon, XCircleIcon, WarningIcon, ArrowsInIcon, ArrowsOutIcon } from "@phosphor-icons/react";
|
||||
import { Modal } from "@/app/_components/GlobalComponents/UIElements/Modal";
|
||||
import { Button } from "@/app/_components/GlobalComponents/UIElements/Button";
|
||||
import { useSSEContext } from "@/app/_contexts/SSEContext";
|
||||
import { SSEEvent } from "@/app/_utils/sse-events";
|
||||
import { usePageVisibility } from "@/app/_hooks/usePageVisibility";
|
||||
import { useTranslations } from "next-intl";
|
||||
|
||||
interface LiveLogModalProps {
|
||||
isOpen: boolean;
|
||||
@@ -14,6 +17,9 @@ interface LiveLogModalProps {
|
||||
jobComment?: string;
|
||||
}
|
||||
|
||||
const MAX_LINES_FULL_RENDER = 10000;
|
||||
const TAIL_LINES = 5000;
|
||||
|
||||
export const LiveLogModal = ({
|
||||
isOpen,
|
||||
onClose,
|
||||
@@ -21,40 +27,136 @@ export const LiveLogModal = ({
|
||||
jobId,
|
||||
jobComment,
|
||||
}: LiveLogModalProps) => {
|
||||
const t = useTranslations();
|
||||
const [logContent, setLogContent] = useState<string>("");
|
||||
const [status, setStatus] = useState<"running" | "completed" | "failed">("running");
|
||||
const [status, setStatus] = useState<"running" | "completed" | "failed">(
|
||||
"running"
|
||||
);
|
||||
const [exitCode, setExitCode] = useState<number | null>(null);
|
||||
const [tailMode, setTailMode] = useState<boolean>(false);
|
||||
const [showSizeWarning, setShowSizeWarning] = useState<boolean>(false);
|
||||
const logEndRef = useRef<HTMLDivElement>(null);
|
||||
const { subscribe } = useSSEContext();
|
||||
const isPageVisible = usePageVisibility();
|
||||
const lastOffsetRef = useRef<number>(0);
|
||||
const abortControllerRef = useRef<AbortController | null>(null);
|
||||
const [fileSize, setFileSize] = useState<number>(0);
|
||||
const [lineCount, setLineCount] = useState<number>(0);
|
||||
const [maxLines, setMaxLines] = useState<number>(500);
|
||||
const [totalLines, setTotalLines] = useState<number>(0);
|
||||
const [truncated, setTruncated] = useState<boolean>(false);
|
||||
const [showFullLog, setShowFullLog] = useState<boolean>(false);
|
||||
const [isJobComplete, setIsJobComplete] = useState<boolean>(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen || !runId) return;
|
||||
if (isOpen) {
|
||||
lastOffsetRef.current = 0;
|
||||
setLogContent("");
|
||||
setTailMode(false);
|
||||
setShowSizeWarning(false);
|
||||
setFileSize(0);
|
||||
setLineCount(0);
|
||||
setShowFullLog(false);
|
||||
setIsJobComplete(false);
|
||||
}
|
||||
}, [isOpen, runId]);
|
||||
|
||||
const fetchLogs = async () => {
|
||||
try {
|
||||
const response = await fetch(`/api/logs/stream?runId=${runId}`);
|
||||
const data = await response.json();
|
||||
useEffect(() => {
|
||||
if (isOpen && runId && !isJobComplete) {
|
||||
lastOffsetRef.current = 0;
|
||||
setLogContent("");
|
||||
fetchLogs();
|
||||
}
|
||||
}, [maxLines]);
|
||||
|
||||
if (data.content) {
|
||||
setLogContent(data.content);
|
||||
const fetchLogs = useCallback(async () => {
|
||||
if (abortControllerRef.current) {
|
||||
abortControllerRef.current.abort();
|
||||
}
|
||||
|
||||
const abortController = new AbortController();
|
||||
abortControllerRef.current = abortController;
|
||||
|
||||
try {
|
||||
const url = `/api/logs/stream?runId=${runId}&offset=${lastOffsetRef.current}&maxLines=${maxLines}`;
|
||||
const response = await fetch(url, {
|
||||
signal: abortController.signal,
|
||||
});
|
||||
const data = await response.json();
|
||||
|
||||
if (data.fileSize !== undefined) {
|
||||
lastOffsetRef.current = data.fileSize;
|
||||
setFileSize(data.fileSize);
|
||||
|
||||
if (data.fileSize > 10 * 1024 * 1024) {
|
||||
setShowSizeWarning(true);
|
||||
}
|
||||
}
|
||||
|
||||
setStatus(data.status || "running");
|
||||
if (data.totalLines !== undefined) {
|
||||
setTotalLines(data.totalLines);
|
||||
}
|
||||
setLineCount(data.displayedLines || 0);
|
||||
|
||||
if (data.exitCode !== undefined) {
|
||||
setExitCode(data.exitCode);
|
||||
if (data.truncated !== undefined) {
|
||||
setTruncated(data.truncated);
|
||||
}
|
||||
|
||||
if (lastOffsetRef.current === 0 && data.content) {
|
||||
setLogContent(data.content);
|
||||
|
||||
if (data.truncated) {
|
||||
setTailMode(true);
|
||||
}
|
||||
} catch (error) {
|
||||
} else if (data.newContent) {
|
||||
setLogContent((prev) => {
|
||||
const combined = prev + data.newContent;
|
||||
const lines = combined.split("\n");
|
||||
|
||||
if (lines.length > maxLines) {
|
||||
return lines.slice(-maxLines).join("\n");
|
||||
}
|
||||
|
||||
return combined;
|
||||
});
|
||||
}
|
||||
|
||||
const jobStatus = data.status || "running";
|
||||
setStatus(jobStatus);
|
||||
|
||||
if (jobStatus === "completed" || jobStatus === "failed") {
|
||||
setIsJobComplete(true);
|
||||
}
|
||||
|
||||
if (data.exitCode !== undefined) {
|
||||
setExitCode(data.exitCode);
|
||||
}
|
||||
} catch (error: any) {
|
||||
if (error.name !== "AbortError") {
|
||||
console.error("Failed to fetch logs:", error);
|
||||
}
|
||||
};
|
||||
}
|
||||
}, [runId, maxLines]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen || !runId || !isPageVisible) return;
|
||||
|
||||
fetchLogs();
|
||||
|
||||
const interval = setInterval(fetchLogs, 2000);
|
||||
let interval: NodeJS.Timeout | null = null;
|
||||
if (isPageVisible && !isJobComplete) {
|
||||
interval = setInterval(fetchLogs, 3000);
|
||||
}
|
||||
|
||||
return () => clearInterval(interval);
|
||||
}, [isOpen, runId]);
|
||||
return () => {
|
||||
if (interval) {
|
||||
clearInterval(interval);
|
||||
}
|
||||
if (abortControllerRef.current) {
|
||||
abortControllerRef.current.abort();
|
||||
}
|
||||
};
|
||||
}, [isOpen, runId, isPageVisible, fetchLogs, isJobComplete]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen) return;
|
||||
@@ -64,53 +166,83 @@ export const LiveLogModal = ({
|
||||
setStatus("completed");
|
||||
setExitCode(event.data.exitCode);
|
||||
|
||||
fetch(`/api/logs/stream?runId=${runId}`)
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
fetch(`/api/logs/stream?runId=${runId}&offset=0`)
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
if (data.content) {
|
||||
setLogContent(data.content);
|
||||
const lines = data.content.split("\n");
|
||||
setLineCount(lines.length);
|
||||
if (tailMode && lines.length > TAIL_LINES) {
|
||||
setLogContent(lines.slice(-TAIL_LINES).join("\n"));
|
||||
} else {
|
||||
setLogContent(data.content);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if (event.type === "job-failed" && event.data.runId === runId) {
|
||||
setStatus("failed");
|
||||
setExitCode(event.data.exitCode);
|
||||
|
||||
fetch(`/api/logs/stream?runId=${runId}`)
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
fetch(`/api/logs/stream?runId=${runId}&offset=0`)
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
if (data.content) {
|
||||
setLogContent(data.content);
|
||||
const lines = data.content.split("\n");
|
||||
setLineCount(lines.length);
|
||||
if (tailMode && lines.length > TAIL_LINES) {
|
||||
setLogContent(lines.slice(-TAIL_LINES).join("\n"));
|
||||
} else {
|
||||
setLogContent(data.content);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return unsubscribe;
|
||||
}, [isOpen, runId, subscribe]);
|
||||
}, [isOpen, runId, subscribe, tailMode]);
|
||||
|
||||
useEffect(() => {
|
||||
logEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
||||
if (logEndRef.current) {
|
||||
logEndRef.current.scrollIntoView({ behavior: "instant" });
|
||||
}
|
||||
}, [logContent]);
|
||||
|
||||
const toggleTailMode = () => {
|
||||
setTailMode(!tailMode);
|
||||
if (!tailMode) {
|
||||
const lines = logContent.split("\n");
|
||||
if (lines.length > TAIL_LINES) {
|
||||
setLogContent(lines.slice(-TAIL_LINES).join("\n"));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const formatFileSize = (bytes: number): string => {
|
||||
if (bytes < 1024) return `${bytes} B`;
|
||||
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
||||
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
||||
};
|
||||
|
||||
const titleWithStatus = (
|
||||
<div className="flex items-center gap-3">
|
||||
<span>Live Job Execution{jobComment && `: ${jobComment}`}</span>
|
||||
<span>{t("cronjobs.liveJobExecution")}{jobComment && `: ${jobComment}`}</span>
|
||||
{status === "running" && (
|
||||
<span className="flex items-center gap-1 text-sm text-blue-500">
|
||||
<Loader2 className="w-4 h-4 animate-spin" />
|
||||
Running...
|
||||
<span className="flex items-center gap-1 text-sm text-status-info">
|
||||
<CircleNotchIcon className="w-4 h-4 animate-spin" />
|
||||
{t("cronjobs.running")}
|
||||
</span>
|
||||
)}
|
||||
{status === "completed" && (
|
||||
<span className="flex items-center gap-1 text-sm text-green-500">
|
||||
<CheckCircle2 className="w-4 h-4" />
|
||||
Completed (Exit: {exitCode})
|
||||
<span className="flex items-center gap-1 text-sm text-status-success">
|
||||
<CheckCircleIcon className="w-4 h-4" />
|
||||
{t("cronjobs.completed", { exitCode: exitCode ?? 0 })}
|
||||
</span>
|
||||
)}
|
||||
{status === "failed" && (
|
||||
<span className="flex items-center gap-1 text-sm text-red-500">
|
||||
<XCircle className="w-4 h-4" />
|
||||
Failed (Exit: {exitCode})
|
||||
<span className="flex items-center gap-1 text-sm text-status-error">
|
||||
<XCircleIcon className="w-4 h-4" />
|
||||
{t("cronjobs.jobFailed", { exitCode: exitCode ?? 1 })}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
@@ -125,15 +257,108 @@ export const LiveLogModal = ({
|
||||
preventCloseOnClickOutside={status === "running"}
|
||||
>
|
||||
<div className="space-y-4">
|
||||
<div className="bg-black/90 dark:bg-black/60 rounded-lg p-4 max-h-[60vh] overflow-auto">
|
||||
<pre className="text-xs font-mono text-green-400 whitespace-pre-wrap break-words">
|
||||
{logContent || "Waiting for job to start...\n\nLogs will appear here in real-time."}
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
<div className="flex items-center gap-3">
|
||||
{!showFullLog ? (
|
||||
<>
|
||||
<label htmlFor="maxLines" className="text-sm text-muted-foreground">
|
||||
{t("cronjobs.showLast")}
|
||||
</label>
|
||||
<select
|
||||
id="maxLines"
|
||||
value={maxLines}
|
||||
onChange={(e) => setMaxLines(parseInt(e.target.value, 10))}
|
||||
className="bg-background0 border border-border rounded px-2 py-1 text-sm"
|
||||
>
|
||||
<option value="100">{t("cronjobs.nLines", { count: "100" })}</option>
|
||||
<option value="500">{t("cronjobs.nLines", { count: "500" })}</option>
|
||||
<option value="1000">{t("cronjobs.nLines", { count: "1,000" })}</option>
|
||||
<option value="2000">{t("cronjobs.nLines", { count: "2,000" })}</option>
|
||||
<option value="5000">{t("cronjobs.nLines", { count: "5,000" })}</option>
|
||||
</select>
|
||||
{truncated && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
setShowFullLog(true);
|
||||
setMaxLines(50000);
|
||||
}}
|
||||
className="text-xs"
|
||||
>
|
||||
{totalLines > 0
|
||||
? t("cronjobs.viewFullLog", { totalLines: totalLines.toLocaleString() })
|
||||
: t("cronjobs.viewFullLogNoCount")}
|
||||
</Button>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{totalLines > 0
|
||||
? t("cronjobs.viewingFullLog", { totalLines: totalLines.toLocaleString() })
|
||||
: t("cronjobs.viewingFullLogNoCount")}
|
||||
</span>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
setShowFullLog(false);
|
||||
setMaxLines(500);
|
||||
}}
|
||||
className="text-xs"
|
||||
>
|
||||
{t("cronjobs.backToWindowedView")}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{truncated && !showFullLog && (
|
||||
<div className="text-sm text-status-warning flex items-center gap-1 terminal-font">
|
||||
<WarningIcon className="h-4 w-4" />
|
||||
{t("cronjobs.showingLastOf", {
|
||||
lineCount: lineCount.toLocaleString(),
|
||||
totalLines: totalLines.toLocaleString()
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{showSizeWarning && (
|
||||
<div className="bg-background2 ascii-border p-3 flex items-start gap-3 terminal-font">
|
||||
<WarningIcon className="h-4 w-4 text-status-warning mt-0.5 flex-shrink-0" />
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-sm text-foreground">
|
||||
<span className="font-medium">{t("cronjobs.largeLogFileDetected")}</span> ({formatFileSize(fileSize)})
|
||||
{tailMode && ` - ${t("cronjobs.tailModeEnabled", { tailLines: TAIL_LINES.toLocaleString() })}`}
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={toggleTailMode}
|
||||
className="text-status-warning hover:text-status-warning hover:bg-background2 h-auto py-1 px-2 text-xs"
|
||||
title={tailMode ? t("cronjobs.showAllLines") : t("cronjobs.enableTailMode")}
|
||||
>
|
||||
{tailMode ? <ArrowsOutIcon className="h-3 w-3" /> : <ArrowsInIcon className="h-3 w-3" />}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="bg-background0 p-4 max-h-[60vh] overflow-auto terminal-font ascii-border">
|
||||
<pre className="text-xs text-status-success whitespace-pre-wrap break-words">
|
||||
{logContent || t("cronjobs.waitingForJobToStart")}
|
||||
<div ref={logEndRef} />
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<div className="text-xs text-muted-foreground">
|
||||
Run ID: {runId} | Job ID: {jobId}
|
||||
<div className="flex justify-between items-center text-xs text-muted-foreground">
|
||||
<span>
|
||||
{t("cronjobs.runIdJobId", { runId, jobId })}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { Modal } from "@/app/_components/GlobalComponents/UIElements/Modal";
|
||||
import { Button } from "@/app/_components/GlobalComponents/UIElements/Button";
|
||||
import { FileText, Trash2, Eye, X, RefreshCw, AlertCircle, CheckCircle } from "lucide-react";
|
||||
import { FileTextIcon, TrashIcon, EyeIcon, XIcon, ArrowsClockwiseIcon, WarningCircleIcon, CheckCircleIcon } from "@phosphor-icons/react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import {
|
||||
getJobLogs,
|
||||
@@ -173,7 +173,7 @@ export const LogsModal = ({
|
||||
className="btn-primary glow-primary"
|
||||
size="sm"
|
||||
>
|
||||
<RefreshCw
|
||||
<ArrowsClockwiseIcon
|
||||
className={`w-4 h-4 mr-2 ${isLoadingLogs ? "animate-spin" : ""
|
||||
}`}
|
||||
/>
|
||||
@@ -182,10 +182,10 @@ export const LogsModal = ({
|
||||
{logs.length > 0 && (
|
||||
<Button
|
||||
onClick={handleDeleteAllLogs}
|
||||
className="btn-destructive glow-primary"
|
||||
variant="destructive"
|
||||
size="sm"
|
||||
>
|
||||
<Trash2 className="w-4 h-4 mr-2" />
|
||||
<TrashIcon className="w-4 h-4 mr-2" />
|
||||
{t("cronjobs.deleteAll")}
|
||||
</Button>
|
||||
)}
|
||||
@@ -208,11 +208,11 @@ export const LogsModal = ({
|
||||
logs.map((log) => (
|
||||
<div
|
||||
key={log.filename}
|
||||
className={`p-3 rounded border cursor-pointer transition-colors ${selectedLog === log.filename
|
||||
? "border-primary bg-primary/10"
|
||||
className={`p-3 ascii-border cursor-pointer transition-colors terminal-font ${selectedLog === log.filename
|
||||
? "border-primary bg-background2"
|
||||
: log.hasError
|
||||
? "border-red-500/50 hover:border-red-500"
|
||||
: "border-border hover:border-primary/50"
|
||||
? "border-red-600 hover:border-red-600"
|
||||
: "ascii-border hover:border-primary"
|
||||
}`}
|
||||
onClick={() => handleViewLog(log.filename)}
|
||||
>
|
||||
@@ -220,11 +220,11 @@ export const LogsModal = ({
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
{log.hasError ? (
|
||||
<AlertCircle className="w-4 h-4 flex-shrink-0 text-red-500" />
|
||||
<WarningCircleIcon className="w-4 h-4 flex-shrink-0 text-status-error" />
|
||||
) : log.exitCode === 0 ? (
|
||||
<CheckCircle className="w-4 h-4 flex-shrink-0 text-green-500" />
|
||||
<CheckCircleIcon className="w-4 h-4 flex-shrink-0 text-status-success" />
|
||||
) : (
|
||||
<FileText className="w-4 h-4 flex-shrink-0" />
|
||||
<FileTextIcon className="w-4 h-4 flex-shrink-0" />
|
||||
)}
|
||||
<span className="text-sm font-medium truncate">
|
||||
{formatTimestamp(log.timestamp)}
|
||||
@@ -236,9 +236,9 @@ export const LogsModal = ({
|
||||
</p>
|
||||
{log.exitCode !== undefined && (
|
||||
<span
|
||||
className={`text-xs px-1.5 py-0.5 rounded ${log.hasError
|
||||
? "bg-red-500/10 text-red-600 dark:text-red-400"
|
||||
: "bg-green-500/10 text-green-600 dark:text-green-400"
|
||||
className={`text-xs px-1.5 py-0.5 ${log.hasError
|
||||
? "bg-background2 text-status-error"
|
||||
: "bg-background2 text-status-success"
|
||||
}`}
|
||||
>
|
||||
Exit: {log.exitCode}
|
||||
@@ -251,10 +251,10 @@ export const LogsModal = ({
|
||||
e.stopPropagation();
|
||||
handleDeleteLog(log.filename);
|
||||
}}
|
||||
className="btn-destructive glow-primary p-1 h-auto"
|
||||
variant="destructive"
|
||||
size="sm"
|
||||
>
|
||||
<Trash2 className="w-3 h-3" />
|
||||
<TrashIcon className="w-3 h-3" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -271,13 +271,13 @@ export const LogsModal = ({
|
||||
{t("common.loading")}...
|
||||
</div>
|
||||
) : selectedLog ? (
|
||||
<pre className="h-full overflow-auto bg-muted/50 p-4 rounded border border-border text-xs font-mono whitespace-pre-wrap">
|
||||
<pre className="h-full overflow-auto bg-background0 tui-scrollbar p-4 ascii-border text-xs font-mono whitespace-pre-wrap terminal-font">
|
||||
{logContent}
|
||||
</pre>
|
||||
) : (
|
||||
<div className="h-full flex items-center justify-center text-muted-foreground">
|
||||
<div className="text-center">
|
||||
<Eye className="w-12 h-12 mx-auto mb-2 opacity-50" />
|
||||
<EyeIcon className="w-12 h-12 mx-auto mb-2 opacity-50" />
|
||||
<p>{t("cronjobs.selectLogToView")}</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -288,7 +288,7 @@ export const LogsModal = ({
|
||||
|
||||
<div className="mt-4 pt-4 border-t border-border flex justify-end">
|
||||
<Button onClick={onClose} className="btn-primary glow-primary">
|
||||
<X className="w-4 h-4 mr-2" />
|
||||
<XIcon className="w-4 h-4 mr-2" />
|
||||
{t("common.close")}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
286
app/_components/FeatureComponents/Modals/RestoreBackupModal.tsx
Normal file
286
app/_components/FeatureComponents/Modals/RestoreBackupModal.tsx
Normal file
@@ -0,0 +1,286 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { Modal } from "@/app/_components/GlobalComponents/UIElements/Modal";
|
||||
import { Button } from "@/app/_components/GlobalComponents/UIElements/Button";
|
||||
import {
|
||||
UploadIcon,
|
||||
TrashIcon,
|
||||
CalendarIcon,
|
||||
UserIcon,
|
||||
DownloadIcon,
|
||||
ArrowsClockwiseIcon,
|
||||
CheckIcon,
|
||||
} from "@phosphor-icons/react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { CronJob } from "@/app/_utils/cronjob-utils";
|
||||
import { unwrapCommand } from "@/app/_utils/wrapper-utils-client";
|
||||
import { copyToClipboard } from "@/app/_utils/global-utils";
|
||||
|
||||
interface BackupFile {
|
||||
filename: string;
|
||||
job: CronJob;
|
||||
backedUpAt: string;
|
||||
}
|
||||
|
||||
interface RestoreBackupModalProps {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
backups: BackupFile[];
|
||||
onRestore: (filename: string) => void;
|
||||
onRestoreAll: () => void;
|
||||
onBackupAll: () => void;
|
||||
onDelete: (filename: string) => void;
|
||||
onRefresh: () => void;
|
||||
}
|
||||
|
||||
export const RestoreBackupModal = ({
|
||||
isOpen,
|
||||
onClose,
|
||||
backups,
|
||||
onRestore,
|
||||
onRestoreAll,
|
||||
onBackupAll,
|
||||
onDelete,
|
||||
onRefresh,
|
||||
}: RestoreBackupModalProps) => {
|
||||
const t = useTranslations();
|
||||
const [deletingFilename, setDeletingFilename] = useState<string | null>(null);
|
||||
const [commandCopied, setCommandCopied] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (isOpen) {
|
||||
onRefresh();
|
||||
}
|
||||
}, [isOpen]);
|
||||
|
||||
const handleRestoreAll = () => {
|
||||
if (window.confirm(t("cronjobs.confirmRestoreAll"))) {
|
||||
onRestoreAll();
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = async (filename: string) => {
|
||||
if (window.confirm(t("cronjobs.confirmDeleteBackup"))) {
|
||||
setDeletingFilename(filename);
|
||||
await onDelete(filename);
|
||||
setDeletingFilename(null);
|
||||
onRefresh();
|
||||
}
|
||||
};
|
||||
|
||||
const formatDate = (dateString: string) => {
|
||||
try {
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleString();
|
||||
} catch {
|
||||
return dateString;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
isOpen={isOpen}
|
||||
onClose={onClose}
|
||||
title={t("cronjobs.backups")}
|
||||
size="xl"
|
||||
>
|
||||
<div className="space-y-4">
|
||||
<div className="flex flex-col sm:flex-row gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={onBackupAll}
|
||||
className="btn-outline flex-1"
|
||||
>
|
||||
<DownloadIcon className="h-4 w-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">{t("cronjobs.backupAll")}</span>
|
||||
<span className="sm:hidden">Backup</span>
|
||||
</Button>
|
||||
{backups.length > 0 && (
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={handleRestoreAll}
|
||||
className="btn-primary flex-1"
|
||||
>
|
||||
<UploadIcon className="h-4 w-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">{t("cronjobs.restoreAll")}</span>
|
||||
<span className="sm:hidden">Restore</span>
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={onRefresh}
|
||||
className="btn-outline sm:w-auto"
|
||||
title={t("common.refresh")}
|
||||
>
|
||||
<ArrowsClockwiseIcon className="h-4 w-4" />
|
||||
<span className="sm:hidden ml-2">Refresh</span>
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{backups.length === 0 ? (
|
||||
<div className="text-center py-8 text-muted-foreground">
|
||||
<p>{t("cronjobs.noBackupsFound")}</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-3 max-h-[500px] overflow-y-auto tui-scrollbar pr-2 pb-2">
|
||||
{backups.map((backup) => (
|
||||
<div
|
||||
key={backup.filename}
|
||||
className="tui-card p-3 terminal-font"
|
||||
>
|
||||
<div className="flex flex-col gap-3 lg:hidden">
|
||||
<div className="flex items-center justify-between">
|
||||
<code className="text-xs bg-background0 text-status-warning px-1.5 py-0.5 terminal-font ascii-border">
|
||||
{backup.job.schedule}
|
||||
</code>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
onRestore(backup.filename);
|
||||
onClose();
|
||||
}}
|
||||
className="btn-outline h-8 px-3"
|
||||
title={t("cronjobs.restoreThisBackup")}
|
||||
>
|
||||
<UploadIcon className="h-3 w-3" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
size="sm"
|
||||
onClick={() => handleDelete(backup.filename)}
|
||||
disabled={deletingFilename === backup.filename}
|
||||
className="h-8 px-3"
|
||||
title={t("cronjobs.deleteBackup")}
|
||||
>
|
||||
{deletingFilename === backup.filename ? (
|
||||
<div className="h-3 w-3 animate-spin rounded-full border-2 border-current border-t-transparent" />
|
||||
) : (
|
||||
<TrashIcon className="h-3 w-3" />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
{commandCopied === backup.filename && (
|
||||
<CheckIcon className="h-3 w-3 text-status-success flex-shrink-0" />
|
||||
)}
|
||||
<pre
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
copyToClipboard(unwrapCommand(backup.job.command));
|
||||
setCommandCopied(backup.filename);
|
||||
setTimeout(() => setCommandCopied(null), 3000);
|
||||
}}
|
||||
className="max-w-full overflow-x-auto flex-1 cursor-pointer text-sm font-medium terminal-font bg-background1 px-2 py-1 ascii-border break-all"
|
||||
title={unwrapCommand(backup.job.command)}
|
||||
>
|
||||
{unwrapCommand(backup.job.command)}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-3 text-xs text-muted-foreground">
|
||||
<div className="flex items-center gap-1">
|
||||
<UserIcon className="h-3 w-3" />
|
||||
<span>{backup.job.user}</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
<CalendarIcon className="h-3 w-3" />
|
||||
<span>{formatDate(backup.backedUpAt)}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="hidden lg:flex items-center gap-3">
|
||||
<div className="flex-shrink-0">
|
||||
<code className="text-xs bg-background0 text-status-warning px-1.5 py-0.5 terminal-font ascii-border">
|
||||
{backup.job.schedule}
|
||||
</code>
|
||||
</div>
|
||||
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2">
|
||||
{commandCopied === backup.filename && (
|
||||
<CheckIcon className="h-3 w-3 text-status-success flex-shrink-0" />
|
||||
)}
|
||||
<pre
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
copyToClipboard(unwrapCommand(backup.job.command));
|
||||
setCommandCopied(backup.filename);
|
||||
setTimeout(() => setCommandCopied(null), 3000);
|
||||
}}
|
||||
className="flex-1 cursor-pointer overflow-hidden text-sm font-medium terminal-font bg-background1 px-2 py-1 ascii-border truncate"
|
||||
title={unwrapCommand(backup.job.command)}
|
||||
>
|
||||
{unwrapCommand(backup.job.command)}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-3 text-xs text-muted-foreground flex-shrink-0">
|
||||
<div className="flex items-center gap-1">
|
||||
<UserIcon className="h-3 w-3" />
|
||||
<span>{backup.job.user}</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
<CalendarIcon className="h-3 w-3" />
|
||||
<span>{formatDate(backup.backedUpAt)}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2 flex-shrink-0">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
onRestore(backup.filename);
|
||||
onClose();
|
||||
}}
|
||||
className="btn-outline h-8 px-3"
|
||||
title={t("cronjobs.restoreThisBackup")}
|
||||
>
|
||||
<UploadIcon className="h-3 w-3" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
size="sm"
|
||||
onClick={() => handleDelete(backup.filename)}
|
||||
disabled={deletingFilename === backup.filename}
|
||||
className="h-8 px-3"
|
||||
title={t("cronjobs.deleteBackup")}
|
||||
>
|
||||
{deletingFilename === backup.filename ? (
|
||||
<div className="h-3 w-3 animate-spin rounded-full border-2 border-current border-t-transparent" />
|
||||
) : (
|
||||
<TrashIcon className="h-3 w-3" />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{backup.job.comment && (
|
||||
<p className="text-xs text-muted-foreground italic mt-2">
|
||||
{backup.job.comment}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex flex-col sm:flex-row sm:justify-between gap-2 pt-4 border-t border-border">
|
||||
<p className="text-sm text-muted-foreground text-center sm:text-left">
|
||||
{t("cronjobs.availableBackups")}: {backups.length}
|
||||
</p>
|
||||
<Button variant="outline" onClick={onClose} className="btn-outline w-full sm:w-auto">
|
||||
{t("common.close")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
@@ -6,7 +6,8 @@ import { Input } from "@/app/_components/GlobalComponents/FormElements/Input";
|
||||
import { BashEditor } from "@/app/_components/FeatureComponents/Scripts/BashEditor";
|
||||
import { BashSnippetHelper } from "@/app/_components/FeatureComponents/Scripts/BashSnippetHelper";
|
||||
import { showToast } from "@/app/_components/GlobalComponents/UIElements/Toast";
|
||||
import { FileText, Code } from "lucide-react";
|
||||
import { FileTextIcon, CodeIcon, InfoIcon, TrashIcon } from "@phosphor-icons/react";
|
||||
import { useTranslations } from "next-intl";
|
||||
|
||||
interface ScriptModalProps {
|
||||
isOpen: boolean;
|
||||
@@ -24,6 +25,8 @@ interface ScriptModalProps {
|
||||
};
|
||||
onFormChange: (updates: Partial<ScriptModalProps["form"]>) => void;
|
||||
additionalFormData?: Record<string, string>;
|
||||
isDraft?: boolean;
|
||||
onClearDraft?: () => void;
|
||||
}
|
||||
|
||||
export const ScriptModal = ({
|
||||
@@ -36,7 +39,11 @@ export const ScriptModal = ({
|
||||
form,
|
||||
onFormChange,
|
||||
additionalFormData = {},
|
||||
isDraft = false,
|
||||
onClearDraft,
|
||||
}: ScriptModalProps) => {
|
||||
const t = useTranslations();
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
|
||||
@@ -72,12 +79,12 @@ export const ScriptModal = ({
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal isOpen={isOpen} onClose={onClose} title={title} size="xl">
|
||||
<form onSubmit={handleSubmit} className="space-y-6">
|
||||
<Modal isOpen={isOpen} onClose={onClose} title={title} size="2xl">
|
||||
<form onSubmit={handleSubmit} className="space-y-6 terminal-font">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-foreground mb-2">
|
||||
Script Name <span className="text-red-500">*</span>
|
||||
<label className="block text-sm font-medium mb-2">
|
||||
Script Name <span className="text-status-error">*</span>
|
||||
</label>
|
||||
<Input
|
||||
value={form.name}
|
||||
@@ -86,15 +93,15 @@ export const ScriptModal = ({
|
||||
required
|
||||
className={
|
||||
!form.name.trim()
|
||||
? "border-red-300 focus:border-red-500 focus:ring-red-500"
|
||||
? "border-status-error focus:border-status-error"
|
||||
: ""
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-foreground mb-2">
|
||||
<label className="block text-sm font-medium mb-2">
|
||||
Description{" "}
|
||||
<span className="text-muted-foreground text-xs">(optional)</span>
|
||||
<span className="text-xs opacity-60">(optional)</span>
|
||||
</label>
|
||||
<Input
|
||||
value={form.description}
|
||||
@@ -105,22 +112,27 @@ export const ScriptModal = ({
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6 h-[500px]">
|
||||
<div className="lg:col-span-1 bg-muted/20 rounded-lg p-4 flex flex-col h-full overflow-hidden">
|
||||
<div className="lg:col-span-1 bg-background0 ascii-border p-4 flex flex-col h-full overflow-hidden">
|
||||
<div className="flex items-center gap-2 mb-4 flex-shrink-0">
|
||||
<Code className="h-4 w-4 text-primary" />
|
||||
<h3 className="text-sm font-medium text-foreground">Snippets</h3>
|
||||
<CodeIcon className="h-4 w-4" />
|
||||
<h3 className="text-sm font-medium">Snippets</h3>
|
||||
</div>
|
||||
<div className="flex-1 overflow-y-auto min-h-0">
|
||||
<div className="flex-1 overflow-y-auto min-h-0 !pr-0 tui-scrollbar">
|
||||
<BashSnippetHelper onInsertSnippet={handleInsertSnippet} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="lg:col-span-2 flex flex-col h-full overflow-hidden">
|
||||
<div className="flex items-center gap-2 mb-4 flex-shrink-0">
|
||||
<FileText className="h-4 w-4 text-primary" />
|
||||
<h3 className="text-sm font-medium text-foreground">
|
||||
Script Content <span className="text-red-500">*</span>
|
||||
<FileTextIcon className="h-4 w-4" />
|
||||
<h3 className="text-sm font-medium">
|
||||
Script Content <span className="text-status-error">*</span>
|
||||
</h3>
|
||||
{isDraft && (
|
||||
<span className="ml-auto px-2 py-0.5 text-xs font-medium bg-background0 text-status-info ascii-border">
|
||||
{t("scripts.draft")}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex-1 min-h-0">
|
||||
<BashEditor
|
||||
@@ -133,21 +145,36 @@ export const ScriptModal = ({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-3 pt-4 border-t border-border/30">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={onClose}
|
||||
className="btn-outline"
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button type="submit" className="btn-primary glow-primary">
|
||||
{submitButtonIcon}
|
||||
{submitButtonText}
|
||||
</Button>
|
||||
<div className="flex justify-between items-center gap-3 pt-4 border-border border-t">
|
||||
<div>
|
||||
{isDraft && onClearDraft && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
onClick={onClearDraft}
|
||||
className="opacity-60 hover:opacity-100"
|
||||
>
|
||||
<TrashIcon className="h-4 w-4 mr-2" />
|
||||
{t("scripts.clearDraft")}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex gap-3">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={onClose}
|
||||
className="btn-outline"
|
||||
>
|
||||
{t("scripts.close")}
|
||||
</Button>
|
||||
<Button type="submit" className="btn-primary glow-primary">
|
||||
{submitButtonIcon}
|
||||
{submitButtonText}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useEffect, useState } from "react";
|
||||
import { Modal } from "@/app/_components/GlobalComponents/UIElements/Modal";
|
||||
import { Button } from "@/app/_components/GlobalComponents/UIElements/Button";
|
||||
import { Input } from "@/app/_components/GlobalComponents/FormElements/Input";
|
||||
import { FileText, Search, Check, Terminal } from "lucide-react";
|
||||
import { FileTextIcon, MagnifyingGlassIcon, CheckIcon, TerminalIcon } from "@phosphor-icons/react";
|
||||
import { Script } from "@/app/_utils/scripts-utils";
|
||||
import { getScriptContent } from "@/app/_server/actions/scripts";
|
||||
import { getHostScriptPath } from "@/app/_server/actions/scripts";
|
||||
@@ -84,7 +84,7 @@ export const SelectScriptModal = ({
|
||||
>
|
||||
<div className="space-y-4">
|
||||
<div className="relative">
|
||||
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
||||
<MagnifyingGlassIcon className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
||||
<Input
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
@@ -119,12 +119,12 @@ export const SelectScriptModal = ({
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<FileText className="h-4 w-4 text-primary flex-shrink-0" />
|
||||
<FileTextIcon className="h-4 w-4 text-primary flex-shrink-0" />
|
||||
<h4 className="font-medium text-foreground truncate">
|
||||
{script.name}
|
||||
</h4>
|
||||
{selectedScriptId === script.id && (
|
||||
<Check className="h-4 w-4 text-green-500 flex-shrink-0" />
|
||||
<CheckIcon className="h-4 w-4 text-status-success flex-shrink-0" />
|
||||
)}
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground line-clamp-2">
|
||||
@@ -148,7 +148,7 @@ export const SelectScriptModal = ({
|
||||
{t("scripts.scriptPreview")}
|
||||
</h3>
|
||||
</div>
|
||||
<div className="p-4 h-full max-h-80 overflow-y-auto">
|
||||
<div className="p-4 h-full max-h-80 overflow-y-auto tui-scrollbar">
|
||||
{previewScript ? (
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
@@ -162,12 +162,12 @@ export const SelectScriptModal = ({
|
||||
|
||||
<div>
|
||||
<div className="flex items-center gap-2 mb-2">
|
||||
<Terminal className="h-4 w-4 text-primary" />
|
||||
<TerminalIcon className="h-4 w-4 text-primary" />
|
||||
<span className="text-sm font-medium text-foreground">
|
||||
{t("scripts.commandPreview")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="bg-muted/30 p-3 rounded border border-border/30">
|
||||
<div className="bg-muted/30 p-3 rounded border border-border">
|
||||
<code className="text-sm font-mono text-foreground break-all">
|
||||
{hostScriptPath}
|
||||
</code>
|
||||
@@ -178,7 +178,7 @@ export const SelectScriptModal = ({
|
||||
<span className="text-sm font-medium text-foreground">
|
||||
{t("scripts.scriptContent")}
|
||||
</span>
|
||||
<div className="bg-muted/30 p-3 rounded border border-border/30 mt-2 max-h-32 overflow-auto">
|
||||
<div className="bg-muted/30 p-3 rounded border border-border mt-2 max-h-32 overflow-auto tui-scrollbar">
|
||||
<pre className="text-xs font-mono text-foreground whitespace-pre-wrap">
|
||||
{previewContent}
|
||||
</pre>
|
||||
@@ -187,7 +187,7 @@ export const SelectScriptModal = ({
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-center text-muted-foreground py-8">
|
||||
<FileText className="h-12 w-12 mx-auto mb-4 opacity-50" />
|
||||
<FileTextIcon className="h-12 w-12 mx-auto mb-4 opacity-50" />
|
||||
<p>{t("scripts.selectScriptToPreview")}</p>
|
||||
</div>
|
||||
)}
|
||||
@@ -195,7 +195,7 @@ export const SelectScriptModal = ({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-2 pt-3 border-t border-border/50">
|
||||
<div className="flex justify-end gap-2 pt-3 border-t border-border">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
@@ -210,7 +210,7 @@ export const SelectScriptModal = ({
|
||||
disabled={!previewScript}
|
||||
className="btn-primary glow-primary"
|
||||
>
|
||||
<Check className="h-4 w-4 mr-2" />
|
||||
<CheckIcon className="h-4 w-4 mr-2" />
|
||||
{t("scripts.selectScript")}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -16,7 +16,6 @@ export const PWAInstallPrompt = (): JSX.Element | null => {
|
||||
useEffect(() => {
|
||||
if (typeof window === "undefined") return;
|
||||
const onBeforeInstallPrompt = (e: Event) => {
|
||||
e.preventDefault();
|
||||
setDeferred(e as BeforeInstallPromptEvent);
|
||||
};
|
||||
const onAppInstalled = () => {
|
||||
@@ -42,17 +41,17 @@ export const PWAInstallPrompt = (): JSX.Element | null => {
|
||||
if (choice.outcome === "accepted") {
|
||||
setDeferred(null);
|
||||
}
|
||||
} catch (_err) {}
|
||||
} catch (_err) { }
|
||||
}, [deferred]);
|
||||
|
||||
if (isInstalled || !deferred) return null;
|
||||
|
||||
return (
|
||||
<button
|
||||
className="px-3 py-1 rounded-md border border-border/50 bg-background/80 hover:bg-background/60"
|
||||
className="px-3 py-2 ascii-border bg-background0 hover:bg-background1 transition-colors terminal-font text-sm"
|
||||
onClick={onInstall}
|
||||
>
|
||||
Install App
|
||||
Install
|
||||
</button>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { EditorView } from "@codemirror/view";
|
||||
import { EditorState } from "@codemirror/state";
|
||||
import { javascript } from "@codemirror/lang-javascript";
|
||||
import { oneDark } from "@codemirror/theme-one-dark";
|
||||
import { EditorView, keymap } from "@codemirror/view";
|
||||
import { EditorState, Transaction } from "@codemirror/state";
|
||||
import { shell } from "@codemirror/legacy-modes/mode/shell";
|
||||
import { StreamLanguage } from "@codemirror/language";
|
||||
import { catppuccinMocha, catppuccinLatte } from './catppuccin-theme';
|
||||
import { useTheme } from 'next-themes';
|
||||
import { Button } from "@/app/_components/GlobalComponents/UIElements/Button";
|
||||
import { Terminal, Copy, Check } from "lucide-react";
|
||||
import { TerminalIcon, CopyIcon, CheckIcon } from "@phosphor-icons/react";
|
||||
|
||||
interface BashEditorProps {
|
||||
value: string;
|
||||
@@ -21,25 +23,136 @@ export const BashEditor = ({
|
||||
onChange,
|
||||
placeholder = "#!/bin/bash\n# Your bash script here\necho 'Hello World'",
|
||||
className = "",
|
||||
label = "Bash Script",
|
||||
label,
|
||||
}: BashEditorProps) => {
|
||||
const [copied, setCopied] = useState(false);
|
||||
const editorRef = useRef<HTMLDivElement>(null);
|
||||
const editorViewRef = useRef<EditorView | null>(null);
|
||||
const { theme } = useTheme();
|
||||
|
||||
const insertFourSpaces = ({
|
||||
state,
|
||||
dispatch,
|
||||
}: {
|
||||
state: EditorState;
|
||||
dispatch: (tr: Transaction) => void;
|
||||
}) => {
|
||||
if (state.selection.ranges.some((range) => !range.empty)) {
|
||||
const changes = state.selection.ranges
|
||||
.map((range) => {
|
||||
const fromLine = state.doc.lineAt(range.from).number;
|
||||
const toLine = state.doc.lineAt(range.to).number;
|
||||
const changes = [];
|
||||
for (let line = fromLine; line <= toLine; line++) {
|
||||
const lineObj = state.doc.line(line);
|
||||
changes.push({ from: lineObj.from, insert: " " });
|
||||
}
|
||||
return changes;
|
||||
})
|
||||
.flat();
|
||||
dispatch(state.update({ changes }));
|
||||
} else {
|
||||
dispatch(state.update(state.replaceSelection(" ")));
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
const removeFourSpaces = ({
|
||||
state,
|
||||
dispatch,
|
||||
}: {
|
||||
state: EditorState;
|
||||
dispatch: (tr: Transaction) => void;
|
||||
}) => {
|
||||
if (state.selection.ranges.some((range) => !range.empty)) {
|
||||
const changes = state.selection.ranges
|
||||
.map((range) => {
|
||||
const fromLine = state.doc.lineAt(range.from).number;
|
||||
const toLine = state.doc.lineAt(range.to).number;
|
||||
const changes = [];
|
||||
for (let line = fromLine; line <= toLine; line++) {
|
||||
const lineObj = state.doc.line(line);
|
||||
const indent = lineObj.text.match(/^ /);
|
||||
if (indent) {
|
||||
changes.push({ from: lineObj.from, to: lineObj.from + 4 });
|
||||
}
|
||||
}
|
||||
return changes;
|
||||
})
|
||||
.flat();
|
||||
dispatch(state.update({ changes }));
|
||||
} else {
|
||||
const cursor = state.selection.main.head;
|
||||
const line = state.doc.lineAt(cursor);
|
||||
const beforeCursor = line.text.slice(0, cursor - line.from);
|
||||
const spacesToRemove = beforeCursor.match(/ {1,4}$/);
|
||||
if (spacesToRemove) {
|
||||
const removeCount = spacesToRemove[0].length;
|
||||
dispatch(
|
||||
state.update({
|
||||
changes: { from: cursor - removeCount, to: cursor },
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!editorRef.current) return;
|
||||
|
||||
const bashLanguage = javascript({
|
||||
typescript: false,
|
||||
jsx: false,
|
||||
});
|
||||
const isDark = theme === 'catppuccin-mocha';
|
||||
const bashLanguage = StreamLanguage.define(shell);
|
||||
|
||||
const getThemeColors = () => {
|
||||
const root = document.documentElement;
|
||||
const style = getComputedStyle(root);
|
||||
|
||||
return {
|
||||
background: style.getPropertyValue('--base').trim() || (isDark ? '#1e1e2e' : '#eff1f5'),
|
||||
foreground: style.getPropertyValue('--text').trim() || (isDark ? '#cdd6f4' : '#4c4f69'),
|
||||
border: style.getPropertyValue('--box-border-color').trim() || (isDark ? '#313244' : '#9ca0b0'),
|
||||
surface: style.getPropertyValue('--surface0').trim() || (isDark ? '#313244' : '#ccd0da'),
|
||||
};
|
||||
};
|
||||
|
||||
const colors = getThemeColors();
|
||||
|
||||
const customTheme = EditorView.theme({
|
||||
"&": {
|
||||
backgroundColor: colors.background,
|
||||
color: colors.foreground,
|
||||
border: `1px solid ${colors.border}`,
|
||||
borderRadius: '0',
|
||||
},
|
||||
".cm-content": {
|
||||
caretColor: colors.foreground,
|
||||
padding: '12px'
|
||||
},
|
||||
".cm-gutters": {
|
||||
backgroundColor: colors.surface,
|
||||
color: colors.foreground,
|
||||
borderRight: `1px solid ${colors.border}`,
|
||||
opacity: '0.6',
|
||||
},
|
||||
".cm-activeLineGutter": {
|
||||
backgroundColor: colors.surface,
|
||||
opacity: '1',
|
||||
},
|
||||
".cm-scroller": {
|
||||
fontFamily: 'JetBrains Mono, Fira CodeIcon, monospace',
|
||||
},
|
||||
}, { dark: isDark });
|
||||
|
||||
const state = EditorState.create({
|
||||
doc: value || placeholder,
|
||||
extensions: [
|
||||
bashLanguage,
|
||||
oneDark,
|
||||
customTheme,
|
||||
keymap.of([
|
||||
{ key: "Tab", run: insertFourSpaces },
|
||||
{ key: "Shift-Tab", run: removeFourSpaces },
|
||||
]),
|
||||
EditorView.updateListener.of((update: any) => {
|
||||
if (update.docChanged) {
|
||||
onChange(update.state.doc.toString());
|
||||
@@ -49,7 +162,7 @@ export const BashEditor = ({
|
||||
"&": {
|
||||
fontSize: "14px",
|
||||
fontFamily:
|
||||
'ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace',
|
||||
'JetBrains Mono, Fira CodeIcon, ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace',
|
||||
height: "100%",
|
||||
maxHeight: "100%",
|
||||
},
|
||||
@@ -62,7 +175,7 @@ export const BashEditor = ({
|
||||
},
|
||||
".cm-scroller": {
|
||||
fontFamily:
|
||||
'ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace',
|
||||
'JetBrains Mono, Fira CodeIcon, ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace',
|
||||
height: "100%",
|
||||
maxHeight: "100%",
|
||||
},
|
||||
@@ -80,7 +193,7 @@ export const BashEditor = ({
|
||||
return () => {
|
||||
view.destroy();
|
||||
};
|
||||
}, []);
|
||||
}, [theme]);
|
||||
|
||||
useEffect(() => {
|
||||
if (editorViewRef.current) {
|
||||
@@ -111,27 +224,28 @@ export const BashEditor = ({
|
||||
{label && (
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Terminal className="h-4 w-4 text-cyan-500" />
|
||||
<TerminalIcon className="h-4 w-4" />
|
||||
<span className="text-sm font-medium">{label}</span>
|
||||
</div>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={handleCopy}
|
||||
className="btn-outline h-7 px-2"
|
||||
>
|
||||
{copied ? (
|
||||
<Check className="h-3 w-3 mr-1" />
|
||||
<CheckIcon className="h-3 w-3 mr-1" />
|
||||
) : (
|
||||
<Copy className="h-3 w-3 mr-1" />
|
||||
<CopyIcon className="h-3 w-3 mr-1" />
|
||||
)}
|
||||
{copied ? "Copied!" : "Copy"}
|
||||
{copied ? "Copied!" : "CopyIcon"}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
<div className="border border-border overflow-hidden h-full">
|
||||
<div ref={editorRef} className="h-full rounded-lg" />
|
||||
<div className="overflow-hidden h-full">
|
||||
<div ref={editorRef} className="h-full" />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4,15 +4,15 @@ import { useState, useEffect } from "react";
|
||||
import { Button } from "@/app/_components/GlobalComponents/UIElements/Button";
|
||||
import { Input } from "@/app/_components/GlobalComponents/FormElements/Input";
|
||||
import {
|
||||
Search,
|
||||
FileText,
|
||||
MagnifyingGlassIcon,
|
||||
FileTextIcon,
|
||||
FolderOpen,
|
||||
Code,
|
||||
Settings,
|
||||
CodeIcon,
|
||||
GearIcon,
|
||||
Database,
|
||||
Copy,
|
||||
Check,
|
||||
} from "lucide-react";
|
||||
CopyIcon,
|
||||
CheckIcon,
|
||||
} from "@phosphor-icons/react";
|
||||
import {
|
||||
fetchSnippets,
|
||||
fetchSnippetCategories,
|
||||
@@ -25,16 +25,18 @@ interface BashSnippetHelperProps {
|
||||
}
|
||||
|
||||
const categoryIcons = {
|
||||
"File Operations": FileText,
|
||||
Loops: Code,
|
||||
Conditionals: Code,
|
||||
"System Operations": Settings,
|
||||
"File Operations": FileTextIcon,
|
||||
Loops: CodeIcon,
|
||||
Conditionals: CodeIcon,
|
||||
"System Operations": GearIcon,
|
||||
"Database Operations": Database,
|
||||
"User Examples": FolderOpen,
|
||||
"Custom Scripts": Code,
|
||||
"UserIcon Examples": FolderOpen,
|
||||
"Custom Scripts": CodeIcon,
|
||||
};
|
||||
|
||||
export const BashSnippetHelper = ({ onInsertSnippet }: BashSnippetHelperProps) => {
|
||||
export const BashSnippetHelper = ({
|
||||
onInsertSnippet,
|
||||
}: BashSnippetHelperProps) => {
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
const [selectedCategory, setSelectedCategory] = useState<string | null>(null);
|
||||
const [copiedId, setCopiedId] = useState<string | null>(null);
|
||||
@@ -107,7 +109,7 @@ export const BashSnippetHelper = ({ onInsertSnippet }: BashSnippetHelperProps) =
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<div className="text-center py-8">
|
||||
<Code className="h-8 w-8 text-muted-foreground mx-auto mb-2 animate-spin" />
|
||||
<CodeIcon className="h-8 w-8 text-muted-foreground mx-auto mb-2 animate-spin" />
|
||||
<p className="text-sm text-muted-foreground">Loading snippets...</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -117,7 +119,7 @@ export const BashSnippetHelper = ({ onInsertSnippet }: BashSnippetHelperProps) =
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<div className="relative">
|
||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
||||
<MagnifyingGlassIcon className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
||||
<Input
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
@@ -127,7 +129,7 @@ export const BashSnippetHelper = ({ onInsertSnippet }: BashSnippetHelperProps) =
|
||||
</div>
|
||||
|
||||
{!searchQuery && (
|
||||
<div className="overflow-x-auto">
|
||||
<div className="overflow-x-auto tui-scrollbar">
|
||||
<div className="flex gap-1 pb-2 min-w-max">
|
||||
<Button
|
||||
type="button"
|
||||
@@ -140,7 +142,7 @@ export const BashSnippetHelper = ({ onInsertSnippet }: BashSnippetHelperProps) =
|
||||
</Button>
|
||||
{categories.map((category) => {
|
||||
const Icon =
|
||||
categoryIcons[category as keyof typeof categoryIcons] || Code;
|
||||
categoryIcons[category as keyof typeof categoryIcons] || CodeIcon;
|
||||
return (
|
||||
<Button
|
||||
key={category}
|
||||
@@ -161,15 +163,15 @@ export const BashSnippetHelper = ({ onInsertSnippet }: BashSnippetHelperProps) =
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="space-y-2 overflow-y-auto custom-scrollbar">
|
||||
<div className="space-y-2 overflow-y-auto !pr-0 tui-scrollbar">
|
||||
{filteredSnippets.map((snippet) => {
|
||||
const Icon =
|
||||
categoryIcons[snippet.category as keyof typeof categoryIcons] ||
|
||||
Code;
|
||||
CodeIcon;
|
||||
return (
|
||||
<div
|
||||
key={snippet.id}
|
||||
className="bg-muted/30 rounded-lg border border-border/50 p-3 hover:bg-accent/30 transition-colors"
|
||||
className="bg-muted/30 rounded-lg border border-border p-3 hover:bg-accent/30 transition-colors"
|
||||
>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
@@ -178,7 +180,7 @@ export const BashSnippetHelper = ({ onInsertSnippet }: BashSnippetHelperProps) =
|
||||
{snippet.title}
|
||||
</h4>
|
||||
{snippet.source === "user" && (
|
||||
<span className="inline-block px-1.5 py-0.5 text-xs bg-green-100 text-green-700 rounded border border-green-200">
|
||||
<span className="inline-block px-1.5 py-0.5 text-xs text-status-success border border-border">
|
||||
User
|
||||
</span>
|
||||
)}
|
||||
@@ -190,7 +192,7 @@ export const BashSnippetHelper = ({ onInsertSnippet }: BashSnippetHelperProps) =
|
||||
{snippet.tags.slice(0, 3).map((tag) => (
|
||||
<span
|
||||
key={tag}
|
||||
className="inline-block px-2 py-1 text-xs bg-primary/10 text-primary rounded border border-primary/20"
|
||||
className="inline-block px-2 py-1 text-xs bg-primary/10 text-primary border border-border"
|
||||
>
|
||||
{tag}
|
||||
</span>
|
||||
@@ -207,12 +209,11 @@ export const BashSnippetHelper = ({ onInsertSnippet }: BashSnippetHelperProps) =
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => handleCopy(snippet)}
|
||||
className="h-6 w-8 p-0 text-xs"
|
||||
>
|
||||
{copiedId === snippet.id ? (
|
||||
<Check className="h-3 w-3" />
|
||||
<CheckIcon className="h-3 w-3" />
|
||||
) : (
|
||||
<Copy className="h-3 w-3" />
|
||||
<CopyIcon className="h-3 w-3" />
|
||||
)}
|
||||
</Button>
|
||||
<Button
|
||||
@@ -220,7 +221,7 @@ export const BashSnippetHelper = ({ onInsertSnippet }: BashSnippetHelperProps) =
|
||||
variant="default"
|
||||
size="sm"
|
||||
onClick={() => handleInsert(snippet)}
|
||||
className="h-6 px-3 text-xs flex-1"
|
||||
className="flex-1"
|
||||
>
|
||||
Insert
|
||||
</Button>
|
||||
@@ -232,7 +233,7 @@ export const BashSnippetHelper = ({ onInsertSnippet }: BashSnippetHelperProps) =
|
||||
|
||||
{filteredSnippets.length === 0 && (
|
||||
<div className="text-center py-8">
|
||||
<Code className="h-8 w-8 text-muted-foreground mx-auto mb-2" />
|
||||
<CodeIcon className="h-8 w-8 text-muted-foreground mx-auto mb-2" />
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{searchQuery
|
||||
? `No snippets found for "${searchQuery}"`
|
||||
@@ -243,4 +244,4 @@ export const BashSnippetHelper = ({ onInsertSnippet }: BashSnippetHelperProps) =
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -9,15 +9,15 @@ import {
|
||||
import { Button } from "@/app/_components/GlobalComponents/UIElements/Button";
|
||||
import { Input } from "@/app/_components/GlobalComponents/FormElements/Input";
|
||||
import {
|
||||
Clock,
|
||||
Info,
|
||||
CheckCircle,
|
||||
AlertCircle,
|
||||
ClockIcon,
|
||||
InfoIcon,
|
||||
CheckCircleIcon,
|
||||
WarningCircleIcon,
|
||||
Calendar,
|
||||
ChevronDown,
|
||||
ChevronUp,
|
||||
Search,
|
||||
} from "lucide-react";
|
||||
CaretDownIcon,
|
||||
CaretUpIcon,
|
||||
MagnifyingGlassIcon,
|
||||
} from "@phosphor-icons/react";
|
||||
import { useLocale } from "next-intl";
|
||||
|
||||
interface CronExpressionHelperProps {
|
||||
@@ -87,20 +87,20 @@ export const CronExpressionHelper = ({
|
||||
/>
|
||||
<div className="absolute right-3 top-1/2 -translate-y-1/2">
|
||||
{explanation?.isValid ? (
|
||||
<CheckCircle className="h-4 w-4 text-green-500" />
|
||||
<CheckCircleIcon className="h-4 w-4 text-status-success" />
|
||||
) : value ? (
|
||||
<AlertCircle className="h-4 w-4 text-red-500" />
|
||||
<WarningCircleIcon className="h-4 w-4 text-status-error" />
|
||||
) : (
|
||||
<Clock className="h-4 w-4 text-muted-foreground" />
|
||||
<ClockIcon className="h-4 w-4 text-muted-foreground" />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{explanation && (
|
||||
<div className="bg-muted/30 rounded p-2 border border-border/30">
|
||||
<div className="bg-background0 p-2 text-status-warning ascii-border terminal-font">
|
||||
<div className="space-y-1">
|
||||
<div className="flex items-start gap-2">
|
||||
<Info className="h-3 w-3 text-primary mt-0.5 flex-shrink-0" />
|
||||
<InfoIcon className="h-3 w-3 text-primary mt-0.5 flex-shrink-0" />
|
||||
<div className="flex-1">
|
||||
<p className="text-xs italic text-muted-foreground">
|
||||
{explanation.isValid
|
||||
@@ -108,7 +108,7 @@ export const CronExpressionHelper = ({
|
||||
: "Invalid Expression"}
|
||||
</p>
|
||||
{explanation.error && (
|
||||
<p className="text-xs text-red-600 dark:text-red-400 mt-0.5">
|
||||
<p className="text-xs text-status-error mt-0.5">
|
||||
{explanation.error}
|
||||
</p>
|
||||
)}
|
||||
@@ -117,7 +117,7 @@ export const CronExpressionHelper = ({
|
||||
|
||||
{explanation.isValid && explanation.nextRuns.length > 0 && (
|
||||
<div className="flex items-start gap-2">
|
||||
<Calendar className="h-3 w-3 text-blue-500 mt-0.5 flex-shrink-0" />
|
||||
<Calendar className="h-3 w-3 text-status-info mt-0.5 flex-shrink-0" />
|
||||
<div className="flex-1">
|
||||
<p className="text-xs text-muted-foreground mb-1">
|
||||
Next executions:
|
||||
@@ -137,7 +137,7 @@ export const CronExpressionHelper = ({
|
||||
)}
|
||||
|
||||
{showPatterns && (
|
||||
<div className="bg-muted/30 rounded-lg border border-border/50">
|
||||
<div className="bg-background0 ascii-border terminal-font">
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
@@ -145,24 +145,24 @@ export const CronExpressionHelper = ({
|
||||
e.stopPropagation();
|
||||
setShowPatternsPanel(!showPatternsPanel);
|
||||
}}
|
||||
className="w-full text-left p-3 hover:bg-accent/30 transition-colors rounded-t-lg"
|
||||
className="w-full text-left p-3 hover:bg-background0 transition-colors"
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-sm font-medium">Quick Patterns</span>
|
||||
<div className="p-1">
|
||||
{showPatternsPanel ? (
|
||||
<ChevronUp className="h-4 w-4" />
|
||||
<CaretUpIcon className="h-4 w-4" />
|
||||
) : (
|
||||
<ChevronDown className="h-4 w-4" />
|
||||
<CaretDownIcon className="h-4 w-4" />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
|
||||
{showPatternsPanel && (
|
||||
<div className="p-3 border-t border-border/50">
|
||||
<div className="p-3 border-t border-border">
|
||||
<div className="relative mb-3">
|
||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
||||
<MagnifyingGlassIcon className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
||||
<Input
|
||||
value={patternSearch}
|
||||
onChange={(e) => setPatternSearch(e.target.value)}
|
||||
@@ -171,7 +171,7 @@ export const CronExpressionHelper = ({
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-3 max-h-64 overflow-y-auto custom-scrollbar">
|
||||
<div className="space-y-3 max-h-64 overflow-y-auto tui-scrollbar">
|
||||
{filteredPatterns.map((category) => (
|
||||
<div key={category.category} className="space-y-2">
|
||||
<h4 className="font-medium text-foreground text-sm">
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useState, useEffect } from "react";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/app/_components/GlobalComponents/Cards/Card";
|
||||
import { Button } from "@/app/_components/GlobalComponents/UIElements/Button";
|
||||
import {
|
||||
FileText,
|
||||
Plus,
|
||||
Edit,
|
||||
Trash2,
|
||||
Copy,
|
||||
Copy as CopyIcon,
|
||||
CheckCircle,
|
||||
Files,
|
||||
} from "lucide-react";
|
||||
FileTextIcon,
|
||||
PlusIcon,
|
||||
PencilSimpleIcon,
|
||||
TrashIcon,
|
||||
CopyIcon,
|
||||
CheckCircleIcon,
|
||||
FilesIcon,
|
||||
} from "@phosphor-icons/react";
|
||||
import { Script } from "@/app/_utils/scripts-utils";
|
||||
import {
|
||||
createScript,
|
||||
@@ -32,6 +31,8 @@ interface ScriptsManagerProps {
|
||||
scripts: Script[];
|
||||
}
|
||||
|
||||
const DRAFT_STORAGE_KEY = "cronjob_script_draft";
|
||||
|
||||
export const ScriptsManager = ({
|
||||
scripts: initialScripts,
|
||||
}: ScriptsManagerProps) => {
|
||||
@@ -46,11 +47,13 @@ export const ScriptsManager = ({
|
||||
const [isCloning, setIsCloning] = useState(false);
|
||||
const t = useTranslations();
|
||||
|
||||
const [createForm, setCreateForm] = useState({
|
||||
const defaultFormValues = {
|
||||
name: "",
|
||||
description: "",
|
||||
content: "#!/bin/bash\n# Your script here\necho 'Hello World'",
|
||||
});
|
||||
};
|
||||
|
||||
const [createForm, setCreateForm] = useState(defaultFormValues);
|
||||
|
||||
const [editForm, setEditForm] = useState({
|
||||
name: "",
|
||||
@@ -58,6 +61,37 @@ export const ScriptsManager = ({
|
||||
content: "",
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
try {
|
||||
const savedDraft = localStorage.getItem(DRAFT_STORAGE_KEY);
|
||||
if (savedDraft) {
|
||||
const parsedDraft = JSON.parse(savedDraft);
|
||||
setCreateForm(parsedDraft);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to load draft from localStorage:", error);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
try {
|
||||
localStorage.setItem(DRAFT_STORAGE_KEY, JSON.stringify(createForm));
|
||||
} catch (error) {
|
||||
console.error("Failed to save draft to localStorage:", error);
|
||||
}
|
||||
}, [createForm]);
|
||||
|
||||
const isDraft =
|
||||
createForm.name.trim() !== "" ||
|
||||
createForm.description.trim() !== "" ||
|
||||
createForm.content !== defaultFormValues.content;
|
||||
|
||||
const handleClearDraft = () => {
|
||||
setCreateForm(defaultFormValues);
|
||||
localStorage.removeItem(DRAFT_STORAGE_KEY);
|
||||
showToast("success", t("scripts.draftCleared"));
|
||||
};
|
||||
|
||||
const refreshScripts = async () => {
|
||||
try {
|
||||
const { fetchScripts } = await import("@/app/_server/actions/scripts");
|
||||
@@ -78,6 +112,8 @@ export const ScriptsManager = ({
|
||||
if (result.success) {
|
||||
await refreshScripts();
|
||||
setIsCreateModalOpen(false);
|
||||
setCreateForm(defaultFormValues);
|
||||
localStorage.removeItem(DRAFT_STORAGE_KEY);
|
||||
showToast("success", "Script created successfully");
|
||||
} else {
|
||||
showToast("error", "Failed to create script", result.message);
|
||||
@@ -170,8 +206,8 @@ export const ScriptsManager = ({
|
||||
<CardHeader>
|
||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="p-2 bg-primary/10 rounded-lg">
|
||||
<FileText className="h-5 w-5 text-primary" />
|
||||
<div className="p-2 bg-background0 ascii-border">
|
||||
<FileTextIcon className="h-5 w-5 text-primary" />
|
||||
</div>
|
||||
<div>
|
||||
<CardTitle className="text-xl brand-gradient">
|
||||
@@ -186,16 +222,16 @@ export const ScriptsManager = ({
|
||||
onClick={() => setIsCreateModalOpen(true)}
|
||||
className="btn-primary glow-primary"
|
||||
>
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
<PlusIcon className="h-4 w-4 mr-2" />
|
||||
{t("scripts.newScript")}
|
||||
</Button>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{scripts.length === 0 ? (
|
||||
<div className="text-center py-16">
|
||||
<div className="mx-auto w-20 h-20 bg-gradient-to-br from-primary/20 to-blue-500/20 rounded-full flex items-center justify-center mb-6">
|
||||
<FileText className="h-10 w-10 text-primary" />
|
||||
<div className="text-center py-16 terminal-font">
|
||||
<div className="mx-auto w-20 h-20 bg-background2 ascii-border flex items-center justify-center mb-6">
|
||||
<FileTextIcon className="h-10 w-10 text-primary" />
|
||||
</div>
|
||||
<h3 className="text-xl font-semibold mb-3 brand-gradient">
|
||||
{t("scripts.noScriptsYet")}
|
||||
@@ -208,7 +244,7 @@ export const ScriptsManager = ({
|
||||
className="btn-primary glow-primary"
|
||||
size="lg"
|
||||
>
|
||||
<Plus className="h-5 w-5 mr-2" />
|
||||
<PlusIcon className="h-5 w-5 mr-2" />
|
||||
{t("scripts.createYourFirstScript")}
|
||||
</Button>
|
||||
</div>
|
||||
@@ -217,7 +253,7 @@ export const ScriptsManager = ({
|
||||
{scripts.map((script) => (
|
||||
<div
|
||||
key={script.id}
|
||||
className="glass-card p-4 border border-border/50 rounded-lg hover:bg-accent/30 transition-colors"
|
||||
className="glass-card p-4 ascii-border hover:bg-accent/30 transition-colors terminal-font"
|
||||
>
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<div className="flex-1 min-w-0">
|
||||
@@ -245,11 +281,11 @@ export const ScriptsManager = ({
|
||||
size="sm"
|
||||
onClick={() => handleCopy(script)}
|
||||
className="btn-outline h-8 px-3"
|
||||
title="Copy script content to clipboard"
|
||||
aria-label="Copy script content to clipboard"
|
||||
title="CopyIcon script content to clipboard"
|
||||
aria-label="CopyIcon script content to clipboard"
|
||||
>
|
||||
{copiedId === script.id ? (
|
||||
<CheckCircle className="h-3 w-3 text-green-500" />
|
||||
<CheckCircleIcon className="h-3 w-3 text-status-success" />
|
||||
) : (
|
||||
<CopyIcon className="h-3 w-3" />
|
||||
)}
|
||||
@@ -265,7 +301,7 @@ export const ScriptsManager = ({
|
||||
title="Clone script"
|
||||
aria-label="Clone script"
|
||||
>
|
||||
<Files className="h-3 w-3" />
|
||||
<FilesIcon className="h-3 w-3" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
@@ -286,7 +322,7 @@ export const ScriptsManager = ({
|
||||
title="Edit script"
|
||||
aria-label="Edit script"
|
||||
>
|
||||
<Edit className="h-3 w-3" />
|
||||
<PencilSimpleIcon className="h-3 w-3" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
@@ -295,11 +331,11 @@ export const ScriptsManager = ({
|
||||
setSelectedScript(script);
|
||||
setIsDeleteModalOpen(true);
|
||||
}}
|
||||
className="btn-destructive h-8 px-3"
|
||||
className="h-8 px-3"
|
||||
title="Delete script"
|
||||
aria-label="Delete script"
|
||||
>
|
||||
<Trash2 className="h-3 w-3" />
|
||||
<TrashIcon className="h-3 w-3" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -318,6 +354,8 @@ export const ScriptsManager = ({
|
||||
onFormChange={(updates) =>
|
||||
setCreateForm((prev) => ({ ...prev, ...updates }))
|
||||
}
|
||||
isDraft={isDraft}
|
||||
onClearDraft={handleClearDraft}
|
||||
/>
|
||||
|
||||
<EditScriptModal
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import { Extension } from '@codemirror/state';
|
||||
import { EditorView } from '@codemirror/view';
|
||||
|
||||
export const catppuccinMocha: Extension = EditorView.theme({
|
||||
'&': {
|
||||
backgroundColor: '#1e1e2e',
|
||||
color: '#cdd6f4',
|
||||
fontSize: '14px',
|
||||
fontFamily: 'JetBrains Mono, monospace',
|
||||
border: '1px solid #45475a',
|
||||
borderRadius: '0',
|
||||
},
|
||||
'.cm-content': { caretColor: '#f5e0dc', padding: '12px' },
|
||||
'.cm-gutters': {
|
||||
backgroundColor: '#181825',
|
||||
color: '#6c7086',
|
||||
borderRight: '1px solid #45475a',
|
||||
},
|
||||
}, { dark: true });
|
||||
|
||||
export const catppuccinLatte: Extension = EditorView.theme({
|
||||
'&': {
|
||||
backgroundColor: '#eff1f5',
|
||||
color: '#4c4f69',
|
||||
fontSize: '14px',
|
||||
fontFamily: 'JetBrains Mono, monospace',
|
||||
border: '1px solid #9ca0b0',
|
||||
borderRadius: '0',
|
||||
},
|
||||
'.cm-content': { caretColor: '#dc8a78', padding: '12px' },
|
||||
'.cm-gutters': {
|
||||
backgroundColor: '#e6e9ef',
|
||||
color: '#8c8fa1',
|
||||
borderRight: '1px solid #9ca0b0',
|
||||
},
|
||||
}, { dark: false });
|
||||
@@ -1,6 +1,6 @@
|
||||
import { cn } from "@/app/_utils/global-utils";
|
||||
import { HTMLAttributes, forwardRef } from "react";
|
||||
import { Zap } from "lucide-react";
|
||||
import { LightningIcon } from "@phosphor-icons/react";
|
||||
import { StatusBadge } from "@/app/_components/GlobalComponents/Badges/StatusBadge";
|
||||
|
||||
export interface PerformanceMetric {
|
||||
@@ -20,14 +20,14 @@ export const PerformanceSummary = forwardRef<HTMLDivElement, PerformanceSummaryP
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"p-3 bg-gradient-to-r from-purple-500/5 to-pink-500/5 border border-purple-500/20 rounded-lg glass-card",
|
||||
"p-3 bg-background0 ascii-border glass-card terminal-font",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<div className="flex items-center gap-2 mb-3">
|
||||
<Zap className="h-4 w-4 text-purple-500" />
|
||||
<span className="text-sm font-medium text-purple-600 dark:text-purple-400">
|
||||
<LightningIcon className="h-4 w-4" />
|
||||
<span className="text-sm font-medium">
|
||||
Performance Summary
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -4,13 +4,7 @@ import { MetricCard } from "@/app/_components/GlobalComponents/Cards/MetricCard"
|
||||
import { SystemStatus } from "@/app/_components/FeatureComponents/System/SystemStatus";
|
||||
import { PerformanceSummary } from "@/app/_components/FeatureComponents/System/PerformanceSummary";
|
||||
import { Sidebar } from "@/app/_components/FeatureComponents/Layout/Sidebar";
|
||||
import {
|
||||
Clock,
|
||||
HardDrive,
|
||||
Cpu,
|
||||
Monitor,
|
||||
Wifi,
|
||||
} from "lucide-react";
|
||||
import { ClockIcon, HardDriveIcon, CpuIcon, MonitorIcon, WifiHighIcon } from "@phosphor-icons/react";
|
||||
|
||||
interface SystemInfoType {
|
||||
hostname: string;
|
||||
@@ -54,10 +48,11 @@ interface SystemInfoType {
|
||||
details: string;
|
||||
};
|
||||
}
|
||||
import { useState, useEffect } from "react";
|
||||
import { useState, useEffect, useRef } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { useSSEContext } from "@/app/_contexts/SSEContext";
|
||||
import { SSEEvent } from "@/app/_utils/sse-events";
|
||||
import { usePageVisibility } from "@/app/_hooks/usePageVisibility";
|
||||
|
||||
interface SystemInfoCardProps {
|
||||
systemInfo: SystemInfoType;
|
||||
@@ -70,28 +65,53 @@ export const SystemInfoCard = ({
|
||||
const [systemInfo, setSystemInfo] =
|
||||
useState<SystemInfoType>(initialSystemInfo);
|
||||
const [isUpdating, setIsUpdating] = useState(false);
|
||||
const [isDisabled, setIsDisabled] = useState(false);
|
||||
const t = useTranslations();
|
||||
const { subscribe } = useSSEContext();
|
||||
const isPageVisible = usePageVisibility();
|
||||
|
||||
const abortControllerRef = useRef<AbortController | null>(null);
|
||||
|
||||
const updateSystemInfo = async () => {
|
||||
if (isDisabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (abortControllerRef.current) {
|
||||
abortControllerRef.current.abort();
|
||||
}
|
||||
|
||||
const abortController = new AbortController();
|
||||
abortControllerRef.current = abortController;
|
||||
|
||||
try {
|
||||
setIsUpdating(true);
|
||||
const response = await fetch('/api/system-stats');
|
||||
const response = await fetch("/api/system-stats", {
|
||||
signal: abortController.signal,
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to fetch system stats');
|
||||
throw new Error("Failed to fetch system stats");
|
||||
}
|
||||
const freshData = await response.json();
|
||||
if (freshData === null) {
|
||||
setIsDisabled(true);
|
||||
return;
|
||||
}
|
||||
setSystemInfo(freshData);
|
||||
} catch (error) {
|
||||
console.error("Failed to update system info:", error);
|
||||
} catch (error: any) {
|
||||
if (error.name !== "AbortError") {
|
||||
console.error("Failed to update system info:", error);
|
||||
}
|
||||
} finally {
|
||||
setIsUpdating(false);
|
||||
if (!abortControllerRef.current?.signal.aborted) {
|
||||
setIsUpdating(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const unsubscribe = subscribe((event: SSEEvent) => {
|
||||
if (event.type === "system-stats") {
|
||||
if (event.type === "system-stats" && event.data !== null) {
|
||||
setSystemInfo(event.data);
|
||||
}
|
||||
});
|
||||
@@ -105,30 +125,42 @@ export const SystemInfoCard = ({
|
||||
};
|
||||
|
||||
updateTime();
|
||||
updateSystemInfo();
|
||||
|
||||
if (isPageVisible) {
|
||||
updateSystemInfo();
|
||||
}
|
||||
|
||||
const updateInterval = parseInt(
|
||||
process.env.NEXT_PUBLIC_CLOCK_UPDATE_INTERVAL || "30000"
|
||||
);
|
||||
|
||||
let mounted = true;
|
||||
let timeoutId: NodeJS.Timeout | null = null;
|
||||
|
||||
const doUpdate = () => {
|
||||
if (!mounted) return;
|
||||
if (!mounted || !isPageVisible || isDisabled) return;
|
||||
updateTime();
|
||||
updateSystemInfo().finally(() => {
|
||||
if (mounted) {
|
||||
setTimeout(doUpdate, updateInterval);
|
||||
if (mounted && isPageVisible && !isDisabled) {
|
||||
timeoutId = setTimeout(doUpdate, updateInterval);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
setTimeout(doUpdate, updateInterval);
|
||||
if (isPageVisible && !isDisabled) {
|
||||
timeoutId = setTimeout(doUpdate, updateInterval);
|
||||
}
|
||||
|
||||
return () => {
|
||||
mounted = false;
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
if (abortControllerRef.current) {
|
||||
abortControllerRef.current.abort();
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
}, [isPageVisible, isDisabled]);
|
||||
|
||||
const quickStats = {
|
||||
cpu: systemInfo.cpu.usage,
|
||||
@@ -138,52 +170,51 @@ export const SystemInfoCard = ({
|
||||
|
||||
const basicInfoItems = [
|
||||
{
|
||||
icon: Clock,
|
||||
icon: ClockIcon,
|
||||
label: t("sidebar.uptime"),
|
||||
value: systemInfo.uptime,
|
||||
color: "text-orange-500",
|
||||
},
|
||||
];
|
||||
|
||||
const performanceItems = [
|
||||
{
|
||||
icon: HardDrive,
|
||||
icon: HardDriveIcon,
|
||||
label: t("sidebar.memory"),
|
||||
value: `${systemInfo.memory.used} / ${systemInfo.memory.total}`,
|
||||
detail: `${systemInfo.memory.free} free`,
|
||||
status: systemInfo.memory.status,
|
||||
color: "text-cyan-500",
|
||||
showProgress: true,
|
||||
progressValue: systemInfo.memory.usage,
|
||||
},
|
||||
{
|
||||
icon: Cpu,
|
||||
icon: CpuIcon,
|
||||
label: t("sidebar.cpu"),
|
||||
value: systemInfo.cpu.model,
|
||||
detail: `${systemInfo.cpu.cores} cores`,
|
||||
status: systemInfo.cpu.status,
|
||||
color: "text-pink-500",
|
||||
showProgress: true,
|
||||
progressValue: systemInfo.cpu.usage,
|
||||
},
|
||||
{
|
||||
icon: Monitor,
|
||||
icon: MonitorIcon,
|
||||
label: t("sidebar.gpu"),
|
||||
value: systemInfo.gpu.model,
|
||||
detail: systemInfo.gpu.memory
|
||||
? `${systemInfo.gpu.memory} VRAM`
|
||||
: systemInfo.gpu.status,
|
||||
status: systemInfo.gpu.status,
|
||||
color: "text-indigo-500",
|
||||
},
|
||||
...(systemInfo.network ? [{
|
||||
icon: Wifi,
|
||||
label: t("sidebar.network"),
|
||||
value: `${systemInfo.network.latency}ms`,
|
||||
detail: `${systemInfo.network.latency}ms latency • ${systemInfo.network.speed}`,
|
||||
status: systemInfo.network.status,
|
||||
color: "text-teal-500",
|
||||
}] : []),
|
||||
...(systemInfo.network
|
||||
? [
|
||||
{
|
||||
icon: WifiHighIcon,
|
||||
label: t("sidebar.network"),
|
||||
value: `${systemInfo.network.latency}ms`,
|
||||
detail: `${systemInfo.network.latency}ms latency • ${systemInfo.network.speed}`,
|
||||
status: systemInfo.network.status,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
];
|
||||
|
||||
const performanceMetrics = [
|
||||
@@ -197,18 +228,19 @@ export const SystemInfoCard = ({
|
||||
value: `${systemInfo.memory.usage}%`,
|
||||
status: systemInfo.memory.status,
|
||||
},
|
||||
...(systemInfo.network ? [{
|
||||
label: t("sidebar.networkLatency"),
|
||||
value: `${systemInfo.network.latency}ms`,
|
||||
status: systemInfo.network.status,
|
||||
}] : []),
|
||||
...(systemInfo.network
|
||||
? [
|
||||
{
|
||||
label: t("sidebar.networkLatency"),
|
||||
value: `${systemInfo.network.latency}ms`,
|
||||
status: systemInfo.network.status,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
];
|
||||
|
||||
return (
|
||||
<Sidebar
|
||||
defaultCollapsed={false}
|
||||
quickStats={quickStats}
|
||||
>
|
||||
<Sidebar defaultCollapsed={false} quickStats={quickStats}>
|
||||
<SystemStatus
|
||||
status={systemInfo.systemStatus.overall}
|
||||
details={systemInfo.systemStatus.details}
|
||||
@@ -227,7 +259,6 @@ export const SystemInfoCard = ({
|
||||
icon={item.icon}
|
||||
label={item.label}
|
||||
value={item.value}
|
||||
color={item.color}
|
||||
variant="basic"
|
||||
/>
|
||||
))}
|
||||
@@ -238,7 +269,7 @@ export const SystemInfoCard = ({
|
||||
<h3 className="text-xs font-semibold text-foreground mb-2 uppercase tracking-wide">
|
||||
{t("sidebar.performanceMetrics")}
|
||||
</h3>
|
||||
<div className="space-y-2">
|
||||
<div className="space-y-4">
|
||||
{performanceItems.map((item) => (
|
||||
<MetricCard
|
||||
key={item.label}
|
||||
@@ -247,7 +278,6 @@ export const SystemInfoCard = ({
|
||||
value={item.value}
|
||||
detail={item.detail}
|
||||
status={item.status}
|
||||
color={item.color}
|
||||
variant="performance"
|
||||
showProgress={item.showProgress}
|
||||
progressValue={item.progressValue}
|
||||
@@ -271,4 +301,4 @@ export const SystemInfoCard = ({
|
||||
</div>
|
||||
</Sidebar>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { cn } from "@/app/_utils/global-utils";
|
||||
import { HTMLAttributes, forwardRef } from "react";
|
||||
import { Activity } from "lucide-react";
|
||||
import { PulseIcon } from "@phosphor-icons/react";
|
||||
import { useTranslations } from "next-intl";
|
||||
|
||||
export interface SystemStatusProps extends HTMLAttributes<HTMLDivElement> {
|
||||
@@ -22,27 +22,27 @@ export const SystemStatus = forwardRef<HTMLDivElement, SystemStatusProps>(
|
||||
switch (lowerStatus) {
|
||||
case "operational":
|
||||
return {
|
||||
bgColor: "bg-emerald-500/10",
|
||||
borderColor: "border-emerald-500/20",
|
||||
dotColor: "bg-emerald-500",
|
||||
bgColor: "bg-background0",
|
||||
borderColor: "ascii-border",
|
||||
dotColor: "bg-status-success",
|
||||
};
|
||||
case "warning":
|
||||
return {
|
||||
bgColor: "bg-yellow-500/10",
|
||||
borderColor: "border-yellow-500/20",
|
||||
dotColor: "bg-yellow-500",
|
||||
bgColor: "bg-background0",
|
||||
borderColor: "ascii-border",
|
||||
dotColor: "bg-status-warning",
|
||||
};
|
||||
case "critical":
|
||||
return {
|
||||
bgColor: "bg-destructive/10",
|
||||
borderColor: "border-destructive/20",
|
||||
dotColor: "bg-destructive",
|
||||
bgColor: "bg-background0",
|
||||
borderColor: "ascii-border",
|
||||
dotColor: "bg-status-error",
|
||||
};
|
||||
default:
|
||||
return {
|
||||
bgColor: "bg-muted",
|
||||
borderColor: "border-border",
|
||||
dotColor: "bg-muted-foreground",
|
||||
bgColor: "bg-background0",
|
||||
borderColor: "ascii-border",
|
||||
dotColor: "bg-status-success",
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -53,7 +53,7 @@ export const SystemStatus = forwardRef<HTMLDivElement, SystemStatusProps>(
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"p-4 border border-border/50 rounded-lg glass-card",
|
||||
"p-4 glass-card terminal-font",
|
||||
config.bgColor,
|
||||
config.borderColor,
|
||||
className
|
||||
@@ -61,10 +61,10 @@ export const SystemStatus = forwardRef<HTMLDivElement, SystemStatusProps>(
|
||||
{...props}
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
<div className={cn("w-3 h-3 rounded-full", config.dotColor)} />
|
||||
<div className={cn("w-3 h-3", config.dotColor)} />
|
||||
<div className="flex-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<Activity className="h-4 w-4 text-muted-foreground" />
|
||||
<PulseIcon className="h-4 w-4 text-muted-foreground" />
|
||||
<span className="text-sm font-medium text-foreground">
|
||||
{t("system.systemStatus")}: {status}
|
||||
</span>
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { WarningIcon, XIcon } from "@phosphor-icons/react";
|
||||
|
||||
export const WrapperScriptWarning = () => {
|
||||
const [isVisible, setIsVisible] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const t = useTranslations();
|
||||
|
||||
useEffect(() => {
|
||||
const dismissed = localStorage.getItem("wrapper-warning-dismissed");
|
||||
if (dismissed === "true") {
|
||||
setIsLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
checkWrapperScriptModification();
|
||||
}, []);
|
||||
|
||||
const checkWrapperScriptModification = async () => {
|
||||
try {
|
||||
const response = await fetch("/api/system/wrapper-check");
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
setIsVisible(data.modified);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to check wrapper script:", error);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const dismissWarning = () => {
|
||||
setIsVisible(false);
|
||||
localStorage.setItem("wrapper-warning-dismissed", "true");
|
||||
};
|
||||
|
||||
if (isLoading || !isVisible) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="bg-amber-500/10 border border-amber-500/20 rounded-lg p-4 mb-4">
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="flex items-start space-x-3">
|
||||
<WarningIcon className="w-5 h-5 text-amber-500 mt-0.5 flex-shrink-0" />
|
||||
<div className="flex-1">
|
||||
<h3 className="text-sm font-medium text-amber-800 dark:text-amber-400">
|
||||
{t("warnings.wrapperScriptModified")}
|
||||
</h3>
|
||||
<p className="text-sm text-amber-700 dark:text-amber-500 mt-1">
|
||||
{t("warnings.wrapperScriptModifiedDescription")}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
onClick={dismissWarning}
|
||||
className="text-amber-600 dark:text-amber-400 hover:text-amber-800 dark:hover:text-amber-300 transition-colors ml-4"
|
||||
aria-label="Dismiss warning"
|
||||
>
|
||||
<XIcon className="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -1,9 +1,8 @@
|
||||
'use client'
|
||||
|
||||
import { Moon, Sun } from 'lucide-react';
|
||||
import { useTheme } from 'next-themes';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Button } from '@/app/_components/GlobalComponents/UIElements/Button';
|
||||
import { SunIcon, MoonIcon } from '@phosphor-icons/react';
|
||||
|
||||
export const ThemeToggle = () => {
|
||||
const [mounted, setMounted] = useState(false);
|
||||
@@ -13,19 +12,22 @@ export const ThemeToggle = () => {
|
||||
setMounted(true);
|
||||
}, []);
|
||||
|
||||
if (!mounted) {
|
||||
return null;
|
||||
}
|
||||
if (!mounted) return null;
|
||||
|
||||
const isDark = theme === 'dark';
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')}
|
||||
<button
|
||||
onClick={() => setTheme(isDark ? 'light' : 'dark')}
|
||||
className="p-2 ascii-border bg-background0 hover:bg-background1 transition-colors"
|
||||
aria-label={isDark ? 'Switch to light mode' : 'Switch to dark mode'}
|
||||
title={isDark ? 'Switch to light mode' : 'Switch to dark mode'}
|
||||
>
|
||||
<Sun className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
|
||||
<Moon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
|
||||
<span className="sr-only">Toggle theme</span>
|
||||
</Button>
|
||||
{isDark ? (
|
||||
<SunIcon size={20} weight="regular" className="text-foreground" />
|
||||
) : (
|
||||
<MoonIcon size={20} weight="regular" className="text-foreground" />
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { Button } from "@/app/_components/GlobalComponents/UIElements/Button";
|
||||
import { ChevronDown, User, X } from "lucide-react";
|
||||
import { CaretDownIcon, UserIcon, XIcon } from "@phosphor-icons/react";
|
||||
import { fetchAvailableUsers } from "@/app/_server/actions/cronjobs";
|
||||
import { useTranslations } from "next-intl";
|
||||
|
||||
@@ -42,7 +42,7 @@ export const UserFilter = ({
|
||||
<div
|
||||
className={`flex items-center gap-2 px-3 py-2 bg-muted/50 rounded-md ${className}`}
|
||||
>
|
||||
<User className="h-4 w-4 text-muted-foreground" />
|
||||
<UserIcon className="h-4 w-4 text-muted-foreground" />
|
||||
<span className="text-sm text-muted-foreground">Loading users...</span>
|
||||
</div>
|
||||
);
|
||||
@@ -50,41 +50,42 @@ export const UserFilter = ({
|
||||
|
||||
return (
|
||||
<div className={`relative ${className}`}>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setIsOpen(!isOpen)}
|
||||
className="w-full justify-between"
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<User className="h-4 w-4" />
|
||||
<span className="text-sm">
|
||||
{selectedUser ? `${t("common.userWithUsername", { user: selectedUser })}` : t("common.allUsers")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
{selectedUser && (
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onUserChange(null);
|
||||
}}
|
||||
className="p-1 hover:bg-accent rounded"
|
||||
>
|
||||
<X className="h-3 w-3" />
|
||||
</button>
|
||||
)}
|
||||
<ChevronDown className="h-4 w-4" />
|
||||
</div>
|
||||
</Button>
|
||||
<div className="flex items-center gap-1">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setIsOpen(!isOpen)}
|
||||
className="flex-1 justify-between"
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<UserIcon className="h-4 w-4" />
|
||||
<span className="text-sm">
|
||||
{selectedUser
|
||||
? `${t("common.userWithUsername", { user: selectedUser })}`
|
||||
: t("common.allUsers")}
|
||||
</span>
|
||||
</div>
|
||||
<CaretDownIcon className="h-4 w-4" />
|
||||
</Button>
|
||||
{selectedUser && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => onUserChange(null)}
|
||||
className="p-2 h-8 w-8 flex-shrink-0"
|
||||
>
|
||||
<XIcon className="h-3 w-3" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{isOpen && (
|
||||
<div className="absolute top-full left-0 right-0 mt-1 bg-background border border-border rounded-md shadow-lg z-50 max-h-48 overflow-y-auto">
|
||||
<div className="absolute top-full left-0 right-0 p-1 mt-1 bg-background0 border border-border rounded-md shadow-lg z-50 max-h-48 overflow-y-auto tui-scrollbar">
|
||||
<button
|
||||
onClick={() => {
|
||||
onUserChange(null);
|
||||
setIsOpen(false);
|
||||
}}
|
||||
className={`w-full text-left px-3 py-2 text-sm hover:bg-accent transition-colors ${!selectedUser ? "bg-accent text-accent-foreground" : ""
|
||||
className={`w-full text-left px-3 py-2 text-sm hover:border-border transition-colors ${!selectedUser ? "border border-border" : "border border-transparent"
|
||||
}`}
|
||||
>
|
||||
{t("common.allUsers")}
|
||||
@@ -96,7 +97,7 @@ export const UserFilter = ({
|
||||
onUserChange(user);
|
||||
setIsOpen(false);
|
||||
}}
|
||||
className={`w-full text-left px-3 py-2 text-sm hover:bg-accent transition-colors ${selectedUser === user ? "bg-accent text-accent-foreground" : ""
|
||||
className={`w-full text-left px-3 py-2 text-sm border border-transparent hover:border-border transition-colors ${selectedUser === user ? "border border-border" : "border border-transparent"
|
||||
}`}
|
||||
>
|
||||
{user}
|
||||
@@ -106,4 +107,4 @@ export const UserFilter = ({
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { Button } from "@/app/_components/GlobalComponents/UIElements/Button";
|
||||
import { ChevronDown, User } from "lucide-react";
|
||||
import { CaretDownIcon, UserIcon } from "@phosphor-icons/react";
|
||||
import { fetchAvailableUsers } from "@/app/_server/actions/cronjobs";
|
||||
|
||||
interface UserSwitcherProps {
|
||||
@@ -43,7 +43,7 @@ export const UserSwitcher = ({
|
||||
<div
|
||||
className={`flex items-center gap-2 px-3 py-2 bg-muted/50 rounded-md ${className}`}
|
||||
>
|
||||
<User className="h-4 w-4 text-muted-foreground" />
|
||||
<UserIcon className="h-4 w-4 text-muted-foreground" />
|
||||
<span className="text-sm text-muted-foreground">Loading users...</span>
|
||||
</div>
|
||||
);
|
||||
@@ -52,27 +52,35 @@ export const UserSwitcher = ({
|
||||
return (
|
||||
<div className={`relative ${className}`}>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => setIsOpen(!isOpen)}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setIsOpen(!isOpen);
|
||||
}}
|
||||
className="w-full justify-between"
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<User className="h-4 w-4" />
|
||||
<UserIcon className="h-4 w-4" />
|
||||
<span className="text-sm">{selectedUser || "Select user"}</span>
|
||||
</div>
|
||||
<ChevronDown className="h-4 w-4" />
|
||||
<CaretDownIcon className="h-4 w-4" />
|
||||
</Button>
|
||||
|
||||
{isOpen && (
|
||||
<div className="absolute top-full left-0 right-0 mt-1 bg-background border border-border rounded-md shadow-lg z-50 max-h-48 overflow-y-auto">
|
||||
<div className="absolute top-full left-0 right-0 mt-1 bg-background0 border border-border rounded-md shadow-lg z-50 max-h-48 overflow-y-auto tui-scrollbar">
|
||||
{users.map((user) => (
|
||||
<button
|
||||
type="button"
|
||||
key={user}
|
||||
onClick={() => {
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
onUserChange(user);
|
||||
setIsOpen(false);
|
||||
}}
|
||||
className={`w-full text-left px-3 py-2 text-sm hover:bg-accent transition-colors ${selectedUser === user ? "bg-accent text-accent-foreground" : ""
|
||||
className={`w-full text-left px-3 py-2 text-sm hover:bg-accent transition-colors ${selectedUser === user ? "border border-border" : "border border-transparent"
|
||||
}`}
|
||||
>
|
||||
{user}
|
||||
@@ -82,4 +90,4 @@ export const UserSwitcher = ({
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { AlertCircle, X } from "lucide-react";
|
||||
import { WarningCircleIcon, XIcon } from "@phosphor-icons/react";
|
||||
import { JobError, removeJobError } from "@/app/_utils/error-utils";
|
||||
|
||||
interface ErrorBadgeProps {
|
||||
@@ -30,7 +30,7 @@ export const ErrorBadge = ({
|
||||
className="flex items-center gap-1 px-2 py-1 bg-destructive/10 text-destructive border border-destructive/20 rounded text-xs hover:bg-destructive/20 transition-colors"
|
||||
title={error.message}
|
||||
>
|
||||
<AlertCircle className="h-3 w-3" />
|
||||
<WarningCircleIcon className="h-3 w-3" />
|
||||
<span className="hidden sm:inline">Error</span>
|
||||
</button>
|
||||
<button
|
||||
@@ -38,7 +38,7 @@ export const ErrorBadge = ({
|
||||
className="p-1 text-destructive hover:bg-destructive/10 rounded transition-colors"
|
||||
title="Dismiss error"
|
||||
>
|
||||
<X className="h-3 w-3" />
|
||||
<XIcon className="h-3 w-3" />
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { cn } from "@/app/_utils/global-utils";
|
||||
import { HTMLAttributes, forwardRef } from "react";
|
||||
import { CheckCircle, AlertTriangle, XCircle, Activity } from "lucide-react";
|
||||
import { CheckCircleIcon, WarningIcon, XCircleIcon, PulseIcon } from "@phosphor-icons/react";
|
||||
import { useTranslations } from "next-intl";
|
||||
|
||||
export interface StatusBadgeProps extends HTMLAttributes<HTMLDivElement> {
|
||||
@@ -31,46 +31,41 @@ export const StatusBadge = forwardRef<HTMLDivElement, StatusBadgeProps>(
|
||||
case "operational":
|
||||
case "stable":
|
||||
return {
|
||||
color: "text-emerald-500",
|
||||
bgColor: "bg-emerald-500/10",
|
||||
borderColor: "border-emerald-500/20",
|
||||
icon: CheckCircle,
|
||||
color: "text-status-success",
|
||||
bgColor: "bg-background0",
|
||||
icon: CheckCircleIcon,
|
||||
label: t("system.optimal"),
|
||||
};
|
||||
case "moderate":
|
||||
case "warning":
|
||||
return {
|
||||
color: "text-yellow-500",
|
||||
bgColor: "bg-yellow-500/10",
|
||||
borderColor: "border-yellow-500/20",
|
||||
icon: AlertTriangle,
|
||||
color: "text-status-warning",
|
||||
bgColor: "bg-background0",
|
||||
icon: WarningIcon,
|
||||
label: t("system.warning"),
|
||||
};
|
||||
case "high":
|
||||
case "slow":
|
||||
return {
|
||||
color: "text-orange-500",
|
||||
bgColor: "bg-orange-500/10",
|
||||
borderColor: "border-orange-500/20",
|
||||
icon: AlertTriangle,
|
||||
color: "text-status-warning",
|
||||
bgColor: "bg-background0",
|
||||
icon: WarningIcon,
|
||||
label: t("system.high"),
|
||||
};
|
||||
case "critical":
|
||||
case "poor":
|
||||
case "offline":
|
||||
return {
|
||||
color: "text-destructive",
|
||||
bgColor: "bg-destructive/10",
|
||||
borderColor: "border-destructive/20",
|
||||
icon: XCircle,
|
||||
color: "text-status-error",
|
||||
bgColor: "bg-background0",
|
||||
icon: XCircleIcon,
|
||||
label: t("system.critical"),
|
||||
};
|
||||
default:
|
||||
return {
|
||||
color: "text-muted-foreground",
|
||||
bgColor: "bg-muted",
|
||||
borderColor: "border-border",
|
||||
icon: Activity,
|
||||
color: "",
|
||||
bgColor: "bg-background0",
|
||||
icon: PulseIcon,
|
||||
label: t("system.unknown"),
|
||||
};
|
||||
}
|
||||
@@ -83,9 +78,8 @@ export const StatusBadge = forwardRef<HTMLDivElement, StatusBadgeProps>(
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"inline-flex items-center gap-1.5 rounded-full border px-2 py-1",
|
||||
"inline-flex items-center gap-1.5 ascii-border px-2 py-1 terminal-font",
|
||||
config.bgColor,
|
||||
config.borderColor,
|
||||
{
|
||||
"text-xs": size === "sm",
|
||||
"text-sm": size === "md",
|
||||
|
||||
@@ -1,72 +1,43 @@
|
||||
import { cn } from '@/app/_utils/global-utils';
|
||||
import { HTMLAttributes, forwardRef } from 'react';
|
||||
|
||||
export const Card = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(
|
||||
({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'rounded-lg border bg-card text-card-foreground shadow-sm',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
({ className = '', ...props }, ref) => (
|
||||
<div ref={ref} className={`tui-card ${className}`} {...props} />
|
||||
)
|
||||
);
|
||||
Card.displayName = 'Card';
|
||||
|
||||
const CardHeader = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(
|
||||
({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn('flex flex-col space-y-1.5 p-6', className)}
|
||||
{...props}
|
||||
/>
|
||||
export const CardHeader = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(
|
||||
({ className = '', ...props }, ref) => (
|
||||
<div ref={ref} className={`p-4 border-b border-foreground1 ${className}`} {...props} />
|
||||
)
|
||||
);
|
||||
CardHeader.displayName = 'CardHeader';
|
||||
|
||||
const CardTitle = forwardRef<HTMLParagraphElement, HTMLAttributes<HTMLHeadingElement>>(
|
||||
({ className, ...props }, ref) => (
|
||||
<h3
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'text-2xl font-semibold leading-none tracking-tight',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
export const CardTitle = forwardRef<HTMLHeadingElement, HTMLAttributes<HTMLHeadingElement>>(
|
||||
({ className = '', ...props }, ref) => (
|
||||
<h3 ref={ref} className={`terminal-font font-bold uppercase ${className}`} {...props} />
|
||||
)
|
||||
);
|
||||
CardTitle.displayName = 'CardTitle';
|
||||
|
||||
const CardDescription = forwardRef<HTMLParagraphElement, HTMLAttributes<HTMLParagraphElement>>(
|
||||
({ className, ...props }, ref) => (
|
||||
<p
|
||||
ref={ref}
|
||||
className={cn('text-sm text-muted-foreground', className)}
|
||||
{...props}
|
||||
/>
|
||||
export const CardDescription = forwardRef<HTMLParagraphElement, HTMLAttributes<HTMLParagraphElement>>(
|
||||
({ className = '', ...props }, ref) => (
|
||||
<p ref={ref} className={`terminal-font text-sm ${className}`} {...props} />
|
||||
)
|
||||
);
|
||||
CardDescription.displayName = 'CardDescription';
|
||||
|
||||
const CardContent = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(
|
||||
({ className, ...props }, ref) => (
|
||||
<div ref={ref} className={cn('p-4 lg:p-6 pt-0', className)} {...props} />
|
||||
export const CardContent = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(
|
||||
({ className = '', ...props }, ref) => (
|
||||
<div ref={ref} className={`p-4 ${className}`} {...props} />
|
||||
)
|
||||
);
|
||||
CardContent.displayName = 'CardContent';
|
||||
|
||||
const CardFooter = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(
|
||||
({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn('flex items-center p-6 pt-0', className)}
|
||||
{...props}
|
||||
/>
|
||||
export const CardFooter = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(
|
||||
({ className = '', ...props }, ref) => (
|
||||
<div ref={ref} className={`flex items-center p-4 border-t border-foreground1 ${className}`} {...props} />
|
||||
)
|
||||
);
|
||||
CardFooter.displayName = 'CardFooter';
|
||||
|
||||
export { CardHeader, CardFooter, CardTitle, CardDescription, CardContent };
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { cn } from "@/app/_utils/global-utils";
|
||||
import { HTMLAttributes, forwardRef } from "react";
|
||||
import { LucideIcon } from "lucide-react";
|
||||
import { HTMLAttributes, forwardRef, ComponentType } from "react";
|
||||
import { IconProps } from "@phosphor-icons/react";
|
||||
import { StatusBadge } from "@/app/_components/GlobalComponents/Badges/StatusBadge";
|
||||
import { ProgressBar } from "@/app/_components/GlobalComponents/UIElements/ProgressBar";
|
||||
import { TruncatedText } from "@/app/_components/GlobalComponents/UIElements/TruncatedText";
|
||||
|
||||
export interface MetricCardProps extends HTMLAttributes<HTMLDivElement> {
|
||||
icon: LucideIcon;
|
||||
icon: ComponentType<IconProps>;
|
||||
label: string;
|
||||
value: string;
|
||||
detail?: string;
|
||||
@@ -27,7 +27,7 @@ export const MetricCard = forwardRef<HTMLDivElement, MetricCardProps>(
|
||||
value,
|
||||
detail,
|
||||
status,
|
||||
color = "text-blue-500",
|
||||
color,
|
||||
variant = "basic",
|
||||
showProgress = false,
|
||||
progressValue = 0,
|
||||
@@ -40,14 +40,14 @@ export const MetricCard = forwardRef<HTMLDivElement, MetricCardProps>(
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex items-start gap-3 p-3 border border-border/50 rounded-lg hover:bg-accent/50 transition-colors duration-200 glass-card-hover",
|
||||
"flex items-start gap-3 p-3 tui-card-mini transition-colors duration-200 terminal-font",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
"p-2 rounded-lg border border-border/50 flex-shrink-0 bg-card/50"
|
||||
"p-2 ascii-border flex-shrink-0 bg-background0"
|
||||
)}
|
||||
>
|
||||
<Icon className={cn("h-4 w-4", color)} />
|
||||
@@ -55,7 +55,7 @@ export const MetricCard = forwardRef<HTMLDivElement, MetricCardProps>(
|
||||
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<p className="text-xs font-medium text-muted-foreground uppercase tracking-wide">
|
||||
<p className="text-xs font-medium uppercase tracking-wide terminal-font">
|
||||
{label}
|
||||
</p>
|
||||
{status && variant === "performance" && (
|
||||
@@ -67,12 +67,12 @@ export const MetricCard = forwardRef<HTMLDivElement, MetricCardProps>(
|
||||
<TruncatedText
|
||||
text={value}
|
||||
maxLength={40}
|
||||
className="text-sm font-medium text-foreground"
|
||||
className="text-sm font-medium terminal-font"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{detail && (
|
||||
<p className="text-xs text-muted-foreground mb-2">{detail}</p>
|
||||
<p className="text-xs mb-2 terminal-font">{detail}</p>
|
||||
)}
|
||||
|
||||
{showProgress && (
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
import { cn } from '@/app/_utils/global-utils';
|
||||
import { InputHTMLAttributes, forwardRef } from 'react';
|
||||
|
||||
export interface InputProps extends InputHTMLAttributes<HTMLInputElement> { }
|
||||
export interface InputProps extends InputHTMLAttributes<HTMLInputElement> {}
|
||||
|
||||
export const Input = forwardRef<HTMLInputElement, InputProps>(
|
||||
({ className, type, ...props }, ref) => {
|
||||
({ className = '', ...props }, ref) => {
|
||||
return (
|
||||
<input
|
||||
type={type}
|
||||
className={cn(
|
||||
'flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
|
||||
className
|
||||
)}
|
||||
className={`terminal-font ascii-border px-3 py-2 bg-background0 w-full ${className}`}
|
||||
ref={ref}
|
||||
{...props}
|
||||
/>
|
||||
|
||||
46
app/_components/GlobalComponents/Logo/Logo.tsx
Normal file
46
app/_components/GlobalComponents/Logo/Logo.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
"use client";
|
||||
|
||||
import { AsteriskIcon, TerminalIcon } from "@phosphor-icons/react";
|
||||
|
||||
interface LogoProps {
|
||||
size?: number;
|
||||
showGlow?: boolean;
|
||||
}
|
||||
|
||||
export const Logo = ({ size = 48, showGlow = false }: LogoProps) => {
|
||||
const iconSize = size * 0.8;
|
||||
const asteriskSize = size * 0.4;
|
||||
const asteriskOffset = size * 0.08;
|
||||
|
||||
return (
|
||||
<div
|
||||
className="relative flex items-center justify-center flex-shrink-0"
|
||||
style={{ width: size, height: size }}
|
||||
>
|
||||
{showGlow && (
|
||||
<div
|
||||
className="absolute inset-0 bg-gradient-to-br from-primary/20 via-primary/10 to-transparent blur-xl"
|
||||
style={{ width: size, height: size }}
|
||||
/>
|
||||
)}
|
||||
|
||||
<div className="relative z-10 flex items-center justify-center w-full h-full">
|
||||
<TerminalIcon
|
||||
className="text-primary drop-shadow-[0_0_10px_rgba(var(--primary-rgb),0.4)]"
|
||||
weight="duotone"
|
||||
style={{ width: iconSize, height: iconSize }}
|
||||
/>
|
||||
<AsteriskIcon
|
||||
className="text-primary absolute drop-shadow-[0_0_8px_rgba(var(--primary-rgb),0.6)]"
|
||||
weight="bold"
|
||||
style={{
|
||||
width: asteriskSize,
|
||||
height: asteriskSize,
|
||||
top: -asteriskOffset,
|
||||
right: -asteriskOffset
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -1,4 +1,3 @@
|
||||
import { cn } from '@/app/_utils/global-utils';
|
||||
import { ButtonHTMLAttributes, forwardRef } from 'react';
|
||||
|
||||
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
@@ -7,30 +6,31 @@ export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
}
|
||||
|
||||
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
({ className, variant = 'default', size = 'default', ...props }, ref) => {
|
||||
({ className = '', variant = 'default', size = 'default', children, ...props }, ref) => {
|
||||
const baseClasses = 'terminal-font border border-border px-4 py-2 cursor-pointer inline-flex items-center justify-center disabled:opacity-50 disabled:cursor-not-allowed';
|
||||
const variantClasses = {
|
||||
default: 'bg-background1 hover:bg-background2',
|
||||
destructive: 'text-status-error hover:bg-status-error hover:text-white',
|
||||
outline: 'bg-background0 hover:bg-background1',
|
||||
secondary: 'bg-background2 hover:bg-background1',
|
||||
ghost: 'border-0 bg-transparent hover:bg-background1',
|
||||
link: 'border-0 underline bg-transparent',
|
||||
};
|
||||
const sizeClasses = {
|
||||
default: '',
|
||||
sm: 'px-2 py-1 text-sm',
|
||||
lg: 'px-6 py-3',
|
||||
icon: 'p-2',
|
||||
};
|
||||
|
||||
return (
|
||||
<button
|
||||
className={cn(
|
||||
'inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
|
||||
{
|
||||
'bg-primary text-primary-foreground hover:bg-primary/90': variant === 'default',
|
||||
'bg-destructive text-destructive-foreground hover:bg-destructive/90': variant === 'destructive',
|
||||
'border border-input bg-background hover:bg-accent hover:text-accent-foreground': variant === 'outline',
|
||||
'bg-secondary text-secondary-foreground hover:bg-secondary/80': variant === 'secondary',
|
||||
'hover:bg-accent hover:text-accent-foreground': variant === 'ghost',
|
||||
'text-primary underline-offset-4 hover:underline': variant === 'link',
|
||||
},
|
||||
{
|
||||
'h-10 px-4 py-2': size === 'default',
|
||||
'h-9 rounded-md px-3': size === 'sm',
|
||||
'h-11 rounded-md px-8': size === 'lg',
|
||||
'h-10 w-10': size === 'icon',
|
||||
},
|
||||
className
|
||||
)}
|
||||
className={`${baseClasses} ${variantClasses[variant]} ${sizeClasses[size]} ${className}`}
|
||||
ref={ref}
|
||||
{...props}
|
||||
/>
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
128
app/_components/GlobalComponents/UIElements/DropdownMenu.tsx
Normal file
128
app/_components/GlobalComponents/UIElements/DropdownMenu.tsx
Normal file
@@ -0,0 +1,128 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useRef, useEffect, ReactNode } from "react";
|
||||
import { Button } from "@/app/_components/GlobalComponents/UIElements/Button";
|
||||
import { DotsThreeVerticalIcon } from "@phosphor-icons/react";
|
||||
|
||||
const DROPDOWN_HEIGHT = 200;
|
||||
|
||||
interface DropdownMenuItem {
|
||||
label: string;
|
||||
icon?: ReactNode;
|
||||
onClick: () => void;
|
||||
disabled?: boolean;
|
||||
variant?: "default" | "destructive";
|
||||
}
|
||||
|
||||
interface DropdownMenuProps {
|
||||
items: DropdownMenuItem[];
|
||||
triggerLabel?: string;
|
||||
triggerIcon?: ReactNode;
|
||||
triggerClassName?: string;
|
||||
onOpenChange?: (isOpen: boolean) => void;
|
||||
}
|
||||
|
||||
export const DropdownMenu = ({
|
||||
items,
|
||||
triggerLabel,
|
||||
triggerIcon = <DotsThreeVerticalIcon className="h-3 w-3" />,
|
||||
triggerClassName = "btn-outline h-8 px-3",
|
||||
onOpenChange,
|
||||
}: DropdownMenuProps) => {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [positionAbove, setPositionAbove] = useState(false);
|
||||
const dropdownRef = useRef<HTMLDivElement>(null);
|
||||
const triggerRef = useRef<HTMLButtonElement>(null);
|
||||
|
||||
const handleOpenChange = (open: boolean) => {
|
||||
if (open && triggerRef.current) {
|
||||
const rect = triggerRef.current.getBoundingClientRect();
|
||||
const viewportHeight = window.innerHeight;
|
||||
const spaceBelow = viewportHeight - rect.bottom;
|
||||
const spaceAbove = rect.top;
|
||||
|
||||
setPositionAbove(spaceBelow < DROPDOWN_HEIGHT && spaceAbove > spaceBelow);
|
||||
}
|
||||
setIsOpen(open);
|
||||
onOpenChange?.(open);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const handleClickOutside = (event: MouseEvent) => {
|
||||
if (
|
||||
dropdownRef.current &&
|
||||
!dropdownRef.current.contains(event.target as Node)
|
||||
) {
|
||||
handleOpenChange(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleEscape = (event: KeyboardEvent) => {
|
||||
if (event.key === "Escape") {
|
||||
handleOpenChange(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (isOpen) {
|
||||
document.addEventListener("mousedown", handleClickOutside);
|
||||
document.addEventListener("keydown", handleEscape);
|
||||
}
|
||||
|
||||
return () => {
|
||||
document.removeEventListener("mousedown", handleClickOutside);
|
||||
document.removeEventListener("keydown", handleEscape);
|
||||
};
|
||||
}, [isOpen]);
|
||||
|
||||
const handleItemClick = (item: DropdownMenuItem) => {
|
||||
if (!item.disabled) {
|
||||
item.onClick();
|
||||
handleOpenChange(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="relative inline-block" ref={dropdownRef}>
|
||||
<Button
|
||||
ref={triggerRef}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => handleOpenChange(!isOpen)}
|
||||
className={triggerClassName}
|
||||
aria-label={triggerLabel || "Open menu"}
|
||||
title={triggerLabel || "Open menu"}
|
||||
>
|
||||
{triggerIcon}
|
||||
{triggerLabel && <span className="ml-2">{triggerLabel}</span>}
|
||||
</Button>
|
||||
|
||||
{isOpen && (
|
||||
<div
|
||||
className={`absolute right-0 w-56 ascii-border bg-background0 shadow-lg z-[9999] overflow-hidden terminal-font ${positionAbove ? "bottom-full mb-2" : "top-full mt-2"
|
||||
}`}
|
||||
>
|
||||
<div className="p-1">
|
||||
{items.map((item, index) => (
|
||||
<button
|
||||
key={index}
|
||||
onClick={() => handleItemClick(item)}
|
||||
disabled={item.disabled}
|
||||
className={`w-full flex items-center border border-transparent gap-3 px-4 py-2 text-sm transition-colors ${item.disabled
|
||||
? "opacity-50 cursor-not-allowed"
|
||||
: item.variant === "destructive"
|
||||
? "text-status-error hover:border hover:border-border"
|
||||
: "hover:border-border"
|
||||
}`}
|
||||
>
|
||||
{item.icon && (
|
||||
<span className="flex-shrink-0">{item.icon}</span>
|
||||
)}
|
||||
<span className="flex-1 text-left">{item.label}</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -1,18 +1,18 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef } from "react";
|
||||
import { X } from "lucide-react";
|
||||
import { cn } from "@/app/_utils/global-utils";
|
||||
import { Button } from "@/app/_components/GlobalComponents/UIElements/Button";
|
||||
import { XIcon } from "@phosphor-icons/react";
|
||||
import { Button } from "./Button";
|
||||
|
||||
interface ModalProps {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
title: string;
|
||||
children: React.ReactNode;
|
||||
size?: "sm" | "md" | "lg" | "xl";
|
||||
size?: "sm" | "md" | "lg" | "xl" | "2xl" | "3xl";
|
||||
showCloseButton?: boolean;
|
||||
preventCloseOnClickOutside?: boolean;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export const Modal = ({
|
||||
@@ -23,95 +23,53 @@ export const Modal = ({
|
||||
size = "md",
|
||||
showCloseButton = true,
|
||||
preventCloseOnClickOutside = false,
|
||||
className = "",
|
||||
}: ModalProps) => {
|
||||
const modalRef = useRef<HTMLDivElement>(null);
|
||||
const dialogRef = useRef<HTMLDialogElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const handleEscape = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape") {
|
||||
onClose();
|
||||
}
|
||||
};
|
||||
const dialog = dialogRef.current;
|
||||
if (!dialog) return;
|
||||
|
||||
if (isOpen) {
|
||||
document.addEventListener("keydown", handleEscape);
|
||||
dialog.showModal();
|
||||
document.body.style.overflow = "hidden";
|
||||
}
|
||||
|
||||
return () => {
|
||||
document.removeEventListener("keydown", handleEscape);
|
||||
} else {
|
||||
dialog.close();
|
||||
document.body.style.overflow = "unset";
|
||||
};
|
||||
}, [isOpen, onClose]);
|
||||
|
||||
useEffect(() => {
|
||||
const handleClickOutside = (event: MouseEvent) => {
|
||||
if (
|
||||
modalRef.current &&
|
||||
!modalRef.current.contains(event.target as Node) &&
|
||||
!preventCloseOnClickOutside
|
||||
) {
|
||||
const target = event.target as Element;
|
||||
const isClickingOnModal = target.closest('[data-modal="true"]');
|
||||
const isClickingOnBackdrop =
|
||||
target.classList.contains("modal-backdrop");
|
||||
|
||||
if (isClickingOnBackdrop) {
|
||||
onClose();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (isOpen) {
|
||||
document.addEventListener("mousedown", handleClickOutside);
|
||||
}
|
||||
|
||||
return () => {
|
||||
document.removeEventListener("mousedown", handleClickOutside);
|
||||
};
|
||||
}, [isOpen, onClose, preventCloseOnClickOutside]);
|
||||
|
||||
if (!isOpen) return null;
|
||||
}, [isOpen]);
|
||||
|
||||
const sizeClasses = {
|
||||
sm: "max-w-md",
|
||||
md: "max-w-lg",
|
||||
lg: "max-w-2xl",
|
||||
xl: "max-w-4xl",
|
||||
sm: "w-[600px]",
|
||||
md: "w-[800px]",
|
||||
lg: "w-[1000px]",
|
||||
xl: "w-[1200px]",
|
||||
"2xl": "w-[1400px]",
|
||||
"3xl": "w-[90vw]",
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className="fixed inset-0 z-50 flex items-end justify-center sm:items-center p-0 sm:p-4"
|
||||
data-modal="true"
|
||||
<dialog
|
||||
ref={dialogRef}
|
||||
className={`ascii-border terminal-font bg-background0 mobile-modal ${sizeClasses[size]} max-w-[95vw] ${className}`}
|
||||
onClick={(e) => {
|
||||
if (e.target === dialogRef.current && !preventCloseOnClickOutside) {
|
||||
onClose();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="absolute inset-0 bg-black/50 backdrop-blur-sm modal-backdrop" />
|
||||
|
||||
<div
|
||||
ref={modalRef}
|
||||
className={cn(
|
||||
"relative w-full bg-card border border-border shadow-lg overflow-y-auto",
|
||||
"max-h-[85vh]",
|
||||
"sm:rounded-lg sm:max-h-[90vh] sm:w-full",
|
||||
sizeClasses[size]
|
||||
<div className="border-border border-b p-4 flex justify-between items-center bg-background0">
|
||||
<h2 className="terminal-font font-bold uppercase">{title}</h2>
|
||||
{showCloseButton && (
|
||||
<Button variant="ghost" size="icon" onClick={onClose}>
|
||||
<XIcon className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
>
|
||||
<div className="flex items-center justify-between p-4 sm:p-6 border-b border-border sticky top-0 bg-card z-10">
|
||||
<h2 className="text-lg font-semibold text-foreground">{title}</h2>
|
||||
{showCloseButton && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={onClose}
|
||||
className="h-8 w-8"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="p-4 sm:p-6">{children}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="p-4 max-h-[70vh] overflow-y-auto tui-scrollbar bg-background0">
|
||||
{children}
|
||||
</div>
|
||||
</dialog>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -25,35 +25,29 @@ export const ProgressBar = forwardRef<HTMLDivElement, ProgressBarProps>(
|
||||
const percentage = Math.min(Math.max((value / max) * 100, 0), 100);
|
||||
|
||||
const getColorClass = (percentage: number) => {
|
||||
if (percentage >= 90) return "bg-destructive";
|
||||
if (percentage >= 80) return "bg-orange-500";
|
||||
if (percentage >= 70) return "bg-yellow-500";
|
||||
return "bg-emerald-500";
|
||||
if (percentage >= 90) return "bg-red-600";
|
||||
if (percentage >= 80) return "bg-yellow-600";
|
||||
if (percentage >= 70) return "bg-yellow-600";
|
||||
return "bg-green-600";
|
||||
};
|
||||
|
||||
const getGradientClass = (percentage: number) => {
|
||||
if (percentage >= 90)
|
||||
return "bg-gradient-to-r from-destructive to-red-600";
|
||||
if (percentage >= 80)
|
||||
return "bg-gradient-to-r from-orange-500 to-orange-600";
|
||||
if (percentage >= 70)
|
||||
return "bg-gradient-to-r from-yellow-500 to-yellow-600";
|
||||
return "bg-gradient-to-r from-emerald-500 to-emerald-600";
|
||||
return getColorClass(percentage);
|
||||
};
|
||||
|
||||
return (
|
||||
<div ref={ref} className={cn("w-full", className)} {...props}>
|
||||
<div ref={ref} className={cn("w-full terminal-font", className)} {...props}>
|
||||
{showLabel && (
|
||||
<div className="flex justify-between items-center mb-1">
|
||||
<span className="text-xs text-muted-foreground">Usage</span>
|
||||
<span className="text-xs font-medium text-foreground">
|
||||
<span className="text-xs">Usage</span>
|
||||
<span className="text-xs font-medium">
|
||||
{Math.round(percentage)}%
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div
|
||||
className={cn("w-full bg-muted rounded-full overflow-hidden", {
|
||||
className={cn("w-full bg-background2 ascii-border overflow-hidden", {
|
||||
"h-1.5": size === "sm",
|
||||
"h-2": size === "md",
|
||||
"h-3": size === "lg",
|
||||
|
||||
54
app/_components/GlobalComponents/UIElements/Switch.tsx
Normal file
54
app/_components/GlobalComponents/UIElements/Switch.tsx
Normal file
@@ -0,0 +1,54 @@
|
||||
"use client";
|
||||
|
||||
interface SwitchProps {
|
||||
checked: boolean;
|
||||
onCheckedChange: (checked: boolean) => void;
|
||||
className?: string;
|
||||
disabled?: boolean;
|
||||
id?: string;
|
||||
}
|
||||
|
||||
export const Switch = ({ checked, onCheckedChange, className = "", disabled = false, id }: SwitchProps) => {
|
||||
const handleClick = () => {
|
||||
if (!disabled) {
|
||||
onCheckedChange(!checked);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`inline-flex items-center ${disabled ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer'} ${className}`}
|
||||
onClick={handleClick}
|
||||
role="checkbox"
|
||||
aria-checked={checked}
|
||||
aria-labelledby={id}
|
||||
tabIndex={disabled ? -1 : 0}
|
||||
onKeyDown={(e) => {
|
||||
if (!disabled && (e.key === ' ' || e.key === 'Enter')) {
|
||||
e.preventDefault();
|
||||
handleClick();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="relative w-5 h-5 ascii-border bg-background0 transition-all focus-within:ring-2 focus-within:ring-primary/20 flex items-center justify-center group">
|
||||
{checked && (
|
||||
<svg
|
||||
className="w-3.5 h-3.5 text-primary transition-transform duration-200"
|
||||
viewBox="0 0 12 12"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M10 3L4.5 8.5L2 6"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="square"
|
||||
strokeLinejoin="miter"
|
||||
/>
|
||||
</svg>
|
||||
)}
|
||||
<div className="absolute inset-0 border border-primary/0 group-hover:border-primary/50 transition-colors pointer-events-none" />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { X, CheckCircle, AlertCircle, Info, AlertTriangle } from "lucide-react";
|
||||
import { XIcon, CheckCircleIcon, WarningCircleIcon, InfoIcon, WarningIcon } from "@phosphor-icons/react";
|
||||
import { cn } from "@/app/_utils/global-utils";
|
||||
import { ErrorDetailsModal } from "@/app/_components/FeatureComponents/Modals/ErrorDetailsModal";
|
||||
|
||||
@@ -30,19 +30,17 @@ interface ToastProps {
|
||||
}
|
||||
|
||||
const toastIcons = {
|
||||
success: CheckCircle,
|
||||
error: AlertCircle,
|
||||
info: Info,
|
||||
warning: AlertTriangle,
|
||||
success: CheckCircleIcon,
|
||||
error: WarningCircleIcon,
|
||||
info: InfoIcon,
|
||||
warning: WarningIcon,
|
||||
};
|
||||
|
||||
const toastStyles = {
|
||||
success:
|
||||
"border-green-500/20 bg-green-500/10 text-green-700 dark:text-green-400",
|
||||
error: "border-red-500/20 bg-red-500/10 text-red-700 dark:text-red-400",
|
||||
info: "border-blue-500/20 bg-blue-500/10 text-blue-700 dark:text-blue-400",
|
||||
warning:
|
||||
"border-yellow-500/20 bg-yellow-500/10 text-yellow-700 dark:text-yellow-400",
|
||||
success: "ascii-border bg-background0 text-status-success",
|
||||
error: "ascii-border bg-background0 text-status-error",
|
||||
info: "ascii-border bg-background0 text-status-info",
|
||||
warning: "ascii-border bg-background0 text-status-warning",
|
||||
};
|
||||
|
||||
export const Toast = ({ toast, onRemove, onErrorClick }: ToastProps) => {
|
||||
@@ -62,7 +60,7 @@ export const Toast = ({ toast, onRemove, onErrorClick }: ToastProps) => {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"flex items-start gap-3 p-4 rounded-lg border backdrop-blur-md transition-all duration-300 ease-in-out",
|
||||
"flex items-start gap-3 p-4 terminal-font transition-all duration-300 ease-in-out",
|
||||
toastStyles[toast.type],
|
||||
isVisible ? "translate-x-0 opacity-100" : "translate-x-full opacity-0"
|
||||
)}
|
||||
@@ -92,7 +90,7 @@ export const Toast = ({ toast, onRemove, onErrorClick }: ToastProps) => {
|
||||
}}
|
||||
className="flex-shrink-0 p-1 rounded-md hover:bg-black/10 transition-colors"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
<XIcon className="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,23 +1,32 @@
|
||||
export const WRITE_CRONTAB = (content: string, user: string) => `echo '${content}' | crontab -u ${user} -`;
|
||||
export const WRITE_CRONTAB = (content: string, user: string) => {
|
||||
return `crontab -u ${user} - << 'EOF'\n${content}\nEOF`;
|
||||
};
|
||||
|
||||
export const READ_CRONTAB = (user: string) => `crontab -l -u ${user} 2>/dev/null || echo ""`;
|
||||
export const READ_CRONTAB = (user: string) =>
|
||||
`crontab -l -u ${user} 2>/dev/null || echo ""`;
|
||||
|
||||
export const READ_CRON_FILE = () => 'crontab -l 2>/dev/null || echo ""'
|
||||
export const READ_CRON_FILE = () => 'crontab -l 2>/dev/null || echo ""';
|
||||
|
||||
export const WRITE_CRON_FILE = (content: string) => `echo "${content}" | crontab -`;
|
||||
export const WRITE_CRON_FILE = (content: string) => {
|
||||
return `crontab - << 'EOF'\n${content}\nEOF`;
|
||||
};
|
||||
|
||||
export const WRITE_HOST_CRONTAB = (base64Content: string, user: string) => `echo '${base64Content}' | base64 -d | crontab -u ${user} -`;
|
||||
export const WRITE_HOST_CRONTAB = (base64Content: string, user: string) => {
|
||||
const escapedContent = base64Content.replace(/'/g, "'\\''");
|
||||
return `echo '${escapedContent}' | base64 -d | crontab -u ${user} -`;
|
||||
};
|
||||
|
||||
export const ID_U = (username: string) => `id -u ${username}`;
|
||||
|
||||
export const ID_G = (username: string) => `id -g ${username}`;
|
||||
|
||||
export const MAKE_SCRIPT_EXECUTABLE = (scriptPath: string) => `chmod +x "${scriptPath}"`;
|
||||
export const MAKE_SCRIPT_EXECUTABLE = (scriptPath: string) =>
|
||||
`chmod +x "${scriptPath}"`;
|
||||
|
||||
export const RUN_SCRIPT = (scriptPath: string) => `bash "${scriptPath}"`;
|
||||
|
||||
export const GET_TARGET_USER = `getent passwd | grep ":/home/" | head -1 | cut -d: -f1`
|
||||
export const GET_TARGET_USER = `getent passwd | grep ":/home/" | head -1 | cut -d: -f1`;
|
||||
|
||||
export const GET_DOCKER_SOCKET_OWNER = 'stat -c "%U" /var/run/docker.sock'
|
||||
export const GET_DOCKER_SOCKET_OWNER = 'stat -c "%U" /var/run/docker.sock';
|
||||
|
||||
export const READ_CRONTABS_DIRECTORY = `ls /var/spool/cron/crontabs/ 2>/dev/null || echo ''`;
|
||||
export const READ_CRONTABS_DIRECTORY = `ls /var/spool/cron/crontabs/ 2>/dev/null || echo ''`;
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
export const Locales = [
|
||||
{ locale: "en", label: "English" },
|
||||
{ locale: "it", label: "Italian" },
|
||||
];
|
||||
@@ -1,7 +1,14 @@
|
||||
"use client";
|
||||
|
||||
import React, { createContext, useContext, useEffect, useRef, useState } from "react";
|
||||
import React, {
|
||||
createContext,
|
||||
useContext,
|
||||
useEffect,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import { SSEEvent } from "@/app/_utils/sse-events";
|
||||
import { usePageVisibility } from "@/app/_hooks/usePageVisibility";
|
||||
|
||||
interface SSEContextType {
|
||||
isConnected: boolean;
|
||||
@@ -10,13 +17,22 @@ interface SSEContextType {
|
||||
|
||||
const SSEContext = createContext<SSEContextType | null>(null);
|
||||
|
||||
export const SSEProvider: React.FC<{ children: React.ReactNode, liveUpdatesEnabled: boolean }> = ({ children, liveUpdatesEnabled }) => {
|
||||
export const SSEProvider: React.FC<{
|
||||
children: React.ReactNode;
|
||||
liveUpdatesEnabled: boolean;
|
||||
}> = ({ children, liveUpdatesEnabled }) => {
|
||||
const [isConnected, setIsConnected] = useState(false);
|
||||
const eventSourceRef = useRef<EventSource | null>(null);
|
||||
const subscribersRef = useRef<Set<(event: SSEEvent) => void>>(new Set());
|
||||
const isPageVisible = usePageVisibility();
|
||||
|
||||
useEffect(() => {
|
||||
if (!liveUpdatesEnabled) {
|
||||
if (!liveUpdatesEnabled || !isPageVisible) {
|
||||
if (eventSourceRef.current) {
|
||||
eventSourceRef.current.close();
|
||||
eventSourceRef.current = null;
|
||||
setIsConnected(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -30,7 +46,14 @@ export const SSEProvider: React.FC<{ children: React.ReactNode, liveUpdatesEnabl
|
||||
setIsConnected(false);
|
||||
};
|
||||
|
||||
const eventTypes = ["job-started", "job-completed", "job-failed", "log-line", "system-stats", "heartbeat"];
|
||||
const eventTypes = [
|
||||
"job-started",
|
||||
"job-completed",
|
||||
"job-failed",
|
||||
"log-line",
|
||||
"system-stats",
|
||||
"heartbeat",
|
||||
];
|
||||
|
||||
eventTypes.forEach((eventType) => {
|
||||
eventSource.addEventListener(eventType, (event: MessageEvent) => {
|
||||
@@ -48,7 +71,7 @@ export const SSEProvider: React.FC<{ children: React.ReactNode, liveUpdatesEnabl
|
||||
return () => {
|
||||
eventSource.close();
|
||||
};
|
||||
}, []);
|
||||
}, [liveUpdatesEnabled, isPageVisible]);
|
||||
|
||||
const subscribe = (callback: (event: SSEEvent) => void) => {
|
||||
subscribersRef.current.add(callback);
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
handleEditSubmit,
|
||||
handleNewCronSubmit,
|
||||
handleToggleLogging,
|
||||
handleBackup,
|
||||
} from "@/app/_components/FeatureComponents/Cronjobs/helpers";
|
||||
|
||||
interface CronJobListProps {
|
||||
@@ -126,7 +127,10 @@ export const useCronJobState = ({ cronJobs, scripts }: CronJobListProps) => {
|
||||
};
|
||||
|
||||
const handleDeleteLocal = async (id: string) => {
|
||||
await handleDelete(id, getHelperState());
|
||||
const job = cronJobs.find(j => j.id === id);
|
||||
if (job) {
|
||||
await handleDelete(job, getHelperState());
|
||||
}
|
||||
};
|
||||
|
||||
const handleCloneLocal = async (newComment: string) => {
|
||||
@@ -134,11 +138,17 @@ export const useCronJobState = ({ cronJobs, scripts }: CronJobListProps) => {
|
||||
};
|
||||
|
||||
const handlePauseLocal = async (id: string) => {
|
||||
await handlePause(id);
|
||||
const job = cronJobs.find(j => j.id === id);
|
||||
if (job) {
|
||||
await handlePause(job);
|
||||
}
|
||||
};
|
||||
|
||||
const handleResumeLocal = async (id: string) => {
|
||||
await handleResume(id);
|
||||
const job = cronJobs.find(j => j.id === id);
|
||||
if (job) {
|
||||
await handleResume(job);
|
||||
}
|
||||
};
|
||||
|
||||
const handleRunLocal = async (id: string) => {
|
||||
@@ -148,7 +158,10 @@ export const useCronJobState = ({ cronJobs, scripts }: CronJobListProps) => {
|
||||
};
|
||||
|
||||
const handleToggleLoggingLocal = async (id: string) => {
|
||||
await handleToggleLogging(id);
|
||||
const job = cronJobs.find(j => j.id === id);
|
||||
if (job) {
|
||||
await handleToggleLogging(job);
|
||||
}
|
||||
};
|
||||
|
||||
const handleViewLogs = (job: CronJob) => {
|
||||
@@ -185,6 +198,13 @@ export const useCronJobState = ({ cronJobs, scripts }: CronJobListProps) => {
|
||||
await handleNewCronSubmit(e, getHelperState());
|
||||
};
|
||||
|
||||
const handleBackupLocal = async (id: string) => {
|
||||
const job = cronJobs.find(j => j.id === id);
|
||||
if (job) {
|
||||
await handleBackup(job);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
deletingId,
|
||||
runningJobId,
|
||||
@@ -233,5 +253,6 @@ export const useCronJobState = ({ cronJobs, scripts }: CronJobListProps) => {
|
||||
handleEdit,
|
||||
handleEditSubmitLocal,
|
||||
handleNewCronSubmitLocal,
|
||||
handleBackupLocal,
|
||||
};
|
||||
};
|
||||
24
app/_hooks/usePageVisibility.ts
Normal file
24
app/_hooks/usePageVisibility.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
|
||||
export function usePageVisibility(): boolean {
|
||||
const [isVisible, setIsVisible] = useState<boolean>(
|
||||
typeof document !== "undefined" ? !document.hidden : true
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const handleVisibilityChange = () => {
|
||||
setIsVisible(!document.hidden);
|
||||
};
|
||||
|
||||
document.addEventListener("visibilitychange", handleVisibilityChange);
|
||||
|
||||
return () => {
|
||||
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return isVisible;
|
||||
}
|
||||
@@ -4,7 +4,21 @@ import { ThemeProvider as NextThemesProvider } from 'next-themes';
|
||||
import { type ThemeProviderProps } from 'next-themes/dist/types';
|
||||
|
||||
export const ThemeProvider = ({ children, ...props }: ThemeProviderProps) => {
|
||||
return <NextThemesProvider {...props}>{children}</NextThemesProvider>;
|
||||
return (
|
||||
<NextThemesProvider
|
||||
attribute="data-webtui-theme"
|
||||
defaultTheme="light"
|
||||
themes={['light', 'dark']}
|
||||
value={{
|
||||
light: 'catppuccin-latte',
|
||||
dark: 'catppuccin-mocha',
|
||||
}}
|
||||
disableTransitionOnChange
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</NextThemesProvider>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,25 +3,27 @@
|
||||
import {
|
||||
getCronJobs,
|
||||
addCronJob,
|
||||
deleteCronJob,
|
||||
updateCronJob,
|
||||
pauseCronJob,
|
||||
resumeCronJob,
|
||||
cleanupCrontab,
|
||||
readUserCrontab,
|
||||
writeUserCrontab,
|
||||
findJobIndex,
|
||||
updateCronJob,
|
||||
type CronJob,
|
||||
} from "@/app/_utils/cronjob-utils";
|
||||
import { getAllTargetUsers, getUserInfo } from "@/app/_utils/crontab-utils";
|
||||
import { getAllTargetUsers } from "@/app/_utils/crontab-utils";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { getScriptPathForCron } from "@/app/_server/actions/scripts";
|
||||
import { exec } from "child_process";
|
||||
import { promisify } from "util";
|
||||
import { isDocker } from "@/app/_server/actions/global";
|
||||
import {
|
||||
runJobSynchronously,
|
||||
runJobInBackground,
|
||||
} from "@/app/_utils/job-execution-utils";
|
||||
|
||||
const execAsync = promisify(exec);
|
||||
import {
|
||||
pauseJobInLines,
|
||||
resumeJobInLines,
|
||||
deleteJobInLines,
|
||||
} from "@/app/_utils/line-manipulation-utils";
|
||||
import { cleanCrontabContent } from "@/app/_utils/files-manipulation-utils";
|
||||
|
||||
export const fetchCronJobs = async (): Promise<CronJob[]> => {
|
||||
try {
|
||||
@@ -90,10 +92,22 @@ export const createCronJob = async (
|
||||
};
|
||||
|
||||
export const removeCronJob = async (
|
||||
id: string
|
||||
jobData: { id: string; schedule: string; command: string; comment?: string; user: string }
|
||||
): Promise<{ success: boolean; message: string; details?: string }> => {
|
||||
try {
|
||||
const success = await deleteCronJob(id);
|
||||
const cronContent = await readUserCrontab(jobData.user);
|
||||
const lines = cronContent.split("\n");
|
||||
|
||||
const jobIndex = findJobIndex(jobData, lines, jobData.user);
|
||||
|
||||
if (jobIndex === -1) {
|
||||
return { success: false, message: "Cron job not found in crontab" };
|
||||
}
|
||||
|
||||
const newCronEntries = deleteJobInLines(lines, jobIndex);
|
||||
const newCron = await cleanCrontabContent(newCronEntries.join("\n"));
|
||||
const success = await writeUserCrontab(jobData.user, newCron);
|
||||
|
||||
if (success) {
|
||||
revalidatePath("/");
|
||||
return { success: true, message: "Cron job deleted successfully" };
|
||||
@@ -124,8 +138,15 @@ export const editCronJob = async (
|
||||
return { success: false, message: "Missing required fields" };
|
||||
}
|
||||
|
||||
const cronJobs = await getCronJobs(false);
|
||||
const job = cronJobs.find((j) => j.id === id);
|
||||
|
||||
if (!job) {
|
||||
return { success: false, message: "Cron job not found" };
|
||||
}
|
||||
|
||||
const success = await updateCronJob(
|
||||
id,
|
||||
job,
|
||||
schedule,
|
||||
command,
|
||||
comment,
|
||||
@@ -152,7 +173,7 @@ export const cloneCronJob = async (
|
||||
newComment: string
|
||||
): Promise<{ success: boolean; message: string; details?: string }> => {
|
||||
try {
|
||||
const cronJobs = await getCronJobs();
|
||||
const cronJobs = await getCronJobs(false);
|
||||
const originalJob = cronJobs.find((job) => job.id === id);
|
||||
|
||||
if (!originalJob) {
|
||||
@@ -183,10 +204,22 @@ export const cloneCronJob = async (
|
||||
};
|
||||
|
||||
export const pauseCronJobAction = async (
|
||||
id: string
|
||||
jobData: { id: string; schedule: string; command: string; comment?: string; user: string }
|
||||
): Promise<{ success: boolean; message: string; details?: string }> => {
|
||||
try {
|
||||
const success = await pauseCronJob(id);
|
||||
const cronContent = await readUserCrontab(jobData.user);
|
||||
const lines = cronContent.split("\n");
|
||||
|
||||
const jobIndex = findJobIndex(jobData, lines, jobData.user);
|
||||
|
||||
if (jobIndex === -1) {
|
||||
return { success: false, message: "Cron job not found in crontab" };
|
||||
}
|
||||
|
||||
const newCronEntries = pauseJobInLines(lines, jobIndex, jobData.id);
|
||||
const newCron = await cleanCrontabContent(newCronEntries.join("\n"));
|
||||
const success = await writeUserCrontab(jobData.user, newCron);
|
||||
|
||||
if (success) {
|
||||
revalidatePath("/");
|
||||
return { success: true, message: "Cron job paused successfully" };
|
||||
@@ -204,10 +237,22 @@ export const pauseCronJobAction = async (
|
||||
};
|
||||
|
||||
export const resumeCronJobAction = async (
|
||||
id: string
|
||||
jobData: { id: string; schedule: string; command: string; comment?: string; user: string }
|
||||
): Promise<{ success: boolean; message: string; details?: string }> => {
|
||||
try {
|
||||
const success = await resumeCronJob(id);
|
||||
const cronContent = await readUserCrontab(jobData.user);
|
||||
const lines = cronContent.split("\n");
|
||||
|
||||
const jobIndex = findJobIndex(jobData, lines, jobData.user);
|
||||
|
||||
if (jobIndex === -1) {
|
||||
return { success: false, message: "Cron job not found in crontab" };
|
||||
}
|
||||
|
||||
const newCronEntries = resumeJobInLines(lines, jobIndex, jobData.id);
|
||||
const newCron = await cleanCrontabContent(newCronEntries.join("\n"));
|
||||
const success = await writeUserCrontab(jobData.user, newCron);
|
||||
|
||||
if (success) {
|
||||
revalidatePath("/");
|
||||
return { success: true, message: "Cron job resumed successfully" };
|
||||
@@ -257,23 +302,16 @@ export const cleanupCrontabAction = async (): Promise<{
|
||||
};
|
||||
|
||||
export const toggleCronJobLogging = async (
|
||||
id: string
|
||||
jobData: { id: string; schedule: string; command: string; comment?: string; user: string; logsEnabled?: boolean }
|
||||
): Promise<{ success: boolean; message: string; details?: string }> => {
|
||||
try {
|
||||
const cronJobs = await getCronJobs();
|
||||
const job = cronJobs.find((j) => j.id === id);
|
||||
|
||||
if (!job) {
|
||||
return { success: false, message: "Cron job not found" };
|
||||
}
|
||||
|
||||
const newLogsEnabled = !job.logsEnabled;
|
||||
const newLogsEnabled = !jobData.logsEnabled;
|
||||
|
||||
const success = await updateCronJob(
|
||||
id,
|
||||
job.schedule,
|
||||
job.command,
|
||||
job.comment || "",
|
||||
jobData,
|
||||
jobData.schedule,
|
||||
jobData.command,
|
||||
jobData.comment || "",
|
||||
newLogsEnabled
|
||||
);
|
||||
|
||||
@@ -309,7 +347,7 @@ export const runCronJob = async (
|
||||
mode?: "sync" | "async";
|
||||
}> => {
|
||||
try {
|
||||
const cronJobs = await getCronJobs();
|
||||
const cronJobs = await getCronJobs(false);
|
||||
const job = cronJobs.find((j) => j.id === id);
|
||||
|
||||
if (!job) {
|
||||
@@ -356,7 +394,7 @@ export const executeJob = async (
|
||||
mode?: "sync" | "async";
|
||||
}> => {
|
||||
try {
|
||||
const cronJobs = await getCronJobs();
|
||||
const cronJobs = await getCronJobs(false);
|
||||
const job = cronJobs.find((j) => j.id === id);
|
||||
|
||||
if (!job) {
|
||||
@@ -386,3 +424,193 @@ export const executeJob = async (
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export const backupCronJob = async (
|
||||
job: CronJob
|
||||
): Promise<{ success: boolean; message: string; details?: string }> => {
|
||||
try {
|
||||
const {
|
||||
backupJobToFile,
|
||||
} = await import("@/app/_utils/backup-utils");
|
||||
const success = await backupJobToFile(job);
|
||||
if (success) {
|
||||
return { success: true, message: "Cron job backed up successfully" };
|
||||
} else {
|
||||
return { success: false, message: "Failed to backup cron job" };
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error("Error backing up cron job:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: error.message || "Error backing up cron job",
|
||||
details: error.stack,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export const backupAllCronJobs = async (): Promise<{
|
||||
success: boolean;
|
||||
message: string;
|
||||
details?: string;
|
||||
}> => {
|
||||
try {
|
||||
const {
|
||||
backupAllJobsToFiles,
|
||||
} = await import("@/app/_utils/backup-utils");
|
||||
const result = await backupAllJobsToFiles();
|
||||
if (result.success) {
|
||||
return {
|
||||
success: true,
|
||||
message: `Backed up ${result.count} cron job(s) successfully`,
|
||||
};
|
||||
} else {
|
||||
return { success: false, message: "Failed to backup cron jobs" };
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error("Error backing up all cron jobs:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: error.message || "Error backing up all cron jobs",
|
||||
details: error.stack,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export const fetchBackupFiles = async (): Promise<Array<{
|
||||
filename: string;
|
||||
job: CronJob;
|
||||
backedUpAt: string;
|
||||
}>> => {
|
||||
try {
|
||||
const {
|
||||
getAllBackupFiles,
|
||||
} = await import("@/app/_utils/backup-utils");
|
||||
return await getAllBackupFiles();
|
||||
} catch (error) {
|
||||
console.error("Error fetching backup files:", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export const restoreCronJob = async (
|
||||
filename: string
|
||||
): Promise<{ success: boolean; message: string; details?: string }> => {
|
||||
try {
|
||||
const {
|
||||
restoreJobFromBackup,
|
||||
} = await import("@/app/_utils/backup-utils");
|
||||
|
||||
const result = await restoreJobFromBackup(filename);
|
||||
|
||||
if (!result.success || !result.job) {
|
||||
return { success: false, message: "Failed to read backup file" };
|
||||
}
|
||||
|
||||
const job = result.job;
|
||||
const success = await addCronJob(
|
||||
job.schedule,
|
||||
job.command,
|
||||
job.comment || "",
|
||||
job.user,
|
||||
job.logsEnabled || false
|
||||
);
|
||||
|
||||
if (success) {
|
||||
revalidatePath("/");
|
||||
return { success: true, message: "Cron job restored successfully" };
|
||||
} else {
|
||||
return { success: false, message: "Failed to restore cron job" };
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error("Error restoring cron job:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: error.message || "Error restoring cron job",
|
||||
details: error.stack,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteBackup = async (
|
||||
filename: string
|
||||
): Promise<{ success: boolean; message: string; details?: string }> => {
|
||||
try {
|
||||
const {
|
||||
deleteBackupFile,
|
||||
} = await import("@/app/_utils/backup-utils");
|
||||
|
||||
const success = await deleteBackupFile(filename);
|
||||
|
||||
if (success) {
|
||||
return { success: true, message: "Backup deleted successfully" };
|
||||
} else {
|
||||
return { success: false, message: "Failed to delete backup" };
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error("Error deleting backup:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: error.message || "Error deleting backup",
|
||||
details: error.stack,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export const restoreAllCronJobs = async (): Promise<{
|
||||
success: boolean;
|
||||
message: string;
|
||||
details?: string;
|
||||
}> => {
|
||||
try {
|
||||
const {
|
||||
getAllBackupFiles,
|
||||
} = await import("@/app/_utils/backup-utils");
|
||||
|
||||
const backups = await getAllBackupFiles();
|
||||
|
||||
if (backups.length === 0) {
|
||||
return { success: false, message: "No backup files found" };
|
||||
}
|
||||
|
||||
let successCount = 0;
|
||||
let failedCount = 0;
|
||||
|
||||
for (const backup of backups) {
|
||||
const job = backup.job;
|
||||
const success = await addCronJob(
|
||||
job.schedule,
|
||||
job.command,
|
||||
job.comment || "",
|
||||
job.user,
|
||||
job.logsEnabled || false
|
||||
);
|
||||
|
||||
if (success) {
|
||||
successCount++;
|
||||
} else {
|
||||
failedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
revalidatePath("/");
|
||||
|
||||
if (failedCount === 0) {
|
||||
return {
|
||||
success: true,
|
||||
message: `Successfully restored ${successCount} cron job(s)`,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: true,
|
||||
message: `Restored ${successCount} job(s), ${failedCount} failed`,
|
||||
};
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error("Error restoring all cron jobs:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: error.message || "Error restoring all cron jobs",
|
||||
details: error.stack,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { writeFile, readFile, unlink, mkdir } from "fs/promises";
|
||||
import { join } from "path";
|
||||
import path from "path";
|
||||
import { existsSync } from "fs";
|
||||
import { exec } from "child_process";
|
||||
import { promisify } from "util";
|
||||
@@ -13,10 +13,6 @@ import { isDocker, getHostScriptsPath } from "@/app/_server/actions/global";
|
||||
|
||||
const execAsync = promisify(exec);
|
||||
|
||||
export const getScriptPath = (filename: string): string => {
|
||||
return join(process.cwd(), SCRIPTS_DIR, filename);
|
||||
};
|
||||
|
||||
export const getScriptPathForCron = async (
|
||||
filename: string
|
||||
): Promise<string> => {
|
||||
@@ -25,19 +21,19 @@ export const getScriptPathForCron = async (
|
||||
if (docker) {
|
||||
const hostScriptsPath = await getHostScriptsPath();
|
||||
if (hostScriptsPath) {
|
||||
return `bash ${join(hostScriptsPath, filename)}`;
|
||||
return `bash ${path.join(hostScriptsPath, filename)}`;
|
||||
}
|
||||
console.warn("Could not determine host scripts path, using container path");
|
||||
}
|
||||
|
||||
return `bash ${join(process.cwd(), SCRIPTS_DIR, filename)}`;
|
||||
return `bash ${path.join(process.cwd(), SCRIPTS_DIR, filename)}`;
|
||||
};
|
||||
|
||||
export const getHostScriptPath = (filename: string): string => {
|
||||
return `bash ${join(process.cwd(), SCRIPTS_DIR, filename)}`;
|
||||
export const getHostScriptPath = async (filename: string): Promise<string> => {
|
||||
return `bash ${path.join(process.cwd(), SCRIPTS_DIR, filename)}`;
|
||||
};
|
||||
|
||||
export const normalizeLineEndings = (content: string): string => {
|
||||
export const normalizeLineEndings = async (content: string): Promise<string> => {
|
||||
return content.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
||||
};
|
||||
|
||||
@@ -65,14 +61,14 @@ const generateUniqueFilename = async (baseName: string): Promise<string> => {
|
||||
};
|
||||
|
||||
const ensureScriptsDirectory = async () => {
|
||||
const scriptsDir = join(process.cwd(), SCRIPTS_DIR);
|
||||
const scriptsDir = path.join(process.cwd(), SCRIPTS_DIR);
|
||||
if (!existsSync(scriptsDir)) {
|
||||
await mkdir(scriptsDir, { recursive: true });
|
||||
}
|
||||
};
|
||||
|
||||
const ensureHostScriptsDirectory = async () => {
|
||||
const hostScriptsDir = join(process.cwd(), SCRIPTS_DIR);
|
||||
const hostScriptsDir = path.join(process.cwd(), SCRIPTS_DIR);
|
||||
if (!existsSync(hostScriptsDir)) {
|
||||
await mkdir(hostScriptsDir, { recursive: true });
|
||||
}
|
||||
@@ -81,7 +77,7 @@ const ensureHostScriptsDirectory = async () => {
|
||||
const saveScriptFile = async (filename: string, content: string) => {
|
||||
await ensureScriptsDirectory();
|
||||
|
||||
const scriptPath = getScriptPath(filename);
|
||||
const scriptPath = path.join(process.cwd(), SCRIPTS_DIR, filename);
|
||||
await writeFile(scriptPath, content, "utf8");
|
||||
|
||||
try {
|
||||
@@ -92,7 +88,7 @@ const saveScriptFile = async (filename: string, content: string) => {
|
||||
};
|
||||
|
||||
const deleteScriptFile = async (filename: string) => {
|
||||
const scriptPath = getScriptPath(filename);
|
||||
const scriptPath = path.join(process.cwd(), SCRIPTS_DIR, filename);
|
||||
if (existsSync(scriptPath)) {
|
||||
await unlink(scriptPath);
|
||||
}
|
||||
@@ -125,7 +121,7 @@ export const createScript = async (
|
||||
|
||||
`;
|
||||
|
||||
const normalizedContent = normalizeLineEndings(content);
|
||||
const normalizedContent = await normalizeLineEndings(content);
|
||||
const fullContent = metadataHeader + normalizedContent;
|
||||
|
||||
await saveScriptFile(filename, fullContent);
|
||||
@@ -176,7 +172,7 @@ export const updateScript = async (
|
||||
|
||||
`;
|
||||
|
||||
const normalizedContent = normalizeLineEndings(content);
|
||||
const normalizedContent = await normalizeLineEndings(content);
|
||||
const fullContent = metadataHeader + normalizedContent;
|
||||
|
||||
await saveScriptFile(existingScript.filename, fullContent);
|
||||
@@ -235,7 +231,7 @@ export const cloneScript = async (
|
||||
|
||||
`;
|
||||
|
||||
const normalizedContent = normalizeLineEndings(originalContent);
|
||||
const normalizedContent = await normalizeLineEndings(originalContent);
|
||||
const fullContent = metadataHeader + normalizedContent;
|
||||
|
||||
await saveScriptFile(filename, fullContent);
|
||||
@@ -262,7 +258,7 @@ export const cloneScript = async (
|
||||
|
||||
export const getScriptContent = async (filename: string): Promise<string> => {
|
||||
try {
|
||||
const scriptPath = getScriptPath(filename);
|
||||
const scriptPath = path.join(process.cwd(), SCRIPTS_DIR, filename);
|
||||
|
||||
if (existsSync(scriptPath)) {
|
||||
const content = await readFile(scriptPath, "utf8");
|
||||
@@ -299,7 +295,7 @@ export const executeScript = async (
|
||||
}> => {
|
||||
try {
|
||||
await ensureHostScriptsDirectory();
|
||||
const hostScriptPath = getHostScriptPath(filename);
|
||||
const hostScriptPath = await getHostScriptPath(filename);
|
||||
|
||||
if (!existsSync(hostScriptPath)) {
|
||||
return {
|
||||
|
||||
59
app/_server/actions/translations/index.ts
Normal file
59
app/_server/actions/translations/index.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import "server-only";
|
||||
|
||||
/**
|
||||
* Load translation messages for a given locale.
|
||||
* First checks for custom translations in ./data/translations/,
|
||||
* then falls back to built-in translations in app/_translations/.
|
||||
*
|
||||
* This function is server-only and should only be called from server components
|
||||
* or server actions.
|
||||
*/
|
||||
export const loadTranslationMessages = async (locale: string): Promise<any> => {
|
||||
const customTranslationPath = path.join(
|
||||
process.cwd(),
|
||||
"data",
|
||||
"translations",
|
||||
`${locale}.json`
|
||||
);
|
||||
|
||||
try {
|
||||
if (fs.existsSync(customTranslationPath)) {
|
||||
const customMessages = JSON.parse(
|
||||
fs.readFileSync(customTranslationPath, "utf8")
|
||||
);
|
||||
return customMessages;
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(`Failed to load custom translation for ${locale}:`, error);
|
||||
}
|
||||
|
||||
try {
|
||||
const messages = (await import(`../../../_translations/${locale}.json`))
|
||||
.default;
|
||||
return messages;
|
||||
} catch (error) {
|
||||
const fallbackMessages = (await import("../../../_translations/en.json"))
|
||||
.default;
|
||||
return fallbackMessages;
|
||||
}
|
||||
};
|
||||
|
||||
type TranslationFunction = (key: string) => string;
|
||||
|
||||
|
||||
export const getTranslations = async (
|
||||
locale: string = process.env.LOCALE || "en"
|
||||
): Promise<TranslationFunction> => {
|
||||
const messages = await loadTranslationMessages(locale);
|
||||
|
||||
return (key: string) => {
|
||||
const keys = key.split(".");
|
||||
let value: any = messages;
|
||||
for (const k of keys) {
|
||||
value = value?.[k];
|
||||
}
|
||||
return value || key;
|
||||
};
|
||||
};
|
||||
@@ -10,7 +10,8 @@
|
||||
"cancel": "Cancel",
|
||||
"close": "Close",
|
||||
"refresh": "Refresh",
|
||||
"loading": "Loading"
|
||||
"loading": "Loading",
|
||||
"version": "Version {version}"
|
||||
},
|
||||
"cronjobs": {
|
||||
"cronJobs": "Cron Jobs",
|
||||
@@ -55,7 +56,57 @@
|
||||
"loading": "Loading",
|
||||
"close": "Close",
|
||||
"healthy": "Healthy",
|
||||
"failed": "Failed (Exit: {exitCode})"
|
||||
"failed": "Failed (Exit: {exitCode})",
|
||||
"backupJob": "Backup job",
|
||||
"restoreJob": "Restore job",
|
||||
"backupAll": "Backup All",
|
||||
"backups": "Backups",
|
||||
"restoreAll": "Restore All",
|
||||
"confirmRestoreAll": "Are you sure you want to restore all backed up jobs? This will add them to your crontab.",
|
||||
"backupJobSuccess": "Job backed up successfully",
|
||||
"backupJobFailed": "Failed to backup job",
|
||||
"backupAllSuccess": "All jobs backed up successfully",
|
||||
"backupAllFailed": "Failed to backup all jobs",
|
||||
"restoreJobSuccess": "Job restored successfully",
|
||||
"restoreJobFailed": "Failed to restore job",
|
||||
"moreActions": "More actions",
|
||||
"restoreBackups": "Restore Backups",
|
||||
"availableBackups": "Available Backups",
|
||||
"noBackupsFound": "No backup files found",
|
||||
"backedUpAt": "Backed up at",
|
||||
"restoreThisBackup": "Restore this backup",
|
||||
"deleteBackup": "Delete backup",
|
||||
"confirmDeleteBackup": "Are you sure you want to delete this backup? This action cannot be undone.",
|
||||
"backupDeleted": "Backup deleted successfully",
|
||||
"filters": "Filters",
|
||||
"filtersAndDisplay": "Filters & Display Options",
|
||||
"filterByUser": "Filter by User",
|
||||
"scheduleDisplay": "Schedule Display",
|
||||
"cronSyntax": "Cron Syntax",
|
||||
"humanReadable": "Human Readable",
|
||||
"both": "Both",
|
||||
"minimalMode": "Minimal Mode",
|
||||
"minimalModeDescription": "Show compact view with icons instead of full text",
|
||||
"applyFilters": "Apply Filters",
|
||||
"nLines": "{count} lines",
|
||||
"liveJobExecution": "Live Job Execution",
|
||||
"running": "Running...",
|
||||
"completed": "Completed (Exit: {exitCode})",
|
||||
"jobFailed": "Failed (Exit: {exitCode})",
|
||||
"showLast": "Show last:",
|
||||
"viewFullLog": "View Full Log ({totalLines} lines)",
|
||||
"viewFullLogNoCount": "View Full Log",
|
||||
"viewingFullLog": "Viewing full log ({totalLines} lines)",
|
||||
"viewingFullLogNoCount": "Viewing full log",
|
||||
"backToWindowedView": "Back to Windowed View",
|
||||
"showingLastOf": "Showing last {lineCount} of {totalLines} lines",
|
||||
"showingLastLines": "Showing last {lineCount} lines",
|
||||
"largeLogFileDetected": "Large log file detected",
|
||||
"tailModeEnabled": "Tail mode enabled, showing last {tailLines} lines",
|
||||
"showAllLines": "Show all lines",
|
||||
"enableTailMode": "Enable tail mode",
|
||||
"waitingForJobToStart": "Waiting for job to start...\n\nLogs will appear here in real-time.",
|
||||
"runIdJobId": "Run ID: {runId} | Job ID: {jobId}"
|
||||
},
|
||||
"scripts": {
|
||||
"scripts": "Scripts",
|
||||
@@ -77,7 +128,11 @@
|
||||
"commandPreview": "Command Preview",
|
||||
"scriptContent": "Script Content",
|
||||
"selectScriptToPreview": "Select a script to preview",
|
||||
"searchScripts": "Search scripts..."
|
||||
"searchScripts": "Search scripts...",
|
||||
"draft": "Draft",
|
||||
"clearDraft": "Clear Draft",
|
||||
"close": "Close",
|
||||
"draftCleared": "Draft cleared"
|
||||
},
|
||||
"sidebar": {
|
||||
"systemOverview": "System Overview",
|
||||
@@ -112,5 +167,42 @@
|
||||
"available": "Available",
|
||||
"systemStatus": "System Status",
|
||||
"lastUpdated": "Last updated"
|
||||
},
|
||||
"login": {
|
||||
"welcomeTitle": "Welcome to Cr*nMaster",
|
||||
"signInWithPasswordOrSSO": "Sign in with password or SSO",
|
||||
"signInWithSSO": "Sign in with SSO",
|
||||
"enterPasswordToContinue": "Enter your password to continue",
|
||||
"authenticationNotConfigured": "Authentication Not Configured",
|
||||
"noAuthMethodsEnabled": "Neither password authentication nor OIDC SSO is enabled. Please configure at least one authentication method in your environment variables to be able to log in.",
|
||||
"enterPassword": "Enter password",
|
||||
"signingIn": "Signing in...",
|
||||
"signIn": "Sign In",
|
||||
"redirecting": "Redirecting...",
|
||||
"redirectingToOIDC": "Redirecting to OIDC provider",
|
||||
"pleaseWait": "Please wait...",
|
||||
"orContinueWith": "Or continue with",
|
||||
"loginFailed": "Login failed",
|
||||
"genericError": "An error occurred. Please try again."
|
||||
},
|
||||
"warnings": {
|
||||
"wrapperScriptModified": "Wrapper Script Modified",
|
||||
"wrapperScriptModifiedDescription": "Your cron-log-wrapper.sh script has been modified from the official version. This may affect logging functionality. Consider reverting to the official version or ensure your changes don't break the required format for log parsing."
|
||||
},
|
||||
"notFound": {
|
||||
"title": "404 - Page Not Found",
|
||||
"subtitle": "ERROR: The requested resource could not be located",
|
||||
"message": "The page you're looking for doesn't exist. Want to play snake instead?",
|
||||
"gameOver": "GAME OVER",
|
||||
"score": "Score",
|
||||
"highScore": "High Score",
|
||||
"pressToStart": "Press SPACE or tap to start",
|
||||
"pressToRestart": "Press SPACE or tap to restart",
|
||||
"controls": "Controls",
|
||||
"useArrowKeys": "Use arrow keys to move",
|
||||
"tapToMove": "Tap screen edges to move",
|
||||
"goHome": "Return to Dashboard",
|
||||
"pauseGame": "Press P to pause",
|
||||
"paused": "PAUSED"
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,10 @@
|
||||
"change": "Modifica",
|
||||
"description": "Descrizione",
|
||||
"optional": "Opzionale",
|
||||
"cancel": "Annulla"
|
||||
"cancel": "Annulla",
|
||||
"refresh": "Aggiorna",
|
||||
"close": "Chiudi",
|
||||
"version": "Versione {version}"
|
||||
},
|
||||
"cronjobs": {
|
||||
"cronJobs": "Operazioni Cron",
|
||||
@@ -52,7 +55,54 @@
|
||||
"loading": "Caricamento",
|
||||
"close": "Chiudi",
|
||||
"healthy": "Sano",
|
||||
"failed": "Fallito (Exit: {exitCode})"
|
||||
"failed": "Fallito (Exit: {exitCode})",
|
||||
"backupJob": "Backup operazione",
|
||||
"restoreJob": "Ripristina operazione",
|
||||
"backupAll": "Backup Tutti",
|
||||
"backups": "Backups",
|
||||
"restoreAll": "Ripristina Tutti",
|
||||
"confirmRestoreAll": "Sei sicuro di voler ripristinare tutte le operazioni salvate? Verranno aggiunte al tuo crontab.",
|
||||
"backupJobSuccess": "Backup operazione completato con successo",
|
||||
"backupJobFailed": "Backup operazione fallito",
|
||||
"backupAllSuccess": "Backup di tutte le operazioni completato con successo",
|
||||
"backupAllFailed": "Backup di tutte le operazioni fallito",
|
||||
"restoreJobSuccess": "Operazione ripristinata con successo",
|
||||
"restoreJobFailed": "Ripristino operazione fallito",
|
||||
"moreActions": "Altre azioni",
|
||||
"restoreBackups": "Ripristina Backup",
|
||||
"availableBackups": "Backup Disponibili",
|
||||
"noBackupsFound": "Nessun file di backup trovato",
|
||||
"backedUpAt": "Backup effettuato il",
|
||||
"restoreThisBackup": "Ripristina questo backup",
|
||||
"deleteBackup": "Elimina backup",
|
||||
"confirmDeleteBackup": "Sei sicuro di voler eliminare questo backup? Questa azione non può essere annullata.",
|
||||
"backupDeleted": "Backup eliminato con successo",
|
||||
"filters": "Filtri",
|
||||
"filtersAndDisplay": "Filtri e Opzioni di Visualizzazione",
|
||||
"filterByUser": "Filtra per Utente",
|
||||
"scheduleDisplay": "Visualizzazione Pianificazione",
|
||||
"cronSyntax": "Sintassi Cron",
|
||||
"humanReadable": "Comprensibile",
|
||||
"both": "Entrambi",
|
||||
"minimalMode": "Modalità Minima",
|
||||
"minimalModeDescription": "Mostra vista compatta con icone invece del testo completo",
|
||||
"applyFilters": "Applica Filtri",
|
||||
"nLines": "{count} linee",
|
||||
"liveJobExecution": "Esecuzione Lavoro Live",
|
||||
"running": "In esecuzione...",
|
||||
"completed": "Completato (Exit: {exitCode})",
|
||||
"jobFailed": "Fallito (Exit: {exitCode})",
|
||||
"showLast": "Mostra ultime:",
|
||||
"viewFullLog": "Visualizza Log Completo ({totalLines} linee)",
|
||||
"viewingFullLog": "Visualizzazione log completo ({totalLines} linee)",
|
||||
"backToWindowedView": "Torna alla Vista Finestrata",
|
||||
"showingLastOf": "Mostrando ultime {lineCount} di {totalLines} linee",
|
||||
"largeLogFileDetected": "Rilevato file di log di grandi dimensioni",
|
||||
"tailModeEnabled": "Modalità tail abilitata, mostrando ultime {tailLines} linee",
|
||||
"showAllLines": "Mostra tutte le linee",
|
||||
"enableTailMode": "Abilita modalità tail",
|
||||
"waitingForJobToStart": "In attesa che il lavoro inizi...\n\nI log appariranno qui in tempo reale.",
|
||||
"runIdJobId": "ID Esecuzione: {runId} | ID Lavoro: {jobId}"
|
||||
},
|
||||
"scripts": {
|
||||
"scripts": "Script",
|
||||
@@ -74,7 +124,11 @@
|
||||
"commandPreview": "Anteprima Comando",
|
||||
"scriptContent": "Contenuto Script",
|
||||
"selectScriptToPreview": "Seleziona uno script per l'anteprima",
|
||||
"searchScripts": "Cerca script..."
|
||||
"searchScripts": "Cerca script...",
|
||||
"draft": "Bozza",
|
||||
"clearDraft": "Cancella Bozza",
|
||||
"close": "Chiudi",
|
||||
"draftCleared": "Bozza cancellata"
|
||||
},
|
||||
"sidebar": {
|
||||
"systemOverview": "Panoramica del Sistema",
|
||||
@@ -109,5 +163,43 @@
|
||||
"available": "Disponibile",
|
||||
"systemStatus": "Stato del Sistema",
|
||||
"lastUpdated": "Ultimo aggiornamento"
|
||||
},
|
||||
"login": {
|
||||
"welcomeTitle": "Benvenuto in Cr*nMaster",
|
||||
"signInWithPasswordOrSSO": "Accedi con password o SSO",
|
||||
"signInWithSSO": "Accedi con SSO",
|
||||
"enterPasswordToContinue": "Inserisci la tua password per continuare",
|
||||
"authenticationNotConfigured": "Autenticazione Non Configurata",
|
||||
"noAuthMethodsEnabled": "Né l'autenticazione password né l'OIDC SSO sono abilitati. Si prega di configurare almeno un metodo di autenticazione nelle variabili d'ambiente per poter effettuare il login.",
|
||||
"enterPassword": "Inserisci password",
|
||||
"signingIn": "Accesso in corso...",
|
||||
"signIn": "Accedi",
|
||||
"redirecting": "Reindirizzamento...",
|
||||
"redirectingToOIDC": "Reindirizzamento al provider OIDC",
|
||||
"pleaseWait": "Attendere prego...",
|
||||
"orContinueWith": "Oppure continua con",
|
||||
"loginFailed": "Accesso fallito",
|
||||
"genericError": "Si è verificato un errore. Riprova."
|
||||
},
|
||||
"warnings": {
|
||||
"wrapperScriptModified": "Script Wrapper Modificato",
|
||||
"wrapperScriptModifiedDescription": "Il tuo script cron-log-wrapper.sh è stato modificato dalla versione ufficiale. Questo potrebbe influenzare la funzionalità di logging. Considera di ripristinare la versione ufficiale o assicurati che le tue modifiche non interrompano il formato richiesto per l'analisi dei log."
|
||||
},
|
||||
"notFound": {
|
||||
"title": "404 - Pagina Non Trovata",
|
||||
"subtitle": "ERRORE: La risorsa richiesta non è stata trovata",
|
||||
"message": "La pagina che stai cercando non esiste. Partitella a snake?",
|
||||
"playSnake": "Gioca a Snake mentre sei qui",
|
||||
"gameOver": "GAME OVER",
|
||||
"score": "Punteggio",
|
||||
"highScore": "Punteggio Massimo",
|
||||
"pressToStart": "Premi SPAZIO o tocca per iniziare",
|
||||
"pressToRestart": "Premi SPAZIO o tocca per ricominciare",
|
||||
"controls": "Controlli",
|
||||
"useArrowKeys": "Usa i tasti freccia per muoverti",
|
||||
"tapToMove": "Tocca i bordi dello schermo per muoverti",
|
||||
"goHome": "Torna alla Dashboard",
|
||||
"pauseGame": "Premi P per mettere in pausa",
|
||||
"paused": "IN PAUSA"
|
||||
}
|
||||
}
|
||||
@@ -56,16 +56,19 @@ export async function requireAuth(
|
||||
return null;
|
||||
}
|
||||
|
||||
const hasValidApiKey = validateApiKey(request);
|
||||
if (hasValidApiKey) {
|
||||
return null;
|
||||
const apiKey = process.env.API_KEY;
|
||||
if (apiKey) {
|
||||
const hasValidApiKey = validateApiKey(request);
|
||||
if (hasValidApiKey) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (process.env.DEBUGGER) {
|
||||
console.log("[API Auth] Unauthorized request:", {
|
||||
path: request.nextUrl.pathname,
|
||||
hasSession: hasValidSession,
|
||||
hasApiKey: hasValidApiKey,
|
||||
apiKeyConfigured: !!process.env.API_KEY,
|
||||
hasAuthHeader: !!request.headers.get("authorization"),
|
||||
});
|
||||
}
|
||||
|
||||
189
app/_utils/backup-utils.ts
Normal file
189
app/_utils/backup-utils.ts
Normal file
@@ -0,0 +1,189 @@
|
||||
import { promises as fs } from "fs";
|
||||
import path from "path";
|
||||
import { getCronJobs, type CronJob } from "@/app/_utils/cronjob-utils";
|
||||
|
||||
const BACKUP_DIR = path.join(process.cwd(), "data", "backup");
|
||||
|
||||
const ensureBackupDirectoryExists = async (): Promise<void> => {
|
||||
try {
|
||||
await fs.mkdir(BACKUP_DIR, { recursive: true });
|
||||
} catch (error) {
|
||||
console.error("Error creating backup directory:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
const sanitizeFilename = (id: string): string => {
|
||||
return id.replace(/[^a-zA-Z0-9_-]/g, "_");
|
||||
};
|
||||
|
||||
export const backupJobToFile = async (job: CronJob): Promise<boolean> => {
|
||||
try {
|
||||
await ensureBackupDirectoryExists();
|
||||
|
||||
const jobData = {
|
||||
id: job.id,
|
||||
schedule: job.schedule,
|
||||
command: job.command,
|
||||
comment: job.comment || "",
|
||||
user: job.user,
|
||||
paused: job.paused || false,
|
||||
logsEnabled: job.logsEnabled || false,
|
||||
backedUpAt: new Date().toISOString(),
|
||||
};
|
||||
|
||||
const filename = `${sanitizeFilename(job.id)}.job`;
|
||||
const filepath = path.join(BACKUP_DIR, filename);
|
||||
|
||||
await fs.writeFile(filepath, JSON.stringify(jobData, null, 2), "utf8");
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error(`Error backing up job ${job.id}:`, error);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export const backupAllJobsToFiles = async (): Promise<{
|
||||
success: boolean;
|
||||
count: number;
|
||||
}> => {
|
||||
try {
|
||||
await ensureBackupDirectoryExists();
|
||||
|
||||
const cronJobs = await getCronJobs(false);
|
||||
|
||||
let successCount = 0;
|
||||
|
||||
for (const job of cronJobs) {
|
||||
const success = await backupJobToFile(job);
|
||||
if (success) {
|
||||
successCount++;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
success: successCount === cronJobs.length,
|
||||
count: successCount,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error backing up all jobs:", error);
|
||||
return {
|
||||
success: false,
|
||||
count: 0,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export const listBackupFiles = async (): Promise<string[]> => {
|
||||
try {
|
||||
await ensureBackupDirectoryExists();
|
||||
|
||||
const files = await fs.readdir(BACKUP_DIR);
|
||||
return files.filter((file) => file.endsWith(".job"));
|
||||
} catch (error) {
|
||||
console.error("Error listing backup files:", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export const readBackupFile = async (
|
||||
filename: string
|
||||
): Promise<CronJob | null> => {
|
||||
try {
|
||||
const filepath = path.join(BACKUP_DIR, filename);
|
||||
const content = await fs.readFile(filepath, "utf8");
|
||||
const jobData = JSON.parse(content);
|
||||
|
||||
return {
|
||||
id: jobData.id,
|
||||
schedule: jobData.schedule,
|
||||
command: jobData.command,
|
||||
comment: jobData.comment,
|
||||
user: jobData.user,
|
||||
paused: jobData.paused,
|
||||
logsEnabled: jobData.logsEnabled,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(`Error reading backup file ${filename}:`, error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export const getAllBackupFiles = async (): Promise<
|
||||
Array<{
|
||||
filename: string;
|
||||
job: CronJob;
|
||||
backedUpAt: string;
|
||||
}>
|
||||
> => {
|
||||
try {
|
||||
await ensureBackupDirectoryExists();
|
||||
|
||||
const files = await fs.readdir(BACKUP_DIR);
|
||||
const jobFiles = files.filter((file) => file.endsWith(".job"));
|
||||
|
||||
const backups = await Promise.all(
|
||||
jobFiles.map(async (filename) => {
|
||||
try {
|
||||
const filepath = path.join(BACKUP_DIR, filename);
|
||||
const content = await fs.readFile(filepath, "utf8");
|
||||
const jobData = JSON.parse(content);
|
||||
|
||||
return {
|
||||
filename,
|
||||
job: {
|
||||
id: jobData.id,
|
||||
schedule: jobData.schedule,
|
||||
command: jobData.command,
|
||||
comment: jobData.comment,
|
||||
user: jobData.user,
|
||||
paused: jobData.paused,
|
||||
logsEnabled: jobData.logsEnabled,
|
||||
} as CronJob,
|
||||
backedUpAt: jobData.backedUpAt,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(`Error reading backup file ${filename}:`, error);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
return backups.filter((backup) => backup !== null) as Array<{
|
||||
filename: string;
|
||||
job: CronJob;
|
||||
backedUpAt: string;
|
||||
}>;
|
||||
} catch (error) {
|
||||
console.error("Error getting all backup files:", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export const restoreJobFromBackup = async (
|
||||
filename: string
|
||||
): Promise<{ success: boolean; job?: CronJob }> => {
|
||||
try {
|
||||
const job = await readBackupFile(filename);
|
||||
if (!job) {
|
||||
return { success: false };
|
||||
}
|
||||
|
||||
return { success: true, job };
|
||||
} catch (error) {
|
||||
console.error(`Error restoring job from backup ${filename}:`, error);
|
||||
return { success: false };
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteBackupFile = async (filename: string): Promise<boolean> => {
|
||||
try {
|
||||
const filepath = path.join(BACKUP_DIR, filename);
|
||||
await fs.unlink(filepath);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error(`Error deleting backup file ${filename}:`, error);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
unwrapCommand,
|
||||
isCommandWrapped,
|
||||
} from "@/app/_utils/wrapper-utils";
|
||||
import { generateShortUUID } from "@/app/_utils/uuid-utils";
|
||||
|
||||
const execAsync = promisify(exec);
|
||||
|
||||
@@ -45,7 +46,7 @@ export interface CronJob {
|
||||
};
|
||||
}
|
||||
|
||||
const readUserCrontab = async (user: string): Promise<string> => {
|
||||
export const readUserCrontab = async (user: string): Promise<string> => {
|
||||
const docker = await isDocker();
|
||||
|
||||
if (docker) {
|
||||
@@ -58,7 +59,7 @@ const readUserCrontab = async (user: string): Promise<string> => {
|
||||
}
|
||||
};
|
||||
|
||||
const writeUserCrontab = async (
|
||||
export const writeUserCrontab = async (
|
||||
user: string,
|
||||
content: string
|
||||
): Promise<boolean> => {
|
||||
@@ -101,7 +102,9 @@ const getAllUsers = async (): Promise<{ user: string; content: string }[]> => {
|
||||
}
|
||||
};
|
||||
|
||||
export const getCronJobs = async (includeLogErrors: boolean = true): Promise<CronJob[]> => {
|
||||
export const getCronJobs = async (
|
||||
includeLogErrors: boolean = true
|
||||
): Promise<CronJob[]> => {
|
||||
try {
|
||||
const userCrontabs = await getAllUsers();
|
||||
let allJobs: CronJob[] = [];
|
||||
@@ -111,15 +114,16 @@ export const getCronJobs = async (includeLogErrors: boolean = true): Promise<Cro
|
||||
|
||||
const lines = content.split("\n");
|
||||
const jobs = parseJobsFromLines(lines, user);
|
||||
|
||||
allJobs.push(...jobs);
|
||||
}
|
||||
|
||||
if (includeLogErrors) {
|
||||
const { getAllJobLogErrors } = await import("@/app/_server/actions/logs");
|
||||
const jobIds = allJobs.map(job => job.id);
|
||||
const jobIds = allJobs.map((job) => job.id);
|
||||
const errorMap = await getAllJobLogErrors(jobIds);
|
||||
|
||||
allJobs = allJobs.map(job => ({
|
||||
allJobs = allJobs.map((job) => ({
|
||||
...job,
|
||||
logError: errorMap.get(job.id),
|
||||
}));
|
||||
@@ -140,27 +144,31 @@ export const addCronJob = async (
|
||||
logsEnabled: boolean = false
|
||||
): Promise<boolean> => {
|
||||
try {
|
||||
const jobId = generateShortUUID();
|
||||
|
||||
if (user) {
|
||||
const cronContent = await readUserCrontab(user);
|
||||
|
||||
const lines = cronContent.split("\n");
|
||||
const existingJobs = parseJobsFromLines(lines, user);
|
||||
const nextJobIndex = existingJobs.length;
|
||||
const jobId = `${user}-${nextJobIndex}`;
|
||||
|
||||
let finalCommand = command;
|
||||
if (logsEnabled && !isCommandWrapped(command)) {
|
||||
const docker = await isDocker();
|
||||
finalCommand = await wrapCommandWithLogger(jobId, command, docker, comment);
|
||||
finalCommand = await wrapCommandWithLogger(
|
||||
jobId,
|
||||
command,
|
||||
docker,
|
||||
comment
|
||||
);
|
||||
} else if (logsEnabled && isCommandWrapped(command)) {
|
||||
finalCommand = command;
|
||||
}
|
||||
|
||||
const formattedComment = formatCommentWithMetadata(comment, logsEnabled);
|
||||
const formattedComment = formatCommentWithMetadata(
|
||||
comment,
|
||||
logsEnabled,
|
||||
jobId
|
||||
);
|
||||
|
||||
const newEntry = formattedComment
|
||||
? `# ${formattedComment}\n${schedule} ${finalCommand}`
|
||||
: `${schedule} ${finalCommand}`;
|
||||
const newEntry = `# ${formattedComment}\n${schedule} ${finalCommand}`;
|
||||
|
||||
let newCron;
|
||||
if (cronContent.trim() === "") {
|
||||
@@ -174,25 +182,26 @@ export const addCronJob = async (
|
||||
} else {
|
||||
const cronContent = await readCronFiles();
|
||||
|
||||
const currentUser = process.env.USER || "user";
|
||||
const lines = cronContent.split("\n");
|
||||
const existingJobs = parseJobsFromLines(lines, currentUser);
|
||||
const nextJobIndex = existingJobs.length;
|
||||
const jobId = `${currentUser}-${nextJobIndex}`;
|
||||
|
||||
let finalCommand = command;
|
||||
if (logsEnabled && !isCommandWrapped(command)) {
|
||||
const docker = await isDocker();
|
||||
finalCommand = await wrapCommandWithLogger(jobId, command, docker, comment);
|
||||
finalCommand = await wrapCommandWithLogger(
|
||||
jobId,
|
||||
command,
|
||||
docker,
|
||||
comment
|
||||
);
|
||||
} else if (logsEnabled && isCommandWrapped(command)) {
|
||||
finalCommand = command;
|
||||
}
|
||||
|
||||
const formattedComment = formatCommentWithMetadata(comment, logsEnabled);
|
||||
const formattedComment = formatCommentWithMetadata(
|
||||
comment,
|
||||
logsEnabled,
|
||||
jobId
|
||||
);
|
||||
|
||||
const newEntry = formattedComment
|
||||
? `# ${formattedComment}\n${schedule} ${finalCommand}`
|
||||
: `${schedule} ${finalCommand}`;
|
||||
const newEntry = `# ${formattedComment}\n${schedule} ${finalCommand}`;
|
||||
|
||||
let newCron;
|
||||
if (cronContent.trim() === "") {
|
||||
@@ -212,11 +221,25 @@ export const addCronJob = async (
|
||||
|
||||
export const deleteCronJob = async (id: string): Promise<boolean> => {
|
||||
try {
|
||||
const [user, jobIndexStr] = id.split("-");
|
||||
const jobIndex = parseInt(jobIndexStr);
|
||||
const allJobs = await getCronJobs(false);
|
||||
const targetJob = allJobs.find((j) => j.id === id);
|
||||
|
||||
if (!targetJob) {
|
||||
console.error(`Job with id ${id} not found`);
|
||||
return false;
|
||||
}
|
||||
|
||||
const user = targetJob.user;
|
||||
const cronContent = await readUserCrontab(user);
|
||||
const lines = cronContent.split("\n");
|
||||
const userJobs = parseJobsFromLines(lines, user);
|
||||
const jobIndex = userJobs.findIndex((j) => j.id === id);
|
||||
|
||||
if (jobIndex === -1) {
|
||||
console.error(`Job with id ${id} not found in parsed jobs`);
|
||||
return false;
|
||||
}
|
||||
|
||||
const newCronEntries = deleteJobInLines(lines, jobIndex);
|
||||
const newCron = await cleanCrontabContent(newCronEntries.join("\n"));
|
||||
|
||||
@@ -228,43 +251,54 @@ export const deleteCronJob = async (id: string): Promise<boolean> => {
|
||||
};
|
||||
|
||||
export const updateCronJob = async (
|
||||
id: string,
|
||||
jobData: {
|
||||
id: string;
|
||||
schedule: string;
|
||||
command: string;
|
||||
comment?: string;
|
||||
user: string;
|
||||
},
|
||||
schedule: string,
|
||||
command: string,
|
||||
comment: string = "",
|
||||
logsEnabled: boolean = false
|
||||
): Promise<boolean> => {
|
||||
try {
|
||||
const [user, jobIndexStr] = id.split("-");
|
||||
const jobIndex = parseInt(jobIndexStr);
|
||||
|
||||
const user = jobData.user;
|
||||
const cronContent = await readUserCrontab(user);
|
||||
const lines = cronContent.split("\n");
|
||||
const existingJobs = parseJobsFromLines(lines, user);
|
||||
const currentJob = existingJobs[jobIndex];
|
||||
|
||||
if (!currentJob) {
|
||||
console.error(`Job with index ${jobIndex} not found`);
|
||||
const jobIndex = findJobIndex(jobData, lines, user);
|
||||
|
||||
if (jobIndex === -1) {
|
||||
console.error(`Job not found in crontab`);
|
||||
return false;
|
||||
}
|
||||
|
||||
const isWrappd = isCommandWrapped(command);
|
||||
const isWrapped = isCommandWrapped(command);
|
||||
|
||||
let finalCommand = command;
|
||||
|
||||
if (logsEnabled && !isWrappd) {
|
||||
if (logsEnabled && !isWrapped) {
|
||||
const docker = await isDocker();
|
||||
finalCommand = await wrapCommandWithLogger(id, command, docker, comment);
|
||||
}
|
||||
else if (!logsEnabled && isWrappd) {
|
||||
finalCommand = await wrapCommandWithLogger(
|
||||
jobData.id,
|
||||
command,
|
||||
docker,
|
||||
comment
|
||||
);
|
||||
} else if (!logsEnabled && isWrapped) {
|
||||
finalCommand = unwrapCommand(command);
|
||||
}
|
||||
else if (logsEnabled && isWrappd) {
|
||||
} else if (logsEnabled && isWrapped) {
|
||||
const unwrapped = unwrapCommand(command);
|
||||
const docker = await isDocker();
|
||||
finalCommand = await wrapCommandWithLogger(id, unwrapped, docker, comment);
|
||||
}
|
||||
else {
|
||||
finalCommand = await wrapCommandWithLogger(
|
||||
jobData.id,
|
||||
unwrapped,
|
||||
docker,
|
||||
comment
|
||||
);
|
||||
} else {
|
||||
finalCommand = command;
|
||||
}
|
||||
|
||||
@@ -274,7 +308,8 @@ export const updateCronJob = async (
|
||||
schedule,
|
||||
finalCommand,
|
||||
comment,
|
||||
logsEnabled
|
||||
logsEnabled,
|
||||
jobData.id
|
||||
);
|
||||
const newCron = await cleanCrontabContent(newCronEntries.join("\n"));
|
||||
|
||||
@@ -287,12 +322,26 @@ export const updateCronJob = async (
|
||||
|
||||
export const pauseCronJob = async (id: string): Promise<boolean> => {
|
||||
try {
|
||||
const [user, jobIndexStr] = id.split("-");
|
||||
const jobIndex = parseInt(jobIndexStr);
|
||||
const allJobs = await getCronJobs(false);
|
||||
const targetJob = allJobs.find((j) => j.id === id);
|
||||
|
||||
if (!targetJob) {
|
||||
console.error(`Job with id ${id} not found`);
|
||||
return false;
|
||||
}
|
||||
|
||||
const user = targetJob.user;
|
||||
const cronContent = await readUserCrontab(user);
|
||||
const lines = cronContent.split("\n");
|
||||
const newCronEntries = pauseJobInLines(lines, jobIndex);
|
||||
const userJobs = parseJobsFromLines(lines, user);
|
||||
const jobIndex = userJobs.findIndex((j) => j.id === id);
|
||||
|
||||
if (jobIndex === -1) {
|
||||
console.error(`Job with id ${id} not found in parsed jobs`);
|
||||
return false;
|
||||
}
|
||||
|
||||
const newCronEntries = pauseJobInLines(lines, jobIndex, id);
|
||||
const newCron = await cleanCrontabContent(newCronEntries.join("\n"));
|
||||
|
||||
return await writeUserCrontab(user, newCron);
|
||||
@@ -304,12 +353,26 @@ export const pauseCronJob = async (id: string): Promise<boolean> => {
|
||||
|
||||
export const resumeCronJob = async (id: string): Promise<boolean> => {
|
||||
try {
|
||||
const [user, jobIndexStr] = id.split("-");
|
||||
const jobIndex = parseInt(jobIndexStr);
|
||||
const allJobs = await getCronJobs(false);
|
||||
const targetJob = allJobs.find((j) => j.id === id);
|
||||
|
||||
if (!targetJob) {
|
||||
console.error(`Job with id ${id} not found`);
|
||||
return false;
|
||||
}
|
||||
|
||||
const user = targetJob.user;
|
||||
const cronContent = await readUserCrontab(user);
|
||||
const lines = cronContent.split("\n");
|
||||
const newCronEntries = resumeJobInLines(lines, jobIndex);
|
||||
const userJobs = parseJobsFromLines(lines, user);
|
||||
const jobIndex = userJobs.findIndex((j) => j.id === id);
|
||||
|
||||
if (jobIndex === -1) {
|
||||
console.error(`Job with id ${id} not found in parsed jobs`);
|
||||
return false;
|
||||
}
|
||||
|
||||
const newCronEntries = resumeJobInLines(lines, jobIndex, id);
|
||||
const newCron = await cleanCrontabContent(newCronEntries.join("\n"));
|
||||
|
||||
return await writeUserCrontab(user, newCron);
|
||||
@@ -336,3 +399,31 @@ export const cleanupCrontab = async (): Promise<boolean> => {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export const findJobIndex = (
|
||||
jobData: {
|
||||
id: string;
|
||||
schedule: string;
|
||||
command: string;
|
||||
comment?: string;
|
||||
user: string;
|
||||
paused?: boolean;
|
||||
},
|
||||
lines: string[],
|
||||
user: string
|
||||
): number => {
|
||||
const cronContentStr = lines.join("\n");
|
||||
const userJobs = parseJobsFromLines(lines, user);
|
||||
|
||||
if (cronContentStr.includes(`id: ${jobData.id}`)) {
|
||||
return userJobs.findIndex((j) => j.id === jobData.id);
|
||||
}
|
||||
|
||||
return userJobs.findIndex(
|
||||
(j) =>
|
||||
j.schedule === jobData.schedule &&
|
||||
j.command === jobData.command &&
|
||||
j.user === jobData.user &&
|
||||
(j.comment || "") === (jobData.comment || "")
|
||||
);
|
||||
};
|
||||
|
||||
@@ -11,13 +11,44 @@ export interface JobError {
|
||||
}
|
||||
|
||||
const STORAGE_KEY = "cronmaster-job-errors";
|
||||
const MAX_LOG_AGE_DAYS = parseInt(
|
||||
process.env.NEXT_PUBLIC_MAX_LOG_AGE_DAYS || "30",
|
||||
10
|
||||
);
|
||||
|
||||
/**
|
||||
* Clean up old errors from localStorage based on MAX_LOG_AGE_DAYS.
|
||||
* This is called automatically when getting errors.
|
||||
*/
|
||||
const cleanupOldErrors = (errors: JobError[]): JobError[] => {
|
||||
const maxAgeMs = MAX_LOG_AGE_DAYS * 24 * 60 * 60 * 1000;
|
||||
const now = Date.now();
|
||||
|
||||
return errors.filter((error) => {
|
||||
try {
|
||||
const errorTime = new Date(error.timestamp).getTime();
|
||||
const age = now - errorTime;
|
||||
return age < maxAgeMs;
|
||||
} catch {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const getJobErrors = (): JobError[] => {
|
||||
if (typeof window === "undefined") return [];
|
||||
|
||||
try {
|
||||
const stored = localStorage.getItem(STORAGE_KEY);
|
||||
return stored ? JSON.parse(stored) : [];
|
||||
const errors = stored ? JSON.parse(stored) : [];
|
||||
|
||||
const cleanedErrors = cleanupOldErrors(errors);
|
||||
|
||||
if (cleanedErrors.length !== errors.length) {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(cleanedErrors));
|
||||
}
|
||||
|
||||
return cleanedErrors;
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
@@ -37,7 +68,7 @@ export const setJobError = (error: JobError) => {
|
||||
}
|
||||
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(errors));
|
||||
} catch { }
|
||||
} catch {}
|
||||
};
|
||||
|
||||
export const removeJobError = (errorId: string) => {
|
||||
@@ -47,7 +78,7 @@ export const removeJobError = (errorId: string) => {
|
||||
const errors = getJobErrors();
|
||||
const filtered = errors.filter((e) => e.id !== errorId);
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(filtered));
|
||||
} catch { }
|
||||
} catch {}
|
||||
};
|
||||
|
||||
export const getJobErrorsByJobId = (jobId: string): JobError[] => {
|
||||
@@ -59,5 +90,5 @@ export const clearAllJobErrors = () => {
|
||||
|
||||
try {
|
||||
localStorage.removeItem(STORAGE_KEY);
|
||||
} catch { }
|
||||
} catch {}
|
||||
};
|
||||
|
||||
@@ -5,19 +5,26 @@ export const cn = (...inputs: ClassValue[]) => {
|
||||
return twMerge(clsx(inputs));
|
||||
};
|
||||
|
||||
type TranslationFunction = (key: string) => string;
|
||||
|
||||
export const getTranslations = async (
|
||||
locale: string = process.env.LOCALE || "en"
|
||||
): Promise<TranslationFunction> => {
|
||||
const messages = (await import(`../_translations/${locale}.json`)).default;
|
||||
|
||||
return (key: string) => {
|
||||
const keys = key.split(".");
|
||||
let value: any = messages;
|
||||
for (const k of keys) {
|
||||
value = value?.[k];
|
||||
export const copyToClipboard = async (text: string): Promise<boolean> => {
|
||||
try {
|
||||
if (navigator?.clipboard?.writeText) {
|
||||
await navigator.clipboard.writeText(text);
|
||||
return true;
|
||||
} else {
|
||||
const textArea = document.createElement("textarea");
|
||||
textArea.value = text;
|
||||
textArea.style.position = "fixed";
|
||||
textArea.style.left = "-9999px";
|
||||
textArea.style.top = "-9999px";
|
||||
document.body.appendChild(textArea);
|
||||
textArea.focus();
|
||||
textArea.select();
|
||||
const successful = document.execCommand("copy");
|
||||
document.body.removeChild(textArea);
|
||||
return successful;
|
||||
}
|
||||
return value || key;
|
||||
};
|
||||
} catch (err) {
|
||||
console.error("Failed to copy to clipboard:", err);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -7,9 +7,11 @@ import {
|
||||
saveRunningJob,
|
||||
updateRunningJob,
|
||||
getRunningJob,
|
||||
removeRunningJob,
|
||||
} from "./running-jobs-utils";
|
||||
import { sseBroadcaster } from "./sse-broadcaster";
|
||||
import { generateLogFolderName } from "./wrapper-utils";
|
||||
import { generateLogFolderName, cleanupOldLogFiles } from "./wrapper-utils";
|
||||
import { watchForLogFile } from "./log-watcher";
|
||||
|
||||
const execAsync = promisify(exec);
|
||||
|
||||
@@ -83,18 +85,29 @@ export const runJobInBackground = async (
|
||||
|
||||
child.unref();
|
||||
|
||||
const jobStartTime = new Date();
|
||||
|
||||
saveRunningJob({
|
||||
id: runId,
|
||||
cronJobId: job.id,
|
||||
pid: child.pid!,
|
||||
startTime: new Date().toISOString(),
|
||||
startTime: jobStartTime.toISOString(),
|
||||
status: "running",
|
||||
logFolderName,
|
||||
});
|
||||
|
||||
watchForLogFile(runId, logFolderName, jobStartTime, (logFileName) => {
|
||||
try {
|
||||
updateRunningJob(runId, { logFileName });
|
||||
console.log(`[RunningJob] Cached logFileName for ${runId}: ${logFileName}`);
|
||||
} catch (error) {
|
||||
console.error(`[RunningJob] Failed to cache logFileName for ${runId}:`, error);
|
||||
}
|
||||
});
|
||||
|
||||
sseBroadcaster.broadcast({
|
||||
type: "job-started",
|
||||
timestamp: new Date().toISOString(),
|
||||
timestamp: jobStartTime.toISOString(),
|
||||
data: {
|
||||
runId,
|
||||
cronJobId: job.id,
|
||||
@@ -112,9 +125,6 @@ export const runJobInBackground = async (
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Monitor a running job and update status when complete
|
||||
*/
|
||||
const monitorRunningJob = (runId: string, pid: number): void => {
|
||||
const checkInterval = setInterval(async () => {
|
||||
try {
|
||||
@@ -130,6 +140,15 @@ const monitorRunningJob = (runId: string, pid: number): void => {
|
||||
exitCode,
|
||||
});
|
||||
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
removeRunningJob(runId);
|
||||
await cleanupOldLogFiles(runningJob?.cronJobId || "");
|
||||
} catch (error) {
|
||||
console.error(`Error cleaning up job ${runId}:`, error);
|
||||
}
|
||||
}, 5000);
|
||||
|
||||
const runningJob = getRunningJob(runId);
|
||||
|
||||
if (runningJob) {
|
||||
@@ -176,7 +195,7 @@ const getExitCodeFromLog = async (
|
||||
runId: string
|
||||
): Promise<number | undefined> => {
|
||||
try {
|
||||
const { readdir, readFile } = await import("fs/promises");
|
||||
const { readdir, readFile, access } = await import("fs/promises");
|
||||
const path = await import("path");
|
||||
|
||||
const job = getRunningJob(runId);
|
||||
@@ -185,6 +204,13 @@ const getExitCodeFromLog = async (
|
||||
}
|
||||
|
||||
const logDir = path.join(process.cwd(), "data", "logs", job.logFolderName);
|
||||
|
||||
try {
|
||||
await access(logDir);
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const files = await readdir(logDir);
|
||||
|
||||
const sortedFiles = files.sort().reverse();
|
||||
|
||||
@@ -1,8 +1,25 @@
|
||||
import { CronJob } from "@/app/_utils/cronjob-utils";
|
||||
import { generateShortUUID } from "@/app/_utils/uuid-utils";
|
||||
import { createHash } from "crypto";
|
||||
|
||||
const generateStableJobId = (
|
||||
schedule: string,
|
||||
command: string,
|
||||
user: string,
|
||||
comment?: string,
|
||||
lineIndex?: number
|
||||
): string => {
|
||||
const content = `${schedule}|${command}|${user}|${comment || ""}|${
|
||||
lineIndex || 0
|
||||
}`;
|
||||
const hash = createHash("md5").update(content).digest("hex");
|
||||
return hash.substring(0, 8);
|
||||
};
|
||||
|
||||
export const pauseJobInLines = (
|
||||
lines: string[],
|
||||
targetJobIndex: number
|
||||
targetJobIndex: number,
|
||||
uuid: string
|
||||
): string[] => {
|
||||
const newCronEntries: string[] = [];
|
||||
let currentJobIndex = 0;
|
||||
@@ -51,9 +68,15 @@ export const pauseJobInLines = (
|
||||
lines[i + 1].trim()
|
||||
) {
|
||||
if (currentJobIndex === targetJobIndex) {
|
||||
const comment = trimmedLine.substring(1).trim();
|
||||
const commentText = trimmedLine.substring(1).trim();
|
||||
const { comment, logsEnabled } = parseCommentMetadata(commentText);
|
||||
const formattedComment = formatCommentWithMetadata(
|
||||
comment,
|
||||
logsEnabled,
|
||||
uuid
|
||||
);
|
||||
const nextLine = lines[i + 1].trim();
|
||||
const pausedEntry = `# PAUSED: ${comment}\n# ${nextLine}`;
|
||||
const pausedEntry = `# PAUSED: ${formattedComment}\n# ${nextLine}`;
|
||||
newCronEntries.push(pausedEntry);
|
||||
i += 2;
|
||||
currentJobIndex++;
|
||||
@@ -71,7 +94,8 @@ export const pauseJobInLines = (
|
||||
}
|
||||
|
||||
if (currentJobIndex === targetJobIndex) {
|
||||
const pausedEntry = `# PAUSED:\n# ${trimmedLine}`;
|
||||
const formattedComment = formatCommentWithMetadata("", false, uuid);
|
||||
const pausedEntry = `# PAUSED: ${formattedComment}\n# ${trimmedLine}`;
|
||||
newCronEntries.push(pausedEntry);
|
||||
} else {
|
||||
newCronEntries.push(line);
|
||||
@@ -86,7 +110,8 @@ export const pauseJobInLines = (
|
||||
|
||||
export const resumeJobInLines = (
|
||||
lines: string[],
|
||||
targetJobIndex: number
|
||||
targetJobIndex: number,
|
||||
uuid: string
|
||||
): string[] => {
|
||||
const newCronEntries: string[] = [];
|
||||
let currentJobIndex = 0;
|
||||
@@ -118,10 +143,18 @@ export const resumeJobInLines = (
|
||||
|
||||
if (trimmedLine.startsWith("# PAUSED:")) {
|
||||
if (currentJobIndex === targetJobIndex) {
|
||||
const comment = trimmedLine.substring(9).trim();
|
||||
const commentText = trimmedLine.substring(9).trim();
|
||||
const { comment, logsEnabled } = parseCommentMetadata(commentText);
|
||||
if (i + 1 < lines.length && lines[i + 1].trim().startsWith("# ")) {
|
||||
const cronLine = lines[i + 1].trim().substring(2);
|
||||
const resumedEntry = comment ? `# ${comment}\n${cronLine}` : cronLine;
|
||||
const formattedComment = formatCommentWithMetadata(
|
||||
comment,
|
||||
logsEnabled,
|
||||
uuid
|
||||
);
|
||||
const resumedEntry = formattedComment
|
||||
? `# ${formattedComment}\n${cronLine}`
|
||||
: cronLine;
|
||||
newCronEntries.push(resumedEntry);
|
||||
i += 2;
|
||||
} else {
|
||||
@@ -156,47 +189,95 @@ export const resumeJobInLines = (
|
||||
|
||||
export const parseCommentMetadata = (
|
||||
commentText: string
|
||||
): { comment: string; logsEnabled: boolean } => {
|
||||
): { comment: string; logsEnabled: boolean; uuid?: string } => {
|
||||
if (!commentText) {
|
||||
return { comment: "", logsEnabled: false };
|
||||
}
|
||||
|
||||
const parts = commentText.split("|").map((p) => p.trim());
|
||||
let comment = parts[0] || "";
|
||||
let comment = "";
|
||||
let logsEnabled = false;
|
||||
let uuid: string | undefined;
|
||||
|
||||
if (parts.length > 1) {
|
||||
// Format: "fccview absolutely rocks | logsEnabled: true"
|
||||
const metadata = parts[1];
|
||||
const logsMatch = metadata.match(/logsEnabled:\s*(true|false)/i);
|
||||
if (logsMatch) {
|
||||
logsEnabled = logsMatch[1].toLowerCase() === "true";
|
||||
const firstPartIsMetadata =
|
||||
parts[0].match(/logsEnabled:\s*(true|false)/i) ||
|
||||
parts[0].match(/id:\s*([a-z0-9]{8}|[a-z0-9]{4}-[a-z0-9]{4})/i);
|
||||
|
||||
if (firstPartIsMetadata) {
|
||||
comment = "";
|
||||
const metadata = parts.join("|").trim();
|
||||
|
||||
const logsMatch = metadata.match(/logsEnabled:\s*(true|false)/i);
|
||||
if (logsMatch) {
|
||||
logsEnabled = logsMatch[1].toLowerCase() === "true";
|
||||
}
|
||||
|
||||
const uuidMatches = Array.from(
|
||||
metadata.matchAll(/id:\s*([a-z0-9]{8}|[a-z0-9]{4}-[a-z0-9]{4})/gi)
|
||||
);
|
||||
if (uuidMatches.length > 0) {
|
||||
uuid = uuidMatches[uuidMatches.length - 1][1].toLowerCase();
|
||||
}
|
||||
} else {
|
||||
comment = parts[0] || "";
|
||||
const metadata = parts.slice(1).join("|").trim();
|
||||
|
||||
const logsMatch = metadata.match(/logsEnabled:\s*(true|false)/i);
|
||||
if (logsMatch) {
|
||||
logsEnabled = logsMatch[1].toLowerCase() === "true";
|
||||
}
|
||||
|
||||
const uuidMatches = Array.from(
|
||||
metadata.matchAll(/id:\s*([a-z0-9]{8}|[a-z0-9]{4}-[a-z0-9]{4})/gi)
|
||||
);
|
||||
if (uuidMatches.length > 0) {
|
||||
uuid = uuidMatches[uuidMatches.length - 1][1].toLowerCase();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Format: logsEnabled: true
|
||||
const logsMatch = commentText.match(/^logsEnabled:\s*(true|false)$/i);
|
||||
if (logsMatch) {
|
||||
logsEnabled = logsMatch[1].toLowerCase() === "true";
|
||||
const logsMatch = commentText.match(/logsEnabled:\s*(true|false)/i);
|
||||
const uuidMatch = commentText.match(
|
||||
/id:\s*([a-z0-9]{8}|[a-z0-9]{4}-[a-z0-9]{4})/i
|
||||
);
|
||||
|
||||
if (logsMatch || uuidMatch) {
|
||||
if (logsMatch) {
|
||||
logsEnabled = logsMatch[1].toLowerCase() === "true";
|
||||
}
|
||||
if (uuidMatch) {
|
||||
uuid = uuidMatch[1].toLowerCase();
|
||||
}
|
||||
comment = "";
|
||||
} else {
|
||||
comment = parts[0] || "";
|
||||
}
|
||||
}
|
||||
|
||||
return { comment, logsEnabled };
|
||||
return { comment, logsEnabled, uuid };
|
||||
};
|
||||
|
||||
export const formatCommentWithMetadata = (
|
||||
comment: string,
|
||||
logsEnabled: boolean
|
||||
logsEnabled: boolean,
|
||||
uuid: string
|
||||
): string => {
|
||||
const trimmedComment = comment.trim();
|
||||
const metadataParts: string[] = [];
|
||||
|
||||
if (logsEnabled) {
|
||||
return trimmedComment
|
||||
? `${trimmedComment} | logsEnabled: true`
|
||||
: `logsEnabled: true`;
|
||||
metadataParts.push("logsEnabled: true");
|
||||
}
|
||||
|
||||
return trimmedComment;
|
||||
metadataParts.push(`id: ${uuid}`);
|
||||
|
||||
const metadata = metadataParts.join(" | ");
|
||||
|
||||
if (trimmedComment) {
|
||||
return `${trimmedComment} | ${metadata}`;
|
||||
}
|
||||
|
||||
return metadata;
|
||||
};
|
||||
|
||||
export const parseJobsFromLines = (
|
||||
@@ -206,6 +287,7 @@ export const parseJobsFromLines = (
|
||||
const jobs: CronJob[] = [];
|
||||
let currentComment = "";
|
||||
let currentLogsEnabled = false;
|
||||
let currentUuid: string | undefined;
|
||||
let jobIndex = 0;
|
||||
let i = 0;
|
||||
|
||||
@@ -228,7 +310,7 @@ export const parseJobsFromLines = (
|
||||
|
||||
if (trimmedLine.startsWith("# PAUSED:")) {
|
||||
const commentText = trimmedLine.substring(9).trim();
|
||||
const { comment, logsEnabled } = parseCommentMetadata(commentText);
|
||||
const { comment, logsEnabled, uuid } = parseCommentMetadata(commentText);
|
||||
|
||||
if (i + 1 < lines.length) {
|
||||
const nextLine = lines[i + 1].trim();
|
||||
@@ -239,8 +321,11 @@ export const parseJobsFromLines = (
|
||||
const schedule = parts.slice(0, 5).join(" ");
|
||||
const command = parts.slice(5).join(" ");
|
||||
|
||||
const jobId =
|
||||
uuid || generateStableJobId(schedule, command, user, comment, i);
|
||||
|
||||
jobs.push({
|
||||
id: `${user}-${jobIndex}`,
|
||||
id: jobId,
|
||||
schedule,
|
||||
command,
|
||||
comment: comment || undefined,
|
||||
@@ -266,9 +351,11 @@ export const parseJobsFromLines = (
|
||||
lines[i + 1].trim()
|
||||
) {
|
||||
const commentText = trimmedLine.substring(1).trim();
|
||||
const { comment, logsEnabled } = parseCommentMetadata(commentText);
|
||||
const { comment, logsEnabled, uuid } =
|
||||
parseCommentMetadata(commentText);
|
||||
currentComment = comment;
|
||||
currentLogsEnabled = logsEnabled;
|
||||
currentUuid = uuid;
|
||||
i++;
|
||||
continue;
|
||||
} else {
|
||||
@@ -291,8 +378,12 @@ export const parseJobsFromLines = (
|
||||
}
|
||||
|
||||
if (schedule && command) {
|
||||
const jobId =
|
||||
currentUuid ||
|
||||
generateStableJobId(schedule, command, user, currentComment, i);
|
||||
|
||||
jobs.push({
|
||||
id: `${user}-${jobIndex}`,
|
||||
id: jobId,
|
||||
schedule,
|
||||
command,
|
||||
comment: currentComment || undefined,
|
||||
@@ -304,6 +395,7 @@ export const parseJobsFromLines = (
|
||||
jobIndex++;
|
||||
currentComment = "";
|
||||
currentLogsEnabled = false;
|
||||
currentUuid = undefined;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
@@ -399,7 +491,8 @@ export const updateJobInLines = (
|
||||
schedule: string,
|
||||
command: string,
|
||||
comment: string = "",
|
||||
logsEnabled: boolean = false
|
||||
logsEnabled: boolean = false,
|
||||
uuid: string
|
||||
): string[] => {
|
||||
const newCronEntries: string[] = [];
|
||||
let currentJobIndex = 0;
|
||||
@@ -433,7 +526,8 @@ export const updateJobInLines = (
|
||||
if (currentJobIndex === targetJobIndex) {
|
||||
const formattedComment = formatCommentWithMetadata(
|
||||
comment,
|
||||
logsEnabled
|
||||
logsEnabled,
|
||||
uuid
|
||||
);
|
||||
const newEntry = formattedComment
|
||||
? `# PAUSED: ${formattedComment}\n# ${schedule} ${command}`
|
||||
@@ -466,7 +560,8 @@ export const updateJobInLines = (
|
||||
if (currentJobIndex === targetJobIndex) {
|
||||
const formattedComment = formatCommentWithMetadata(
|
||||
comment,
|
||||
logsEnabled
|
||||
logsEnabled,
|
||||
uuid
|
||||
);
|
||||
const newEntry = formattedComment
|
||||
? `# ${formattedComment}\n${schedule} ${command}`
|
||||
@@ -487,7 +582,11 @@ export const updateJobInLines = (
|
||||
}
|
||||
|
||||
if (currentJobIndex === targetJobIndex) {
|
||||
const formattedComment = formatCommentWithMetadata(comment, logsEnabled);
|
||||
const formattedComment = formatCommentWithMetadata(
|
||||
comment,
|
||||
logsEnabled,
|
||||
uuid
|
||||
);
|
||||
const newEntry = formattedComment
|
||||
? `# ${formattedComment}\n${schedule} ${command}`
|
||||
: `${schedule} ${command}`;
|
||||
|
||||
@@ -95,3 +95,62 @@ export const stopLogWatcher = () => {
|
||||
watcher = null;
|
||||
}
|
||||
};
|
||||
|
||||
export const watchForLogFile = (
|
||||
runId: string,
|
||||
logFolderName: string,
|
||||
jobStartTime: Date,
|
||||
callback: (logFileName: string) => void
|
||||
): NodeJS.Timeout => {
|
||||
const logDir = path.join(LOGS_DIR, logFolderName);
|
||||
const startTime = jobStartTime.getTime();
|
||||
const maxAttempts = 30;
|
||||
let attempts = 0;
|
||||
|
||||
const checkInterval = setInterval(() => {
|
||||
attempts++;
|
||||
|
||||
if (attempts > maxAttempts) {
|
||||
console.warn(`[LogWatcher] Timeout waiting for log file for ${runId}`);
|
||||
clearInterval(checkInterval);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (!existsSync(logDir)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const files = readdirSync(logDir);
|
||||
const logFiles = files
|
||||
.filter((f) => f.endsWith(".log"))
|
||||
.map((f) => {
|
||||
const filePath = path.join(logDir, f);
|
||||
try {
|
||||
const stats = statSync(filePath);
|
||||
return {
|
||||
name: f,
|
||||
birthtime: stats.birthtime || stats.mtime,
|
||||
};
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter((f): f is { name: string; birthtime: Date } => f !== null);
|
||||
|
||||
const matchingFile = logFiles.find((f) => {
|
||||
const fileTime = f.birthtime.getTime();
|
||||
return fileTime >= startTime - 5000 && fileTime <= startTime + 30000;
|
||||
});
|
||||
|
||||
if (matchingFile) {
|
||||
clearInterval(checkInterval);
|
||||
callback(matchingFile.name);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`[LogWatcher] Error watching for log file ${runId}:`, error);
|
||||
}
|
||||
}, 500);
|
||||
|
||||
return checkInterval;
|
||||
};
|
||||
|
||||
@@ -86,4 +86,4 @@ export const getScriptById = (
|
||||
id: string
|
||||
): Script | undefined => {
|
||||
return scripts.find((script) => script.id === id);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -15,12 +15,20 @@ class SSEBroadcaster {
|
||||
controller,
|
||||
connectedAt: new Date(),
|
||||
});
|
||||
console.log(`[SSE] Client ${id} connected. Total clients: ${this.clients.size}`);
|
||||
if (process.env.DEBUGGER) {
|
||||
console.log(
|
||||
`[SSE] Client ${id} connected. Total clients: ${this.clients.size}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
removeClient(id: string): void {
|
||||
this.clients.delete(id);
|
||||
console.log(`[SSE] Client ${id} disconnected. Total clients: ${this.clients.size}`);
|
||||
if (process.env.DEBUGGER) {
|
||||
console.log(
|
||||
`[SSE] Client ${id} disconnected. Total clients: ${this.clients.size}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
broadcast(event: SSEEvent): void {
|
||||
@@ -36,23 +44,29 @@ class SSEBroadcaster {
|
||||
client.controller.enqueue(encoded);
|
||||
successCount++;
|
||||
} catch (error) {
|
||||
console.error(`[SSE] Failed to send to client ${id}:`, error);
|
||||
if (process.env.DEBUGGER) {
|
||||
console.error(`[SSE] Failed to send to client ${id}:`, error);
|
||||
}
|
||||
this.removeClient(id);
|
||||
failCount++;
|
||||
}
|
||||
});
|
||||
|
||||
if (this.clients.size > 0) {
|
||||
console.log(
|
||||
`[SSE] Broadcast ${event.type} to ${successCount} clients (${failCount} failed)`
|
||||
);
|
||||
if (process.env.DEBUGGER) {
|
||||
console.log(
|
||||
`[SSE] Broadcast ${event.type} to ${successCount} clients (${failCount} failed)`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sendToClient(clientId: string, event: SSEEvent): void {
|
||||
const client = this.clients.get(clientId);
|
||||
if (!client) {
|
||||
console.warn(`[SSE] Client ${clientId} not found`);
|
||||
if (process.env.DEBUGGER) {
|
||||
console.warn(`[SSE] Client ${clientId} not found`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -61,7 +75,9 @@ class SSEBroadcaster {
|
||||
const encoder = new TextEncoder();
|
||||
client.controller.enqueue(encoder.encode(formattedEvent));
|
||||
} catch (error) {
|
||||
console.error(`[SSE] Failed to send to client ${clientId}:`, error);
|
||||
if (process.env.DEBUGGER) {
|
||||
console.error(`[SSE] Failed to send to client ${clientId}:`, error);
|
||||
}
|
||||
this.removeClient(clientId);
|
||||
}
|
||||
}
|
||||
|
||||
15
app/_utils/uuid-utils.ts
Normal file
15
app/_utils/uuid-utils.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
export const generateShortUUID = (): string => {
|
||||
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
||||
const part1 = Array.from({ length: 4 }, () =>
|
||||
chars[Math.floor(Math.random() * chars.length)]
|
||||
).join('');
|
||||
const part2 = Array.from({ length: 4 }, () =>
|
||||
chars[Math.floor(Math.random() * chars.length)]
|
||||
).join('');
|
||||
|
||||
return `${part1}-${part2}`;
|
||||
};
|
||||
|
||||
export const isValidShortUUID = (uuid: string): boolean => {
|
||||
return /^[a-z0-9]{4}-[a-z0-9]{4}$/.test(uuid);
|
||||
};
|
||||
@@ -15,10 +15,6 @@ export const generateLogFolderName = (
|
||||
jobId: string,
|
||||
comment?: string
|
||||
): string => {
|
||||
if (comment && comment.trim()) {
|
||||
const sanitized = sanitizeForFilesystem(comment.trim());
|
||||
return sanitized ? `${sanitized}_${jobId}` : jobId;
|
||||
}
|
||||
return jobId;
|
||||
};
|
||||
|
||||
@@ -38,7 +34,6 @@ export const ensureWrapperScriptInData = (): string => {
|
||||
if (!existsSync(dataScriptPath)) {
|
||||
try {
|
||||
copyFileSync(sourceScriptPath, dataScriptPath);
|
||||
console.log(`Copied wrapper script to ${dataScriptPath}`);
|
||||
} catch (error) {
|
||||
console.error("Failed to copy wrapper script to data directory:", error);
|
||||
return sourceScriptPath;
|
||||
@@ -105,3 +100,55 @@ export const extractJobIdFromWrappedCommand = (
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
export const cleanupOldLogFiles = async (
|
||||
jobId: string,
|
||||
maxFiles: number = 10
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { readdir, stat, unlink } = await import("fs/promises");
|
||||
const logFolderName = generateLogFolderName(jobId);
|
||||
const logDir = path.join(process.cwd(), "data", "logs", logFolderName);
|
||||
|
||||
try {
|
||||
await stat(logDir);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
|
||||
const files = await readdir(logDir);
|
||||
const logFiles = files
|
||||
.filter((f) => f.endsWith(".log"))
|
||||
.map((f) => ({
|
||||
name: f,
|
||||
path: path.join(logDir, f),
|
||||
stats: null as any,
|
||||
}));
|
||||
|
||||
for (const file of logFiles) {
|
||||
try {
|
||||
file.stats = await stat(file.path);
|
||||
} catch (error) {
|
||||
console.error(`Error stat-ing log file ${file.path}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
const validFiles = logFiles
|
||||
.filter((f) => f.stats)
|
||||
.sort((a, b) => b.stats.mtime.getTime() - a.stats.mtime.getTime());
|
||||
|
||||
if (validFiles.length > maxFiles) {
|
||||
const filesToDelete = validFiles.slice(maxFiles);
|
||||
for (const file of filesToDelete) {
|
||||
try {
|
||||
await unlink(file.path);
|
||||
console.log(`Cleaned up old log file: ${file.path}`);
|
||||
} catch (error) {
|
||||
console.error(`Error deleting log file ${file.path}:`, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error cleaning up log files for job ${jobId}:`, error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,10 +3,6 @@ import { validateSession, getSessionCookieName } from "@/app/_utils/session-util
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
/**
|
||||
* Validate session for middleware
|
||||
* This runs in Node.js runtime so it can access the filesystem
|
||||
*/
|
||||
export async function GET(request: NextRequest) {
|
||||
const cookieName = getSessionCookieName();
|
||||
const sessionId = request.cookies.get(cookieName)?.value;
|
||||
|
||||
@@ -32,6 +32,13 @@ export const POST = async (request: NextRequest) => {
|
||||
);
|
||||
|
||||
const cookieName = getSessionCookieName();
|
||||
|
||||
if (process.env.DEBUGGER) {
|
||||
console.log("LOGIN - cookieName:", cookieName);
|
||||
console.log("LOGIN - NODE_ENV:", process.env.NODE_ENV);
|
||||
console.log("LOGIN - HTTPS:", process.env.HTTPS);
|
||||
console.log("LOGIN - sessionId:", sessionId.substring(0, 10) + "...");
|
||||
}
|
||||
response.cookies.set(cookieName, sessionId, {
|
||||
httpOnly: true,
|
||||
secure:
|
||||
|
||||
@@ -87,7 +87,7 @@ export async function DELETE(
|
||||
if (authError) return authError;
|
||||
|
||||
try {
|
||||
const result = await removeCronJob(params.id);
|
||||
const result = await removeCronJob({ id: params.id, schedule: "", command: "", user: "" });
|
||||
|
||||
if (result.success) {
|
||||
return NextResponse.json(result);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getRunningJob } from "@/app/_utils/running-jobs-utils";
|
||||
import { readFile } from "fs/promises";
|
||||
import { readFile, open } from "fs/promises";
|
||||
import { existsSync } from "fs";
|
||||
import path from "path";
|
||||
import { requireAuth } from "@/app/_utils/api-auth-utils";
|
||||
@@ -14,6 +14,13 @@ export const GET = async (request: NextRequest) => {
|
||||
try {
|
||||
const searchParams = request.nextUrl.searchParams;
|
||||
const runId = searchParams.get("runId");
|
||||
const offsetStr = searchParams.get("offset");
|
||||
const offset = offsetStr ? parseInt(offsetStr, 10) : 0;
|
||||
|
||||
const maxLinesStr = searchParams.get("maxLines");
|
||||
const maxLines = maxLinesStr
|
||||
? Math.min(Math.max(parseInt(maxLinesStr, 10), 100), 5000)
|
||||
: 500;
|
||||
|
||||
if (!runId) {
|
||||
return NextResponse.json(
|
||||
@@ -66,16 +73,154 @@ export const GET = async (request: NextRequest) => {
|
||||
}
|
||||
|
||||
const sortedFiles = files.sort().reverse();
|
||||
const latestLogFile = path.join(logDir, sortedFiles[0]);
|
||||
|
||||
const content = await readFile(latestLogFile, "utf-8");
|
||||
let latestLogFile: string | null = null;
|
||||
let latestStats: any = null;
|
||||
const jobStartTime = new Date(job.startTime);
|
||||
const TIME_TOLERANCE_MS = 5000;
|
||||
|
||||
if (job.logFileName) {
|
||||
const cachedFilePath = path.join(logDir, job.logFileName);
|
||||
if (existsSync(cachedFilePath)) {
|
||||
try {
|
||||
const { stat } = await import("fs/promises");
|
||||
latestLogFile = cachedFilePath;
|
||||
latestStats = await stat(latestLogFile);
|
||||
} catch (error) {
|
||||
console.error(`Error reading cached log file ${job.logFileName}:`, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!latestLogFile) {
|
||||
for (const file of sortedFiles) {
|
||||
const filePath = path.join(logDir, file);
|
||||
try {
|
||||
const { stat } = await import("fs/promises");
|
||||
const stats = await stat(filePath);
|
||||
const fileCreateTime = stats.birthtime || stats.mtime;
|
||||
|
||||
if (fileCreateTime.getTime() >= jobStartTime.getTime() - TIME_TOLERANCE_MS) {
|
||||
latestLogFile = filePath;
|
||||
latestStats = stats;
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error checking file ${file}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
if (!latestLogFile && sortedFiles.length > 0) {
|
||||
try {
|
||||
const { stat } = await import("fs/promises");
|
||||
const fallbackPath = path.join(logDir, sortedFiles[0]);
|
||||
const fallbackStats = await stat(fallbackPath);
|
||||
const now = new Date();
|
||||
const fileAge = now.getTime() - (fallbackStats.birthtime || fallbackStats.mtime).getTime();
|
||||
|
||||
if (fileAge <= TIME_TOLERANCE_MS) {
|
||||
latestLogFile = fallbackPath;
|
||||
latestStats = fallbackStats;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error stat-ing fallback file:`, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!latestLogFile || !latestStats) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
status: job.status,
|
||||
content: "",
|
||||
message: "No log file found for this run",
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
}
|
||||
|
||||
const fileSize = latestStats.size;
|
||||
|
||||
let displayedLines: string[] = [];
|
||||
let truncated = false;
|
||||
let totalLines = 0;
|
||||
let content = "";
|
||||
let newContent = "";
|
||||
|
||||
if (offset === 0) {
|
||||
const AVERAGE_LINE_LENGTH = 100;
|
||||
const ESTIMATED_BYTES = maxLines * AVERAGE_LINE_LENGTH * 2;
|
||||
const bytesToRead = Math.min(ESTIMATED_BYTES, fileSize);
|
||||
|
||||
if (bytesToRead < fileSize) {
|
||||
const fileHandle = await open(latestLogFile, "r");
|
||||
const buffer = Buffer.alloc(bytesToRead);
|
||||
await fileHandle.read(buffer, 0, bytesToRead, fileSize - bytesToRead);
|
||||
await fileHandle.close();
|
||||
|
||||
const tailContent = buffer.toString("utf-8");
|
||||
const lines = tailContent.split("\n");
|
||||
|
||||
if (lines[0] && lines[0].length > 0) {
|
||||
lines.shift();
|
||||
}
|
||||
|
||||
if (lines.length > maxLines) {
|
||||
displayedLines = lines.slice(-maxLines);
|
||||
truncated = true;
|
||||
} else {
|
||||
displayedLines = lines;
|
||||
truncated = true;
|
||||
}
|
||||
} else {
|
||||
const fullContent = await readFile(latestLogFile, "utf-8");
|
||||
const allLines = fullContent.split("\n");
|
||||
totalLines = allLines.length;
|
||||
|
||||
if (totalLines > maxLines) {
|
||||
displayedLines = allLines.slice(-maxLines);
|
||||
truncated = true;
|
||||
} else {
|
||||
displayedLines = allLines;
|
||||
}
|
||||
}
|
||||
|
||||
if (truncated) {
|
||||
content = `[LOG TRUNCATED - Showing last ${maxLines} lines (${(fileSize / 1024 / 1024).toFixed(2)}MB total)]\n\n` + displayedLines.join("\n");
|
||||
} else {
|
||||
content = displayedLines.join("\n");
|
||||
totalLines = displayedLines.length;
|
||||
}
|
||||
newContent = content;
|
||||
} else {
|
||||
if (offset < fileSize) {
|
||||
const fileHandle = await open(latestLogFile, "r");
|
||||
const bytesToRead = fileSize - offset;
|
||||
const buffer = Buffer.alloc(bytesToRead);
|
||||
await fileHandle.read(buffer, 0, bytesToRead, offset);
|
||||
await fileHandle.close();
|
||||
|
||||
newContent = buffer.toString("utf-8");
|
||||
const newLines = newContent.split("\n").filter(l => l.length > 0);
|
||||
if (newLines.length > 0) {
|
||||
content = newContent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
status: job.status,
|
||||
content,
|
||||
newContent,
|
||||
fullContent: offset === 0 ? content : undefined,
|
||||
logFile: sortedFiles[0],
|
||||
isComplete: job.status !== "running",
|
||||
exitCode: job.exitCode,
|
||||
fileSize,
|
||||
offset,
|
||||
totalLines: offset === 0 && !truncated ? totalLines : undefined,
|
||||
displayedLines: displayedLines.length,
|
||||
truncated,
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error("Error streaming log:", error);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getTranslations } from "@/app/_utils/global-utils";
|
||||
import { getTranslations } from "@/app/_server/actions/translations";
|
||||
import * as si from "systeminformation";
|
||||
import {
|
||||
getPing,
|
||||
@@ -18,6 +18,11 @@ export const dynamic = "force-dynamic";
|
||||
export const GET = async (request: NextRequest) => {
|
||||
const authError = await requireAuth(request);
|
||||
if (authError) return authError;
|
||||
|
||||
if (process.env.DISABLE_SYSTEM_STATS === "true") {
|
||||
return NextResponse.json(null);
|
||||
}
|
||||
|
||||
try {
|
||||
const t = await getTranslations();
|
||||
|
||||
@@ -71,8 +76,8 @@ export const GET = async (request: NextRequest) => {
|
||||
network: {
|
||||
speed:
|
||||
mainInterface &&
|
||||
mainInterface.rx_sec != null &&
|
||||
mainInterface.tx_sec != null
|
||||
mainInterface.rx_sec != null &&
|
||||
mainInterface.tx_sec != null
|
||||
? `${Math.round(rxSpeed + txSpeed)} Mbps`
|
||||
: t("system.unknown"),
|
||||
latency: latency,
|
||||
|
||||
38
app/api/system/wrapper-check/route.ts
Normal file
38
app/api/system/wrapper-check/route.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { readFileSync, existsSync } from "fs";
|
||||
import path from "path";
|
||||
import { DATA_DIR } from "@/app/_consts/file";
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const officialScriptPath = path.join(
|
||||
process.cwd(),
|
||||
"app",
|
||||
"_scripts",
|
||||
"cron-log-wrapper.sh"
|
||||
);
|
||||
|
||||
const dataScriptPath = path.join(
|
||||
process.cwd(),
|
||||
DATA_DIR,
|
||||
"cron-log-wrapper.sh"
|
||||
);
|
||||
|
||||
if (!existsSync(dataScriptPath)) {
|
||||
return NextResponse.json({ modified: false });
|
||||
}
|
||||
|
||||
const officialScript = readFileSync(officialScriptPath, "utf-8");
|
||||
const dataScript = readFileSync(dataScriptPath, "utf-8");
|
||||
|
||||
const modified = officialScript !== dataScript;
|
||||
|
||||
return NextResponse.json({ modified });
|
||||
} catch (error) {
|
||||
console.error("Error checking wrapper script:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to check wrapper script" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
521
app/globals.css
521
app/globals.css
@@ -1,300 +1,263 @@
|
||||
/* eslint-disable */
|
||||
/* @ts-nocheck */
|
||||
|
||||
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
|
||||
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;600;700&display=swap');
|
||||
@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@300;400;500;600;700&display=swap');
|
||||
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
@layer base {
|
||||
:root {
|
||||
--font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
--font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', 'Monaco', 'Courier New', monospace;
|
||||
--background: 0 0% 100%;
|
||||
--foreground: 240 10% 3.9%;
|
||||
--card: 0 0% 100%;
|
||||
--card-foreground: 240 10% 3.9%;
|
||||
--popover: 0 0% 100%;
|
||||
--popover-foreground: 240 10% 3.9%;
|
||||
--primary: 280 100% 60%;
|
||||
--primary-foreground: 0 0% 98%;
|
||||
--secondary: 240 4.8% 95.9%;
|
||||
--secondary-foreground: 240 5.9% 10%;
|
||||
--muted: 240 4.8% 95.9%;
|
||||
--muted-foreground: 240 3.8% 46.1%;
|
||||
--accent: 240 4.8% 95.9%;
|
||||
--accent-foreground: 240 5.9% 10%;
|
||||
--destructive: 0 84.2% 60.2%;
|
||||
--destructive-foreground: 210 40% 98%;
|
||||
--border: 240 5.9% 90%;
|
||||
--input: 240 5.9% 90%;
|
||||
--ring: 280 100% 60%;
|
||||
--radius: 0.75rem;
|
||||
--chart-1: 280 100% 60%;
|
||||
--chart-2: 160 84% 39%;
|
||||
--chart-3: 30 100% 50%;
|
||||
--chart-4: 340 100% 50%;
|
||||
--chart-5: 200 100% 50%;
|
||||
[data-webtui-theme="catppuccin-latte"] {
|
||||
--box-border-color: #9ca0b0;
|
||||
--table-border-color: #9ca0b0;
|
||||
--separator-color: #9ca0b0;
|
||||
}
|
||||
|
||||
.dark {
|
||||
--background: 240 10% 8%;
|
||||
--foreground: 0 0% 98%;
|
||||
--card: 240 10% 12%;
|
||||
--card-foreground: 0 0% 98%;
|
||||
--popover: 240 10% 12%;
|
||||
--popover-foreground: 0 0% 98%;
|
||||
--primary: 280 100% 40%;
|
||||
--primary-foreground: 240 10% 8%;
|
||||
--secondary: 240 3.7% 18%;
|
||||
--secondary-foreground: 0 0% 98%;
|
||||
--muted: 240 3.7% 18%;
|
||||
--muted-foreground: 240 5% 64.9%;
|
||||
--accent: 240 3.7% 18%;
|
||||
--accent-foreground: 0 0% 98%;
|
||||
--destructive: 0 62.8% 30.6%;
|
||||
--destructive-foreground: 0 0% 98%;
|
||||
--border: 240 3.7% 25%;
|
||||
--input: 240 3.7% 18%;
|
||||
--ring: 280 100% 40%;
|
||||
--chart-1: 280 100% 40%;
|
||||
--chart-2: 160 84% 30%;
|
||||
--chart-3: 30 100% 35%;
|
||||
--chart-4: 340 100% 35%;
|
||||
--chart-5: 200 100% 35%;
|
||||
[data-webtui-theme="catppuccin-mocha"] {
|
||||
--box-border-color: #313244;
|
||||
--table-border-color: #313244;
|
||||
--separator-color: #313244;
|
||||
}
|
||||
}
|
||||
|
||||
@layer base {
|
||||
* {
|
||||
@apply border-border;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar {
|
||||
-webkit-appearance: none;
|
||||
}
|
||||
|
||||
body {
|
||||
@apply bg-background text-foreground;
|
||||
position: relative;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
overflow-x: hidden;
|
||||
font-family: var(--font-sans);
|
||||
font-feature-settings: "cv02", "cv03", "cv04", "cv11";
|
||||
font-variation-settings: normal;
|
||||
}
|
||||
|
||||
/* Terminal-style fonts for code elements */
|
||||
code, pre, .font-mono {
|
||||
font-family: var(--font-mono);
|
||||
font-feature-settings: "liga" 1, "calt" 1;
|
||||
}
|
||||
|
||||
/* Brand styling */
|
||||
.brand-text {
|
||||
font-family: var(--font-mono);
|
||||
font-weight: 600;
|
||||
letter-spacing: -0.025em;
|
||||
}
|
||||
|
||||
/* Terminal-style headings */
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
font-family: var(--font-sans);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* Terminal-style buttons and inputs */
|
||||
button, input, textarea, select {
|
||||
font-family: var(--font-sans);
|
||||
}
|
||||
|
||||
/* Code blocks and terminal areas */
|
||||
.terminal-text {
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
/* Cyberpunk-inspired gradient background */
|
||||
@layer components {
|
||||
.hero-gradient {
|
||||
background: linear-gradient(135deg,
|
||||
hsl(280 100% 60% / 0.1) 0%,
|
||||
hsl(160 84% 39% / 0.05) 25%,
|
||||
hsl(30 100% 50% / 0.05) 50%,
|
||||
hsl(340 100% 50% / 0.05) 75%,
|
||||
hsl(200 100% 50% / 0.1) 100%);
|
||||
}
|
||||
|
||||
.hero-gradient::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background:
|
||||
radial-gradient(circle at 20% 80%, hsl(280 100% 60% / 0.15) 0%, transparent 50%),
|
||||
radial-gradient(circle at 80% 20%, hsl(160 84% 39% / 0.15) 0%, transparent 50%),
|
||||
radial-gradient(circle at 40% 40%, hsl(340 100% 50% / 0.1) 0%, transparent 50%);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.dark .hero-gradient::before {
|
||||
background:
|
||||
radial-gradient(circle at 20% 80%, hsl(280 100% 50% / 0.08) 0%, transparent 50%),
|
||||
radial-gradient(circle at 80% 20%, hsl(160 84% 35% / 0.08) 0%, transparent 50%),
|
||||
radial-gradient(circle at 40% 40%, hsl(340 100% 45% / 0.06) 0%, transparent 50%);
|
||||
}
|
||||
|
||||
/* Glass morphism cards */
|
||||
.glass-card {
|
||||
@apply backdrop-blur-md bg-card/80 border border-border/50;
|
||||
}
|
||||
|
||||
.dark .glass-card {
|
||||
@apply backdrop-blur-md bg-card/80 border border-border/70;
|
||||
}
|
||||
|
||||
.glass-card-hover {
|
||||
@apply glass-card;
|
||||
}
|
||||
|
||||
/* Vibrant gradient text */
|
||||
.brand-gradient {
|
||||
@apply bg-gradient-to-r from-purple-500 via-pink-500 to-orange-500 bg-clip-text text-transparent;
|
||||
}
|
||||
|
||||
.dark .brand-gradient {
|
||||
@apply bg-gradient-to-r from-purple-600 via-pink-600 to-orange-600 bg-clip-text text-transparent;
|
||||
}
|
||||
|
||||
.brand-gradient-alt {
|
||||
@apply bg-gradient-to-r from-cyan-500 via-blue-500 to-purple-500 bg-clip-text text-transparent;
|
||||
}
|
||||
|
||||
.dark .brand-gradient-alt {
|
||||
@apply bg-gradient-to-r from-cyan-600 via-blue-600 to-purple-600 bg-clip-text text-transparent;
|
||||
}
|
||||
|
||||
/* Neon glow effects */
|
||||
.glow-primary {
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.glow-primary:hover {
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.glow-cyan {
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.glow-orange {
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.glow-pink {
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
/* Status indicators */
|
||||
.status-error {
|
||||
@apply bg-red-500/20 text-red-700 dark:text-red-400 border-red-500/30;
|
||||
}
|
||||
|
||||
/* Custom scrollbar */
|
||||
.custom-scrollbar {
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: hsl(var(--muted-foreground) / 0.3) transparent;
|
||||
}
|
||||
|
||||
.custom-scrollbar::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
.custom-scrollbar::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.custom-scrollbar::-webkit-scrollbar-thumb {
|
||||
background-color: hsl(var(--muted-foreground) / 0.3);
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
|
||||
background-color: hsl(var(--muted-foreground) / 0.5);
|
||||
}
|
||||
|
||||
/* Tooltip styles */
|
||||
.tooltip {
|
||||
@apply absolute z-50 px-3 py-2 text-sm text-white bg-gray-900 rounded-lg shadow-lg opacity-0 invisible transition-all duration-200;
|
||||
}
|
||||
|
||||
.tooltip.show {
|
||||
@apply opacity-100 visible;
|
||||
}
|
||||
|
||||
/* Responsive text utilities */
|
||||
.text-responsive {
|
||||
@apply text-sm sm:text-base lg:text-lg;
|
||||
}
|
||||
|
||||
.text-responsive-lg {
|
||||
@apply text-base sm:text-lg lg:text-xl;
|
||||
}
|
||||
|
||||
.text-responsive-xl {
|
||||
@apply text-lg sm:text-xl lg:text-2xl;
|
||||
}
|
||||
|
||||
/* Button variants with new colors */
|
||||
.btn-primary {
|
||||
@apply bg-gradient-to-r from-purple-500 to-pink-500 text-white hover:from-purple-600 hover:to-pink-600 transition-all;
|
||||
}
|
||||
|
||||
.dark .btn-primary {
|
||||
@apply bg-gradient-to-r from-purple-600 to-pink-600 text-white hover:from-purple-700 hover:to-pink-700 transition-all;
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
@apply bg-gradient-to-r from-cyan-500 to-blue-500 text-white hover:from-cyan-600 hover:to-blue-600 transition-all;
|
||||
}
|
||||
|
||||
.dark .btn-secondary {
|
||||
@apply bg-gradient-to-r from-cyan-600 to-blue-600 text-white hover:from-cyan-700 hover:to-blue-700 transition-all;
|
||||
}
|
||||
|
||||
.btn-outline {
|
||||
@apply border border-border bg-background hover:bg-accent hover:text-accent-foreground transition-colors;
|
||||
}
|
||||
|
||||
.btn-ghost {
|
||||
@apply hover:bg-accent hover:text-accent-foreground transition-colors;
|
||||
}
|
||||
|
||||
.btn-destructive {
|
||||
@apply bg-gradient-to-r from-red-500 to-pink-500 text-white hover:from-red-600 hover:to-pink-600 transition-all;
|
||||
}
|
||||
|
||||
.dark .btn-destructive {
|
||||
@apply bg-gradient-to-r from-red-600 to-pink-600 text-white hover:from-red-700 hover:to-pink-700 transition-all;
|
||||
}
|
||||
|
||||
/* Neon accent borders */
|
||||
.neon-border {
|
||||
border: 1px solid transparent;
|
||||
background: linear-gradient(white, white) padding-box,
|
||||
linear-gradient(45deg, hsl(280 100% 60%), hsl(160 84% 39%), hsl(30 100% 50%)) border-box;
|
||||
}
|
||||
|
||||
.neon-border-dark {
|
||||
border: 1px solid transparent;
|
||||
background: linear-gradient(hsl(240 10% 3.9%), hsl(240 10% 3.9%)) padding-box,
|
||||
linear-gradient(45deg, hsl(280 100% 70%), hsl(160 84% 45%), hsl(30 100% 60%)) border-box;
|
||||
}
|
||||
body {
|
||||
font-family: 'IBM Plex Mono', monospace !important;
|
||||
font-weight: 500 !important;
|
||||
}
|
||||
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6 {
|
||||
font-family: 'Azeret Mono Variable', monospace !important;
|
||||
}
|
||||
|
||||
p,
|
||||
span,
|
||||
a,
|
||||
label,
|
||||
input,
|
||||
textarea,
|
||||
button,
|
||||
select,
|
||||
option {
|
||||
font-family: 'IBM Plex Mono', monospace !important;
|
||||
font-weight: 500 !important;
|
||||
}
|
||||
|
||||
pre {
|
||||
scrollbar-width: none !important;
|
||||
-ms-overflow-style: none !important;
|
||||
}
|
||||
|
||||
pre::-webkit-scrollbar {
|
||||
display: none !important;
|
||||
width: 0 !important;
|
||||
height: 0 !important;
|
||||
}
|
||||
|
||||
|
||||
@layer utilities {
|
||||
body.sidebar-collapsed main.lg\:ml-80 {
|
||||
margin-left: 4rem !important; /* 64px */
|
||||
.ascii-border {
|
||||
border: 1px solid var(--box-border-color, var(--foreground2));
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.border-border {
|
||||
border-color: var(--box-border-color, var(--foreground2)) !important;
|
||||
}
|
||||
|
||||
.tui-scrollbar {
|
||||
scrollbar-width: auto !important;
|
||||
padding-right: 5px;
|
||||
}
|
||||
|
||||
@media (min-width: 992px) {
|
||||
.tui-scrollbar {
|
||||
padding-right: 15px;
|
||||
}
|
||||
}
|
||||
|
||||
.tui-scrollbar::-webkit-scrollbar {
|
||||
-webkit-appearance: none;
|
||||
width: 7px;
|
||||
height: 10px;
|
||||
background-color: var(--background1) !important;
|
||||
}
|
||||
|
||||
.tui-scrollbar::-webkit-scrollbar-thumb {
|
||||
background-color: var(--background0) !important;
|
||||
border: 1px solid var(--box-border-color, var(--foreground2));
|
||||
visibility: visible !important;
|
||||
opacity: 1 !important;
|
||||
min-height: 40px !important;
|
||||
height: 40px !important;
|
||||
}
|
||||
|
||||
.tui-scrollbar::-webkit-scrollbar-thumb:hover {
|
||||
background-color: var(--primary) !important;
|
||||
box-shadow: 0 0 8px var(--primary);
|
||||
}
|
||||
|
||||
.tui-scrollbar::-webkit-scrollbar-track {
|
||||
background: var(--background1);
|
||||
border-left: 1px solid var(--box-border-color, var(--foreground2));
|
||||
}
|
||||
|
||||
.tui-scrollbar::-webkit-scrollbar-corner {
|
||||
background: var(--background1);
|
||||
}
|
||||
|
||||
.bg-background0 {
|
||||
background-color: var(--background0) !important;
|
||||
}
|
||||
|
||||
.bg-background1 {
|
||||
background-color: var(--background1) !important;
|
||||
}
|
||||
|
||||
.bg-background2 {
|
||||
background-color: var(--background2) !important;
|
||||
}
|
||||
|
||||
.border-foreground1 {
|
||||
border-color: var(--box-border-color, var(--foreground2)) !important;
|
||||
}
|
||||
|
||||
.text-foreground0 {
|
||||
color: var(--foreground0) !important;
|
||||
}
|
||||
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
padding: 0;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap;
|
||||
border-width: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@layer components {
|
||||
.tui-card {
|
||||
background: var(--background0) !important;
|
||||
border: 1px solid var(--box-border-color, var(--foreground2)) !important;
|
||||
box-shadow: 8px 4px 0 var(--box-border-color, var(--foreground2));
|
||||
border-radius: 0 !important;
|
||||
}
|
||||
|
||||
.tui-card-mini {
|
||||
background: var(--background0) !important;
|
||||
border: 1px solid var(--box-border-color, var(--foreground2)) !important;
|
||||
box-shadow: 2px 4px 0 var(--box-border-color, var(--foreground2));
|
||||
border-radius: 0 !important;
|
||||
}
|
||||
|
||||
.terminal-log {
|
||||
background: var(--background0) !important;
|
||||
border: 1px solid var(--box-border-color, var(--foreground2)) !important;
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
padding: 1rem;
|
||||
color: var(--foreground0);
|
||||
}
|
||||
|
||||
.text-status-info {
|
||||
color: var(--mauve);
|
||||
}
|
||||
|
||||
.text-status-warning {
|
||||
color: var(--yellow);
|
||||
}
|
||||
|
||||
.text-status-success {
|
||||
color: var(--green);
|
||||
}
|
||||
|
||||
.text-status-error {
|
||||
color: var(--red);
|
||||
}
|
||||
|
||||
.bg-status-info {
|
||||
background-color: var(--mauve);
|
||||
}
|
||||
|
||||
.bg-status-warning {
|
||||
background-color: var(--yellow);
|
||||
}
|
||||
|
||||
.bg-status-success {
|
||||
background-color: var(--green);
|
||||
}
|
||||
|
||||
.bg-status-error {
|
||||
background-color: var(--red);
|
||||
}
|
||||
|
||||
dialog {
|
||||
background: var(--background0) !important;
|
||||
margin: auto;
|
||||
padding: 0;
|
||||
width: 90vw;
|
||||
max-height: 90vh;
|
||||
}
|
||||
|
||||
dialog::backdrop {
|
||||
background: rgba(0, 0, 0, 0.8) !important;
|
||||
}
|
||||
|
||||
dialog[open] {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.no-sidebar main {
|
||||
margin-left: 0 !important;
|
||||
}
|
||||
|
||||
body:not(.sidebar-collapsed) main {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
@media (min-width: 1024px) {
|
||||
body:not(.sidebar-collapsed) main {
|
||||
margin-left: 320px;
|
||||
}
|
||||
|
||||
body.sidebar-collapsed main {
|
||||
margin-left: 64px;
|
||||
}
|
||||
|
||||
.no-sidebar main {
|
||||
margin-left: 0 !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 992px) {
|
||||
.mobile-modal {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
top: auto;
|
||||
width: 100% !important;
|
||||
max-height: 90vh;
|
||||
max-width: 100%;
|
||||
margin: inherit;
|
||||
}
|
||||
}
|
||||
40
app/i18n.ts
40
app/i18n.ts
@@ -1,24 +1,24 @@
|
||||
import { getRequestConfig } from "next-intl/server";
|
||||
import { Locales } from "@/app/_consts/global";
|
||||
|
||||
const validLocales = Locales.map((item) => item.locale);
|
||||
import { loadTranslationMessages } from "@/app/_server/actions/translations";
|
||||
|
||||
export default getRequestConfig(async ({ locale }) => {
|
||||
const safeLocale = locale && validLocales.includes(locale) ? locale : "en";
|
||||
const safeLocale = locale || "en";
|
||||
|
||||
try {
|
||||
return {
|
||||
locale: safeLocale,
|
||||
messages: (await import(`./_translations/${safeLocale}.json`)).default,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(
|
||||
`Failed to load translations for locale: ${safeLocale}`,
|
||||
error
|
||||
);
|
||||
return {
|
||||
locale: "en",
|
||||
messages: (await import("./_translations/en.json")).default,
|
||||
};
|
||||
}
|
||||
});
|
||||
try {
|
||||
const messages = await loadTranslationMessages(safeLocale);
|
||||
return {
|
||||
locale: safeLocale,
|
||||
messages,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(
|
||||
`Failed to load translations for locale: ${safeLocale}`,
|
||||
error
|
||||
);
|
||||
const fallbackMessages = await loadTranslationMessages("en");
|
||||
return {
|
||||
locale: "en",
|
||||
messages: fallbackMessages,
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import type { Metadata } from "next";
|
||||
import { JetBrains_Mono, Inter } from "next/font/google";
|
||||
import { JetBrains_Mono } from "next/font/google";
|
||||
import "@/app/globals.css";
|
||||
import { ThemeProvider } from "@/app/_providers/ThemeProvider";
|
||||
import { ServiceWorkerRegister } from "@/app/_components/FeatureComponents/PWA/ServiceWorkerRegister";
|
||||
import { Locales } from "@/app/_consts/global";
|
||||
import { loadTranslationMessages } from "@/app/_server/actions/translations";
|
||||
import '@fontsource/ibm-plex-mono/400.css';
|
||||
import '@fontsource/ibm-plex-mono/500.css';
|
||||
import '@fontsource/ibm-plex-mono/600.css';
|
||||
import '@fontsource-variable/azeret-mono';
|
||||
|
||||
import { NextIntlClientProvider } from "next-intl";
|
||||
|
||||
@@ -13,15 +17,10 @@ const jetbrainsMono = JetBrains_Mono({
|
||||
display: "swap",
|
||||
});
|
||||
|
||||
const inter = Inter({
|
||||
subsets: ["latin"],
|
||||
variable: "--font-sans",
|
||||
display: "swap",
|
||||
});
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Cr*nMaster - Cron Management made easy",
|
||||
description: "The ultimate cron job management platform with intelligent scheduling, real-time monitoring, and powerful automation tools",
|
||||
description:
|
||||
"The ultimate cron job management platform with intelligent scheduling, real-time monitoring, and powerful automation tools",
|
||||
manifest: "/manifest.json",
|
||||
appleWebApp: {
|
||||
capable: true,
|
||||
@@ -32,7 +31,7 @@ export const metadata: Metadata = {
|
||||
telephone: false,
|
||||
},
|
||||
icons: {
|
||||
icon: "/logo.png",
|
||||
icon: "/favicon.png",
|
||||
shortcut: "/logo.png",
|
||||
apple: "/logo.png",
|
||||
},
|
||||
@@ -54,15 +53,10 @@ export default async function RootLayout({
|
||||
let locale = process.env.LOCALE || "en";
|
||||
let messages;
|
||||
|
||||
|
||||
if (!Locales.some((item) => item.locale === locale)) {
|
||||
locale = "en";
|
||||
}
|
||||
|
||||
messages = (await import(`./_translations/${locale}.json`)).default;
|
||||
messages = await loadTranslationMessages(locale);
|
||||
|
||||
return (
|
||||
<html lang="en" suppressHydrationWarning>
|
||||
<html lang="en" suppressHydrationWarning data-webtui-theme="catppuccin-latte">
|
||||
<head>
|
||||
<meta name="application-name" content="Cr*nMaster" />
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
@@ -70,16 +64,23 @@ export default async function RootLayout({
|
||||
<meta name="apple-mobile-web-app-title" content="Cr*nMaster" />
|
||||
<meta name="mobile-web-app-capable" content="yes" />
|
||||
<link rel="apple-touch-icon" href="/logo.png" />
|
||||
<link rel="stylesheet" href="/webtui/base.css" />
|
||||
<link rel="stylesheet" href="/webtui/theme-catppuccin.css" />
|
||||
<script
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `
|
||||
(function() {
|
||||
const theme = localStorage.getItem('theme') || 'light';
|
||||
const webtui = theme === 'dark' ? 'catppuccin-mocha' : 'catppuccin-latte';
|
||||
document.documentElement.setAttribute('data-webtui-theme', webtui);
|
||||
})();
|
||||
`,
|
||||
}}
|
||||
/>
|
||||
</head>
|
||||
<body className={`${inter.variable} ${jetbrainsMono.variable} font-sans`}>
|
||||
|
||||
<body className={`${jetbrainsMono.variable} terminal-font`}>
|
||||
<NextIntlClientProvider locale={locale} messages={messages}>
|
||||
<ThemeProvider
|
||||
attribute="class"
|
||||
defaultTheme="dark"
|
||||
enableSystem
|
||||
disableTransitionOnChange
|
||||
>
|
||||
<ThemeProvider>
|
||||
{children}
|
||||
</ThemeProvider>
|
||||
<ServiceWorkerRegister />
|
||||
|
||||
@@ -1,17 +1,29 @@
|
||||
'use server';
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
import { LoginForm } from "@/app/_components/FeatureComponents/LoginForm/LoginForm";
|
||||
import { readFileSync } from "fs";
|
||||
import path from "path";
|
||||
|
||||
export default async function LoginPage() {
|
||||
const hasPassword = !!process.env.AUTH_PASSWORD;
|
||||
const hasOIDC = process.env.SSO_MODE === "oidc";
|
||||
const hasPassword = !!process.env.AUTH_PASSWORD;
|
||||
const hasOIDC = process.env.SSO_MODE === "oidc";
|
||||
const oidcAutoRedirect = process.env.OIDC_AUTO_REDIRECT === "true";
|
||||
|
||||
return (
|
||||
<div className="min-h-screen relative">
|
||||
<div className="hero-gradient absolute inset-0 -z-10"></div>
|
||||
<div className="relative z-10 flex items-center justify-center min-h-screen p-4">
|
||||
<LoginForm hasPassword={hasPassword} hasOIDC={hasOIDC} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
const packageJsonPath = path.join(process.cwd(), "package.json");
|
||||
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
||||
const version = packageJson.version;
|
||||
|
||||
return (
|
||||
<div className="min-h-screen relative">
|
||||
<div className="hero-gradient absolute inset-0 -z-10"></div>
|
||||
<div className="relative z-10 flex items-center justify-center min-h-screen p-4">
|
||||
<LoginForm
|
||||
hasPassword={hasPassword}
|
||||
hasOIDC={hasOIDC}
|
||||
oidcAutoRedirect={oidcAutoRedirect}
|
||||
version={version}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,24 @@
|
||||
import { Asterisk, Terminal } from "lucide-react";
|
||||
"use client";
|
||||
|
||||
export default async function Logo() {
|
||||
import { AsteriskIcon, TerminalIcon } from "@phosphor-icons/react";
|
||||
|
||||
export default function Logo() {
|
||||
return (
|
||||
<div className="m-auto mt-20 relative w-[600px] h-[600px]">
|
||||
<div className="p-3 bg-gradient-to-br from-purple-500 via-pink-500 to-orange-500 rounded-[200px] w-full h-full">
|
||||
<div className="relative">
|
||||
<Terminal className="h-[350px] w-[350px] text-white relative top-[120px] left-[120px]" />
|
||||
<Asterisk className="h-[200px] w-[200px] text-white absolute top-14 right-[90px]" />
|
||||
<div className="min-h-screen bg-background0 flex items-center justify-center p-8">
|
||||
<div className="relative">
|
||||
<div className="w-[600px] h-[600px] ascii-border bg-background1 p-16 flex items-center justify-center">
|
||||
<div className="absolute w-[600px] h-[600px] bg-gradient-to-br from-primary/20 via-primary/10 to-transparent blur-3xl" />
|
||||
|
||||
<div className="relative z-10 flex items-center justify-center w-full h-full">
|
||||
<TerminalIcon
|
||||
className="h-80 w-80 text-primary drop-shadow-[0_0_40px_rgba(var(--primary-rgb),0.6)]"
|
||||
weight="duotone"
|
||||
/>
|
||||
<AsteriskIcon
|
||||
className="h-40 w-40 text-primary absolute -top-4 -right-4 drop-shadow-[0_0_30px_rgba(var(--primary-rgb),0.8)]"
|
||||
weight="bold"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
117
app/not-found.tsx
Normal file
117
app/not-found.tsx
Normal file
@@ -0,0 +1,117 @@
|
||||
import Link from "next/link";
|
||||
import { getTranslations } from "@/app/_server/actions/translations";
|
||||
import { SnakeGame } from "@/app/_components/FeatureComponents/Games/SnakeGame";
|
||||
import { Logo } from "@/app/_components/GlobalComponents/Logo/Logo";
|
||||
import { SystemInfoCard } from "@/app/_components/FeatureComponents/System/SystemInfo";
|
||||
import { ThemeToggle } from "@/app/_components/FeatureComponents/Theme/ThemeToggle";
|
||||
import { LogoutButton } from "@/app/_components/FeatureComponents/LoginForm/LogoutButton";
|
||||
import { ToastContainer } from "@/app/_components/GlobalComponents/UIElements/Toast";
|
||||
import { PWAInstallPrompt } from "@/app/_components/FeatureComponents/PWA/PWAInstallPrompt";
|
||||
import { SSEProvider } from "@/app/_contexts/SSEContext";
|
||||
import { readFileSync } from "fs";
|
||||
import path from "path";
|
||||
|
||||
export default async function NotFound() {
|
||||
const t = await getTranslations();
|
||||
const liveUpdatesEnabled =
|
||||
(typeof process.env.LIVE_UPDATES === "boolean" &&
|
||||
process.env.LIVE_UPDATES === true) ||
|
||||
process.env.LIVE_UPDATES !== "false";
|
||||
|
||||
const packageJsonPath = path.join(process.cwd(), "package.json");
|
||||
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
||||
const version = packageJson.version;
|
||||
|
||||
const initialSystemInfo = {
|
||||
hostname: "Loading...",
|
||||
platform: "Loading...",
|
||||
uptime: "Loading...",
|
||||
memory: {
|
||||
total: "0 B",
|
||||
used: "0 B",
|
||||
free: "0 B",
|
||||
usage: 0,
|
||||
status: "Loading",
|
||||
},
|
||||
cpu: {
|
||||
model: "Loading...",
|
||||
cores: 0,
|
||||
usage: 0,
|
||||
status: "Loading",
|
||||
},
|
||||
gpu: {
|
||||
model: "Loading...",
|
||||
status: "Loading",
|
||||
},
|
||||
disk: {
|
||||
total: "0 B",
|
||||
used: "0 B",
|
||||
free: "0 B",
|
||||
usage: 0,
|
||||
status: "Loading",
|
||||
},
|
||||
systemStatus: {
|
||||
overall: "Loading",
|
||||
details: "Fetching system information...",
|
||||
},
|
||||
};
|
||||
|
||||
const bodyClass = process.env.DISABLE_SYSTEM_STATS === "true" ? "no-sidebar" : "";
|
||||
|
||||
return (
|
||||
<SSEProvider liveUpdatesEnabled={liveUpdatesEnabled}>
|
||||
<div className={`min-h-screen bg-background0 ${bodyClass}`}>
|
||||
<header className="border-border border-b sticky top-0 z-20 bg-background0 lg:h-[90px]">
|
||||
<div className="container mx-auto px-4 py-4">
|
||||
<div className="flex items-center justify-between lg:justify-center">
|
||||
<div className="flex items-center gap-4">
|
||||
<Logo size={48} showGlow={true} />
|
||||
<div>
|
||||
<h1 className="text-xl sm:text-2xl lg:text-3xl font-bold terminal-font uppercase">
|
||||
Cr*nMaster
|
||||
</h1>
|
||||
<p className="text-xs terminal-font flex items-center gap-2">
|
||||
{t("common.version").replace("{version}", version)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{process.env.AUTH_PASSWORD && (
|
||||
<div className="lg:absolute lg:right-10">
|
||||
<LogoutButton />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{process.env.DISABLE_SYSTEM_STATS !== "true" && (
|
||||
<SystemInfoCard systemInfo={initialSystemInfo} />
|
||||
)}
|
||||
|
||||
<main className="transition-all duration-300">
|
||||
<div className="px-4 py-8 lg:px-8">
|
||||
<div className="text-center mt-6 mb-12">
|
||||
<div className="text-6xl font-bold terminal-font text-status-error mb-2">404</div>
|
||||
<p className="terminal-font text-sm mb-4">{t("notFound.message")}</p>
|
||||
<Link
|
||||
href="/"
|
||||
className="ascii-border bg-background1 hover:bg-background2 px-4 py-2 terminal-font uppercase font-bold transition-colors text-sm inline-block"
|
||||
>
|
||||
{t("notFound.goHome")}
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<SnakeGame />
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<ToastContainer />
|
||||
|
||||
<div className="flex items-center gap-2 fixed bottom-4 left-4 lg:right-4 lg:left-auto z-10 bg-background0 ascii-border p-1">
|
||||
<ThemeToggle />
|
||||
<PWAInstallPrompt />
|
||||
</div>
|
||||
</div>
|
||||
</SSEProvider>
|
||||
);
|
||||
}
|
||||
78
app/page.tsx
78
app/page.tsx
@@ -6,15 +6,26 @@ import { ThemeToggle } from "@/app/_components/FeatureComponents/Theme/ThemeTogg
|
||||
import { LogoutButton } from "@/app/_components/FeatureComponents/LoginForm/LogoutButton";
|
||||
import { ToastContainer } from "@/app/_components/GlobalComponents/UIElements/Toast";
|
||||
import { PWAInstallPrompt } from "@/app/_components/FeatureComponents/PWA/PWAInstallPrompt";
|
||||
import { getTranslations } from "@/app/_utils/global-utils";
|
||||
import { WrapperScriptWarning } from "@/app/_components/FeatureComponents/System/WrapperScriptWarning";
|
||||
import { getTranslations } from "@/app/_server/actions/translations";
|
||||
import { SSEProvider } from "@/app/_contexts/SSEContext";
|
||||
import { Logo } from "@/app/_components/GlobalComponents/Logo/Logo";
|
||||
import { readFileSync } from "fs";
|
||||
import path from "path";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
export const maxDuration = 300;
|
||||
|
||||
export default async function Home() {
|
||||
const t = await getTranslations();
|
||||
const liveUpdatesEnabled = (typeof process.env.LIVE_UPDATES === "boolean" && process.env.LIVE_UPDATES === true) || process.env.LIVE_UPDATES !== "false";
|
||||
const liveUpdatesEnabled =
|
||||
(typeof process.env.LIVE_UPDATES === "boolean" &&
|
||||
process.env.LIVE_UPDATES === true) ||
|
||||
process.env.LIVE_UPDATES !== "false";
|
||||
|
||||
const packageJsonPath = path.join(process.cwd(), "package.json");
|
||||
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
||||
const version = packageJson.version;
|
||||
|
||||
const [cronJobs, scripts] = await Promise.all([
|
||||
getCronJobs(),
|
||||
@@ -55,49 +66,48 @@ export default async function Home() {
|
||||
},
|
||||
};
|
||||
|
||||
const bodyClass = process.env.DISABLE_SYSTEM_STATS === "true" ? "no-sidebar" : "";
|
||||
|
||||
return (
|
||||
<SSEProvider liveUpdatesEnabled={liveUpdatesEnabled}>
|
||||
<div className="min-h-screen relative">
|
||||
<div className="hero-gradient absolute inset-0 -z-10"></div>
|
||||
<div className="relative z-10">
|
||||
<header className="border-b border-border/50 bg-background/80 backdrop-blur-md sticky top-0 z-20 shadow-sm lg:h-[90px]">
|
||||
<div className="container mx-auto px-4 py-4">
|
||||
<div className="flex items-center justify-between lg:justify-center">
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="relative">
|
||||
<img src="/logo.png" alt="logo" className="w-14 h-14" />
|
||||
<div className="absolute top-0 right-0 w-3 h-3 bg-emerald-500 rounded-full animate-pulse"></div>
|
||||
</div>
|
||||
<div>
|
||||
<h1 className="text-xl sm:text-2xl lg:text-3xl font-bold brand-gradient brand-text">
|
||||
Cr*nMaster
|
||||
</h1>
|
||||
<p className="text-xs text-muted-foreground font-mono tracking-wide">
|
||||
{t("common.cronManagementMadeEasy")}
|
||||
</p>
|
||||
</div>
|
||||
<div className={`min-h-screen bg-background0 ${bodyClass}`}>
|
||||
<header className="border-border border-b sticky top-0 z-20 bg-background0 lg:h-[90px]">
|
||||
<div className="container mx-auto px-4 py-4">
|
||||
<div className="flex items-center justify-between lg:justify-center">
|
||||
<div className="flex items-center gap-4">
|
||||
<Logo size={48} showGlow={true} />
|
||||
<div>
|
||||
<h1 className="text-xl sm:text-2xl lg:text-3xl font-bold terminal-font uppercase">
|
||||
Cr<span className="text-status-error">*</span>nMaster
|
||||
</h1>
|
||||
<p className="text-xs terminal-font flex items-center gap-2">
|
||||
{t("common.version").replace("{version}", version)}
|
||||
</p>
|
||||
</div>
|
||||
{process.env.AUTH_PASSWORD && (
|
||||
<div className="lg:absolute lg:right-10">
|
||||
<LogoutButton />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{process.env.AUTH_PASSWORD && (
|
||||
<div className="lg:absolute lg:right-10">
|
||||
<LogoutButton />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</header>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{process.env.DISABLE_SYSTEM_STATS !== "true" && (
|
||||
<SystemInfoCard systemInfo={initialSystemInfo} />
|
||||
)}
|
||||
|
||||
<main className="lg:ml-80 transition-all duration-300 ml-0 sidebar-collapsed:lg:ml-16">
|
||||
<div className="container mx-auto px-4 py-8 lg:px-8">
|
||||
<TabbedInterface cronJobs={cronJobs} scripts={scripts} />
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
<main className="transition-all duration-300">
|
||||
<div className="px-4 py-8 lg:px-8">
|
||||
<WrapperScriptWarning />
|
||||
<TabbedInterface cronJobs={cronJobs} scripts={scripts} />
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<ToastContainer />
|
||||
|
||||
<div className="flex items-center gap-2 fixed bottom-4 left-4 lg:right-4 lg:left-auto z-10 bg-background/80 backdrop-blur-md border border-border/50 rounded-lg p-1">
|
||||
<div className="flex items-center gap-2 fixed bottom-4 left-4 lg:right-4 lg:left-auto z-10 bg-background0 ascii-border p-1">
|
||||
<ThemeToggle />
|
||||
<PWAInstallPrompt />
|
||||
</div>
|
||||
|
||||
227
howto/API.md
227
howto/API.md
@@ -106,6 +106,104 @@ curl -H "Authorization: Bearer YOUR_API_KEY" \
|
||||
|
||||
---
|
||||
|
||||
### PATCH /api/cronjobs/:id
|
||||
|
||||
Update a cron job.
|
||||
|
||||
**Parameters:**
|
||||
|
||||
- `id` (string) - Cron job ID
|
||||
|
||||
**Request:**
|
||||
|
||||
```json
|
||||
{
|
||||
"schedule": "0 3 * * *",
|
||||
"command": "/usr/bin/echo updated",
|
||||
"comment": "Updated job",
|
||||
"logsEnabled": true
|
||||
}
|
||||
```
|
||||
|
||||
**Response:**
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "Cron job updated successfully"
|
||||
}
|
||||
```
|
||||
|
||||
**Example:**
|
||||
|
||||
```bash
|
||||
curl -X PATCH \
|
||||
-H "Authorization: Bearer YOUR_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"schedule":"0 3 * * *","command":"/usr/bin/echo updated"}' \
|
||||
https://your-cronmaster-url.com/api/cronjobs/fccview-0
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### DELETE /api/cronjobs/:id
|
||||
|
||||
Delete a cron job.
|
||||
|
||||
**Parameters:**
|
||||
|
||||
- `id` (string) - Cron job ID
|
||||
|
||||
**Response:**
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": "Cron job deleted successfully"
|
||||
}
|
||||
```
|
||||
|
||||
**Example:**
|
||||
|
||||
```bash
|
||||
curl -X DELETE \
|
||||
-H "Authorization: Bearer YOUR_API_KEY" \
|
||||
https://your-cronmaster-url.com/api/cronjobs/fccview-0
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### GET /api/cronjobs/:id/execute
|
||||
|
||||
Manually execute a cron job.
|
||||
|
||||
**Parameters:**
|
||||
|
||||
- `id` (string) - Cron job ID
|
||||
|
||||
**Query Parameters:**
|
||||
|
||||
- `runInBackground` (boolean, optional) - Whether to run the job in background. Defaults to `true`.
|
||||
|
||||
**Response:**
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"runId": "run-123",
|
||||
"message": "Job execution started"
|
||||
}
|
||||
```
|
||||
|
||||
**Example:**
|
||||
|
||||
```bash
|
||||
curl -H "Authorization: Bearer YOUR_API_KEY" \
|
||||
https://your-cronmaster-url.com/api/cronjobs/fccview-0/execute?runInBackground=true
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### GET /api/scripts
|
||||
|
||||
List all scripts.
|
||||
@@ -196,6 +294,127 @@ curl -H "Authorization: Bearer YOUR_API_KEY" \
|
||||
|
||||
---
|
||||
|
||||
### GET /api/logs/stream
|
||||
|
||||
Stream job execution logs.
|
||||
|
||||
**Query Parameters:**
|
||||
|
||||
- `runId` (string, required) - The run ID of the job execution
|
||||
- `offset` (number, optional) - Byte offset for streaming new content. Defaults to `0`.
|
||||
- `maxLines` (number, optional) - Maximum lines to return. Defaults to `500`, min `100`, max `5000`.
|
||||
|
||||
**Note:** When `offset=0`, the endpoint only reads the last `maxLines` from the file for performance. This means `totalLines` is only returned when the file is small enough to read entirely (not truncated).
|
||||
|
||||
**Response:**
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "running",
|
||||
"content": "[log content]",
|
||||
"newContent": "[new log content since offset]",
|
||||
"logFile": "2025-11-10_14-30-00.log",
|
||||
"isComplete": false,
|
||||
"exitCode": null,
|
||||
"fileSize": 1024,
|
||||
"offset": 0,
|
||||
"totalLines": 50,
|
||||
"displayedLines": 50,
|
||||
"truncated": false
|
||||
}
|
||||
```
|
||||
|
||||
**Response Fields:**
|
||||
|
||||
- `status` (string) - Job status: "running", "completed", or "failed"
|
||||
- `content` (string) - The log content to display
|
||||
- `newContent` (string) - New content since the last offset (for streaming)
|
||||
- `logFile` (string) - Name of the log file
|
||||
- `isComplete` (boolean) - Whether the job has completed
|
||||
- `exitCode` (number | null) - Exit code of the job (null if still running)
|
||||
- `fileSize` (number) - Total size of the log file in bytes
|
||||
- `offset` (number) - Current byte offset
|
||||
- `totalLines` (number | undefined) - Total number of lines in the file (only returned when file is small enough to read entirely)
|
||||
- `displayedLines` (number) - Number of lines being displayed
|
||||
- `truncated` (boolean) - Whether the content is truncated due to maxLines limit
|
||||
|
||||
**Example:**
|
||||
|
||||
```bash
|
||||
curl -H "Authorization: Bearer YOUR_API_KEY" \
|
||||
"https://your-cronmaster-url.com/api/logs/stream?runId=run-123&offset=0&maxLines=500"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### GET /api/system/wrapper-check
|
||||
|
||||
Check if the log wrapper script has been modified from the default.
|
||||
|
||||
**Response:**
|
||||
|
||||
```json
|
||||
{
|
||||
"modified": false
|
||||
}
|
||||
```
|
||||
|
||||
**Example:**
|
||||
|
||||
```bash
|
||||
curl -H "Authorization: Bearer YOUR_API_KEY" \
|
||||
https://your-cronmaster-url.com/api/system/wrapper-check
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### GET /api/oidc/login
|
||||
|
||||
Initiate OIDC (SSO) login flow. Redirects to the OIDC provider's authorization endpoint.
|
||||
|
||||
**Note:** This endpoint is only available when `SSO_MODE=oidc` is configured.
|
||||
|
||||
**Response:** HTTP 302 redirect to OIDC provider
|
||||
|
||||
**Example:**
|
||||
|
||||
```bash
|
||||
curl -L https://your-cronmaster-url.com/api/oidc/login
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### GET /api/oidc/callback
|
||||
|
||||
OIDC callback endpoint. Handles the authorization code from the OIDC provider and creates a session.
|
||||
|
||||
**Note:** This endpoint is typically called by the OIDC provider after authentication, not directly by clients.
|
||||
|
||||
**Query Parameters:**
|
||||
|
||||
- `code` (string) - Authorization code from OIDC provider
|
||||
- `state` (string) - State parameter for CSRF protection
|
||||
|
||||
**Response:** HTTP 302 redirect to application root
|
||||
|
||||
---
|
||||
|
||||
### GET /api/oidc/logout
|
||||
|
||||
Initiate OIDC logout flow. Redirects to the OIDC provider's logout endpoint.
|
||||
|
||||
**Note:** This endpoint is only available when `SSO_MODE=oidc` is configured.
|
||||
|
||||
**Response:** HTTP 302 redirect to OIDC provider logout endpoint
|
||||
|
||||
**Example:**
|
||||
|
||||
```bash
|
||||
curl -L https://your-cronmaster-url.com/api/oidc/logout
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### POST /api/auth/login
|
||||
|
||||
Login with password (alternative to API key).
|
||||
@@ -264,11 +483,3 @@ Logout and clear session (requires login first).
|
||||
"message": "Authentication required. Use session cookie or API key (Bearer token)."
|
||||
}
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
For local testing I have made a node script that checks all available endpoints:
|
||||
|
||||
```bash
|
||||
AUTH_PASSWORD=your-password node test-api.js https://your-cronmaster-url.com
|
||||
```
|
||||
|
||||
@@ -35,14 +35,12 @@ ports:
|
||||
```yaml
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- DOCKER=true
|
||||
- NEXT_PUBLIC_CLOCK_UPDATE_INTERVAL=30000
|
||||
- AUTH_PASSWORD=very_strong_password
|
||||
- HOST_CRONTAB_USER=root
|
||||
```
|
||||
|
||||
- **NODE_ENV**: Set to `production` for production deployments
|
||||
- **DOCKER**: Must be `true` when running in Docker
|
||||
- **NEXT_PUBLIC_CLOCK_UPDATE_INTERVAL**: Clock update interval in milliseconds (default: 30000)
|
||||
- **AUTH_PASSWORD**: Strong password for authentication
|
||||
- **HOST_CRONTAB_USER**: User whose crontab to read (default: root, can be comma-separated for multiple users)
|
||||
@@ -52,7 +50,7 @@ environment:
|
||||
#### Localization
|
||||
|
||||
```yaml
|
||||
- LOCALE=en # or other supported locales (see /app/_translations/)
|
||||
- LOCALE=en # or any locale code (supports custom translations in ./data/translations/)
|
||||
```
|
||||
|
||||
#### Logging Configuration
|
||||
@@ -155,7 +153,6 @@ services:
|
||||
- "40123:3000"
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- DOCKER=true
|
||||
- NEXT_PUBLIC_CLOCK_UPDATE_INTERVAL=30000
|
||||
|
||||
# Localization
|
||||
|
||||
@@ -15,10 +15,35 @@ This document provides a comprehensive reference for all environment variables u
|
||||
| Variable | Default | Description |
|
||||
| --------------- | ------------- | ---------------------------------------------------------------------------- |
|
||||
| `APP_URL` | Auto-detected | Public URL of your Cronmaster instance (e.g., `https://cron.yourdomain.com`) |
|
||||
| `LOCALE` | `en` | Application locale/language setting |
|
||||
| `LOCALE` | `en` | Application locale/language setting (supports custom translations) |
|
||||
| `HOME` | `/home` | Path to home directory (optional override) |
|
||||
| `AUTH_PASSWORD` | `N/A` | Password for authentication (can be used alone or with SSO) |
|
||||
|
||||
## Custom Translations
|
||||
|
||||
CronMaster supports custom user-made translations. You can create your own translation files and use them by setting the `LOCALE` environment variable.
|
||||
|
||||
**For detailed instructions on creating custom translations or contributing official translations, see [TRANSLATIONS.md](TRANSLATIONS.md).**
|
||||
|
||||
### Quick Setup for Custom Translations
|
||||
|
||||
```bash
|
||||
# Create translations directory
|
||||
mkdir -p ./data/translations
|
||||
|
||||
# Copy template and customize
|
||||
cp app/_translations/en.json ./data/translations/your-locale.json
|
||||
|
||||
# Set locale and restart
|
||||
export LOCALE=your-locale
|
||||
```
|
||||
|
||||
Translation loading priority:
|
||||
|
||||
1. Custom: `./data/translations/{locale}.json`
|
||||
2. Built-in: `app/_translations/{locale}.json`
|
||||
3. Fallback: `app/_translations/en.json`
|
||||
|
||||
## Docker Configuration
|
||||
|
||||
| Variable | Default | Description |
|
||||
@@ -31,13 +56,15 @@ This document provides a comprehensive reference for all environment variables u
|
||||
| ----------------------------------- | ------- | -------------------------------------------------- |
|
||||
| `NEXT_PUBLIC_CLOCK_UPDATE_INTERVAL` | `30000` | Clock update interval in milliseconds (30 seconds) |
|
||||
| `LIVE_UPDATES` | `true` | Enable/disable Server-Sent Events for live updates |
|
||||
| `DISABLE_SYSTEM_STATS` | `false` | Set to `true` to completely disable system stats (stops polling and hides sidebar) |
|
||||
|
||||
## Logging Configuration
|
||||
|
||||
| Variable | Default | Description |
|
||||
| ------------------ | ------- | ---------------------------------------------- |
|
||||
| `MAX_LOG_AGE_DAYS` | `30` | Days to keep job execution logs before cleanup |
|
||||
| `MAX_LOGS_PER_JOB` | `50` | Maximum number of log files to keep per job |
|
||||
| Variable | Default | Description |
|
||||
| ------------------------------ | ------- | ---------------------------------------------------------------- |
|
||||
| `MAX_LOG_AGE_DAYS` | `30` | Days to keep job execution logs before cleanup |
|
||||
| `NEXT_PUBLIC_MAX_LOG_AGE_DAYS` | `30` | Days to keep error history in browser localStorage (client-side) |
|
||||
| `MAX_LOGS_PER_JOB` | `50` | Maximum number of log files to keep per job |
|
||||
|
||||
## Authentication & Security
|
||||
|
||||
@@ -58,6 +85,7 @@ This document provides a comprehensive reference for all environment variables u
|
||||
| `OIDC_CLIENT_SECRET` | `N/A` | OIDC client secret (optional, for confidential clients) |
|
||||
| `OIDC_LOGOUT_URL` | `N/A` | Custom logout URL for OIDC provider |
|
||||
| `OIDC_GROUPS_SCOPE` | `groups` | Scope for requesting user groups |
|
||||
| `OIDC_AUTO_REDIRECT` | `false` | Automatically redirect to OIDC provider when it's the only authentication method (no password set) |
|
||||
| `INTERNAL_API_URL` | `http://localhost:3000` | Internal API URL override for specific nginx configurations with SSO |
|
||||
|
||||
### API Authentication
|
||||
@@ -108,7 +136,7 @@ services:
|
||||
- AUTH_PASSWORD=your_secure_password
|
||||
- HOST_CRONTAB_USER=root
|
||||
- APP_URL=https://cron.yourdomain.com
|
||||
- LOCALE=en
|
||||
- LOCALE=en
|
||||
- NEXT_PUBLIC_CLOCK_UPDATE_INTERVAL=30000
|
||||
- LIVE_UPDATES=true
|
||||
- MAX_LOG_AGE_DAYS=30
|
||||
@@ -118,6 +146,7 @@ services:
|
||||
- OIDC_CLIENT_ID=your_client_id
|
||||
- OIDC_CLIENT_SECRET=your_client_secret
|
||||
- OIDC_LOGOUT_URL=https://auth.yourdomain.com/logout
|
||||
- OIDC_AUTO_REDIRECT=true
|
||||
- API_KEY=your_api_key
|
||||
```
|
||||
|
||||
|
||||
93
howto/LOGS.md
Normal file
93
howto/LOGS.md
Normal file
@@ -0,0 +1,93 @@
|
||||
# Job Execution Logging
|
||||
|
||||
CronMaster includes an optional logging feature that captures detailed execution information for your cronjobs.
|
||||
|
||||
## How It Works
|
||||
|
||||
When you enable logging for a cronjob, CronMaster automatically wraps your command with a log wrapper script. This wrapper:
|
||||
|
||||
- Captures **stdout** and **stderr** output
|
||||
- Records the **exit code** of your command
|
||||
- Timestamps the **start and end** of execution
|
||||
- Calculates **execution duration**
|
||||
- Stores all this information in organized log files
|
||||
|
||||
## Enabling Logs
|
||||
|
||||
1. When creating or editing a cronjob, check the "Enable Logging" checkbox
|
||||
2. The wrapper is automatically added to your crontab entry
|
||||
3. Jobs run independently - they continue to work even if CronMaster is offline
|
||||
|
||||
## Log Storage
|
||||
|
||||
Logs are stored in the `./data/logs/` directory with descriptive folder names:
|
||||
|
||||
- If a job has a **description/comment**: `{sanitized-description}_{jobId}/`
|
||||
- If a job has **no description**: `{jobId}/`
|
||||
|
||||
Example structure:
|
||||
|
||||
```
|
||||
./data/logs/
|
||||
├── backup-database_root-0/
|
||||
│ ├── 2025-11-10_14-30-00.log
|
||||
│ ├── 2025-11-10_15-30-00.log
|
||||
│ └── 2025-11-10_16-30-00.log
|
||||
├── daily-cleanup_root-1/
|
||||
│ └── 2025-11-10_14-35-00.log
|
||||
├── root-2/ (no description provided)
|
||||
│ └── 2025-11-10_14-40-00.log
|
||||
```
|
||||
|
||||
**Note**: Folder names are sanitized to be filesystem-safe (lowercase, alphanumeric with hyphens, max 50 chars for the description part).
|
||||
|
||||
## Log Format
|
||||
|
||||
Each log file includes:
|
||||
|
||||
```
|
||||
--- [ JOB START ] ----------------------------------------------------
|
||||
Command : bash /app/scripts/backup.sh
|
||||
Timestamp : 2025-11-10 14:30:00
|
||||
Host : hostname
|
||||
User : root
|
||||
--- [ JOB OUTPUT ] ---------------------------------------------------
|
||||
|
||||
[command output here]
|
||||
|
||||
--- [ JOB SUMMARY ] --------------------------------------------------
|
||||
Timestamp : 2025-11-10 14:30:45
|
||||
Duration : 45s
|
||||
Exit Code : 0
|
||||
Status : SUCCESS
|
||||
--- [ JOB END ] ------------------------------------------------------
|
||||
```
|
||||
|
||||
## Automatic Cleanup
|
||||
|
||||
Logs are automatically cleaned up to prevent disk space issues:
|
||||
|
||||
- **Maximum logs per job**: 50 log files
|
||||
- **Maximum age**: 30 days
|
||||
- **Cleanup trigger**: When viewing logs or after manual execution
|
||||
- **Method**: Oldest logs are deleted first when limits are exceeded
|
||||
|
||||
## Docker Considerations
|
||||
|
||||
- Mount the `./data` directory to persist logs on the host
|
||||
- The wrapper script location: `./data/cron-log-wrapper.sh`. This will be generated automatically the first time you enable logging.
|
||||
|
||||
## Non-Docker Considerations
|
||||
|
||||
- Logs are stored at `./data/logs/` relative to the project directory
|
||||
- The codebase wrapper script location: `./app/_scripts/cron-log-wrapper.sh`
|
||||
- The running wrapper script location: `./data/cron-log-wrapper.sh`
|
||||
|
||||
## Important Notes
|
||||
|
||||
- Logging is **optional** and disabled by default
|
||||
- Jobs with logging enabled are marked with a blue "Logged" badge in the UI
|
||||
- Logs are captured for both scheduled runs and manual executions
|
||||
- Commands with file redirections (>, >>) may conflict with logging
|
||||
- The crontab stores the **wrapped command**, so jobs run independently of CronMaster
|
||||
|
||||
415
howto/TRANSLATIONS.md
Normal file
415
howto/TRANSLATIONS.md
Normal file
@@ -0,0 +1,415 @@
|
||||
# Translation Guide
|
||||
|
||||
CronMaster supports internationalization (i18n) with both **unofficial custom translations** and **official translations** that can be contributed to the project.
|
||||
|
||||
## Quick links
|
||||
|
||||
- [Custom User Translations (Unofficial)](#custom-user-translations-unofficial)
|
||||
- [Official Translations via Pull Request](#official-translations-via-pull-request)
|
||||
- [Translation File Structure](#translation-file-structure)
|
||||
- [Testing Your Translations](#testing-your-translations)
|
||||
- [Translation Guidelines](#translation-guidelines)
|
||||
|
||||
## Custom User Translations (Unofficial)
|
||||
|
||||
You can create your own translation files locally without modifying the source code. These translations are loaded from the `./data/translations/` directory.
|
||||
|
||||
### Quick Setup
|
||||
|
||||
1. **Create the translations directory:**
|
||||
|
||||
```bash
|
||||
mkdir -p ./data/translations
|
||||
```
|
||||
|
||||
2. **Copy a template:**
|
||||
|
||||
```bash
|
||||
cp app/_translations/en.json ./data/translations/your-locale.json
|
||||
```
|
||||
|
||||
**Note**: for docker users, you can copy the translation template from the [source code](https://github.com/fccview/cronmaster/blob/main/app/_translations/en.json)
|
||||
|
||||
3. **Set your locale:**
|
||||
```bash
|
||||
export LOCALE=your-locale
|
||||
```
|
||||
|
||||
### Step-by-Step Guide
|
||||
|
||||
#### 1. Prepare the Directory Structure
|
||||
|
||||
```bash
|
||||
# Create translations directory in your data folder
|
||||
mkdir -p ./data/translations
|
||||
|
||||
# Verify the structure
|
||||
ls -la ./data/translations/
|
||||
```
|
||||
|
||||
#### 2. Create Your Translation File
|
||||
|
||||
Use English as a template and create your locale file:
|
||||
|
||||
```bash
|
||||
# Copy English template
|
||||
cp app/_translations/en.json ./data/translations/fr.json
|
||||
|
||||
# Or for any other locale
|
||||
cp app/_translations/en.json ./data/translations/es.json
|
||||
cp app/_translations/en.json ./data/translations/de.json
|
||||
```
|
||||
|
||||
#### 3. Edit Your Translation
|
||||
|
||||
Open your translation file and modify the values:
|
||||
|
||||
```bash
|
||||
# Edit with your preferred editor
|
||||
nano ./data/translations/fr.json
|
||||
# or
|
||||
code ./data/translations/fr.json
|
||||
```
|
||||
|
||||
#### 4. Configure Environment
|
||||
|
||||
Set the `LOCALE` environment variable to your locale code:
|
||||
|
||||
```bash
|
||||
# For French
|
||||
export LOCALE=fr
|
||||
|
||||
# For Spanish
|
||||
export LOCALE=es
|
||||
|
||||
# For German
|
||||
export LOCALE=de
|
||||
```
|
||||
|
||||
#### 5. Restart the Application
|
||||
|
||||
Restart CronMaster to load the new translations:
|
||||
|
||||
```bash
|
||||
# If running with npm/yarn
|
||||
npm restart
|
||||
# or
|
||||
yarn restart
|
||||
|
||||
# If using Docker
|
||||
docker-compose restart cronmaster
|
||||
```
|
||||
|
||||
### Translation Priority
|
||||
|
||||
Translations are loaded in this order:
|
||||
|
||||
1. **Custom**: `./data/translations/{locale}.json` (highest priority)
|
||||
2. **Built-in**: `app/_translations/{locale}.json`
|
||||
3. **Fallback**: `app/_translations/en.json` (English)
|
||||
|
||||
This means you can override any built-in translation by creating a custom file with the same locale code.
|
||||
|
||||
## Official Translations via Pull Request
|
||||
|
||||
To contribute an official translation to the CronMaster project, you'll need to create a pull request **targeting the `develop` branch**. All feature contributions, including translations, are merged into `develop` first before being released to `main`.
|
||||
|
||||
**Important:** Do not target the `main` branch directly. All pull requests should be made against `develop`.
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- Basic knowledge of Git and GitHub
|
||||
- Understanding of JSON format
|
||||
- Familiarity with the CronMaster interface
|
||||
- Accuracy in translation
|
||||
|
||||
### Step-by-Step Contribution Process
|
||||
|
||||
#### 1. Fork the Repository
|
||||
|
||||
```bash
|
||||
# Fork the repository on GitHub
|
||||
# Visit: https://github.com/fccview/cronmaster
|
||||
# Click "Fork" button in the top right
|
||||
```
|
||||
|
||||
#### 2. Clone Your Fork
|
||||
|
||||
```bash
|
||||
# Clone your fork locally
|
||||
git clone https://github.com/YOUR_USERNAME/cronmaster.git
|
||||
cd cronmaster
|
||||
|
||||
# Add upstream remote
|
||||
git remote add upstream https://github.com/fccview/cronmaster.git
|
||||
```
|
||||
|
||||
#### 3. Create a Feature Branch
|
||||
|
||||
```bash
|
||||
# First, ensure you're on the develop branch
|
||||
git checkout develop
|
||||
git pull upstream develop
|
||||
|
||||
# Then create and switch to a new feature branch
|
||||
git checkout -b feature/add-locale-XX
|
||||
|
||||
# Example for Spanish:
|
||||
git checkout develop
|
||||
git pull upstream develop
|
||||
git checkout -b feature/add-locale-es
|
||||
|
||||
# Example for French:
|
||||
git checkout develop
|
||||
git pull upstream develop
|
||||
git checkout -b feature/add-locale-fr
|
||||
```
|
||||
|
||||
#### 4. Create the Translation File
|
||||
|
||||
```bash
|
||||
# Copy the English template
|
||||
cp app/_translations/en.json app/_translations/LOCALE.json
|
||||
|
||||
# Replace LOCALE with your locale code (e.g., es, fr, de, it, pt, etc.)
|
||||
cp app/_translations/en.json app/_translations/es.json
|
||||
```
|
||||
|
||||
#### 5. Translate the Content
|
||||
|
||||
Open your translation file and translate all values:
|
||||
|
||||
```bash
|
||||
# Edit the translation file
|
||||
nano app/_translations/es.json
|
||||
# or
|
||||
code app/_translations/es.json
|
||||
```
|
||||
|
||||
**Important:** Do not change the JSON keys, only translate the string values.
|
||||
|
||||
#### 6. Test Your Translation
|
||||
|
||||
```bash
|
||||
# Set your locale for testing
|
||||
export LOCALE=es
|
||||
|
||||
# Start the development server
|
||||
npm run dev
|
||||
# or
|
||||
yarn dev
|
||||
|
||||
# Visit http://localhost:3000 and verify translations
|
||||
```
|
||||
|
||||
#### 7. Commit Your Changes
|
||||
|
||||
```bash
|
||||
# Add your translation file
|
||||
git add app/_translations/es.json
|
||||
|
||||
# Commit with a descriptive message
|
||||
git commit -m "feat: add Spanish (es) translation
|
||||
|
||||
- Complete Spanish translation for all UI strings
|
||||
- Tested with LOCALE=es environment variable
|
||||
- Follows translation guidelines and structure"
|
||||
```
|
||||
|
||||
#### 8. Push to Your Fork
|
||||
|
||||
```bash
|
||||
# Push your branch to GitHub
|
||||
git push origin feature/add-locale-es
|
||||
```
|
||||
|
||||
#### 9. Create a Pull Request
|
||||
|
||||
1. Visit your fork on GitHub
|
||||
2. Click "Compare & pull request" for your branch
|
||||
3. **Important:** Ensure the pull request targets the `develop` branch (not `main`)
|
||||
- The "base repository" should be `fccview/cronmaster`
|
||||
- The "base" branch should be `develop`
|
||||
- The "head repository" should be `YOUR_USERNAME/cronmaster`
|
||||
- The "compare" branch should be `feature/add-locale-XX`
|
||||
4. Fill out the pull request template:
|
||||
|
||||
**Title:** `feat: add Spanish (es) translation`
|
||||
|
||||
**Description:**
|
||||
|
||||
```markdown
|
||||
## Description
|
||||
|
||||
This PR adds official Spanish translation support to CronMaster.
|
||||
|
||||
## Changes
|
||||
|
||||
- Added `app/_translations/es.json` with complete Spanish translations
|
||||
- All UI strings have been translated accurately
|
||||
- Translation structure matches the English template
|
||||
|
||||
## Testing
|
||||
|
||||
- Tested with `LOCALE=es` environment variable
|
||||
- Verified all pages and components display correctly
|
||||
- No broken translations or missing keys
|
||||
|
||||
## Checklist
|
||||
|
||||
- [x] Translation is complete (all keys translated)
|
||||
- [x] No JSON syntax errors
|
||||
- [x] Follows translation guidelines
|
||||
- [x] Tested in development environment
|
||||
- [x] Commit message follows conventional format
|
||||
```
|
||||
|
||||
#### 10. Address Review Feedback
|
||||
|
||||
The maintainers may request changes. Make any necessary updates:
|
||||
|
||||
```bash
|
||||
# Make changes based on feedback
|
||||
git add app/_translations/es.json
|
||||
git commit -m "fix: update Spanish translations based on review feedback"
|
||||
git push origin feature/add-locale-es
|
||||
```
|
||||
|
||||
### Pull Request Requirements
|
||||
|
||||
Your pull request must meet these criteria:
|
||||
|
||||
- [ ] **Complete Translation**: All keys from `en.json` must be translated
|
||||
- [ ] **Valid JSON**: No syntax errors, proper escaping
|
||||
- [ ] **Accurate Translation**: Professional, accurate translations
|
||||
- [ ] **Consistent Terminology**: Use consistent terms throughout
|
||||
- [ ] **Cultural Adaptation**: Adapt content appropriately for the locale
|
||||
- [ ] **Tested**: Verified working in the application
|
||||
- [ ] **Proper Commit**: Follows conventional commit format
|
||||
|
||||
### Translation Standards
|
||||
|
||||
- Use proper grammar and punctuation
|
||||
- Maintain consistent terminology
|
||||
- Keep technical terms in English when appropriate
|
||||
- Use appropriate formality level for the target language
|
||||
- Consider cultural context and conventions
|
||||
- Keep translations concise but complete
|
||||
|
||||
## Translation File Structure
|
||||
|
||||
All translation files follow this JSON structure:
|
||||
|
||||
```json
|
||||
{
|
||||
"common": {
|
||||
"cronManagementMadeEasy": "Cron Management made easy",
|
||||
"user": "User",
|
||||
"cancel": "Cancel",
|
||||
"close": "Close"
|
||||
},
|
||||
"cronjobs": {
|
||||
"cronJobs": "Cron Jobs",
|
||||
"scheduledTasks": "Scheduled Tasks"
|
||||
},
|
||||
"scripts": {
|
||||
"bashScripts": "Bash Scripts"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Key Guidelines
|
||||
|
||||
- **Keys remain unchanged**: Never modify the JSON keys
|
||||
- **Values are translated**: Only translate the string values
|
||||
- **Hierarchy preserved**: Maintain the nested object structure
|
||||
- **Data types maintained**: Keep arrays as arrays, objects as objects
|
||||
|
||||
## Testing Your Translations
|
||||
|
||||
### Development Testing
|
||||
|
||||
```bash
|
||||
# Set your locale
|
||||
export LOCALE=your-locale
|
||||
|
||||
# Start development server
|
||||
npm run dev
|
||||
|
||||
# Test all pages and features:
|
||||
# - Main dashboard
|
||||
# - Cron job management
|
||||
# - Script editor
|
||||
# - Settings pages
|
||||
# - Error messages
|
||||
# - Modal dialogs
|
||||
```
|
||||
|
||||
### Docker Testing
|
||||
|
||||
```yaml
|
||||
# docker-compose.yml
|
||||
services:
|
||||
cronmaster:
|
||||
environment:
|
||||
- LOCALE=your-locale
|
||||
volumes:
|
||||
- ./data/translations:/app/data/translations:ro
|
||||
```
|
||||
|
||||
### Validation Checklist
|
||||
|
||||
- [ ] All pages load without errors
|
||||
- [ ] No untranslated strings (should show key names if missing)
|
||||
- [ ] Text fits within UI components
|
||||
- [ ] Pluralization works correctly (if applicable)
|
||||
- [ ] Special characters display correctly
|
||||
- [ ] Date/time formats are appropriate for locale
|
||||
|
||||
## Translation Guidelines
|
||||
|
||||
### General Principles
|
||||
|
||||
1. **Accuracy**: Provide accurate, professional translations
|
||||
2. **Consistency**: Use consistent terminology throughout
|
||||
3. **Context Awareness**: Consider UI context and user expectations
|
||||
4. **Cultural Sensitivity**: Adapt content appropriately for the culture
|
||||
5. **Technical Precision**: Maintain technical accuracy for cron/bash concepts
|
||||
|
||||
### Technical Terms
|
||||
|
||||
Some terms should remain in English:
|
||||
|
||||
- "Cron" (the utility name)
|
||||
- "Bash" (the shell name)
|
||||
- Technical file formats (JSON, YAML, etc.)
|
||||
- Command names and parameters
|
||||
- Status messages that are code-related
|
||||
|
||||
### UI-Specific Considerations
|
||||
|
||||
- **Button labels**: Keep short and actionable
|
||||
- **Error messages**: Clear and helpful
|
||||
- **Navigation**: Consistent with user expectations
|
||||
- **Date/Time**: Use locale-appropriate formats
|
||||
- **Numbers**: Follow locale conventions
|
||||
|
||||
### Quality Assurance
|
||||
|
||||
Before submitting:
|
||||
|
||||
- Proofread all translations
|
||||
- Test in context of the application
|
||||
- Verify no broken JSON syntax
|
||||
- Ensure all keys are translated
|
||||
- Check for consistent style and tone
|
||||
|
||||
## Need Help?
|
||||
|
||||
- **Issues**: Report translation bugs or request new locales
|
||||
- **Discussions**: Discuss translation approaches and guidelines
|
||||
- **Discord**: Join our community for translation help
|
||||
|
||||
---
|
||||
|
||||
**Note**: This guide applies to CronMaster version 1.x and later. For older versions, translations must be contributed directly to the main repository.
|
||||
@@ -37,6 +37,9 @@ export const middleware = async (request: NextRequest) => {
|
||||
const sessionId = request.cookies.get(cookieName)?.value;
|
||||
|
||||
if (process.env.DEBUGGER) {
|
||||
console.log("MIDDLEWARE - cookieName:", cookieName);
|
||||
console.log("MIDDLEWARE - NODE_ENV:", process.env.NODE_ENV);
|
||||
console.log("MIDDLEWARE - HTTPS:", process.env.HTTPS);
|
||||
console.log("MIDDLEWARE - sessionId:", sessionId);
|
||||
console.log("MIDDLEWARE - cookies:", request.cookies.getAll());
|
||||
}
|
||||
|
||||
2
next-env.d.ts
vendored
2
next-env.d.ts
vendored
@@ -2,4 +2,4 @@
|
||||
/// <reference types="next/image-types/global" />
|
||||
|
||||
// NOTE: This file should not be edited
|
||||
// see https://nextjs.org/docs/basic-features/typescript for more information.
|
||||
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
|
||||
|
||||
@@ -1,49 +1,55 @@
|
||||
const withNextIntl = require('next-intl/plugin')('./app/i18n.ts');
|
||||
|
||||
const withPWA = require('next-pwa')({
|
||||
dest: 'public',
|
||||
register: true,
|
||||
skipWaiting: true,
|
||||
disable: process.env.NODE_ENV === 'development',
|
||||
buildExcludes: [/middleware-manifest\.json$/]
|
||||
dest: 'public',
|
||||
register: true,
|
||||
skipWaiting: true,
|
||||
disable: process.env.NODE_ENV === 'development',
|
||||
buildExcludes: [/middleware-manifest\.json$/]
|
||||
})
|
||||
|
||||
/** @type {import('next').NextConfig} */
|
||||
const withNextIntl = require('next-intl/plugin')('./app/i18n.ts')
|
||||
|
||||
const nextConfig = {
|
||||
webpack: (config, { dev, isServer }) => {
|
||||
config.resolve.alias = {
|
||||
...config.resolve.alias,
|
||||
'osx-temperature-sensor': false,
|
||||
};
|
||||
output: 'standalone',
|
||||
experimental: {
|
||||
serverComponentsExternalPackages: [],
|
||||
webpackBuildWorker: true
|
||||
},
|
||||
swcMinify: true,
|
||||
images: {
|
||||
unoptimized: true
|
||||
},
|
||||
webpack: (config, { dev, isServer }) => {
|
||||
config.resolve.alias = {
|
||||
...config.resolve.alias,
|
||||
'osx-temperature-sensor': false,
|
||||
};
|
||||
|
||||
if (dev && !isServer) {
|
||||
config.watchOptions = {
|
||||
...config.watchOptions,
|
||||
ignored: /node_modules/,
|
||||
};
|
||||
}
|
||||
if (dev && !isServer) {
|
||||
config.watchOptions = {
|
||||
...config.watchOptions,
|
||||
ignored: /node_modules/,
|
||||
};
|
||||
}
|
||||
|
||||
return config;
|
||||
},
|
||||
async headers() {
|
||||
return [
|
||||
{
|
||||
source: '/manifest.json',
|
||||
headers: [
|
||||
{ key: 'Content-Type', value: 'application/manifest+json' },
|
||||
],
|
||||
},
|
||||
{
|
||||
source: '/sw.js',
|
||||
headers: [
|
||||
{ key: 'Service-Worker-Allowed', value: '/' },
|
||||
{ key: 'Cache-Control', value: 'no-cache' },
|
||||
],
|
||||
},
|
||||
]
|
||||
},
|
||||
return config;
|
||||
},
|
||||
async headers() {
|
||||
return [
|
||||
{
|
||||
source: '/manifest.json',
|
||||
headers: [
|
||||
{ key: 'Content-Type', value: 'application/manifest+json' },
|
||||
],
|
||||
},
|
||||
{
|
||||
source: '/sw.js',
|
||||
headers: [
|
||||
{ key: 'Service-Worker-Allowed', value: '/' },
|
||||
{ key: 'Cache-Control', value: 'no-cache' },
|
||||
],
|
||||
},
|
||||
]
|
||||
},
|
||||
}
|
||||
|
||||
module.exports = withNextIntl({
|
||||
...withPWA(nextConfig)
|
||||
});
|
||||
module.exports = withPWA(withNextIntl(nextConfig))
|
||||
|
||||
14
package.json
14
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cronjob-manager",
|
||||
"version": "1.5.0",
|
||||
"version": "2.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
@@ -13,15 +13,21 @@
|
||||
"@codemirror/commands": "^6.8.1",
|
||||
"@codemirror/lang-javascript": "^6.2.4",
|
||||
"@codemirror/language": "^6.11.3",
|
||||
"@codemirror/legacy-modes": "^6.5.2",
|
||||
"@codemirror/lint": "^6.8.5",
|
||||
"@codemirror/search": "^6.5.11",
|
||||
"@codemirror/state": "^6.5.2",
|
||||
"@codemirror/theme-one-dark": "^6.1.3",
|
||||
"@codemirror/view": "^6.38.1",
|
||||
"@fontsource-variable/azeret-mono": "^5.2.11",
|
||||
"@fontsource/ibm-plex-mono": "^5.2.7",
|
||||
"@phosphor-icons/react": "^2.1.10",
|
||||
"@types/node": "^20",
|
||||
"@types/react": "^18",
|
||||
"@types/react-dom": "^18",
|
||||
"@types/react-syntax-highlighter": "^15.5.13",
|
||||
"@webtui/css": "^0.1.5",
|
||||
"@webtui/theme-catppuccin": "^0.0.3",
|
||||
"autoprefixer": "^10.0.1",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"clsx": "^2.0.0",
|
||||
@@ -29,9 +35,8 @@
|
||||
"cron-parser": "^5.3.0",
|
||||
"cronstrue": "^3.2.0",
|
||||
"jose": "^6.1.1",
|
||||
"lucide-react": "^0.294.0",
|
||||
"minimatch": "^10.0.3",
|
||||
"next": "14.0.4",
|
||||
"next": "14.2.35",
|
||||
"next-intl": "^4.4.0",
|
||||
"next-pwa": "^5.6.0",
|
||||
"next-themes": "^0.2.1",
|
||||
@@ -49,6 +54,7 @@
|
||||
"@types/bcryptjs": "^2.4.6",
|
||||
"@types/minimatch": "^6.0.0",
|
||||
"eslint": "^8",
|
||||
"eslint-config-next": "14.0.4"
|
||||
"eslint-config-next": "14.0.4",
|
||||
"postcss-import": "^16.1.1"
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user