f试ssefahahå�¯èƒ½å�¡å�¡å�¡é©¬å�¡å�¡è®¡ç®—机视觉事实上事实上飒飒飒gjâ—�â—�â—�â—�hfkttkgdgkmcuocucocucocé¡¶é¡¶é¡¶é¡¶é¡¶é¡¶é¡¶é¡¶é¡¶é¡¶é¡¶é¡¶uco朵朵å�¯å�¯æ”¾2å·�峨2555555666369🌹 �����ѩ�����һ����dddf2qevf2fv69666 ? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!PK %GW]=¹�S S ? database/migrations/2024_07_29_121039_create_pebblely_table.phpnu „[µü¤ id(); $table->integer('user_id'); $table->string('image'); $table->timestamps(); }); } public function down(): void { Schema::dropIfExists('pebblely'); } }; PK %GW]¯I4 4 L database/migrations/2024_07_25_131428_add_pebblely_key_to_settings_table.phpnu „[µü¤ text('pebblely_key')->nullable(); }); } public function down(): void { Schema::table('settings', function (Blueprint $table) {}); } }; PK %GW]Çáb— — extension.jsonnu „[µü¤ { "name": "Product Photography", "type": "extension", "version": "2.3.0", "description": "Product Photography extension for magicai" } PK %GW]K:ÖMˆ ˆ # System/Services/PebblelyService.phpnu „[µü¤ 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(); } } PK %GW]§¾|œ® ® ! System/Services/PebblelyTrait.phpnu „[µü¤ 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); } } } PK %GW] Ĺ ¹ System/Models/UserPebblely.phpnu „[µü¤ belongsTo(User::class, 'user_id', 'id'); } } PK %GW]9rçH« « , System/ProductPhotographyServiceProvider.phpnu „[µü¤ 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']; } } PK %GW]ä§+Ãå å 8 System/Http/Controllers/ProductPhotographyController.phpnu „[µü¤ 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']); } } PK %GW]|L¿ÝØ Ø 5 System/Http/Controllers/PebblelySettingController.phpnu „[µü¤ 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.'), ]); } } PK %GW] ‹ã3J J 2 System/Http/Requests/ProductPhotographyRequest.phpnu „[µü¤ 'required', 'background' => 'required', ]; } } PK %GW]F²€¥ž ž ! resources/views/setting.blade.phpnu „[µü¤ @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 PK %GW]D§NYe Ye resources/views/index.blade.phpnu „[µü¤ @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')