From 27a21dfa625c29edf865ff4db5e31419bee733a0 Mon Sep 17 00:00:00 2001 From: Sean Sube Date: Fri, 21 Jul 2023 15:31:14 -0500 Subject: [PATCH] fix(gui): attempt to decode unicode EXIF tags --- gui/src/components/Profiles.tsx | 35 ++++++++++++++++++++++++++------- onnx-web.code-workspace | 1 + 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/gui/src/components/Profiles.tsx b/gui/src/components/Profiles.tsx index 92fe992f..65ffb5bc 100644 --- a/gui/src/components/Profiles.tsx +++ b/gui/src/components/Profiles.tsx @@ -1,4 +1,4 @@ -import { doesExist, mustExist } from '@apextoaster/js-utils'; +import { InvalidArgumentError, Maybe, doesExist, mustExist } from '@apextoaster/js-utils'; import { Delete as DeleteIcon, ImageSearch, Save as SaveIcon } from '@mui/icons-material'; import { Autocomplete, @@ -172,21 +172,42 @@ export async function parseImageParams(file: File): Promise { + return Array.isArray(it) && typeof it[0] === 'number'; +} + +export function decodeTag(tag: Maybe): Maybe { + // eslint-disable-next-line no-restricted-syntax + if (!doesExist(tag)) { + return undefined; + } + + if (isString(tag.value)) { + return tag.value; + } + + if (tag.description === '[Unicode encoded text]' && isNumberArray(tag.value)) { + return Buffer.from(tag.value).toString('utf-8'); + } + + throw new InvalidArgumentError('tag value cannot be decoded'); +} + export async function parseJSONParams(json: string): Promise> { const data = JSON.parse(json); const params: Partial = { diff --git a/onnx-web.code-workspace b/onnx-web.code-workspace index e190a56e..71b1e537 100644 --- a/onnx-web.code-workspace +++ b/onnx-web.code-workspace @@ -102,6 +102,7 @@ "venv", "virtualenv", "VRAM", + "webp", "zustand" ] }