Beispiel #1
0
 def test_sanitizeFilename(self):
     testData = {
         "aCompletely_ValidFilename-that-needs.no.substitution":
         "aCompletely_ValidFilename-that-needs.no.substitution",
         "one_invalid_character": "one?invalid_character",
         "_a__lot_of_invalid_characters_": "<a//lot?of*invalid'characters>",
         "": ""
     }
     self.assertEqual(PathUtils.sanitizeFilename(None), '')
     for result, testData in testData.items():
         self.assertEqual(PathUtils.sanitizeFilename(testData), result)
Beispiel #2
0
 def put(self, dir_name):
     self.log.logDebug('put called', dir_name)
     dir_name = PathUtils.sanitizeFilename(dir_name)
     if not request.form or (not request.form['doc_path']
                             and not request.form['root_dir']):
         self.log.logWarn('directories put was called with invalid data.')
         abort(400, 'Invalid Parameters')
     newPath = PathUtils.sanitizePathList(
         [basePath, request.form['doc_path'], dir_name])
     self.log.logDebug('saving path', newPath)
     Path(newPath).mkdir()
     self.log.logDebug(
         'mkdir:', {'path': PathUtils.sanitizePathString(newPath, True)})
     return {'path': PathUtils.sanitizePathString(newPath, True)}
Beispiel #3
0
    def put(self, doc_name):
        if request.form['doc_path']:
            pathToSaveTo = PathUtils.sanitizePathList(
                [basePath, request.form['doc_path']])
            Path(pathToSaveTo).mkdir(parents=True, exist_ok=True)
        else:
            pathToSaveTo = basePath
        name = PathUtils.sanitizeFilename(doc_name)
        filePath = PathUtils.sanitizePathList([pathToSaveTo, name])
        try:
            f = request.files['file']
        except:
            abort(400, 'No or invalid file given')

        f.save(filePath)
        return self.getResponseObject(open(filePath, encoding='utf-8'))
Beispiel #4
0
    def post(self, doc_name):
        imgId = str(uuid.uuid4().hex[:8])

        path = request.headers['docpath']
        if path:
            pathParts = [basePath, path, metaSubPath, doc_name]
        else:
            pathParts = [basePath, metaSubPath, doc_name]
        dirPath = PathUtils.sanitizePathList(pathParts)
        Path(dirPath).mkdir(parents=True, exist_ok=True)

        f = request.files['upload']
        name = PathUtils.sanitizeFilename(f.filename)
        name = f'{imgId}_{name}'

        filePath = PathUtils.sanitizePathList([dirPath, name])
        self.log.logDebug(f'saving new image in {filePath}')
        f.save(filePath)

        self.addMappingToImageFile(name, dirPath)

        return {"url": self.getUrlForImage(doc_name, name, path)}