@things-factory/attachment-base 7.0.1-alpha.10 → 7.0.1-alpha.102
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/dist-server/service/attachment/attachment-mutation.js +13 -1
- package/dist-server/service/attachment/attachment-mutation.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/server/service/attachment/attachment-mutation.ts +17 -2
- package/translations/en.json +2 -1
- package/translations/ja.json +2 -1
- package/translations/ko.json +2 -1
- package/translations/ms.json +2 -1
- package/translations/zh.json +2 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@things-factory/attachment-base",
|
3
|
-
"version": "7.0.1-alpha.
|
3
|
+
"version": "7.0.1-alpha.102",
|
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.
|
33
|
-
"@things-factory/env": "^7.0.1-alpha.
|
34
|
-
"@things-factory/shell": "^7.0.1-alpha.
|
32
|
+
"@things-factory/auth-base": "^7.0.1-alpha.102",
|
33
|
+
"@things-factory/env": "^7.0.1-alpha.71",
|
34
|
+
"@things-factory/shell": "^7.0.1-alpha.102",
|
35
35
|
"mime": "^3.0.0",
|
36
36
|
"multer": "^1.4.5-lts.1"
|
37
37
|
},
|
38
|
-
"gitHead": "
|
38
|
+
"gitHead": "2bce598261c2d7377ea008ee687358480a2869bc"
|
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,
|
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)
|
package/translations/en.json
CHANGED
package/translations/ja.json
CHANGED
package/translations/ko.json
CHANGED
package/translations/ms.json
CHANGED
@@ -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
|
}
|