diff --git a/functions.js b/functions.js index e49e97b..ffa30ee 100644 --- a/functions.js +++ b/functions.js @@ -176,7 +176,7 @@ const createDirIfNotExist = async (client, folder) => { * function [createUser] * @returns [string] status */ -const webdavTest = async (filePath) => { +const uploadDav = async (dirPath, filePath) => { // connect to webdav client = createClient( @@ -187,24 +187,15 @@ const webdavTest = async (filePath) => { digest: process.env.WEBDAV_USE_DIGEST == 'true' }) - // decide path - current_date = new Date(); - var dir_path = path.join( - process.env.WEBDAV_PATH_PREFIX, - current_date.getUTCFullYear().toString(), - current_date.getUTCMonth().toString(), - 'test' // TODO: replace with article slug - ) - // create directory if not exists - console.debug(`Loading ${dir_path}`) - await createDirIfNotExist(client, dir_path) + console.debug(`Loading ${dirPath}`) + await createDirIfNotExist(client, dirPath) // upload a file console.debug('Uploading file') s = fs.createReadStream(filePath) .pipe(client.createWriteStream( - path.join(dir_path, path.basename(filePath)) + path.join(dirPath, path.basename(filePath)) )) .on('finish', () => console.debug('Uploaded successfully.')) @@ -216,5 +207,5 @@ module.exports = { pushToGhost, mediumToGhost, generateUserData, - webdavTest + uploadDav } diff --git a/index.js b/index.js index 6ce12e8..90c87da 100755 --- a/index.js +++ b/index.js @@ -5,13 +5,14 @@ const dotenv = require('dotenv') dotenv.config() const program = require('commander'); +const path = require('path') const { fetchFromMedium, pushToGhost, mediumToGhost, generateUserData, - webdavTest, + uploadDav, } = require ('./functions'); program @@ -56,7 +57,15 @@ program.command('create-user ') program.command('webdav-test ') .description('[test command] upload stuff to WebDAV') .action(async (file) => { - webdavTest(file); + // decide path + current_date = new Date(); + var dir_path = path.join( + process.env.WEBDAV_PATH_PREFIX, + current_date.getUTCFullYear().toString(), + current_date.getUTCMonth().toString(), + 'test' // TODO: replace with article slug + ) + uploadDav(dir_path, file); }); program.parse(process.argv)