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) => {
|
app.post("/api/s3/test", requireAdmin, async (req, res) => {
|
||||||
// Support testing with submitted credentials (may not be saved yet)
|
// Merge submitted values with saved config — secret is often blank (keep existing)
|
||||||
const { endpoint, region, bucket, accessKeyId, secretAccessKey } = req.body;
|
const saved = db.s3Config || {};
|
||||||
const testCfg = {
|
const testCfg = {
|
||||||
endpoint: endpoint || db.s3Config?.endpoint || "",
|
endpoint: (req.body.endpoint || saved.endpoint || "").trim(),
|
||||||
region: region || db.s3Config?.region || "us-east-1",
|
region: (req.body.region || saved.region || "us-east-1").trim(),
|
||||||
bucket: bucket || db.s3Config?.bucket || "",
|
bucket: (req.body.bucket || saved.bucket || "").trim(),
|
||||||
accessKeyId: accessKeyId || db.s3Config?.accessKeyId || "",
|
accessKeyId: (req.body.accessKeyId || saved.accessKeyId || "").trim(),
|
||||||
secretAccessKey: secretAccessKey || db.s3Config?.secretAccessKey || "",
|
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)
|
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" });
|
return res.status(400).json({ success: false, error: "Bucket, Access Key ID, and Secret Key are required to test" });
|
||||||
|
|
||||||
const testClient = buildS3Client(testCfg);
|
const testClient = buildS3Client(testCfg);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Test by checking if bucket exists and is accessible
|
|
||||||
await testClient.send(new HeadBucketCommand({ Bucket: testCfg.bucket }));
|
await testClient.send(new HeadBucketCommand({ Bucket: testCfg.bucket }));
|
||||||
|
|
||||||
res.json({ success: true, message: "✓ S3 connection confirmed! Credentials are valid and the bucket is accessible." });
|
res.json({ success: true, message: "✓ S3 connection confirmed! Credentials are valid and the bucket is accessible." });
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue