feat: 优化 Skills URL 自动识别

- 新增 /api/fetch-skill-info 接口识别 GitHub skills 仓库
- 解析 skill markdown 的简介、应用场景和包含内容
- Skills 创建页支持一键自动填充标题、简介、来源链接

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jowe
2026-03-25 23:11:34 +08:00
parent f767a8a1b4
commit 3a63bc907e
3 changed files with 563 additions and 56 deletions

51
app.py
View File

@@ -1909,6 +1909,56 @@ def create_app(config_name='default'):
'message': f'抓取失败: {str(e)}'
}), 500
@app.route('/api/fetch-skill-info', methods=['POST'])
@login_required
def fetch_skill_info():
"""抓取 Skill 信息GitHub 仓库)"""
# 只允许管理员访问
if not isinstance(current_user, AdminModel):
return jsonify({'success': False, 'message': '无权访问'}), 403
try:
data = request.get_json()
url = data.get('url', '').strip()
if not url:
return jsonify({
'success': False,
'message': '请提供 GitHub 仓库URL'
}), 400
# 创建抓取器
fetcher = WebsiteFetcher(timeout=15)
# 抓取 Skill 信息
info = fetcher.fetch_skill_info(url)
if not info:
return jsonify({
'success': False,
'message': '无法获取 Skill 信息,请检查 URL 是否为有效的 GitHub 仓库'
})
return jsonify({
'success': True,
'data': {
'name': info.get('name', ''),
'short_desc': info.get('short_desc', ''),
'description': info.get('description', ''),
'github_url': info.get('github_url', ''),
'source_repo': info.get('source_repo', ''),
'source_type': 'github',
'usage': info.get('usage', ''),
'examples': info.get('examples', '')
}
})
except Exception as e:
return jsonify({
'success': False,
'message': f'抓取失败: {str(e)}'
}), 500
@app.route('/api/upload-logo', methods=['POST'])
@login_required
def upload_logo():
@@ -3417,6 +3467,7 @@ Sitemap: {}sitemap.xml
# Skills管理视图
class SkillAdmin(SecureModelView):
create_template = 'admin/skill/create.html'
can_edit = True
can_delete = True
can_create = True