diff --git a/src/actions/files.js b/src/actions/files.js index 3795de8b..7b9912f2 100644 --- a/src/actions/files.js +++ b/src/actions/files.js @@ -210,7 +210,7 @@ export function fetchUploadQueue(dongleId) { }; } -export function doUpload(dongleId, fileNames, paths, urls) { +export function doUpload(dongleId, paths, urls) { return async (dispatch, getState) => { const { device } = getState(); let loopedUploads = !deviceVersionAtLeast(device, '0.8.13'); @@ -230,12 +230,13 @@ export function doUpload(dongleId, fileNames, paths, urls) { expiry: Math.floor(Date.now() / 1000) + (86400 * 7), }; const resp = await athenaCall(dongleId, payload, 'action_files_athena_uploads'); + console.log('resp', resp) if (resp && resp.error && resp.error.code === -32000 && resp.error.data.message === 'too many values to unpack (expected 3)') { loopedUploads = true; } else if (!resp || resp.error) { - const newUploading = fileNames.reduce((state, fn) => { - state[fn] = {}; + const newUploading = paths.reduce((state, path) => { + state[pathToFileName(dongleId, path)] = {}; return state; }, {}); dispatch(updateDeviceOnline(dongleId, Math.floor(Date.now() / 1000))); @@ -243,28 +244,52 @@ export function doUpload(dongleId, fileNames, paths, urls) { } else if (resp.offline) { dispatch(updateDeviceOnline(dongleId, 0)); } else if (resp.result === 'Device offline, message queued') { - const newUploading = fileNames.reduce((state, fn) => { - state[fn] = { progress: 0, current: false }; + const newUploading = paths.reduce((state, path) => { + state[pathToFileName(dongleId, path)] = { progress: 0, current: false }; return state; }, {}); dispatch(updateFiles(newUploading)); } else if (resp.result) { if (resp.result.failed) { - const uploading = resp.result.failed - .filter((path) => paths.indexOf(path) > -1) - .reduce((state, path) => { - const fn = fileNames[paths.indexOf(path)]; - state[fn] = { notFound: true }; - return state; - }, {}); - dispatch(updateFiles(uploading)); + + // only if all file names for a segment file type failed + let failedFiltered = []; + for (let f of resp.result.failed) { + console.log('resp failed', f) + let failedCnt = resp.result.failed.filter((p) => pathToFileName(dongleId, p) === pathToFileName(dongleId, f)).length; + let requestedCnt = paths.filter((p) => pathToFileName(dongleId, p) === pathToFileName(dongleId, f)).length; + if (failedCnt >= requestedCnt) { + failedFiltered.push(f); + } + console.log('resp failed_type_cnt', failedCnt, 'requested_type_cnt', requestedCnt) + } + + console.log('resp paths', paths) + console.log('resp failed', resp.result.failed.map((f) => f.split('--').pop())) + // let failed = resp.result.failed.map((f) => pathToFileName(dongleId, f)); + // let requested = new Set(paths.map((f) => pathToFileName(dongleId, f))); + // let diff = failed.filter((f) => requested.has(f)); + // // console.log(['resp custom failed', failed, requested, diff]) + + if (failedFiltered) { + // console.log('resp failed', resp_result_failed, paths) + + const uploading = failedFiltered + .reduce((state, path) => { + const fn = pathToFileName(dongleId, path); + state[fn] = { notFound: true }; + return state; + }, {}); + + dispatch(updateFiles(uploading)); + } } dispatch(fetchUploadQueue(dongleId)); } } if (loopedUploads) { - for (let i = 0; i < fileNames.length; i++) { + for (let i = 0; i < paths.length; i++) { const payload = { id: 0, jsonrpc: '2.0', @@ -276,18 +301,18 @@ export function doUpload(dongleId, fileNames, paths, urls) { const resp = await athenaCall(dongleId, payload, 'files_actions_athena_upload'); if (!resp || resp.error) { const uploading = {}; - uploading[fileNames[i]] = {}; + uploading[pathToFileName(dongleId, paths[i])] = {}; dispatch(updateDeviceOnline(dongleId, Math.floor(Date.now() / 1000))); dispatch(updateFiles(uploading)); } else if (resp.offline) { dispatch(updateDeviceOnline(dongleId, 0)); } else if (resp.result === 'Device offline, message queued') { const uploading = {}; - uploading[fileNames[i]] = { progress: 0, current: false }; + uploading[pathToFileName(dongleId, paths[i])] = { progress: 0, current: false }; dispatch(updateFiles(uploading)); } else if (resp.result === 404 || resp?.result?.failed?.[0] === paths[i]) { const uploading = {}; - uploading[fileNames[i]] = { notFound: true }; + uploading[pathToFileName(dongleId, paths[i])] = { notFound: true }; dispatch(updateFiles(uploading)); } else if (resp.result) { dispatch(fetchUploadQueue(dongleId)); diff --git a/src/components/DriveView/Media.jsx b/src/components/DriveView/Media.jsx index 5a7cb5a5..29550283 100644 --- a/src/components/DriveView/Media.jsx +++ b/src/components/DriveView/Media.jsx @@ -355,7 +355,7 @@ class Media extends Component { console.log('123. fileNames', fileNames) console.log('123. paths', paths) console.log('123. urls', urls) - this.props.dispatch(doUpload(dongleId, fileNames, paths, urls)); + this.props.dispatch(doUpload(dongleId, paths, urls)); } } @@ -403,7 +403,7 @@ class Media extends Component { const urls = await fetchUploadUrls(dongleId, paths); if (urls) { - this.props.dispatch(doUpload(dongleId, Object.keys(uploading), paths, urls)); + this.props.dispatch(doUpload(dongleId, paths, urls)); } } @@ -801,6 +801,7 @@ class Media extends Component { renderUploadMenuItem([file, name, type]) { const { device, classes, files, profile } = this.props; const { windowWidth } = this.state; + console.log('file', file, 'name', name, 'type', type) const canUpload = device.is_owner || (profile && profile.superuser); const uploadButtonWidth = windowWidth < 425 ? 80 : 120;