Add (very rudimentary password check)
This also properly handles other errors if/when they come up
This commit is contained in:
parent
4cfea0ac3d
commit
406e54c018
3 changed files with 47 additions and 21 deletions
18
server.js
18
server.js
|
@ -139,7 +139,12 @@ app.ws('/ws/fetch-medium', (ws, req) => {
|
||||||
command = msg.split(' ')
|
command = msg.split(' ')
|
||||||
if (command.length == 3 && command[0] == 'fetch') {
|
if (command.length == 3 && command[0] == 'fetch') {
|
||||||
const postSlug = command[1]
|
const postSlug = command[1]
|
||||||
const mediumUrl = command[2]
|
const password = command[2]
|
||||||
|
|
||||||
|
if (password != process.env.SEANCE_PW) {
|
||||||
|
ws.send('error: Something went wrong. Please try again :(')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const postMetaFile = `${postSlug}.json`
|
const postMetaFile = `${postSlug}.json`
|
||||||
|
|
||||||
|
@ -183,9 +188,15 @@ app.ws('/ws/push-ghost', (ws, req) => {
|
||||||
console.log(`We got: ${msg}`)
|
console.log(`We got: ${msg}`)
|
||||||
|
|
||||||
command = msg.split(' ')
|
command = msg.split(' ')
|
||||||
if (command.length == 2 && command[0] == 'push') {
|
if (command.length == 3 && command[0] == 'push') {
|
||||||
const postSlug = command[1]
|
const postSlug = command[1]
|
||||||
|
|
||||||
|
// check password
|
||||||
|
if (command[2] != process.env.SEANCE_PW) {
|
||||||
|
ws.send('error: Something went wrong. Please try again :(')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Start the Seance session
|
// Start the Seance session
|
||||||
seance = new Seance()
|
seance = new Seance()
|
||||||
|
|
||||||
|
@ -207,6 +218,9 @@ app.ws('/ws/push-ghost', (ws, req) => {
|
||||||
console.info(`"${postSlug}" pushed successfully.`)
|
console.info(`"${postSlug}" pushed successfully.`)
|
||||||
ws.send(`done: ${postSlug}`)
|
ws.send(`done: ${postSlug}`)
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
ws.send('error: Malformed message')
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -11,6 +11,7 @@ function mediumFetch(e) {
|
||||||
|
|
||||||
const postSlug = document.querySelector('[data-post-slug]').dataset.postSlug
|
const postSlug = document.querySelector('[data-post-slug]').dataset.postSlug
|
||||||
const mediumUrl = document.querySelector('[data-post-mediumurl]').dataset.postMediumurl
|
const mediumUrl = document.querySelector('[data-post-mediumurl]').dataset.postMediumurl
|
||||||
|
var password = document.querySelector('input[name=password]').value
|
||||||
console.log('Fetching ' + postSlug)
|
console.log('Fetching ' + postSlug)
|
||||||
const socketProtocol = (window.location.protocol === 'https:' ? 'wss:' : 'ws:')
|
const socketProtocol = (window.location.protocol === 'https:' ? 'wss:' : 'ws:')
|
||||||
const socketUrl = socketProtocol + '//' + window.location.host + '/ws/fetch-medium/'
|
const socketUrl = socketProtocol + '//' + window.location.host + '/ws/fetch-medium/'
|
||||||
|
@ -30,7 +31,7 @@ function mediumFetch(e) {
|
||||||
statusDiv.appendChild(statusText)
|
statusDiv.appendChild(statusText)
|
||||||
|
|
||||||
socket.onopen = () => {
|
socket.onopen = () => {
|
||||||
socket.send('fetch ' + postSlug + ' ' + mediumUrl)
|
socket.send('fetch ' + postSlug + ' ' + password)
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.onmessage = m => {
|
socket.onmessage = m => {
|
||||||
|
@ -43,13 +44,22 @@ function mediumFetch(e) {
|
||||||
|
|
||||||
statusText.innerHTML = `<b>${command}: </b>${commandData}`
|
statusText.innerHTML = `<b>${command}: </b>${commandData}`
|
||||||
|
|
||||||
// if it's done, clean up
|
if (command == 'notification') {
|
||||||
if (command == 'done') {
|
addNotification(commandData)
|
||||||
|
} else if (command == 'done' || command == 'error') {
|
||||||
|
|
||||||
|
// if it's an error, say it
|
||||||
|
if (command == 'error') {
|
||||||
|
addNotification(commandData, className='is-danger')
|
||||||
|
} else {
|
||||||
|
// show alert
|
||||||
|
addNotification(`${postSlug} has been fetched successfully. You can now push it to Ghost`, 'is-success')
|
||||||
|
}
|
||||||
|
|
||||||
|
// since it's done, clean up
|
||||||
// remove statusbar
|
// remove statusbar
|
||||||
statusDiv.removeChild(statusText)
|
statusDiv.removeChild(statusText)
|
||||||
|
|
||||||
// show alert
|
|
||||||
addNotification(`${postSlug} has been fetched successfully. You can now push it to Ghost`, 'is-success')
|
|
||||||
|
|
||||||
// show buttons, change text and save slug
|
// show buttons, change text and save slug
|
||||||
for (i=0;i<statusDiv.children.length;i++) {
|
for (i=0;i<statusDiv.children.length;i++) {
|
||||||
|
@ -61,8 +71,6 @@ function mediumFetch(e) {
|
||||||
}
|
}
|
||||||
statusDiv.children[i].classList.remove('is-hidden')
|
statusDiv.children[i].classList.remove('is-hidden')
|
||||||
}
|
}
|
||||||
} else if (command == 'notification') {
|
|
||||||
addNotification(commandData)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -75,6 +83,7 @@ function ghostPush(e) {
|
||||||
if(e) { e.preventDefault() }
|
if(e) { e.preventDefault() }
|
||||||
|
|
||||||
const postSlug = document.querySelector('[data-post-slug]').dataset.postSlug
|
const postSlug = document.querySelector('[data-post-slug]').dataset.postSlug
|
||||||
|
var password = document.querySelector('input[name=password]').value
|
||||||
console.log('Pushing ' + postSlug)
|
console.log('Pushing ' + postSlug)
|
||||||
const socketProtocol = (window.location.protocol === 'https:' ? 'wss:' : 'ws:')
|
const socketProtocol = (window.location.protocol === 'https:' ? 'wss:' : 'ws:')
|
||||||
const socketUrl = socketProtocol + '//' + window.location.host + '/ws/push-ghost/'
|
const socketUrl = socketProtocol + '//' + window.location.host + '/ws/push-ghost/'
|
||||||
|
@ -94,7 +103,7 @@ function ghostPush(e) {
|
||||||
statusDiv.appendChild(statusText)
|
statusDiv.appendChild(statusText)
|
||||||
|
|
||||||
socket.onopen = () => {
|
socket.onopen = () => {
|
||||||
socket.send('push ' + postSlug)
|
socket.send('push ' + postSlug + ' ' + password)
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.onmessage = m => {
|
socket.onmessage = m => {
|
||||||
|
@ -108,14 +117,22 @@ function ghostPush(e) {
|
||||||
|
|
||||||
statusText.innerHTML = `<b>${command}: </b>${commandData}`
|
statusText.innerHTML = `<b>${command}: </b>${commandData}`
|
||||||
|
|
||||||
// if it's done, clean up
|
if (command == 'notification') {
|
||||||
if (command[0] == 'done') {
|
addNotification(commandData)
|
||||||
|
} else if (command == 'done' || command == 'error') {
|
||||||
|
|
||||||
|
// if it's an error, say it
|
||||||
|
if (command == 'error') {
|
||||||
|
addNotification(commandData, className='is-danger')
|
||||||
|
} else {
|
||||||
|
// show alert
|
||||||
|
addNotification(`${postSlug} has been pushed to Ghost`, 'is-success')
|
||||||
|
}
|
||||||
|
|
||||||
|
// since it's done, clean up
|
||||||
// remove statusbar
|
// remove statusbar
|
||||||
statusDiv.removeChild(statusText)
|
statusDiv.removeChild(statusText)
|
||||||
|
|
||||||
// show alert
|
|
||||||
addNotification(`${postSlug} has been pushed to Ghost`, 'is-success')
|
|
||||||
|
|
||||||
// show buttons and change text
|
// show buttons and change text
|
||||||
for (i=0;i<statusDiv.children.length;i++) {
|
for (i=0;i<statusDiv.children.length;i++) {
|
||||||
if (statusDiv.children[i].innerText.startsWith('Push')) {
|
if (statusDiv.children[i].innerText.startsWith('Push')) {
|
||||||
|
@ -123,12 +140,6 @@ function ghostPush(e) {
|
||||||
}
|
}
|
||||||
statusDiv.children[i].classList.remove('is-hidden')
|
statusDiv.children[i].classList.remove('is-hidden')
|
||||||
}
|
}
|
||||||
} else if (command == 'notification') {
|
|
||||||
var n = document.createElement('div')
|
|
||||||
n.classList.add('notification')
|
|
||||||
n.classList.add('is-warning')
|
|
||||||
n.innerHTML = commandData
|
|
||||||
document.getElementById('notifications').appendChild(n)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
<p v-if="post.subtitle" class="subtitle is-6">{{ post.subtitle }}</p>
|
<p v-if="post.subtitle" class="subtitle is-6">{{ post.subtitle }}</p>
|
||||||
<p>by {{ post.author }}</p>
|
<p>by {{ post.author }}</p>
|
||||||
<div class="notifications" id="notifications"></div>
|
<div class="notifications" id="notifications"></div>
|
||||||
|
<input type="password" name="password" placeholder="password" class="input is-primary is-small"/>
|
||||||
</div>
|
</div>
|
||||||
<footer class="card-footer" id="statusbar">
|
<footer class="card-footer" id="statusbar">
|
||||||
<a :href="post.mediumUrl" v-if="post.mediumUrl" class="card-footer-item">View on Medium</a>
|
<a :href="post.mediumUrl" v-if="post.mediumUrl" class="card-footer-item">View on Medium</a>
|
||||||
|
|
Loading…
Reference in a new issue