Skip to main content

fileUploadService

Workspace API


Workspace API / services/fileUploadService

services/fileUploadService

Interfaces

FileUploadResult

Defined in: services/fileUploadService.ts:19

Properties

success

success: boolean

Defined in: services/fileUploadService.ts:20

fileId?

optional fileId: string

Defined in: services/fileUploadService.ts:21

filename?

optional filename: string

Defined in: services/fileUploadService.ts:22

fileUrl?

optional fileUrl: string

Defined in: services/fileUploadService.ts:23

fileSize?

optional fileSize: number

Defined in: services/fileUploadService.ts:24

contentType?

optional contentType: string

Defined in: services/fileUploadService.ts:25

error?

optional error: string

Defined in: services/fileUploadService.ts:26

code?

optional code: string

Defined in: services/fileUploadService.ts:27

processingStatus?

optional processingStatus: "failed" | "queued" | "completed"

Defined in: services/fileUploadService.ts:28

processingError?

optional processingError: string

Defined in: services/fileUploadService.ts:29

duplicateInfo?

optional duplicateInfo: DuplicateInfo

Defined in: services/fileUploadService.ts:30

exactDuplicate?

optional exactDuplicate: boolean

Defined in: services/fileUploadService.ts:31

message?

optional message: string

Defined in: services/fileUploadService.ts:32


FileDownloadResult

Defined in: services/fileUploadService.ts:35

Properties

success

success: boolean

Defined in: services/fileUploadService.ts:36

content?

optional content: Buffer<ArrayBufferLike>

Defined in: services/fileUploadService.ts:37

filename?

optional filename: string

Defined in: services/fileUploadService.ts:38

contentType?

optional contentType: string

Defined in: services/fileUploadService.ts:39

fileSize?

optional fileSize: number

Defined in: services/fileUploadService.ts:40

error?

optional error: string

Defined in: services/fileUploadService.ts:41


FileInfo

Defined in: services/fileUploadService.ts:44

Properties

filename

filename: string

Defined in: services/fileUploadService.ts:45

fileSize

fileSize: number

Defined in: services/fileUploadService.ts:46

contentType

contentType: string

Defined in: services/fileUploadService.ts:47

uploadedAt

uploadedAt: Date

Defined in: services/fileUploadService.ts:48

fileUrl

fileUrl: string

Defined in: services/fileUploadService.ts:49


LocationRecord

Defined in: services/fileUploadService.ts:93

Properties

id

id: string

Defined in: services/fileUploadService.ts:94

documentId

documentId: string

Defined in: services/fileUploadService.ts:95

displayPath

displayPath: string

Defined in: services/fileUploadService.ts:96

displayFilename

displayFilename: string

Defined in: services/fileUploadService.ts:97

projectId

projectId: string | null

Defined in: services/fileUploadService.ts:98

organizationId

organizationId: string

Defined in: services/fileUploadService.ts:99

createdAt

createdAt: Date

Defined in: services/fileUploadService.ts:100

createdBy

createdBy: string | null

Defined in: services/fileUploadService.ts:101

deletedAt

deletedAt: Date | null

Defined in: services/fileUploadService.ts:102

deletedBy

deletedBy: string | null

Defined in: services/fileUploadService.ts:103


DocumentRecord

Defined in: services/fileUploadService.ts:106

Properties

id

id: string

Defined in: services/fileUploadService.ts:107

organizationId

organizationId: string

Defined in: services/fileUploadService.ts:108

storagePath

storagePath: string

Defined in: services/fileUploadService.ts:109

fileSizeBytes

fileSizeBytes: number | null

Defined in: services/fileUploadService.ts:110

contentType

contentType: string | null

Defined in: services/fileUploadService.ts:111

contentHash

contentHash: string | null

Defined in: services/fileUploadService.ts:112

status

status: string

Defined in: services/fileUploadService.ts:113

extractionMethod

extractionMethod: string | null

Defined in: services/fileUploadService.ts:114

createdAt

createdAt: Date

Defined in: services/fileUploadService.ts:115

updatedAt

updatedAt: Date

Defined in: services/fileUploadService.ts:116


DuplicateCheckResult

Defined in: services/fileUploadService.ts:119

Properties

contentMatch

contentMatch: { document: DocumentRecord; locations: LocationRecord[]; } | null

Defined in: services/fileUploadService.ts:120

pathConflict

pathConflict: LocationRecord | null

Defined in: services/fileUploadService.ts:124


DuplicateInfo

Defined in: services/fileUploadService.ts:127

Properties

duplicateType

duplicateType: "exact_match" | "content" | "filename"

Defined in: services/fileUploadService.ts:128

contentMatches?

optional contentMatches: boolean

Defined in: services/fileUploadService.ts:129

existingFile

existingFile: object

Defined in: services/fileUploadService.ts:130

documentId

documentId: string

storagePath

storagePath: string

filename

filename: string

uploadedAt

uploadedAt: Date

projectId?

optional projectId: string | null

isDifferentLocation?

optional isDifferentLocation: boolean

Defined in: services/fileUploadService.ts:137

existingLocations?

optional existingLocations: LocationRecord[]

Defined in: services/fileUploadService.ts:138

targetLocation?

optional targetLocation: object

Defined in: services/fileUploadService.ts:139

projectId

projectId: string | null

storagePath

storagePath: string

Functions

computeFileHash()

computeFileHash(fileBuffer): string

Defined in: services/fileUploadService.ts:55

Compute SHA256 hash of file content

Parameters

fileBuffer

Buffer

Returns

string


checkForDuplicates()

checkForDuplicates(contentHash, targetPath, organizationId, log): Promise<DuplicateCheckResult>

Defined in: services/fileUploadService.ts:154

