Resolving actor birth and residence place before storage. Layout improvements.
This commit is contained in:
21
src/media.js
21
src/media.js
@@ -188,10 +188,10 @@ async function storeAvatars(profile, actor) {
|
||||
console.log(`Storing ${profile.avatars.length} avatars for '${profile.name}'`);
|
||||
|
||||
const files = await Promise.map(profile.avatars, async (avatarUrl, index) => {
|
||||
const { pathname } = new URL(avatarUrl);
|
||||
const mimetype = mime.getType(pathname);
|
||||
|
||||
try {
|
||||
const { pathname } = new URL(avatarUrl);
|
||||
const mimetype = mime.getType(pathname);
|
||||
|
||||
const res = await bhttp.get(avatarUrl);
|
||||
|
||||
if (res.statusCode === 200) {
|
||||
@@ -220,7 +220,7 @@ async function storeAvatars(profile, actor) {
|
||||
|
||||
throw new Error(`Response ${res.statusCode} not OK`);
|
||||
} catch (error) {
|
||||
console.warn(`Failed to store avatar ${index + 1} for '${profile.name}'`);
|
||||
console.warn(`Failed to store avatar ${index + 1} for '${profile.name}': ${avatarUrl}`);
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -228,17 +228,12 @@ async function storeAvatars(profile, actor) {
|
||||
concurrency: 2,
|
||||
});
|
||||
|
||||
const avatars = files.filter(file => file);
|
||||
|
||||
const existingAvatars = await knex('media')
|
||||
.whereIn('hash', files.map(file => file.hash));
|
||||
|
||||
const newAvatars = files.filter((file) => {
|
||||
if (!file) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !existingAvatars.some(avatar => file.hash === avatar.hash);
|
||||
});
|
||||
.whereIn('hash', avatars.map(file => file.hash));
|
||||
|
||||
const newAvatars = avatars.filter(file => !existingAvatars.some(avatar => file.hash === avatar.hash));
|
||||
const hasAvatar = existingAvatars.some(avatar => avatar.role === 'avatar');
|
||||
|
||||
await knex('media')
|
||||
|
||||
Reference in New Issue
Block a user