Saving EXIF data for jpegs.
This commit is contained in:
@@ -8,32 +8,59 @@ const fetchItem = require('./item.js');
|
||||
const interpolate = require('../interpolate.js');
|
||||
const save = require('../save/save.js');
|
||||
const textToStream = require('../save/textToStream.js');
|
||||
const saveMeta = require('../save/meta.js');
|
||||
|
||||
const exiftool = require('node-exiftool');
|
||||
const exiftoolBin = require('dist-exiftool');
|
||||
|
||||
const ep = new exiftool.ExiftoolProcess(exiftoolBin);
|
||||
|
||||
module.exports = function(posts, user) {
|
||||
return Promise.all(posts.map(post => {
|
||||
return Promise.resolve().then(() => {
|
||||
return Promise.all(post.content.items.map((item, index) => {
|
||||
item.index = index;
|
||||
return Promise.resolve().then(() => {
|
||||
return ep.open();
|
||||
}).then(() => {
|
||||
return Promise.all(posts.map(post => {
|
||||
return Promise.resolve().then(() => {
|
||||
return Promise.all(post.content.items.map((item, index) => {
|
||||
item.index = index;
|
||||
|
||||
if(item.self) {
|
||||
return Object.assign({}, item, {stream: textToStream(item.text)});
|
||||
}
|
||||
if(item.self) {
|
||||
return Object.assign({}, item, {stream: textToStream(item.text)});
|
||||
}
|
||||
|
||||
return fetchItem(item.url, 0).then(stream => {
|
||||
return Object.assign({}, item, {stream});
|
||||
});
|
||||
}));
|
||||
}).then(items => {
|
||||
return Promise.all(items.map(item => {
|
||||
const type = item.type.split('/')[0];
|
||||
const filepath = post.content.album ? interpolate(config.library.album[type], user, post, item) : interpolate(config.library[type], user, post, item);
|
||||
return fetchItem(item.url, 0).then(stream => {
|
||||
return Object.assign({}, item, {stream});
|
||||
});
|
||||
}));
|
||||
}).then(items => {
|
||||
return Promise.all(items.map(item => {
|
||||
const type = item.type.split('/')[0];
|
||||
const filepath = post.content.album ? interpolate(config.library.album[type], user, post, item) : interpolate(config.library[type], user, post, item);
|
||||
|
||||
return Promise.resolve().then(() => {
|
||||
return fs.ensureDir(path.dirname(filepath));
|
||||
}).then(() => {
|
||||
return save(filepath, item.stream)
|
||||
});
|
||||
}));
|
||||
});
|
||||
}));
|
||||
return Promise.resolve().then(() => {
|
||||
return fs.ensureDir(path.dirname(filepath));
|
||||
}).then(() => {
|
||||
return save(filepath, item.stream);
|
||||
}).then(() => {
|
||||
const interpolatedMeta = Object.entries(config.library.meta).reduce((acc, [key, value]) => {
|
||||
acc[key] = interpolate(value, user, post, item);
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
if(Object.keys(interpolatedMeta).length > 0) {
|
||||
return saveMeta(filepath, {
|
||||
comment: item.description
|
||||
}, ep);
|
||||
}
|
||||
});
|
||||
}));
|
||||
});
|
||||
}));
|
||||
}).then(() => {
|
||||
console.log('closing...');
|
||||
return ep.close();
|
||||
}).catch(error => {
|
||||
return ep.close();
|
||||
});
|
||||
};
|
||||
|
||||
@@ -14,11 +14,10 @@ const extensions = {
|
||||
|
||||
function interpolate(pattern, user, post, item) {
|
||||
const dateFormat = config.library.dateFormat || 'YYYYMMDD';
|
||||
const vars = {};
|
||||
|
||||
if(config.library.base) {
|
||||
pattern = path.join(config.library.base, pattern);
|
||||
}
|
||||
const vars = {
|
||||
$base: config.library.base
|
||||
};
|
||||
|
||||
if(user) {
|
||||
Object.assign(vars, {
|
||||
@@ -76,7 +75,9 @@ function interpolate(pattern, user, post, item) {
|
||||
|
||||
return Object.entries(vars).reduce((acc, [key, value], index) => {
|
||||
// substitute slashes for filesystem compatability
|
||||
value = (value || '').toString().replace(/\//g, config.library.slashSubstitute);
|
||||
if(key !== '$base') {
|
||||
value = (value || '').toString().replace(/\//g, config.library.slashSubstitute);
|
||||
}
|
||||
|
||||
return acc.replace(key, value);
|
||||
}, pattern);
|
||||
|
||||
Reference in New Issue
Block a user