Updating testData in storage
All checks were successful
Build and Push to Registry / build-and-push (push) Successful in 2m15s
All checks were successful
Build and Push to Registry / build-and-push (push) Successful in 2m15s
This commit is contained in:
parent
5fc485e233
commit
457994c506
@ -1076,12 +1076,6 @@ export default class Services {
|
|||||||
return await retrieveData(storages, hash);
|
return await retrieveData(storages, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async testDataInStorage(hash: string): Promise<Record<string, boolean | null> | null> {
|
|
||||||
const storages = [STORAGEURL];
|
|
||||||
|
|
||||||
return await testData(storages, hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getDiffByValueFromDb(hash: string): Promise<UserDiff | null> {
|
public async getDiffByValueFromDb(hash: string): Promise<UserDiff | null> {
|
||||||
const db = await Database.getInstance();
|
const db = await Database.getInstance();
|
||||||
const diff = await db.getObject('diffs', hash);
|
const diff = await db.getObject('diffs', hash);
|
||||||
|
@ -20,6 +20,15 @@ export async function storeData(servers: string[], key: string, value: Blob, ttl
|
|||||||
url = urlObj.toString();
|
url = urlObj.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test first that data is not already stored
|
||||||
|
const testResponse = await testData(url, key);
|
||||||
|
if (testResponse) {
|
||||||
|
console.log('Data already stored:', key);
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
console.log('Data not stored for server:', key, server);
|
||||||
|
}
|
||||||
|
|
||||||
// Send the encrypted ArrayBuffer as the raw request body.
|
// Send the encrypted ArrayBuffer as the raw request body.
|
||||||
const response = await axios.post(url, value, {
|
const response = await axios.post(url, value, {
|
||||||
headers: {
|
headers: {
|
||||||
@ -94,30 +103,17 @@ interface TestResponse {
|
|||||||
value: boolean;
|
value: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function testData(servers: string[], key: string): Promise<Record<string, boolean | null> | null> {
|
export async function testData(url: string, key: string): Promise<boolean | null> {
|
||||||
const res: Record<string, boolean | null> = {};
|
|
||||||
for (const server of servers) {
|
|
||||||
res[server] = null;
|
|
||||||
try {
|
try {
|
||||||
// Handle relative paths (for development proxy) vs absolute URLs (for production)
|
|
||||||
const url = server.startsWith('/')
|
|
||||||
? `${server}/test/${key}` // Relative path - use as-is for proxy
|
|
||||||
: new URL(`${server}/test/${key}`).toString(); // Absolute URL - construct properly
|
|
||||||
|
|
||||||
const response = await axios.get(url);
|
const response = await axios.get(url);
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
console.error(`${server}: Test response status: ${response.status}`);
|
console.error(`Test response status: ${response.status}`);
|
||||||
continue;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const data: TestResponse = response.data;
|
return true;
|
||||||
|
|
||||||
res[server] = data.value;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error retrieving data:', error);
|
console.error('Error testing data:', error);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user