1010use Filament \Notifications \Notification ;
1111use Filament \Panel ;
1212use Filament \Schemas \Components \Section ;
13+ use Illuminate \Support \Facades \Http ;
1314
1415class PasteFoxSharePlugin implements HasPluginSettings, Plugin
1516{
@@ -83,9 +84,61 @@ public function getSettingsForm(): array
8384 ->helperText (trans ('pastefox-share::messages.password_helper ' ))
8485 ->default (fn () => config ('pastefox-share.password ' )),
8586 ]),
87+
88+ Section::make (trans ('pastefox-share::messages.section_custom_domain ' ))
89+ ->description (trans ('pastefox-share::messages.section_custom_domain_description ' ))
90+ ->schema ([
91+ Select::make ('custom_domain ' )
92+ ->label (trans ('pastefox-share::messages.custom_domain ' ))
93+ ->options (fn () => $ this ->getCustomDomainOptions ())
94+ ->disableOptionWhen (fn (string $ value ): bool => str_ends_with ($ value , ':disabled ' ))
95+ ->default (fn () => config ('pastefox-share.custom_domain ' ))
96+ ->helperText (fn () => filled (config ('pastefox-share.api_key ' ))
97+ ? trans ('pastefox-share::messages.custom_domain_helper ' )
98+ : trans ('pastefox-share::messages.custom_domain_no_api_key ' ))
99+ ->disabled (fn () => blank (config ('pastefox-share.api_key ' ))),
100+ ]),
86101 ];
87102 }
88103
104+ protected function getCustomDomainOptions (): array
105+ {
106+ $ options = ['' => trans ('pastefox-share::messages.custom_domain_none ' )];
107+
108+ $ apiKey = config ('pastefox-share.api_key ' );
109+ if (blank ($ apiKey )) {
110+ return $ options ;
111+ }
112+
113+ try {
114+ $ response = Http::withHeaders ([
115+ 'X-API-Key ' => $ apiKey ,
116+ 'Content-Type ' => 'application/json ' ,
117+ ])
118+ ->timeout (10 )
119+ ->get ('https://pastefox.com/api/domains ' )
120+ ->json ();
121+
122+ if ($ response ['success ' ] ?? false ) {
123+ foreach ($ response ['domains ' ] ?? [] as $ domain ) {
124+ if ($ domain ['status ' ] !== 'ACTIVE ' ) {
125+ continue ;
126+ }
127+
128+ if ($ domain ['isActive ' ] ?? false ) {
129+ $ options [$ domain ['domain ' ]] = $ domain ['domain ' ];
130+ } else {
131+ $ options [$ domain ['domain ' ] . ':disabled ' ] = $ domain ['domain ' ] . ' ( ' . trans ('pastefox-share::messages.custom_domain_inactive ' ) . ') ' ;
132+ }
133+ }
134+ }
135+ } catch (\Exception $ e ) {
136+ // Silently fail, just return default options
137+ }
138+
139+ return $ options ;
140+ }
141+
89142 public function saveSettings (array $ data ): void
90143 {
91144 $ this ->writeToEnvironment ([
@@ -94,6 +147,7 @@ public function saveSettings(array $data): void
94147 'PASTEFOX_EFFECT ' => $ data ['effect ' ] ?? 'NONE ' ,
95148 'PASTEFOX_THEME ' => $ data ['theme ' ] ?? 'dark ' ,
96149 'PASTEFOX_PASSWORD ' => $ data ['password ' ] ?? '' ,
150+ 'PASTEFOX_CUSTOM_DOMAIN ' => $ data ['custom_domain ' ] ?? '' ,
97151 ]);
98152
99153 Notification::make ()
0 commit comments