##// END OF EJS Templates
file-store: changed for stream upload endpoint.
milka -
r4611:29d668ad stable
parent child Browse files
Show More
@@ -21,7 +21,6 b''
21 21 import os
22 22 import time
23 23 import errno
24 import shutil
25 24 import hashlib
26 25
27 26 from rhodecode.lib.ext_json import json
@@ -212,10 +211,19 b' class LocalFileStorage(object):'
212 211 filename, path = self.resolve_name(uid_filename, dest_directory)
213 212 stored_file_dir = os.path.dirname(path)
214 213
215 file_obj.seek(0)
214 no_body_seek = kwargs.pop('no_body_seek', False)
215 if no_body_seek:
216 pass
217 else:
218 file_obj.seek(0)
216 219
217 220 with open(path, "wb") as dest:
218 shutil.copyfileobj(file_obj, dest)
221 length = 256 * 1024
222 while 1:
223 buf = file_obj.read(length)
224 if not buf:
225 break
226 dest.write(buf)
219 227
220 228 metadata = {}
221 229 if extra_metadata:
@@ -27,11 +27,14 b' def pyramid_ext_json(info):'
27 27 """
28 28 def _render(value, system):
29 29 request = system.get('request')
30 indent = None
30 31 if request is not None:
31 32 response = request.response
32 33 ct = response.content_type
33 34 if ct == response.default_content_type:
34 35 response.content_type = 'application/json'
35 return json.dumps(value)
36 indent = getattr(request, 'ext_json_indent', None)
37
38 return json.dumps(value, indent=indent)
36 39
37 40 return _render
@@ -749,8 +749,11 b' class User(Base, BaseModel):'
749 749
750 750 def get_artifact_token(self, cache=True):
751 751 artifacts_tokens = UserApiKeys.query()\
752 .filter(UserApiKeys.user == self)\
752 .filter(UserApiKeys.user == self) \
753 .filter(or_(UserApiKeys.expires == -1,
754 UserApiKeys.expires >= time.time())) \
753 755 .filter(UserApiKeys.role == UserApiKeys.ROLE_ARTIFACT_DOWNLOAD)
756
754 757 if cache:
755 758 artifacts_tokens = artifacts_tokens.options(
756 759 FromCache("sql_cache_short", "get_user_artifact_token_%s" % self.user_id))
@@ -760,6 +763,24 b' class User(Base, BaseModel):'
760 763 return artifacts_tokens[0].api_key
761 764 return 'NO_ARTIFACT_TOKEN_AVAILABLE'
762 765
766 def get_or_create_artifact_token(self):
767 artifacts_tokens = UserApiKeys.query()\
768 .filter(UserApiKeys.user == self) \
769 .filter(or_(UserApiKeys.expires == -1,
770 UserApiKeys.expires >= time.time())) \
771 .filter(UserApiKeys.role == UserApiKeys.ROLE_ARTIFACT_DOWNLOAD)
772
773 artifacts_tokens = artifacts_tokens.all()
774 if artifacts_tokens:
775 return artifacts_tokens[0].api_key
776 else:
777 from rhodecode.model.auth_token import AuthTokenModel
778 artifact_token = AuthTokenModel().create(
779 self, 'auto-generated-artifact-token',
780 lifetime=-1, role=UserApiKeys.ROLE_ARTIFACT_DOWNLOAD)
781 Session.commit()
782 return artifact_token.api_key
783
763 784 @classmethod
764 785 def get(cls, user_id, cache=False):
765 786 if not user_id:
@@ -60,6 +60,9 b' class RepoGroupModel(BaseModel):'
60 60 return self._get_instance(RepoGroup, repo_group,
61 61 callback=RepoGroup.get_by_group_name)
62 62
63 def get_repo_group(self, repo_group):
64 return self._get_repo_group(repo_group)
65
63 66 @LazyProperty
64 67 def repos_path(self):
65 68 """
@@ -270,6 +270,8 b' function registerRCRoutes() {'
270 270 pyroutes.register('repo_artifacts_list', '/%(repo_name)s/artifacts', ['repo_name']);
271 271 pyroutes.register('repo_artifacts_new', '/%(repo_name)s/artifacts/new', ['repo_name']);
272 272 pyroutes.register('repo_artifacts_store', '/%(repo_name)s/artifacts/store', ['repo_name']);
273 pyroutes.register('repo_artifacts_stream_script', '/_file_store/stream-upload-script', []);
274 pyroutes.register('repo_artifacts_stream_store', '/_file_store/stream-upload', []);
273 275 pyroutes.register('repo_artifacts_update', '/%(repo_name)s/artifacts/update/%(uid)s', ['repo_name', 'uid']);
274 276 pyroutes.register('repo_automation', '/%(repo_name)s/settings/automation', ['repo_name']);
275 277 pyroutes.register('repo_automation_update', '/%(repo_name)s/settings/automation/%(entry_id)s/update', ['repo_name', 'entry_id']);
General Comments 0
You need to be logged in to leave comments. Login now