diff options
| author | xianon <xianon@hotmail.co.jp> | 2021-12-03 11:19:28 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-03 11:19:28 +0900 |
| commit | 22464c434eb7faf3af4c8c44389996925c04eca6 (patch) | |
| tree | 82245fcb5a16b1b832c22df5cf15c7417ac5584e /packages/backend/src/models/repositories | |
| parent | feat: Undo Accept (#7980) (diff) | |
| download | misskey-22464c434eb7faf3af4c8c44389996925c04eca6.tar.gz misskey-22464c434eb7faf3af4c8c44389996925c04eca6.tar.bz2 misskey-22464c434eb7faf3af4c8c44389996925c04eca6.zip | |
fix: 画像ファイルの縦横サイズの取得で Exif Orientation を考慮する (#8014)
* 画像ファイルの縦横サイズの取得で Exif Orientation を考慮する
* test: Add rotate.jpg test
* Webpublic 画像を返す時のみ Exif Orientation を考慮して縦横サイズを返す
* test: Support orientation
Diffstat (limited to 'packages/backend/src/models/repositories')
| -rw-r--r-- | packages/backend/src/models/repositories/drive-file.ts | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/packages/backend/src/models/repositories/drive-file.ts b/packages/backend/src/models/repositories/drive-file.ts index ddf9a46afd..f2f0308dc0 100644 --- a/packages/backend/src/models/repositories/drive-file.ts +++ b/packages/backend/src/models/repositories/drive-file.ts @@ -28,6 +28,19 @@ export class DriveFileRepository extends Repository<DriveFile> { ); } + public getPublicProperties(file: DriveFile): DriveFile['properties'] { + if (file.properties.orientation != null) { + const properties = JSON.parse(JSON.stringify(file.properties)); + if (file.properties.orientation >= 5) { + [properties.width, properties.height] = [properties.height, properties.width]; + } + properties.orientation = undefined; + return properties; + } + + return file.properties; + } + public getPublicUrl(file: DriveFile, thumbnail = false, meta?: Meta): string | null { // リモートかつメディアプロキシ if (file.uri != null && file.userHost != null && config.mediaProxy != null) { @@ -122,7 +135,7 @@ export class DriveFileRepository extends Repository<DriveFile> { size: file.size, isSensitive: file.isSensitive, blurhash: file.blurhash, - properties: file.properties, + properties: opts.self ? file.properties : this.getPublicProperties(file), url: opts.self ? file.url : this.getPublicUrl(file, false, meta), thumbnailUrl: this.getPublicUrl(file, true, meta), comment: file.comment, @@ -202,6 +215,11 @@ export const packedDriveFileSchema = { optional: true as const, nullable: false as const, example: 720 }, + orientation: { + type: 'number' as const, + optional: true as const, nullable: false as const, + example: 8 + }, avgColor: { type: 'string' as const, optional: true as const, nullable: false as const, |