🌳
pt0/deployF/servicesF/minioF/minioActionsF.mts
1import * as _ from 'lodash-es'
2import fs from 'fs'
3import path from 'path'
13export const creds = () => {
14 const {consoleHostname, accessKeyId, secretAccessKey} = minioKubeCtx.getStore()!
15 console.log(`
16 ${consoleHostname} ${accessKeyId} / ${secretAccessKey}
17 `.trim())
20export const ls = async () => {
21 const {bucket_name} = minioKubeCtx.getStore()!
22 const allPaths = _.map(await getBucketPaths({bucket_name}), 'Key')
23 const topDirs = _.chain(allPaths).map((path) => _.split(path, '/')[0]).uniq().value()
24 // console.log({bucket_name}); process.exit()
25 betLog({topDirs})
28export const deldir = async () => {
29 const {bucket_name} = minioKubeCtx.getStore()!
30 const dirToDel = 'og4db'
31 const allPaths = _.map(await getBucketPaths({bucket_name}), 'Key')
32 const pathsToDelete = _.filter(allPaths, (path) => _.startsWith(path, `${dirToDel}/`))
33 if (_.isEmpty(pathsToDelete)) return betLog({msg: 'no paths to delete', dirToDel})
34 const {deleted} = await deleteObjects({bucket_name, keysA: pathsToDelete as string[]})
35 betLog({deleted, dirToDel})
38export const uploadfile = async () => {
39 const {bucket_name} = minioKubeCtx.getStore()!
40 const localPath = process.argv[4]
41 assertDefined(localPath, {localPath})
42 throwIf(() => !fs.existsSync(localPath), {localPath})
44 const key = 'uploads/' + path.basename(localPath)
45 const body = fs.readFileSync(localPath)
47 await putObject({bucket_name, key, body})
49 const fetched = await getObjectBody({bucket_name, key})
51 throwIf(() => !body.equals(fetched), {key, fetchedLen: fetched.length, bodyLen: body.length})
52 betLog({uploaded: key, verified: true, bytes: body.length})
54uploadfile.cliAcceptsPositional = true