(callback)
| 929 | } |
| 930 | |
| 931 | function checkIfComplete(callback) { |
| 932 | if (pendingRequests === 0) { |
| 933 | |
| 934 | const additionalInfo = { |
| 935 | timestamp: new Date().toISOString(), |
| 936 | inurl: inurl |
| 937 | |
| 938 | } |
| 939 | if (singleFileDownload) { |
| 940 | showModal('获取完毕,正在生成单个文件...') |
| 941 | |
| 942 | finalData = { |
| 943 | info: additionalInfo, |
| 944 | video: videos |
| 945 | } |
| 946 | if (saveJson) { |
| 947 | zip.file('data.json', JSON.stringify(finalData, null, 4)) |
| 948 | } |
| 949 | if (savetowebdav) { |
| 950 | |
| 951 | WebDAVManager.uploadFile(webdavfold, `${sanitizeFileName(name)}.json`, JSON.stringify(finalData, null, 4)) |
| 952 | } |
| 953 | |
| 954 | const jsonIndexContent = generateJsonIndexContent(finalData) |
| 955 | const numFiles = Object.keys(zip.files).length // 获取压缩包中文件的数量 |
| 956 | |
| 957 | if (numFiles === 0) { |
| 958 | const htmlContent = jsonIndexContent // 替换为实际的HTML内容 |
| 959 | const htmlBlob = new Blob([htmlContent], { type: 'text/html' }) |
| 960 | const htmlUrl = URL.createObjectURL(htmlBlob) |
| 961 | |
| 962 | const a = document.createElement('a') |
| 963 | a.href = htmlUrl |
| 964 | a.download = `${sanitizeFileName(name)}.html` |
| 965 | a.click() |
| 966 | closeModal() |
| 967 | downloadLogFile() |
| 968 | |
| 969 | if (callback) callback() |
| 970 | } else { |
| 971 | zip.file(`${sanitizeFileName(name)}.html`, jsonIndexContent) |
| 972 | |
| 973 | // 生成并下载单个文件 |
| 974 | zip.generateAsync({ type: 'blob' }, function updateCallback(metadata) { |
| 975 | const progress = metadata.percent.toFixed(2) |
| 976 | showModal(`压缩进度: ${progress}%`) |
| 977 | }).then(content => { |
| 978 | const zipUrl = URL.createObjectURL(content) |
| 979 | const a = document.createElement('a') |
| 980 | a.href = zipUrl |
| 981 | a.download = `${name}.zip` |
| 982 | a.click() |
| 983 | URL.revokeObjectURL(zipUrl) |
| 984 | closeModal() |
| 985 | downloadLogFile() |
| 986 | if (callback) callback() |
| 987 | }) |
| 988 | } |
no test coverage detected