|
|
@ -241,6 +241,59 @@ class ImageService extends SiteService {
|
|
|
|
return icon;
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getPostImageInfo() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const siteImagesDir = path.join(this.dtp.config.root, 'client', 'img');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let icon;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await fs.promises.access(siteImagesDir);
|
|
|
|
|
|
|
|
const iconMetadata = await sharp(path.join(siteImagesDir, 'default-poster.jpg')).metadata();
|
|
|
|
|
|
|
|
icon = {
|
|
|
|
|
|
|
|
metadata: iconMetadata,
|
|
|
|
|
|
|
|
path: `/img/default-poster.jpg`,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
icon = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return icon;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async updatePostImage(imageDefinition, file) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.log.debug('updating site icon', { imageDefinition, file });
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const siteImagesDir = path.join(this.dtp.config.root, 'client', 'img');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const sourceIconFilePath = file.path;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await sharp(sourceIconFilePath).resize({
|
|
|
|
|
|
|
|
fit: sharp.fit.inside,
|
|
|
|
|
|
|
|
width: 540,
|
|
|
|
|
|
|
|
height: 960,
|
|
|
|
|
|
|
|
}).jpeg()
|
|
|
|
|
|
|
|
.toFile(path.join(siteImagesDir, `default-poster.jpg`));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return path.join(siteImagesDir, 'default-poster.jpg');
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
this.log.error('failed to update site icon', { error });
|
|
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
this.log.info('removing uploaded image from local file system', { file: file.path });
|
|
|
|
|
|
|
|
await fs.promises.rm(file.path);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async updateSiteIcon(imageDefinition, file) {
|
|
|
|
async updateSiteIcon(imageDefinition, file) {
|
|
|
|
|
|
|
|
|
|
|
|
this.log.debug('updating site icon', { imageDefinition, file });
|
|
|
|
this.log.debug('updating site icon', { imageDefinition, file });
|
|
|
@ -261,15 +314,13 @@ class ImageService extends SiteService {
|
|
|
|
|
|
|
|
|
|
|
|
for (var size of sizes) {
|
|
|
|
for (var size of sizes) {
|
|
|
|
await sharp(sourceIconFilePath).resize({
|
|
|
|
await sharp(sourceIconFilePath).resize({
|
|
|
|
fit: sharp.fit.contain,
|
|
|
|
fit: sharp.fit.inside,
|
|
|
|
width: size,
|
|
|
|
width: size,
|
|
|
|
height: size,
|
|
|
|
height: size,
|
|
|
|
}).png()
|
|
|
|
}).png()
|
|
|
|
.toFile(path.join(siteIconDir, `icon-${size}x${size}.png`));
|
|
|
|
.toFile(path.join(siteIconDir, `icon-${size}x${size}.png`));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await fs.promises.cp(sourceIconFilePath, path.join(siteIconDir, `${siteDomain}.png`));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await fs.promises.cp(sourceIconFilePath, path.join(siteImagesDir, 'social-cards', `${siteDomain}.png`));
|
|
|
|
await fs.promises.cp(sourceIconFilePath, path.join(siteImagesDir, 'social-cards', `${siteDomain}.png`));
|
|
|
|
return path.join(siteIconDir, 'icon-512x512.png');
|
|
|
|
return path.join(siteIconDir, 'icon-512x512.png');
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|