forked from MartialBE/one-hub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
32 changed files
with
2,361 additions
and
663 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package cli | ||
|
||
import ( | ||
"encoding/json" | ||
"one-api/common" | ||
"one-api/relay/util" | ||
"os" | ||
"sort" | ||
) | ||
|
||
func ExportPrices() { | ||
prices := util.GetPricesList("default") | ||
|
||
if len(prices) == 0 { | ||
common.SysError("No prices found") | ||
return | ||
} | ||
|
||
// Sort prices by ChannelType | ||
sort.Slice(prices, func(i, j int) bool { | ||
if prices[i].ChannelType == prices[j].ChannelType { | ||
return prices[i].Model < prices[j].Model | ||
} | ||
return prices[i].ChannelType < prices[j].ChannelType | ||
}) | ||
|
||
// 导出到当前目录下的 prices.json 文件 | ||
file, err := os.Create("prices.json") | ||
if err != nil { | ||
common.SysError("Failed to create file: " + err.Error()) | ||
return | ||
} | ||
defer file.Close() | ||
|
||
jsonData, err := json.MarshalIndent(prices, "", " ") | ||
if err != nil { | ||
common.SysError("Failed to encode prices: " + err.Error()) | ||
return | ||
} | ||
|
||
_, err = file.Write(jsonData) | ||
if err != nil { | ||
common.SysError("Failed to write to file: " + err.Error()) | ||
return | ||
} | ||
|
||
common.SysLog("Prices exported to prices.json") | ||
} |
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.