add download script

This commit is contained in:
Joshua 2022-10-12 20:40:03 +02:00
parent b6e3270f4e
commit 82a1b4c08d
3 changed files with 52 additions and 0 deletions

View file

@ -9,9 +9,13 @@ export {
relative,
} from "https://deno.land/std@0.135.0/path/mod.ts";
export { download } from "https://deno.land/x/download@v1.0.1/mod.ts";
export {
ensureFile,
ensureFileSync,
ensureDirSync,
} from "https://deno.land/std@0.135.0/fs/mod.ts";
export { default as serve } from "https://deno.land/x/static_files@1.1.6/mod.ts";

View file

@ -23,6 +23,7 @@ scripts:
cmd:
- vr s3
- vr routes
- vr download
routes:
desc: Generate the Routes used for the Project
@ -31,3 +32,6 @@ scripts:
s3:
desc: Generate S3 Routes
cmd: deno run --unstable -A --no-check --no-prompt ./scripts/s3.ts
download:
desc: Download Files from S3
cmd: deno run --unstable -A ./scripts/download.ts

44
scripts/download.ts Normal file
View file

@ -0,0 +1,44 @@
import { ensureFileSync, ensureDirSync, download, wait } from "../deps.ts";
import S3Files from "../src/generated/s3.ts";
if (!S3Files) {
throw new Error('This File depends on the Index generated by "vr s3", please run that and try again.')
}
const IMAGE_FOLDER_NAME = 'dreamland-assets'
const ImageSpinner = wait({
text: 'Downloading Files from S3...',
spinner: 'aesthetic'
})
async function downloadFiles(Files: typeof S3Files) {
ensureDirSync(`../src/generated/${IMAGE_FOLDER_NAME}`)
try {
await Files.forEach(async (file) => {
ImageSpinner.text = `Downloading ${file.key}`
ensureFileSync(`./src/generated/${IMAGE_FOLDER_NAME}/${file.key}`)
return await download(file.url, {
dir: `./src/generated/${IMAGE_FOLDER_NAME}`,
file: file.key,
})
})
} catch (error) {
return console.error(error)
}
}
if (import.meta.main) {
try {
await downloadFiles(S3Files)
} catch (error) {
console.error(error)
ImageSpinner.fail("Something went wrong.")
Deno.exit(1)
}
ImageSpinner.succeed("Downloaded Files from S3.")
Deno.exit(0)
}