add new back

This commit is contained in:
2025-10-27 18:58:38 +03:00
parent a6065dd95c
commit 6c190b80fb
16 changed files with 996 additions and 147 deletions

View File

@@ -1,9 +1,10 @@
const express = require('express')
const fs = require('fs')
const path = require('path')
const router = express.Router()
// Create remote-assets/docs directory if it doesn't exist
const docsDir = '../../remote-assets/docs'
const docsDir = path.join(__dirname, '../../remote-assets/docs')
if (!fs.existsSync(docsDir)) {
fs.mkdirSync(docsDir, { recursive: true })
}
@@ -47,7 +48,7 @@ router.post('/docs', (req, res) => {
// Save file to disk
try {
const binaryData = Buffer.from(fileData, 'base64')
const filePath = `${docsDir}/${id}.${type}`
const filePath = path.join(docsDir, `${id}.${type}`)
fs.writeFileSync(filePath, binaryData)
console.log(`[BUY API] File saved to ${filePath}, size: ${binaryData.length} bytes`)
@@ -150,7 +151,7 @@ router.get('/docs/:id/file', (req, res) => {
return res.status(404).json({ error: 'Document not found' })
}
const filePath = `${docsDir}/${id}.${doc.type}`
const filePath = path.join(docsDir, `${id}.${doc.type}`)
if (!fs.existsSync(filePath)) {
console.log('[BUY API] File not found on disk:', filePath)
return res.status(404).json({ error: 'File not found on disk' })