mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-03 20:21:27 +03:00
Fixed bug where sharing didn't work for some videos
View count now increments on each play unless the video is shared
This commit is contained in:
@@ -2233,6 +2233,27 @@ app.post('/api/disableSharing', optionalJwt, function(req, res) {
|
||||
});
|
||||
});
|
||||
|
||||
app.post('/api/incrementViewCount', optionalJwt, async (req, res) => {
|
||||
let file_uid = req.body.file_uid;
|
||||
let sub_id = req.body.sub_id;
|
||||
let uuid = req.body.uuid;
|
||||
|
||||
if (!uuid && req.isAuthenticated()) {
|
||||
uuid = req.user.uid;
|
||||
}
|
||||
|
||||
const file_obj = await db_api.getVideo(file_uid, uuid, sub_id);
|
||||
|
||||
const current_view_count = file_obj && file_obj['local_view_count'] ? file_obj['local_view_count'] : 0;
|
||||
const new_view_count = current_view_count + 1;
|
||||
|
||||
await db_api.setVideoProperty(file_uid, {local_view_count: new_view_count}, uuid, sub_id);
|
||||
|
||||
res.send({
|
||||
success: true
|
||||
});
|
||||
});
|
||||
|
||||
// categories
|
||||
|
||||
app.post('/api/getAllCategories', optionalJwt, async (req, res) => {
|
||||
@@ -2759,7 +2780,7 @@ app.get('/api/stream/:id', optionalJwt, (req, res) => {
|
||||
var head;
|
||||
let optionalParams = url_api.parse(req.url,true).query;
|
||||
let id = decodeURIComponent(req.params.id);
|
||||
let file_path = req.query.file_path ? decodeURIComponent(req.query.file_path) : null;
|
||||
let file_path = req.query.file_path ? decodeURIComponent(req.query.file_path.split('?')[0]) : null;
|
||||
if (!file_path && (req.isAuthenticated() || req.can_watch)) {
|
||||
let usersFileFolder = config_api.getConfigItem('ytdl_users_base_path');
|
||||
if (optionalParams['subName']) {
|
||||
|
||||
@@ -205,10 +205,28 @@ async function importUnregisteredFiles() {
|
||||
|
||||
}
|
||||
|
||||
async function getVideo(file_uid, uuid, sub_id) {
|
||||
const base_db_path = uuid ? users_db.get('users').find({uid: uuid}) : db;
|
||||
const sub_db_path = sub_id ? base_db_path.get('subscriptions').find({id: sub_id}).get('videos') : base_db_path.get('files');
|
||||
return sub_db_path.find({uid: file_uid}).value();
|
||||
}
|
||||
|
||||
async function setVideoProperty(file_uid, assignment_obj, uuid, sub_id) {
|
||||
const base_db_path = uuid ? users_db.get('users').find({uid: uuid}) : db;
|
||||
const sub_db_path = sub_id ? base_db_path.get('subscriptions').find({id: sub_id}).get('videos') : base_db_path.get('files');
|
||||
const file_db_path = sub_db_path.find({uid: file_uid});
|
||||
if (!(file_db_path.value())) {
|
||||
logger.error(`Failed to find file with uid ${file_uid}`);
|
||||
}
|
||||
sub_db_path.find({uid: file_uid}).assign(assignment_obj).write();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
initialize: initialize,
|
||||
registerFileDB: registerFileDB,
|
||||
updatePlaylist: updatePlaylist,
|
||||
getFileDirectoriesAndDBs: getFileDirectoriesAndDBs,
|
||||
importUnregisteredFiles: importUnregisteredFiles
|
||||
importUnregisteredFiles: importUnregisteredFiles,
|
||||
getVideo: getVideo,
|
||||
setVideoProperty: setVideoProperty
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user