Code Duplication    Length = 28-32 lines in 2 locations

backend/tracim_backend/views/contents_api/file_controller.py 2 locations

@@ 189-220 (lines=32) @@
186
            as_attachment=hapic_data.query.force_download
187
        )
188
189
    @hapic.with_api_doc(tags=[SWAGGER_TAG__FILE_ENDPOINTS])
190
    @require_workspace_role(UserRoleInWorkspace.READER)
191
    @require_content_types([FILE_TYPE])
192
    @hapic.input_query(FileQuerySchema())
193
    @hapic.input_path(WorkspaceAndContentRevisionIdPathSchema())
194
    @hapic.output_file([])
195
    def download_revisions_file(self, context, request: TracimRequest, hapic_data=None):  # nopep8
196
        """
197
        Download raw file for specific revision of content.
198
        """
199
        app_config = request.registry.settings['CFG']
200
        api = ContentApi(
201
            show_archived=True,
202
            show_deleted=True,
203
            current_user=request.current_user,
204
            session=request.dbsession,
205
            config=app_config,
206
        )
207
        content = api.get_one(
208
            hapic_data.path.content_id,
209
            content_type=CONTENT_TYPES.Any_SLUG
210
        )
211
        revision = api.get_one_revision(
212
            revision_id=hapic_data.path.revision_id,
213
            content=content
214
        )
215
        file = DepotManager.get().get(revision.depot_file)
216
        return HapicFile(
217
            file_object=file,
218
            mimetype=file.content_type,
219
            filename=revision.file_name,
220
            as_attachment=hapic_data.query.force_download
221
        )
222
223
    # preview
@@ 159-186 (lines=28) @@
156
        api.save(content)
157
        return
158
159
    @hapic.with_api_doc(tags=[SWAGGER_TAG__FILE_ENDPOINTS])
160
    @require_workspace_role(UserRoleInWorkspace.READER)
161
    @require_content_types([FILE_TYPE])
162
    @hapic.input_query(FileQuerySchema())
163
    @hapic.input_path(WorkspaceAndContentIdPathSchema())
164
    @hapic.output_file([])
165
    def download_file(self, context, request: TracimRequest, hapic_data=None):
166
        """
167
        Download raw file of last revision of content.
168
        """
169
        app_config = request.registry.settings['CFG']
170
        api = ContentApi(
171
            show_archived=True,
172
            show_deleted=True,
173
            current_user=request.current_user,
174
            session=request.dbsession,
175
            config=app_config,
176
        )
177
        content = api.get_one(
178
            hapic_data.path.content_id,
179
            content_type=CONTENT_TYPES.Any_SLUG
180
        )
181
        file = DepotManager.get().get(content.depot_file)
182
        return HapicFile(
183
            file_object=file,
184
            mimetype=file.content_type,
185
            filename=content.file_name,
186
            as_attachment=hapic_data.query.force_download
187
        )
188
189
    @hapic.with_api_doc(tags=[SWAGGER_TAG__FILE_ENDPOINTS])