mirror of
https://github.com/ivabus/pantry
synced 2024-11-27 02:35: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()
|
||||||
|
|
Loading…
Reference in a new issue