2018-03-02 04:48:12 +01:00
|
|
|
/*
|
2018-08-03 04:18:08 +02:00
|
|
|
This file is part of FreeTube.
|
|
|
|
FreeTube is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
FreeTube is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with FreeTube. If not, see <http://www.gnu.org/licenses/>.
|
2018-03-02 04:48:12 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2018-08-03 04:18:08 +02:00
|
|
|
* File used for functions related to video history.
|
|
|
|
*/
|
2018-03-02 04:48:12 +01:00
|
|
|
|
|
|
|
/**
|
2018-08-03 04:18:08 +02:00
|
|
|
* Add a video to the history database file
|
|
|
|
*
|
|
|
|
* @param {string} videoId - The video ID of the video to be saved.
|
|
|
|
*
|
|
|
|
* @return {Void}
|
|
|
|
*/
|
|
|
|
function addToHistory(videoId){
|
|
|
|
const data = {
|
|
|
|
videoId: videoId,
|
|
|
|
timeWatched: new Date().getTime(),
|
|
|
|
};
|
|
|
|
historyDb.insert(data, (err, newDoc) => {});
|
2018-03-02 04:48:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-03 04:18:08 +02:00
|
|
|
* Remove a video from the history database file
|
|
|
|
*
|
|
|
|
* @param {string} videoId - The video ID of the video to be removed.
|
|
|
|
*
|
|
|
|
* @return {Void}
|
|
|
|
*/
|
|
|
|
function removeFromHistory(videoId){
|
|
|
|
const data = {videoId: videoId};
|
|
|
|
historyDb.remove(data, {}, (err, numRemoved) => {});
|
2018-03-02 04:48:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the videos within the history database.
|
|
|
|
*
|
|
|
|
* @return {Void}
|
|
|
|
*/
|
|
|
|
function showHistory(){
|
|
|
|
console.log('checking history');
|
|
|
|
|
2018-09-19 17:01:21 +02:00
|
|
|
historyView.videoList = [];
|
2018-03-02 04:48:12 +01:00
|
|
|
|
2018-08-03 04:18:08 +02:00
|
|
|
historyDb.find({}).sort({
|
|
|
|
timeWatched: -1
|
|
|
|
}).exec((err, docs) => {
|
2018-09-19 17:01:21 +02:00
|
|
|
docs.forEach((video) => {
|
|
|
|
invidiousAPI('videos', video.videoId, {}, (data) => {
|
|
|
|
displayVideo(data, 'history');
|
2018-03-15 15:59:50 +01:00
|
|
|
});
|
2018-03-02 04:48:12 +01:00
|
|
|
});
|
2018-09-19 17:01:21 +02:00
|
|
|
|
|
|
|
loadingView.seen = false;
|
2018-08-03 04:18:08 +02:00
|
|
|
});
|
|
|
|
}
|