0
0
mirror of https://github.com/sp-tarkov/db-website.git synced 2025-02-08 04:30:45 -05:00

api rewrite

- api now uses bun + ElysiaJS
This commit is contained in:
TheSparta 2024-04-07 22:24:02 +01:00
parent d19412a794
commit 7089960cce
78 changed files with 574 additions and 9335 deletions

View File

@ -1,15 +0,0 @@
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
[*.{yml,yaml}]
indent_size = 2

View File

@ -1,19 +1,4 @@
APP_NAME=Lumen GITEA_ITEMS_URL="https://dev.sp-tarkov.com/SPT-AKI/Server/raw/branch/master/project/assets/database/templates/items.json"
APP_ENV=local GITEA_CUSTOMIZATION_URL="https://dev.sp-tarkov.com/SPT-AKI/Server/raw/branch/master/project/assets/database/templates/customization.json"
APP_KEY= GITEA_HANDBOOK_URL="https://dev.sp-tarkov.com/SPT-AKI/Server/raw/branch/master/project/assets/database/templates/handbook.json"
APP_DEBUG=true GITEA_LOCALES_API_URL="https://dev.sp-tarkov.com/api/v1/repos/SPT-AKI/Server/contents/project%2Fassets%2Fdatabase%2Flocales%2Fglobal"
APP_URL=http://localhost
APP_TIMEZONE=UTC
LOG_CHANNEL=stack
LOG_SLACK_WEBHOOK_URL=
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
CACHE_DRIVER=file
QUEUE_CONNECTION=sync

42
api/.gitignore vendored Normal file
View File

@ -0,0 +1,42 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local
# vercel
.vercel
**/*.trace
**/*.zip
**/*.tar.gz
**/*.tgz
**/*.log
package-lock.json
**/*.bun

View File

@ -1,6 +0,0 @@
php:
preset: laravel
disabled:
- unused_use
js: true
css: true

View File

@ -1,13 +0,0 @@
# SP Tarkov items API
## How to install
* Clone the repo
* Make sure you have PHP and composer installed on your PC
* To verify that you have PHP and composer working, try these commands `php -v` and `composer -v`
* Go inside the cloned repo and install the dependencies with this command `composer install`
* If you don't have a local server like Apache or Nginx, you can use PHP to start a server with this command in the root folder of the repo `php -S localhost:8000 -t public`
## How to use
* Check the `routes/web.php` for the available routes and use whatever utility you are confortable with to call the API endpoints, ex: Postman

View File

@ -1,10 +0,0 @@
<?php
namespace App\Config;
final class GiteaConfig {
public const RAW_ITEMS_URL = 'https://dev.sp-tarkov.com/SPT-AKI/Server/raw/branch/master/project/assets/database/templates/items.json';
public const RAW_CUSTOMIZATION_URL = 'https://dev.sp-tarkov.com/SPT-AKI/Server/raw/branch/master/project/assets/database/templates/customization.json';
public const LOCALES_GLOBAL_URL = 'https://dev.sp-tarkov.com/api/v1/repos/SPT-AKI/Server/contents/project%2Fassets%2Fdatabase%2Flocales%2Fglobal';
public const RAW_LOCALES_GLOBAL_BASE_URL = 'https://dev.sp-tarkov.com/SPT-AKI/Server/raw/branch/master/project/assets/database/locales/global/';
}

View File

@ -1,35 +0,0 @@
<?php
namespace App\Console\Commands;
use App\Data\ItemsCollection;
use Illuminate\Console\Command;
class RefreshItemsCache extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $signature = "items:refresh";
/**
* The console command description.
*
* @var string
*/
protected $description = "Refresh all items cache";
/**
* Execute the console command.
*
* @param ItemsCollection $itemsCollection
* @return void
*/
public function handle(ItemsCollection $itemsCollection): void
{
$itemsCollection->refreshAllCache();
}
}

View File

@ -1,30 +0,0 @@
<?php
namespace App\Console;
use App\Console\Commands\RefreshItemsCache;
use Illuminate\Console\Scheduling\Schedule;
use Laravel\Lumen\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
RefreshItemsCache::class,
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
//
}
}

View File

