🐛 修复文件管理共享剪贴板模块语法
This commit is contained in:
1 parent
5db619a1e8
commit
bf68e8dded
2 files changed
+25
-22
No files matched your search
@@ -15,25 +15,13 @@ def rewrite(path: Path, text: str) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def patch_file_manage(path: Path) -> bool:
|
def patch_file_manage(path: Path) -> bool:
|
||||||
text = path.read_text(encoding='utf-8')
|
"""Do not mutate Vite's shared file-management bundle.
|
||||||
old = text
|
|
||||||
if 'detailTimeline:It(s.timeline||[])' in text and 'fcbxTimelineCollapsed' not in text:
|
It imports the clipboard chunk, which is also shared by the upload/download
|
||||||
text = text.replace(
|
service. Structural text replacement in a minified bundle is unsafe and can
|
||||||
'detailTimeline:It(s.timeline||[])}},nt=t=>',
|
invalidate the module graph. Lifecycle presentation is handled by the
|
||||||
'detailTimeline:It(s.timeline||[]),fcbxTimelineCollapsed:!0}},nt=t=>',
|
standalone DOM script below instead.
|
||||||
1,
|
"""
|
||||||
)
|
|
||||||
render_old = 'N(e(b).detailTimeline,(n,K)=>(p(),f("div",{key:`${n.key}-${K}`,class:"grid grid-cols-[auto_minmax(0,1fr)] gap-3"}'
|
|
||||||
render_new = 'N((e(b).fcbxTimelineCollapsed&&e(b).detailTimeline.filter(ga=>ga.key==="retrieved_event").length>3)?e(b).detailTimeline.filter((ga,Qa)=>ga.key!=="retrieved_event"||e(b).detailTimeline.filter(Ja=>Ja.key==="retrieved_event").indexOf(ga)<3):e(b).detailTimeline,(n,K)=>(p(),f("div",{key:`${n.key}-${K}`,class:"grid grid-cols-[auto_minmax(0,1fr)] gap-3"}'
|
|
||||||
if render_old in text and 'ga.key==="retrieved_event"' not in text:
|
|
||||||
text = text.replace(render_old, render_new, 1)
|
|
||||||
close_old = ']))),128))],2)])):j("",!0),l("section",kn,'
|
|
||||||
close_new = ']))),128)),e(b).detailTimeline.filter(n=>n.key==="retrieved_event").length>3?(p(),f("button",{key:0,type:"button",class:o(["mt-3 rounded-lg border px-3 py-2 text-sm font-medium transition",[e(u)?"border-gray-600 text-gray-200 hover:bg-gray-700":"border-gray-200 text-gray-700 hover:bg-gray-50"]]),onClick:m[99]||(m[99]=n=>e(b).fcbxTimelineCollapsed=!e(b).fcbxTimelineCollapsed)},r(e(b).fcbxTimelineCollapsed?`展开全部取件记录(共 ${e(b).detailTimeline.filter(n=>n.key==="retrieved_event").length} 次)":"收起取件记录"),3)):j("",!0)],2)])):j("",!0),l("section",kn,'
|
|
||||||
if close_old in text and '展开全部取件记录' not in text:
|
|
||||||
text = text.replace(close_old, close_new, 1)
|
|
||||||
if text != old:
|
|
||||||
rewrite(path, text)
|
|
||||||
return True
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@@ -49,7 +37,7 @@ def patch_clipboard(path: Path) -> bool:
|
|||||||
if not match:
|
if not match:
|
||||||
return False
|
return False
|
||||||
name = match.group('name')
|
name = match.group('name')
|
||||||
replacement = f'''const {name}=async(a,e={{}})=>{{const{{successMsg:t="复制成功",errorMsg:n="复制失败,请手动复制",showMsg:s=!0,notify:c}}=e,l=(r,d)=>{{s&&c?.(r,d)}},q=()=>{{try{{window.prompt("复制下面内容",a)}}catch{{}}}};try{{if(navigator.clipboard&&window.isSecureContext)try{{await navigator.clipboard.writeText(a);return l(t,"success"),!0}}catch{{}}const r=document.createElement("textarea");r.value=a,r.setAttribute("readonly","");r.className="fcbx-copy-fallback";r.style.cssText="position:fixed;left:0;top:0;width:1px;height:1px;opacity:0;z-index:-1";document.body.appendChild(r);r.focus();r.select();r.setSelectionRange(0,r.value.length);let d=!1;try{{d=document.execCommand("copy")}}finally{{document.body.removeChild(r)}}if(d)return l(t,"success"),!0;q();l("已打开手动复制窗口","warning");return!1}}catch(r){{return console.error("复制失败:",r),q(),l(n,"error"),!1}}}}'''
|
replacement = f'''const {name}=async(a,e={{}})=>{{const{{successMsg:t="复制成功",errorMsg:n="复制失败,请手动复制",showMsg:s=!0,notify:c}}=e,l=(r,d)=>{{s&&c?.(r,d)}},q=()=>{{try{{window.prompt("复制下面内容",a)}}catch{{}}}};try{{if(navigator.clipboard&&window.isSecureContext)try{{await navigator.clipboard.writeText(a);return l(t,"success"),!0}}catch{{}}const r=document.createElement("textarea");r.value=a,r.setAttribute("readonly","");r.className="fcbx-copy-fallback";r.style.cssText="position:fixed;left:0;top:0;width:1px;height:1px;opacity:0;z-index:-1";document.body.appendChild(r);r.focus();r.select();r.setSelectionRange(0,r.value.length);let d=!1;try{{d=document.execCommand("copy")}}finally{{document.body.removeChild(r)}}if(d)return l(t,"success"),!0;q();l("已打开手动复制窗口","warning");return!1}}catch(r){{return console.error("复制失败:",r),q(),l(n,"error"),!1}}}},'''
|
||||||
text = text[:match.start()] + replacement + text[match.end():]
|
text = text[:match.start()] + replacement + text[match.end():]
|
||||||
if text != old:
|
if text != old:
|
||||||
rewrite(path, text)
|
rewrite(path, text)
|
||||||
@@ -169,7 +157,9 @@ def main() -> None:
|
|||||||
if write_detail_collapse_script(theme):
|
if write_detail_collapse_script(theme):
|
||||||
changed.append(str((assets / 'fcb-lifecycle-collapse-v3.js').relative_to(ASSETS_ROOT)))
|
changed.append(str((assets / 'fcb-lifecycle-collapse-v3.js').relative_to(ASSETS_ROOT)))
|
||||||
if not changed:
|
if not changed:
|
||||||
raise SystemExit('admin timeline/clipboard patch markers not found or already patched')
|
# The standalone lifecycle script is idempotently regenerated even when
|
||||||
|
# the clipboard bundle was already patched in a cached build layer.
|
||||||
|
return
|
||||||
print('patched admin assets:', ', '.join(changed))
|
print('patched admin assets:', ', '.join(changed))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from scripts.patch_admin_timeline_ui import build_lifecycle_script
|
from scripts.patch_admin_timeline_ui import build_lifecycle_script, patch_clipboard
|
||||||
|
|
||||||
|
|
||||||
class AdminTimelinePatchTests(unittest.TestCase):
|
class AdminTimelinePatchTests(unittest.TestCase):
|
||||||
@@ -11,6 +13,17 @@ class AdminTimelinePatchTests(unittest.TestCase):
|
|||||||
self.assertIn("展开全部取件记录", script)
|
self.assertIn("展开全部取件记录", script)
|
||||||
self.assertIn("row.style.overflow = 'visible'", script)
|
self.assertIn("row.style.overflow = 'visible'", script)
|
||||||
|
|
||||||
|
def test_clipboard_rewrite_keeps_module_declaration_separator(self):
|
||||||
|
source = '''const m=async(a,e={})=>{try{return!0}catch(r){return!1}},R=async(a,e={})=>{return a};export{m};'''
|
||||||
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
path = Path(temp_dir) / "clipboard-test.js"
|
||||||
|
path.write_text(source, encoding="utf-8")
|
||||||
|
|
||||||
|
self.assertTrue(patch_clipboard(path))
|
||||||
|
patched = path.read_text(encoding="utf-8")
|
||||||
|
|
||||||
|
self.assertIn("}},R=async", patched)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
Reference in new issue
Block a user