Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(backend): original image is not original image on web page #59

Merged
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
### General
- Enhance: モデレーションログ機能の強化

---

- 4K/8K画像が2K以下で表示されてしまう問題を修正しました
- 既存のファイルは更新されず、新規アップロード分にのみ適用されます

### Client
- Fix: ノートのメニューにある「詳細」ボタンの表示がログイン/ログアウト状態で統一されていない問題を修正

Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type Source = {
nirila?: {
abuseDiscordHook?: string;
disableAbuseRepository?: boolean;
maxWebImageSize?: number;
}
};

Expand Down Expand Up @@ -172,6 +173,7 @@ export type Config = {
nirila: {
abuseDiscordHook?: string;
disableAbuseRepository?: boolean;
maxWebImageSize?: number;
}
};

Expand Down
15 changes: 11 additions & 4 deletions packages/backend/src/core/DriveService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,19 +301,26 @@ export class DriveService {
let img: sharp.Sharp | null = null;
let satisfyWebpublic: boolean;
let isAnimated: boolean;
let compressedWidth: number;
let compressedHeight: number;

try {
img = await sharpBmp(path, type);
const metadata = await img.metadata();
isAnimated = !!(metadata.pages && metadata.pages > 1);

const maxSize = this.config.nirila?.maxWebImageSize ?? 8192;
// nirila Extension: We want to keep original size as possible
// noinspection PointlessBooleanExpressionJS
satisfyWebpublic = !!(
type !== 'image/svg+xml' && // security reason
type !== 'image/avif' && // not supported by Mastodon and MS Edge
!(metadata.exif ?? metadata.iptc ?? metadata.xmp ?? metadata.tifftagPhotoshop) &&
Sayamame-beans marked this conversation as resolved.
Show resolved Hide resolved
metadata.width && metadata.width <= 2048 &&
metadata.height && metadata.height <= 2048
metadata.width && metadata.width <= maxSize &&
metadata.height && metadata.height <= maxSize
);
compressedWidth = metadata.width && metadata.width <= maxSize ? metadata.width : maxSize;
compressedHeight = metadata.height && metadata.height <= maxSize ? metadata.height : maxSize;
} catch (err) {
this.registerLogger.warn(`sharp failed: ${err}`);
return {
Expand All @@ -330,9 +337,9 @@ export class DriveService {

try {
if (['image/jpeg', 'image/webp', 'image/avif'].includes(type)) {
webpublic = await this.imageProcessingService.convertSharpToWebp(img, 2048, 2048);
webpublic = await this.imageProcessingService.convertSharpToWebp(img, compressedWidth, compressedHeight);
} else if (['image/png', 'image/bmp', 'image/svg+xml'].includes(type)) {
webpublic = await this.imageProcessingService.convertSharpToPng(img, 2048, 2048);
webpublic = await this.imageProcessingService.convertSharpToPng(img, compressedWidth, compressedHeight);
} else {
this.registerLogger.debug('web image not created (not an required image)');
}
Expand Down
Loading