diff --git a/cmd/s3-genindex/main.go b/cmd/s3-genindex/main.go index 04b8fea..58c37b8 100644 --- a/cmd/s3-genindex/main.go +++ b/cmd/s3-genindex/main.go @@ -11,6 +11,7 @@ import ( "regexp" "sort" "strings" + "time" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/credentials" @@ -61,6 +62,15 @@ func parseS3URL(s3URL string) (*S3Config, error) { // processS3Bucket processes an S3 bucket and generates index files func processS3Bucket(s3Config *S3Config, opts *indexgen.Options) error { + if opts.DryRun { + // In dry run mode, just show what would be done without connecting + fmt.Printf("Would connect to S3 endpoint: %s\n", s3Config.Endpoint) + fmt.Printf("Would list objects in bucket: %s\n", s3Config.Bucket) + fmt.Printf("Would write S3 index file: %s\n", opts.OutputFile) + fmt.Printf("Note: Dry run mode - no actual S3 connection made\n") + return nil + } + // Get credentials from environment variables accessKey := os.Getenv("AWS_ACCESS_KEY_ID") secretKey := os.Getenv("AWS_SECRET_ACCESS_KEY") @@ -126,15 +136,16 @@ func processS3Bucket(s3Config *S3Config, opts *indexgen.Options) error { } entry := indexgen.FileEntry{ - Name: keyName, - Path: keyName, - IsDir: false, - Size: *obj.Size, - ModTime: *obj.LastModified, - IsSymlink: false, - IconType: indexgen.GetIconType(keyName), - SizePretty: indexgen.PrettySize(*obj.Size), - ModTimeISO: obj.LastModified.Format("2006-01-02T15:04:05Z"), + Name: keyName, + Path: keyName, + IsDir: false, + Size: *obj.Size, + ModTime: *obj.LastModified, + IsSymlink: false, + IconType: indexgen.GetIconType(keyName), + SizePretty: indexgen.PrettySize(*obj.Size), + ModTimeISO: obj.LastModified.Format(time.RFC3339), + ModTimeHuman: obj.LastModified.Format(time.RFC822), } // Set CSS class based on file type @@ -193,15 +204,15 @@ func generateS3HTML(entries []indexgen.FileEntry, opts *indexgen.Options) error // Prepare template data (similar to ProcessDir in indexgen) data := struct { - DirName string - Entries []indexgen.FileEntry - TopDir string - Hostname string + DirName string + Entries []indexgen.FileEntry + DirAppend bool + OutputFile string }{ - DirName: opts.TopDir, // Use bucket name as directory name - Entries: entries, - TopDir: opts.TopDir, - Hostname: "S3 Bucket", // Could be improved to show actual endpoint + DirName: opts.TopDir, // Use bucket name as directory name + Entries: entries, + DirAppend: opts.DirAppend, + OutputFile: opts.OutputFile, } // Create output file