@@ -17,8 +17,8 @@ import { CreateDocumentDto, DOCUMENT_SOURCE, DOCUMENT_SYSTEM } from './document.
1717import { Document } from './document.entity' ;
1818import { VISIBILITY_FLAG } from '../alcs/application/application-document/application-document.entity' ;
1919
20- const DEFAULT_DB_TAGS = [ 'ORCS Classification: 85100-20' ] ;
21- const DEFAULT_S3_TAGS = 'ORCS-Classification= 85100-20';
20+ const ORCS_LABEL = 'ORCS Classification' ;
21+ const DEFAULT_DOC_TAGS = [ ' 85100-20'] ;
2222
2323@Injectable ( )
2424export class DocumentService {
@@ -52,14 +52,15 @@ export class DocumentService {
5252 user : User ,
5353 source = DOCUMENT_SOURCE . ALC ,
5454 system : DOCUMENT_SYSTEM ,
55+ tags ?: string [ ] ,
5556 ) {
5657 const fileKey = `${ filePath } /${ v4 ( ) } ` ;
5758 const command = new PutObjectCommand ( {
5859 Bucket : this . bucket ,
5960 Key : fileKey ,
6061 Body : await file . toBuffer ( ) ,
6162 ACL : 'bucket-owner-full-control' ,
62- Tagging : DEFAULT_S3_TAGS ,
63+ Tagging : this . formatTagsForS3 ( tags ?? DEFAULT_DOC_TAGS ) ,
6364 ContentType : file . mimetype ,
6465 ContentLength : file . file . bytesRead ,
6566 } ) ;
@@ -72,6 +73,7 @@ export class DocumentService {
7273 fileName,
7374 source,
7475 system,
76+ tags : this . formatTagsForDb ( tags ?? DEFAULT_DOC_TAGS ) ,
7577 } ) ;
7678
7779 this . logger . debug ( `File Uploaded to ${ fileKey } ` ) ;
@@ -87,14 +89,15 @@ export class DocumentService {
8789 user : User ,
8890 source = DOCUMENT_SOURCE . ALC ,
8991 system : DOCUMENT_SYSTEM ,
92+ tags ?: string [ ] ,
9093 ) {
9194 const fileKey = `${ filePath } /${ v4 ( ) } ` ;
9295 const command = new PutObjectCommand ( {
9396 Bucket : this . bucket ,
9497 Key : fileKey ,
9598 Body : file ,
9699 ACL : 'bucket-owner-full-control' ,
97- Tagging : DEFAULT_S3_TAGS ,
100+ Tagging : this . formatTagsForS3 ( tags ?? DEFAULT_DOC_TAGS ) ,
98101 ContentType : mimeType ,
99102 ContentLength : fileSize ,
100103 } ) ;
@@ -107,6 +110,7 @@ export class DocumentService {
107110 fileName,
108111 source,
109112 system,
113+ tags : this . formatTagsForDb ( tags ?? DEFAULT_DOC_TAGS ) ,
110114 } ) ;
111115
112116 this . logger . debug ( `File Uploaded to ${ fileKey } ` ) ;
@@ -121,13 +125,13 @@ export class DocumentService {
121125 await this . documentRepository . softRemove ( documents ) ;
122126 }
123127
124- async getUploadUrl ( filePath : string ) {
128+ async getUploadUrl ( filePath : string , tags ?: string [ ] ) {
125129 const fileKey = `${ filePath } /${ v4 ( ) } ` ;
126130 const command = new PutObjectCommand ( {
127131 Bucket : this . bucket ,
128132 Key : fileKey ,
129133 ACL : 'bucket-owner-full-control' ,
130- Tagging : DEFAULT_S3_TAGS ,
134+ Tagging : this . formatTagsForS3 ( tags ?? DEFAULT_DOC_TAGS ) ,
131135 } ) ;
132136
133137 return {
@@ -263,7 +267,7 @@ export class DocumentService {
263267 source : data . source ,
264268 system : data . system ,
265269 uploadedBy : data . uploadedBy ,
266- tags : DEFAULT_DB_TAGS ,
270+ tags : this . formatTagsForDb ( data . tags ?? DEFAULT_DOC_TAGS ) ,
267271 } ) ,
268272 ) ;
269273 }
@@ -292,4 +296,12 @@ export class DocumentService {
292296 document . source = updates . source ;
293297 await this . documentRepository . save ( document ) ;
294298 }
299+
300+ formatTagsForDb ( tags : string [ ] ) : string [ ] {
301+ return tags . map ( ( tag ) => `${ ORCS_LABEL } : ${ tag } ` ) ;
302+ }
303+
304+ formatTagsForS3 ( tags : string [ ] ) : string {
305+ return tags . map ( ( tag ) => `${ ORCS_LABEL . replace ( / \ / g, '-' ) } =${ tag } ` ) . join ( '&' ) ;
306+ }
295307}
0 commit comments