Skip to content

Commit

Permalink
Only strip suffix of file if an extension is added (mckaywrigley#1764)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikey032 authored Jun 2, 2024
1 parent fb7dd9d commit ef4f8f3
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion db/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ export const createFile = async (
) => {
let validFilename = fileRecord.name.replace(/[^a-z0-9.]/gi, "_").toLowerCase()
const extension = file.name.split(".").pop()
const baseName = validFilename.substring(0, validFilename.lastIndexOf("."))
const extensionIndex = validFilename.lastIndexOf(".")
const baseName = validFilename.substring(0, (extensionIndex < 0) ? undefined : extensionIndex)
const maxBaseNameLength = 100 - (extension?.length || 0) - 1
if (baseName.length > maxBaseNameLength) {
fileRecord.name = baseName.substring(0, maxBaseNameLength) + "." + extension
Expand Down

0 comments on commit ef4f8f3

Please sign in to comment.