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
5 changes: 5 additions & 0 deletions src/features/webhook/assembly/api/webhook.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export const handleWebhookEvent = async (req: NextRequest) => {
const dropboxConnectionService = new DropboxConnectionsService(user)
const connection = await dropboxConnectionService.getConnectionForWorkspace()

if (!connection.status) {
console.info(`Sync is not enabled for this workspace. Skipping webhook event`)
return NextResponse.json({})
}

if (!connection.refreshToken) throw new APIError('No refresh token found', httpStatus.NOT_FOUND)
if (!connection.accountId) throw new APIError('No accountId found', httpStatus.NOT_FOUND)

Expand Down
19 changes: 15 additions & 4 deletions src/lib/copilot/CopilotAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
CopilotFileCreateSchema,
type CopilotFileList,
CopilotFileListSchema,
CopilotFileRetrieve,
type CopilotFileRetrieve,
CopilotFileRetrieveSchema,
type CopilotListArgs,
type CopilotPrice,
Expand Down Expand Up @@ -191,10 +191,13 @@ export class CopilotAPI {
channelId: string,
fileType: ObjectTypeValue,
): Promise<CreateFileType> {
const saniztedPath = sanitizeFileNameForAssembly(path)
console.info(`CopilotAPI#_createFile. Path: ${saniztedPath}`)

const createFileResponse = await this.copilot.createFile({
fileType,
requestBody: {
path: sanitizeFileNameForAssembly(path),
path: saniztedPath,
channelId,
},
})
Expand All @@ -220,8 +223,16 @@ export class CopilotAPI {
return await this.copilot.deleteFile({ id })
}

async _listFiles(channelId: string, nextToken?: string): Promise<CopilotFileList> {
const list = await this.copilot.listFiles({ channelId, nextToken, limit: MAX_FILES_LIMIT })
async _listFiles(
channelId: string,
nextToken?: string,
customLimit?: number,
): Promise<CopilotFileList> {
const list = await this.copilot.listFiles({
channelId,
nextToken,
limit: customLimit || MAX_FILES_LIMIT,
})
return CopilotFileListSchema.parse(list)
}

Expand Down
9 changes: 9 additions & 0 deletions src/utils/filePath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ export function sanitizePath(path: string) {
}

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
}

export function getFaultyPath(filename: string): string {
return unorm
.nfd(filename) // decompose accents
.replace(/[\u0300-\u036f]/g, '') // remove diacritics
Expand Down