feat: download via standard https
not quite working yet though
This commit is contained in:
parent
f0d68dc68e
commit
740dd892f9
2 changed files with 33 additions and 10 deletions
10
README.md
10
README.md
|
@ -4,6 +4,14 @@ Fetches all PDFs for upcoming events, concatenates them and uploads them as atta
|
||||||
|
|
||||||
Based on https://github.com/churchtools/churchtools-js-client/tree/master/examples/Node.js
|
Based on https://github.com/churchtools/churchtools-js-client/tree/master/examples/Node.js
|
||||||
|
|
||||||
|
## Planned Features
|
||||||
|
|
||||||
|
- concatenate songs
|
||||||
|
- convert uploaded office documents to PDF
|
||||||
|
|
||||||
|
Later as server cronjob
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
- `npm run setup` (npm install, copy and fill in settings.js.example to settings.js)
|
- `npm run setup` (equivalent to `npm install` and copy settings.js.example to settings.js)
|
||||||
|
- fill in values in `settings.js`
|
||||||
- `npm start`
|
- `npm start`
|
||||||
|
|
29
index.js
29
index.js
|
@ -5,8 +5,10 @@ const axiosCookieJarSupport = require('axios-cookiejar-support');
|
||||||
const tough = require('tough-cookie');
|
const tough = require('tough-cookie');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
|
const cookieJar = new tough.CookieJar();
|
||||||
|
|
||||||
function initChurchToolsClient() {
|
function initChurchToolsClient() {
|
||||||
churchtoolsClient.setCookieJar(axiosCookieJarSupport.wrapper, new tough.CookieJar());
|
churchtoolsClient.setCookieJar(axiosCookieJarSupport.wrapper, cookieJar);
|
||||||
churchtoolsClient.setBaseUrl(SETTINGS.BASEURL);
|
churchtoolsClient.setBaseUrl(SETTINGS.BASEURL);
|
||||||
// Logging can be activated to either LOG_LEVEL_NONE (no logging at all, default),
|
// Logging can be activated to either LOG_LEVEL_NONE (no logging at all, default),
|
||||||
// LOG_LEVEL_DEBUG (outputs every request and response including request/response data)
|
// LOG_LEVEL_DEBUG (outputs every request and response including request/response data)
|
||||||
|
@ -15,7 +17,6 @@ function initChurchToolsClient() {
|
||||||
activateLogging(LOG_LEVEL_INFO);
|
activateLogging(LOG_LEVEL_INFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
function login() {
|
function login() {
|
||||||
// if we have a login token, we use this
|
// if we have a login token, we use this
|
||||||
if (SETTINGS.TOKEN) {
|
if (SETTINGS.TOKEN) {
|
||||||
|
@ -58,13 +59,27 @@ async function mergeEventSongs(event) {
|
||||||
Promise.allSettled(result)
|
Promise.allSettled(result)
|
||||||
).then(result =>
|
).then(result =>
|
||||||
result.map(song => song.value.files.find(f => f.name.includes("Akkorde")))
|
result.map(song => song.value.files.find(f => f.name.includes("Akkorde")))
|
||||||
.map(f =>
|
.map(f => {
|
||||||
churchtoolsClient.get(f.fileUrl).then(file => {
|
// https://github.com/churchtools/churchtools-js-client/issues/25
|
||||||
filename = `${date}/${f.name}`
|
filename = `${date}/${f.name}`
|
||||||
fs.createWriteStream(filename).write(file)
|
const url = f.fileUrl
|
||||||
return filename
|
const file = fs.createWriteStream(filename);
|
||||||
|
https.get(
|
||||||
|
url,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Cookie: await cookieJar.getCookieStringSync()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(response) => {
|
||||||
|
response.pipe(file);
|
||||||
|
file.on("finish", () => {
|
||||||
|
file.close();
|
||||||
|
console.log("Download Completed");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
})
|
})
|
||||||
)
|
|
||||||
).then(result =>
|
).then(result =>
|
||||||
Promise.allSettled(result)
|
Promise.allSettled(result)
|
||||||
).then(result => {
|
).then(result => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue