-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
COMS file upload and PCNS Document create
- Loading branch information
1 parent
757a5c9
commit 9378815
Showing
14 changed files
with
205 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
import { IStamps } from '../interfaces/IStamps'; | ||
import { ChefsSubmissionForm } from './ChefsSubmissionForm'; | ||
|
||
export type Document = { | ||
documentId?: string; // Primary Key | ||
documentId: string; // Primary Key | ||
submissionId: string; | ||
filename: string | null; | ||
mimeType: string | null; | ||
filesize: bigint | null; | ||
submission: ChefsSubmissionForm | null; | ||
filesize: number | null; | ||
} & Partial<IStamps>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { comsAxios } from './interceptors'; | ||
import { setDispositionHeader } from '@/utils/utils'; | ||
|
||
import type { AxiosRequestConfig } from 'axios'; | ||
|
||
const PATH = '/object'; | ||
|
||
export default { | ||
/** | ||
* @function createObject | ||
* Post an object | ||
* @param {any} object Object to be created | ||
* @param {string} bucketId Bucket id containing the object | ||
* @param {AxiosRequestConfig} axiosOptions Axios request config options | ||
* @returns {Promise} An axios response | ||
*/ | ||
async createObject( | ||
object: any, | ||
headers: { | ||
metadata?: Array<{ key: string; value: string }>; | ||
}, | ||
params: { | ||
bucketId?: string; | ||
tagset?: Array<{ key: string; value: string }>; | ||
}, | ||
axiosOptions?: AxiosRequestConfig | ||
) { | ||
// setDispositionHeader constructs header based on file name | ||
// Content-Type defaults octet-stream if MIME type unavailable | ||
const config = { | ||
headers: { | ||
'Content-Disposition': setDispositionHeader(object.name), | ||
'Content-Type': object?.type ?? 'application/octet-stream' | ||
}, | ||
params: { | ||
bucketId: params.bucketId, | ||
tagset: {} | ||
} | ||
}; | ||
|
||
// Map the metadata if required | ||
if (headers.metadata) { | ||
config.headers = { | ||
...config.headers, | ||
...Object.fromEntries(headers.metadata.map((x: { key: string; value: string }) => [x.key, x.value])) | ||
}; | ||
} | ||
|
||
// Map the tagset if required | ||
if (params.tagset) { | ||
config.params.tagset = Object.fromEntries( | ||
params.tagset.map((x: { key: string; value: string }) => [x.key, x.value]) | ||
); | ||
} | ||
|
||
return comsAxios(axiosOptions).put(PATH, object, config); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import comsService from './comsService'; | ||
import { appAxios } from './interceptors'; | ||
|
||
const PATH = '/document'; | ||
|
||
export default { | ||
/** | ||
* @function createDocument | ||
* @returns {Promise} An axios response | ||
*/ | ||
async createDocument(file: File, submissionId: string, bucketId: string) { | ||
let comsResponse; | ||
try { | ||
comsResponse = await comsService.createObject( | ||
file, | ||
{}, | ||
{ bucketId }, | ||
{ timeout: 0 } // Infinite timeout for big files upload to avoid timeout error | ||
); | ||
|
||
return appAxios().put(PATH, { | ||
submissionId: submissionId, | ||
documentId: comsResponse.data.id, | ||
filename: comsResponse.data.name, | ||
mimeType: comsResponse.data.mimeType, | ||
length: comsResponse.data.length | ||
}); | ||
} catch (e) { | ||
// TODO: Delete object if Prisma write fails | ||
} | ||
}, | ||
|
||
async listDocuments(submissionId: string) { | ||
try { | ||
return appAxios().get(`${PATH}/list/${submissionId}`); | ||
} catch (e) { | ||
console.log(e); | ||
Check warning on line 37 in frontend/src/services/documentService.ts GitHub Actions / Unit Tests (Frontend) (16.x)
Check warning on line 37 in frontend/src/services/documentService.ts GitHub Actions / Unit Tests (Frontend) (18.x)
Check warning on line 37 in frontend/src/services/documentService.ts GitHub Actions / Unit Tests (Frontend) (20.x)
Check warning on line 37 in frontend/src/services/documentService.ts GitHub Actions / Unit Tests (Frontend) (16.x)
Check warning on line 37 in frontend/src/services/documentService.ts GitHub Actions / Unit Tests (Frontend) (18.x)
|
||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export { default as AuthService } from './authService'; | ||
export { default as ConfigService } from './configService'; | ||
export { default as chefsService } from './chefsService'; | ||
export { default as comsService } from './comsService'; | ||
export { default as documentService } from './documentService'; | ||
export { default as userService } from './userService'; |
Oops, something went wrong.