mirror of
https://github.com/ivabus/pantry
synced 2024-11-26 18:25:08 +03:00
add -s(ource) filter to ls-aws-s3.ts
This commit is contained in:
parent
ddc55b93f2
commit
5b760cbb07
1 changed files with 14 additions and 2 deletions
|
@ -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()
|
||||||
|
@ -80,4 +92,4 @@ function produceMatrix(objects: FileInfo[]): void {
|
||||||
}))
|
}))
|
||||||
output.sort((a, b) => a.project < b.project ? -1: 1)
|
output.sort((a, b) => a.project < b.project ? -1: 1)
|
||||||
console.table(output)
|
console.table(output)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue