def _download(request, extension, version, path, public=True): extension_etag = hashlib.sha256() extension_etag.update(unicode(extension.uuid)) extension_etag.update(unicode(version.pk)) return get_file_response(request, path, content_type='application/zip', etag=extension_etag.hexdigest(), public=public)
def download_file(request, file_id, type=None): # Fetch what we need with a minimum amount of queries (Transforms on # Version and Webapp are avoided). This breaks several things like # translations, but it should be fine here, we don't need much to go on. file_ = get_object_or_404(File.objects.select_related('version'), pk=file_id) webapp = get_object_or_404(Webapp.objects.all().no_transforms(), pk=file_.version.webapp_id, is_packaged=True) if webapp.is_disabled or file_.status == mkt.STATUS_DISABLED: if not acl.check_webapp_ownership(request, webapp, viewer=True, ignore_disabled=True): raise http.Http404() # We treat blocked files like public files so users get the update. if file_.status in [mkt.STATUS_PUBLIC, mkt.STATUS_BLOCKED]: path = file_.signed_file_path public = True else: # This is someone asking for an unsigned packaged app. if not acl.check_webapp_ownership(request, webapp, dev=True): raise http.Http404() path = file_.file_path public = False log.info('Downloading package: %s from %s' % (webapp.id, path)) return get_file_response(request, path, content_type='application/zip', etag=file_.hash.split(':')[-1], public=public)
def _download(request, extension, version, path, public=True): extension_etag = hashlib.sha256() extension_etag.update(unicode(extension.uuid)) extension_etag.update(unicode(version.pk)) return get_file_response( request, path, content_type="application/zip", etag=extension_etag.hexdigest(), public=public )
def retrieve(self, request, *args, **kwargs): obj = self.get_object() if not getattr(obj, 'image_hash', None): raise Http404 return get_file_response(request, obj.image_path(self.image_suffix), content_type='image/png', public=True)
def get_signed_packaged(request, addon, version_id): version = get_object_or_404(addon.versions, pk=version_id) file = version.all_files[0] path = addon.sign_if_packaged(version.pk, reviewer=True) if not path: raise http.Http404 log.info('Returning signed package addon: %s, version: %s, path: %s' % (addon.pk, version_id, path)) return get_file_response(request, path, content_type='application/zip', etag=file.hash.split(':')[-1], public=False)
def get(self, request, note_id, pk, *args, **kwargs): attach = get_object_or_404(CommAttachment, pk=pk) self.check_object_permissions(request, attach) full_path = os.path.join(settings.REVIEWER_ATTACHMENTS_PATH, attach.filepath) content_type = 'application/force-download' if attach.is_image(): content_type = 'image' return get_file_response(request, full_path, content_type=content_type)
def serve(request, viewer, key): """ This is to serve files off of st.a.m.o, not standard a.m.o. For this we use token based authentication. """ files = viewer.get_files() obj = files.get(key) if not obj: log.error(u'Couldn\'t find %s in %s (%d entries) for file %s' % (key, files.keys()[:10], len(files.keys()), viewer.file.id)) raise http.Http404() return get_file_response(request, obj['full'], content_type=obj['mimetype'])
def download(request, langpack_id, **kwargs): langpack = get_object_or_404(LangPack, pk=langpack_id) if langpack.active or action_allowed(request, "LangPacks", "%"): log.info("Downloading package: %s from %s" % (langpack.pk, langpack.file_path)) langpack_etag = hashlib.sha256() langpack_etag.update(langpack.pk) langpack_etag.update(unicode(langpack.file_version)) return get_file_response( request, langpack.file_path, content_type="application/zip", etag=langpack_etag.hexdigest(), public=True ) else: raise Http404
def download(request, langpack_id, **kwargs): langpack = get_object_or_404(LangPack, pk=langpack_id) if langpack.active or action_allowed(request, 'LangPacks', '%'): log.info('Downloading package: %s from %s' % (langpack.pk, langpack.file_path)) langpack_etag = hashlib.sha256() langpack_etag.update(langpack.pk) langpack_etag.update(unicode(langpack.file_version)) return get_file_response(request, langpack.file_path, content_type='application/zip', etag=langpack_etag.hexdigest(), public=True) else: raise Http404
def download_file(request, file_id, type=None): # Fetch what we need with a minimum amount of queries (Transforms on # Version and Webapp are avoided). This breaks several things like # translations, but it should be fine here, we don't need much to go on. file_ = get_object_or_404(File.objects.select_related('version'), pk=file_id) webapp = get_object_or_404(Webapp.objects.all().no_transforms(), pk=file_.version.addon_id, is_packaged=True) if webapp.is_disabled or file_.status in [ mkt.STATUS_DISABLED, mkt.STATUS_REJECTED ]: if not acl.check_addon_ownership( request, webapp, viewer=True, ignore_disabled=True): raise http.Http404() # We treat blocked files like public files so users get the update. if file_.status in [mkt.STATUS_PUBLIC, mkt.STATUS_BLOCKED]: path = file_.signed_file_path public = True else: # This is someone asking for an unsigned packaged app. if not acl.check_addon_ownership(request, webapp, dev=True): raise http.Http404() path = file_.file_path public = False log.info('Downloading package: %s from %s' % (webapp.id, path)) return get_file_response(request, path, content_type='application/zip', etag=file_.hash.split(':')[-1], public=public)
def retrieve(self, request, *args, **kwargs): obj = self.get_object() if not getattr(obj, "image_hash", None): raise Http404 return get_file_response(request, obj.image_path(self.image_suffix), content_type="image/png", public=True)