diff options
Diffstat (limited to 'lib/vendor-document-list/import-service.ts')
| -rw-r--r-- | lib/vendor-document-list/import-service.ts | 71 |
1 files changed, 67 insertions, 4 deletions
diff --git a/lib/vendor-document-list/import-service.ts b/lib/vendor-document-list/import-service.ts index 9e1016ea..f2c62d0b 100644 --- a/lib/vendor-document-list/import-service.ts +++ b/lib/vendor-document-list/import-service.ts @@ -471,7 +471,7 @@ class ImportService { */ private encryptDES(text: string): string { try { - const cipher = crypto.createCipher('des-ecb', this.DES_KEY) + const cipher = crypto.createCipheriv('des-ecb', this.DES_KEY, '') cipher.setAutoPadding(true) let encrypted = cipher.update(text, 'utf8', 'base64') encrypted += cipher.final('base64') @@ -498,7 +498,13 @@ class ImportService { const downloadUrl = `${process.env.DOLCE_DOWNLOAD_URL}?key=${encryptedKey}` ||`http://60.100.99.217:1111/Download.aspx?key=${encryptedKey}` - console.log(`Downloading file: ${fileName} with key: ${encryptedKey.substring(0, 20)}...`) + console.log(`π DOLCE λ€μ΄λ‘λ λ§ν¬ μμ±:`) + console.log(` νμΌλͺ
: ${fileName}`) + console.log(` FileId: ${fileId}`) + console.log(` UserId: ${userId}`) + console.log(` μνΈν ν€: ${encryptedKey}`) + console.log(` λ€μ΄λ‘λ URL: ${downloadUrl}`) + console.log(`π₯ DOLCEμμ νμΌ λ€μ΄λ‘λ μμ: ${fileName}`) const response = await fetch(downloadUrl, { method: 'GET', @@ -508,16 +514,18 @@ class ImportService { }) if (!response.ok) { + console.error(`β DOLCE λ€μ΄λ‘λ μ€ν¨: HTTP ${response.status}`) + console.error(` URL: ${downloadUrl}`) throw new Error(`File download failed: HTTP ${response.status}`) } const buffer = Buffer.from(await response.arrayBuffer()) - console.log(`Downloaded ${buffer.length} bytes for ${fileName}`) + console.log(`β
DOLCEμμ νμΌ λ€μ΄λ‘λ μλ£: ${fileName} (${buffer.length} bytes)`) return buffer } catch (error) { - console.error(`Failed to download file ${fileName}:`, error) + console.error(`β DOLCE νμΌ λ€μ΄λ‘λ μ€ν¨: ${fileName}`, error) throw error } } @@ -1524,6 +1532,61 @@ async getImportStatus( const enabled = process.env[`IMPORT_${upperSystem}_ENABLED`] return enabled === 'true' || enabled === '1' } + + /** + * DOLCE μ
λ‘λ νμΈ ν
μ€νΈ (μ
λ‘λ ν νμΌμ΄ DOLCEμ μ‘΄μ¬νλμ§ νμΈ) + */ + async testDOLCEFileDownload( + fileId: string, + userId: string, + fileName: string + ): Promise<{ success: boolean; downloadUrl?: string; error?: string }> { + try { + // μνΈν λ¬Έμμ΄ μμ±: FileIdβUserIdβFileName + const encryptString = `${fileId}β${userId}β${fileName}` + const encryptedKey = this.encryptDES(encryptString) + + const downloadUrl = `${process.env.DOLCE_DOWNLOAD_URL}?key=${encryptedKey}` || `http://60.100.99.217:1111/Download.aspx?key=${encryptedKey}` + + console.log(`π§ͺ DOLCE νμΌ λ€μ΄λ‘λ ν
μ€νΈ:`) + console.log(` νμΌλͺ
: ${fileName}`) + console.log(` FileId: ${fileId}`) + console.log(` UserId: ${userId}`) + console.log(` μνΈν ν€: ${encryptedKey}`) + console.log(` λ€μ΄λ‘λ URL: ${downloadUrl}`) + + const response = await fetch(downloadUrl, { + method: 'GET', + headers: { + 'User-Agent': 'DOLCE-Integration-Service' + } + }) + + if (!response.ok) { + console.error(`β DOLCE νμΌ λ€μ΄λ‘λ ν
μ€νΈ μ€ν¨: HTTP ${response.status}`) + return { + success: false, + downloadUrl, + error: `HTTP ${response.status}` + } + } + + const buffer = Buffer.from(await response.arrayBuffer()) + console.log(`β
DOLCE νμΌ λ€μ΄λ‘λ ν
μ€νΈ μ±κ³΅: ${fileName} (${buffer.length} bytes)`) + + return { + success: true, + downloadUrl + } + + } catch (error) { + console.error(`β DOLCE νμΌ λ€μ΄λ‘λ ν
μ€νΈ μ€ν¨: ${fileName}`, error) + return { + success: false, + error: error instanceof Error ? error.message : 'Unknown error' + } + } + } } export const importService = new ImportService()
\ No newline at end of file |
