Skip to content

Commit

Permalink
Merge pull request #53 from digital-land/bugParty
Browse files Browse the repository at this point in the history
Bug party
  • Loading branch information
GeorgeGoodall authored Feb 6, 2024
2 parents 513cb39 + 6a53942 commit fb4fe14
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion config/default.yaml
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down
18 changes: 15 additions & 3 deletions src/controllers/uploadController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion test/unit/uploadController.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fb4fe14

Please sign in to comment.