fix(web): 媒体库图片添加 JWT token 认证参数
/uploads 路径需要认证,图片 src 须带 ?token= 参数才能正常显示。 MediaLibrary 组件现在从 localStorage 读取 access_token 并附加到图片 URL。
This commit is contained in:
@@ -158,7 +158,11 @@ export default function MediaLibrary() {
|
|||||||
cover={
|
cover={
|
||||||
<div onClick={() => toggleSelect(item.id)} style={{ height: 140, display: 'flex', alignItems: 'center', justifyContent: 'center', background: 'var(--ant-color-fill-quaternary, #f5f5f5)', overflow: 'hidden', position: 'relative', cursor: 'pointer' }}>
|
<div onClick={() => toggleSelect(item.id)} style={{ height: 140, display: 'flex', alignItems: 'center', justifyContent: 'center', background: 'var(--ant-color-fill-quaternary, #f5f5f5)', overflow: 'hidden', position: 'relative', cursor: 'pointer' }}>
|
||||||
{isImage(item.content_type) ? (
|
{isImage(item.content_type) ? (
|
||||||
<img src={(item.thumbnail_path || item.storage_path).replace(/^\.\//, '/')} alt={item.alt_text || item.filename} style={{ width: '100%', height: '100%', objectFit: 'cover' }} />
|
<img src={(() => {
|
||||||
|
const base = (item.thumbnail_path || item.storage_path).replace(/^\.\//, '/');
|
||||||
|
const token = localStorage.getItem('access_token');
|
||||||
|
return token ? `${base}?token=${token}` : base;
|
||||||
|
})()} alt={item.alt_text || item.filename} style={{ width: '100%', height: '100%', objectFit: 'cover' }} />
|
||||||
) : (
|
) : (
|
||||||
<InboxOutlined style={{ fontSize: 36, color: 'var(--ant-color-text-quaternary)' }} />
|
<InboxOutlined style={{ fontSize: 36, color: 'var(--ant-color-text-quaternary)' }} />
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user