(folderName, oldFileName)
| 1833 | |
| 1834 | // 重命名文件 |
| 1835 | async function renameFile(folderName, oldFileName) { |
| 1836 | // 弹出对话框让用户输入新文件名 |
| 1837 | const newFileName = prompt(`请输入 ${oldFileName} 的新文件名:`) |
| 1838 | if (!newFileName) { |
| 1839 | alert('未输入新文件名,操作已取消。') |
| 1840 | return |
| 1841 | } |
| 1842 | const encodedOldFileName = encodeURIComponent(oldFileName) // 对旧文件名进行编码 |
| 1843 | |
| 1844 | const encodedNewFileName = encodeURIComponent(newFileName + '.json') // 对新文件名进行编码 |
| 1845 | const sourcePath = folderName + '/' + encodedOldFileName |
| 1846 | const destinationPath = folderName + '/' + encodedNewFileName |
| 1847 | |
| 1848 | const MOVE = { |
| 1849 | method: 'MOVE', |
| 1850 | path: sourcePath, |
| 1851 | headers: { |
| 1852 | 'Destination': url + destinationPath, |
| 1853 | 'Overwrite': 'T' // 允许覆盖目标文件 |
| 1854 | }, |
| 1855 | success: () => { |
| 1856 | alert(`文件 ${oldFileName} 已成功重命名为 ${newFileName}`) |
| 1857 | listFilesAndFolders(folderName) // 刷新文件列表 |
| 1858 | }, |
| 1859 | fail: (xhr) => { |
| 1860 | if (xhr.status === 409) { |
| 1861 | alert('冲突:文件名可能已存在或路径不正确') |
| 1862 | } else { |
| 1863 | alert('重命名文件失败:' + xhr.status) |
| 1864 | } |
| 1865 | } |
| 1866 | } |
| 1867 | |
| 1868 | await GM_xhr({ ...MOVE }) |
| 1869 | } |
| 1870 | |
| 1871 | // 删除文件 |
| 1872 | async function deleteFile(folderName, fileName) { |
nothing calls this directly
no test coverage detected