@things-factory/reference-app 6.1.94 → 6.1.97
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/tsconfig.tsbuildinfo +1 -1
- package/package.json +34 -34
- package/attachments/03e21709-60c1-4796-bb0b-9920148ce2c6.png +0 -0
- package/attachments/1c5f7b4e-45f7-47dc-94e2-6d4aa04c331d.png +0 -0
- package/attachments/29b819e1-eaf5-4998-b711-1eece872a6c6.png +0 -0
- package/attachments/5c7f2330-a93d-4c48-bcca-6b2a10974386.png +0 -0
- package/attachments/92a49294-725c-445c-8fe3-98d328d6d0a5.png +0 -0
- package/attachments/97e18c62-6e73-4407-a062-276cd25de43a.png +0 -0
- package/attachments/9c6e1599-a4e2-483e-833d-c67e336b27e5.png +0 -0
- package/attachments/9d1d12ea-0140-46cc-8eba-b1ab475bfd98.png +0 -0
- package/attachments/a727d8fa-5afe-47b3-9b29-97a1f26637f3.png +0 -0
- package/attachments/b713c6b6-15e3-4c80-a288-b0e8eba5e091.png +0 -0
- package/attachments/c5a385d9-6a96-481a-9c10-f2cb108ec525.png +0 -0
- package/attachments/c7b6e18b-fd21-49c5-8a38-9b2455957c2a.png +0 -0
- package/attachments/cfbb23dc-a61d-4898-a988-73814f509b11.jpeg +0 -0
- package/attachments/dabc0a7e-bb5b-46a3-b73c-d310c95f0832.png +0 -0
- package/attachments/dd3a00c8-1175-4329-b374-1e7096f338aa.png +0 -0
- package/attachments/f099313a-c616-4753-b2d7-33db2ac29b3b.png +0 -0
- package/attachments/f90a4af7-5555-4078-8960-2c978363ac42.png +0 -0
- package/attachments/fb5bac1e-e5c6-44d3-89fa-b0f23a4dae62.jpeg +0 -0
- package/client/tsconfig.json +0 -13
- package/config.development.js +0 -42
- package/db.sqlite +0 -0
- package/logs/.08636eb59927f12972f6774f5947c8507b3564c2-audit.json +0 -20
- package/logs/.5e5d741d8b7784a2fbad65eedc0fd46946aaf6f2-audit.json +0 -15
- package/logs/application-2023-08-06-10.log +0 -4
- package/logs/application-2023-08-06-19.log +0 -1
- package/logs/connections-2023-08-06-10.log +0 -0
- package/server/constants/index.ts +0 -1
- package/server/constants/type-constants.ts +0 -24
- package/server/controllers/create-data-sample-mockup.ts +0 -291
- package/server/controllers/index.ts +0 -1
- package/server/index.ts +0 -5
- package/server/middlewares/index.ts +0 -3
- package/server/migrations/index.ts +0 -9
- package/server/routes.ts +0 -26
- package/server/service/data-sample-mockup/data-sample-mockup-mutation.ts +0 -19
- package/server/service/data-sample-mockup/data-sample-mockup-type.ts +0 -10
- package/server/service/data-sample-mockup/index.ts +0 -4
- package/server/service/index.ts +0 -19
- package/server/service/reference/index.ts +0 -5
- package/server/service/reference/lambda-call.ts +0 -71
- package/server/service/reference/reference-mutation.ts +0 -53
- package/server/service/reference/reference-query.ts +0 -79
- package/server/tsconfig.json +0 -9
package/server/service/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/* EXPORT ENTITY TYPES */
|
|
2
|
-
|
|
3
|
-
/* IMPORT ENTITIES AND RESOLVERS */
|
|
4
|
-
import { entities as ReferenceEntities, resolvers as ReferenceResolvers } from './reference'
|
|
5
|
-
import { entities as DataSampleMockupEntities, resolvers as DataSampleMockupMutation } from './data-sample-mockup'
|
|
6
|
-
|
|
7
|
-
export const entities = [
|
|
8
|
-
/* ENTITIES */
|
|
9
|
-
...ReferenceEntities,
|
|
10
|
-
...DataSampleMockupEntities
|
|
11
|
-
]
|
|
12
|
-
|
|
13
|
-
export const schema = {
|
|
14
|
-
resolverClasses: [
|
|
15
|
-
/* RESOLVER CLASSES */
|
|
16
|
-
...ReferenceResolvers,
|
|
17
|
-
...DataSampleMockupMutation
|
|
18
|
-
]
|
|
19
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import fetch from 'node-fetch'
|
|
2
|
-
|
|
3
|
-
import { config } from '@things-factory/env'
|
|
4
|
-
import { gqlBuilder } from '@things-factory/utils'
|
|
5
|
-
|
|
6
|
-
const appSyncConfig = config.get('awsAppSync')
|
|
7
|
-
|
|
8
|
-
export async function extractInfos(images) {
|
|
9
|
-
const extraction = {
|
|
10
|
-
success_count: true,
|
|
11
|
-
failure_count: true,
|
|
12
|
-
result: {
|
|
13
|
-
boundaries: true,
|
|
14
|
-
texts: true
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
const query = gqlBuilder.jsonToGraphQLQuery({
|
|
18
|
-
mutation: {
|
|
19
|
-
extractInfos: {
|
|
20
|
-
__args: {
|
|
21
|
-
images
|
|
22
|
-
},
|
|
23
|
-
ocr: extraction,
|
|
24
|
-
barcode: extraction
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
const body = JSON.stringify({ query })
|
|
30
|
-
const response = await fetch(appSyncConfig['apiUrl'], {
|
|
31
|
-
method: 'POST',
|
|
32
|
-
headers: {
|
|
33
|
-
'Content-Type': 'application/graphql',
|
|
34
|
-
'x-api-key': appSyncConfig['apiKey']
|
|
35
|
-
},
|
|
36
|
-
body
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
const jsonRes = await response.json()
|
|
40
|
-
return jsonRes
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// @deprecated
|
|
44
|
-
function getRequestBody(images) {
|
|
45
|
-
// @things-factory/utils gqlBuilder.buildArgs 와 유사
|
|
46
|
-
const imageArgs = images.map(obj => {
|
|
47
|
-
const args = []
|
|
48
|
-
for (let key in obj) {
|
|
49
|
-
args.push(`${key}: \"${obj[key]}\"`)
|
|
50
|
-
}
|
|
51
|
-
return '{' + args.join(',') + '}'
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
// console.log(gqlBuilder.buildArgs(images))
|
|
55
|
-
// console.log(imageArgs)
|
|
56
|
-
|
|
57
|
-
const body = JSON.stringify({
|
|
58
|
-
query: `mutation {
|
|
59
|
-
upload(images: ${imageArgs}) {
|
|
60
|
-
success_count
|
|
61
|
-
failure_count
|
|
62
|
-
results {
|
|
63
|
-
boundaries
|
|
64
|
-
texts
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}`
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
return body
|
|
71
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { FileUpload } from 'graphql-upload/GraphQLUpload.js'
|
|
2
|
-
import GraphQLUpload from 'graphql-upload/GraphQLUpload.js'
|
|
3
|
-
import { Arg, Ctx, Mutation, Resolver, Root } from 'type-graphql'
|
|
4
|
-
|
|
5
|
-
import { Attachment, createAttachments } from '@things-factory/attachment-base'
|
|
6
|
-
import { publishProgress } from '@things-factory/shell'
|
|
7
|
-
import { sleep } from '@things-factory/utils'
|
|
8
|
-
|
|
9
|
-
@Resolver()
|
|
10
|
-
export class ReferenceMutation {
|
|
11
|
-
@Mutation(returns => String, { description: 'To reference of file upload' })
|
|
12
|
-
async referenceUpload(
|
|
13
|
-
@Root() _,
|
|
14
|
-
@Arg('files', () => [GraphQLUpload])
|
|
15
|
-
files: FileUpload[],
|
|
16
|
-
@Ctx() context: ResolverContext
|
|
17
|
-
): Promise<string> {
|
|
18
|
-
const { domain, user, tx } = context.state
|
|
19
|
-
const all = Promise.all(files)
|
|
20
|
-
|
|
21
|
-
if (files?.length > 0) {
|
|
22
|
-
const attachments: Attachment[] = files.map(attachment => {
|
|
23
|
-
return {
|
|
24
|
-
file: attachment,
|
|
25
|
-
refType: 'Reference',
|
|
26
|
-
refBy: 100,
|
|
27
|
-
category: 'Reference'
|
|
28
|
-
} as any
|
|
29
|
-
})
|
|
30
|
-
await createAttachments(_, { attachments }, context)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return 'success'
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
@Mutation(returns => String, { description: 'To reference of pending job progress' })
|
|
37
|
-
async referencePendingJob(@Root() _, @Arg('tag') tag: string, @Ctx() context: ResolverContext): Promise<string> {
|
|
38
|
-
const { domain } = context.state
|
|
39
|
-
|
|
40
|
-
for (var i = 0; i <= 100; i++) {
|
|
41
|
-
await sleep(100)
|
|
42
|
-
|
|
43
|
-
publishProgress({
|
|
44
|
-
domain,
|
|
45
|
-
tag,
|
|
46
|
-
progress: i,
|
|
47
|
-
message: `${i * 10} / 1000`
|
|
48
|
-
})
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return 'success'
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { GraphQLScalarType } from 'graphql'
|
|
2
|
-
import type { FileUpload } from 'graphql-upload/GraphQLUpload.js'
|
|
3
|
-
import GraphQLUpload from 'graphql-upload/GraphQLUpload.js'
|
|
4
|
-
import { Arg, Ctx, Query, Resolver, Root } from 'type-graphql'
|
|
5
|
-
|
|
6
|
-
import { Attachment, createAttachments } from '@things-factory/attachment-base'
|
|
7
|
-
import { publishProgress, ScalarAny } from '@things-factory/shell'
|
|
8
|
-
import { sleep } from '@things-factory/utils'
|
|
9
|
-
|
|
10
|
-
import { extractInfos } from './lambda-call'
|
|
11
|
-
|
|
12
|
-
@Resolver()
|
|
13
|
-
export class ReferenceQuery {
|
|
14
|
-
@Query(returns => [ScalarAny], { description: 'To reference of ocr request' })
|
|
15
|
-
async ocrRequest(
|
|
16
|
-
@Root() _,
|
|
17
|
-
@Arg('images', () => [GraphQLUpload])
|
|
18
|
-
images: FileUpload[],
|
|
19
|
-
@Ctx() context: ResolverContext
|
|
20
|
-
): Promise<GraphQLScalarType[]> {
|
|
21
|
-
const { domain, user, tx } = context.state
|
|
22
|
-
const all = Promise.all(images)
|
|
23
|
-
|
|
24
|
-
if (images?.length > 0) {
|
|
25
|
-
const attachments: Attachment[] = images.map(attachment => {
|
|
26
|
-
return {
|
|
27
|
-
file: attachment,
|
|
28
|
-
refType: 'Reference',
|
|
29
|
-
refBy: 100,
|
|
30
|
-
category: 'Reference'
|
|
31
|
-
} as any
|
|
32
|
-
})
|
|
33
|
-
await createAttachments(_, { attachments }, context)
|
|
34
|
-
|
|
35
|
-
const files = await Promise.all(
|
|
36
|
-
images.map(async file => {
|
|
37
|
-
const { createReadStream, filename, mimetype } = await file
|
|
38
|
-
const readStream = createReadStream()
|
|
39
|
-
const image = await this.streamToString(readStream)
|
|
40
|
-
// format is 'image/jpeg'
|
|
41
|
-
const formatArr = mimetype.split('/')
|
|
42
|
-
return { data: image, name: filename, format: formatArr[formatArr.length - 1] }
|
|
43
|
-
})
|
|
44
|
-
)
|
|
45
|
-
const res: any = await extractInfos(files)
|
|
46
|
-
console.log('interpretImages response', JSON.stringify(res, null, ' '))
|
|
47
|
-
return res.data?.extractInfos
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return []
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
streamToString(stream) {
|
|
54
|
-
const chunks = []
|
|
55
|
-
return new Promise((resolve, reject) => {
|
|
56
|
-
stream.on('data', chunk => chunks.push(Buffer.from(chunk)))
|
|
57
|
-
stream.on('error', err => reject(err))
|
|
58
|
-
stream.on('end', () => resolve(Buffer.concat(chunks).toString('base64')))
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
@Query(returns => String, { description: 'To reference of pending job progress' })
|
|
63
|
-
async ocrPendingJob(@Root() _, @Arg('tag') tag: string, @Ctx() context: ResolverContext): Promise<string> {
|
|
64
|
-
const { domain } = context.state
|
|
65
|
-
|
|
66
|
-
for (var i = 0; i <= 100; i++) {
|
|
67
|
-
await sleep(100)
|
|
68
|
-
|
|
69
|
-
publishProgress({
|
|
70
|
-
domain,
|
|
71
|
-
tag,
|
|
72
|
-
progress: i,
|
|
73
|
-
message: `${i * 10} / 1000`
|
|
74
|
-
})
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return 'success'
|
|
78
|
-
}
|
|
79
|
-
}
|