Beracles commited on
Commit ·
ac0d8be
1
Parent(s): cd639b6
parse username
Browse filesFiles changed (2)
- app.py+7-7
- extract.py+9-24
41 unmodified lines42434445464748495023 unmodified lines7475767778798011 unmodified lines929394959697989910010141 unmodified lines"""# reuse hf_token field as json stringtoken, user_name, redirect, source, _ = extract(hf_token)if user_name is None:user_name = "__fake__"# redirect all traffic to the proxy severglobal ai23 unmodified lineselse:assert "games" in service_listif service == "games":print(f"{beijing()} [{user_name}] [{game}] {nlp_command}")nlp_command = normalize_text(nlp_command)call_pgai.from_cache = Trueoutp = call_pgai.call_pgai(11 unmodified lines# add proxy version info to the outputoutp["timestamp"] = beijing().__str__()outp["proxy-version"] = proxy_versionoutp["user"] = user_nameoutp["game"] = gameif source:outp["source"] = sourceoutp["cache"] = call_pgai.from_cacheapp_util.call_logger(outp, identity, token)service_end = beijing()41 unmodified lines42434445464748495023 unmodified lines7475767778798011 unmodified lines929394959697989910010141 unmodified lines"""# reuse hf_token field as json stringtoken, user, redirect, source, username, _ = extract(hf_token)if user is None:user = "__fake__"# redirect all traffic to the proxy severglobal ai23 unmodified lineselse:assert "games" in service_listif service == "games":print(f"{beijing()} [{user}] [{game}] {nlp_command}")nlp_command = normalize_text(nlp_command)call_pgai.from_cache = Trueoutp = call_pgai.call_pgai(11 unmodified lines# add proxy version info to the outputoutp["timestamp"] = beijing().__str__()outp["proxy-version"] = proxy_versionoutp["user"] = useroutp["username"] = usernameoutp["game"] = gameoutp["source"] = sourceoutp["cache"] = call_pgai.from_cacheapp_util.call_logger(outp, identity, token)service_end = beijing()
2 unmodified lines345678910111213141516171819202122232425262728293031323334352 unmodified linesdef extract(hf_token):"""Extract token, user, redirect, source, and info from input hf_token.If hf_token is simple, it is the token itself."""info = {} # a copy of hf_token in json formattry:info = json.loads(hf_token)except json.decoder.JSONDecodeError:return hf_token, None, None, None, Nonetry:token = info["token"]except KeyError:token = Nonetry:user = info["user"]except KeyError:user = Nonetry:redirect = info["redirect"]except KeyError:redirect = Nonetry:source = info["source"]except KeyError:source = Nonereturn token, user, redirect, source, info2 unmodified lines345678910111213141516171819202 unmodified linesdef extract(hf_token):"""Extract token, user, redirect, source, username and info from input hf_token.If hf_token is simple, it is the token itself."""info = {} # a copy of hf_token in json formattry:info = dict(json.loads(hf_token))except json.decoder.JSONDecodeError:return hf_token, None, None, None, None,Nonetoken = info.get("token", None)user = info.get("user", None)redirect = info.get("redirect", None)source = info.get("source", None)username = info.get("username", None)return token, user, redirect, source, username, info
app.py+7-7
extract.py+9-24