@ -1,238 +0,0 @@
<?php
namespace App\Data;
use App\Exceptions\ItemNotFoundException;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Str;
use App\Config\GiteaConfig;
use Illuminate\Support\Facades\Log;
class ItemsCollection
{
protected Collection $items;
protected Collection $locales;
private string $items_cache_key = 'items';
private string $locales_cache_key = 'locales';
public function __construct()
{
if (!Cache::has($this->items_cache_key)) {
$this->refreshItemsCache();
} else {
$this->items = Cache::get($this->items_cache_key);
}
if (!Cache::has($this->locales_cache_key)) {
$this->refreshLocalesCache();
} else {
$this->locales = Cache::get($this->locales_cache_key);
}
}
/**
* Refeshes the locales for the items and clothing
*
* @return void
*/
public function refreshLocalesCache(): void
{
$this->locales = collect();
$rawLocalesGlobalBaseUrl = GiteaConfig::RAW_LOCALES_GLOBAL_BASE_URL;
$localesList = collect(Http::withOptions(['verify' => false])->get(GiteaConfig::LOCALES_GLOBAL_URL)->json());
foreach ($localesList as $locale)
{
// Extract the json name for the locale
preg_match('/([a-z]{2}(-[a-z]{2})?).json/', $locale['name'], $currentLocaleName, PREG_OFFSET_CAPTURE);
if (empty($currentLocaleName) || !$currentLocaleName[1][0]) continue;
$trimmedCurrentLocaleName = trim($currentLocaleName[1][0]);
$currentLocaleJson = Http::withOptions(['verify' => false])->get($rawLocalesGlobalBaseUrl . $trimmedCurrentLocaleName . ".json")->json();
$templates = [];
foreach ($this->items as $item) {
if ($item['_type'] === 'Node' || !property_exists((object) $currentLocaleJson, $item['_id'].' Name')) continue;
$array = [
"Name" => $currentLocaleJson[$item['_id'].' Name'],
"ShortName" => $currentLocaleJson[$item['_id'].' ShortName'],
"Description" => $currentLocaleJson[$item['_id'].' Description']
];
//var_dump($item);die;
$templates[$item['_id']] = $array;
}
$this->locales = $this->locales->merge(collect([$trimmedCurrentLocaleName => $templates]));
}
Cache::put($this->locales_cache_key, $this->locales);
}
/**
* Refreshes the items of the DB
*
* @return void
*/
public function refreshItemsCache(): void
{
$this->items = collect(Http::withOptions(['verify' => false])->get(GiteaConfig::RAW_ITEMS_URL)->json());
$this->items = $this->items->merge(collect(Http::withOptions(['verify' => false])
->get(GiteaConfig::RAW_CUSTOMIZATION_URL)->json()));
Cache::put($this->items_cache_key, $this->items);
}
/**
* @return Collection
*/
public function getLocales(): Collection
{
return $this->locales->keys();
}
/**
* @return void
*/
public function refreshAllCache(): void
{
$this->refreshItemsCache();
$this->refreshLocalesCache();
}
/**
* Checks if the query is in the key
* @param string $key
* @param string $query
* @return bool
*/
private function contains(string $key, string $query): bool
{
$key = Str::lower(trim($key));
$query = Str::lower(trim($query));
return Str::contains($key, $query);
}
/**
* @param string $query the content of the query eg. 'AK'
* @param string $locale the chosen local. Default to 'en'
* @return Collection
*/
public function findItem(string $query, string $locale): Collection
{
return $this->items->filter(function ($val, $key) use ($query, $locale) {
return $this->contains($val['_id'], $query)
|| $this->contains($val['_name'], $query)
|| $this->contains($val['_parent'], $query)
|| (($this->locales[$locale][$key] ?? false)
&& ($this->contains($this->locales[$locale][$key]['Name'], $query) || $this->contains($this->locales[$locale][$key]['ShortName'], $query))
);
})->map(function ($item) use ($locale) {
return [
'item' => [
'_id' => $item['_id'],
'_name' => $item['_name'],
],
'locale' => $this->locales[$locale][$item['_id']] ?? ''
];
})->values();
}
/**
* @param string $id the item ID to look for
* @param string $locale the chosen local. Default to 'en'
* @return array
* @throws ItemNotFoundException
*/
public function getItemById(string $id, string $locale): array
{
$item = $this->items[$id] ?? throw new ItemNotFoundException('Item not found');
return [
'item' => $item,
'locale' => $this->locales[$locale][$id] ?? ''
];
}
public function getHierarchy(string $id, string $locale = 'en'): Collection {
// Return 404 if the item does not exist
$itemData = $this->items[$id] ?? throw new ItemNotFoundException('Item not found');
// Initialize the hierarchy with the current item
$item = [
'item'=> [
'_id' => $itemData['_id'],
'_name' => $itemData['_name'],
'_parent' => $itemData['_parent']
],
'locale' => $this->locales[$locale][$id] ?? ''
];
$hierarchy = collect([$id => $item]);
// Check the whole hierarchy and merge into the return variable
while (!empty($item['item']['_parent'] ?? '')) {
$itemtId = $item['item']['_parent'];
$itemData = $this->items[$itemtId] ?? null;
$item = [
'item'=> [
'_id' => $itemData['_id'],
'_name' => $itemData['_name'],
'_parent' => $itemData['_parent']
],
'locale' => $this->locales[$locale][$itemtId] ?? ''
];
$hierarchy = $hierarchy->merge([$itemtId => $item]);
}
return $hierarchy;
}
public function getItemLocale(string $locale, string $itemID): array {
return $this->locales[$locale][$itemID] ?? [];
}
/**
* @param string $locale the chosen local. Default to 'en'
* @return array
* @throws ItemNotFoundException
*/
public function getAllItemsName(string $locale): Collection
{
return $this->items->map(function ($item) use ($locale) {
return [
'item' => [
'_id' => $item['_id'],
],
'locale' => collect($this->getItemLocale($locale, $item['_id']))->only(['Name', 'ShortName'])
];
})->filter(function ($item) {
return json_encode($item['locale']) != '[]';
})->values();
}
/**
* @param string $id the item ID to look for
* @param string $locale the chosen local. Default to 'en'
* @return array
* @throws ItemNotFoundException
*/
public function getItemNameById(string $id, string $locale): array
{
$itemLocale = $this->locales[$locale][$id] ?? '';
if ($itemLocale == '') {
return $itemLocale;
}
return [
'locale' => collect($itemLocale)->only(['Name', 'ShortName'])
];
}
}

View File

@ -1,10 +0,0 @@
<?php
namespace App\Events;
use Illuminate\Queue\SerializesModels;
abstract class Event
{
use SerializesModels;
}

View File

@ -1,16 +0,0 @@
<?php
namespace App\Events;
class ExampleEvent extends Event
{
/**
* Create a new event instance.
*
* @return void
*/
public function __construct()
{
//
}
}

View File

@ -1,58 +0,0 @@
<?php
namespace App\Exceptions;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Validation\ValidationException;
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Throwable;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that should not be reported.
*
* @var array
*/
protected $dontReport = [
AuthorizationException::class,
HttpException::class,
ModelNotFoundException::class,
ValidationException::class,
];
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Throwable $exception
* @return void
*
* @throws \Exception
*/
public function report(Throwable $exception)
{
parent::report($exception);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Throwable $exception
* @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse
*
* @throws \Throwable
*/
public function render($request, Throwable $exception)
{
if ($exception instanceof NotFoundHttpException) {
return redirect('/search');
}
return parent::render($request, $exception);
}
}

View File

@ -1,10 +0,0 @@
<?php
namespace App\Exceptions;
use Exception;
class ItemNotFoundException extends Exception
{
}

View File

@ -1,10 +0,0 @@
<?php
namespace App\Http\Controllers;
use Laravel\Lumen\Routing\Controller as BaseController;
class Controller extends BaseController
{
}

View File

