예제 #1
0
파일: media.py 프로젝트: wub/MediaCrush
    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)
예제 #2
0
파일: api.py 프로젝트: mpmedia/MediaCrush
    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'}
예제 #3
0
파일: api.py 프로젝트: dbanda/MediaCrush
    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()}
예제 #4
0
파일: media.py 프로젝트: JIVS/MediaCrush
    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)
예제 #5
0
파일: api.py 프로젝트: Janakas/MediaCrush
    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'}
예제 #6
0
파일: api.py 프로젝트: mpmedia/MediaCrush
    def get(self, id):
        klass = RedisObject.klass(id)

        if not klass:
            return {'error': 404}, 404

        o = klass.from_hash(id)
        return objects[klass](o)
예제 #7
0
파일: api.py 프로젝트: Janakas/MediaCrush
    def get(self, id):
        klass = RedisObject.klass(id)

        if not klass:
            return {'error': 404}, 404

        o = klass.from_hash(id)
        return objects[klass](o)
예제 #8
0
    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)
예제 #9
0
    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)
예제 #10
0
    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))
예제 #11
0
    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))
예제 #12
0
파일: api.py 프로젝트: Janakas/MediaCrush
    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'}
예제 #13
0
파일: api.py 프로젝트: mpmedia/MediaCrush
    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'}
예제 #14
0
파일: api.py 프로젝트: Janakas/MediaCrush
    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
예제 #15
0
파일: api.py 프로젝트: mpmedia/MediaCrush
    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
예제 #16
0
파일: api.py 프로젝트: Janakas/MediaCrush
    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"}
예제 #17
0
파일: api.py 프로젝트: mpmedia/MediaCrush
    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"}
예제 #18
0
    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))
예제 #19
0
    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
예제 #20
0
파일: media.py 프로젝트: dioptre/MediaCrush
    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))
예제 #21
0
파일: api.py 프로젝트: mpmedia/MediaCrush
    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
예제 #22
0
파일: api.py 프로젝트: nerdzeu/NERDZCrush
    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
예제 #23
0
    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)
예제 #24
0
파일: api.py 프로젝트: Janakas/MediaCrush
    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
예제 #25
0
    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}
예제 #26
0
    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))
예제 #27
0
파일: api.py 프로젝트: dioptre/MediaCrush
    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}
예제 #28
0
    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))
예제 #29
0
    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)
예제 #30
0
파일: api.py 프로젝트: mpmedia/MediaCrush
    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
예제 #31
0
    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)
예제 #32
0
    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))
예제 #33
0
파일: media.py 프로젝트: nerdzeu/NERDZCrush
    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))
예제 #34
0
파일: api.py 프로젝트: Janakas/MediaCrush
    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
예제 #35
0
파일: api.py 프로젝트: nerdzeu/NERDZCrush
    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}
예제 #36
0
    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)
예제 #37
0
파일: media.py 프로젝트: nerdzeu/NERDZCrush
    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)
예제 #38
0
파일: api.py 프로젝트: mpmedia/MediaCrush
    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()}