Skip to content

Commit 7ee7698

Browse files
committed
fix get providers API
1 parent a718294 commit 7ee7698

File tree

2 files changed

+80
-2
lines changed

2 files changed

+80
-2
lines changed

internal/server/controllers/provider.go

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,33 @@ func (c *Controller) UpdateProvider(ctx *fiber.Ctx) error {
5757
}
5858

5959
func (c *Controller) GetMultiProviders(ctx *fiber.Ctx) error {
60-
return ctx.JSON(c.config.Providers)
60+
// Combine legacy provider config with new multi-provider config
61+
result := make(map[string]*settings.ProviderConfig)
62+
63+
// First, add all providers from the new multi-provider map
64+
if c.config.Providers != nil {
65+
for name, config := range c.config.Providers {
66+
result[name] = config
67+
}
68+
}
69+
70+
// Then, add the legacy provider if it exists and isn't already in the map
71+
if c.config.Provider != "" {
72+
if _, exists := result[c.config.Provider]; !exists {
73+
result[c.config.Provider] = &settings.ProviderConfig{
74+
Email: c.config.Email,
75+
Password: c.config.Password,
76+
PasswordFile: c.config.PasswordFile,
77+
LoginToken: c.config.LoginToken,
78+
LoginTokenFile: c.config.LoginTokenFile,
79+
AppKey: c.config.AppKey,
80+
AppSecret: c.config.AppSecret,
81+
ConsumerKey: c.config.ConsumerKey,
82+
}
83+
}
84+
}
85+
86+
return ctx.JSON(result)
6187
}
6288

6389
func (c *Controller) UpdateMultiProviders(ctx *fiber.Ctx) error {
@@ -66,6 +92,45 @@ func (c *Controller) UpdateMultiProviders(ctx *fiber.Ctx) error {
6692
return err
6793
}
6894

95+
// If there's a legacy provider configured, check if it's in the input
96+
if c.config.Provider != "" {
97+
if legacyConfig, hasLegacy := providers[c.config.Provider]; hasLegacy {
98+
// Update the legacy top-level fields
99+
c.config.Email = legacyConfig.Email
100+
c.config.Password = legacyConfig.Password
101+
c.config.PasswordFile = legacyConfig.PasswordFile
102+
c.config.LoginToken = legacyConfig.LoginToken
103+
c.config.LoginTokenFile = legacyConfig.LoginTokenFile
104+
c.config.AppKey = legacyConfig.AppKey
105+
c.config.AppSecret = legacyConfig.AppSecret
106+
c.config.ConsumerKey = legacyConfig.ConsumerKey
107+
108+
// Create a new map with only the non-legacy providers
109+
nonLegacyProviders := make(map[string]*settings.ProviderConfig)
110+
for name, config := range providers {
111+
if name != c.config.Provider {
112+
nonLegacyProviders[name] = config
113+
}
114+
}
115+
116+
// Update the providers map with only non-legacy providers
117+
if len(nonLegacyProviders) > 0 {
118+
c.config.Providers = nonLegacyProviders
119+
} else {
120+
// If no other providers, clear the providers map
121+
c.config.Providers = nil
122+
}
123+
124+
if err := c.config.SaveSettings(c.configPath); err != nil {
125+
log.Errorf("Failed to save settings: %s", err.Error())
126+
return ctx.Status(500).SendString("Failed to save settings")
127+
}
128+
129+
return ctx.SendStatus(fiber.StatusOK)
130+
}
131+
}
132+
133+
// No legacy provider match, update the entire providers map
69134
c.config.Providers = providers
70135

71136
if err := c.config.SaveSettings(c.configPath); err != nil {

web/components/multi-provider-control.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,20 @@ export const MultiProviderControl = () => {
180180
if (currentProviderSettings?.consumer_key) config.consumer_key = formData.consumerKey;
181181

182182
if (credentials) {
183-
const success = await add_provider_config(credentials, providerName, config);
183+
let success = false;
184+
185+
if (editingProvider) {
186+
// For editing, update the entire providers map
187+
const updatedProviders = {
188+
...providers,
189+
[providerName]: config
190+
};
191+
success = await update_multi_providers(credentials, updatedProviders);
192+
} else {
193+
// For adding, use add_provider_config
194+
success = await add_provider_config(credentials, providerName, config);
195+
}
196+
184197
if (success) {
185198
setProviders(prev => ({
186199
...prev,

0 commit comments

Comments
 (0)