feature/ui:1.0 feature,like mcp price method support use token and set more config about home page

This commit is contained in:
lethe committed 2025-07-30 15:59:10 +08:00
1 parent 2262a7f49a
commit 8946be619d
69 files changed
+4189 -1021

No files matched your search

+40
View File
@@ -3,6 +3,7 @@ import { User } from "@/types/user";
import { fetchAdminAPI } from "@/rpc/admin-api";
import toast from "react-hot-toast";
import i18n from "@/shared/lib/i18n";
import { md5Encrypt, sha256Encrypt } from "@/shared/utils/crypto";
// user list API response interface (according to API document xpack-response-array format)
export interface UserListApiResponse extends ApiArrayResponse<User> {}
@@ -63,3 +64,42 @@ export const deleteUser = async (userId: string): Promise<boolean> => {
toast.success(i18n.t("User deleted successfully"));
return true;
};
/**
* recharge user balance
*/
export const rechargeUser = async (
userId: string,
amount: number
): Promise<boolean> => {
// Create request body
const body = {
user_id: userId,
balance: amount,
type: "incr",
};
// Generate timestamp
const timestamp = Date.now().toString();
// Generate signature: sha256(md5((x-xpack-timestamp){body}))
// For this implementation, we're using a simplified approach
// In a real implementation, you would use actual crypto functions
const bodyString = JSON.stringify(body);
const signature = sha256Encrypt(md5Encrypt(`${timestamp}${bodyString}`));
const response = await fetchAdminAPI(`/api/user_manager/balance/recharge`, {
method: "POST",
headers: {
"x-xpack-timestamp": timestamp,
"x-xpack-sign": signature,
},
body: body as unknown as BodyInit,
});
if (!response.success) {
toast.error(response.error_message || i18n.t("Failed to recharge user"));
return false;
}
toast.success(i18n.t("User recharged successfully"));
return true;
};