Skip to content

Commit

Permalink
almost works
Browse files Browse the repository at this point in the history
  • Loading branch information
sshane committed Jul 25, 2024
1 parent 6d0e6fe commit 504d8c9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
22 changes: 14 additions & 8 deletions src/actions/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import * as Types from './types';
import { deviceOnCellular, getDeviceFromState, deviceVersionAtLeast, asyncSleep } from '../utils';

export const FILE_NAMES = {
qcameras: 'qcamera.ts',
cameras: 'fcamera.hevc',
dcameras: 'dcamera.hevc',
ecameras: 'ecamera.hevc',
qlogs: 'qlog.bz2',
logs: 'rlog.bz2',
qcameras: ['qcamera.ts'],
cameras: ['fcamera.hevc'],
dcameras: ['dcamera.hevc'],
ecameras: ['ecamera.hevc'],
qlogs: ['qlog.bz2'],
logs: ['rlog.bz2', 'rlog.zst'],
};
const MAX_OPEN_REQUESTS = 15;
const MAX_RETRIES = 5;
Expand All @@ -21,7 +21,8 @@ let openRequests = 0;

function pathToFileName(dongleId, path) {
const [seg, fileType] = path.split('/');
const type = Object.entries(FILE_NAMES).find((e) => e[1] === fileType)[0];
const type = Object.entries(FILE_NAMES).find((e) => e[1].includes(fileType))[0];
console.log('pathToFileName', path, type)
return `${dongleId}|${seg}/${type}`;
}

Expand Down Expand Up @@ -97,6 +98,7 @@ export function fetchFiles(routeName, nocache = false) {
let files;
try {
files = await Raw.getRouteFiles(routeName, nocache);
console.log('files', files)
} catch (err) {
console.error(err);
Sentry.captureException(err, { fingerprint: 'action_files_fetch_files' });
Expand All @@ -117,6 +119,7 @@ export function fetchFiles(routeName, nocache = false) {
};
return state;
}, {});
console.log('urls', urls)

dispatch({
type: Types.ACTION_FILES_URLS,
Expand Down Expand Up @@ -169,7 +172,7 @@ export function fetchUploadQueue(dongleId) {
const segNum = urlParts[urlParts.length - 2];
const datetime = urlParts[urlParts.length - 3];
const dongle = urlParts[urlParts.length - 4];
const type = Object.entries(FILE_NAMES).find((e) => e[1] === filename)[0];
const type = Object.entries(FILE_NAMES).find((e) => e[1].includes(filename))[0];
const fileName = `${dongle}|${datetime}--${segNum}/${type}`;
const waitingWifi = Boolean(deviceOnCellular(device) && uploading.allow_cellular === false);
uploadingFiles[fileName] = {
Expand Down Expand Up @@ -295,6 +298,7 @@ export function doUpload(dongleId, fileNames, paths, urls) {

export function fetchAthenaQueue(dongleId) {
return async (dispatch) => {
console.log('fetchAthenaQueue')
let queue;
try {
queue = await Devices.getAthenaQueue(dongleId);
Expand All @@ -312,10 +316,12 @@ export function fetchAthenaQueue(dongleId) {

if (q.method === 'uploadFileToUrl') {
const fileName = pathToFileName(dongleId, q.params[0]);
console.log('uploadFileToUrl', q.params[0], fileName)
newUploading[fileName] = { progress: 0, current: false };
} else if (q.method === 'uploadFilesToUrls') {
for (const { fn } of q.params.files_data) {
const fileName = pathToFileName(dongleId, fn);
console.log(['uploadFilesToUrls', fn, fileName])
newUploading[fileName] = { progress: 0, current: false };
}
}
Expand Down
34 changes: 22 additions & 12 deletions src/components/DriveView/Media.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,16 +334,19 @@ class Media extends Component {
}));

const routeNoDongleId = currentRoute.fullname.split('|')[1];
const path = `${routeNoDongleId}--${getSegmentNumber(currentRoute)}/${FILE_NAMES[type]}`;
const fileName = `${dongleId}|${routeNoDongleId}--${getSegmentNumber(currentRoute)}/${type}`;

const uploading = {};
uploading[fileName] = { requested: true };
this.props.dispatch(updateFiles(uploading));

const urls = await fetchUploadUrls(dongleId, [path]);
if (urls) {
this.props.dispatch(doUpload(dongleId, [fileName], [path], urls));
// request any possible file names
for (let fn of FILE_NAMES[type]){
const path = `${routeNoDongleId}--${getSegmentNumber(currentRoute)}/${fn}`;
const fileName = `${dongleId}|${routeNoDongleId}--${getSegmentNumber(currentRoute)}/${type}`;

const uploading = {};
uploading[fileName] = { requested: true };
this.props.dispatch(updateFiles(uploading));

const urls = await fetchUploadUrls(dongleId, [path]);

Check failure on line 346 in src/components/DriveView/Media.jsx

View workflow job for this annotation

GitHub Actions / test

Unexpected `await` inside a loop
if (urls) {
this.props.dispatch(doUpload(dongleId, [fileName], [path], urls));
}
}
}

Expand Down Expand Up @@ -376,10 +379,17 @@ class Media extends Component {
}
this.props.dispatch(updateFiles(uploading));

const paths = Object.keys(uploading).map((fileName) => {
// const paths = Object.keys(uploading).map((fileName) => {
// const [seg, type] = fileName.split('/');
// console.log('returning', `${seg.split('|')[1]}/${FILE_NAMES[type]}`)
// return `${seg.split('|')[1]}/${FILE_NAMES[type]}`;
// });

const paths = Object.keys(uploading).flatMap((fileName) => {
const [seg, type] = fileName.split('/');
return `${seg.split('|')[1]}/${FILE_NAMES[type]}`;
return FILE_NAMES[type].map(file => `${seg.split('|')[1]}/${file}`);
});
console.log('paths v2', paths)

const urls = await fetchUploadUrls(dongleId, paths);
if (urls) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Files/UploadQueue.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class UploadQueue extends Component {
</div>
</td>
<td className={ classes.uploadCell } style={ cellStyle }>
{ FILE_NAMES[type].split('.')[0].substring(0, logNameLength) }
{ FILE_NAMES[type][0].split('.')[0].substring(0, logNameLength) }
</td>
{ upload.current
? (
Expand Down

0 comments on commit 504d8c9

Please sign in to comment.