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);
|
||||
}
|
||||
|
||||
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> {
|
||||
const db = await Database.getInstance();
|
||||
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();
|
||||
}
|
||||
|
||||
// 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.
|
||||
const response = await axios.post(url, value, {
|
||||
headers: {
|
||||
@ -94,30 +103,17 @@ interface TestResponse {
|
||||
value: boolean;
|
||||
}
|
||||
|
||||
export async function testData(servers: string[], key: string): Promise<Record<string, boolean | null> | null> {
|
||||
const res: Record<string, boolean | null> = {};
|
||||
for (const server of servers) {
|
||||
res[server] = null;
|
||||
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
|
||||
export async function testData(url: string, key: string): Promise<boolean | null> {
|
||||
try {
|
||||
const response = await axios.get(url);
|
||||
if (response.status !== 200) {
|
||||
console.error(`Test response status: ${response.status}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
const response = await axios.get(url);
|
||||
if (response.status !== 200) {
|
||||
console.error(`${server}: Test response status: ${response.status}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const data: TestResponse = response.data;
|
||||
|
||||
res[server] = data.value;
|
||||
} catch (error) {
|
||||
console.error('Error retrieving data:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Error testing data:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user