Skip to content

Commit

Permalink
Credentials are now handled via a header. FormData is now native to n…
Browse files Browse the repository at this point in the history
…ode-fetch.
  • Loading branch information
gavoja committed Sep 5, 2022
1 parent 45679b7 commit 6c7f664
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 111 deletions.
22 changes: 14 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env node
import FormData from 'form-data'
import fs from 'fs'
import minimist from 'minimist'
import fetch from 'node-fetch'
import fetch, { FormData, File } from 'node-fetch'
import path from 'path'
import watch from 'simple-watcher'
import * as url from 'url'
Expand Down Expand Up @@ -69,11 +68,10 @@ Website:
// =============================================================================

async function post ({ archivePath, target, packmgrPath, checkIfUp }) {
const url = target + packmgrPath
const form = new FormData()
form.append('file', fs.createReadStream(archivePath))
form.append('force', 'true')
form.append('install', 'true')
form.set('file', new File([fs.readFileSync(archivePath)], { type: 'text/plain' }))
form.set('force', 'true')
form.set('install', 'true')

// Check if AEM is up and runnig.
if (checkIfUp && !await check(target)) {
Expand All @@ -82,7 +80,15 @@ async function post ({ archivePath, target, packmgrPath, checkIfUp }) {

const result = { target }
try {
const res = await fetch(url, { method: 'POST', body: form })
const urlObj = new URL(target + packmgrPath)
const url = urlObj.origin + urlObj.pathname
const fetchArgs = { method: 'POST', body: form }
if (urlObj.password) {
const credentials = Buffer.from(`${urlObj.username}:${urlObj.password}`).toString('base64')
fetchArgs.headers = { Authorization: `Basic ${credentials}` }
}

const res = await fetch(url, fetchArgs)

if (res.ok) {
const text = await res.text()
Expand Down Expand Up @@ -159,7 +165,7 @@ export async function * push (args) {
archive = pack.save()
if (archive.err) {
log.debug(archive.err)
await wait(100)
await wait(3000)
log.info('Failed to create ZIP, retrying...')
} else {
break
Expand Down
102 changes: 2 additions & 100 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aemsync",
"version": "5.0.1",
"version": "5.0.3",
"description": "The code and content synchronization for Sling / AEM (Adobe Experience Manager).",
"author": "Michal Kochel <[email protected]>",
"type": "module",
Expand All @@ -26,7 +26,6 @@
},
"dependencies": {
"adm-zip": "0.5.9",
"form-data": "4.0.0",
"globrex": "0.1.2",
"minimist": "1.2.6",
"node-fetch": "3.2.10",
Expand Down
4 changes: 3 additions & 1 deletion src/package.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import fs from 'fs'
import globrex from 'globrex'
import path from 'path'
import * as url from 'url'
import util from 'util'
import * as log from './log.js'
import Zip from './zip.js'

const DATA_PATH = path.resolve('./data')
const DIRNAME = url.fileURLToPath(new URL('..', import.meta.url))
const DATA_PATH = path.resolve(DIRNAME, 'data')
const PACKAGE_CONTENT_PATH = path.join(DATA_PATH, 'package-content')
const NT_FOLDER_PATH = path.join(DATA_PATH, 'nt-folder', '.content.xml')
const FILTER_ZIP_PATH = 'META-INF/vault/filter.xml'
Expand Down

0 comments on commit 6c7f664

Please sign in to comment.