add -s(ource) filter to ls-aws-s3.ts

This commit is contained in:
Jacob Heider 2022-10-04 01:24:48 -04:00
parent 07c7e38802
commit 7110059093

View file

@ -16,7 +16,11 @@ import { format }from "deno/datetime/mod.ts"
const sortByModified = Deno.args.includes("-m") const sortByModified = Deno.args.includes("-m")
const reverse = Deno.args.includes("-r") const reverse = Deno.args.includes("-r")
const fullMatrix = Deno.args.includes("-x") const fullMatrix = Deno.args.includes("-x")
const source = Deno.args.includes("-s")
if (source && fullMatrix) {
throw new Error("incompatible flags (-x -s)")
}
const s3 = new S3({ const s3 = new S3({
accessKeyID: Deno.env.get("AWS_ACCESS_KEY_ID")!, accessKeyID: Deno.env.get("AWS_ACCESS_KEY_ID")!,
@ -26,7 +30,7 @@ const s3 = new S3({
const bucket = s3.getBucket(Deno.env.get("AWS_S3_BUCKET")!) const bucket = s3.getBucket(Deno.env.get("AWS_S3_BUCKET")!)
const output: FileInfo[] = [] let output: FileInfo[] = []
for await(const obj of bucket.listAllObjects({ batchSize: 200 })) { for await(const obj of bucket.listAllObjects({ batchSize: 200 })) {
const { key, lastModified } = obj const { key, lastModified } = obj
@ -37,6 +41,14 @@ for await(const obj of bucket.listAllObjects({ batchSize: 200 })) {
if (fullMatrix) { if (fullMatrix) {
produceMatrix(output) produceMatrix(output)
} else { } else {
output = output.filter(x => {
const match = x.key.match(new RegExp("/(darwin|linux)/(aarch64|x86-64)/v.*\.tar\.(x|g)z"))
switch (source) {
case true: return !match
case false: return match
}
})
output.sort((a, b) => { output.sort((a, b) => {
switch (sortByModified) { switch (sortByModified) {
case true: return a.lastModified.valueOf() - b.lastModified.valueOf() case true: return a.lastModified.valueOf() - b.lastModified.valueOf()