Created
May 20, 2021 14:48
-
-
Save brutalzinn/adfa7f29cebf427f53bfe563129a085a to your computer and use it in GitHub Desktop.
to suelen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const root_dir = path.join(path.dirname(require.main.filename),'arquivos') | |
const fs = require('fs'); | |
const uuid = require('uuid').v4; | |
const criaEndereco = (destino, arquivoNome) => { | |
return path.join(root_dir, destino, arquivoNome); | |
} | |
const criaNome = (tipo) => { | |
const tipoTratado = tipo.split('/')[1]; | |
return `${uuid()}.${tipoTratado}`; | |
} | |
const move = async (temporario, definitivo) => { | |
return fs.renameSync(temporario, definitivo); | |
} | |
const substituir = async (temporario,dir,arquivo) => { | |
console.log('#######overwrite',temporario,dir,path.join(root_dir,dir,arquivo)) | |
return fs.renameSync(temporario, path.join(root_dir,dir,arquivo)); | |
} | |
const remove = async (arquivo,dir) => { | |
return fs.unlinkSync(path.join(root_dir,dir,arquivo)); | |
} | |
module.exports = { | |
criaEndereco, | |
substituir, | |
criaNome, | |
move, | |
remove | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment