Closed LucaPurcilly closed 7 hours ago
I noticed some old videolecture code also existing in the storage service. Is this being used? if not it should be replaced with the new code you guys have added. The last time the code below was touched was 12 months ago. /**
Otherwise, the code looks good
I noticed some old videolecture code also existing in the storage service. Is this being used? if not it should be replaced with the new code you guys have added. The last time the code below was touched was 12 months ago. /**
- gets videoURL for a Lecture if online, and video in base64 from file if offline
- @param videoName
- @param resolution
- @returns {Promise} */ export const getVideoURL = async (videoName, resolution) => { let videoUrl; if (!resolution){ resolution = '360'; } try { if (isOnline) { videoUrl = api.getVideoStreamUrl(videoName, resolution); } else { throw new Error('No internet connection in getVideoUrl.'); } } catch (error) { // Use locally stored video if they exist and the DB cannot be reached try { videoUrl = await FileSystem.readAsStringAsync(lectureVideoPath + videoName + '.json'); } catch (e){ handleError(e, 'getVideoUrl'); } } finally { return videoUrl; } };
Otherwise, the code looks good
I'm going to leave the code how it is for now, as this seems like something that should be addressed in the streaming PBI, and not here.
Why is your new StoreLectureVideo function and some other store video functionality happening in the same function?
async function storeLectureData(sectionList, course) {
for (let section of sectionList) {
//Stores lecture data
let componentList = await api.getComponents(section._id);
await AsyncStorage.setItem('C' + section._id, JSON.stringify(componentList));
for (let component of componentList) {
if (component.type === 'lecture') {
if (component.component.contentType === 'video') {
await makeDirectory();
await storeLectureVideo(component.component._id + '_l');
}
continue;
}
if (component.component.image) {
//Stores images
try {
let image = await api.getBucketImage(component.component.image);
await AsyncStorage.setItem('I' + component.component._id, JSON.stringify(image));
} catch {
await AsyncStorage.setItem('I' + component.component._id, defaultImage.base64);
}
} else if (component.component.video) {
//Stores videos
await makeDirectory();
await FileSystem.writeAsStringAsync(lectureVideoPath + component.component.video + '.json', await api.getBucketImage(component.component.video));
}
}
//add a new variable "DateOfDownload" to the course object
if (course.dateOfDownload === undefined) {
course.dateOfDownload = new Date().toISOString();
}
}
}
};
Why is your new StoreLectureVideo function and some other store video functionality happening in the same function? async function storeLectureData(sectionList, course) { for (let section of sectionList) { //Stores lecture data let componentList = await api.getComponents(section._id); await AsyncStorage.setItem('C' + section._id, JSON.stringify(componentList)); for (let component of componentList) { if (component.type === 'lecture') { if (component.component.contentType === 'video') { await makeDirectory(); await storeLectureVideo(component.component._id + '_l'); } continue; } if (component.component.image) { //Stores images try { let image = await api.getBucketImage(component.component.image); await AsyncStorage.setItem('I' + component.component._id, JSON.stringify(image)); } catch { await AsyncStorage.setItem('I' + component.component._id, defaultImage.base64); } } else if (component.component.video) { //Stores videos await makeDirectory(); await FileSystem.writeAsStringAsync(lectureVideoPath + component.component.video + '.json', await api.getBucketImage(component.component.video)); } } //add a new variable "DateOfDownload" to the course object if (course.dateOfDownload === undefined) { course.dateOfDownload = new Date().toISOString(); } } }
};
The new store video replaces what I assume the old video logic was supposed to accomplish. But for some reason the "old" video logic is only hit when on exercises and not lectures, so I didn't want to break anything by removing it.
It also uses the "old" lecture model, which I'm pretty sure isn't used anywhere anymore.
I'll delete the code for now, and if anything breaks, we can revert this change.
Note this pbi relies on running transcoding service locally; due to lack of CD for transcoding service this will not work if attempted to usertest when in staging.
Note this pbi relies on running transcoding service locally; due to lack of CD for transcoding service this will not work if attempted to usertest when in staging.
Since this relies on the current version of transcoding service which isn't deployed, I changed the storeLectureVideo() function to no longer throw an error. This means that courses can still be downloaded as before, even if the transcoding service hasn't been updated.
Description
This PR allows users to download videos, so that they can be stored and watched while offline.
The streaming/playing of these videos will be solved in another PR.
Changes
This adds functionality to the storeLecture function in storage service, and will download and store video files as MP4 in the file directory. They can then later be fetched to be watched.
Related Issues
Solves PBI #371
Checklist
Screenshots (if applicable)
N/A
If mobile/frontend pull request, what version of the backend is it stable, and running on?
These changes are reliant on the Staging branch of transcoding service, which currently isn't deployed. This means that to test this, we need to run the backend and transcoding service locally.