detail-panel.svelte 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. <script lang="ts">
  2. import { page } from '$app/stores';
  3. import { locale } from '$lib/stores/preferences.store';
  4. import { featureFlags, serverConfig } from '$lib/stores/server-config.store';
  5. import { getAssetFilename } from '$lib/utils/asset-utils';
  6. import { AlbumResponseDto, AssetResponseDto, ThumbnailFormat, api } from '@api';
  7. import type { LatLngTuple } from 'leaflet';
  8. import { DateTime } from 'luxon';
  9. import { createEventDispatcher } from 'svelte';
  10. import { asByteUnitString } from '../../utils/byte-units';
  11. import ImageThumbnail from '../assets/thumbnail/image-thumbnail.svelte';
  12. import UserAvatar from '../shared-components/user-avatar.svelte';
  13. import { mdiCalendar, mdiCameraIris, mdiClose, mdiImageOutline, mdiMapMarkerOutline } from '@mdi/js';
  14. import Icon from '$lib/components/elements/icon.svelte';
  15. export let asset: AssetResponseDto;
  16. export let albums: AlbumResponseDto[] = [];
  17. let textarea: HTMLTextAreaElement;
  18. let description: string;
  19. $: isOwner = $page?.data?.user?.id === asset.ownerId;
  20. $: {
  21. // Get latest description from server
  22. if (asset.id && !api.isSharedLink) {
  23. api.assetApi.getAssetById({ id: asset.id }).then((res) => {
  24. people = res.data?.people || [];
  25. textarea.value = res.data?.exifInfo?.description || '';
  26. });
  27. }
  28. }
  29. $: latlng = (() => {
  30. const lat = asset.exifInfo?.latitude;
  31. const lng = asset.exifInfo?.longitude;
  32. if (lat && lng) {
  33. return [Number(lat.toFixed(7)), Number(lng.toFixed(7))] as LatLngTuple;
  34. }
  35. })();
  36. $: {
  37. if (!asset.exifInfo) {
  38. api.assetApi.getAssetById({ id: asset.id }).then((res) => {
  39. asset.exifInfo = res.data?.exifInfo;
  40. });
  41. }
  42. }
  43. $: lat = latlng ? latlng[0] : undefined;
  44. $: lng = latlng ? latlng[1] : undefined;
  45. $: people = asset.people || [];
  46. const dispatch = createEventDispatcher();
  47. const getMegapixel = (width: number, height: number): number | undefined => {
  48. const megapixel = Math.round((height * width) / 1_000_000);
  49. if (megapixel) {
  50. return megapixel;
  51. }
  52. return undefined;
  53. };
  54. const autoGrowHeight = (e: Event) => {
  55. const target = e.target as HTMLTextAreaElement;
  56. target.style.height = 'auto';
  57. target.style.height = `${target.scrollHeight}px`;
  58. };
  59. const handleFocusIn = () => {
  60. dispatch('description-focus-in');
  61. };
  62. const handleFocusOut = async () => {
  63. dispatch('description-focus-out');
  64. try {
  65. await api.assetApi.updateAsset({
  66. id: asset.id,
  67. updateAssetDto: {
  68. description: description,
  69. },
  70. });
  71. } catch (error) {
  72. console.error(error);
  73. }
  74. };
  75. </script>
  76. <section class="p-2 dark:bg-immich-dark-bg dark:text-immich-dark-fg">
  77. <div class="flex place-items-center gap-2">
  78. <button
  79. class="flex place-content-center place-items-center rounded-full p-3 transition-colors hover:bg-gray-200 dark:text-immich-dark-fg dark:hover:bg-gray-900"
  80. on:click={() => dispatch('close')}
  81. >
  82. <Icon path={mdiClose} size="24" />
  83. </button>
  84. <p class="text-lg text-immich-fg dark:text-immich-dark-fg">Info</p>
  85. </div>
  86. {#if asset.isOffline}
  87. <section class="px-4 py-4">
  88. <div role="alert">
  89. <div class="rounded-t bg-red-500 px-4 py-2 font-bold text-white">Asset offline</div>
  90. <div class="rounded-b border border-t-0 border-red-400 bg-red-100 px-4 py-3 text-red-700">
  91. <p>
  92. This asset is offline. Immich can not access its file location. Please ensure the asset is available and
  93. then rescan the library.
  94. </p>
  95. </div>
  96. </div>
  97. </section>
  98. {/if}
  99. <section class="mx-4 mt-10" style:display={!isOwner && textarea?.value == '' ? 'none' : 'block'}>
  100. <textarea
  101. bind:this={textarea}
  102. class="max-h-[500px]
  103. w-full resize-none overflow-hidden border-b border-gray-500 bg-transparent text-base text-black outline-none transition-all focus:border-b-2 focus:border-immich-primary disabled:border-none dark:text-white dark:focus:border-immich-dark-primary"
  104. placeholder={!isOwner ? '' : 'Add a description'}
  105. on:focusin={handleFocusIn}
  106. on:focusout={handleFocusOut}
  107. on:input={autoGrowHeight}
  108. bind:value={description}
  109. disabled={!isOwner}
  110. />
  111. </section>
  112. {#if !api.isSharedLink && people.length > 0}
  113. <section class="px-4 py-4 text-sm">
  114. <h2>PEOPLE</h2>
  115. <div class="mt-4 flex flex-wrap gap-2">
  116. {#each people as person (person.id)}
  117. <a href="/people/{person.id}" class="w-[90px]" on:click={() => dispatch('close-viewer')}>
  118. <ImageThumbnail
  119. curve
  120. shadow
  121. url={api.getPeopleThumbnailUrl(person.id)}
  122. altText={person.name}
  123. title={person.name}
  124. widthStyle="90px"
  125. heightStyle="90px"
  126. thumbhash={null}
  127. />
  128. <p class="mt-1 truncate font-medium" title={person.name}>{person.name}</p>
  129. {#if person.birthDate}
  130. {@const personBirthDate = DateTime.fromISO(person.birthDate)}
  131. <p
  132. class="font-light"
  133. title={personBirthDate.toLocaleString(
  134. {
  135. month: 'long',
  136. day: 'numeric',
  137. year: 'numeric',
  138. },
  139. { locale: $locale },
  140. )}
  141. >
  142. Age {Math.floor(DateTime.fromISO(asset.fileCreatedAt).diff(personBirthDate, 'years').years)}
  143. </p>
  144. {/if}
  145. </a>
  146. {/each}
  147. </div>
  148. </section>
  149. {/if}
  150. <div class="px-4 py-4">
  151. {#if !asset.exifInfo && !asset.isExternal}
  152. <p class="text-sm">NO EXIF INFO AVAILABLE</p>
  153. {:else if !asset.exifInfo && asset.isExternal}
  154. <div class="flex gap-4 py-4">
  155. <div>
  156. <p class="break-all">
  157. Metadata not loaded for {asset.originalPath}
  158. </p>
  159. </div>
  160. </div>
  161. {:else}
  162. <p class="text-sm">DETAILS</p>
  163. {/if}
  164. {#if asset.exifInfo?.dateTimeOriginal}
  165. {@const assetDateTimeOriginal = DateTime.fromISO(asset.exifInfo.dateTimeOriginal, {
  166. zone: asset.exifInfo.timeZone ?? undefined,
  167. })}
  168. <div class="flex gap-4 py-4">
  169. <div>
  170. <Icon path={mdiCalendar} size="24" />
  171. </div>
  172. <div>
  173. <p>
  174. {assetDateTimeOriginal.toLocaleString(
  175. {
  176. month: 'short',
  177. day: 'numeric',
  178. year: 'numeric',
  179. },
  180. { locale: $locale },
  181. )}
  182. </p>
  183. <div class="flex gap-2 text-sm">
  184. <p>
  185. {assetDateTimeOriginal.toLocaleString(
  186. {
  187. weekday: 'short',
  188. hour: 'numeric',
  189. minute: '2-digit',
  190. timeZoneName: 'longOffset',
  191. },
  192. { locale: $locale },
  193. )}
  194. </p>
  195. </div>
  196. </div>
  197. </div>{/if}
  198. {#if asset.exifInfo?.fileSizeInByte}
  199. <div class="flex gap-4 py-4">
  200. <div><Icon path={mdiImageOutline} size="24" /></div>
  201. <div>
  202. <p class="break-all">
  203. {getAssetFilename(asset)}
  204. </p>
  205. <div class="flex gap-2 text-sm">
  206. {#if asset.exifInfo.exifImageHeight && asset.exifInfo.exifImageWidth}
  207. {#if getMegapixel(asset.exifInfo.exifImageHeight, asset.exifInfo.exifImageWidth)}
  208. <p>
  209. {getMegapixel(asset.exifInfo.exifImageHeight, asset.exifInfo.exifImageWidth)} MP
  210. </p>
  211. {/if}
  212. <p>{asset.exifInfo.exifImageHeight} x {asset.exifInfo.exifImageWidth}</p>
  213. {/if}
  214. <p>{asByteUnitString(asset.exifInfo.fileSizeInByte, $locale)}</p>
  215. </div>
  216. </div>
  217. </div>
  218. {/if}
  219. {#if asset.exifInfo?.make || asset.exifInfo?.model || asset.exifInfo?.fNumber}
  220. <div class="flex gap-4 py-4">
  221. <div><Icon path={mdiCameraIris} size="24" /></div>
  222. <div>
  223. <p>{asset.exifInfo.make || ''} {asset.exifInfo.model || ''}</p>
  224. <div class="flex gap-2 text-sm">
  225. {#if asset.exifInfo?.fNumber}
  226. <p>{`ƒ/${asset.exifInfo.fNumber.toLocaleString($locale)}` || ''}</p>
  227. {/if}
  228. {#if asset.exifInfo.exposureTime}
  229. <p>{`${asset.exifInfo.exposureTime}`}</p>
  230. {/if}
  231. {#if asset.exifInfo.focalLength}
  232. <p>{`${asset.exifInfo.focalLength.toLocaleString($locale)} mm`}</p>
  233. {/if}
  234. {#if asset.exifInfo.iso}
  235. <p>
  236. {`ISO ${asset.exifInfo.iso}`}
  237. </p>
  238. {/if}
  239. </div>
  240. </div>
  241. </div>
  242. {/if}
  243. {#if asset.exifInfo?.city}
  244. <div class="flex gap-4 py-4">
  245. <div><Icon path={mdiMapMarkerOutline} size="24" /></div>
  246. <div>
  247. <p>{asset.exifInfo.city}</p>
  248. {#if asset.exifInfo?.state}
  249. <div class="flex gap-2 text-sm">
  250. <p>{asset.exifInfo.state}</p>
  251. </div>
  252. {/if}
  253. {#if asset.exifInfo?.country}
  254. <div class="flex gap-2 text-sm">
  255. <p>{asset.exifInfo.country}</p>
  256. </div>
  257. {/if}
  258. </div>
  259. </div>
  260. {/if}
  261. </div>
  262. </section>
  263. {#if latlng && $featureFlags.loaded && $featureFlags.map}
  264. <div class="h-[360px]">
  265. {#await import('../shared-components/leaflet') then { Map, TileLayer, Marker }}
  266. <Map center={latlng} zoom={14}>
  267. <TileLayer
  268. urlTemplate={$serverConfig.mapTileUrl}
  269. options={{
  270. attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>',
  271. }}
  272. />
  273. <Marker {latlng}>
  274. <p>
  275. {lat}, {lng}
  276. </p>
  277. <a href="https://www.openstreetmap.org/?mlat={lat}&mlon={lng}&zoom=15#map=15/{lat}/{lng}">
  278. Open in OpenStreetMap
  279. </a>
  280. </Marker>
  281. </Map>
  282. {/await}
  283. </div>
  284. {/if}
  285. {#if asset.owner && !isOwner}
  286. <section class="px-6 pt-6 dark:text-immich-dark-fg">
  287. <p class="text-sm">SHARED BY</p>
  288. <div class="flex gap-4 pt-4">
  289. <div>
  290. <UserAvatar user={asset.owner} size="md" autoColor />
  291. </div>
  292. <div class="mb-auto mt-auto">
  293. <p>
  294. {asset.owner.firstName}
  295. {asset.owner.lastName}
  296. </p>
  297. </div>
  298. </div>
  299. </section>
  300. {/if}
  301. {#if albums.length > 0}
  302. <section class="p-6 dark:text-immich-dark-fg">
  303. <p class="pb-4 text-sm">APPEARS IN</p>
  304. {#each albums as album}
  305. <a data-sveltekit-preload-data="hover" href={`/albums/${album.id}`}>
  306. <!-- svelte-ignore a11y-no-static-element-interactions -->
  307. <div
  308. class="flex gap-4 py-2 hover:cursor-pointer"
  309. on:click={() => dispatch('click', album)}
  310. on:keydown={() => dispatch('click', album)}
  311. >
  312. <div>
  313. <img
  314. alt={album.albumName}
  315. class="h-[50px] w-[50px] rounded object-cover"
  316. src={album.albumThumbnailAssetId &&
  317. api.getAssetThumbnailUrl(album.albumThumbnailAssetId, ThumbnailFormat.Jpeg)}
  318. draggable="false"
  319. />
  320. </div>
  321. <div class="mb-auto mt-auto">
  322. <p class="dark:text-immich-dark-primary">{album.albumName}</p>
  323. <div class="flex gap-2 text-sm">
  324. <p>{album.assetCount} items</p>
  325. {#if album.shared}
  326. <p>· Shared</p>
  327. {/if}
  328. </div>
  329. </div>
  330. </div>
  331. </a>
  332. {/each}
  333. </section>
  334. {/if}