Skip to content

Commit cadf815

Browse files
authored
fix(ui): thumbnails when serverURL config is provided (#8124)
1 parent 638382e commit cadf815

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

packages/ui/src/fields/Upload/HasMany/index.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ export function UploadComponentHasMany(props: Props) {
6262
>
6363
{fileDocs.map(({ relationTo, value }, index) => {
6464
const id = String(value.id)
65+
const url: string = value.thumbnailURL || value.url
66+
let src: string
67+
68+
try {
69+
src = new URL(url, serverURL).toString()
70+
} catch {
71+
src = `${serverURL}${url}`
72+
}
73+
6574
return (
6675
<DraggableSortableItem disabled={!isSortable} id={id} key={id}>
6776
{(draggableSortableItemProps) => (
@@ -100,7 +109,7 @@ export function UploadComponentHasMany(props: Props) {
100109
id={id}
101110
mimeType={value?.mimeType as string}
102111
onRemove={() => removeItem(index)}
103-
src={`${serverURL}${value.url}`}
112+
src={src}
104113
withMeta={false}
105114
x={value?.width as number}
106115
y={value?.height as number}

packages/ui/src/fields/Upload/HasOne/index.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ export function UploadComponentHasOne(props: Props) {
2626
const { relationTo, value } = fileDoc
2727
const id = String(value.id)
2828

29+
const url: string = value.thumbnailURL || value.url
30+
let src: string
31+
32+
try {
33+
src = new URL(url, serverURL).toString()
34+
} catch {
35+
src = `${serverURL}${url}`
36+
}
37+
2938
return (
3039
<UploadCard className={[baseClass, className].filter(Boolean).join(' ')}>
3140
<RelationshipContent
@@ -38,7 +47,7 @@ export function UploadComponentHasOne(props: Props) {
3847
id={id}
3948
mimeType={value?.mimeType as string}
4049
onRemove={onRemove}
41-
src={`${serverURL}${value.url}`}
50+
src={src}
4251
x={value?.width as number}
4352
y={value?.height as number}
4453
/>

0 commit comments

Comments
 (0)