Skip to content

fix: correct OSS route registration and get_url resolution - #6523

Open
ZH007-s wants to merge 1 commit into
1Panel-dev:v2from
ZH007-s:fix/oss-route-resolution
Open

fix: correct OSS route registration and get_url resolution#6523
ZH007-s wants to merge 1 commit into
1Panel-dev:v2from
ZH007-s:fix/oss-route-resolution

Conversation

@ZH007-s

@ZH007-s ZH007-s commented Jul 28, 2026

Copy link
Copy Markdown

web.py 中同一个 URLConf 被分别挂载到管理端和聊天端:
path(admin_api_prefix, include("oss.urls"))
path(chat_api_prefix, include("oss.urls"))
但 oss.urls 的 app_name 都是 oss。不指定实例命名空间时,Django 会出现重复 URL namespace,之后通过 reverse() 或解析路由时可能指向不确定的 oss 路由。
改成:
include("oss.urls", namespace="admin_oss")
include("oss.urls", namespace="chat_oss")
让管理端和聊天端各自独立。同理,文件检索路由使用 admin_oss_retrieval 和 chat_oss_retrieval。
retrieval_urls.py 里的实际问题在这一条:
re_path(rf'^/oss/get_url/(?P[\w-]+)?$', ...)
有三个缺陷:
子路由被 path('admin/', include(...)) 挂载后,传入的剩余路径是 oss/get_url/...,没有开头 /;原正则要求 /oss,因此通常匹配不到。
捕获参数叫 url,但 GetUrlView 接收的是 application_id,即使匹配也会收到错误的关键字参数。
? 让 ID 可选,不符合获取应用 URL 必须提供 application_id 的接口语义。
修复后:
re_path(r'^oss/get_url/(?P<application_id>[\w-]+)/?$', ...)
现在以下路径都会正确进入 GetUrlView,并把 ID 作为 application_id 传入:
/admin/oss/get_url/<application_id>
/chat/oss/get_url/<application_id>
两处 rf'...' 改为 r'...' 只是清理:正则中没有插值变量,行为没有变化。

@ZH007-s ZH007-s changed the title fix:OSS 路由重复注册和 get_url 无法正确分发的问题,外部 URL 路径本身不变。 fix:OSS 路由重复注册和 get_url 无法正确分发的问题,外部 URL 路径本身不变。 Jul 28, 2026
@ZH007-s ZH007-s changed the title fix:OSS 路由重复注册和 get_url 无法正确分发的问题,外部 URL 路径本身不变。 fix: correct OSS route registration and get_url resolution Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant