设置登录

进一步完善日志
This commit is contained in:
CN-JS-HuiBai
2026-04-03 22:23:47 +08:00
parent 84c5b8f858
commit e30736c3e7
2 changed files with 123 additions and 13 deletions

View File

@@ -451,13 +451,15 @@ const clearConvertCache = () => {
app.get('/api/buckets', async (req, res) => {
try {
const auth = extractS3Credentials(req);
console.log(`[s3] list buckets start endpoint=${defaultS3ClientConfig.endpoint || 'aws-default'} region=${defaultS3ClientConfig.region} authProvided=${Boolean(auth.username)}`);
const s3Client = createS3Client(auth);
const command = new ListBucketsCommand({});
const response = await s3Client.send(command);
const buckets = response.Buckets || [];
console.log(`[s3] list buckets complete count=${buckets.length}`);
res.json({ buckets });
} catch (error) {
console.error('Error listing buckets:', error);
console.error('[s3] list buckets failed:', error);
res.status(500).json({ error: 'Failed to list buckets', detail: error.message });
}
});
@@ -473,14 +475,21 @@ app.get('/api/videos', async (req, res) => {
const auth = extractS3Credentials(req);
const s3Client = createS3Client(auth);
let continuationToken;
let pageNumber = 0;
console.log(`[s3] scan bucket start bucket=${bucket} endpoint=${defaultS3ClientConfig.endpoint || 'aws-default'} authProvided=${Boolean(auth.username)}`);
do {
pageNumber += 1;
console.log(`[s3] scan bucket page request bucket=${bucket} page=${pageNumber} continuationToken=${continuationToken || 'none'}`);
const command = new ListObjectsV2Command({
Bucket: bucket,
ContinuationToken: continuationToken,
});
const response = await s3Client.send(command);
allObjects.push(...(response.Contents || []));
const pageItems = response.Contents || [];
allObjects.push(...pageItems);
console.log(`[s3] scan bucket page result bucket=${bucket} page=${pageNumber} objects=${pageItems.length} truncated=${Boolean(response.IsTruncated)} nextToken=${response.NextContinuationToken || 'none'} scannedTotal=${allObjects.length}`);
continuationToken = response.IsTruncated ? response.NextContinuationToken : undefined;
} while (continuationToken);
@@ -499,9 +508,10 @@ app.get('/api/videos', async (req, res) => {
return videoExtensions.some(ext => lowerKey.endsWith(ext));
});
console.log(`[s3] scan bucket complete bucket=${bucket} pages=${pageNumber} objects=${allObjects.length} videos=${videos.length}`);
res.json({ videos });
} catch (error) {
console.error('Error fetching videos:', error);
console.error(`[s3] scan bucket failed bucket=${req.query.bucket || BUCKET_NAME || 'unknown'}:`, error);
res.status(500).json({ error: 'Failed to fetch videos from S3', detail: error.message });
}
});