MCPcopy Create free account
hub / github.com/ChinaGodMan/UserScripts / uploadFile

Function uploadFile

missav-explorer/missav-explorer.user.js:1798–1832  ·  view source on GitHub ↗
(folderName, fileName, fileContent)

Source from the content-addressed store, hash-verified

1796 // 上传文件到 WebDAV
1797
1798 async function uploadFile(folderName, fileName, fileContent) {
1799 // 检查文件是否已存在
1800 const HEAD = {
1801 method: 'HEAD',
1802 path: folderName + '/' + fileName,
1803 success: () => {
1804 //alert('文件已存在,无需重复上传');
1805 window.addToLog(fileName + '文件存在', 'info')
1806 // 可以在这里执行文件已存在时的逻辑,比如显示提示信息或执行其他操作
1807 },
1808 fail: async (xhr) => {
1809 if (xhr.status === 404) {
1810 // 文件不存在,执行上传操作
1811 const PUT = {
1812 method: 'PUT',
1813 path: folderName + '/' + fileName,
1814 data: fileContent,
1815 success: () => {
1816
1817 window.addToLog(fileName + '文件上传成功', 'info')
1818 },
1819 fail: (xhr) => {
1820 window.addToLog(fileName + '文件上传失败', 'error')
1821 }
1822 }
1823
1824 await GM_xhr({ ...PUT })
1825 } else {
1826 window.addToLog(fileName + '文件检查上传失败', 'error')
1827 }
1828 }
1829 }
1830
1831 await GM_xhr({ ...HEAD })
1832 }
1833
1834 // 重命名文件
1835 async function renameFile(folderName, oldFileName) {

Callers

nothing calls this directly

Calls 1

GM_xhrFunction · 0.85

Tested by

no test coverage detected