В этом коде URL возвращает данные, значения данных извлекаются в массив с помощью Object.values (). Массив состоит из списка видео ссылок. Когда используется почтальон, ссылки работают, потому что они являются пакетами fre sh. Когда я использую этот код для извлечения ссылки на видеоплеер, он генерирует URL с истекшим сроком действия. Я также использовал no-cache.
async function postData(url = '', data = {}) {
// Default options are marked with *
const response = await fetch(url, {
method: 'POST', // *GET, POST, PUT, DELETE, etc.
mode: 'cors', // no-cors, *cors, same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json'
// 'Content-Type': 'application/x-www-form-urlencoded',
},
redirect: 'follow', // manual, *follow, error
referrerPolicy: 'no-referrer', // no-referrer, *client
body: JSON.stringify(data) // body data type must match "Content-Type" header
});
return await response.json(); // parses JSON response into native JavaScript objects
}
postData('http://127.0.0.1:5000/video', {'email': '', 'password': '' })
.then((data) => {
var x = Object.values(data);
console.log(x); // JSON data parsed by `response.json()` call
var mylapse = document.getElementById('timelapse');
var thislapse = x;
var activeVideo = 0;
mylapse.addEventListener('ended', function(e) {
// update the new active video index
activeVideo = (++activeVideo) % thislapse.length;
// update the video source and play
mylapse.src = thislapse[activeVideo];
mylapse.play();
});
});