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`)
|
||||
);
|
||||
|
||||
|
||||
INSERT INTO `vn`.`packingSiteConfig` SET
|
||||
shinobiUrl = 'http://shinobi.verdnatura.es',
|
||||
shinobiUrl = 'https://shinobi.verdnatura.es',
|
||||
shinobiToken = 'BW4o7FZyJ85she1hlRDe6QnwW3jwEP',
|
||||
shinobiGroupKey = 'xVqft9LFXg',
|
||||
avgBoxingTime = 30;
|
|
@ -9,13 +9,13 @@ module.exports = Self => {
|
|||
{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: false,
|
||||
required: true,
|
||||
description: 'Ticket id'
|
||||
},
|
||||
{
|
||||
arg: 'time',
|
||||
type: 'number',
|
||||
required: false,
|
||||
arg: 'filename',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'Time to add'
|
||||
},
|
||||
{
|
||||
|
@ -35,56 +35,56 @@ 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 myOptions = {};
|
||||
// console.log('ENTRY');
|
||||
|
||||
console.log('getFile', filename);
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const expedition = await models.Expedition.findById(id, null, myOptions);
|
||||
const packingSiteConfig = await models.PackingSiteConfig.findOne({}, myOptions);
|
||||
const monitorId = 'Xme2hiqz1f';
|
||||
// console.log(packingSiteConfig);
|
||||
|
||||
const addTime = (time ? time : packingSiteConfig.avgBoxingTime) * 1000;
|
||||
const start = new Date(expedition.created);// '2022-07-27T09:00:00';// new Date('2022-07-27'); //
|
||||
const end = new Date(start.getTime() + addTime);
|
||||
// console.log(addTime);
|
||||
// console.log(start.toString().split('.')[0]);
|
||||
// console.log(end.toString().split('.')[0]);
|
||||
const query = `
|
||||
SELECT
|
||||
e.id,
|
||||
ps.monitorId,
|
||||
e.created
|
||||
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 timeUrl = `?start=${start.toString().split('.')[0]}&end=${end.toString().split('.')[0]}`;
|
||||
const url = `${packingSiteConfig.shinobiUrl}${videoUrl}${timeUrl}&endIsStartTo`;
|
||||
const monitorId = '6Ou0D1bhBw'; // expedition.monitorId
|
||||
|
||||
// console.log(url);
|
||||
const videoList = await axios.post(url);
|
||||
// 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 videoUrl =
|
||||
`/${packingSiteConfig.shinobiToken}/videos/${packingSiteConfig.shinobiGroupKey}/${monitorId}/${filename}`;
|
||||
|
||||
const headers = Object.assign({}, req.headers, {
|
||||
host: 'shinobi.verdnatura.es'
|
||||
});
|
||||
const httpOptions = {
|
||||
host: 'shinobi.verdnatura.es',
|
||||
path: '/BW4o7FZyJ85she1hlRDe6QnwW3jwEP/videos/xVqft9LFXg/Xme2hiqz1f/2022-08-02T11-45-01.mp4',
|
||||
path: videoUrl,
|
||||
port: 443,
|
||||
headers
|
||||
};
|
||||
console.log('shinobi.verdnatura.es' + videoUrl);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const req = https.request(httpOptions,
|
||||
shinobiRes => {
|
||||
const req = https.request(httpOptions, shinobiRes => {
|
||||
console.log('entry');
|
||||
shinobiRes.pause();
|
||||
res.writeHeader(shinobiRes.statusCode, shinobiRes.headers);
|
||||
shinobiRes.pipe(res);
|
||||
});
|
||||
|
||||
req.on('error', error => {
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
req.on('end', res => {
|
||||
resolve();
|
||||
});
|
||||
req.end();
|
||||
|
|
|
@ -33,7 +33,7 @@ module.exports = Self => {
|
|||
|
||||
Self.getVideoList = async(id, from, to, options) => {
|
||||
const myOptions = {};
|
||||
console.log(id);
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
|
@ -67,14 +67,15 @@ module.exports = Self => {
|
|||
const videoUrl = `/${packingSiteConfig.shinobiToken}/videos/${packingSiteConfig.shinobiGroupKey}/${monitorId}`;
|
||||
const timeUrl = `?start=${start.toISOString().split('.')[0]}&end=${end.toISOString().split('.')[0]}`;
|
||||
const url = `${packingSiteConfig.shinobiUrl}${videoUrl}${timeUrl}`;
|
||||
console.log(url);
|
||||
|
||||
console.log('try get');
|
||||
const response = await axios(url).then(res => {
|
||||
return res;
|
||||
});
|
||||
console.log('finish get');
|
||||
let response;
|
||||
|
||||
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 => {
|
||||
require('../methods/boxing/getVideo')(Self);
|
||||
require('../methods/boxing/getVideoList')(Self);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue