diff --git a/config/default.yaml b/config/default.yaml index f861852d..e7e875d4 100644 --- a/config/default.yaml +++ b/config/default.yaml @@ -1,6 +1,6 @@ port: 5000 api: { - url: https://publish-api.development.digital-land.info, + url: https://publish-api.planning.data.gov.uk, port: 8082, validationEndpoint: /api/dataset/validate/file/request } diff --git a/src/controllers/uploadController.js b/src/controllers/uploadController.js index d73c210a..7df693f9 100644 --- a/src/controllers/uploadController.js +++ b/src/controllers/uploadController.js @@ -32,9 +32,9 @@ class UploadController extends PageController { let jsonResult = {} try { jsonResult = await this.validateFile({ + ...req.file, filePath: req.file.path, fileName: req.file.originalname, - originalname: req.file.originalname, dataset: req.sessionModel.get('dataset'), dataSubject: req.sessionModel.get('data-subject'), // organisation: 'local-authority-eng:CAT', // ToDo: this needs to be dynamic, not collected in the prototype, should it be? @@ -94,7 +94,9 @@ class UploadController extends PageController { !UploadController.sizeIsValid(datafile) || !UploadController.fileNameIsntTooLong(datafile) || !UploadController.fileNameIsValid(datafile) || - !UploadController.fileNameDoesntContainDoubleExtension(datafile) + !UploadController.fileNameDoesntContainDoubleExtension(datafile) || + !UploadController.fileMimeTypeIsValid(datafile) || + !UploadController.fileMimeTypeMatchesExtension(datafile) ) { return false } @@ -169,7 +171,17 @@ class UploadController extends PageController { } static fileMimeTypeIsValid (datafile) { - const allowedMimeTypes = ['text/csv', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/json', 'application/vnd.geo+json', 'application/gml+xml', 'application/gpkg'] + const allowedMimeTypes = [ + 'text/csv', + 'application/vnd.ms-excel', + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + 'application/json', + 'application/vnd.geo+json', + 'application/gml+xml', + 'application/gpkg', + 'application/geopackage+sqlite3', + 'application/octet-stream' // This is a catch all for when the mime type is not recognised + ] if (!allowedMimeTypes.includes(datafile.mimetype)) { return false } diff --git a/test/unit/uploadController.test.js b/test/unit/uploadController.test.js index 2bd23538..28fc3be3 100644 --- a/test/unit/uploadController.test.js +++ b/test/unit/uploadController.test.js @@ -73,7 +73,8 @@ describe('UploadController', () => { originalname: 'test.csv', dataset: 'test', dataSubject: 'test', - organization: 'local-authority-eng:CAT' + organization: 'local-authority-eng:CAT', + mimetype: 'text/csv' } const result = await uploadController.validateFile(params)