@things-factory/attachment-base 7.0.1-alpha.99 → 7.0.1-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/attachment-base",
3
- "version": "7.0.1-alpha.99",
3
+ "version": "7.0.1-beta.1",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -29,11 +29,11 @@
29
29
  "@aws-sdk/s3-presigned-post": "^3.46.0",
30
30
  "@azure/storage-blob": "^12.16.0",
31
31
  "@koa/multer": "^3.0.0",
32
- "@things-factory/auth-base": "^7.0.1-alpha.99",
33
- "@things-factory/env": "^7.0.1-alpha.71",
34
- "@things-factory/shell": "^7.0.1-alpha.97",
32
+ "@things-factory/auth-base": "^7.0.1-beta.1",
33
+ "@things-factory/env": "^7.0.1-beta.1",
34
+ "@things-factory/shell": "^7.0.1-beta.1",
35
35
  "mime": "^3.0.0",
36
36
  "multer": "^1.4.5-lts.1"
37
37
  },
38
- "gitHead": "78a7b8cb64a9c096f779ae19ebac00e2962c2f23"
38
+ "gitHead": "f117e0029bfbd061d3f76caa067ed81305f6c2b7"
39
39
  }
@@ -5,13 +5,15 @@ import promisesAll from 'promises-all'
5
5
  import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
6
6
  import { In } from 'typeorm'
7
7
 
8
- import { logger } from '@things-factory/env'
8
+ import { config, logger } from '@things-factory/env'
9
9
  import { getRepository } from '@things-factory/shell'
10
10
 
11
11
  import { STORAGE } from '../../attachment-const'
12
12
  import { Attachment } from './attachment'
13
13
  import { AttachmentPatch, NewAttachment, UploadURL } from './attachment-types'
14
14
 
15
+ const allowedMimeTypes = config.get('fileUpload/mimeTypes', [])
16
+
15
17
  @Resolver(Attachment)
16
18
  export class AttachmentMutation {
17
19
  @Directive('@transaction')
@@ -106,8 +108,21 @@ export class AttachmentMutation {
106
108
 
107
109
  export async function createAttachment(_: any, { attachment }, context: ResolverContext): Promise<Attachment> {
108
110
  const { file, category, refType = '', refBy, description } = attachment
111
+ const { mimetype } = (await file) as FileUpload
112
+
113
+ if(allowedMimeTypes instanceof Array && allowedMimeTypes.length > 0 && !allowedMimeTypes.includes('*/*')) {
114
+ const isAllowed = allowedMimeTypes.some(type => {
115
+ const [typeMain, typeSub] = type.split('/')
116
+ const [mimeMain, mimeSub] = mimetype.split('/')
117
+ return (typeMain === mimeMain && (typeSub === '*' || typeSub === mimeSub)) || (typeMain === '*' && typeSub === '*')
118
+ })
119
+
120
+ if(!isAllowed) {
121
+ throw Error(context.t(`error.not allowed file type for upload`, { mimetype }))
122
+ }
123
+ }
109
124
 
110
- const { id, path, size, filename, mimetype, encoding, contents } = await STORAGE.uploadFile({ file, context })
125
+ const { id, path, size, filename, encoding, contents } = await STORAGE.uploadFile({ file, context })
111
126
  const { domain, user, tx } = context.state
112
127
 
113
128
  const repository = tx ? tx.getRepository(Attachment) : getRepository(Attachment)
@@ -2,5 +2,6 @@
2
2
  "label.category": "category",
3
3
  "label.file": "file",
4
4
  "label.select file": "select file",
5
- "label.ref_by": "Reference ID"
5
+ "label.ref_by": "Reference ID",
6
+ "error.not allowed file type for upload": "{mimetype} is not an allowed file type for upload."
6
7
  }
@@ -2,5 +2,6 @@
2
2
  "label.category": "カテゴリ",
3
3
  "label.file": "ファイル",
4
4
  "label.select file": "ファイル選択",
5
- "label.ref_by": "参照 ID"
5
+ "label.ref_by": "参照 ID",
6
+ "error.not allowed file type for upload": "{mimetype}はアップロードが許可されていないファイルタイプです。"
6
7
  }
@@ -2,5 +2,6 @@
2
2
  "label.category": "카테고리",
3
3
  "label.file": "파일",
4
4
  "label.select file": "파일 선택",
5
- "label.ref_by": "참조 ID"
5
+ "label.ref_by": "참조 ID",
6
+ "error.not allowed file type for upload": "{mimetype}은 업로드가 허가되지 않은 파일형식입니다."
6
7
  }
@@ -2,5 +2,6 @@
2
2
  "label.category": "kategori",
3
3
  "label.file": "fail",
4
4
  "label.select file": "pilih fail",
5
- "label.ref_by": "rujukan ID"
5
+ "label.ref_by": "rujukan ID",
6
+ "error.not allowed file type for upload": "{mimetype} adalah jenis fail yang tidak dibenarkan untuk dimuat naik."
6
7
  }
@@ -2,5 +2,6 @@
2
2
  "label.category": "分类",
3
3
  "label.file": "文件",
4
4
  "label.select file": "选择文件",
5
- "label.ref_by": "参考 ID"
5
+ "label.ref_by": "参考 ID",
6
+ "error.not allowed file type for upload": "{mimetype}是未经允许的上传文件类型。"
6
7
  }