-
-
Save dmitryshelomanov/74c885780d89457161b74507d5b44294 to your computer and use it in GitHub Desktop.
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 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