Fix Clouddrop IP folders and concurrent log creation verification
CI / verify (push) Canceled after 0s

This commit is contained in:
Sucukdeluxe committed 2026-10-15 04:33:52 +02:00
1 parent 345870dcc9
commit bc4a718210
3 files changed
+22 -17

No files matched your search

+20 -15
View File
@@ -61,15 +61,20 @@ class ClouddropLogApi {
|| Number(expires) <= Date.now() || !/^[a-f0-9]{64}$/.test(signature || '') || extra !== undefined) {
throw new CloudLogError('INVALID_RESPONSE');
}
const response = await this.request('https://api64.ipify.org?format=json', {
signal, maxRedirections: 0, headersTimeout: 15000, bodyTimeout: 15000,
headers: { Accept: 'application/json' }
});
const text = await response.body.text();
let ip;
try { ip = JSON.parse(text).ip; } catch {}
if (response.statusCode !== 200 || !isIP(ip || '')) throw new CloudLogError('IP_UNAVAILABLE');
return { accountId, ip, folderName: ip.replaceAll(':', '_') };
for (const endpoint of ['https://api.ipify.org?format=json', 'https://api64.ipify.org?format=json']) {
try {
const response = await this.request(endpoint, {
signal, maxRedirections: 0, headersTimeout: 10000, bodyTimeout: 10000,
headers: { Accept: 'application/json' }
});
const text = await response.body.text();
const ip = JSON.parse(text).ip;
if (response.statusCode === 200 && isIP(ip || '')) return { accountId, ip, folderName: ip };
} catch {
if (signal?.aborted) throw new CloudLogError('IP_UNAVAILABLE');
}
}
throw new CloudLogError('IP_UNAVAILABLE');
}
async ensureFolder(name, signal) {
@@ -91,6 +96,7 @@ class ClouddropLogApi {
}
async createFile(folderId, name, id, signal) {
const verificationRoute = `/check-duplicate?parent=${encodeURIComponent(folderId)}&filename=${encodeURIComponent(name)}`;
let created;
try {
created = await this.call('/create-file', {
@@ -99,14 +105,13 @@ class ClouddropLogApi {
});
} catch (error) {
if (error.status !== 409) throw error;
const existing = await this.call(`/files?parent=${encodeURIComponent(folderId)}&limit=2500&sync=${encodeURIComponent(id)}`, { signal });
const file = existing.files?.find(item => item.filename === name && item.parentId === folderId && !item.isFolder);
if (!file) throw error;
created = { id: file.id, filename: file.filename };
const existing = await this.call(verificationRoute, { signal });
if (!existing.exists || !existing.existingId) throw error;
created = { id: existing.existingId, filename: name };
}
if (!created.id || created.filename !== name) throw new CloudLogError('INVALID_RESPONSE');
const listing = await this.call(`/files?parent=${encodeURIComponent(folderId)}&limit=2500&sync=${encodeURIComponent(id)}`, { signal });
if (!Array.isArray(listing.files) || !listing.files.some(file => file.id === created.id && file.parentId === folderId)) {
const verification = await this.call(verificationRoute, { signal });
if (verification.exists !== true || verification.existingId !== created.id) {
throw new CloudLogError('UNRESTRICTED_KEY_REQUIRED');
}
return String(created.id);