@things-factory/attachment-base 8.0.0-alpha.8 → 8.0.0-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": "8.0.0-alpha.8",
3
+ "version": "8.0.0-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.18.0",
31
31
  "@koa/multer": "^3.0.0",
32
- "@things-factory/auth-base": "^8.0.0-alpha.8",
33
- "@things-factory/env": "^8.0.0-alpha.8",
34
- "@things-factory/shell": "^8.0.0-alpha.8",
32
+ "@things-factory/auth-base": "^8.0.0-beta.1",
33
+ "@things-factory/env": "^8.0.0-beta.1",
34
+ "@things-factory/shell": "^8.0.0-beta.1",
35
35
  "mime": "^3.0.0",
36
36
  "multer": "^1.4.5-lts.1"
37
37
  },
38
- "gitHead": "0a9fb3ab431934982294b58c743d01b6f782a15f"
38
+ "gitHead": "36c494e587640c1490318ef7b95adab02606e0c2"
39
39
  }
package/server/index.ts CHANGED
@@ -13,3 +13,12 @@ import './routes'
13
13
 
14
14
  export * from './attachment-const'
15
15
  export * from './util'
16
+
17
+ import { normalizeNamesToNFC } from './nfc-normalize'
18
+
19
+ process.on('bootstrap-module-start' as any, async ({ app, config, client }: any) => {
20
+ /* 이 코드는 기존 첨부파일의 NFC 정규화를 강제로 실행하기 위해서 임시로 작성되었다. */
21
+ normalizeNamesToNFC()
22
+ .then(() => console.log('Normalization completed.'))
23
+ .catch(err => console.error('Error during normalization:', err))
24
+ })
@@ -0,0 +1,25 @@
1
+ import { getRepository } from '@things-factory/shell'
2
+ import { Attachment } from './service/attachment/attachment'
3
+
4
+ export async function normalizeNamesToNFC() {
5
+ const attachmentRepository = getRepository(Attachment)
6
+
7
+ // 모든 Attachment 항목을 조회
8
+ const attachments = await attachmentRepository.find()
9
+
10
+ // NFD로 저장된 name을 NFC로 변환하여 업데이트
11
+ for (const attachment of attachments) {
12
+ if (attachment.name) {
13
+ const normalizedName = attachment.name.normalize('NFC')
14
+
15
+ // name이 NFD로 저장된 경우만 업데이트
16
+ if (attachment.name !== normalizedName) {
17
+ attachment.name = normalizedName
18
+ await attachmentRepository.save(attachment)
19
+ console.log(`Updated name for attachment ID ${attachment.id}: ${normalizedName}`)
20
+ }
21
+ }
22
+ }
23
+
24
+ console.log('All names have been normalized to NFC.')
25
+ }
@@ -23,20 +23,7 @@ export class AttachmentQuery {
23
23
  domain,
24
24
  alias: 'attachment',
25
25
  searchables: ['name', 'description', 'tags']
26
- }).addSelect([
27
- 'attachment.domain',
28
- 'attachment.id',
29
- 'attachment.name',
30
- 'attachment.path',
31
- 'attachment.size',
32
- 'attachment.mimetype',
33
- 'attachment.encoding',
34
- 'attachment.category',
35
- 'attachment.updatedAt',
36
- 'attachment.updater',
37
- 'attachment.createdAt',
38
- 'attachment.creator'
39
- ])
26
+ })
40
27
 
41
28
  const [items, total] = await queryBuilder.getManyAndCount()
42
29
 
@@ -75,7 +75,10 @@ export class Attachment {
75
75
  @Field()
76
76
  path?: string
77
77
 
78
- @Column()
78
+ @Column({
79
+ nullable: true,
80
+ type: DATABASE_TYPE == 'mssql' ? 'bigint' : undefined
81
+ })
79
82
  @Field()
80
83
  size?: string
81
84
 
@@ -86,7 +89,10 @@ export class Attachment {
86
89
  ? 'longblob'
87
90
  : DATABASE_TYPE == 'postgres'
88
91
  ? 'bytea'
89
- : 'blob'
92
+ : DATABASE_TYPE == 'mssql'
93
+ ? 'varbinary'
94
+ : 'blob',
95
+ length: DATABASE_TYPE == 'mssql' ? 'MAX' : undefined
90
96
  })
91
97
  contents?: Buffer
92
98
 
@@ -11,7 +11,9 @@ const crypto = require('crypto')
11
11
  if (STORAGE && STORAGE.type == 'database') {
12
12
  STORAGE.uploadFile = async ({ id, file, context }) => {
13
13
  var { createReadStream, filename, mimetype, encoding } = await file
14
- filename = Buffer.from(filename, 'latin1').toString('utf-8') /* Because busboy uses latin1 encoding */
14
+ filename = Buffer.from(filename, 'latin1')
15
+ .toString('utf-8')
16
+ .normalize('NFC') /* Because busboy uses latin1 encoding */
15
17
 
16
18
  const stream = createReadStream()
17
19
 
@@ -14,7 +14,9 @@ if (STORAGE && STORAGE.type == 'file') {
14
14
 
15
15
  STORAGE.uploadFile = async ({ id, file }) => {
16
16
  var { createReadStream, filename, mimetype, encoding } = await file
17
- filename = Buffer.from(filename, 'latin1').toString('utf-8') /* Because busboy uses latin1 encoding */
17
+ filename = Buffer.from(filename, 'latin1')
18
+ .toString('utf-8')
19
+ .normalize('NFC') /* Because busboy uses latin1 encoding */
18
20
 
19
21
  const stream = createReadStream()
20
22
 
@@ -36,7 +36,9 @@ if (STORAGE && STORAGE.type == 's3') {
36
36
  /* upload file */
37
37
  STORAGE.uploadFile = async ({ id, file }) => {
38
38
  var { createReadStream, filename, mimetype, encoding } = await file
39
- filename = Buffer.from(filename, 'latin1').toString('utf-8') /* Because busboy uses latin1 encoding */
39
+ filename = Buffer.from(filename, 'latin1')
40
+ .toString('utf-8')
41
+ .normalize('NFC') /* Because busboy uses latin1 encoding */
40
42
 
41
43
  const stream = createReadStream()
42
44
  id = id || crypto.randomUUID()