Skip to content

Commit

Permalink
Lint and make allow server deletion toggle function. Thanks Gamer3514!
Browse files Browse the repository at this point in the history
  • Loading branch information
kokofixcomputers committed Oct 30, 2024
1 parent d15b0cd commit 5f40a47
Show file tree
Hide file tree
Showing 19 changed files with 93 additions and 60 deletions.
10 changes: 5 additions & 5 deletions app/Console/Commands/Schedule/RenewalCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Console\Command;
use Jexactyl\Services\Servers\SuspensionService;
use Jexactyl\Services\Servers\ServerDeletionService;
use Exception;

class RenewalCommand extends Command
{
/**
Expand Down Expand Up @@ -51,19 +51,19 @@ protected function process(Server $server)
foreach ($servers as $svr) {
try {
$this->line('Renewing server ' . $svr->name, false);

$svr->update(['renewal' => $svr->renewal - 1]);

if ($svr->renewal <= 0) {
$this->line('Suspending server ' . $svr->name, false);
$this->suspensionService->toggle($svr, 'suspend');
}

if ($svr->renewal <= -7) {
$this->line('Deleting server ' . $svr->name, false);
$this->deletionService->handle($svr);
}
} catch (Exception $e) {
} catch (\Exception $e) {
$this->line('Error processing server ' . $svr->name . ': ' . $e->getMessage());
}
}
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Api/Client/DiscordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function unlink(): JsonResponse
return new JsonResponse(['error' => 'No authenticated user'], 401);
}
$user->update(['discord_id' => null]);

return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
}

Expand Down
4 changes: 4 additions & 0 deletions app/Http/ViewComposers/StoreComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public function compose(View $view)
'enabled' => $this->setting('renewal:editing', Composer::TYPE_BOOL),
],

'deletion' => [
'enabled' => $this->setting('renewal:deletion', Composer::TYPE_BOOL),
],

'referrals' => [
'enabled' => $this->setting('referrals:enabled', Composer::TYPE_BOOL),
'reward' => $this->setting('referrals:reward', Composer::TYPE_INT),
Expand Down
22 changes: 14 additions & 8 deletions resources/scripts/components/auth/LoginContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import useFlash from '@/plugins/useFlash';
import { useStoreState } from 'easy-peasy';
import { Formik, FormikHelpers } from 'formik';
import { FaDiscord } from 'react-icons/fa';
import { MdOutlineEmail } from "react-icons/md";
import { MdOutlineEmail } from 'react-icons/md';
import Field from '@/components/elements/Field';
import React, { useEffect, useRef, useState } from 'react';
import { Button } from '@/components/elements/button/index';
Expand Down Expand Up @@ -108,19 +108,25 @@ const LoginContainer = ({ history }: RouteComponentProps) => {
<div css={tw`mt-6 text-center`}>
{email && (
<Link to={'/auth/register'}>
<Button css={tw`bg-green-500 text-white w-full mt-2 hover:bg-green-600`} size={Button.Sizes.Large}>
<MdOutlineEmail className="inline-block mr-2" />
<Button
css={tw`bg-green-500 text-white w-full mt-2 hover:bg-green-600`}
size={Button.Sizes.Large}
>
<MdOutlineEmail className='inline-block mr-2' />
Signup with Email
</Button>
</Link>
)}
{discord && (
<Link to={'/auth/discord'}>
<Button css={tw`bg-blue-500 text-white w-full mt-2 hover:bg-blue-600`} size={Button.Sizes.Large}>
<FaDiscord className="inline-block mr-2" />
Authenticate with Discord
</Button>
</Link>
<Button
css={tw`bg-blue-500 text-white w-full mt-2 hover:bg-blue-600`}
size={Button.Sizes.Large}
>
<FaDiscord className='inline-block mr-2' />
Authenticate with Discord
</Button>
</Link>
)}
</div>
)}
Expand Down
4 changes: 2 additions & 2 deletions resources/scripts/components/dashboard/ApiKeyModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const ApiKeyModal = ({ apiKey }: Props) => {
<>
<h3 css={tw`mb-6 text-2xl`}>Your API Key</h3>
<p css={tw`text-sm mb-6`}>
The API key you have requested is shown below. For safety reasons, please store this in a safe location, it will not be
shown again.
The API key you have requested is shown below. For safety reasons, please store this in a safe location,
it will not be shown again.
</p>
<pre css={tw`text-sm bg-neutral-900 rounded py-2 px-4 font-mono`}>
<CopyOnClick text={apiKey}>
Expand Down
6 changes: 4 additions & 2 deletions resources/scripts/components/dashboard/DashboardContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export default () => {
{showOnlyAdmin ? 'Showing other servers' : 'Showing your servers'}
</h1>
<h3 className={'text-2xl mt-2 text-neutral-500'}>
Select a server to view, update or modify. Go to storefront in the sidebar to create a new server.
Select a server to view, update or modify. Go to storefront in the sidebar to create a
new server.
</h3>
</div>
<Switch
Expand Down Expand Up @@ -97,7 +98,8 @@ export default () => {
</div>
) : (
<p className={'text-gray-400 text-lg font-semibold text-center'}>
Doesn&apos;t look like you have any servers here. Create one in storefront from the sidebar if it&apos;s open.
Doesn&apos;t look like you have any servers here. Create one in storefront from the
sidebar if it&apos;s open.
</p>
)
}
Expand Down
26 changes: 11 additions & 15 deletions resources/scripts/components/dashboard/ServerRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const StatusIndicatorBox = styled(GreyRowBox)<{ $status: ServerPowerState | unde
? tw`bg-green-500`
: tw`bg-yellow-500`};
}
&:hover .status-bar {
${tw`opacity-75`};
}
Expand Down Expand Up @@ -89,19 +89,17 @@ export default ({ server, className }: { server: Server; className?: string }) =
>
<div css={tw`flex flex-col col-span-12 items-center justify-center text-center`}>
<div>
<p css={tw`text-xl font-medium break-words m-2 text-gray-200`}>
{server.name || "No Server Name"}
</p>
<p css={tw`text-xl font-medium break-words m-2 text-gray-200`}>{server.name || 'No Server Name'}</p>
<p css={tw`text-sm text-neutral-400 break-words line-clamp-1 mb-2`}>
{server.allocations.length > 0
{server.allocations.length > 0
? server.allocations
.filter((alloc) => alloc.isDefault)
.map((allocation) => (
<React.Fragment key={allocation.ip + allocation.port.toString()}>
{allocation.alias || ip(allocation.ip)}:{allocation.port}
</React.Fragment>
))
: "No Allocations"}
.filter((alloc) => alloc.isDefault)
.map((allocation) => (
<React.Fragment key={allocation.ip + allocation.port.toString()}>
{allocation.alias || ip(allocation.ip)}:{allocation.port}
</React.Fragment>
))
: 'No Allocations'}
</p>
</div>
<div css={tw`flex flex-col col-span-full sm:flex-row items-baseline justify-center`}>
Expand Down Expand Up @@ -136,9 +134,7 @@ export default ({ server, className }: { server: Server; className?: string }) =
<div css={tw`flex flex-col items-center w-full sm:w-auto mb-4 sm:mb-0`}>
<div css={tw`flex justify-center text-neutral-500`}>
<Icon.Cpu size={20} />
<IconDescription $alarm={alarms.cpu}>
{stats.cpuUsagePercent.toFixed(2)}%
</IconDescription>
<IconDescription $alarm={alarms.cpu}>{stats.cpuUsagePercent.toFixed(2)}%</IconDescription>
</div>
</div>

Expand Down
8 changes: 4 additions & 4 deletions resources/scripts/components/server/console/PowerButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ export default ({ className }: PowerButtonProps) => {
disabled={status !== 'offline'}
onClick={onButtonClick.bind(this, 'start')}
>
<Icon.Play className="mr-2" /> Start
<Icon.Play className='mr-2' /> Start
</Button>
</Can>
<Can action={'control.restart'}>
<Button.Text className={'flex-1'} disabled={!status} onClick={onButtonClick.bind(this, 'restart')}>
<Icon.RefreshCcw className="mr-2" /> Restart
<Icon.RefreshCcw className='mr-2' /> Restart
</Button.Text>
</Can>
<Can action={'control.stop'}>
Expand All @@ -69,7 +69,7 @@ export default ({ className }: PowerButtonProps) => {
disabled={status === 'offline'}
onClick={onButtonClick.bind(this, killable ? 'stop' : 'stop')}
>
<Icon.Square className="mr-2" /> {killable ? 'Stop' : 'Stop'}
<Icon.Square className='mr-2' /> {killable ? 'Stop' : 'Stop'}
</Button.Danger>
</Can>
<Can action={'control.kill'}>
Expand All @@ -78,7 +78,7 @@ export default ({ className }: PowerButtonProps) => {
disabled={status === 'offline'}
onClick={onButtonClick.bind(this, killable ? 'kill' : 'kill')}
>
<Icon.Zap className="mr-2" /> {killable ? 'Kill' : 'Kill'}
<Icon.Zap className='mr-2' /> {killable ? 'Kill' : 'Kill'}
</Button.Danger>
</Can>
</div>
Expand Down
10 changes: 8 additions & 2 deletions resources/scripts/components/server/files/ChmodFileModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const ChmodFileModal = ({ files, ...props }: OwnProps) => {
};

// Generate a title based on the files being chmoded
const title = `Changing Permissions for: ${files.map(f => f.file).join(', ')}`;
const title = `Changing Permissions for: ${files.map((f) => f.file).join(', ')}`;

return (
<Formik onSubmit={submit} initialValues={{ mode: files.length > 1 ? '' : files[0].mode || '' }}>
Expand All @@ -64,7 +64,13 @@ const ChmodFileModal = ({ files, ...props }: OwnProps) => {
<Form css={tw`m-0`}>
<div css={tw`flex flex-wrap items-end`}>
<div css={tw`w-full sm:flex-1 sm:mr-4`}>
<Field type={'string'} id={'file_mode'} name={'mode'} label={'File Mode'} autoFocus />
<Field
type={'string'}
id={'file_mode'}
name={'mode'}
label={'File Mode'}
autoFocus
/>
</div>
<div css={tw`w-full sm:w-auto mt-4 sm:mt-0`}>
<Button css={tw`w-full`}>Update</Button>
Expand Down
11 changes: 4 additions & 7 deletions resources/scripts/components/server/files/FileEditContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ const getLanguageFromFilename = (filename: string) => {
case 'swift':
return 'swift';
case 'm':
case 'h':
return 'objectivec';
case 'scala':
return 'scala';
Expand Down Expand Up @@ -161,10 +160,8 @@ export default () => {

setLoading(true);
clearFlashes('files:view');

const savePromise = isMobile()
? fetchFileContent!()
: Promise.resolve(editorRef.current.getValue());

const savePromise = isMobile() ? fetchFileContent!() : Promise.resolve(editorRef.current.getValue());

savePromise
.then((content) => saveFileContents(uuid, name || hashToPath(hash), content))
Expand Down Expand Up @@ -234,8 +231,8 @@ export default () => {
/>
) : (
<Editor
height="75vh"
theme="vs-dark"
height='75vh'
theme='vs-dark'
language={getLanguageFromFilename(hash.replace(/^#/, ''))}
value={content}
onMount={(editor, monaco) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import tw from 'twin.macro';
import Can from '@/components/elements/Can';
import { ServerContext } from '@/state/server';
import { useStoreState } from 'easy-peasy';
import CopyOnClick from '@/components/elements/CopyOnClick';
import TitledGreyBox from '@/components/elements/TitledGreyBox';
import ServerContentBlock from '@/components/elements/ServerContentBlock';
Expand All @@ -11,6 +12,7 @@ import ReinstallServerBox from '@/components/server/settings/ReinstallServerBox'
import ChangeBackgroundBox from '@/components/server/settings/ChangeBackgroundBox';

export default () => {
const deletion = useStoreState((state) => state.storefront.data!.deletion.enabled);
const uuid = ServerContext.useStoreState((state) => state.server.data!.uuid);
const node = ServerContext.useStoreState((state) => state.server.data!.node);

Expand All @@ -34,7 +36,7 @@ export default () => {
</div>
</CopyOnClick>
</TitledGreyBox>
<DeleteServerBox />
{deletion && <DeleteServerBox />}
<ChangeBackgroundBox />
</div>
<div className={'w-full mt-6 md:flex-1 md:mt-0'}>
Expand Down
4 changes: 3 additions & 1 deletion resources/scripts/components/server/users/UsersContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export default () => {
showFlashKey={'users'}
>
{!subusers.length ? (
<p css={tw`text-center text-sm text-neutral-300`}>It looks like this server doesn&apos;t have any subusers.</p>
<p css={tw`text-center text-sm text-neutral-300`}>
It looks like this server doesn&apos;t have any subusers.
</p>
) : (
subusers.map((subuser) => <UserRow key={subuser.uuid} subuser={subuser} />)
)}
Expand Down
4 changes: 3 additions & 1 deletion resources/scripts/components/store/CreateContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ export default () => {
</option>
))}
</Select>
<p className={'mt-1 text-xs text-gray-400'}>Select a nest or catagory to use for your server.</p>
<p className={'mt-1 text-xs text-gray-400'}>
Select a nest or catagory to use for your server.
</p>
</TitledGreyBox>
<TitledGreyBox title={'Server Egg'} icon={faEgg} className={'mt-8 sm:mt-0'}>
<Select name={'egg'} onChange={(e) => setEgg(parseInt(e.target.value))}>
Expand Down
3 changes: 2 additions & 1 deletion resources/scripts/components/store/PurchaseContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export default () => {
<ContentBox title={'Purchase credits'} showFlashes={'account:balance'} css={tw`mt-8 sm:mt-0 sm:ml-8`}>
{!paypal && !stripe ? (
<p className={'text-gray-400 text-sm text-center'}>
Payment gateways are unavailable at this time. If you think this is a mistake, please contact an admin.
Payment gateways are unavailable at this time. If you think this is a mistake, please
contact an admin.
</p>
) : (
<>
Expand Down
24 changes: 16 additions & 8 deletions resources/scripts/components/store/ResourcesContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import PurchaseBox from '@/components/elements/store/PurchaseBox';
import PageContentBlock from '@/components/elements/PageContentBlock';
import ResourceBar from '@/components/elements/store/ResourceBar';



const Container = styled.div`
${tw`flex flex-wrap`};
Expand Down Expand Up @@ -91,7 +89,9 @@ export default () => {
setOpen={setOpen}
icon={<Icon.Cpu />}
setResource={setResource}
description={'Buy CPU to improve server load times and performance. <span className="text-yellow-400">(REQUIRED TO DEPLOY SERVER)</span>'}
description={
'Buy CPU to improve server load times and performance. <span className="text-yellow-400">(REQUIRED TO DEPLOY SERVER)</span>'
}
/>
<PurchaseBox
type={'Memory'}
Expand All @@ -101,7 +101,9 @@ export default () => {
setOpen={setOpen}
icon={<Icon.PieChart />}
setResource={setResource}
description={'Buy RAM to improve overall server performance. <span className="text-yellow-400">(REQUIRED TO DEPLOY SERVER)</span>'}
description={
'Buy RAM to improve overall server performance. <span className="text-yellow-400">(REQUIRED TO DEPLOY SERVER)</span>'
}
/>
<PurchaseBox
type={'Disk'}
Expand All @@ -111,7 +113,9 @@ export default () => {
setOpen={setOpen}
icon={<Icon.HardDrive />}
setResource={setResource}
description={'Buy disk to store more files. <span className="text-yellow-400">(REQUIRED TO DEPLOY SERVER)</span>'}
description={
'Buy disk to store more files. <span className="text-yellow-400">(REQUIRED TO DEPLOY SERVER)</span>'
}
/>
<PurchaseBox
type={'Slots'}
Expand All @@ -120,7 +124,9 @@ export default () => {
setOpen={setOpen}
icon={<Icon.Server />}
setResource={setResource}
description={'Buy a server slot so you can deploy a new server. <span className="text-yellow-400">(REQUIRED TO DEPLOY SERVER)</span>'}
description={
'Buy a server slot so you can deploy a new server. <span className="text-yellow-400">(REQUIRED TO DEPLOY SERVER)</span>'
}
/>
</Container>
<Container className={'lg:grid lg:grid-cols-4 my-10 gap-8'}>
Expand All @@ -131,7 +137,9 @@ export default () => {
setOpen={setOpen}
icon={<Icon.Share2 />}
setResource={setResource}
description={'Buy a network port to add to a server. <span className="text-yellow-400">(REQUIRED TO DEPLOY SERVER)</span>'}
description={
'Buy a network port to add to a server. <span className="text-yellow-400">(REQUIRED TO DEPLOY SERVER)</span>'
}
/>
<PurchaseBox
type={'Backups'}
Expand Down Expand Up @@ -182,7 +190,7 @@ export default () => {
</Link>
</div>
</div>
)}
)}
</div>
</PageContentBlock>
);
Expand Down
Loading

0 comments on commit 5f40a47

Please sign in to comment.