Skip to content

Commit

Permalink
Lowercase extension when uploading files and fix searching for images…
Browse files Browse the repository at this point in the history
… with uppercase extensions (#386)
  • Loading branch information
dmerckx committed Jun 19, 2024
1 parent 6c9265f commit 7750a8b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/dashboard/hook/UseUploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@ export function useUploads(onSelect?: (entry: EntryRow) => void) {
})
)

const extension = extname(upload.file.name)
const path = slugify(basename(upload.file.name, extension))
const extensionOriginal = extname(upload.file.name)
const extension = extensionOriginal.toLowerCase()
const path = slugify(basename(upload.file.name, extensionOriginal))
const prev = await graph.preferPublished.maybeGet(Entry({parent: parentId}))

const entryLocation = {
Expand All @@ -211,7 +212,7 @@ export function useUploads(onSelect?: (entry: EntryRow) => void) {
: location

const hash = await createFileHash(new Uint8Array(buffer))
const title = basename(upload.file.name, extension)
const title = basename(upload.file.name, extensionOriginal)
const entry = await createEntryRow<Media.File>(config, {
...entryLocation,
parent: parent?.entryId ?? null,
Expand Down
9 changes: 6 additions & 3 deletions src/field/link/ImageLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ export interface ImageField<Fields = undefined>
ImageLink<Type.Infer<Fields>>
> {}

const imageCondition = Entry.type
.is('MediaFile')
.and(MediaFile.extension.isIn(imageExtensions))
const imageCondition = Entry.type.is('MediaFile').and(
MediaFile.extension.isIn([
...imageExtensions,
...imageExtensions.map(e => e.toUpperCase()) //Fix for historic files with case-insensitive extensions
])
)

function imagePicker<Fields>(
multiple: boolean,
Expand Down

0 comments on commit 7750a8b

Please sign in to comment.