@things-factory/attachment-base 7.0.0-alpha.8 → 7.0.0
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/attachment-const.d.ts +3 -0
- package/dist-server/awb-storage-s3.d.ts +1 -0
- package/dist-server/awb-storage-s3.js.map +1 -1
- package/dist-server/index.d.ts +7 -0
- package/dist-server/migrations/index.d.ts +1 -0
- package/dist-server/routes.d.ts +4 -0
- package/dist-server/service/attachment/attachment-mutation.d.ts +46 -0
- package/dist-server/service/attachment/attachment-mutation.js +24 -12
- package/dist-server/service/attachment/attachment-mutation.js.map +1 -1
- package/dist-server/service/attachment/attachment-query.d.ts +11 -0
- package/dist-server/service/attachment/attachment-query.js +3 -3
- package/dist-server/service/attachment/attachment-query.js.map +1 -1
- package/dist-server/service/attachment/attachment-types.d.ts +27 -0
- package/dist-server/service/attachment/attachment-types.js +8 -8
- package/dist-server/service/attachment/attachment-types.js.map +1 -1
- package/dist-server/service/attachment/attachment.d.ts +24 -0
- package/dist-server/service/attachment/attachment.js +2 -2
- package/dist-server/service/attachment/attachment.js.map +1 -1
- package/dist-server/service/attachment/index.d.ts +5 -0
- package/dist-server/service/index.d.ts +6 -0
- package/dist-server/storage-azure-blob.d.ts +1 -0
- package/dist-server/storage-azure-blob.js.map +1 -1
- package/dist-server/storage-database.d.ts +1 -0
- package/dist-server/storage-database.js +4 -9
- package/dist-server/storage-database.js.map +1 -1
- package/dist-server/storage-file.d.ts +1 -0
- package/dist-server/storage-file.js.map +1 -1
- package/dist-server/storage-s3.d.ts +1 -0
- package/dist-server/storage-s3.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/dist-server/util/index.d.ts +1 -0
- package/dist-server/util/upload-awb.d.ts +2 -0
- package/dist-server/util/upload-awb.js +1 -2
- package/dist-server/util/upload-awb.js.map +1 -1
- package/package.json +6 -6
- package/server/service/attachment/attachment-mutation.ts +17 -2
- package/server/service/attachment/attachment-query.ts +4 -1
- package/server/service/attachment/attachment.ts +21 -21
- package/server/storage-azure-blob.ts +1 -1
- 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
@@ -0,0 +1 @@
|
|
1
|
+
export * from './upload-awb';
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.uploadAwb =
|
3
|
+
exports.uploadAwb = uploadAwb;
|
4
4
|
require("../awb-storage-s3");
|
5
5
|
const attachment_const_1 = require("../attachment-const");
|
6
6
|
async function uploadAwb(param) {
|
@@ -8,5 +8,4 @@ async function uploadAwb(param) {
|
|
8
8
|
let result = await attachment_const_1.AWBSTORAGE.uploadFile({ stream: content, filename: title });
|
9
9
|
return result;
|
10
10
|
}
|
11
|
-
exports.uploadAwb = uploadAwb;
|
12
11
|
//# sourceMappingURL=upload-awb.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"upload-awb.js","sourceRoot":"","sources":["../../server/util/upload-awb.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"upload-awb.js","sourceRoot":"","sources":["../../server/util/upload-awb.ts"],"names":[],"mappings":";;AAIA,8BAMC;AAVD,6BAA0B;AAE1B,0DAAgD;AAEzC,KAAK,UAAU,SAAS,CAAC,KAAU;IACxC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,KAAK,CAAA;IAEhC,IAAI,MAAM,GAAG,MAAM,6BAAU,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAA;IAE9E,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import '../awb-storage-s3'\n\nimport { AWBSTORAGE } from '../attachment-const'\n\nexport async function uploadAwb(param: any) {\n const { content, title } = param\n\n let result = await AWBSTORAGE.uploadFile({ stream: content, filename: title })\n\n return result\n}\n"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@things-factory/attachment-base",
|
3
|
-
"version": "7.0.0
|
3
|
+
"version": "7.0.0",
|
4
4
|
"main": "dist-server/index.js",
|
5
5
|
"browser": "client/index.js",
|
6
6
|
"things-factory": true,
|
@@ -27,13 +27,13 @@
|
|
27
27
|
"@aws-sdk/client-s3": "^3.46.0",
|
28
28
|
"@aws-sdk/lib-storage": "^3.46.0",
|
29
29
|
"@aws-sdk/s3-presigned-post": "^3.46.0",
|
30
|
-
"@azure/storage-blob": "^12.
|
30
|
+
"@azure/storage-blob": "^12.18.0",
|
31
31
|
"@koa/multer": "^3.0.0",
|
32
|
-
"@things-factory/auth-base": "^7.0.0
|
33
|
-
"@things-factory/env": "^7.0.0
|
34
|
-
"@things-factory/shell": "^7.0.0
|
32
|
+
"@things-factory/auth-base": "^7.0.0",
|
33
|
+
"@things-factory/env": "^7.0.0",
|
34
|
+
"@things-factory/shell": "^7.0.0",
|
35
35
|
"mime": "^3.0.0",
|
36
36
|
"multer": "^1.4.5-lts.1"
|
37
37
|
},
|
38
|
-
"gitHead": "
|
38
|
+
"gitHead": "00f3917ca132679e3571f3f4fd16f4caf84f488e"
|
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)
|
@@ -11,7 +11,10 @@ import { Attachment } from './attachment'
|
|
11
11
|
export class AttachmentQuery {
|
12
12
|
@Directive('@privilege(category: "attachment", privilege: "query", domainOwnerGranted: true)')
|
13
13
|
@Query(returns => AttachmentList)
|
14
|
-
async attachments(
|
14
|
+
async attachments(
|
15
|
+
@Ctx() context: ResolverContext,
|
16
|
+
@Args(type => ListParam) params: ListParam
|
17
|
+
): Promise<AttachmentList> {
|
15
18
|
const { domain } = context.state
|
16
19
|
|
17
20
|
const queryBuilder = getQueryBuilderFromListParams({
|
@@ -34,50 +34,50 @@ const DATABASE_TYPE = ORMCONFIG.type
|
|
34
34
|
export class Attachment {
|
35
35
|
@PrimaryGeneratedColumn('uuid')
|
36
36
|
@Field(type => ID)
|
37
|
-
readonly id
|
37
|
+
readonly id?: string
|
38
38
|
|
39
39
|
@ManyToOne(type => Domain, { nullable: false })
|
40
40
|
@Field(type => Domain)
|
41
|
-
domain
|
41
|
+
domain?: Domain
|
42
42
|
|
43
43
|
@RelationId((attachment: Attachment) => attachment.domain)
|
44
|
-
domainId
|
44
|
+
domainId?: string
|
45
45
|
|
46
46
|
@Column()
|
47
47
|
@Field()
|
48
|
-
name
|
48
|
+
name?: string
|
49
49
|
|
50
50
|
@Column({ nullable: true })
|
51
51
|
@Field({ nullable: true })
|
52
|
-
description
|
52
|
+
description?: string
|
53
53
|
|
54
54
|
@Column()
|
55
55
|
@Field()
|
56
|
-
mimetype
|
56
|
+
mimetype?: string
|
57
57
|
|
58
58
|
@Column()
|
59
59
|
@Field()
|
60
|
-
encoding
|
60
|
+
encoding?: string
|
61
61
|
|
62
62
|
@Column({ nullable: true })
|
63
63
|
@Field({ nullable: true })
|
64
|
-
category
|
64
|
+
category?: string
|
65
65
|
|
66
66
|
@Column({ nullable: true, default: '' })
|
67
67
|
@Field({ nullable: true })
|
68
|
-
refType
|
68
|
+
refType?: string = ''
|
69
69
|
|
70
70
|
@Column({ nullable: true })
|
71
71
|
@Field({ nullable: true })
|
72
|
-
refBy
|
72
|
+
refBy?: string
|
73
73
|
|
74
74
|
@Column()
|
75
75
|
@Field()
|
76
|
-
path
|
76
|
+
path?: string
|
77
77
|
|
78
78
|
@Column()
|
79
79
|
@Field()
|
80
|
-
size
|
80
|
+
size?: string
|
81
81
|
|
82
82
|
@Column({
|
83
83
|
nullable: true,
|
@@ -85,32 +85,32 @@ export class Attachment {
|
|
85
85
|
DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
|
86
86
|
? 'longblob'
|
87
87
|
: DATABASE_TYPE == 'postgres'
|
88
|
-
|
89
|
-
|
88
|
+
? 'bytea'
|
89
|
+
: 'blob'
|
90
90
|
})
|
91
|
-
contents
|
91
|
+
contents?: Buffer
|
92
92
|
|
93
93
|
@CreateDateColumn()
|
94
94
|
@Field()
|
95
|
-
createdAt
|
95
|
+
createdAt?: Date
|
96
96
|
|
97
97
|
@UpdateDateColumn()
|
98
98
|
@Field()
|
99
|
-
updatedAt
|
99
|
+
updatedAt?: Date
|
100
100
|
|
101
101
|
@ManyToOne(type => User)
|
102
102
|
@Field(type => User, { nullable: true })
|
103
|
-
creator
|
103
|
+
creator?: User
|
104
104
|
|
105
105
|
@RelationId((attachment: Attachment) => attachment.creator)
|
106
|
-
creatorId
|
106
|
+
creatorId?: string
|
107
107
|
|
108
108
|
@ManyToOne(type => User)
|
109
109
|
@Field(type => User, { nullable: true })
|
110
|
-
updater
|
110
|
+
updater?: User
|
111
111
|
|
112
112
|
@RelationId((attachment: Attachment) => attachment.updater)
|
113
|
-
updaterId
|
113
|
+
updaterId?: string
|
114
114
|
|
115
115
|
@Field()
|
116
116
|
get fullpath(): string {
|
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
|
}
|