Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"react-time-ago": "^7.3.5",
"require-in-the-middle": "7.5.2",
"tailwind-merge": "^3.3.1",
"unorm": "^1.6.0",
"zod": "^4.1.1"
},
"devDependencies": {
Expand All @@ -61,6 +62,7 @@
"@types/react": "^19",
"@types/react-dom": "^19",
"@types/react-linkify": "^1.0.4",
"@types/unorm": "^1.3.31",
"drizzle-kit": "^0.31.4",
"husky": "^9.1.7",
"lint-staged": "^16.1.5",
Expand Down
17 changes: 17 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/features/sync/lib/Sync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class SyncService extends AuthenticatedDropboxService {
error.status === 400 &&
error.body.message === 'Folder already exists'
) {
console.info({ message: error.body.message })
console.info({ message: error.body.message, path: itemPath })
await this.handleFolderCreatedCase(
lastItem,
tempFileType,
Expand All @@ -202,7 +202,7 @@ export class SyncService extends AuthenticatedDropboxService {
return
}
console.error(
`SyncService#createAndUploadFileToAssembly. Upload failed. Channel ID: ${assemblyChannelId}`,
`SyncService#createAndUploadFileToAssembly. Upload failed. Channel ID: ${assemblyChannelId}. Path: ${itemPath}`,
)
throw error
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/copilot/CopilotAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
} from '@/lib/copilot/types'
import logger from '@/lib/logger'
import { withRetry } from '@/lib/withRetry'
import { sanitizeFileNameForAssembly } from '@/utils/filePath'

export class CopilotAPI {
readonly copilot: SDK
Expand Down Expand Up @@ -191,7 +192,7 @@ export class CopilotAPI {
const createFileResponse = await this.copilot.createFile({
fileType,
requestBody: {
path,
path: sanitizeFileNameForAssembly(path),
channelId,
},
})
Expand Down
10 changes: 10 additions & 0 deletions src/utils/filePath.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as p from 'node:path'
import dayjs from 'dayjs'
import unorm from 'unorm'
import { ObjectType } from '@/db/constants'

export function buildPathArray(path: string): string[] {
Expand Down Expand Up @@ -79,3 +80,12 @@ export function splitPathAndFolder(fullPath: string): { path: string; folder: st
export function sanitizePath(path: string) {
return path.replace(/^\/+/, '')
}

export function sanitizeFileNameForAssembly(filename: string): string {
return unorm
.nfd(filename) // decompose accents
.replace(/[\u0300-\u036f]/g, '') // remove diacritics
.replace(/[^a-zA-Z0-9._-]/g, '_') // replace special chars with _
.replace(/_+/g, '_') // collapse multiple _
.replace(/^_+|_+$/g, '') // trim _ from ends
}
Comment on lines 84 to 91
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export function sanitizeFileNameForAssembly(filename: string): string {
const lastDotIndex = filename.lastIndexOf('.')
// if there's no extension, sanitize the whole filename
if (lastDotIndex === -1) {
return filename.replace(/[^a-zA-Z0-9_-]/g, ' ')
}
const name = filename.slice(0, lastDotIndex)
const extension = filename.slice(lastDotIndex + 1)
const sanitizedName = name.replace(/[^a-zA-Z0-9_-]/g, ' ')
return `${sanitizedName}.${extension}`
}
export function sanitizeFileNameForAssembly(filename: string): string {
const lastDotIndex = filename.lastIndexOf('.')
const sanitizedName = name.replace(/[^a-zA-Z0-9_-]/g, ' ')
// if there's no extension, sanitize the whole filename
if (lastDotIndex === -1) {
return sanitizedName
}
const name = sanitizedName.slice(0, lastDotIndex)
const extension = sanitizedName.slice(lastDotIndex + 1)
return `${sanitizedName}.${extension}`
}

File extensions don't have accent characters so this should be safe? Just a suggestion, wdyt?