-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat release: admin model market feature
- Loading branch information
1 parent
b3d4068
commit 6f6d818
Showing
22 changed files
with
293 additions
and
579 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package admin | ||
|
||
var MarketInstance *Market | ||
|
||
func InitInstance() { | ||
MarketInstance = NewMarket() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package admin | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
type ModelTag []string | ||
type MarketModel struct { | ||
Id string `json:"id" mapstructure:"id" required:"true"` | ||
Name string `json:"name" mapstructure:"name" required:"true"` | ||
Description string `json:"description" mapstructure:"description"` | ||
Default bool `json:"default" mapstructure:"default"` | ||
HighContext bool `json:"high_context" mapstructure:"high_context"` | ||
Avatar string `json:"avatar" mapstructure:"avatar"` | ||
Tag ModelTag `json:"tag" mapstructure:"tag"` | ||
} | ||
type MarketModelList []MarketModel | ||
|
||
type Market struct { | ||
Models MarketModelList `json:"models" mapstructure:"models"` | ||
} | ||
|
||
func NewMarket() *Market { | ||
var models MarketModelList | ||
if err := viper.UnmarshalKey("market", &models); err != nil { | ||
fmt.Println(fmt.Sprintf("[market] read config error: %s, use default config", err.Error())) | ||
models = MarketModelList{} | ||
} | ||
|
||
return &Market{ | ||
Models: models, | ||
} | ||
} | ||
|
||
func (m *Market) GetModels() MarketModelList { | ||
return m.Models | ||
} | ||
|
||
func (m *Market) GetModel(id string) *MarketModel { | ||
for _, model := range m.Models { | ||
if model.Id == id { | ||
return &model | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (m *Market) SaveConfig() error { | ||
viper.Set("market", m.Models) | ||
return viper.WriteConfig() | ||
} | ||
|
||
func (m *Market) SetModels(models MarketModelList) error { | ||
m.Models = models | ||
return m.SaveConfig() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import axios from "axios"; | ||
import { Model } from "@/api/types.ts"; | ||
import { ChargeProps } from "@/admin/charge.ts"; | ||
|
||
export async function getApiModels(): Promise<string[]> { | ||
try { | ||
const res = await axios.get("/v1/models"); | ||
return res.data as string[]; | ||
} catch (e) { | ||
console.warn(e); | ||
return []; | ||
} | ||
} | ||
|
||
export async function getApiMarket(): Promise<Model[]> { | ||
try { | ||
const res = await axios.get("/v1/market"); | ||
return res.data as Model[]; | ||
} catch (e) { | ||
console.warn(e); | ||
return []; | ||
} | ||
} | ||
|
||
export async function getApiCharge(): Promise<ChargeProps[]> { | ||
try { | ||
const res = await axios.get("/v1/charge"); | ||
return res.data as ChargeProps[]; | ||
} catch (e) { | ||
console.warn(e); | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ | |
|
||
--gold: 45 100% 50%; | ||
--link: 210 100% 63%; | ||
--error: 20 80% 50%; | ||
} | ||
|
||
.dark { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.