Skip to content

Instantly share code, notes, and snippets.

@dmitryshelomanov
Created December 12, 2017 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitryshelomanov/74c885780d89457161b74507d5b44294 to your computer and use it in GitHub Desktop.
Save dmitryshelomanov/74c885780d89457161b74507d5b44294 to your computer and use it in GitHub Desktop.
const debug = require('debug')('banner:uploadBanner')
const fs = require('mz/fs')
const path = require('path')
const {
isZipFile,
notEmptyFile,
uuid,
decompress,
folderTree
} = require('../../helpers')
const tempPath = name => ({
archive: path.resolve(__dirname, `..`, `..`, `..`, `tmp/archives/${uuid()}--${name}`),
decompose: path.resolve(__dirname, `..`, `..`, `..`, `tmp/decompress/${uuid()}`)
})
async function lastLoaded(ctx) {
const { files } = ctx.request
const { archive, decompose } = tempPath(files.archive.name)
await fs.rename(files.archive.path, archive)
await decompress(archive, decompose)
ctx.body = folderTree(decompose)
}
module.exports = (router, path) => router.post(
path,
notEmptyFile, isZipFile, lastLoaded
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment