def frame(self, id): send = self._send_file(id) if send: return send # We only want to maintain one page for mobile, not a dozen if request.user_agent.platform in [ 'android', 'iphone', 'ipad' ] or 'windows phone' in request.user_agent.string.lower(): return redirect("/" + id, code=302) klass = RedisObject.klass(id) if klass is Album: album = klass.from_hash(id) v = _album_params(album) v['embedded'] = True v['filename'] = id return render_template("album-embedded.html", **v) if klass is not File: abort(404) f = File.from_hash(id) template_params = _template_params(f) template_params['embedded'] = True return render_template("direct.html", **template_params)
def hash_text(self, h): klass = RedisObject.klass(h) max_length = 2048 if not klass or klass not in [Album, File]: return {'error': 404}, 404 properties = ["title", "description"] if not any(prop in request.form for prop in properties): return {'error': 400}, 400 try: o = klass.from_hash(h) # We don't care about the object type if not check_password_hash(o.ip, get_ip()): return {'error': 401}, 401 except: return {'error': 401}, 401 if o.text_locked: return {'error': 408}, 408 for prop in properties: if prop in request.form: data = request.form[prop] if len(data) > max_length: return {'error': 414}, 414 setattr(o, prop, data) o.save() return {'status': 'success'}
def flags_post(self, h): klass = RedisObject.klass(h) if not klass: return {'error': 404}, 404 try: o = klass.from_hash(h) if not check_password_hash(o.ip, get_ip()): return {'error': 401}, 401 except Exception as e: print("exception", e) return {'error': 401}, 401 # At this point, we're authenticated and o is the object. for flag, value in list(request.form.items()): v = True if value == 'true' else False try: setattr(o.flags, flag, v) except AttributeError as e: print("error", e) return {'error': 415}, 415 o.save() return {"flags": o.flags.as_dict()}
def frame(self, id): send = self._send_file(id) if send: return send # We only want to maintain one page for mobile, not a dozen if ( request.user_agent.platform in ["android", "iphone", "ipad"] or "windows phone" in request.user_agent.string.lower() ): return redirect("/" + id, code=302) klass = RedisObject.klass(id) if klass is Album: album = klass.from_hash(id) v = _album_params(album) v["embedded"] = True v["filename"] = id return render_template("album-embedded.html", **v) if klass is not File: abort(404) f = File.from_hash(id) template_params = _template_params(f) template_params["embedded"] = True return render_template("direct.html", **template_params)
def get(self, id): klass = RedisObject.klass(id) if not klass: return {'error': 404}, 404 o = klass.from_hash(id) return objects[klass](o)
def fragment(self, id): klass = RedisObject.klass(id) if klass is not File: abort(404) f = File.from_hash(id) params = _template_params(f) params['album'] = True return render_template(params['fragment'], **params)
def status(self, id): klass = RedisObject.klass(id) if klass is not File: abort(404) f = File.from_hash(id) template_params = _template_params(f) if f.status in ['done', 'ready']: return tor_redirect('/' + f.hash) return render_template("status.html", **_template_params(f))
def delete(self, h): klass = RedisObject.klass(h) if not klass: return {'error': 404}, 404 try: o = klass.from_hash(h) if not check_password_hash(o.ip, get_ip()): return {'error': 401}, 401 except: return {'error': 401}, 401 deletion_procedures[klass](o) return {'status': 'success'}
def info(self): if not "list" in request.args: return {'error': 400}, 400 items = request.args['list'].split(',') res = {} for i in items: klass = RedisObject.klass(i) if not klass or klass not in objects: res[i] = None else: o = klass.from_hash(i) res[i] = objects[klass](o) return res
def album_zip(self): if "hash" not in request.form: return {"error": 415}, 415 h = request.form["hash"] klass = RedisObject.klass(h) if not klass or klass is not Album: return {"error": 404}, 404 if os.path.exists(file_storage(h) + ".zip"): return {"status": "done"} zip_album.delay(h) return {"status": "success"}
def get(self, id, layout): send = self._send_file(id) if send: return send klass = RedisObject.klass(id) if klass is Album: album = klass.from_hash(id) v = _album_params(album) return render_template("albums/%s.html" % layout, **v) if klass is not File: abort(404) f = File.from_hash(id) return render_template("view.html", **_template_params(f))
def status(self, h): klass = RedisObject.klass(h) if not klass: return {'error': 404}, 404 if klass is not File: return {'error': 415}, 415 f = File.from_hash(h) ret = {'status': f.status} if ret['status'] == 'done': ret[h] = _file_object(f) ret['hash'] = h return ret
def get(self, id): send = self._send_file(id) if send: return send klass = RedisObject.klass(id) if klass is Album: album = klass.from_hash(id) v = _album_params(album) return render_template("album.html", **v) if klass is not File: abort(404) f = File.from_hash(id) return render_template("view.html", **_template_params(f))
def status_bulk(self): if not "list" in request.args: return {'error': 400}, 400 items = request.args['list'].split(',') res = {} for i in items: klass = RedisObject.klass(i) if not klass: res[i] = None else: o = klass.from_hash(i) res[i] = {'status': o.status} if klass is not FailedFile: res[i]['file'] = _file_object(o) return res
def status_bulk(self): if not "list" in request.args: return {"error": 400}, 400 items = request.args["list"].split(",") res = {} for i in items: klass = RedisObject.klass(i) if not klass: res[i] = None else: o = klass.from_hash(i) res[i] = {"status": o.status} if klass is not FailedFile: res[i]["file"] = _file_object(o) return res
def direct(self, id): send = self._send_file(id) if send: return send klass = RedisObject.klass(id) if klass is Album: album = klass.from_hash(id) v = _album_params(album) return render_template("album.html", **v) if klass is not File: abort(404) f = File.from_hash(id) template_params = _template_params(f) return render_template("direct.html", **template_params)
def album(self): items = request.form['list'].split(",") for i in items: klass = RedisObject.klass(i) if not klass: # Does not exist return {'error': 404}, 404 if klass != File: # Wrong type return {'error': 415}, 415 if len(items) > 50: return {'error': 413}, 413 a = Album() a.items = items a.ip = secure_ip() a.save() return {"hash": a.hash}
def get(self, id, layout): send = self._send_file(id) if send: return send klass = RedisObject.klass(id) if klass is Album: album = klass.from_hash(id) v = _album_params(album) v['layout'] = layout if layout == "random": random.shuffle(v['items']) # It's in-place return render_template("albums/%s.html" % layout, **v) if klass is not File: abort(404) f = File.from_hash(id) return render_template("view.html", **_template_params(f))
def frame(self, id): send = self._send_file(id) if send: return send klass = RedisObject.klass(id) if klass is Album: album = klass.from_hash(id) v = _album_params(album) v['embedded'] = True v['filename'] = id return render_template("album-embedded.html", **v) if klass is not File: abort(404) f = File.from_hash(id) template_params = _template_params(f) template_params['embedded'] = True return render_template("direct.html", **template_params)
def status(self, h): klass = RedisObject.klass(h) if not klass: return {'error': 404}, 404 if klass is FailedFile: ff = klass.from_hash(h) return {'status': ff.status} if klass is not File: return {'error': 415}, 415 f = File.from_hash(h) ret = {'status': f.status} if f.processor is not None: # When processor is available, ther rest of the information is too, even if the file might not have finished processing yet. ret[h] = _file_object(f) ret['hash'] = h return ret
def direct(self, id): send = self._send_file(id) if send: return send # We only want to maintain one page for mobile, not a dozen if request.user_agent.platform in ['android', 'iphone', 'ipad'] or 'windows phone' in request.user_agent.string.lower(): return redirect("/" + id, code=302) klass = RedisObject.klass(id) if klass is Album: album = klass.from_hash(id) v = _album_params(album) return render_template("album.html", **v) if klass is not File: abort(404) f = File.from_hash(id) template_params = _template_params(f) return render_template("direct.html", **template_params)
def get(self, id, layout): klass = RedisObject.klass(id) if klass is Album: album = klass.from_hash(id) v = _album_params(album) v['layout'] = layout if layout == "random": random.shuffle(v['items']) # It's in-place return render_template("albums/%s.html" % layout, **v) if klass is not File: abort(404) f = File.from_hash(id) if not f.processor: # TODO: Better error page return render_template("error.html", error="Unable to detect file type") return render_template("view.html", **_template_params(f))
def album(self): items = request.form["list"].split(",") for i in items: klass = RedisObject.klass(i) if not klass: # Does not exist return {"error": 404}, 404 if klass != File: # Wrong type return {"error": 415}, 415 if len(items) > 1024: return {"error": 413}, 413 a = Album() a.items = items a.ip = secure_ip() a.metadata = json.dumps({"has_zip": False}) a.save() return {"hash": a.hash}
def direct(self, id): send = self._send_file(id) if send: return send # We only want to maintain one page for mobile, not a dozen if (request.user_agent.platform in ["android", "iphone", "ipad"] or "windows phone" in request.user_agent.string.lower()): return redirect("/" + id, code=302) klass = RedisObject.klass(id) if klass is Album: album = klass.from_hash(id) v = _album_params(album) return render_template("album.html", **v) if klass is not File: abort(404) f = File.from_hash(id) template_params = _template_params(f) return render_template("direct.html", **template_params)
def flags_post(self, h): klass = RedisObject.klass(h) if not klass: return {'error': 404}, 404 try: o = klass.from_hash(h) if not check_password_hash(o.ip, get_ip()): return {'error': 401}, 401 except: return {'error': 401}, 401 # At this point, we're authenticated and o is the object. for flag, value in request.form.items(): v = True if value == 'true' else False try: setattr(o.flags, flag, v) except AttributeError: return {'error': 415}, 415 o.save() return {"flags": o.flags.as_dict()}