コード例 #1
0
def imageview_head_textureid(image):
    try:
        texture = model.gettexture(image)
        if not texture:
            return Response(json.dumps(
                dict(error="Not Found", errorMessage="无法找到相应文件.")),
                            status=404,
                            mimetype='application/json; charset=utf-8')
        if cache_head.get(texture.hash):
            return Response(cache_head.get(image), mimetype='image/png')
        filename = "".join(
            [os.getcwd(), "/data/texture/", texture.hash, '.png'])
        if texture.type != "SKIN":
            return Response(json.dumps(
                dict(
                    error="皮肤请求类型错误",
                    errorMessage="无法抓取该类型皮肤文件的head部分",
                )),
                            status=403,
                            mimetype='application/json; charset=utf-8')
        img = utils.gethead_skin(filename)
        cache_head.set(image, img)
    except FileNotFoundError:
        return Response(status=404)
    return Response(img, mimetype='image/png')
コード例 #2
0
def kf_profile_cape(profileid):
    result = model.getprofile_id(profileid)
    if not result:
        return Response(json.dumps({
            "error": "ForbiddenOperationException",
            "errorMessage": "no such profile."
        }), status=403, mimetype='application/json; charset=utf-8')
    data = result.get()
    if not data.cape:
        return Response(json.dumps({
            "error": "ForbiddenOperationException",
            "errorMessage": "the profile has no any cape."
        }), status=403)
    return Response(json.dumps(model.kf_format_textures(model.gettexture(data.cape))), mimetype='application/json; charset=utf-8')
コード例 #3
0
def kf_profile_cape_change(profileid):
    if request.is_json:
        data = request.json
        result = model.getprofile_id(profileid)
        if not result:
            return Response(json.dumps({
                "error": "ForbiddenOperationException",
                "errorMessage": "no such profile."
            }), status=403, mimetype='application/json; charset=utf-8')
        result = result.get()
        accessToken = data.get("accessToken")

        if not accessToken:
            return Response(json.dumps({
                "error": "ForbiddenOperationException",
                "errorMessage": "no such profile."
            }), status=403, mimetype='application/json; charset=utf-8')

        if Token.is_validate_strict(accessToken):
            raise Exceptions.InvalidToken()

        user = Token.getuser_byaccessToken(accessToken)

        if model.isBanned(user):
            raise Exceptions.InvalidToken()

        texture = model.gettexture(data.get("texture"))

        if not texture:
            raise Exceptions.InvalidToken()

        if texture.isPrivate:
            if texture.userid != user.uuid:
                raise Exceptions.InvalidToken()

        if texture.type != "cape":
            raise Exceptions.InvalidToken()

        if result.cape == texture.textureid:
            return Response(status=204)

        result.cape = texture.textureid
        result.change_time = datetime.datetime.now()
        result.save()
        return Response(status=204)
コード例 #4
0
def format_profile_csl(profile):
    IReturn = {"username": profile.name, "textures": {}}
    if profile.skin:
        skin = model.gettexture(profile.skin)
        if skin:
            model.gettexture(profile.skin)
            IReturn['textures'][{
                "STEVE": "default",
                "ALEX": "silm"
            }[skin.model]] = skin.hash

    if profile.cape:
        cape = model.gettexture(profile.cape)
        if cape:
            model.gettexture(profile.skin)
            IReturn['textures']["cape"] = cape.hash

    return IReturn