Skip to content

Commit

Permalink
remove fileNames from doUpload (buggy with requesting multiple file n…
Browse files Browse the repository at this point in the history
…ames), fix "not found" temporarily
  • Loading branch information
sshane committed Jul 25, 2024
1 parent 7973353 commit fd58103
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 19 deletions.
59 changes: 42 additions & 17 deletions src/actions/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -230,41 +230,66 @@ 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)));
dispatch(updateFiles(newUploading));
} 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',
Expand All @@ -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));
Expand Down
5 changes: 3 additions & 2 deletions src/components/DriveView/Media.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

}
Expand Down Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit fd58103

Please sign in to comment.