多🌹444收拾收拾计算机视觉手机手机手机手机4大尺寸惆怅长岑长 ??????????????????????????С??????????????P??????????????????????????????????????????????????????^?????????? ????j?????????? ? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!database/migrations/2024_07_29_121039_create_pebblely_table.php 0000644 00000001123 15266620547 0017605 0 ustar 00 id(); $table->integer('user_id'); $table->string('image'); $table->timestamps(); }); } public function down(): void { Schema::dropIfExists('pebblely'); } }; database/migrations/2024_07_25_131428_add_pebblely_key_to_settings_table.php 0000644 00000001064 15266620547 0022367 0 ustar 00 text('pebblely_key')->nullable(); }); } public function down(): void { Schema::table('settings', function (Blueprint $table) {}); } }; extension.json 0000644 00000000227 15266620547 0007471 0 ustar 00 { "name": "Product Photography", "type": "extension", "version": "2.3.0", "description": "Product Photography extension for magicai" } System/Services/PebblelyService.php 0000644 00000005610 15266620547 0013422 0 ustar 00 secretKey = Setting::getCache()->pebblely_key; $this->client = new Client; $this->storage = SettingTwo::getCache()->ai_image_storage; } private function get($url) { $this->apiError(); try { $response = $this->client->get(self::BASE_URL . $url, [ 'headers' => $this->getHeaders(), ])->getBody()->getContents(); return json_decode($response, true); } catch (GuzzleException $e) { return [ 'error' => 'API request failed', 'message' => __('insufficient credit'), ]; } } private function post($url, $params) { $this->apiError(); try { $response = $this->client->post(self::BASE_URL . $url, [ 'headers' => $this->getHeaders(), 'json' => $params, ])->getBody()->getContents(); return json_decode($response, true); } catch (GuzzleException $e) { // Get the response body if available, otherwise set a default message $errorMessage = $e->getResponse() ? $e->getResponse()->getBody()->getContents() : 'No response body available'; $decodedMessage = json_decode($errorMessage, true); $detailMessage = is_array($decodedMessage) && isset($decodedMessage['detail']) ? $decodedMessage['detail'] : 'An unexpected error occurred'; return [ 'error' => 'An unexpected error occurred', 'message' => $detailMessage, ]; } } private function getHeaders(): array { return [ 'X-Pebblely-Access-Token' => $this->secretKey, 'content-type' => 'application/json', ]; } private function apiError() { if (blank($this->secretKey)) { return [ 'error' => 'API key is missing', 'message' => __('insufficient credit'), ]; } } public function query(): Builder { return UserPebblely::query(); } } System/Services/PebblelyTrait.php 0000644 00000005256 15266620547 0013113 0 ustar 00 get(self::THEMES_URL); } public function removeBg($image): array|string { $image = $this->imageControl($image); $body = [ 'image' => $image, ]; $response = $this->post(self::REMOVE_BG_URL, $body); return $this->getResponse($response); } public function createBg($image, string $theme, int $height = 2048, int $width = 2048): array|string { $image = $this->imageControl($image); $body = [ 'images' => [$image], 'theme' => $theme, 'height' => $height, 'width' => $width, ]; $response = $this->post(self::CREATE_BACKGROUND_URL, $body); if (isset($response['error'])) { return [ 'error' => $response['error'], 'message' => $response['message'], ]; } else { $imageBytes = base64_decode($response['data']); $imageName = Str::random(12) . '.png'; Storage::disk($this->storage)->put($imageName, $imageBytes); if ($this->storage == 'public') { return Helper::parseUrl(config('app.url'), 'uploads', $imageName); } else { return Storage::disk($this->storage)->url($imageName); } } } private function imageControl($image): string { $imageContent = ''; if ($image instanceof \Illuminate\Http\UploadedFile) { $imageContent = file_get_contents($image->getRealPath()); } elseif (is_array($image) && isset($image['tmp_name'])) { $imageContent = file_get_contents($image['tmp_name']); } elseif (is_string($image) && is_readable($image)) { $imageContent = file_get_contents($image); } return base64_encode($imageContent); } private function imageSave($response): string { $imageBytes = base64_decode($response['data']); $imageName = Str::random(12) . '.png'; Storage::disk('public')->put($imageName, $imageBytes); return Helper::parseUrl('/uploads', $imageName); } private function getResponse($response): array|string { if (isset($response['error'])) { return [ 'error' => $response['error'], 'message' => $response['message'], ]; } else { return $this->imageSave($response); } } } System/Models/UserPebblely.php 0000644 00000000671 15266620547 0012402 0 ustar 00 belongsTo(User::class, 'user_id', 'id'); } } System/ProductPhotographyServiceProvider.php 0000644 00000005653 15266620547 0015470 0 ustar 00 registerConfig(); } // pebblely public function boot(Kernel $kernel): void { $this->registerTranslations() ->registerViews() ->registerRoutes() ->registerMigrations(); } public function registerConfig(): static { $this->mergeConfigFrom(__DIR__ . '/../config/product-photography.php', 'product-photography'); return $this; } protected function registerTranslations(): static { $this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'product-photography'); return $this; } public function registerViews(): static { $this->loadViewsFrom([__DIR__ . '/../resources/views'], 'product-photography'); return $this; } public function registerMigrations(): static { $this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); return $this; } private function registerRoutes(): static { $this->router() ->group([ 'middleware' => ['web', 'auth'], ], function (Router $router) { $router ->name('dashboard.') ->prefix('dashboard') ->group(function (Router $router) { $router ->name('user.') ->prefix('user') ->group(function (Router $router) { $router->resource('ai-product-shot', ProductPhotographyController::class)->only(['index', 'store']); $router->get('ai-product-shot-delete/{id}', [ProductPhotographyController::class, 'delete'])->name('ai-product-shot.delete'); }); $router ->controller(PebblelySettingController::class) ->prefix('admin/settings') ->name('admin.settings.') ->group(function (Router $router) { $router->get('pebblely', 'index')->name('pebblely'); $router->post('pebblely', 'update')->name('pebblely.update'); }); }); }); return $this; } private function router(): Router|Route { return $this->app['router']; } } System/Http/Controllers/ProductPhotographyController.php 0000644 00000006345 15266620547 0017724 0 ustar 00 UserPebblely::query()->where('user_id', Auth::id())->latest()->first(), 'themes' => $this->service->getThemes(), 'images' => UserPebblely::query()->where('user_id', Auth::id())->latest()->get(), ]); } public function store(ProductPhotographyRequest $request): JsonResponse|RedirectResponse { if (Helper::appIsDemo()) { return redirect()->back()->with([ 'type' => 'error', 'status' => 'error', 'message' => trans('This feature is disabled in demo mode.'), ]); } $request->validated(); $driver = Entity::driver(EntityEnum::PEBBLELY)->inputImageCount(1)->calculateCredit(); try { $driver->redirectIfNoCreditBalance(); } catch (Exception $e) { return redirect()->back()->with([ 'message' => $e->getMessage(), 'type' => 'error', ]); } $removedImage = $this->service->removeBg($request->file('image')); $response = $this->service->createBg($removedImage, $request->get('background')); if (! isset($response['error'])) { UserPebblely::query()->create([ 'user_id' => Auth::id(), 'image' => $response, ]); Usage::getSingle()->updateImageCounts($driver->calculate()); $driver->decreaseCredit(); return redirect()->back()->with([ 'message' => __('Image Created Successfully'), 'type' => 'success', ]); } $errorMsg = str_replace(["\r", "\n"], '', $response['error']); $fullMsg = $errorMsg === 'An unexpected error occurred' ? $errorMsg . ' perhaps UserPebblely API Key empty or invalid' : $errorMsg; return redirect()->back()->with([ 'message' => $fullMsg, 'type' => 'error', ]); } public function delete(string $id): JsonResponse|RedirectResponse { if (Helper::appIsDemo()) { return redirect()->back()->with(['message' => trans('This feature is disabled in demo mode.'), 'type' => 'error']); } $model = UserPebblely::query()->findOrFail($id); $model->delete(); return redirect()->back()->with(['message' => __('Deleted Successfully'), 'type' => 'success']); } } System/Http/Controllers/PebblelySettingController.php 0000644 00000001730 15266620547 0017144 0 ustar 00 validate([ 'pebblely_key' => 'required|string', ]); if (Helper::appIsNotDemo()) { $setting = Setting::getCache(); $setting->update([ 'pebblely_key' => $request->get('pebblely_key'), ]); } return back() ->with([ 'type' => 'success', 'message' => __('Pebblely API key has been updated successfully.'), ]); } } System/Http/Requests/ProductPhotographyRequest.php 0000644 00000000512 15266620547 0016524 0 ustar 00 'required', 'background' => 'required', ]; } } resources/views/setting.blade.php 0000644 00000004236 15266620547 0013171 0 ustar 00 @extends('panel.layout.settings') @section('title', __(\App\Domains\Engine\Enums\EngineEnum::PEBBLELY->label() . ' Settings')) @section('titlebar_actions', '') @section('titlebar_subtitle', __('This API key is used for these features: AI Product Photography')) @section('settings')
@endsection @push('script') @endpush resources/views/index.blade.php 0000644 00000062531 15266620547 0012625 0 ustar 00 @extends('panel.layout.app') @section('title', __('AI Product Photography')) @section('titlebar_subtitle', __('State-of-the-art AI image processing for the creation and enhancement of visual content.')) @section('content')