@things-factory/reference-app 9.0.0-beta.27 → 9.0.0-beta.29
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/constants/index.d.ts +1 -0
- package/dist-server/constants/index.js +5 -0
- package/dist-server/constants/index.js.map +1 -0
- package/dist-server/constants/type-constants.d.ts +22 -0
- package/dist-server/constants/type-constants.js +26 -0
- package/dist-server/constants/type-constants.js.map +1 -0
- package/dist-server/controllers/create-data-sample-mockup.d.ts +2 -0
- package/dist-server/controllers/create-data-sample-mockup.js +239 -0
- package/dist-server/controllers/create-data-sample-mockup.js.map +1 -0
- package/dist-server/controllers/index.d.ts +1 -0
- package/dist-server/controllers/index.js +5 -0
- package/dist-server/controllers/index.js.map +1 -0
- package/dist-server/index.d.ts +4 -0
- package/dist-server/index.js +8 -0
- package/dist-server/index.js.map +1 -0
- package/dist-server/middlewares/index.d.ts +1 -0
- package/dist-server/middlewares/index.js +7 -0
- package/dist-server/middlewares/index.js.map +1 -0
- package/dist-server/migrations/index.d.ts +1 -0
- package/dist-server/migrations/index.js +12 -0
- package/dist-server/migrations/index.js.map +1 -0
- package/dist-server/routes.d.ts +0 -0
- package/dist-server/routes.js +24 -0
- package/dist-server/routes.js.map +1 -0
- package/dist-server/service/data-sample-mockup/data-sample-mockup-mutation.d.ts +4 -0
- package/dist-server/service/data-sample-mockup/data-sample-mockup-mutation.js +28 -0
- package/dist-server/service/data-sample-mockup/data-sample-mockup-mutation.js.map +1 -0
- package/dist-server/service/data-sample-mockup/data-sample-mockup-type.d.ts +4 -0
- package/dist-server/service/data-sample-mockup/data-sample-mockup-type.js +20 -0
- package/dist-server/service/data-sample-mockup/data-sample-mockup-type.js.map +1 -0
- package/dist-server/service/data-sample-mockup/index.d.ts +3 -0
- package/dist-server/service/data-sample-mockup/index.js +7 -0
- package/dist-server/service/data-sample-mockup/index.js.map +1 -0
- package/dist-server/service/index.d.ts +4 -0
- package/dist-server/service/index.js +20 -0
- package/dist-server/service/index.js.map +1 -0
- package/dist-server/service/reference/index.d.ts +4 -0
- package/dist-server/service/reference/index.js +8 -0
- package/dist-server/service/reference/index.js.map +1 -0
- package/dist-server/service/reference/lambda-call.d.ts +1 -0
- package/dist-server/service/reference/lambda-call.js +67 -0
- package/dist-server/service/reference/lambda-call.js.map +1 -0
- package/dist-server/service/reference/reference-mutation.d.ts +5 -0
- package/dist-server/service/reference/reference-mutation.js +63 -0
- package/dist-server/service/reference/reference-mutation.js.map +1 -0
- package/dist-server/service/reference/reference-query.d.ts +7 -0
- package/dist-server/service/reference/reference-query.js +84 -0
- package/dist-server/service/reference/reference-query.js.map +1 -0
- package/dist-server/tsconfig.tsbuildinfo +1 -0
- package/package.json +36 -36
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractInfos = extractInfos;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
|
|
6
|
+
const env_1 = require("@things-factory/env");
|
|
7
|
+
const utils_1 = require("@things-factory/utils");
|
|
8
|
+
const appSyncConfig = env_1.config.get('awsAppSync');
|
|
9
|
+
async function extractInfos(images) {
|
|
10
|
+
const extraction = {
|
|
11
|
+
success_count: true,
|
|
12
|
+
failure_count: true,
|
|
13
|
+
result: {
|
|
14
|
+
boundaries: true,
|
|
15
|
+
texts: true
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const query = utils_1.gqlBuilder.jsonToGraphQLQuery({
|
|
19
|
+
mutation: {
|
|
20
|
+
extractInfos: {
|
|
21
|
+
__args: {
|
|
22
|
+
images
|
|
23
|
+
},
|
|
24
|
+
ocr: extraction,
|
|
25
|
+
barcode: extraction
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
const body = JSON.stringify({ query });
|
|
30
|
+
const response = await (0, node_fetch_1.default)(appSyncConfig['apiUrl'], {
|
|
31
|
+
method: 'POST',
|
|
32
|
+
headers: {
|
|
33
|
+
'Content-Type': 'application/graphql',
|
|
34
|
+
'x-api-key': appSyncConfig['apiKey']
|
|
35
|
+
},
|
|
36
|
+
body
|
|
37
|
+
});
|
|
38
|
+
const jsonRes = await response.json();
|
|
39
|
+
return jsonRes;
|
|
40
|
+
}
|
|
41
|
+
// @deprecated
|
|
42
|
+
function getRequestBody(images) {
|
|
43
|
+
// @things-factory/utils gqlBuilder.buildArgs 와 유사
|
|
44
|
+
const imageArgs = images.map(obj => {
|
|
45
|
+
const args = [];
|
|
46
|
+
for (let key in obj) {
|
|
47
|
+
args.push(`${key}: \"${obj[key]}\"`);
|
|
48
|
+
}
|
|
49
|
+
return '{' + args.join(',') + '}';
|
|
50
|
+
});
|
|
51
|
+
// console.log(gqlBuilder.buildArgs(images))
|
|
52
|
+
// console.log(imageArgs)
|
|
53
|
+
const body = JSON.stringify({
|
|
54
|
+
query: `mutation {
|
|
55
|
+
upload(images: ${imageArgs}) {
|
|
56
|
+
success_count
|
|
57
|
+
failure_count
|
|
58
|
+
results {
|
|
59
|
+
boundaries
|
|
60
|
+
texts
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}`
|
|
64
|
+
});
|
|
65
|
+
return body;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=lambda-call.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lambda-call.js","sourceRoot":"","sources":["../../../server/service/reference/lambda-call.ts"],"names":[],"mappings":";;AAOA,oCAiCC;;AAxCD,oEAA8B;AAE9B,6CAA4C;AAC5C,iDAAkD;AAElD,MAAM,aAAa,GAAG,YAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;AAEvC,KAAK,UAAU,YAAY,CAAC,MAAM;IACvC,MAAM,UAAU,GAAG;QACjB,aAAa,EAAE,IAAI;QACnB,aAAa,EAAE,IAAI;QACnB,MAAM,EAAE;YACN,U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AA;AACb,CAAC","sourcesContent":["import fetch from 'node-fetch'\n\nimport { config } from '@things-factory/env'\nimport { gqlBuilder } from '@things-factory/utils'\n\nconst appSyncConfig = config.get('awsAppSync')\n\nexport async function extractInfos(images) {\n const extraction = {\n success_count: true,\n failure_count: true,\n result: {\n boundaries: true,\n texts: true\n }\n }\n const query = gqlBuilder.jsonToGraphQLQuery({\n mutation: {\n extractInfos: {\n __args: {\n images\n },\n ocr: extraction,\n barcode: extraction\n }\n }\n })\n\n const body = JSON.stringify({ query })\n const response = await fetch(appSyncConfig['apiUrl'], {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/graphql',\n 'x-api-key': appSyncConfig['apiKey']\n },\n body\n })\n\n const jsonRes = await response.json()\n return jsonRes\n}\n\n// @deprecated\nfunction getRequestBody(images) {\n // @things-factory/utils gqlBuilder.buildArgs 와 유사\n const imageArgs = images.map(obj => {\n const args = []\n for (let key in obj) {\n args.push(`${key}: \\\"${obj[key]}\\\"`)\n }\n return '{' + args.join(',') + '}'\n })\n\n // console.log(gqlBuilder.buildArgs(images))\n // console.log(imageArgs)\n\n const body = JSON.stringify({\n query: `mutation {\n upload(images: ${imageArgs}) { \n success_count\n failure_count\n results {\n boundaries\n texts\n } \n }\n }`\n })\n\n return body\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { FileUpload } from 'graphql-upload/GraphQLUpload.js';
|
|
2
|
+
export declare class ReferenceMutation {
|
|
3
|
+
referenceUpload(_: any, files: FileUpload[], context: ResolverContext): Promise<string>;
|
|
4
|
+
referencePendingJob(_: any, tag: string, context: ResolverContext): Promise<string>;
|
|
5
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReferenceMutation = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const GraphQLUpload_js_1 = tslib_1.__importDefault(require("graphql-upload/GraphQLUpload.js"));
|
|
6
|
+
const type_graphql_1 = require("type-graphql");
|
|
7
|
+
const attachment_base_1 = require("@things-factory/attachment-base");
|
|
8
|
+
const shell_1 = require("@things-factory/shell");
|
|
9
|
+
const utils_1 = require("@things-factory/utils");
|
|
10
|
+
let ReferenceMutation = class ReferenceMutation {
|
|
11
|
+
async referenceUpload(_, files, context) {
|
|
12
|
+
const { domain, user, tx } = context.state;
|
|
13
|
+
const all = Promise.all(files);
|
|
14
|
+
if ((files === null || files === void 0 ? void 0 : files.length) > 0) {
|
|
15
|
+
const attachments = files.map(attachment => {
|
|
16
|
+
return {
|
|
17
|
+
file: attachment,
|
|
18
|
+
refType: 'Reference',
|
|
19
|
+
refBy: 100,
|
|
20
|
+
category: 'Reference'
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
await (0, attachment_base_1.createAttachments)(_, { attachments }, context);
|
|
24
|
+
}
|
|
25
|
+
return 'success';
|
|
26
|
+
}
|
|
27
|
+
async referencePendingJob(_, tag, context) {
|
|
28
|
+
const { domain } = context.state;
|
|
29
|
+
for (var i = 0; i <= 100; i++) {
|
|
30
|
+
await (0, utils_1.sleep)(100);
|
|
31
|
+
(0, shell_1.publishProgress)({
|
|
32
|
+
domain,
|
|
33
|
+
tag,
|
|
34
|
+
progress: i,
|
|
35
|
+
message: `${i * 10} / 1000`
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return 'success';
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.ReferenceMutation = ReferenceMutation;
|
|
42
|
+
tslib_1.__decorate([
|
|
43
|
+
(0, type_graphql_1.Mutation)(returns => String, { description: 'To reference of file upload' }),
|
|
44
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
45
|
+
tslib_1.__param(1, (0, type_graphql_1.Arg)('files', () => [GraphQLUpload_js_1.default])),
|
|
46
|
+
tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
|
|
47
|
+
tslib_1.__metadata("design:type", Function),
|
|
48
|
+
tslib_1.__metadata("design:paramtypes", [Object, Array, Object]),
|
|
49
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
50
|
+
], ReferenceMutation.prototype, "referenceUpload", null);
|
|
51
|
+
tslib_1.__decorate([
|
|
52
|
+
(0, type_graphql_1.Mutation)(returns => String, { description: 'To reference of pending job progress' }),
|
|
53
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
54
|
+
tslib_1.__param(1, (0, type_graphql_1.Arg)('tag')),
|
|
55
|
+
tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
|
|
56
|
+
tslib_1.__metadata("design:type", Function),
|
|
57
|
+
tslib_1.__metadata("design:paramtypes", [Object, String, Object]),
|
|
58
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
59
|
+
], ReferenceMutation.prototype, "referencePendingJob", null);
|
|
60
|
+
exports.ReferenceMutation = ReferenceMutation = tslib_1.__decorate([
|
|
61
|
+
(0, type_graphql_1.Resolver)()
|
|
62
|
+
], ReferenceMutation);
|
|
63
|
+
//# sourceMappingURL=reference-mutation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reference-mutation.js","sourceRoot":"","sources":["../../../server/service/reference/reference-mutation.ts"],"names":[],"mappings":";;;;AACA,+FAA2D;AAC3D,+CAAiE;AAEjE,qEAA+E;AAC/E,iDAAuD;AACvD,iDAA6C;AAGtC,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAEtB,AAAN,KAAK,CAAC,eAAe,CACX,CAAC,EAET,KAAmB,EACZ,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAC1C,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QAE9B,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,MAAM,IAAG,CAAC,EAAE,CAAC;YACtB,MAAM,WAAW,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AA,mBAAI,GAAE,CAAA;IAAK,mBAAA,IAAA,kBAAG,EAAC,KAAK,CAAC,CAAA;IAAe,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;4DAenE;4BA1CU,iBAAiB;IAD7B,IAAA,uBAAQ,GAAE;GACE,iBAAiB,CA2C7B","sourcesContent":["import type { FileUpload } from 'graphql-upload/GraphQLUpload.js'\nimport GraphQLUpload from 'graphql-upload/GraphQLUpload.js'\nimport { Arg, Ctx, Mutation, Resolver, Root } from 'type-graphql'\n\nimport { Attachment, createAttachments } from '@things-factory/attachment-base'\nimport { publishProgress } from '@things-factory/shell'\nimport { sleep } from '@things-factory/utils'\n\n@Resolver()\nexport class ReferenceMutation {\n @Mutation(returns => String, { description: 'To reference of file upload' })\n async referenceUpload(\n @Root() _,\n @Arg('files', () => [GraphQLUpload])\n files: FileUpload[],\n @Ctx() context: ResolverContext\n ): Promise<string> {\n const { domain, user, tx } = context.state\n const all = Promise.all(files)\n\n if (files?.length > 0) {\n const attachments: Attachment[] = files.map(attachment => {\n return {\n file: attachment,\n refType: 'Reference',\n refBy: 100,\n category: 'Reference'\n } as any\n })\n await createAttachments(_, { attachments }, context)\n }\n\n return 'success'\n }\n\n @Mutation(returns => String, { description: 'To reference of pending job progress' })\n async referencePendingJob(@Root() _, @Arg('tag') tag: string, @Ctx() context: ResolverContext): Promise<string> {\n const { domain } = context.state\n\n for (var i = 0; i <= 100; i++) {\n await sleep(100)\n\n publishProgress({\n domain,\n tag,\n progress: i,\n message: `${i * 10} / 1000`\n })\n }\n\n return 'success'\n }\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { GraphQLScalarType } from 'graphql';
|
|
2
|
+
import type { FileUpload } from 'graphql-upload/GraphQLUpload.js';
|
|
3
|
+
export declare class ReferenceQuery {
|
|
4
|
+
ocrRequest(_: any, images: FileUpload[], context: ResolverContext): Promise<GraphQLScalarType[]>;
|
|
5
|
+
streamToString(stream: any): Promise<unknown>;
|
|
6
|
+
ocrPendingJob(_: any, tag: string, context: ResolverContext): Promise<string>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReferenceQuery = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const GraphQLUpload_js_1 = tslib_1.__importDefault(require("graphql-upload/GraphQLUpload.js"));
|
|
6
|
+
const type_graphql_1 = require("type-graphql");
|
|
7
|
+
const attachment_base_1 = require("@things-factory/attachment-base");
|
|
8
|
+
const shell_1 = require("@things-factory/shell");
|
|
9
|
+
const utils_1 = require("@things-factory/utils");
|
|
10
|
+
const lambda_call_1 = require("./lambda-call");
|
|
11
|
+
let ReferenceQuery = class ReferenceQuery {
|
|
12
|
+
async ocrRequest(_, images, context) {
|
|
13
|
+
var _a;
|
|
14
|
+
const { domain, user, tx } = context.state;
|
|
15
|
+
const all = Promise.all(images);
|
|
16
|
+
if ((images === null || images === void 0 ? void 0 : images.length) > 0) {
|
|
17
|
+
const attachments = images.map(attachment => {
|
|
18
|
+
return {
|
|
19
|
+
file: attachment,
|
|
20
|
+
refType: 'Reference',
|
|
21
|
+
refBy: 100,
|
|
22
|
+
category: 'Reference'
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
await (0, attachment_base_1.createAttachments)(_, { attachments }, context);
|
|
26
|
+
const files = await Promise.all(images.map(async (file) => {
|
|
27
|
+
const { createReadStream, filename, mimetype } = await file;
|
|
28
|
+
const readStream = createReadStream();
|
|
29
|
+
const image = await this.streamToString(readStream);
|
|
30
|
+
// format is 'image/jpeg'
|
|
31
|
+
const formatArr = mimetype.split('/');
|
|
32
|
+
return { data: image, name: filename, format: formatArr[formatArr.length - 1] };
|
|
33
|
+
}));
|
|
34
|
+
const res = await (0, lambda_call_1.extractInfos)(files);
|
|
35
|
+
console.log('interpretImages response', JSON.stringify(res, null, ' '));
|
|
36
|
+
return (_a = res.data) === null || _a === void 0 ? void 0 : _a.extractInfos;
|
|
37
|
+
}
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
streamToString(stream) {
|
|
41
|
+
const chunks = [];
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
stream.on('data', chunk => chunks.push(Buffer.from(chunk)));
|
|
44
|
+
stream.on('error', err => reject(err));
|
|
45
|
+
stream.on('end', () => resolve(Buffer.concat(chunks).toString('base64')));
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async ocrPendingJob(_, tag, context) {
|
|
49
|
+
const { domain } = context.state;
|
|
50
|
+
for (var i = 0; i <= 100; i++) {
|
|
51
|
+
await (0, utils_1.sleep)(100);
|
|
52
|
+
(0, shell_1.publishProgress)({
|
|
53
|
+
domain,
|
|
54
|
+
tag,
|
|
55
|
+
progress: i,
|
|
56
|
+
message: `${i * 10} / 1000`
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return 'success';
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
exports.ReferenceQuery = ReferenceQuery;
|
|
63
|
+
tslib_1.__decorate([
|
|
64
|
+
(0, type_graphql_1.Query)(returns => [shell_1.ScalarAny], { description: 'To reference of ocr request' }),
|
|
65
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
66
|
+
tslib_1.__param(1, (0, type_graphql_1.Arg)('images', () => [GraphQLUpload_js_1.default])),
|
|
67
|
+
tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
|
|
68
|
+
tslib_1.__metadata("design:type", Function),
|
|
69
|
+
tslib_1.__metadata("design:paramtypes", [Object, Array, Object]),
|
|
70
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
71
|
+
], ReferenceQuery.prototype, "ocrRequest", null);
|
|
72
|
+
tslib_1.__decorate([
|
|
73
|
+
(0, type_graphql_1.Query)(returns => String, { description: 'To reference of pending job progress' }),
|
|
74
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
75
|
+
tslib_1.__param(1, (0, type_graphql_1.Arg)('tag')),
|
|
76
|
+
tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
|
|
77
|
+
tslib_1.__metadata("design:type", Function),
|
|
78
|
+
tslib_1.__metadata("design:paramtypes", [Object, String, Object]),
|
|
79
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
80
|
+
], ReferenceQuery.prototype, "ocrPendingJob", null);
|
|
81
|
+
exports.ReferenceQuery = ReferenceQuery = tslib_1.__decorate([
|
|
82
|
+
(0, type_graphql_1.Resolver)()
|
|
83
|
+
], ReferenceQuery);
|
|
84
|
+
//# sourceMappingURL=reference-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reference-query.js","sourceRoot":"","sources":["../../../server/service/reference/reference-query.ts"],"names":[],"mappings":";;;;AAEA,+FAA2D;AAC3D,+CAA8D;AAE9D,qEAA+E;AAC/E,iDAAkE;AAClE,iDAA6C;AAE7C,+CAA4C;AAGrC,IAAM,cAAc,GAApB,MAAM,cAAc;IAEnB,AAAN,KAAK,CAAC,UAAU,CACN,CAAC,EAET,MAAoB,EACb,OAAwB;;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAC1C,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QAE/B,IAAI,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,IAAG,CAAC,EAAE,CAAC;YACvB,MAAM,WAAW,GAAiB,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;gBACxD,OAAO;oBACL,IAAI,EAAE,UAAU;oBAChB,OAAO,EAAE,WAAW;oBACpB,KAAK,EAAE,GAAG;oBACV,QAAQ,EAAE,WAAW;iBACf,CAAA;YACV,CAAC,CAAC,CAAA;YACF,MAAM,IAAA,mCAAiB,EAAC,CAAC,EAAE,EAAE,WAAW,EAAE,E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CAAA;;;;mDAe7D;yBAjEU,cAAc;IAD1B,IAAA,uBAAQ,GAAE;GACE,cAAc,CAkE1B","sourcesContent":["import { GraphQLScalarType } from 'graphql'\nimport type { FileUpload } from 'graphql-upload/GraphQLUpload.js'\nimport GraphQLUpload from 'graphql-upload/GraphQLUpload.js'\nimport { Arg, Ctx, Query, Resolver, Root } from 'type-graphql'\n\nimport { Attachment, createAttachments } from '@things-factory/attachment-base'\nimport { publishProgress, ScalarAny } from '@things-factory/shell'\nimport { sleep } from '@things-factory/utils'\n\nimport { extractInfos } from './lambda-call'\n\n@Resolver()\nexport class ReferenceQuery {\n @Query(returns => [ScalarAny], { description: 'To reference of ocr request' })\n async ocrRequest(\n @Root() _,\n @Arg('images', () => [GraphQLUpload])\n images: FileUpload[],\n @Ctx() context: ResolverContext\n ): Promise<GraphQLScalarType[]> {\n const { domain, user, tx } = context.state\n const all = Promise.all(images)\n\n if (images?.length > 0) {\n const attachments: Attachment[] = images.map(attachment => {\n return {\n file: attachment,\n refType: 'Reference',\n refBy: 100,\n category: 'Reference'\n } as any\n })\n await createAttachments(_, { attachments }, context)\n\n const files = await Promise.all(\n images.map(async file => {\n const { createReadStream, filename, mimetype } = await file\n const readStream = createReadStream()\n const image = await this.streamToString(readStream)\n // format is 'image/jpeg'\n const formatArr = mimetype.split('/')\n return { data: image, name: filename, format: formatArr[formatArr.length - 1] }\n })\n )\n const res: any = await extractInfos(files)\n console.log('interpretImages response', JSON.stringify(res, null, ' '))\n return res.data?.extractInfos\n }\n\n return []\n }\n\n streamToString(stream) {\n const chunks = []\n return new Promise((resolve, reject) => {\n stream.on('data', chunk => chunks.push(Buffer.from(chunk)))\n stream.on('error', err => reject(err))\n stream.on('end', () => resolve(Buffer.concat(chunks).toString('base64')))\n })\n }\n\n @Query(returns => String, { description: 'To reference of pending job progress' })\n async ocrPendingJob(@Root() _, @Arg('tag') tag: string, @Ctx() context: ResolverContext): Promise<string> {\n const { domain } = context.state\n\n for (var i = 0; i <= 100; i++) {\n await sleep(100)\n\n publishProgress({\n domain,\n tag,\n progress: i,\n message: `${i * 10} / 1000`\n })\n }\n\n return 'success'\n }\n}\n"]}
|