Debug: list buckets first
This commit is contained in:
parent
d2c7cee1e8
commit
1dd8563450
1 changed files with 19 additions and 2 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { S3Client, PutObjectCommand, ListObjectsV2Command } from "@aws-sdk/client-s3";
|
import { S3Client, PutObjectCommand, ListObjectsV2Command, ListBucketsCommand } from "@aws-sdk/client-s3";
|
||||||
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
|
||||||
|
|
@ -18,14 +18,31 @@ const client = new S3Client({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const clientNoBucket = new S3Client({
|
||||||
|
region: "auto",
|
||||||
|
endpoint: `https://${R2.accountId}.r2.cloudflarestorage.com`,
|
||||||
|
credentials: {
|
||||||
|
accessKeyId: R2.accessKeyId,
|
||||||
|
secretAccessKey: R2.secretKey,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const baseUrl = `https://pub-37a76fd657c94d1dbc521a109c087a11.r2.dev/tia`;
|
const baseUrl = `https://pub-37a76fd657c94d1dbc521a109c087a11.r2.dev/tia`;
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
try {
|
try {
|
||||||
const command = new ListObjectsV2Command({ Bucket: R2.bucket });
|
// First try listing buckets
|
||||||
|
const bucketsCmd = new ListBucketsCommand({});
|
||||||
|
const bucketsRes = await clientNoBucket.send(bucketsCmd);
|
||||||
|
console.log("Buckets:", bucketsRes.Buckets);
|
||||||
|
|
||||||
|
// Then list objects in "tia" bucket
|
||||||
|
const command = new ListObjectsV2Command({ Bucket: "tia" });
|
||||||
const response = await client.send(command);
|
const response = await client.send(command);
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
success: true,
|
success: true,
|
||||||
|
buckets: bucketsRes.Buckets,
|
||||||
count: response.Contents?.length || 0,
|
count: response.Contents?.length || 0,
|
||||||
items: response.Contents?.map((o) => ({
|
items: response.Contents?.map((o) => ({
|
||||||
key: o.Key,
|
key: o.Key,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue