- Catalogo: qualità di stampa, margini. ora è 300 DPI.
This commit is contained in:
@@ -4,15 +4,16 @@ import axios, {
|
||||
import { Api } from '@api'
|
||||
import * as Types from '@src/store/Api/ApiTypes'
|
||||
|
||||
async function sendRequest(url: string, method: string, mydata: any) {
|
||||
// if (process.env.DEBUG) console.log('sendRequest', method, url)
|
||||
async function sendRequest(url: string, method: string, mydata: any, myformdata?: any, responsedata?: any) {
|
||||
console.log('sendRequest', method, url, mydata)
|
||||
|
||||
let request
|
||||
if (method === 'GET') request = Api.get(url, mydata)
|
||||
else if (method === 'POST') request = Api.post(url, mydata)
|
||||
else if (method === 'DELETE') request = Api.Delete(url, mydata)
|
||||
else if (method === 'PUT') request = Api.put(url, mydata)
|
||||
else if (method === 'PATCH') request = Api.patch(url, mydata)
|
||||
if (method === 'GET') request = Api.get(url, mydata, responsedata)
|
||||
else if (method === 'POST') request = Api.post(url, mydata, responsedata)
|
||||
else if (method === 'postFormData') request = Api.postFormData(url, myformdata, responsedata)
|
||||
else if (method === 'DELETE') request = Api.Delete(url, mydata, responsedata)
|
||||
else if (method === 'PUT') request = Api.put(url, mydata, responsedata)
|
||||
else if (method === 'PATCH') request = Api.patch(url, mydata, responsedata)
|
||||
|
||||
// @ts-ignore
|
||||
const req: Promise<Types.AxiosSuccess | Types.AxiosError> = request
|
||||
|
||||
@@ -47,7 +47,7 @@ export const addAuthHeaders = () => {
|
||||
// delete axiosInstance.defaults.headers.Authorization
|
||||
//}
|
||||
|
||||
async function Request(type: string, path: string, payload: any): Promise<Types.AxiosSuccess | Types.AxiosError | undefined> {
|
||||
async function Request(type: string, path: string, payload: any, responsedata?: any): Promise<Types.AxiosSuccess | Types.AxiosError | undefined> {
|
||||
|
||||
let ricevuto = false
|
||||
const userStore = useUserStore()
|
||||
@@ -65,6 +65,7 @@ async function Request(type: string, path: string, payload: any): Promise<Types.
|
||||
'x-auth': userStore.x_auth_token,
|
||||
'x-refrtok': userStore.refreshToken,
|
||||
},
|
||||
...responsedata,
|
||||
})
|
||||
ricevuto = true
|
||||
// console.log('Request Response: ', response)
|
||||
@@ -119,10 +120,12 @@ async function Request(type: string, path: string, payload: any): Promise<Types.
|
||||
'x-auth': userStore.x_auth_token,
|
||||
'x-refrtok': userStore.refreshToken,
|
||||
},
|
||||
...responsedata,
|
||||
})
|
||||
ricevuto = true
|
||||
return new Types.AxiosSuccess(response.data, response.status)
|
||||
} else if (type === 'postFormData') {
|
||||
console.log('postFormData', payload)
|
||||
response = await axiosInstance.post(path, payload, {
|
||||
baseURL: globalStore.getServerHost(),
|
||||
headers: {
|
||||
@@ -130,6 +133,7 @@ async function Request(type: string, path: string, payload: any): Promise<Types.
|
||||
'x-auth': userStore.x_auth_token,
|
||||
'x-refrtok': userStore.refreshToken,
|
||||
},
|
||||
...responsedata,
|
||||
})
|
||||
ricevuto = true
|
||||
return new Types.AxiosSuccess(response.data, response.status)
|
||||
|
||||
@@ -37,43 +37,43 @@ function ReceiveResponsefromServer(tablesync: string, nametab: string, method: s
|
||||
|
||||
// const algoliaApi = new AlgoliaSearch()
|
||||
export const Api = {
|
||||
async post(path: string, payload?: any) {
|
||||
async post(path: string, payload?: any, responsedata?: any) {
|
||||
const globalStore = useGlobalStore()
|
||||
globalStore.connData.downloading_server = 1
|
||||
globalStore.connData.uploading_server = 1
|
||||
return Request('post', path, payload)
|
||||
return Request('post', path, payload, responsedata)
|
||||
},
|
||||
|
||||
async postFormData(path: string, payload?: any) {
|
||||
async postFormData(path: string, payload?: any, responsedata?: any) {
|
||||
const globalStore = useGlobalStore()
|
||||
globalStore.connData.uploading_server = 1
|
||||
globalStore.connData.downloading_server = 1
|
||||
return Request('postFormData', path, payload)
|
||||
return Request('postFormData', path, payload, responsedata)
|
||||
},
|
||||
|
||||
async get(path: string, payload?: any) {
|
||||
async get(path: string, payload?: any, responsedata?: any) {
|
||||
const globalStore = useGlobalStore()
|
||||
globalStore.connData.downloading_server = 1
|
||||
globalStore.connData.uploading_server = 0
|
||||
return Request('get', path, payload)
|
||||
return Request('get', path, payload, responsedata)
|
||||
},
|
||||
|
||||
async put(path: string, payload?: any) {
|
||||
async put(path: string, payload?: any, responsedata?: any) {
|
||||
const globalStore = useGlobalStore()
|
||||
globalStore.connData.uploading_server = 1
|
||||
return Request('put', path, payload)
|
||||
return Request('put', path, payload, responsedata)
|
||||
},
|
||||
|
||||
async patch(path: string, payload?: any) {
|
||||
async patch(path: string, payload?: any, responsedata?: any) {
|
||||
const globalStore = useGlobalStore()
|
||||
globalStore.connData.uploading_server = 1
|
||||
return Request('patch', path, payload)
|
||||
return Request('patch', path, payload, responsedata)
|
||||
},
|
||||
|
||||
async Delete(path: string, payload: any) {
|
||||
async Delete(path: string, payload: any, responsedata?: any) {
|
||||
const globalStore = useGlobalStore()
|
||||
globalStore.connData.uploading_server = 1
|
||||
return Request('delete', path, payload)
|
||||
return Request('delete', path, payload, responsedata)
|
||||
},
|
||||
|
||||
async checkSession({ token, refresh_token }: any) {
|
||||
@@ -131,7 +131,7 @@ export const Api = {
|
||||
|
||||
},
|
||||
|
||||
async SendReqBase(url: string, method: string, mydata: any, setAuthToken = false, evitaloop = false): Promise<Types.AxiosSuccess | Types.AxiosError> {
|
||||
async SendReqBase(url: string, method: string, mydata: any, setAuthToken = false, evitaloop = false, myformdata?: any, responsedata?: any): Promise<Types.AxiosSuccess | Types.AxiosError> {
|
||||
const mydataout = {
|
||||
...mydata,
|
||||
keyappid: process.env.PAO_APP_ID,
|
||||
@@ -145,7 +145,7 @@ export const Api = {
|
||||
userStore.setServerCode(tools.EMPTY)
|
||||
userStore.setResStatus(0)
|
||||
|
||||
return new Promise((resolve, reject) => sendRequest(url, method, mydataout)
|
||||
return new Promise((resolve, reject) => sendRequest(url, method, mydataout, myformdata, responsedata)
|
||||
.then((res) => {
|
||||
setTimeout(() => {
|
||||
if (method === 'get') {
|
||||
@@ -245,10 +245,12 @@ export const Api = {
|
||||
setAuthToken = false,
|
||||
evitaloop = false,
|
||||
retryCount = 3,
|
||||
retryDelay = 5000
|
||||
retryDelay = 5000,
|
||||
myformdata?: any,
|
||||
responsedata?: any,
|
||||
): Promise<Types.AxiosSuccess | Types.AxiosError> {
|
||||
try {
|
||||
const response = await this.SendReqBase(url, method, mydata, setAuthToken, evitaloop);
|
||||
const response = await this.SendReqBase(url, method, mydata, setAuthToken, evitaloop, myformdata, responsedata);
|
||||
return response;
|
||||
} catch (error: any) {
|
||||
if (retryCount > 0) {
|
||||
@@ -262,7 +264,9 @@ export const Api = {
|
||||
setAuthToken,
|
||||
evitaloop,
|
||||
retryCount - 1,
|
||||
retryDelay
|
||||
retryDelay,
|
||||
myformdata,
|
||||
responsedata,
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user