fix: Update URL

This commit is contained in:
worry 2025-07-05 15:52:46 +08:00
parent 4513af489c
commit a3dade30ac

View File

@ -1,35 +1,36 @@
import { Recipe } from '../types/index.js';
import { Recipe } from '../types/index.js'
// 远程菜谱JSON文件URL
const RECIPES_URL = 'https://weilei.site/all_recipes.json';
const RECIPES_URL =
'https://cdn.jsdelivr.net/gh/worryzyy/HowToCook@mcp/recipes.json'
// 从远程URL获取数据的异步函数
export async function fetchRecipes(): Promise<Recipe[]> {
try {
// 使用fetch API获取远程数据
const response = await fetch(RECIPES_URL);
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
// 解析JSON数据
const data = await response.json();
return data as Recipe[];
} catch (error) {
console.error('获取远程菜谱数据失败:', error);
// 直接返回空数组,不尝试使用本地备份
return [];
}
try {
// 使用fetch API获取远程数据
const response = await fetch(RECIPES_URL)
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`)
}
// 解析JSON数据
const data = await response.json()
return data as Recipe[]
} catch (error) {
console.error('获取远程菜谱数据失败:', error)
// 直接返回空数组,不尝试使用本地备份
return []
}
}
// 获取所有分类
export function getAllCategories(recipes: Recipe[]): string[] {
const categories = new Set<string>();
recipes.forEach((recipe) => {
if (recipe.category) {
categories.add(recipe.category);
}
});
return Array.from(categories);
}
const categories = new Set<string>()
recipes.forEach((recipe) => {
if (recipe.category) {
categories.add(recipe.category)
}
})
return Array.from(categories)
}