refactor(boxing): refactor getVideo
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
4a058faaf8
commit
43df1e7e10
|
@ -7,9 +7,8 @@ CREATE TABLE `vn`.`packingSiteConfig` (
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO `vn`.`packingSiteConfig` SET
|
INSERT INTO `vn`.`packingSiteConfig` SET
|
||||||
shinobiUrl = 'http://shinobi.verdnatura.es',
|
shinobiUrl = 'https://shinobi.verdnatura.es',
|
||||||
shinobiToken = 'BW4o7FZyJ85she1hlRDe6QnwW3jwEP',
|
shinobiToken = 'BW4o7FZyJ85she1hlRDe6QnwW3jwEP',
|
||||||
shinobiGroupKey = 'xVqft9LFXg',
|
shinobiGroupKey = 'xVqft9LFXg',
|
||||||
avgBoxingTime = 30;
|
avgBoxingTime = 30;
|
|
@ -9,13 +9,13 @@ module.exports = Self => {
|
||||||
{
|
{
|
||||||
arg: 'id',
|
arg: 'id',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
required: false,
|
required: true,
|
||||||
description: 'Ticket id'
|
description: 'Ticket id'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'time',
|
arg: 'filename',
|
||||||
type: 'number',
|
type: 'string',
|
||||||
required: false,
|
required: true,
|
||||||
description: 'Time to add'
|
description: 'Time to add'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -35,58 +35,58 @@ module.exports = Self => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.getVideo = async(id, time, req, res, options) => {
|
Self.getVideo = async(id, filename, req, res, options) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
// console.log('ENTRY');
|
|
||||||
|
console.log('getFile', filename);
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const expedition = await models.Expedition.findById(id, null, myOptions);
|
|
||||||
const packingSiteConfig = await models.PackingSiteConfig.findOne({}, myOptions);
|
const packingSiteConfig = await models.PackingSiteConfig.findOne({}, myOptions);
|
||||||
const monitorId = 'Xme2hiqz1f';
|
|
||||||
// console.log(packingSiteConfig);
|
|
||||||
|
|
||||||
const addTime = (time ? time : packingSiteConfig.avgBoxingTime) * 1000;
|
const query = `
|
||||||
const start = new Date(expedition.created);// '2022-07-27T09:00:00';// new Date('2022-07-27'); //
|
SELECT
|
||||||
const end = new Date(start.getTime() + addTime);
|
e.id,
|
||||||
// console.log(addTime);
|
ps.monitorId,
|
||||||
// console.log(start.toString().split('.')[0]);
|
e.created
|
||||||
// console.log(end.toString().split('.')[0]);
|
FROM expedition e
|
||||||
|
JOIN host h ON Convert(h.code USING utf8mb3) COLLATE utf8mb3_unicode_ci = e.hostFk
|
||||||
|
JOIN packingSite ps ON ps.hostFk = h.id
|
||||||
|
WHERE e.id = ?;`;
|
||||||
|
const [expedition] = await models.Expedition.rawSql(query, [id]);
|
||||||
|
|
||||||
const videoUrl = `/${packingSiteConfig.shinobiToken}/videos/${packingSiteConfig.shinobiGroupKey}/${monitorId}`;
|
const monitorId = '6Ou0D1bhBw'; // expedition.monitorId
|
||||||
const timeUrl = `?start=${start.toString().split('.')[0]}&end=${end.toString().split('.')[0]}`;
|
|
||||||
const url = `${packingSiteConfig.shinobiUrl}${videoUrl}${timeUrl}&endIsStartTo`;
|
|
||||||
|
|
||||||
// console.log(url);
|
const videoUrl =
|
||||||
const videoList = await axios.post(url);
|
`/${packingSiteConfig.shinobiToken}/videos/${packingSiteConfig.shinobiGroupKey}/${monitorId}/${filename}`;
|
||||||
// console.log('videoList.data', videoList.data);
|
|
||||||
// console.log(videoList.data.videos);
|
|
||||||
// console.log(videoList.data.videos.length);
|
|
||||||
const length = videoList.data.videos.length;
|
|
||||||
// console.log(length);
|
|
||||||
if (!length) return [];
|
|
||||||
|
|
||||||
const lastVideo = videoList.data.videos[length - 1].href;
|
|
||||||
|
|
||||||
const headers = Object.assign({}, req.headers, {
|
const headers = Object.assign({}, req.headers, {
|
||||||
host: 'shinobi.verdnatura.es'
|
host: 'shinobi.verdnatura.es'
|
||||||
});
|
});
|
||||||
const httpOptions = {
|
const httpOptions = {
|
||||||
host: 'shinobi.verdnatura.es',
|
host: 'shinobi.verdnatura.es',
|
||||||
path: '/BW4o7FZyJ85she1hlRDe6QnwW3jwEP/videos/xVqft9LFXg/Xme2hiqz1f/2022-08-02T11-45-01.mp4',
|
path: videoUrl,
|
||||||
port: 443,
|
port: 443,
|
||||||
headers
|
headers
|
||||||
};
|
};
|
||||||
|
console.log('shinobi.verdnatura.es' + videoUrl);
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const req = https.request(httpOptions,
|
const req = https.request(httpOptions, shinobiRes => {
|
||||||
shinobiRes => {
|
console.log('entry');
|
||||||
shinobiRes.pause();
|
shinobiRes.pause();
|
||||||
res.writeHeader(shinobiRes.statusCode, shinobiRes.headers);
|
res.writeHeader(shinobiRes.statusCode, shinobiRes.headers);
|
||||||
shinobiRes.pipe(res);
|
shinobiRes.pipe(res);
|
||||||
resolve();
|
});
|
||||||
});
|
|
||||||
|
req.on('error', error => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
req.on('end', res => {
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
req.end();
|
req.end();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -33,7 +33,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
Self.getVideoList = async(id, from, to, options) => {
|
Self.getVideoList = async(id, from, to, options) => {
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
console.log(id);
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
@ -67,14 +67,15 @@ module.exports = Self => {
|
||||||
const videoUrl = `/${packingSiteConfig.shinobiToken}/videos/${packingSiteConfig.shinobiGroupKey}/${monitorId}`;
|
const videoUrl = `/${packingSiteConfig.shinobiToken}/videos/${packingSiteConfig.shinobiGroupKey}/${monitorId}`;
|
||||||
const timeUrl = `?start=${start.toISOString().split('.')[0]}&end=${end.toISOString().split('.')[0]}`;
|
const timeUrl = `?start=${start.toISOString().split('.')[0]}&end=${end.toISOString().split('.')[0]}`;
|
||||||
const url = `${packingSiteConfig.shinobiUrl}${videoUrl}${timeUrl}`;
|
const url = `${packingSiteConfig.shinobiUrl}${videoUrl}${timeUrl}`;
|
||||||
console.log(url);
|
|
||||||
|
|
||||||
console.log('try get');
|
let response;
|
||||||
const response = await axios(url).then(res => {
|
|
||||||
return res;
|
|
||||||
});
|
|
||||||
console.log('finish get');
|
|
||||||
|
|
||||||
console.log(response);
|
try {
|
||||||
|
response = await axios.get(url);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return response.data.videos.map(video => video.filename);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
require('../methods/boxing/getVideo')(Self);
|
require('../methods/boxing/getVideo')(Self);
|
||||||
|
require('../methods/boxing/getVideoList')(Self);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue