recordInfoService.js 3.2 KB
const recordInfo =require( '../model/RecordInfoModel')
const tencentRecordInfoModel =require( '../model/tencentRecordInfoModel')
const callfile = require('child_process');
const  fs = require('fs');
const moment = require('moment')
const applacation = require('../applacation')


function recordInfoService(){

}
recordInfoService.prototype.updaterecordInfo = async(channel)=>{
    try {
        let channelupdate = await recordInfo.update(
            {status:0},
            {where:
                {channel:channel}})
        return channelupdate;
    } catch (error) {
        throw error;
    }
}
recordInfoService.prototype.addRecordInfo = async(body) =>{
    try {
        let addrecord =  await recordInfo.create(body);
        return addrecord;
    } catch (error) {
        throw error;
    }
}
recordInfoService.prototype.getRecordInfo = async(channel) =>{
    try {
        let addrecord =  await recordInfo.findAll({where:{channel:channel}});
        return addrecord;
    } catch (error) {
        throw error;
    }
}
recordInfoService.prototype.tencentRecordInfo = async(channelId)=>{
    try {
        let tencentRecordInfo = await tencentRecordInfoModel.findAll({where:{channelId:channelId}})
        return tencentRecordInfo
    } catch (error) {
        throw error;
    }
}

recordInfoService.prototype.getRecordFileURL = async(path,time)=>{
    try {
        let onlinePath = '/netWorkSchool/Agora_Recording_SDK_for_Linux_FULL/samples/'      
        //let onlinePath = '/Users/fzy/Downloads/Agora_Recording_SDK_for_Linux_FULL/samples/' 
        var backFile=[];
        var fileU
        let addrecord =  await recordInfo.findAll({where:{channel:path}});
        addrecord.forEach(function(record){
             let date1 = moment(Number( record.createTime)).format('YYYYMMDD')
             let date2 = moment(Number(record.createTime)-8*60*60*1000).format('YYYYMMDDhhmmss')
             let channeFile = onlinePath+date1;             
             let fschannefiles=fs.readdirSync(channeFile);        
             fschannefiles.forEach(function(cfile){
                 if(record.channel == cfile.split('_')[0]+'_'+cfile.split("_")[1]){
                     let pathURL = onlinePath+date1+"/"+cfile;
                     let files=fs.readdirSync(pathURL);
                     files.forEach(function(file){
                         let type = file.split('.');
                         if(type[1] != 'm3u8'){
                         }else{
                             let fileN = type[0].split('_');
                             if(date2==fileN[1].slice(0,fileN[1].length-3)){
                                 backFile.push({
                                    channel:record.channel,
                                    uid:record.uid,
                                    createTime:record.createTime,
                                    fileUrl:applacation.recordPath+date1+'/'+cfile+'/'+file
                                 })
                                }
                            }
                        })
                    }
                })
            })
            return backFile       
    } catch (error) {
        throw error;
    }
    
}

module.exports = new recordInfoService();