mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-02 10:52:27 +00:00
Merge pull request #1682 from PR0M3TH3AN/fix-storage-default-connections-7359024264233326996
Fix multiple default storage connections issue
This commit is contained in:
2 files changed
+27
No files matched your search
@@ -418,6 +418,16 @@ export class StorageService {
|
||||
account.connections = {};
|
||||
}
|
||||
|
||||
// If this connection is being set as default, unset others
|
||||
if (meta.defaultForUploads) {
|
||||
for (const key in account.connections) {
|
||||
const conn = account.connections[key];
|
||||
if (conn.meta) {
|
||||
conn.meta.defaultForUploads = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
account.connections[connectionId] = {
|
||||
id: connectionId,
|
||||
provider: payload.provider || meta.provider,
|
||||
|
||||
@@ -155,4 +155,21 @@ describe("StorageService", () => {
|
||||
assert.strictEqual(c1.meta.defaultForUploads, false);
|
||||
assert.strictEqual(c2.meta.defaultForUploads, true);
|
||||
});
|
||||
|
||||
test("saveConnection() with defaultForUploads=true clears other defaults", async () => {
|
||||
await storageService.unlock(pubkey, { signer: mockSigner });
|
||||
|
||||
// Save first connection as default
|
||||
await storageService.saveConnection(pubkey, "conn_1", { provider: PROVIDERS.R2 }, { defaultForUploads: true });
|
||||
|
||||
// Save second connection as default
|
||||
await storageService.saveConnection(pubkey, "conn_2", { provider: PROVIDERS.S3 }, { defaultForUploads: true });
|
||||
|
||||
const conns = await storageService.listConnections(pubkey);
|
||||
const c1 = conns.find(c => c.id === "conn_1");
|
||||
const c2 = conns.find(c => c.id === "conn_2");
|
||||
|
||||
assert.strictEqual(c1.meta.defaultForUploads, false);
|
||||
assert.strictEqual(c2.meta.defaultForUploads, true);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user