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