get_video_url.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import axios from "axios";
  2. export async function get_video_url(item) {
  3. try {
  4. const tokenResponse = await axios({
  5. method: 'post',
  6. url: 'http://anvideo.nxmy.com:8011/api/oauth/token',
  7. headers: {
  8. 'Content-Type': 'multipart/form-data'
  9. },
  10. data: {
  11. username: 'admin',
  12. password: 'Zhks123456+'
  13. }
  14. });
  15. const token = `${tokenResponse.data.data.token_type} ${tokenResponse.data.data.access_token}`;
  16. const videoUrlResponse = await axios({
  17. method: 'post',
  18. url: 'http://anvideo.nxmy.com:8011/api/camera/geturl',
  19. headers: {
  20. Authorization: token
  21. },
  22. data: {
  23. camera_id: item.camera_id,
  24. parent_id: item.parent_id
  25. }
  26. });
  27. if (videoUrlResponse.data.content.data.url) {
  28. return videoUrlResponse.data.content.data.url;
  29. } else {
  30. throw new Error('No URL found in response');
  31. }
  32. } catch (error) {
  33. console.error(error);
  34. throw error; // Re-throw the error to be handled by the caller
  35. }
  36. }