Check for duplicate files by content hash and path Uses parallel queries to check for content matches and path conflicts

Parameters

contentHash

string

SHA256 hash of file content

targetPath

string

Full target display path where file will be uploaded

organizationId

string

Organization ID

log

Logger = logger

Logger instance

Returns

Promise<DuplicateCheckResult>


createLocation()

createLocation(documentId, displayPath, displayFilename, projectId, organizationId, userId, log): Promise<LocationRecord>

Defined in: services/fileUploadService.ts:317

Create a location record (for linking existing content to new path)

Parameters

documentId

string

Document ID to link

displayPath

string

Full display path where user sees the file

displayFilename

string

Filename to display

projectId

Project ID (or null for org-level)

string | null

organizationId

string

Organization ID

userId

string

User ID creating the location

log

Logger = logger

Returns

Promise<LocationRecord>


hasRemainingLocations()

hasRemainingLocations(documentId, organizationId, log): Promise<boolean>

Defined in: services/fileUploadService.ts:392

Check if document has any remaining active locations

Parameters

documentId

string

Document ID to check

organizationId

string

Organization ID

log

Logger = logger

Returns

Promise<boolean>


deleteFileFromLocation()

deleteFileFromLocation(locationId, organizationId, userId, log): Promise<{ deleted: boolean; documentDeleted: boolean; }>

Defined in: services/fileUploadService.ts:436

Delete file from location (soft-delete location, cascade delete document if last location)

Parameters

locationId

string

Location ID to delete

organizationId

string

Organization ID

userId

string

User ID performing deletion

log

Logger = logger

Returns

Promise<{ deleted: boolean; documentDeleted: boolean; }>


replaceExistingFileWithNewChunks()

replaceExistingFileWithNewChunks(duplicate, organizationId, projectId, userId, uniqueFilename, fileBuffer, contentType, contentHash, traceId, originalFilename, excludeFurniture, enableTableDetection, log): Promise<{ newFilePath: string; documentId: string; }>

Defined in: services/fileUploadService.ts:657

Replace existing file with new file, processing new file and updating old document record Uploads new file, processes it (chunks it), then updates old document to point to new file/chunks Keeps old document ID but points to new file and chunks

Parameters

duplicate

DuplicateCheckResult

organizationId

string

projectId

string | null

userId

string

uniqueFilename

string

fileBuffer

Buffer

contentType

string

contentHash

string

traceId

string

originalFilename

string

excludeFurniture

boolean = true

enableTableDetection

boolean = true

log

Logger = logger

Returns

Promise<{ newFilePath: string; documentId: string; }>


replaceExistingFile()

replaceExistingFile(duplicate, organizationId, projectId, log): Promise<{ documentId: string; }>

Defined in: services/fileUploadService.ts:865

Prepare for file replacement - old file version will be preserved by object storage versioning When the new file is uploaded to the same path, versioning automatically preserves the old version

Parameters

duplicate

DuplicateCheckResult

organizationId

string

projectId

string | null

log

Logger = logger

Returns

Promise<{ documentId: string; }>


uploadFile()

uploadFile(organizationId, projectId, userId, filename, fileBuffer, contentType, link, replace, rename, renamedFilename, subfolders, traceId, excludeFurniture, enableTableDetection, log): Promise<FileUploadResult>

Defined in: services/fileUploadService.ts:920

Upload a file to a project folder or organization folder Simplified 4-case decision tree:

  1. Content match + path conflict (same doc at same path) → Already exists
  2. Content match + no path conflict → Link here?
  3. No content match + path conflict → Replace or rename?
  4. No content match + no path conflict → Normal upload

Parameters

organizationId

string

projectId

Project ID if uploading to a project, null if uploading to organization

string | null

userId

string

filename

string

fileBuffer

Buffer

contentType

string

boolean = false

If true, link existing content to new path (Case 2)

replace

boolean = false

If true, replace existing file at path (Case 3)

rename

boolean = false

If true, upload with new name (Case 3)

renamedFilename

string | null

subfolders

string[] = []

traceId

string

excludeFurniture

boolean = true

enableTableDetection

boolean = true

log

Logger = logger

Returns

Promise<FileUploadResult>


downloadFile()

downloadFile(organizationId, projectId, userId, filename, log): Promise<FileDownloadResult>

Defined in: services/fileUploadService.ts:1553

Download a file from a project folder

Parameters

organizationId

string

projectId

string

userId

string

filename

string

log

Logger = logger

Returns

Promise<FileDownloadResult>


getFileInfo()

getFileInfo(organizationId, projectId, userId, log): Promise<{ success: boolean; files?: FileInfo[]; error?: string; }>

Defined in: services/fileUploadService.ts:1629

Get file information from project folder

Parameters

organizationId

string

projectId

string

userId

string

log

Logger = logger

Returns

Promise<{ success: boolean; files?: FileInfo[]; error?: string; }>


deleteFile()

deleteFile(organizationId, projectId, userId, filename, log): Promise<{ success: boolean; error?: string; }>

Defined in: services/fileUploadService.ts:1698

Delete a file from project folder

Parameters

organizationId

string

projectId

string

userId

string

filename

string

log

Logger = logger

Returns

Promise<{ success: boolean; error?: string; }>


uploadFileToOrganization()

uploadFileToOrganization(organizationId, userId, filename, fileBuffer, contentType, replace, uploadAsNew, subfolders, log): Promise<FileUploadResult>

Defined in: services/fileUploadService.ts:1767

Upload a file to organization-level folder (no project)

Parameters

organizationId

string

userId

string

filename

string

fileBuffer

Buffer

contentType

string

replace

boolean = false

uploadAsNew

boolean = false

subfolders

string[] = []

log

Logger = logger

Returns

Promise<FileUploadResult>