recordInfoService.js
5.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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}});
console.log('录制文件',addrecord)
let noFile = [];
var allFile = [];
addrecord.forEach(function(record,top){
let date1 = moment(Number( record.createTime)).format('YYYYMMDD')
let date2 = moment(Number(record.createTime)-8*60*60*1000).format('YYYYMMDDhhmmss')
let channeFile = onlinePath+date1;
var fschannefiles=fs.readdirSync(channeFile);
fschannefiles.forEach(function(cfile,index){
if(record.channel == cfile.split('_')[0]+'_'+cfile.split("_")[1]){
let pathURL = onlinePath+date1+"/"+cfile;
let files=fs.readdirSync(pathURL);
if(top == 1){
allFile.push(files);
}
files.forEach(function(file){
let type = file.split('.');
//m3u8 配置
if(type[1] != 'mp4'){
}else{
let noFile = [];
let fileN = type[0].split('_');
console.log('++++++++=========',fileN[1])
console.log(moment(fileN[1], "YYYYMMDDhhmmss").format("X"),record.createTime)
console.log(date2,record.status)
console.log(record.id);
console.log(fileN[1].slice(0,fileN[1].length-3),date2==fileN[1].slice(0,fileN[1].length-3))
if(date2==fileN[1].slice(0,fileN[1].length-3)){
backFile.push({
channel:record.channel,
uid:record.uid,
userId:record.userId,
timestamp:record.timestamp,
createTime:record.createTime,
fileUrl:applacation.recordPath+date1+'/'+cfile+'/'+file
})
}else{
noFile.push(record)
}
}
})
}
})
})
let minNum = 0;
// let minFile = '';
// fschannefiles.forEach(function(minf){
// let minType = file.split('.');
// let minFileN = type[0].split('_');
// console.log('比武绝对值数值',Math.abs(record.createTime.slice(0,record.createTime.length-3),moment(fileN[1], "YYYYMMDDhhmmss").format("X")))
// console.log('比武绝对值',Math.abs(record.createTime.slice(0,record.createTime.length-3)-moment(fileN[1], "YYYYMMDDhhmmss").format("X")))
// let abs = Math.abs(record.createTime.slice(0,record.createTime.length-3)-moment(fileN[1], "YYYYMMDDhhmmss").format("X"))
// if(abs<minNum){
// minNum = abs;
// minFile = minf
// }
// })
// backFile.push({
// channel:record.channel,
// uid:record.uid,
// userId:record.userId,
// timestamp:record.timestamp,
// createTime:record.createTime,
// fileUrl:applacation.recordPath+date1+'/'+cfile+'/'+minFile
// })
return {backFile:backFile,fschannefiles:allFile}
} catch (error) {
throw error;
}
}
module.exports = new recordInfoService();