adding blacklist feature
This commit is contained in:
		
							parent
							
								
									1605f63691
								
							
						
					
					
						commit
						b51a38325f
					
				| 
						 | 
				
			
			@ -24,7 +24,12 @@ exports.save = async (ws, req) => {
 | 
			
		|||
 | 
			
		||||
    if (await redis.get(id)) {
 | 
			
		||||
        ws.send('DATA - Someone is already downloading this video...')
 | 
			
		||||
        ws.close()
 | 
			
		||||
        return ws.close()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (await redis.get(`blacklist:${id}`)) {
 | 
			
		||||
        ws.send('DATA - You can\'t download that. The video is blacklisted.')
 | 
			
		||||
        return ws.close()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const already = await prisma.videos.findFirst({
 | 
			
		||||
| 
						 | 
				
			
			@ -138,6 +143,11 @@ exports.playlist = async (ws, req) => {
 | 
			
		|||
                continue
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (await redis.get(`blacklist:${id}`)) {
 | 
			
		||||
                ws.send(`DATA - ${video.title} is blacklisted from downloading, skipping`)
 | 
			
		||||
                continue
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            ws.send(`INFO - Downloading ${video.title}<br><br>`)
 | 
			
		||||
            await redis.set(id, 'downloading')
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -220,6 +230,11 @@ exports.channel = async (ws, req) => {
 | 
			
		|||
                continue
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (await redis.get(`blacklist:${id}`)) {
 | 
			
		||||
                ws.send(`DATA - ${video.title} is blacklisted from downloading, skipping`)
 | 
			
		||||
                continue
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
            ws.send(`INFO - Downloading ${video.title}<br><br>`)
 | 
			
		||||
            await redis.set(id, 'downloading')
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										2
									
								
								index.js
								
								
								
								
							
							
						
						
									
										2
									
								
								index.js
								
								
								
								
							| 
						 | 
				
			
			@ -4,7 +4,6 @@ const express = require('express')
 | 
			
		|||
const cors = require('cors')
 | 
			
		||||
 | 
			
		||||
const logger = require('./utils/logger.js')
 | 
			
		||||
const redis = require('./utils/redis.js')
 | 
			
		||||
const auto = require('./utils/auto.js')
 | 
			
		||||
 | 
			
		||||
const latestController = require('./controller/latest.js')
 | 
			
		||||
| 
						 | 
				
			
			@ -35,7 +34,6 @@ app.ws('/saveplaylist', websocketController.playlist)
 | 
			
		|||
app.ws('/savechannel', websocketController.channel)
 | 
			
		||||
app.get('/autodownload', websocketController.addAutodownload)
 | 
			
		||||
 | 
			
		||||
redis.flushdb()
 | 
			
		||||
auto.handleCheck()
 | 
			
		||||
// setInterval(() => {
 | 
			
		||||
//   auto.handleCheck()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -47,6 +47,11 @@ async function handleDownload(channelId) {
 | 
			
		|||
            return
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (await redis.get(`blacklist:${id}`)) {
 | 
			
		||||
            logger.info({ message: `${video.title} is blacklisted from downloading, ${id}` })
 | 
			
		||||
            return
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (video.duration > 5400) {
 | 
			
		||||
            logger.info({ message: `${video.title} is longer than 1h30m, ${id}` })
 | 
			
		||||
            return
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,8 +7,13 @@ const redis = new Redis({
 | 
			
		|||
    password: process.env.REDIS_PASS,
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
redis.on('ready', function () {
 | 
			
		||||
redis.on('ready', async function () {
 | 
			
		||||
    logger.info({ message: 'Connected to redis!' })
 | 
			
		||||
 | 
			
		||||
    const keys = await redis.keys('*')
 | 
			
		||||
    const filteredKeys = keys.filter(key => !key.startsWith('blacklist:'))
 | 
			
		||||
    await redis.del(filteredKeys)
 | 
			
		||||
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
module.exports = redis
 | 
			
		||||
		Loading…
	
		Reference in New Issue