mirror of
https://github.com/langgenius/dify.git
synced 2026-04-25 09:36:40 +08:00
fix(api): simplify parameters in get_signed_file_url_for_plugin function
This commit is contained in:
parent
eed82f7ca7
commit
73e8623f07
@ -420,13 +420,7 @@ class PluginUploadFileRequestApi(Resource):
|
|||||||
)
|
)
|
||||||
def post(self, user_model: Account | EndUser, tenant_model: Tenant, payload: RequestRequestUploadFile):
|
def post(self, user_model: Account | EndUser, tenant_model: Tenant, payload: RequestRequestUploadFile):
|
||||||
# generate signed url
|
# generate signed url
|
||||||
url = get_signed_file_url_for_plugin(
|
url = get_signed_file_url_for_plugin(payload.filename, payload.mimetype, tenant_model.id, user_model.id)
|
||||||
payload.filename,
|
|
||||||
payload.mimetype,
|
|
||||||
tenant_model.id,
|
|
||||||
user_model.id,
|
|
||||||
user_model.session_id if isinstance(user_model, EndUser) else None,
|
|
||||||
)
|
|
||||||
return BaseBackwardsInvocationResponse(data={"url": url}).model_dump()
|
return BaseBackwardsInvocationResponse(data={"url": url}).model_dump()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -25,9 +25,7 @@ def get_signed_file_url(upload_file_id: str, as_attachment=False) -> str:
|
|||||||
return f"{url}?{query_string}"
|
return f"{url}?{query_string}"
|
||||||
|
|
||||||
|
|
||||||
def get_signed_file_url_for_plugin(
|
def get_signed_file_url_for_plugin(filename: str, mimetype: str, tenant_id: str, user_id: str) -> str:
|
||||||
filename: str, mimetype: str, tenant_id: str, user_id: str, session_id: str | None
|
|
||||||
) -> str:
|
|
||||||
# Plugin access should use internal URL for Docker network communication
|
# Plugin access should use internal URL for Docker network communication
|
||||||
base_url = dify_config.INTERNAL_FILES_URL or dify_config.FILES_URL
|
base_url = dify_config.INTERNAL_FILES_URL or dify_config.FILES_URL
|
||||||
url = f"{base_url}/files/upload/for-plugin"
|
url = f"{base_url}/files/upload/for-plugin"
|
||||||
@ -37,9 +35,7 @@ def get_signed_file_url_for_plugin(
|
|||||||
msg = f"upload|{filename}|{mimetype}|{tenant_id}|{user_id}|{timestamp}|{nonce}"
|
msg = f"upload|{filename}|{mimetype}|{tenant_id}|{user_id}|{timestamp}|{nonce}"
|
||||||
sign = hmac.new(key, msg.encode(), hashlib.sha256).digest()
|
sign = hmac.new(key, msg.encode(), hashlib.sha256).digest()
|
||||||
encoded_sign = base64.urlsafe_b64encode(sign).decode()
|
encoded_sign = base64.urlsafe_b64encode(sign).decode()
|
||||||
|
return f"{url}?timestamp={timestamp}&nonce={nonce}&sign={encoded_sign}&user_id={user_id}&tenant_id={tenant_id}"
|
||||||
url_user_id = session_id or user_id
|
|
||||||
return f"{url}?timestamp={timestamp}&nonce={nonce}&sign={encoded_sign}&user_id={url_user_id}&tenant_id={tenant_id}"
|
|
||||||
|
|
||||||
|
|
||||||
def verify_plugin_file_signature(
|
def verify_plugin_file_signature(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user