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,64 @@ 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+ /**
105+ * @return array<string, string>
106+ */
107+ protected function getCustomDomainOptions (): array
108+ {
109+ $ options = ['' => trans ('pastefox-share::messages.custom_domain_none ' )];
110+
111+ $ apiKey = config ('pastefox-share.api_key ' );
112+ if (blank ($ apiKey )) {
113+ return $ options ;
114+ }
115+
116+ try {
117+ $ response = Http::withHeaders ([
118+ 'X-API-Key ' => $ apiKey ,
119+ 'Content-Type ' => 'application/json ' ,
120+ ])
121+ ->timeout (10 )
122+ ->get ('https://pastefox.com/api/domains ' )
123+ ->json ();
124+
125+ if ($ response ['success ' ] ?? false ) {
126+ foreach ($ response ['domains ' ] ?? [] as $ domain ) {
127+ if ($ domain ['status ' ] !== 'ACTIVE ' ) {
128+ continue ;
129+ }
130+
131+ if ($ domain ['isActive ' ] ?? false ) {
132+ $ options [$ domain ['domain ' ]] = $ domain ['domain ' ];
133+ } else {
134+ $ options [$ domain ['domain ' ] . ':disabled ' ] = $ domain ['domain ' ] . ' ( ' . trans ('pastefox-share::messages.custom_domain_inactive ' ) . ') ' ;
135+ }
136+ }
137+ }
138+ } catch (\Exception $ e ) {
139+ // Silently fail, just return default options
140+ }
141+
142+ return $ options ;
143+ }
144+
89145 public function saveSettings (array $ data ): void
90146 {
91147 $ this ->writeToEnvironment ([
@@ -94,6 +150,7 @@ public function saveSettings(array $data): void
94150 'PASTEFOX_EFFECT ' => $ data ['effect ' ] ?? 'NONE ' ,
95151 'PASTEFOX_THEME ' => $ data ['theme ' ] ?? 'dark ' ,
96152 'PASTEFOX_PASSWORD ' => $ data ['password ' ] ?? '' ,
153+ 'PASTEFOX_CUSTOM_DOMAIN ' => $ data ['custom_domain ' ] ?? '' ,
97154 ]);
98155
99156 Notification::make ()
0 commit comments