Do images in sequence
This commit is contained in:
parent
bab8b18744
commit
19d89d7c8a
30
update.js
30
update.js
|
@ -14,12 +14,17 @@ const htmlString = fs.readFileSync('Solutions.xml').toString();
|
|||
const $ = cheerio.load(htmlString);
|
||||
const redis = new Redis();
|
||||
|
||||
function onlyUnique(value, index, array) {
|
||||
return array.indexOf(value) === index;
|
||||
}
|
||||
|
||||
async function start() {
|
||||
await directus.auth.login({ email: process.env.DIRECTUS_EMAIL, password: process.env.DIRECTUS_PASSWORD })
|
||||
.catch(() => {
|
||||
console.error('Invalid credentials');
|
||||
});
|
||||
|
||||
const toImport = Array.new()
|
||||
$('solution-article').each(async function(i, element) {
|
||||
let parentTitle = $("name", $(this).parent().parent()).html();
|
||||
let title = he.decode($(this).children("title").html());
|
||||
|
@ -29,17 +34,9 @@ async function start() {
|
|||
let original_id = parseInt(he.decode($(this).children("id").html()));
|
||||
|
||||
await redis.hset("pageurls", original_id, title_slug);
|
||||
console.log('Parsing images');
|
||||
images.each(async function(e, image) {
|
||||
images.each(function(e, image) {
|
||||
let imageUrl = $(image).attr('src');
|
||||
try {
|
||||
let file = await directus.files.import({
|
||||
url: imageUrl,
|
||||
});
|
||||
await redis.hset("images", imageUrl, 'https://directus.anquet.com/assets/' + file.id + '-' + file.width + '-' + file.height);
|
||||
} catch (e) {
|
||||
// Can't import this image.
|
||||
}
|
||||
toImport.push(imageUrl);
|
||||
});
|
||||
description = turndownService.turndown(description);
|
||||
|
||||
|
@ -54,6 +51,19 @@ async function start() {
|
|||
return Promise.resolve();
|
||||
});
|
||||
|
||||
toImport = toImport.filter(onlyUnique);
|
||||
|
||||
for (let i = 0; i < toImport.length; i++) {
|
||||
try {
|
||||
let file = await directus.files.import({
|
||||
url: toImport[i],
|
||||
});
|
||||
await redis.hset("images", toImport[i], 'https://directus.anquet.com/assets/' + file.id + '-' + file.width + '-' + file.height);
|
||||
} catch (e) {
|
||||
// Can't import this image.
|
||||
}
|
||||
}
|
||||
|
||||
const articles = directus.items('omn2omn3');
|
||||
const translations = directus.items('omn2omn3_translations');
|
||||
const pages = await redis.hgetall("pages");
|
||||
|
|
Reference in a new issue