@ -1,162 +0,0 @@
<?php
namespace App\Http\Controllers;
use App\Data\ItemsCollection;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Log;
use Throwable;
class ItemController extends Controller
{
/**
* @var ItemsCollection
*/
private ItemsCollection $itemsCollection;
public function __construct(ItemsCollection $itemsCollection)
{
$this->itemsCollection = $itemsCollection;
}
/**
* @param Request $request
* @return JsonResponse
*/
public function search(Request $request): JsonResponse
{
$status = Response::HTTP_NO_CONTENT;
$result = $this->itemsCollection->findItem($request->input('query'), $request->input('locale') ?? 'en');
$response = [];
if ($result->isNotEmpty()) {
$status = Response::HTTP_OK;
$response = [
'items' => $result->toArray(),
];
}
return response()->json($response, $status);
}
/**
* @param Request $request
* @return JsonResponse
*/
public function getItem(Request $request): JsonResponse
{
try {
return response()->json(
$this->itemsCollection->getItemById(
$request->query('id', ''), $request->query('locale', 'en')
)
);
} catch (Throwable $exception) {
Log::error($exception->getMessage());
Log::error($exception->getTraceAsString());
return response()->json([
'error' => 'Item not found.',
], Response::HTTP_NOT_FOUND);
}
}
// $router->get('item/list', 'ItemController@getAllItems');
// $router->get('item/nameByID', 'ItemController@getItemNameByID');
/**
* @param Request $request
* @return JsonResponse
*/
public function getAllItemsName(Request $request): JsonResponse
{
try {
return response()->json(
$this->itemsCollection->getAllItemsName($request->query('locale', 'en'))
);
} catch (Throwable $exception) {
Log::error($exception->getMessage());
Log::error($exception->getTraceAsString());
return response()->json([
'error' => 'Error during items collection.',
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
/**
* @param Request $request
* @return JsonResponse
*/
public function getItemNameByID(Request $request): JsonResponse
{
try {
return response()->json(
$this->itemsCollection->getItemNameById(
$request->query('id', ''), $request->query('locale', 'en')
)
);
} catch (Throwable $exception) {
Log::error($exception->getMessage());
Log::error($exception->getTraceAsString());
return response()->json([
'error' => 'Item not found.',
], Response::HTTP_NOT_FOUND);
}
}
/**
* @param Request $request The request
* @return JsonResponse Either {"error":"item not found"} or an object containing
* for each id, an object looking like
* {"item":{"_id":"id","_name":"name","_parent":"parent"}, "locale": {"Description":"description", "Name":"name", "ShortName":"shortName"}}
*/
public function getHierarchy(Request $request): JsonResponse
{
try {
return response()->json(
$this->itemsCollection->getHierarchy(
$request->query('id'), $request->query('locale', 'en')
)
);
} catch (Throwable $exception) {
Log::error($exception->getMessage());
Log::error($exception->getTraceAsString());
return response()->json([
'error' => 'Item not found.',
], Response::HTTP_NOT_FOUND);
}
}
/**
* @return JsonResponse
*/
public function getLocales(): JsonResponse
{
try {
return response()->json($this->itemsCollection->getLocales());
} catch (Throwable $exception) {
Log::error($exception->getMessage());
Log::error($exception->getTraceAsString());
return response()->json([
'error' => 'No locale found.',
], Response::HTTP_NOT_FOUND);
}
}
/**
* @return JsonResponse
*/
public function refreshAllCache(): JsonResponse
{
try {
$this->itemsCollection->refreshAllCache();
return response()->json([], Response::HTTP_NO_CONTENT);
} catch (Throwable $exception) {
Log::error($exception->getMessage());
Log::error($exception->getTraceAsString());
return response()->json([
'error' => 'Internal error',
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
}

View File

@ -1,44 +0,0 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Auth\Factory as Auth;
class Authenticate
{
/**
* The authentication guard factory instance.
*
* @var \Illuminate\Contracts\Auth\Factory
*/
protected $auth;
/**
* Create a new middleware instance.
*
* @param \Illuminate\Contracts\Auth\Factory $auth
* @return void
*/
public function __construct(Auth $auth)
{
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
if ($this->auth->guard($guard)->guest()) {
return response('Unauthorized.', 401);
}
return $next($request);
}
}

View File

@ -1,20 +0,0 @@
<?php
namespace App\Http\Middleware;
use Closure;
class ExampleMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
return $next($request);
}
}

View File

@ -1,26 +0,0 @@
<?php
namespace App\Jobs;
class ExampleJob extends Job
{
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
//
}
}

View File

@ -1,24 +0,0 @@
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
abstract class Job implements ShouldQueue
{
/*
|--------------------------------------------------------------------------
| Queueable Jobs
|--------------------------------------------------------------------------
|
| This job base class provides a central location to place any logic that
| is shared across all of your jobs. The trait included with the class
| provides access to the "queueOn" and "delay" queue helper methods.
|
*/
use InteractsWithQueue, Queueable, SerializesModels;
}

View File

@ -1,31 +0,0 @@
<?php
namespace App\Listeners;
use App\Events\ExampleEvent;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class ExampleListener
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param \App\Events\ExampleEvent $event
* @return void
*/
public function handle(ExampleEvent $event)
{
//
}
}

View File

@ -1,33 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Laravel\Lumen\Auth\Authorizable;
class User extends Model implements AuthenticatableContract, AuthorizableContract
{
use Authenticatable, Authorizable, HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email',
];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [
'password',
];
}

View File

@ -1,28 +0,0 @@
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
}
}

View File

@ -1,39 +0,0 @@
<?php
namespace App\Providers;
use App\Models\User;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Boot the authentication services for the application.
*
* @return void
*/
public function boot()
{
// Here you may define how you wish users to be authenticated for your Lumen
// application. The callback which receives the incoming request instance
// should return either a User instance or null. You're free to obtain
// the User instance via an API token or any other method necessary.
$this->app['auth']->viaRequest('api', function ($request) {
if ($request->input('api_token')) {
return User::where('api_token', $request->input('api_token'))->first();
}
});
}
}

View File

@ -1,19 +0,0 @@
<?php
namespace App\Providers;
use Laravel\Lumen\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
\App\Events\ExampleEvent::class => [
\App\Listeners\ExampleListener::class,
],
];
}

View File

@ -1,35 +0,0 @@
#!/usr/bin/env php
<?php
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput;
/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| First we need to get an application instance. This creates an instance
| of the application / container and bootstraps the application so it
| is ready to receive HTTP / Console requests from the environment.
|
*/
$app = require __DIR__.'/bootstrap/app.php';
/*
|--------------------------------------------------------------------------
| Run The Artisan Application
|--------------------------------------------------------------------------
|
| When we run the console application, the current CLI command will be
| executed in this console and the response sent back to a terminal
| or another output device for the developers. Here goes nothing!
|
*/
$kernel = $app->make(
'Illuminate\Contracts\Console\Kernel'
);
exit($kernel->handle(new ArgvInput, new ConsoleOutput));

View File

@ -1,117 +0,0 @@
<?php
require_once __DIR__.'/../vendor/autoload.php';
(new Laravel\Lumen\Bootstrap\LoadEnvironmentVariables(
dirname(__DIR__)
))->bootstrap();
date_default_timezone_set(env('APP_TIMEZONE', 'UTC'));
/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| Here we will load the environment and create the application instance
| that serves as the central piece of this framework. We'll use this
| application as an "IoC" container and router for this framework.
|
*/
$app = new Laravel\Lumen\Application(
dirname(__DIR__)
);
$app->withFacades();
// $app->withEloquent();
/*
|--------------------------------------------------------------------------
| Register Container Bindings
|--------------------------------------------------------------------------
|
| Now we will register a few bindings in the service container. We will
| register the exception handler and the console kernel. You may add
| your own bindings here if you like or you can make another file.
|
*/
$app->singleton(
Illuminate\Contracts\Debug\ExceptionHandler::class,
App\Exceptions\Handler::class
);
$app->singleton(
Illuminate\Contracts\Console\Kernel::class,
App\Console\Kernel::class
);
/*
|--------------------------------------------------------------------------
| Register Config Files
|--------------------------------------------------------------------------
|
| Now we will register the "app" configuration file. If the file exists in
| your configuration directory it will be loaded; otherwise, we'll load
| the default version. You may register other files below as needed.
|
*/
$app->configure('app');
/*
|--------------------------------------------------------------------------
| Register Middleware
|--------------------------------------------------------------------------
|
| Next, we will register the middleware with the application. These can
| be global middleware that run before and after each request into a
| route or middleware that'll be assigned to some specific routes.
|
*/
$app->middleware([
Fruitcake\Cors\HandleCors::class,
]);
// $app->routeMiddleware([
// 'auth' => App\Http\Middleware\Authenticate::class,
// ]);
/*
|--------------------------------------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
|
| Here we will register all of the application's service providers which
| are used to bind services into the container. Service providers are
| totally optional, so you are not required to uncomment this line.
|
*/
// $app->register(App\Providers\AppServiceProvider::class);
// $app->register(App\Providers\AuthServiceProvider::class);
// $app->register(App\Providers\EventServiceProvider::class);
$app->register(Fruitcake\Cors\CorsServiceProvider::class);
/*
|--------------------------------------------------------------------------
| Load The Application Routes
|--------------------------------------------------------------------------
|
| Next we will include the routes file so that they can all be added to
| the application. This will provide all of the URLs the application
| can respond to, as well as the controllers that may handle them.
|
*/
$app->configure('cors');
$app->router->group([
'namespace' => 'App\Http\Controllers',
], function ($router) {
require __DIR__.'/../routes/web.php';
});
return $app;

