mirror of
https://github.com/coaidev/coai.git
synced 2025-05-20 13:30:13 +09:00
chore: sync feat in redeem table
This commit is contained in:
parent
19c09aba62
commit
9f41572b40
@ -29,7 +29,7 @@ func formatResponse(data *DDGResponse) string {
|
|||||||
return strings.Join(res, "\n")
|
return strings.Join(res, "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CallDuckDuckGoAPI(query string) *DDGResponse {
|
func CallDuckDuckGoAPI(query string) (*DDGResponse, error) {
|
||||||
data, err := utils.Get(fmt.Sprintf(
|
data, err := utils.Get(fmt.Sprintf(
|
||||||
"%s/search?q=%s&max_results=%d",
|
"%s/search?q=%s&max_results=%d",
|
||||||
channel.SystemInstance.GetSearchEndpoint(),
|
channel.SystemInstance.GetSearchEndpoint(),
|
||||||
@ -38,8 +38,8 @@ func CallDuckDuckGoAPI(query string) *DDGResponse {
|
|||||||
), nil)
|
), nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return utils.MapToStruct[DDGResponse](data)
|
return utils.MapToRawStruct[DDGResponse](data)
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package web
|
package web
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"chat/globals"
|
||||||
"chat/utils"
|
"chat/utils"
|
||||||
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -22,13 +24,8 @@ func RequestWithUA(url string) string {
|
|||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
func SearchWebResult(q string) string {
|
func SearchReverse(q string) string {
|
||||||
if res := CallDuckDuckGoAPI(q); res != nil {
|
// deprecated
|
||||||
if resp := formatResponse(res); resp != "" {
|
|
||||||
return resp
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uri := GetBingUrl(q)
|
uri := GetBingUrl(q)
|
||||||
if res := CallPilotAPI(uri); res != nil {
|
if res := CallPilotAPI(uri); res != nil {
|
||||||
return utils.Marshal(res.Results)
|
return utils.Marshal(res.Results)
|
||||||
@ -36,3 +33,15 @@ func SearchWebResult(q string) string {
|
|||||||
data := RequestWithUA(uri)
|
data := RequestWithUA(uri)
|
||||||
return ParseBing(data)
|
return ParseBing(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SearchWebResult(q string) string {
|
||||||
|
res, err := CallDuckDuckGoAPI(q)
|
||||||
|
if err != nil {
|
||||||
|
globals.Warn(fmt.Sprintf("[web] failed to get search result: %s (query: %s)", err.Error(), q))
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
content := formatResponse(res)
|
||||||
|
globals.Debug(fmt.Sprintf("[web] search result: %s (query: %s)", utils.Extract(content, 50, "..."), q))
|
||||||
|
return content
|
||||||
|
}
|
||||||
|
@ -27,7 +27,7 @@ import { Textarea } from "@/components/ui/textarea.tsx";
|
|||||||
import { saveAsFile } from "@/utils/dom.ts";
|
import { saveAsFile } from "@/utils/dom.ts";
|
||||||
import { useEffectAsync } from "@/utils/hook.ts";
|
import { useEffectAsync } from "@/utils/hook.ts";
|
||||||
|
|
||||||
function GenerateDialog() {
|
function GenerateDialog({ sync }: { sync: () => void }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const [open, setOpen] = useState<boolean>(false);
|
const [open, setOpen] = useState<boolean>(false);
|
||||||
@ -41,12 +41,15 @@ function GenerateDialog() {
|
|||||||
|
|
||||||
async function generateCode() {
|
async function generateCode() {
|
||||||
const data = await generateRedeem(Number(quota), Number(number));
|
const data = await generateRedeem(Number(quota), Number(number));
|
||||||
if (data.status) setData(data.data.join("\n"));
|
if (data.status) {
|
||||||
else
|
setData(data.data.join("\n"));
|
||||||
|
sync();
|
||||||
|
} else {
|
||||||
toast({
|
toast({
|
||||||
title: t("admin.error"),
|
title: t("admin.error"),
|
||||||
description: data.message,
|
description: data.message,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function close() {
|
function close() {
|
||||||
@ -174,7 +177,7 @@ function RedeemTable() {
|
|||||||
<Button variant={`outline`} size={`icon`} onClick={sync}>
|
<Button variant={`outline`} size={`icon`} onClick={sync}>
|
||||||
<RotateCw className={`h-4 w-4`} />
|
<RotateCw className={`h-4 w-4`} />
|
||||||
</Button>
|
</Button>
|
||||||
<GenerateDialog />
|
<GenerateDialog sync={sync} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -142,7 +142,7 @@ func (c *SystemConfig) GetInitialQuota() float64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *SystemConfig) GetBackend() string {
|
func (c *SystemConfig) GetBackend() string {
|
||||||
return c.General.Backend
|
return strings.TrimSuffix(c.General.Backend, "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *SystemConfig) GetMail() *utils.SmtpPoster {
|
func (c *SystemConfig) GetMail() *utils.SmtpPoster {
|
||||||
@ -209,10 +209,10 @@ func (c *SystemConfig) GetSearchEndpoint() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
endpoint := c.Search.Endpoint
|
endpoint := c.Search.Endpoint
|
||||||
if strings.HasSuffix(endpoint, "/") {
|
if strings.HasSuffix(endpoint, "/search") {
|
||||||
return endpoint[:len(endpoint)-1]
|
|
||||||
} else if !strings.HasSuffix(endpoint, "/search") {
|
|
||||||
return endpoint[:len(endpoint)-7]
|
return endpoint[:len(endpoint)-7]
|
||||||
|
} else if strings.HasSuffix(endpoint, "/") {
|
||||||
|
return endpoint[:len(endpoint)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
return endpoint
|
return endpoint
|
||||||
|
@ -169,7 +169,12 @@ func SplitLangItems(data string) []string {
|
|||||||
return SplitItems(data, []string{",", ",", " ", "\n"})
|
return SplitItems(data, []string{",", ",", " ", "\n"})
|
||||||
}
|
}
|
||||||
|
|
||||||
func Extract(data string, length int, flow string) string {
|
func Extract(data string, length int, flow_ ...string) string {
|
||||||
|
flow := ""
|
||||||
|
if len(flow_) > 0 {
|
||||||
|
flow = flow_[0]
|
||||||
|
}
|
||||||
|
|
||||||
value := []rune(data)
|
value := []rune(data)
|
||||||
if len(value) > length {
|
if len(value) > length {
|
||||||
return string(value[:length]) + flow
|
return string(value[:length]) + flow
|
||||||
|
Loading…
Reference in New Issue
Block a user