Compare commits

...

5 Commits

Author SHA1 Message Date
Arjan Adriaanse abaa3b2ae9 clarify credentials 2022-08-01 13:20:20 +02:00
Kiara Grouwstra d5b38ea3ed cannot set media post id... 2022-02-09 21:34:51 +01:00
Kiara Grouwstra d78066b90a minor debugging edits 2022-02-09 21:32:16 +01:00
Kiara Grouwstra f3efbcbc63 actually print errors 2022-01-03 21:36:47 +01:00
Kiara Grouwstra 81c7890e03 debug prints 2022-01-03 18:47:43 +01:00
3 changed files with 36 additions and 18 deletions

View File

@ -31,17 +31,24 @@ requires setting environment variables, for example:
```
export WINGS_ENDPOINT=https://api.wings.dev
export WINGS_PROJECT=amsterdam.bij1.org
export WINGS_PROJECT=<PROJECT_ID>
export WINGS_APP_KEY=<APP_KEY>
```
These credentials can be generated by adding an App in the Wings admin
backend.
## `yarn migrate`
Converts all articles and pages that do not exist in WordPress yet and
publishes them along with their media, requires setting environment variables, for example:
publishes them along with their media, requires setting environment
variables, for example:
```
export WP_ENDPOINT=http://localhost:8000/wp-json
export WP_USER=<user>
export WP_PASSWORD=<pw>
export WP_USER=<USERNAME>
export WP_PASSWORD=<APPLICATION_PASSWORD>
```
Note that using this API requires a specific application password
which can be generated from the user management page.

View File

@ -7,7 +7,7 @@ console.log(query);
got.post(process.env.WINGS_ENDPOINT || 'https://api.wings.dev', {
headers: {
"Authorization": "Bearer " + process.env.WINGS_APP_KEY,
"x-wings-app-domain": process.env.WINGS_PROJECT
"X-Wings-Project": process.env.WINGS_PROJECT
},
json: {query}
}).json().then((data) => {

View File

@ -7,6 +7,10 @@ import path from "path";
import { renderer, media } from './blocks';
import { data } from '../content';
console.log(`endpoint: ${process.env.WP_ENDPOINT}`);
console.log(`username: ${process.env.WP_USER}`);
console.log(`password: ${process.env.WP_PASSWORD}`);
const wp = new WPAPI({
endpoint: process.env.WP_ENDPOINT,
username: process.env.WP_USER,
@ -21,7 +25,7 @@ const migrate = async (node, resource) => {
console.log(`skipping "${node.slug}"`)
return
}
const mobiledoc = JSON.parse(node.content)
const rendered = renderer.render(mobiledoc);
const mediaIds = await Promise.all(media.map(async (block) => {
@ -38,14 +42,16 @@ const migrate = async (node, resource) => {
return id;
}
catch (e) {
console.error(`failed to upload "${block.attributes.href}"`)
console.error(`Failed to download/upload "${block.attributes.href}" due to error: ${e.message}`)
}
}));
})).catch((e) => {
console.error(`upload error: ${e.message}`);
});
media.length = 0;
let featured = null;
const { url, alt, caption } = node.image ||
node.featured.image || {}
node.featured.image || {};
try {
if (url) {
featured = await wp.media()
@ -58,7 +64,7 @@ const migrate = async (node, resource) => {
}
}
catch (e) {
console.error(`failed to upload featured "${url}"`)
console.error(`failed to upload featured "${url}" due to error: ${e.message}`)
}
console.log(`creating "${node.slug}"`);
@ -75,15 +81,18 @@ const migrate = async (node, resource) => {
})
}
catch (e) {
console.error(`failed to create "${url}"`)
console.error(`failed to create "${url}" due to error: ${e.message}`);
}
await Promise.all(mediaIds.map(async (mediaId) => {
if (mediaId) wp.media().id(mediaId).update({
post: id,
date_gmt: new Date(node.publishedAt)
});
}));
// what's up with setting media to posts? the below snippet yields 'invalid parameter(s): post'...
// await Promise.all(mediaIds.map(async (mediaId) => {
// if (mediaId) wp.media().id(mediaId).update({
// post: id,
// date_gmt: new Date(node.publishedAt)
// });
// })).catch((error) => {
// console.error(error);
// });
}
const download = async (location) => {
@ -117,4 +126,6 @@ const findVacatures = () => {
migrate(node, () => wp.vacatures()) :
migrate(node, () => wp.pages());
}, Promise.resolve());
})()
})().catch((e) => {
console.error(`main loop error: ${e.message}`);
});