BIN
api/bun.lockb Normal file

Binary file not shown.

View File

@ -1,42 +0,0 @@
{
"name": "laravel/lumen",
"description": "The Laravel Lumen Framework.",
"keywords": ["framework", "laravel", "lumen"],
"license": "MIT",
"type": "project",
"require": {
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.3",
"laravel/lumen-framework": "^8.0"
},
"require-dev": {
"deployer/dist": "^6.8",
"fakerphp/faker": "^1.9.1",
"mockery/mockery": "^1.3.1",
"phpunit/phpunit": "^9.3"
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"classmap": [
"tests/"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
]
}
}

7778
api/composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,60 +0,0 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Laravel CORS Options
|--------------------------------------------------------------------------
|
| The allowed_methods and allowed_headers options are case-insensitive.
|
| You don't need to provide both allowed_origins and allowed_origins_patterns.
| If one of the strings passed matches, it is considered a valid origin.
|
| If ['*'] is provided to allowed_methods, allowed_origins or allowed_headers
| all methods / origins / headers are allowed.
|
*/
/*
* You can enable CORS for 1 or multiple paths.
* Example: ['api/*']
*/
'paths' => ['api/*'],
/*
* Matches the request method. `['*']` allows all methods.
*/
'allowed_methods' => ['*'],
/*
* Matches the request origin. `['*']` allows all origins. Wildcards can be used, eg `*.mydomain.com`
*/
'allowed_origins' => ['*'],
/*
* Patterns that can be used with `preg_match` to match the origin.
*/
'allowed_origins_patterns' => [],
/*
* Sets the Access-Control-Allow-Headers response header. `['*']` allows all headers.
*/
'allowed_headers' => ['*'],
/*
* Sets the Access-Control-Expose-Headers response header with these headers.
*/
'exposed_headers' => [],
/*
* Sets the Access-Control-Max-Age response header when > 0.
*/
'max_age' => 0,
/*
* Sets the Access-Control-Allow-Credentials header.
*/
'supports_credentials' => false,
];

View File

@ -1,29 +0,0 @@
<?php
namespace Database\Factories;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
class UserFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = User::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->name,
'email' => $this->faker->unique()->safeEmail,
];
}
}

View File

@ -1,18 +0,0 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
// $this->call('UsersTableSeeder');
}
}

View File

@ -1,75 +0,0 @@
<?php
namespace Deployer;
require 'recipe/laravel.php';
// Project name
set('application', 'SPT-Items-API');
// Project repository
set('repository', 'https://dev.sp-tarkov.com/Rev/spt-items-api.git');
set('shared_dirs', [
'storage/app',
'storage/framework/cache',
'storage/framework/sessions',
'storage/framework/views',
'storage/logs',
]);
// Writable dirs by web server
add('writable_dirs', []);
set('writable_use_sudo', false);
// Hosts
host('spt-server')
->multiplexing(false)
->become('apache')
->set('deploy_path', '/var/www/html');
task('artisan:cache:clear', function () {
run('{{bin/php}} {{release_path}}/artisan cache:clear');
})->desc('Execute artisan cache:clear');
task('deploy:vendors', function () {
run('cd {{release_path}} && /usr/local/bin/composer install --verbose --prefer-dist --no-progress --no-interaction --optimize-autoloader --no-suggest');
})->desc('installing composer packages');
task('artisan:config:cache', function() {})->setPrivate();
task('artisan:down', function() {})->setPrivate();
task('artisan:event:cache', function() {})->setPrivate();
task('artisan:event:clear', function() {})->setPrivate();
task('artisan:horizon:terminate', function() {})->setPrivate();
task('artisan:optimize', function() {})->setPrivate();
task('artisan:optimize:clear', function() {})->setPrivate();
task('artisan:route:cache', function() {})->setPrivate();
task('artisan:storage:link', function() {})->setPrivate();
task('artisan:up', function() {})->setPrivate();
task('artisan:view:cache', function() {})->setPrivate();
task('artisan:view:clear', function() {})->setPrivate();
// custom task
task('items:refresh', function () {
run('cd {{release_path}} && php artisan items:refresh');
});
// Tasks
task('deploy', [
'deploy:info',
'deploy:prepare',
'deploy:lock',
'deploy:release',
'deploy:update_code',
'deploy:shared',
'deploy:vendors',
'deploy:writable',
'artisan:cache:clear',
'items:refresh',
'deploy:symlink',
'deploy:unlock',
'cleanup',
]);
// [Optional] If deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');

25
api/package.json Normal file
View File

@ -0,0 +1,25 @@
{
"name": "api",
"version": "1.0.0",
"module": "src/index.js",
"scripts": {
"start": "bun run src/index.ts",
"dev": "bun run --watch src/index.ts"
},
"dependencies": {
"@elysiajs/cors": "^1.0.2",
"@elysiajs/static": "^1.0.2",
"@elysiajs/swagger": "^1.0.3",
"axios": "^1.6.8",
"elysia": "^1.0.13",
"logestic": "^1.1.1"
},
"devDependencies": {
"@types/bun": "latest"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"author": "SPT",
"license": "MIT"
}

View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Application Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
</php>
</phpunit>

View File

@ -1,21 +0,0 @@
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

View File

@ -1,19 +0,0 @@
{
"files": {
"main.js": "/static/js/main.f3c30fdb.chunk.js",
"main.js.map": "/static/js/main.f3c30fdb.chunk.js.map",
"runtime-main.js": "/static/js/runtime-main.18486819.js",
"runtime-main.js.map": "/static/js/runtime-main.18486819.js.map",
"static/js/2.21456f47.chunk.js": "/static/js/2.21456f47.chunk.js",
"static/js/2.21456f47.chunk.js.map": "/static/js/2.21456f47.chunk.js.map",
"static/js/3.00f77fcf.chunk.js": "/static/js/3.00f77fcf.chunk.js",
"static/js/3.00f77fcf.chunk.js.map": "/static/js/3.00f77fcf.chunk.js.map",
"index.html": "/index.html",
"static/js/2.21456f47.chunk.js.LICENSE.txt": "/static/js/2.21456f47.chunk.js.LICENSE.txt"
},
"entrypoints": [
"static/js/runtime-main.18486819.js",
"static/js/2.21456f47.chunk.js",
"static/js/main.f3c30fdb.chunk.js"
]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

1
api/public/hi.txt Normal file
View File

@ -0,0 +1 @@
asdasd

8
api/public/index.html Normal file
View File

@ -0,0 +1,8 @@
<html>
<head>
</head>
<body>
<p>Hi</p>
</body>
</html>

View File

@ -1,28 +0,0 @@
<?php
/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| First we need to get an application instance. This creates an instance
| of the application / container and bootstraps the application so it
| is ready to receive HTTP / Console requests from the environment.
|
*/
$app = require __DIR__.'/../bootstrap/app.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/
$app->run();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 81 KiB

File diff suppressed because one or more lines are too long

View File

@ -1,84 +0,0 @@
/*
object-assign
(c) Sindre Sorhus
@license MIT
*/
/**
* A better abstraction over CSS.
*
* @copyright Oleg Isonen (Slobodskoi) / Isonen 2014-present
* @website https://github.com/cssinjs/jss
* @license MIT
*/
/**
* React Router v6.0.2
*
* Copyright (c) Remix Software Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/
/** @license MUI v5.0.1
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/** @license React v0.20.2
* scheduler.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/** @license React v16.13.1
* react-is.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/** @license React v17.0.2
* react-dom.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/** @license React v17.0.2
* react-is.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/** @license React v17.0.2
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/** @license React v17.0.2
* react.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

File diff suppressed because one or more lines are too long

View File

@ -1,2 +0,0 @@
(this["webpackJsonpnew-item-finder-website"]=this["webpackJsonpnew-item-finder-website"]||[]).push([[3],{210:function(e,t,n){"use strict";n.r(t),n.d(t,"getCLS",(function(){return p})),n.d(t,"getFCP",(function(){return S})),n.d(t,"getFID",(function(){return F})),n.d(t,"getLCP",(function(){return k})),n.d(t,"getTTFB",(function(){return C}));var i,a,r,o,u=function(e,t){return{name:e,value:void 0===t?-1:t,delta:0,entries:[],id:"v1-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12)}},c=function(e,t){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){if("first-input"===e&&!("PerformanceEventTiming"in self))return;var n=new PerformanceObserver((function(e){return e.getEntries().map(t)}));return n.observe({type:e,buffered:!0}),n}}catch(e){}},f=function(e,t){var n=function n(i){"pagehide"!==i.type&&"hidden"!==document.visibilityState||(e(i),t&&(removeEventListener("visibilitychange",n,!0),removeEventListener("pagehide",n,!0)))};addEventListener("visibilitychange",n,!0),addEventListener("pagehide",n,!0)},s=function(e){addEventListener("pageshow",(function(t){t.persisted&&e(t)}),!0)},m="function"==typeof WeakSet?new WeakSet:new Set,d=function(e,t,n){var i;return function(){t.value>=0&&(n||m.has(t)||"hidden"===document.visibilityState)&&(t.delta=t.value-(i||0),(t.delta||void 0===i)&&(i=t.value,e(t)))}},p=function(e,t){var n,i=u("CLS",0),a=function(e){e.hadRecentInput||(i.value+=e.value,i.entries.push(e),n())},r=c("layout-shift",a);r&&(n=d(e,i,t),f((function(){r.takeRecords().map(a),n()})),s((function(){i=u("CLS",0),n=d(e,i,t)})))},v=-1,l=function(){return"hidden"===document.visibilityState?0:1/0},h=function(){f((function(e){var t=e.timeStamp;v=t}),!0)},g=function(){return v<0&&(v=l(),h(),s((function(){setTimeout((function(){v=l(),h()}),0)}))),{get timeStamp(){return v}}},S=function(e,t){var n,i=g(),a=u("FCP"),r=function(e){"first-contentful-paint"===e.name&&(f&&f.disconnect(),e.startTime<i.timeStamp&&(a.value=e.startTime,a.entries.push(e),m.add(a),n()))},o=performance.getEntriesByName("first-contentful-paint")[0],f=o?null:c("paint",r);(o||f)&&(n=d(e,a,t),o&&r(o),s((function(i){a=u("FCP"),n=d(e,a,t),requestAnimationFrame((function(){requestAnimationFrame((function(){a.value=performance.now()-i.timeStamp,m.add(a),n()}))}))})))},y={passive:!0,capture:!0},w=new Date,E=function(e,t){i||(i=t,a=e,r=new Date,b(removeEventListener),L())},L=function(){if(a>=0&&a<r-w){var e={entryType:"first-input",name:i.type,target:i.target,cancelable:i.cancelable,startTime:i.timeStamp,processingStart:i.timeStamp+a};o.forEach((function(t){t(e)})),o=[]}},T=function(e){if(e.cancelable){var t=(e.timeStamp>1e12?new Date:performance.now())-e.timeStamp;"pointerdown"==e.type?function(e,t){var n=function(){E(e,t),a()},i=function(){a()},a=function(){removeEventListener("pointerup",n,y),removeEventListener("pointercancel",i,y)};addEventListener("pointerup",n,y),addEventListener("pointercancel",i,y)}(t,e):E(t,e)}},b=function(e){["mousedown","keydown","touchstart","pointerdown"].forEach((function(t){return e(t,T,y)}))},F=function(e,t){var n,r=g(),p=u("FID"),v=function(e){e.startTime<r.timeStamp&&(p.value=e.processingStart-e.startTime,p.entries.push(e),m.add(p),n())},l=c("first-input",v);n=d(e,p,t),l&&f((function(){l.takeRecords().map(v),l.disconnect()}),!0),l&&s((function(){var r;p=u("FID"),n=d(e,p,t),o=[],a=-1,i=null,b(addEventListener),r=v,o.push(r),L()}))},k=function(e,t){var n,i=g(),a=u("LCP"),r=function(e){var t=e.startTime;t<i.timeStamp&&(a.value=t,a.entries.push(e)),n()},o=c("largest-contentful-paint",r);if(o){n=d(e,a,t);var p=function(){m.has(a)||(o.takeRecords().map(r),o.disconnect(),m.add(a),n())};["keydown","click"].forEach((function(e){addEventListener(e,p,{once:!0,capture:!0})})),f(p,!0),s((function(i){a=u("LCP"),n=d(e,a,t),requestAnimationFrame((function(){requestAnimationFrame((function(){a.value=performance.now()-i.timeStamp,m.add(a),n()}))}))}))}},C=function(e){var t,n=u("TTFB");t=function(){try{var t=performance.getEntriesByType("navigation")[0]||function(){var e=performance.timing,t={entryType:"navigation",startTime:0};for(var n in e)"navigationStart"!==n&&"toJSON"!==n&&(t[n]=Math.max(e[n]-e.navigationStart,0));return t}();if(n.value=n.delta=t.responseStart,n.value<0)return;n.entries=[t],e(n)}catch(e){}},"complete"===document.readyState?setTimeout(t,0):addEventListener("pageshow",t)}}}]);
//# sourceMappingURL=3.00f77fcf.chunk.js.map

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,2 +0,0 @@
!function(e){function t(t){for(var n,u,a=t[0],c=t[1],f=t[2],s=0,p=[];s<a.length;s++)u=a[s],Object.prototype.hasOwnProperty.call(o,u)&&o[u]&&p.push(o[u][0]),o[u]=0;for(n in c)Object.prototype.hasOwnProperty.call(c,n)&&(e[n]=c[n]);for(l&&l(t);p.length;)p.shift()();return i.push.apply(i,f||[]),r()}function r(){for(var e,t=0;t<i.length;t++){for(var r=i[t],n=!0,a=1;a<r.length;a++){var c=r[a];0!==o[c]&&(n=!1)}n&&(i.splice(t--,1),e=u(u.s=r[0]))}return e}var n={},o={1:0},i=[];function u(t){if(n[t])return n[t].exports;var r=n[t]={i:t,l:!1,exports:{}};return e[t].call(r.exports,r,r.exports,u),r.l=!0,r.exports}u.e=function(e){var t=[],r=o[e];if(0!==r)if(r)t.push(r[2]);else{var n=new Promise((function(t,n){r=o[e]=[t,n]}));t.push(r[2]=n);var i,a=document.createElement("script");a.charset="utf-8",a.timeout=120,u.nc&&a.setAttribute("nonce",u.nc),a.src=function(e){return u.p+"static/js/"+({}[e]||e)+"."+{3:"00f77fcf"}[e]+".chunk.js"}(e);var c=new Error;i=function(t){a.onerror=a.onload=null,clearTimeout(f);var r=o[e];if(0!==r){if(r){var n=t&&("load"===t.type?"missing":t.type),i=t&&t.target&&t.target.src;c.message="Loading chunk "+e+" failed.\n("+n+": "+i+")",c.name="ChunkLoadError",c.type=n,c.request=i,r[1](c)}o[e]=void 0}};var f=setTimeout((function(){i({type:"timeout",target:a})}),12e4);a.onerror=a.onload=i,document.head.appendChild(a)}return Promise.all(t)},u.m=e,u.c=n,u.d=function(e,t,r){u.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},u.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},u.t=function(e,t){if(1&t&&(e=u(e)),8&t)return e;if(4&t&&"object"===typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(u.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)u.d(r,n,function(t){return e[t]}.bind(null,n));return r},u.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return u.d(t,"a",t),t},u.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},u.p="/",u.oe=function(e){throw console.error(e),e};var a=this["webpackJsonpnew-item-finder-website"]=this["webpackJsonpnew-item-finder-website"]||[],c=a.push.bind(a);a.push=t,a=a.slice();for(var f=0;f<a.length;f++)t(a[f]);var l=c;r()}([]);
//# sourceMappingURL=runtime-main.18486819.js.map

File diff suppressed because one or more lines are too long

View File

@ -1,22 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="favicon.ico" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="item finder" />
<link rel="apple-touch-icon" href="/logo_christmas_192.png" />
<link rel="manifest" href="/manifest.json" />
<title>Item Finder</title>
</head>
<body><noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script>!function (e) { function t(t) { for (var n, u, a = t[0], c = t[1], f = t[2], s = 0, p = []; s < a.length; s++)u = a[s], Object.prototype.hasOwnProperty.call(o, u) && o[u] && p.push(o[u][0]), o[u] = 0; for (n in c) Object.prototype.hasOwnProperty.call(c, n) && (e[n] = c[n]); for (l && l(t); p.length;)p.shift()(); return i.push.apply(i, f || []), r() } function r() { for (var e, t = 0; t < i.length; t++) { for (var r = i[t], n = !0, a = 1; a < r.length; a++) { var c = r[a]; 0 !== o[c] && (n = !1) } n && (i.splice(t--, 1), e = u(u.s = r[0])) } return e } var n = {}, o = { 1: 0 }, i = []; function u(t) { if (n[t]) return n[t].exports; var r = n[t] = { i: t, l: !1, exports: {} }; return e[t].call(r.exports, r, r.exports, u), r.l = !0, r.exports } u.e = function (e) { var t = [], r = o[e]; if (0 !== r) if (r) t.push(r[2]); else { var n = new Promise((function (t, n) { r = o[e] = [t, n] })); t.push(r[2] = n); var i, a = document.createElement("script"); a.charset = "utf-8", a.timeout = 120, u.nc && a.setAttribute("nonce", u.nc), a.src = function (e) { return u.p + "static/js/" + ({}[e] || e) + "." + { 3: "ff1076df" }[e] + ".chunk.js" }(e); var c = new Error; i = function (t) { a.onerror = a.onload = null, clearTimeout(f); var r = o[e]; if (0 !== r) { if (r) { var n = t && ("load" === t.type ? "missing" : t.type), i = t && t.target && t.target.src; c.message = "Loading chunk " + e + " failed.\n(" + n + ": " + i + ")", c.name = "ChunkLoadError", c.type = n, c.request = i, r[1](c) } o[e] = void 0 } }; var f = setTimeout((function () { i({ type: "timeout", target: a }) }), 12e4); a.onerror = a.onload = i, document.head.appendChild(a) } return Promise.all(t) }, u.m = e, u.c = n, u.d = function (e, t, r) { u.o(e, t) || Object.defineProperty(e, t, { enumerable: !0, get: r }) }, u.r = function (e) { "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e, Symbol.toStringTag, { value: "Module" }), Object.defineProperty(e, "__esModule", { value: !0 }) }, u.t = function (e, t) { if (1 & t && (e = u(e)), 8 & t) return e; if (4 & t && "object" == typeof e && e && e.__esModule) return e; var r = Object.create(null); if (u.r(r), Object.defineProperty(r, "default", { enumerable: !0, value: e }), 2 & t && "string" != typeof e) for (var n in e) u.d(r, n, function (t) { return e[t] }.bind(null, n)); return r }, u.n = function (e) { var t = e && e.__esModule ? function () { return e.default } : function () { return e }; return u.d(t, "a", t), t }, u.o = function (e, t) { return Object.prototype.hasOwnProperty.call(e, t) }, u.p = "/", u.oe = function (e) { throw console.error(e), e }; var a = this["webpackJsonpnew-item-finder-website"] = this["webpackJsonpnew-item-finder-website"] || [], c = a.push.bind(a); a.push = t, a = a.slice(); for (var f = 0; f < a.length; f++)t(a[f]); var l = c; r() }([])</script>
<script src="/static/js/2.21456f47.chunk.js"></script>
<script src="/static/js/main.f3c30fdb.chunk.js"></script>
</body>
</html>

View File

@ -1,33 +0,0 @@
<?php
/** @var \Laravel\Lumen\Routing\Router $router */
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/
$router->get('/', function () {
return redirect('/search');
});
$router->get('/search[/{id}]', function () {
return view('app');
});
$router->group(['prefix' => 'api'], function () use ($router) {
$router->get('locales', 'ItemController@getLocales');
$router->get('refresh', 'ItemController@refreshAllCache');
$router->post('search', 'ItemController@search');
$router->get('item/hierarchy', 'ItemController@getHierarchy');
$router->get('item/names', 'ItemController@getAllItemsName');
$router->get('item/nameByID', 'ItemController@getItemNameByID');
$router->get('item', 'ItemController@getItem');
});

View File

@ -0,0 +1,144 @@
import { error } from "elysia";
import { CacheService } from "@src/services/CacheService";
export class CacheController {
public static async getLocales() {
return Object.keys(CacheService.getCache("locales"));
}
public static async refreshAllCache(): Promise<void> {
await CacheService.refreshAllCache();
}
public static async searchItem(query: string, localeId: string = "en") {
const items = CacheService.getCache("items");
const locales = CacheService.getCache("locales");
console.log(items, locales);
const searchInput = query.toLowerCase().trim();
const locale = locales[localeId];
return {
items: Object.values(items).filter((item) => {
return (item._id.toLowerCase().includes(searchInput)
|| item._name.toLowerCase().includes(searchInput)
|| item._parent.toLowerCase().includes(searchInput)
|| (locale[item._id] && (locale[item._id]["Name"].toLowerCase().includes(searchInput) || locale[item._id]["ShortName"].toLowerCase().includes(searchInput))));
}).map((item) => {
return {
item: {
_id: item._id,
_name: item._name,
},
locale: locale[item._id] ?? {}
}
})
};
}
public static async getItem(id: string, localeId: string = "en") {
const items = CacheService.getCache("items");
const locales = CacheService.getCache("locales");
const handbook = CacheService.getCache("handbook");
if (!items[id]) {
return error(404, "Item not found");
}
const item = items[id];
const locale = locales[localeId];
return {
item: item,
locale: locale[item._id] ?? {},
handbook: handbook[item._id] ?? {}
};
}
public static async getItemNameById(id: string, localeId: string = "en") {
const items = CacheService.getCache("items");
const locales = CacheService.getCache("locales");
if (!items[id]) {
return error(404, "Item not found");
}
const item = items[id];
const locale = locales[localeId];
if (!locale[item._id]) {
return;
}
return {
locale: {
"Name": locale[item._id]["Name"],
"ShortName": locale[item._id]["ShortName"]
}
};
}
public static async getItemNames(localeId: string = "en") {
const items = CacheService.getCache("items");
const locales = CacheService.getCache("locales");
const handbook = CacheService.getCache("handbook");
const locale = locales[localeId];
return Object.values(items).filter((item) => locale[item._id]).map((item) => {
return {
item: {
_id: item._id
},
locale: {
"Name": locales[localeId][item._id]["Name"],
"ShortName": locales[localeId][item._id]["ShortName"]
},
handbook: handbook[item._id] ?? {}
}
});
}
public static async getItemHierarchy(id: string, localeId: string = "en") {
const items = CacheService.getCache("items");
const locales = CacheService.getCache("locales");
if (!items[id]) {
return;
}
const item = items[id];
const locale = locales[localeId];
let currItem = {
item: {
_id: item._id,
_name: item._name,
_parent: item._parent
},
locale: locale[item._id] ?? {}
};
let hierarchy: Record<string, typeof currItem> = {};
hierarchy[item._id] = currItem;
while (currItem.item._parent) {
const currItemData = items[currItem.item._parent];
currItem = {
item: {
_id: currItemData._id,
_name: currItemData._name,
_parent: currItemData._parent
},
locale: locale[currItemData._id] ?? {}
};
hierarchy[currItemData._id] = currItem;
}
return hierarchy;
}
}

8
api/src/global.d.ts vendored Normal file
View File

@ -0,0 +1,8 @@
declare module "bun" {
interface Env {
GITEA_ITEMS_URL: string;
GITEA_CUSTOMIZATION_URL: string;
GITEA_HANDBOOK_URL: string;
GITEA_LOCALES_API_URL: string;
}
}

27
api/src/index.ts Normal file
View File

@ -0,0 +1,27 @@
import { Elysia } from "elysia";
import { cors } from "@elysiajs/cors";
import { swagger } from "@elysiajs/swagger";
import { staticPlugin } from "@elysiajs/static";
import { Logestic } from "logestic";
import { CacheService } from "@src/services/CacheService";
import { api } from "@src/routes/api";
await CacheService.refreshAllCache();
new Elysia()
.use(swagger({
documentation: {
info: {
title: "SPT-AKI DB API",
version: "1.0.0",
}
}
}))
.use(cors({ allowedHeaders: "Origin, X-Requested-With, Content-Type, Accept" }))
.use(staticPlugin({ prefix: "/", alwaysStatic: true }))
.use(Logestic.preset("fancy"))
.use(api)
.get("*", () => Bun.file("public/index.html"))
.listen(3000, (server) => {
console.log(`Server is running at ${server.hostname}:${server.port}`);
});

View File

@ -0,0 +1,26 @@
import { IGiteaHandbook } from "@src/interfaces/IGiteaHandbook";
import { IGiteaItem } from "@src/interfaces/IGiteaItem";
export type IItemCache = Record<string, IGiteaItem>;
export interface ILocale {
"Name": string,
"ShortName": string,
"Description": string
}
export type ILocaleCache = Record<string, ILocale>;
export type ILocalesCache = Record<string, ILocaleCache>;
export type IHandbookCache = Record<string, Omit<IGiteaHandbook, "Id">>;
export interface ICache {
items: IItemCache;
locales: ILocalesCache;
handbook: IHandbookCache;
}
export type CacheKeys = keyof ICache;
export type CacheValues = ICache[CacheKeys];

View File

@ -0,0 +1,21 @@
export interface IGiteaContentsResponse {
name: string;
path: string;
sha: string;
last_commit_sha: string;
type: string;
size: number;
encoding: string | null;
content: string | null;
target: string | null;
url: string;
html_url: string;
git_url: string;
download_url: string;
submodule_git_url: string | null;
_links: {
self: string;
git: string;
html: string;
}
}

View File

@ -0,0 +1,5 @@
export interface IGiteaHandbook {
Id: string;
ParentId: string;
Price: number;
}

View File

@ -0,0 +1,8 @@
export interface IGiteaItem {
_id: string;
_name: string;
_parent: string;
_type: string;
_props: any;
_proto?: string;
}

View File

@ -0,0 +1 @@
export type IGiteaLocale = Record<string, string>;

View File

@ -0,0 +1,29 @@
import { Elysia, t } from "elysia";
import { item } from "@src/routes/api/item";
import { CacheService } from "@src/services/CacheService";
import { CacheController } from "@src/controllers/cacheController";
export const api = new Elysia({ prefix: "/api" })
.use(item)
.get("/locales", async () => {
return await CacheController.getLocales();
})
.get("/refresh", async () => {
return await CacheController.refreshAllCache();
})
.post("/search", async ({ body }) => {
return CacheController.searchItem(body["query"], body["locale"]);
}, {
body: t.Object({
query: t.String(),
locale: t.Optional(t.String()),
})
})
.get("/cache/:key", async ({ params: { key } }) => {
return await CacheService.getCache(key);
}, {
params: t.Object({
key: t.Union([ t.Literal("items"), t.Literal("locales"), t.Literal("handbook") ]),
})
});

View File

@ -0,0 +1,36 @@
import { Elysia, t } from "elysia";
import { CacheController } from "@src/controllers/cacheController";
export const item = new Elysia({ prefix: "/item" })
.get("/", async ({ query }) => {
return await CacheController.getItem(query["id"], query["locale"]);
}, {
query: t.Object({
id: t.String(),
locale: t.Optional(t.String())
})
})
.get("/nameByID", async ({ query }) => {
return await CacheController.getItemNameById(query["id"], query["locale"]);
}, {
query: t.Object({
id: t.String(),
locale: t.Optional(t.String())
})
})
.get("/names", async ({ query }) => {
return await CacheController.getItemNames(query["locale"]);
}, {
query: t.Object({
locale: t.Optional(t.String())
})
})
.get("/hierarchy", async ({ query }) => {
return await CacheController.getItemHierarchy(query["id"], query["locale"]);
}, {
query: t.Object({
id: t.String(),
locale: t.Optional(t.String())
})
});

View File

@ -0,0 +1,84 @@
import axios from "axios";
import { ILocalesCache, IHandbookCache, ICache, CacheKeys, CacheValues, ILocaleCache } from "@src/interfaces/ICaches";
import { IGiteaContentsResponse } from "@src/interfaces/IGiteaContentsResponse";
import { IGiteaItem } from "@src/interfaces/IGiteaItem";
import { IGiteaLocale } from "@src/interfaces/IGiteaLocale";
import { IGiteaHandbook } from "@src/interfaces/IGiteaHandbook";
import { promisify } from "util";
export class CacheService {
private static cache: Map<CacheKeys, CacheValues> = new Map();
private static async refreshItemsCache(): Promise<void> {
const items = (await axios.get<Record<string, IGiteaItem>>(Bun.env.GITEA_ITEMS_URL)).data;
const customization = (await axios.get<Record<string, IGiteaItem>>(Bun.env.GITEA_CUSTOMIZATION_URL)).data;
this.setCache("items", {
...items,
...customization
});
}
private static async refreshLocalesCache(): Promise<void> {
let locales: ILocalesCache = {};
const localesList = (await axios.get<IGiteaContentsResponse[]>(Bun.env.GITEA_LOCALES_API_URL)).data;
for (const locale of localesList) {
const localeName = locale.name.split(".json")[0].trim();
if (localeName.length === 0) {
continue;
}
const localeJson = (await axios.get<IGiteaLocale>(locale.download_url)).data;
const templates: ILocaleCache = {};
for (const item of Object.values(this.getCache("items"))) {
if (item._type === "Node" || localeJson[`${item._id} Name`] === undefined) {
continue;
}
templates[item._id] = {
"Name": localeJson[`${item._id} Name`],
"ShortName": localeJson[`${item._id} ShortName`],
"Description": localeJson[`${item._id} Description`]
};
}
locales[localeName] = templates;
}
this.setCache("locales", locales);
}
private static async refreshHandbookCache(): Promise<void> {
let handbook: IHandbookCache = {};
const gitea_handbook = (await axios.get<{ Items: IGiteaHandbook[] }>(Bun.env.GITEA_HANDBOOK_URL)).data;
for (const handbookItem of gitea_handbook.Items) {
handbook[handbookItem.Id] = {
ParentId: handbookItem.ParentId,
Price: handbookItem.Price
};
}
this.setCache("handbook", handbook);
}
public static async refreshAllCache(): Promise<void> {
console.log("[CACHE] Refreshing cache...");
await this.refreshItemsCache();
await this.refreshLocalesCache();
await this.refreshHandbookCache();
console.log("[CACHE] Cache refreshed.");
}
public static getCache<T extends CacheKeys>(key: T): ICache[T] {
return this.cache.get(key) as ICache[T];
}
private static setCache<T extends CacheKeys>(key: T, value: ICache[T]): void {
this.cache.set(key, value);
}
}

View File

@ -1,2 +0,0 @@
*
!.gitignore

View File

@ -1,3 +0,0 @@
*
!data/
!.gitignore

View File

@ -1,2 +0,0 @@
*
!.gitignore

View File

@ -1,2 +0,0 @@
*
!.gitignore

View File

@ -1,2 +0,0 @@
*
!.gitignore

View File

@ -1,21 +0,0 @@
<?php
use Laravel\Lumen\Testing\DatabaseMigrations;
use Laravel\Lumen\Testing\DatabaseTransactions;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testExample()
{
$this->get('/');
$this->assertEquals(
$this->app->version(), $this->response->getContent()
);
}
}

View File

@ -1,16 +0,0 @@
<?php
use Laravel\Lumen\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
/**
* Creates the application.
*
* @return \Laravel\Lumen\Application
*/
public function createApplication()
{
return require __DIR__.'/../bootstrap/app.php';
}
}

105
api/tsconfig.json Normal file
View File

@ -0,0 +1,105 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig to read more about this file */
/* Projects */
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
/* Language and Environment */
"target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
/* Modules */
"module": "ESNext", /* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
"moduleResolution": "Bundler", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
"paths": { /* Specify a set of entries that re-map imports to additional lookup locations. */
"@src/*": ["./src/*"]
},
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
// "resolveJsonModule": true, /* Enable importing .json files. */
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
/* JavaScript Support */
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
/* Emit */
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
// "outDir": "./", /* Specify an output folder for all emitted files. */
// "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
// "newLine": "crlf", /* Set the newline character for emitting files. */
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
/* Type Checking */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
}