PASSAGGIO A VITE !
AGG. 1.1.23
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import axios, { AxiosRequestConfig, AxiosInstance, AxiosResponse } from 'axios'
|
||||
import type { AxiosRequestConfig, AxiosInstance, AxiosResponse } from 'axios';
|
||||
import axios from 'axios'
|
||||
|
||||
// import LoginModule from '../Modules/Auth/LoginStore'
|
||||
import { toolsext } from '@src/store/Modules/toolsext'
|
||||
@@ -8,7 +9,8 @@ import { useUserStore } from '@store/UserStore'
|
||||
import { tools } from '@src/store/Modules/tools'
|
||||
import * as Types from './ApiTypes'
|
||||
|
||||
import { from, Observable } from 'rxjs';
|
||||
import type { Observable } from 'rxjs';
|
||||
import { from } from 'rxjs';
|
||||
import { mergeMap, toArray } from 'rxjs/operators';
|
||||
|
||||
export let API_URL = ''
|
||||
@@ -23,14 +25,14 @@ export const axiosInstance: AxiosInstance = axios.create({
|
||||
axiosInstance.interceptors.response.use(
|
||||
|
||||
(response) => {
|
||||
if (process.env.DEBUGGING === '1') console.log(response)
|
||||
if (import.meta.env.DEBUGGING === '1') console.log(response)
|
||||
return response
|
||||
},
|
||||
(error) => {
|
||||
const globalStore = useGlobalStore()
|
||||
// console.log('error', error)
|
||||
if (error.response) {
|
||||
if (process.env.DEBUGGING === '1') console.log('Status = ', error.response.status)
|
||||
if (import.meta.env.DEBUGGING === '1') console.log('Status = ', error.response.status)
|
||||
console.log('Request Error: ', error.response)
|
||||
if (error.response.status !== 0) {
|
||||
globalStore.setStateConnection('online')
|
||||
@@ -163,16 +165,6 @@ async function Request(type: string, path: string, payload: any, responsedata?:
|
||||
);
|
||||
|
||||
});
|
||||
/*
|
||||
console.log('Stream response received, processing...');
|
||||
return handleStreamResponse(response, (data) => {
|
||||
console.log('data...' + data.content)
|
||||
// Aggiorna lo stato dell'applicazione qui
|
||||
// Ad esempio:
|
||||
// outputVisible.value += data.content;
|
||||
});
|
||||
*/
|
||||
|
||||
} else {
|
||||
|
||||
response = await axiosInstance[type](path, payload, config)
|
||||
@@ -255,7 +247,7 @@ async function Request(type: string, path: string, payload: any, responsedata?:
|
||||
globalStore.connData.downloading_server = (globalStore.connData.downloading_server === 1) ? -1 : globalStore.connData.downloading_server
|
||||
}, 1000)
|
||||
|
||||
if (process.env.DEV) {
|
||||
if (import.meta.env.DEV) {
|
||||
console.log('ERROR using', path)
|
||||
// console.log('Error received: ', error)
|
||||
// console.log('ricevuto=', ricevuto)
|
||||
@@ -282,34 +274,4 @@ async function Request(type: string, path: string, payload: any, responsedata?:
|
||||
return Promise.reject(new Types.AxiosError(0, null, mycode, error))
|
||||
}
|
||||
}
|
||||
|
||||
function handleStreamResponse(response: AxiosResponse, updateCallback: (data: any) => void): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
// ... codice precedente ...
|
||||
|
||||
reader.on('data', (chunk: Buffer) => {
|
||||
// ... codice precedente ...
|
||||
if (line.startsWith('data: ')) {
|
||||
const eventData = line.slice(6);
|
||||
try {
|
||||
const parsedData = JSON.parse(eventData);
|
||||
console.log('Received data:', parsedData);
|
||||
updateCallback(parsedData); // Chiamata alla callback per aggiornare lo stato
|
||||
} catch (error) {
|
||||
console.error('Error parsing event data:', error);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
reader.on('end', () => {
|
||||
console.log('Stream ended');
|
||||
resolve('Stream completed');
|
||||
});
|
||||
|
||||
reader.on('error', (error: Error) => {
|
||||
console.error('Stream error:', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
export default Request
|
||||
|
||||
Reference in New Issue
Block a user