Fix storage requests
This commit is contained in:
parent
5a94888a78
commit
091a8d4bd2
@ -11,8 +11,9 @@ import { BackUp } from '~/models/backup.model';
|
|||||||
|
|
||||||
export const U32_MAX = 4294967295;
|
export const U32_MAX = 4294967295;
|
||||||
|
|
||||||
const storageUrl = `/storage`;
|
const BASEURL = `https://demo.4nkweb.com`;
|
||||||
const BOOTSTRAPURL = [`https://demo.4nkweb.com/ws/`];
|
const BOOTSTRAPURL = [`${BASEURL}/ws/`];
|
||||||
|
const STORAGEURL = `${BASEURL}/storage`
|
||||||
const DEFAULTAMOUNT = 1000n;
|
const DEFAULTAMOUNT = 1000n;
|
||||||
|
|
||||||
export default class Services {
|
export default class Services {
|
||||||
@ -264,7 +265,7 @@ export default class Services {
|
|||||||
min_sig_member: 0.0,
|
min_sig_member: 0.0,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
storages: [storageUrl]
|
storages: [STORAGEURL]
|
||||||
},
|
},
|
||||||
owner: {
|
owner: {
|
||||||
members: meAndOne,
|
members: meAndOne,
|
||||||
@ -275,7 +276,7 @@ export default class Services {
|
|||||||
min_sig_member: 1.0,
|
min_sig_member: 1.0,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
storages: [storageUrl]
|
storages: [STORAGEURL]
|
||||||
},
|
},
|
||||||
users: {
|
users: {
|
||||||
members: everyOneElse,
|
members: everyOneElse,
|
||||||
@ -286,7 +287,7 @@ export default class Services {
|
|||||||
min_sig_member: 0.0,
|
min_sig_member: 0.0,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
storages: [storageUrl]
|
storages: [STORAGEURL]
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -313,7 +314,7 @@ export default class Services {
|
|||||||
min_sig_member: 1.0,
|
min_sig_member: 1.0,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
storages: [storageUrl]
|
storages: [STORAGEURL]
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const pairingTemplate = {
|
const pairingTemplate = {
|
||||||
@ -370,7 +371,7 @@ export default class Services {
|
|||||||
min_sig_member: 0.01,
|
min_sig_member: 0.01,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
storages: [storageUrl]
|
storages: [STORAGEURL]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -879,7 +880,7 @@ export default class Services {
|
|||||||
// We check how many copies in storage nodes
|
// We check how many copies in storage nodes
|
||||||
// We check the storage nodes in the process itself
|
// We check the storage nodes in the process itself
|
||||||
// this.sdkClient.get_storages(commitedIn);
|
// this.sdkClient.get_storages(commitedIn);
|
||||||
const storages = [storageUrl];
|
const storages = [STORAGEURL];
|
||||||
|
|
||||||
for (const state of process.states) {
|
for (const state of process.states) {
|
||||||
if (state.state_id === "") {
|
if (state.state_id === "") {
|
||||||
@ -913,7 +914,7 @@ export default class Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async saveDataToStorage(hash: string, data: string, ttl: number | null) {
|
public async saveDataToStorage(hash: string, data: string, ttl: number | null) {
|
||||||
const storages = [storageUrl];
|
const storages = [STORAGEURL];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await storeData(storages, hash, data, ttl);
|
await storeData(storages, hash, data, ttl);
|
||||||
@ -923,13 +924,13 @@ export default class Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async fetchValueFromStorage(hash: string): Promise<any | null> {
|
public async fetchValueFromStorage(hash: string): Promise<any | null> {
|
||||||
const storages = [storageUrl];
|
const storages = [STORAGEURL];
|
||||||
|
|
||||||
return await retrieveData(storages, hash);
|
return await retrieveData(storages, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async testDataInStorage(hash: string): Promise<Record<string, boolean | null> | null> {
|
public async testDataInStorage(hash: string): Promise<Record<string, boolean | null> | null> {
|
||||||
const storages = [storageUrl];
|
const storages = [STORAGEURL];
|
||||||
|
|
||||||
return await testData(storages, hash);
|
return await testData(storages, hash);
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,35 @@
|
|||||||
import axios, { AxiosResponse } from 'axios';
|
import axios, { AxiosResponse } from 'axios';
|
||||||
|
|
||||||
export async function storeData(servers: string[], key: string, value: any, ttl: number | null): Promise<AxiosResponse | null> {
|
export async function storeData(servers: string[], key: string, value: any, ttl: number | null): Promise<AxiosResponse | null> {
|
||||||
for (const server of servers) {
|
for (const server of servers) {
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(`${server}/store`, { key, value, ttl });
|
// Append key and ttl as query parameters
|
||||||
console.log('Data stored successfully:', key);
|
const url = new URL(`${server}/store`);
|
||||||
if (response.status !== 200) {
|
url.searchParams.append('key', key);
|
||||||
console.error('Received response status', response.status);
|
if (ttl !== null) {
|
||||||
continue;
|
url.searchParams.append('ttl', ttl.toString());
|
||||||
}
|
}
|
||||||
return response;
|
|
||||||
} catch (error) {
|
// Send the encrypted Blob as the raw request body.
|
||||||
if (error?.response?.status === 409) {
|
const response = await axios.post(url.toString(), value, {
|
||||||
return null;
|
headers: {
|
||||||
}
|
'Content-Type': 'application/octet-stream'
|
||||||
console.error('Error storing data:', error);
|
},
|
||||||
}
|
});
|
||||||
|
console.log('Data stored successfully:', key);
|
||||||
|
if (response.status !== 200) {
|
||||||
|
console.error('Received response status', response.status);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
} catch (error) {
|
||||||
|
if (error?.response?.status === 409) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
console.error('Error storing data:', error);
|
||||||
}
|
}
|
||||||
return null;
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function retrieveData(servers: string[], key: string): Promise<any | null> {
|
export async function retrieveData(servers: string[], key: string): Promise<any | null> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user