Skip to content

Commit ce3bea1

Browse files
committed
minor corrections to copilot feedback
1 parent 5e00b7a commit ce3bea1

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

core/.env.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ AUTH__KEYCLOAK__URL=https://auth-test.mimer.nu
1111
AUTH__KEYCLOAK__REALM=onecore-test
1212
AUTH__KEYCLOAK__CLIENT_ID=onecore-test
1313
AUTH__KEYCLOAK__CLIENT_SECRET=
14+
# Comma-separated list of IPs allowed to upload scanned receipts, e.g. 10.0.0.1,10.0.0.2
1415
SCANNER__ALLOWED_IPS=
1516
SCANNER__ERROR_NOTIFICATION_EMAIL=

core/src/services/keys-service/scan-receipt.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,13 @@ export const routes = (router: KoaRouter) => {
123123
const { receiptId, keyLoanId } = scanResult
124124

125125
// Upload scanned image to file storage (MinIO)
126+
const knownImageExts = ['jpg', 'jpeg', 'png', 'tiff', 'bmp', 'gif', 'webp']
127+
const fileExt = filename.includes('.')
128+
? filename.split('.').pop()!.toLowerCase()
129+
: ''
130+
const ext = knownImageExts.includes(fileExt) ? fileExt : 'jpeg'
126131
const contentType = ctx.request.type || 'image/jpeg'
127-
const storageFileName = `receipt-${receiptId}-${Date.now()}.${contentType.split('/')[1] || 'jpg'}`
132+
const storageFileName = `receipt-${receiptId}-${Date.now()}.${ext}`
128133

129134
const uploadResult = await fileStorageAdapter.uploadFile(
130135
storageFileName,

services/keys/src/services/key-service/scan-receipt-service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import { Knex } from 'knex'
1515
import { Jimp } from 'jimp'
1616
import jsQR from 'jsqr'
17+
import { logger } from '@onecore/utilities'
1718
import * as receiptsAdapter from './adapters/receipts-adapter'
1819

1920
const UUID_REGEX =
@@ -92,7 +93,8 @@ export async function processScannedReceipt(
9293
)
9394

9495
return { ok: true, data: { receiptId: receipt.id, keyLoanId } }
95-
} catch {
96+
} catch (err) {
97+
logger.error({ err, keyLoanId }, 'Failed to create receipt')
9698
return { ok: false, err: 'receipt-creation-failed' }
9799
}
98100
}

0 commit comments

Comments
 (0)