Skip to content

Commit

Permalink
Improve handling of different file types with similar filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
AlecRust committed Oct 26, 2023
1 parent f6a1a47 commit d59d27c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,18 @@ const processFolder = async (srcFolder, destFolder) => {

if (candidates.length === 0) continue

const mediaFileToCopy = candidates.find((f) => f.includes('-edited')) || candidates[0]
const mediaType = path.extname(title).toLowerCase()

const mediaFileToCopy =
candidates.find((f) => {
return f.toLowerCase().includes(mediaType) && f.includes('-edited')
}) ||
candidates.find((f) => {
return f.toLowerCase().includes(mediaType)
})

if (!mediaFileToCopy) continue

const srcMediaFilePath = path.join(srcFolder, mediaFileToCopy)
let destMediaFilePath = path.join(destFolder, mediaFileToCopy)

Expand Down
49 changes: 49 additions & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,55 @@ describe('Tests', () => {
],
)
})

it('handles different file types with similar filenames', async () => {
await runTest(
[
{
name: 'IMG_0001-edited.JPG',
filesize: '10',
},
{
name: 'IMG_0001.JPG.jpeg',
filesize: '20',
},
{
name: 'IMG_0001.JPG.json',
content: {
title: 'IMG_0001.JPG',
photoTakenTime: {
timestamp: '86400',
},
},
},
{
name: 'IMG_0001.MOV.mp4',
filesize: '30',
},
{
name: 'IMG_0001.MOV.json',
content: {
title: 'IMG_0001.MOV',
photoTakenTime: {
timestamp: '86400',
},
},
},
],
[
{
name: 'IMG_0001.JPG',
filesize: '10',
timestamp: '86400',
},
{
name: 'IMG_0001.MOV.mp4',
filesize: '30',
timestamp: '86400',
},
],
)
})
})

const runTest = async (inputFiles, outputFiles) => {
Expand Down

0 comments on commit d59d27c

Please sign in to comment.