Versão migrada do pacote antigo
This commit is contained in:
commit
eab9e5269f
17 changed files with 5304 additions and 0 deletions
93
ferramentas/mapear_minio.ts
Normal file
93
ferramentas/mapear_minio.ts
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
import fs from "node:fs"
|
||||
import path from "node:path"
|
||||
import dotenv from "dotenv"
|
||||
import * as Minio from "minio"
|
||||
|
||||
dotenv.config()
|
||||
|
||||
const pasta_src = path.resolve(process.cwd(), "src")
|
||||
const arquivoDestino = path.resolve(pasta_src, "estaticos.ts")
|
||||
|
||||
const endPoint = process.env.endPoint as string
|
||||
const port = Number(process.env.port) || 443
|
||||
const useSSL = process.env.useSSL === "true"
|
||||
const accessKey = process.env.accessKey as string
|
||||
const secretKey = process.env.secretKey as string
|
||||
const bucket = "estaticos"
|
||||
|
||||
if (!endPoint || !accessKey || !secretKey || !bucket) {
|
||||
console.error("Variáveis de ambiente do MinIO incompletas em .env")
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const minioClient = new Minio.Client({
|
||||
endPoint,
|
||||
port,
|
||||
useSSL,
|
||||
accessKey,
|
||||
secretKey,
|
||||
})
|
||||
|
||||
export const gerar = (async () => {
|
||||
const objectsList: string[] = []
|
||||
|
||||
const stream = minioClient.listObjectsV2(bucket, "", true)
|
||||
|
||||
stream.on("data", (obj) => {
|
||||
if (obj.name && !obj.name.endsWith("/")) {
|
||||
objectsList.push(`/${obj.name}`) // Minio doesn't return leading slashes usually
|
||||
}
|
||||
})
|
||||
|
||||
stream.on("end", () => {
|
||||
const arquivo_ts = `
|
||||
/**
|
||||
* URLs fixas de estáticos no bucket
|
||||
*/
|
||||
export const estaticos = ()=> (${(() => {
|
||||
type tp = {
|
||||
[key: string]: string | tp
|
||||
}
|
||||
|
||||
const arquivos = {} as tp
|
||||
|
||||
objectsList.sort((a, b) =>
|
||||
a.localeCompare(b, "pt-BR", { sensitivity: "base" }),
|
||||
) // Pre-sort the array alphabetically with pt-BR case-insensitivity
|
||||
|
||||
for (const arquivo of objectsList) {
|
||||
// arquivo already starts with '/'
|
||||
const partes = arquivo.slice(1).split("/")
|
||||
let pasta: any = arquivos
|
||||
for (const [i, parte] of partes.entries()) {
|
||||
if (i === partes.length - 1) {
|
||||
pasta[parte] =
|
||||
`~~~https://paiol.idz.one/estaticos${encodeURI(arquivo)}~~~`
|
||||
} else {
|
||||
pasta[parte] = pasta[parte] || {}
|
||||
pasta = pasta[parte]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return JSON.stringify(arquivos, null, 2)
|
||||
.replace(/"~~~/g, "'")
|
||||
.replace(/~~~"/g, "'")
|
||||
})()}) as const;
|
||||
`
|
||||
|
||||
// criar pasta de arquivo destino
|
||||
const pastaDestino = path.dirname(arquivoDestino)
|
||||
if (!fs.existsSync(pastaDestino)) {
|
||||
fs.mkdirSync(pastaDestino, { recursive: true })
|
||||
}
|
||||
|
||||
// escrever arquivo
|
||||
fs.writeFileSync(arquivoDestino, arquivo_ts)
|
||||
console.log("Arquivo gerado com sucesso")
|
||||
})
|
||||
|
||||
stream.on("error", (err) =>
|
||||
console.log("Erro ao listar objetos do MinIO:", err),
|
||||
)
|
||||
})()
|
||||
Loading…
Add table
Add a link
Reference in a new issue