Skip to content

Commit

Permalink
Fix file upload (#13)
Browse files Browse the repository at this point in the history
* fix file uppload

* fix
  • Loading branch information
umihai29 authored Feb 18, 2025
1 parent 24d21fd commit 6de04b8
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 33 deletions.
14 changes: 14 additions & 0 deletions middleware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,19 @@ async function createServer() {
followRedirects: true,
});

const filesApiProxy = createProxyMiddleware({
pathFilter: '/files',
pathRewrite: { '^/files': '' },
target: process.env.CUSTOMER_OS_API_PATH + '/files/v1/files',
changeOrigin: true,
headers: {
'X-Openline-API-KEY': process.env.INTERNAL_API_KEY,
},
logger: console,
preserveHeaderKeyCase: true,
followRedirects: true,
});

const basConfigProxy = createProxyMiddleware({
pathFilter: '/bas',
pathRewrite: { '^/bas': '' },
Expand All @@ -243,6 +256,7 @@ async function createServer() {
app.use(customerOsApiRestProxy);
app.use(customerOsApiRestProxyForTenant);
app.use(internalApiProxy);
app.use(filesApiProxy);
app.use(basConfigProxy);

//login button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,20 @@ export const ContactNameCell = observer(
{contactName}
</p>
)}
<Icon
name={'eye'}
className='text-gray-400 ml-2 opacity-0 group-hover/contact-preview:opacity-100 cursor-pointer'
onClick={() => {
if (store.ui.showPreviewCard && store.ui.focusRow === contactId) {
store.ui.setShowPreviewCard(false);
} else {
store.ui.setFocusRow(contactId);
store.ui.setShowPreviewCard(true);
}
}}
/>
<div>
<Icon
name={'eye'}
className='text-gray-400 ml-2 opacity-0 group-hover/contact-preview:opacity-100 cursor-pointer'
onClick={() => {
if (store.ui.showPreviewCard && store.ui.focusRow === contactId) {
store.ui.setShowPreviewCard(false);
} else {
store.ui.setFocusRow(contactId);
store.ui.setShowPreviewCard(true);
}
}}
/>
</div>
</div>
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ export const ContractUploader = observer(
label='Upload a document'
>
<FileUploadTrigger
apiBaseUrl='/fs'
apiBaseUrl='/files'
name='contractUpload'
onError={handleError}
onLoadStart={handelLoad}
onLoadEnd={handleLoadEnd}
onSuccess={handleAddAttachment}
endpointOptions={{
fileKeyName: 'file',
uploadUrl: '/files',
uploadUrl: '',
}}
onChange={(file, refId) => {
setFiles((prev) => [...prev, { file, refId }]);
Expand All @@ -105,18 +105,18 @@ export const ContractUploader = observer(
</div>

<FileDropUploader
apiBaseUrl='/files'
onError={handleError}
onLoadStart={handelLoad}
onLoadEnd={handleLoadEnd}
apiBaseUrl='/internal/files'
onSuccess={handleAddAttachment}
onDragOverChange={setIsDragging}
onChange={(file, refId) => {
setFiles((prev) => [...prev, { file, refId }]);
}}
endpointOptions={{
fileKeyName: 'file',
uploadUrl: '/internal/files',
uploadUrl: '',
}}
onChange={(file, refId) => {
setFiles((prev) => [...prev, { file, refId }]);
}}
>
<div className='min-h-5 gap-2'>
Expand All @@ -132,8 +132,8 @@ export const ContractUploader = observer(
id={id}
key={id}
fileName={fileName}
href={`/files/${id}/download`}
onRemove={handleRemoveAttachment}
href={`/internal/files/${id}/download`}
/>
))}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ export const LogoUploader = observer(() => {
</p>

<FileUploadTrigger
apiBaseUrl='/fs'
onChange={setFile}
apiBaseUrl='/files'
name='logoUploader'
onError={handleError}
onLoadStart={handelLoad}
onLoadEnd={handleLoadEnd}
onSuccess={handleTenantLogoUpdate}
endpointOptions={{
fileKeyName: 'file',
uploadUrl: '/files',
uploadUrl: '',
}}
className={cn(
ghostButton({ colorScheme: 'gray' }),
Expand All @@ -93,16 +93,16 @@ export const LogoUploader = observer(() => {
</div>

<FileDropUploader
apiBaseUrl='/fs'
onChange={setFile}
apiBaseUrl='/files'
onError={handleError}
onLoadStart={handelLoad}
onLoadEnd={handleLoadEnd}
onDragOverChange={setIsDragging}
onSuccess={handleTenantLogoUpdate}
endpointOptions={{
fileKeyName: 'file',
uploadUrl: '/files',
uploadUrl: '',
}}
>
{isDragging ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ export const General = () => {

<FileDropUploader
onChange={setFile}
apiBaseUrl='/files'
onError={handleError}
onLoadStart={handelLoad}
onLoadEnd={handleLoadEnd}
apiBaseUrl='/internal/files'
onDragOverChange={setIsDragging}
onSuccess={handleTenantLogoUpdate}
endpointOptions={{
fileKeyName: 'file',
uploadUrl: '/files',
uploadUrl: '',
}}
>
{isDragging ? (
Expand All @@ -117,16 +117,16 @@ export const General = () => {
label='Upload a square logo no bigger than 1MB'
>
<FileUploadTrigger
apiBaseUrl='/fs'
onChange={setFile}
apiBaseUrl='/files'
name='logoUploader'
onError={handleError}
onLoadStart={handelLoad}
onLoadEnd={handleLoadEnd}
onSuccess={handleTenantLogoUpdate}
endpointOptions={{
fileKeyName: 'file',
uploadUrl: '/files',
uploadUrl: '',
}}
className={cn(
outlineButton({ colorScheme: 'gray' }),
Expand Down
9 changes: 4 additions & 5 deletions src/store/Files/Files.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class FilesStore {
this.loaders.set(fileId, true);

const res = await this.transport.http.get(
`/fs/files/${fileId}/download?inline=true`,
`/files/${fileId}/download?inline=true`,
{
responseType: 'blob',
},
Expand Down Expand Up @@ -67,10 +67,9 @@ export class FilesStore {
try {
this.loaders.set(fileId, true);

const res = await this.transport.http.get(
`/fs/files/${fileId}/download`,
{ responseType: 'blob' },
);
const res = await this.transport.http.get(`/files/${fileId}/download`, {
responseType: 'blob',
});
const mimeType = res.data.type;
const blobUrl = window.URL.createObjectURL(res.data);
const fileExtension = this.getFileExtension(mimeType);
Expand Down

0 comments on commit 6de04b8

Please sign in to comment.