Example #1
0
    def save_attachment(self, page_id, file_name, stream):
        file_id = str(uuid.uuid4())
        page_path = os.path.join(self.__path, str(page_id))
        file_path = os.path.join(page_path, file_id)
        Path(page_path).mkdir(parents=True, exist_ok=True)

        with open(file_path, 'wb') as fp:
            shutil.copyfileobj(stream, fp)

        storage_service = registry_service.main_service()
        storage_service.register_attachment(page_id, file_name, file_id)
Example #2
0
 def delete_attachment(self, page_id, file_name):
     storage_service = registry_service.main_service()
     storage_service.delete_attachment(page_id, file_name)
Example #3
0
 def list_attachments(self, page_id) -> List[str]:
     storage_service = registry_service.main_service()
     uploads = storage_service.get_page_attachments(page_id)
     file_names = [u.file_name for u in uploads]
     return file_names
Example #4
0
 def get_attachment_path(self, page_id, file_name) -> str:
     storage_service = registry_service.main_service()
     file_id = storage_service.get_attachment_file_id(page_id, file_name)
     file_path = os.path.join(self.__path, str(page_id), file_id)
     return file_path
Example #5
0
def index():
    pages = main_service().get_pages()
    return flask.render_template('index/index.html', notes=pages)