Fix S3 test: always merge with saved config, add debug logging
This commit is contained in:
parent
ae4360e85a
commit
89291a4baf
1 changed files with 8 additions and 8 deletions
16
server.js
16
server.js
|
|
@ -442,22 +442,22 @@ app.put("/api/s3/config", requireAdmin, (req, res) => {
|
|||
});
|
||||
|
||||
app.post("/api/s3/test", requireAdmin, async (req, res) => {
|
||||
// Support testing with submitted credentials (may not be saved yet)
|
||||
const { endpoint, region, bucket, accessKeyId, secretAccessKey } = req.body;
|
||||
// Merge submitted values with saved config — secret is often blank (keep existing)
|
||||
const saved = db.s3Config || {};
|
||||
const testCfg = {
|
||||
endpoint: endpoint || db.s3Config?.endpoint || "",
|
||||
region: region || db.s3Config?.region || "us-east-1",
|
||||
bucket: bucket || db.s3Config?.bucket || "",
|
||||
accessKeyId: accessKeyId || db.s3Config?.accessKeyId || "",
|
||||
secretAccessKey: secretAccessKey || db.s3Config?.secretAccessKey || "",
|
||||
endpoint: (req.body.endpoint || saved.endpoint || "").trim(),
|
||||
region: (req.body.region || saved.region || "us-east-1").trim(),
|
||||
bucket: (req.body.bucket || saved.bucket || "").trim(),
|
||||
accessKeyId: (req.body.accessKeyId || saved.accessKeyId || "").trim(),
|
||||
secretAccessKey: (req.body.secretAccessKey || saved.secretAccessKey || "").trim(),
|
||||
};
|
||||
console.log("[S3 Test] Config:", { endpoint: testCfg.endpoint, region: testCfg.region, bucket: testCfg.bucket, accessKeyId: testCfg.accessKeyId, hasSecret: !!testCfg.secretAccessKey });
|
||||
if (!testCfg.bucket || !testCfg.accessKeyId || !testCfg.secretAccessKey)
|
||||
return res.status(400).json({ success: false, error: "Bucket, Access Key ID, and Secret Key are required to test" });
|
||||
|
||||
const testClient = buildS3Client(testCfg);
|
||||
|
||||
try {
|
||||
// Test by checking if bucket exists and is accessible
|
||||
await testClient.send(new HeadBucketCommand({ Bucket: testCfg.bucket }));
|
||||
|
||||
res.json({ success: true, message: "✓ S3 connection confirmed! Credentials are valid and the bucket is accessible." });
|
||||
|
|
|
|||
Loading…
Reference in a new issue