feat(ticket_boxing): fix getVideo
gitea/salix/pipeline/head This commit is unstable
Details
gitea/salix/pipeline/head This commit is unstable
Details
This commit is contained in:
parent
8a08b6f399
commit
b4b6d61460
|
@ -1,4 +1,5 @@
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
|
const https = require('https');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethod('getVideo', {
|
Self.remoteMethod('getVideo', {
|
||||||
|
@ -16,23 +17,16 @@ module.exports = Self => {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
required: false,
|
required: false,
|
||||||
description: 'Time to add'
|
description: 'Time to add'
|
||||||
}
|
|
||||||
],
|
|
||||||
returns: [
|
|
||||||
{
|
|
||||||
arg: 'body',
|
|
||||||
type: 'file',
|
|
||||||
root: true
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'Content-Type',
|
arg: 'req',
|
||||||
type: 'String',
|
type: 'object',
|
||||||
http: {target: 'header'}
|
http: {source: 'req'}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'Content-Disposition',
|
arg: 'res',
|
||||||
type: 'String',
|
type: 'object',
|
||||||
http: {target: 'header'}
|
http: {source: 'res'}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
http: {
|
http: {
|
||||||
|
@ -41,42 +35,59 @@ module.exports = Self => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.getVideo = async(id, time, options) => {
|
Self.getVideo = async(id, time, req, res, options) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
console.log('ENTRY');
|
// console.log('ENTRY');
|
||||||
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 expedition = await models.Expedition.findById(id, null, myOptions);
|
||||||
const packingSiteConfig = await models.PackingSiteConfig.findOne({}, myOptions);
|
const packingSiteConfig = await models.PackingSiteConfig.findOne({}, myOptions);
|
||||||
const monitorId = 'VbiUcajdaT';
|
const monitorId = 'Xme2hiqz1f';
|
||||||
console.log(packingSiteConfig);
|
// console.log(packingSiteConfig);
|
||||||
|
|
||||||
const addTime = (time ? time : packingSiteConfig.avgBoxingTime) * 1000;
|
const addTime = (time ? time : packingSiteConfig.avgBoxingTime) * 1000;
|
||||||
const start = new Date(expedition.created);// '2022-07-27T09:00:00';// new Date('2022-07-27'); //
|
const start = new Date(expedition.created);// '2022-07-27T09:00:00';// new Date('2022-07-27'); //
|
||||||
const end = new Date(start.getTime() + addTime);
|
const end = new Date(start.getTime() + addTime);
|
||||||
console.log(addTime);
|
// console.log(addTime);
|
||||||
console.log(start.toISOString().split('.')[0]);
|
// console.log(start.toString().split('.')[0]);
|
||||||
console.log(end.toISOString().split('.')[0]);
|
// console.log(end.toString().split('.')[0]);
|
||||||
|
|
||||||
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.toString().split('.')[0]}&end=${end.toString().split('.')[0]}`;
|
||||||
const url = `${packingSiteConfig.shinobiUrl}${videoUrl}${timeUrl}&endIsStartTo`;
|
const url = `${packingSiteConfig.shinobiUrl}${videoUrl}${timeUrl}&endIsStartTo`;
|
||||||
|
|
||||||
console.log(url);
|
// console.log(url);
|
||||||
const videoList = await axios.post(url);
|
const videoList = await axios.post(url);
|
||||||
console.log(videoList.data);
|
// console.log('videoList.data', videoList.data);
|
||||||
const lastVideo = videoList.data.videos[videoList.data.videos.length - 1].href;
|
// console.log(videoList.data.videos);
|
||||||
console.log(lastVideo);
|
// console.log(videoList.data.videos.length);
|
||||||
const stream = await axios({
|
const length = videoList.data.videos.length;
|
||||||
method: 'get',
|
// console.log(length);
|
||||||
url: `${packingSiteConfig.shinobiUrl}${lastVideo}`,
|
if (!length) return [];
|
||||||
responseType: 'stream'
|
|
||||||
}).then(response => {
|
|
||||||
return response.data;
|
|
||||||
});
|
|
||||||
|
|
||||||
return [stream, 'video/mp4', `filename="${id}.mp4"`];
|
const lastVideo = videoList.data.videos[length - 1].href;
|
||||||
|
|
||||||
|
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',
|
||||||
|
port: 443,
|
||||||
|
headers
|
||||||
|
};
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const req = https.request(httpOptions,
|
||||||
|
shinobiRes => {
|
||||||
|
shinobiRes.pause();
|
||||||
|
res.writeHeader(shinobiRes.statusCode, shinobiRes.headers);
|
||||||
|
shinobiRes.pipe(res);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
req.end();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,7 +7,7 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
$onInit() {
|
$onInit() {
|
||||||
// window.location.href = this.lilium('dashboard');
|
window.location.href = this.lilium(`ticket/${this.ticket.id}/boxing`);
|
||||||
}
|
}
|
||||||
|
|
||||||
lilium(route) {
|
lilium(route) {
|
||||||
|
|
Loading…
Reference in New Issue