Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@
"SERVER_SECRET": "secret",
"ACCOUNTS_URL": "http://localhost:3000",
"COLLABORATOR_API_URL": "http://localhost:3078",
"FRONT_URL": "http://localhost:8080"
"STORAGE_CONFIG": "minio|localhost?accessKey=minioadmin&secretKey=minioadmin",
"MONGO_URL": "mongodb://localhost:27017"
},
"runtimeArgs": ["--nolazy", "-r", "ts-node/register"],
"runtimeVersion": "20",
Expand Down
34 changes: 14 additions & 20 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions dev/doc-import-tool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"build:watch": "compile",
"_phase:bundle": "rushx bundle",
"bundle": "mkdir -p bundle && node esbuild.js",
"run-local": "cross-env SERVER_SECRET=secret COLLABORATOR_URL=ws://localhost:3078 COLLABORATOR_API_URL=http://localhost:3078 FRONT_URL=http://localhost:8087 PRODUCT_ID=ezqms node --nolazy -r ts-node/register ./src/__start.ts",
"run-local": "cross-env SERVER_SECRET=secret MONGO_URL=mongodb://localhost:27017 COLLABORATOR_URL=ws://localhost:3078 COLLABORATOR_API_URL=http://localhost:3078 STORAGE_CONFIG=minio|minio?accessKey=minioadmin&secretKey=minioadmin PRODUCT_ID=ezqms node --nolazy -r ts-node/register ./src/__start.ts",
"run": "cross-env node -r ts-node/register --max-old-space-size=8000 ./src/__start.ts",
"format": "format src",
"test": "jest --passWithNoTests --silent",
Expand All @@ -36,7 +36,6 @@
"esbuild": "^0.20.0",
"@types/minio": "~7.0.11",
"@types/node": "~20.11.16",
"@types/node-fetch": "~2.6.2",
"@typescript-eslint/parser": "^6.11.0",
"eslint-config-standard-with-typescript": "^40.0.0",
"prettier": "^3.1.0",
Expand All @@ -55,18 +54,17 @@
"@hcengineering/core": "^0.6.32",
"@hcengineering/platform": "^0.6.11",
"@hcengineering/server-core": "^0.6.1",
"@hcengineering/server-storage": "^0.6.0",
"@hcengineering/server-token": "^0.6.11",
"@hcengineering/server-tool": "^0.6.0",
"@hcengineering/server-client": "^0.6.0",
"@hcengineering/collaborator-client": "^0.6.4",
"commander": "^8.1.0",
"domhandler": "^5.0.3",
"domutils": "^3.1.0",
"form-data": "^4.0.0",
"htmlparser2": "^9.0.0",
"mammoth": "^1.6.0",
"docx4js": "^3.2.20",
"node-fetch": "^2.6.6",
"zod": "^3.22.4"
}
}
5 changes: 3 additions & 2 deletions dev/doc-import-tool/src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MeasureContext } from '@hcengineering/core'
import docx4js from 'docx4js'
import { AnyNode } from 'domhandler'

Expand All @@ -7,7 +8,7 @@ import importExtractedFile from './import'
import convert from './convert/convert'
import { Config } from './config'

export async function importDoc (config: Config): Promise<void> {
export async function importDoc (ctx: MeasureContext, config: Config): Promise<void> {
const { specFile, doc, backend } = config

const spec = await read(specFile)
Expand All @@ -23,5 +24,5 @@ export async function importDoc (config: Config): Promise<void> {
const contents = await convert(doc, backend)
const extractedFile = await extract(contents, spec, headerRoot)

await importExtractedFile(config, extractedFile)
await importExtractedFile(ctx, config, extractedFile)
}
2 changes: 2 additions & 0 deletions dev/doc-import-tool/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Employee } from '@hcengineering/contact'
import { Ref, WorkspaceId } from '@hcengineering/core'
import { DocumentSpace } from '@hcengineering/controlled-documents'
import { StorageAdapter } from '@hcengineering/server-core'

import { HtmlConversionBackend } from './convert/convert'

Expand All @@ -13,5 +14,6 @@ export interface Config {
owner: Ref<Employee>
backend: HtmlConversionBackend
space: Ref<DocumentSpace>
storageAdapter: StorageAdapter
specFile?: string
}
39 changes: 0 additions & 39 deletions dev/doc-import-tool/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import fs from 'node:fs/promises'
import fetch from 'node-fetch'
import FormData from 'form-data'

export async function readFile (doc: string): Promise<string> {
const buffer = await fs.readFile(doc)
Expand All @@ -21,40 +19,3 @@ export function compareStrExact (a: string, b: string): boolean {
export function clean (s: string): string {
return s.replaceAll('\n', ' ').trim()
}

export async function uploadFile (
contents: string,
name: string,
type: string,
uploadURL: string,
token: string
): Promise<string> {
const data = new FormData()
const buffer = Buffer.from(contents, 'base64')
data.append(
'file',
Object.assign(buffer, {
lastModified: Date.now(),
name,
type
})
)

const resp = await fetch(uploadURL, {
method: 'POST',
headers: {
Authorization: `Bearer ${token}`
},
body: data
})

if (resp.status !== 200) {
if (resp.status === 413) {
throw new Error('File is too large')
} else {
throw Error(`Failed to upload file: ${resp.statusText}`)
}
}

return await resp.text()
}
Loading