Skip to content

Commit

Permalink
some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
RuriYS committed Sep 3, 2024
1 parent 4e6ba09 commit f41b67e
Show file tree
Hide file tree
Showing 26 changed files with 373 additions and 219 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php

namespace Pterodactyl\Http\Controllers\Api\Client\Servers\AddonManager;
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;

use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
use Pterodactyl\Repositories\Wings\DaemonFileRepository;
use Illuminate\Support\Facades\Cache;
use Aternos\Taskmaster\Taskmaster;
use Pterodactyl\Models\Server;
use Illuminate\Http\Request;
use ReadAndParseTask;
use Http;
use Yosymfony\Toml\Toml;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;

class AddonController extends ClientApiController
{
Expand All @@ -21,59 +21,17 @@ public function __construct(

public function index(Request $request, Server $server)
{
$results = [];
$serverFileRepo = $this->fileRepository
->setServer($server);

$nest = strtolower($server->nest->name);
$egg = strtolower($server->egg->name);

if ($nest !== 'minecraft') {
return response()->json(['error' => 'Unsupported nest'], 400);
}

$directoryMap = [
$addonDirectory = [
'fabric' => 'mods/',
'spigot' => 'plugins/',
];

$addonDirectory = $directoryMap[$egg] ?? null;

if ($addonDirectory === null) {
return response()->json(['error' => 'Unsupported egg'], 400);
}

$cacheKey = "server_{$server->id}_addons";
$taskmaster = new Taskmaster();
$taskmaster->autoDetectWorkers(8);

$addons = Cache::remember($cacheKey, now()->addMinutes(30), function () use ($serverFileRepo, $addonDirectory, $taskmaster) {
$addons = [];
$tasks = [];
$indexDirectory = $serverFileRepo->getDirectory("$addonDirectory.index/");

foreach ($indexDirectory as $file) {
$filename = $file['name'];
$filePath = "$addonDirectory.index/$filename";

// Create a new task for each file and run them
$task = new ReadAndParseTask($serverFileRepo, $filePath);
$tasks[] = $task;
$taskmaster->runTask($task);
}

$taskmaster->wait();

// Collect results from all tasks
foreach ($tasks as $task) {
$addons[] = $task->getResult();
}

$taskmaster->stop();

return $addons;
});
][strtolower($server->egg->name)] ?? null;

return response()->json($addons);
$indexDirectory = $serverFileRepo->getDirectory("$addonDirectory.index/");
return response()->json($results);
}

public function search(Request $request)
Expand Down

This file was deleted.

45 changes: 45 additions & 0 deletions app/Jobs/ProcessAddonFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Pterodactyl\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Bus\Batchable;
use Illuminate\Support\Facades\Log;
use Pterodactyl\Models\Server;
use Yosymfony\Toml\Toml;
use Pterodactyl\Repositories\Wings\DaemonFileRepository;

class ProcessAddonFile implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, Batchable;

protected $server;
protected $addonDirectory;
protected $filename;

public function __construct(Server $server, $addonDirectory, $filename)
{
$this->server = $server;
$this->addonDirectory = $addonDirectory;
$this->filename = $filename;
}

public function handle(DaemonFileRepository $fileRepository)
{
try {
Log::debug("Processing addon file: {$this->filename}");
$serverFileRepo = $fileRepository->setServer($this->server);
$content = $serverFileRepo->getContent("{$this->addonDirectory}.index/{$this->filename}");
$parsed = Toml::parse($content);
Log::debug("Successfully processed file: {$this->filename}");
return $parsed;
} catch (\Exception $e) {
Log::error('Error processing file: ' . $this->filename . '. Error: ' . $e->getMessage());
throw $e;
}
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"php": "^8.1 || ^8.2",
"ext-json": "*",
"ext-mbstring": "*",
"ext-parallel": "*",
"ext-pdo": "*",
"ext-pdo_mysql": "*",
"ext-posix": "*",
Expand Down
3 changes: 2 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions database/migrations/2024_08_27_083601_create_job_batches_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up()
{
Schema::create('job_batches', function (Blueprint $table) {
$table->string('id')->primary();
$table->string('name');
$table->integer('total_jobs');
$table->integer('pending_jobs');
$table->integer('failed_jobs');
$table->text('failed_job_ids');
$table->mediumText('options')->nullable();
$table->integer('cancelled_at')->nullable();
$table->integer('created_at');
$table->integer('finished_at')->nullable();
});
}

public function down()
{
Schema::dropIfExists('job_batches');
}
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@
"test": "jest",
"lint": "eslint ./resources/scripts/**/*.{ts,tsx} --ext .ts,.tsx",
"watch": "cross-env NODE_ENV=development ./node_modules/.bin/webpack --watch --progress",
"build": "cross-env NODE_ENV=development NODE_OPTIONS=--openssl-legacy-provider ./node_modules/.bin/webpack --progress",
"build:production": "yarn run clean && cross-env NODE_ENV=production NODE_OPTIONS=--openssl-legacy-provider ./node_modules/.bin/webpack --mode production",
"build": "cross-env NODE_ENV=development ./node_modules/.bin/webpack --progress",
"build:production": "yarn run clean && cross-env NODE_ENV=production ./node_modules/.bin/webpack --mode production",
"serve": "yarn run clean && cross-env WEBPACK_PUBLIC_PATH=/webpack@hmr/ NODE_ENV=development webpack-dev-server --host 0.0.0.0 --port 8080 --public https://pterodactyl.test --hot"
},
"browserslist": [
Expand Down
1 change: 1 addition & 0 deletions resources/scripts/assets/css/GlobalStylesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default createGlobalStyle`
/* Scroll Bar Style */
::-webkit-scrollbar {
display: none;
background: none;
width: 16px;
height: 16px;
Expand Down
2 changes: 1 addition & 1 deletion resources/scripts/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const App = () => {
<GlobalStylesheet />
<StoreProvider store={store}>
<ProgressBar />
<div css={tw`mx-auto w-auto`}>
<div css={tw`mx-auto w-auto h-screen`}>
<Router history={history}>
<Switch>
<Route path={'/auth'}>
Expand Down
35 changes: 16 additions & 19 deletions resources/scripts/components/NavigationBar.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from 'react';
import { useState } from 'react';
import { Link, NavLink } from 'react-router-dom';
import { NavLink } from 'react-router-dom';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faCogs, faLayerGroup, faSignOutAlt } from '@fortawesome/free-solid-svg-icons';
import { faBars, faCogs, faLayerGroup, faSignOutAlt } from '@fortawesome/free-solid-svg-icons';
import { useStoreState } from 'easy-peasy';
import { ApplicationStore } from '@/state';
import SearchContainer from '@/components/dashboard/search/SearchContainer';
Expand Down Expand Up @@ -32,34 +32,29 @@ const RightNavigation = styled.div`
}
`;

export default () => {
const name = useStoreState((state: ApplicationStore) => state.settings.data!.name);
interface NavigationBarProps {
sidebarToggle: () => void;
}

const NavigationBar: React.FC<NavigationBarProps> = ({ sidebarToggle }) => {
const rootAdmin = useStoreState((state: ApplicationStore) => state.user.data!.rootAdmin);
const [isLoggingOut, setIsLoggingOut] = useState(false);

const onTriggerLogout = () => {
setIsLoggingOut(true);
http.post('/auth/logout').finally(() => {
// @ts-expect-error this is valid
window.location = '/';
window.location.href = '/';
});
};

return (
<div className={'w-full bg-neutral-900 shadow-md overflow-x-auto'}>
<div className={'w-full bg-neutral-900 shadow-md overflow-auto px-4'}>
<SpinnerOverlay visible={isLoggingOut} />
<div className={'mx-auto w-full flex items-center h-[3.5rem] max-w-[1200px]'}>
<div id={'logo'} className={'flex-1'}>
<Link
to={'/'}
className={
'text-2xl font-header px-4 no-underline text-neutral-200 hover:text-neutral-100 transition-colors duration-150'
}
>
{name}
</Link>
</div>
<RightNavigation className={'flex h-full items-center justify-center'}>
<div className={'mx-auto w-full flex items-center h-16'}>
<button onClick={sidebarToggle} className='p-2'>
<FontAwesomeIcon icon={faBars} />
</button>
<RightNavigation className={'flex flex-1 flex-row h-full items-center justify-end'}>
<SearchContainer />
<Tooltip placement={'bottom'} content={'Dashboard'}>
<NavLink to={'/'} exact>
Expand Down Expand Up @@ -90,3 +85,5 @@ export default () => {
</div>
);
};

export default NavigationBar;
2 changes: 1 addition & 1 deletion resources/scripts/components/elements/ProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default () => {
}, [progress, continuous]);

return (
<div css={tw`w-full fixed`} style={{ height: '2px' }}>
<div css={tw`w-full fixed z-40`} style={{ height: '2px' }}>
<CSSTransition timeout={150} appear in={visible} unmountOnExit classNames={'fade'}>
<BarFill style={{ width: progress === undefined ? '100%' : `${progress}%` }} />
</CSSTransition>
Expand Down
Loading

0 comments on commit f41b67e

Please sign in to comment.