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