Merge pull request #274 from kylmp/resolution-fixes
This commit is contained in:
@@ -383,11 +383,11 @@ function formatDate (iso: string): string {
|
||||
}
|
||||
}
|
||||
|
||||
function formatBytes (bytes: number): string {
|
||||
export function formatBytes (bytes: number): string {
|
||||
if (bytes < 1024) return bytes + ' B'
|
||||
const kb = bytes / 1024
|
||||
if (kb < 1024) return kb.toFixed(1) + ' KB'
|
||||
if (kb < 1024) return kb.toFixed(1) + ' KiB'
|
||||
const mb = kb / 1024
|
||||
if (mb < 1024) return mb.toFixed(1) + ' MB'
|
||||
return (mb / 1024).toFixed(2) + ' GB'
|
||||
if (mb < 1024) return mb.toFixed(1) + ' MiB'
|
||||
return (mb / 1024).toFixed(2) + ' GiB'
|
||||
}
|
||||
|
||||
@@ -62,6 +62,9 @@ const EXIF_RULES: FieldRule[] = [
|
||||
if (info.exifImageWidth && info.exifImageHeight) {
|
||||
out.width = info.exifImageWidth
|
||||
out.height = info.exifImageHeight
|
||||
if (info.orientation && ['5', '6', '7', '8'].includes(info.orientation)) {
|
||||
[out.width, out.height] = [out.height, out.width]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -55,6 +55,19 @@ describe('buildAssetMetadata', () => {
|
||||
expect(meta.exif?.city).toBeUndefined()
|
||||
})
|
||||
|
||||
it('reports dimensions in display orientation', () => {
|
||||
setConfig({ ipp: { showMetadata: { exif: { dimensions: true } } } })
|
||||
const photo = asset()
|
||||
photo.exifInfo!.exifImageWidth = 4000
|
||||
photo.exifInfo!.exifImageHeight = 3000
|
||||
photo.exifInfo!.orientation = '6'
|
||||
|
||||
expect(buildAssetMetadata(photo, share()).exif).toMatchObject({
|
||||
width: 3000,
|
||||
height: 4000
|
||||
})
|
||||
})
|
||||
|
||||
it('returns description when a description surface is enabled', () => {
|
||||
setConfig({ ipp: { showMetadata: { description: { sidebar: true } } } })
|
||||
const meta = buildAssetMetadata(asset(), share())
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { formatBytes } from '../src/client/sidebar'
|
||||
|
||||
describe('sidebar file metadata formatting', () => {
|
||||
it('uses binary unit labels for binary calculations', () => {
|
||||
expect(formatBytes(1023)).toBe('1023 B')
|
||||
expect(formatBytes(1024)).toBe('1.0 KiB')
|
||||
expect(formatBytes(3_500_000)).toBe('3.3 MiB')
|
||||
expect(formatBytes(3 * 1024 ** 3)).toBe('3.00 GiB')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user