|
@@ -2,7 +2,6 @@
|
2
|
2
|
import typing
|
3
|
3
|
|
4
|
4
|
import transaction
|
5
|
|
-from depot.io.local import LocalStoredFile
|
6
|
5
|
from depot.manager import DepotManager
|
7
|
6
|
from preview_generator.exception import UnavailablePreviewType
|
8
|
7
|
from pyramid.config import Configurator
|
|
@@ -37,7 +36,6 @@ from tracim.models.context_models import RevisionInContext
|
37
|
36
|
from tracim.models.contents import ContentTypeLegacy as ContentType
|
38
|
37
|
from tracim.models.contents import file_type
|
39
|
38
|
from tracim.models.revision_protection import new_revision
|
40
|
|
-from preview_generator.manager import PreviewManager
|
41
|
39
|
|
42
|
40
|
FILE_ENDPOINTS_TAG = 'Files'
|
43
|
41
|
|
|
@@ -136,7 +134,6 @@ class FileController(Controller):
|
136
|
134
|
@hapic.output_file([])
|
137
|
135
|
def preview_pdf(self, context, request: TracimRequest, hapic_data=None):
|
138
|
136
|
app_config = request.registry.settings['CFG']
|
139
|
|
- preview_manager = PreviewManager(app_config.PREVIEW_CACHE_DIR, create_folder=True) # nopep8
|
140
|
137
|
api = ContentApi(
|
141
|
138
|
current_user=request.current_user,
|
142
|
139
|
session=request.dbsession,
|
|
@@ -146,13 +143,11 @@ class FileController(Controller):
|
146
|
143
|
hapic_data.path.content_id,
|
147
|
144
|
content_type=ContentType.Any
|
148
|
145
|
)
|
149
|
|
- file_path = api.get_one_revision_filepath(content.revision_id)
|
150
|
|
- if hapic_data.query.page >= preview_manager.get_page_nb(file_path):
|
151
|
|
- raise Exception('page {page} of content {content_id} does not exist'.format(
|
152
|
|
- page=hapic_data.query.page,
|
153
|
|
- content_id=content.content_id),
|
154
|
|
- )
|
155
|
|
- pdf_preview_path = preview_manager.get_pdf_preview(file_path, page=hapic_data.query.page) # nopep8
|
|
146
|
+ pdf_preview_path = api.get_pdf_preview_path(
|
|
147
|
+ content.content_id,
|
|
148
|
+ content.revision_id,
|
|
149
|
+ page=hapic_data.query.page
|
|
150
|
+ )
|
156
|
151
|
return FileResponse(pdf_preview_path)
|
157
|
152
|
|
158
|
153
|
@hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
|
|
@@ -163,7 +158,6 @@ class FileController(Controller):
|
163
|
158
|
@hapic.output_file([])
|
164
|
159
|
def preview_pdf_full(self, context, request: TracimRequest, hapic_data=None):
|
165
|
160
|
app_config = request.registry.settings['CFG']
|
166
|
|
- preview_manager = PreviewManager(app_config.PREVIEW_CACHE_DIR, create_folder=True) # nopep8
|
167
|
161
|
api = ContentApi(
|
168
|
162
|
current_user=request.current_user,
|
169
|
163
|
session=request.dbsession,
|
|
@@ -173,8 +167,7 @@ class FileController(Controller):
|
173
|
167
|
hapic_data.path.content_id,
|
174
|
168
|
content_type=ContentType.Any
|
175
|
169
|
)
|
176
|
|
- file_path = api.get_one_revision_filepath(content.revision_id)
|
177
|
|
- pdf_preview_path = preview_manager.get_pdf_preview(file_path)
|
|
170
|
+ pdf_preview_path = api.get_full_pdf_preview_path(content.revision_id)
|
178
|
171
|
return FileResponse(pdf_preview_path)
|
179
|
172
|
|
180
|
173
|
@hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
|
|
@@ -186,7 +179,6 @@ class FileController(Controller):
|
186
|
179
|
@hapic.output_file([])
|
187
|
180
|
def preview_pdf_revision(self, context, request: TracimRequest, hapic_data=None):
|
188
|
181
|
app_config = request.registry.settings['CFG']
|
189
|
|
- preview_manager = PreviewManager(app_config.PREVIEW_CACHE_DIR, create_folder=True) # nopep8
|
190
|
182
|
api = ContentApi(
|
191
|
183
|
current_user=request.current_user,
|
192
|
184
|
session=request.dbsession,
|
|
@@ -200,13 +192,11 @@ class FileController(Controller):
|
200
|
192
|
revision_id=hapic_data.path.revision_id,
|
201
|
193
|
content=content
|
202
|
194
|
)
|
203
|
|
- file_path = api.get_one_revision_filepath(revision.revision_id)
|
204
|
|
- if hapic_data.query.page >= preview_manager.get_page_nb(file_path):
|
205
|
|
- raise Exception('page {page} of content {content_id} does not exist'.format(
|
206
|
|
- page=hapic_data.query.page,
|
207
|
|
- content_id=content.content_id),
|
208
|
|
- )
|
209
|
|
- pdf_preview_path = preview_manager.get_pdf_preview(file_path, page=hapic_data.query.page) # nopep8
|
|
195
|
+ pdf_preview_path = api.get_pdf_preview_path(
|
|
196
|
+ revision.content_id,
|
|
197
|
+ revision.revision_id,
|
|
198
|
+ page=hapic_data.query.page
|
|
199
|
+ )
|
210
|
200
|
return FileResponse(pdf_preview_path)
|
211
|
201
|
|
212
|
202
|
# jpg
|
|
@@ -218,7 +208,6 @@ class FileController(Controller):
|
218
|
208
|
@hapic.output_file([])
|
219
|
209
|
def preview_jpg(self, context, request: TracimRequest, hapic_data=None):
|
220
|
210
|
app_config = request.registry.settings['CFG']
|
221
|
|
- preview_manager = PreviewManager(app_config.PREVIEW_CACHE_DIR, create_folder=True) # nopep8
|
222
|
211
|
api = ContentApi(
|
223
|
212
|
current_user=request.current_user,
|
224
|
213
|
session=request.dbsession,
|
|
@@ -228,13 +217,11 @@ class FileController(Controller):
|
228
|
217
|
hapic_data.path.content_id,
|
229
|
218
|
content_type=ContentType.Any
|
230
|
219
|
)
|
231
|
|
- file_path = api.get_one_revision_filepath(content.revision_id)
|
232
|
|
- if hapic_data.query.page >= preview_manager.get_page_nb(file_path):
|
233
|
|
- raise Exception('page {page} of content {content_id} does not exist'.format(
|
234
|
|
- page=hapic_data.query.page,
|
235
|
|
- content_id=content.content_id),
|
236
|
|
- )
|
237
|
|
- jpg_preview_path = preview_manager.get_jpeg_preview(file_path, page=hapic_data.query.page) # nopep8
|
|
220
|
+ jpg_preview_path = api.get_jpg_preview_path(
|
|
221
|
+ content_id=content.content_id,
|
|
222
|
+ revision_id=content.revision_id,
|
|
223
|
+ page=hapic_data.query.page
|
|
224
|
+ )
|
238
|
225
|
return FileResponse(jpg_preview_path)
|
239
|
226
|
|
240
|
227
|
@hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
|
|
@@ -245,7 +232,6 @@ class FileController(Controller):
|
245
|
232
|
@hapic.output_file([])
|
246
|
233
|
def sized_preview_jpg(self, context, request: TracimRequest, hapic_data=None):
|
247
|
234
|
app_config = request.registry.settings['CFG']
|
248
|
|
- preview_manager = PreviewManager(app_config.PREVIEW_CACHE_DIR, create_folder=True) # nopep8
|
249
|
235
|
api = ContentApi(
|
250
|
236
|
current_user=request.current_user,
|
251
|
237
|
session=request.dbsession,
|
|
@@ -255,17 +241,12 @@ class FileController(Controller):
|
255
|
241
|
hapic_data.path.content_id,
|
256
|
242
|
content_type=ContentType.Any
|
257
|
243
|
)
|
258
|
|
- file_path = api.get_one_revision_filepath(content.revision_id)
|
259
|
|
- if hapic_data.query.page >= preview_manager.get_page_nb(file_path):
|
260
|
|
- raise Exception('page {page} of content {content_id} does not exist'.format(
|
261
|
|
- page=hapic_data.query.page,
|
262
|
|
- content_id=content.content_id),
|
263
|
|
- )
|
264
|
|
- jpg_preview_path = preview_manager.get_jpeg_preview(
|
265
|
|
- file_path,
|
|
244
|
+ jpg_preview_path = api.get_jpg_preview_path(
|
|
245
|
+ content_id=content.content_id,
|
|
246
|
+ revision_id=content.revision_id,
|
266
|
247
|
page=hapic_data.query.page,
|
267
|
|
- width=hapic_data.path.width,
|
268
|
248
|
height=hapic_data.path.height,
|
|
249
|
+ width=hapic_data.path.width,
|
269
|
250
|
)
|
270
|
251
|
return FileResponse(jpg_preview_path)
|
271
|
252
|
|
|
@@ -277,7 +258,6 @@ class FileController(Controller):
|
277
|
258
|
@hapic.output_file([])
|
278
|
259
|
def sized_preview_jpg_revision(self, context, request: TracimRequest, hapic_data=None):
|
279
|
260
|
app_config = request.registry.settings['CFG']
|
280
|
|
- preview_manager = PreviewManager(app_config.PREVIEW_CACHE_DIR, create_folder=True) # nopep8
|
281
|
261
|
api = ContentApi(
|
282
|
262
|
current_user=request.current_user,
|
283
|
263
|
session=request.dbsession,
|
|
@@ -291,17 +271,12 @@ class FileController(Controller):
|
291
|
271
|
revision_id=hapic_data.path.revision_id,
|
292
|
272
|
content=content
|
293
|
273
|
)
|
294
|
|
- file_path = api.get_one_revision_filepath(revision.revision_id)
|
295
|
|
- if hapic_data.query.page >= preview_manager.get_page_nb(file_path):
|
296
|
|
- raise Exception('page {page} of content {content_id} does not exist'.format(
|
297
|
|
- page=hapic_data.query.page,
|
298
|
|
- content_id=content.content_id),
|
299
|
|
- )
|
300
|
|
- jpg_preview_path = preview_manager.get_jpeg_preview(
|
301
|
|
- file_path,
|
|
274
|
+ jpg_preview_path = api.get_jpg_preview_path(
|
|
275
|
+ content_id=content.content_id,
|
|
276
|
+ revision_id=revision.revision_id,
|
302
|
277
|
page=hapic_data.query.page,
|
303
|
|
- width=hapic_data.path.width,
|
304
|
278
|
height=hapic_data.path.height,
|
|
279
|
+ width=hapic_data.path.width,
|
305
|
280
|
)
|
306
|
281
|
return FileResponse(jpg_preview_path)
|
307
|
282
|
|