mirror of
https://github.com/langgenius/dify.git
synced 2026-08-29 03:45:08 +08:00
0024a845f7
Signed-off-by: kenwoodjw <blackxin55+@gmail.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: zxhlyh <jasonapring2015@outlook.com> Co-authored-by: 起岚 <155608604+xiaoyaoqilan@users.noreply.github.com> Co-authored-by: Parman Mohammadalizadeh <prmma23@gmail.com> Co-authored-by: Escape0707 <tothesong@gmail.com> Co-authored-by: Xin Zhang <zhangxin@dify.ai> Co-authored-by: iridescentWen <66297467+iridescentWen@users.noreply.github.com> Co-authored-by: Bond Zhu <37842169+MRZHUH@users.noreply.github.com> Co-authored-by: KVOJJJin <jzongcode@gmail.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: 非法操作 <hjlarry@163.com> Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com> Co-authored-by: Asuka Minato <i@asukaminato.eu.org> Co-authored-by: Chester <superdiao6@gmail.com> Co-authored-by: WH-2099 <wh2099@pm.me> Co-authored-by: Jony <619963502@qq.com> Co-authored-by: Jony <13896935+zyz619963502zyz@users.noreply.github.com> Co-authored-by: Harsh Kashyap <harsh.kashyap2001@gmail.com> Co-authored-by: Harsh Kashyap <Harsh23Kashyap@users.noreply.github.com> Co-authored-by: kenwoodjw <blackxin55+@gmail.com> Co-authored-by: csurong <csurong1@gmail.com> Co-authored-by: caosurong <surong.cao@thinkingdata.cn> Co-authored-by: Taranum Wasu <81034301+Taranum01@users.noreply.github.com> Co-authored-by: Taranum01 <50813317+Taranum01@users.noreply.github.com> Co-authored-by: Pranav Agarwal <agarwalpranav0711@gmail.com> Co-authored-by: Stephen Zhou <hi@hyoban.cc> Co-authored-by: zl86790 <marshal_li_b@163.com> Co-authored-by: QuantumGhost <obelisk.reg+git@gmail.com> Co-authored-by: yunlu.wen <yunlu.wen@dify.ai> Co-authored-by: yyh <yuanyouhuilyz@gmail.com>
60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
"""Inner API for published workspace Skills.
|
|
|
|
These endpoints are called by trusted runtime services. They expose only
|
|
published Skill artifacts, never draft files or editable metadata.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import io
|
|
|
|
from flask import request, send_file
|
|
from flask_restx import Resource
|
|
from pydantic import BaseModel, ValidationError
|
|
from sqlalchemy.orm import Session
|
|
|
|
from controllers.common.session import with_session
|
|
from controllers.console.wraps import setup_required
|
|
from controllers.inner_api import inner_api_ns
|
|
from controllers.inner_api.wraps import plugin_inner_api_only
|
|
from services.skill_management_service import SkillManagementService, SkillManagementServiceError
|
|
|
|
|
|
class _SkillTargetQuery(BaseModel):
|
|
tenant_id: str
|
|
|
|
|
|
def _target_query_from_request() -> _SkillTargetQuery:
|
|
return _SkillTargetQuery.model_validate({"tenant_id": request.args.get("tenant_id")})
|
|
|
|
|
|
def _error_response(exc: SkillManagementServiceError) -> tuple[dict[str, str], int]:
|
|
return {"code": exc.code, "message": exc.message}, exc.status_code
|
|
|
|
|
|
@inner_api_ns.route("/skills/<string:skill_id>/pull")
|
|
class PublishedSkillPullApi(Resource):
|
|
@setup_required
|
|
@plugin_inner_api_only
|
|
@inner_api_ns.doc("published_skill_pull")
|
|
@with_session(write=False)
|
|
def get(self, session: Session, skill_id: str):
|
|
try:
|
|
query = _target_query_from_request()
|
|
result = SkillManagementService(session=session).pull_published_archive(
|
|
tenant_id=query.tenant_id, skill_id=skill_id
|
|
)
|
|
return send_file(
|
|
io.BytesIO(result.payload),
|
|
mimetype=result.mime_type,
|
|
as_attachment=True,
|
|
download_name=result.filename,
|
|
)
|
|
except ValidationError as exc:
|
|
return {"code": "invalid_request", "message": str(exc)}, 400
|
|
except SkillManagementServiceError as exc:
|
|
return _error_response(exc)
|
|
|
|
|
|
__all__ = ["PublishedSkillPullApi"]
|