mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
Simplified and reduced redundancy in code
- Removed 'if type == "info"' as requested by @kevr - Checked for valid type against the type dictionary, removing the needed to maintain two separate spots for type definitions.
This commit is contained in:
parent
a4f5c8bef6
commit
25aea216c5
2 changed files with 16 additions and 10 deletions
|
@ -58,10 +58,6 @@ async def rpc(request: Request,
|
||||||
elif v != 5:
|
elif v != 5:
|
||||||
return {"error": "Invalid version specified."}
|
return {"error": "Invalid version specified."}
|
||||||
|
|
||||||
# The PHP implementation sets the type to 'multiinfo' when the type is set to 'info'.
|
|
||||||
if type == "info":
|
|
||||||
type = "multiinfo"
|
|
||||||
|
|
||||||
# Defaults for returned data
|
# Defaults for returned data
|
||||||
returned_data = {}
|
returned_data = {}
|
||||||
|
|
||||||
|
|
|
@ -165,15 +165,14 @@ def RPC(**function_args):
|
||||||
# Get Snapshot URI
|
# Get Snapshot URI
|
||||||
snapshot_uri = config.get("options", "snapshot_uri")
|
snapshot_uri = config.get("options", "snapshot_uri")
|
||||||
|
|
||||||
# Remove duplicate arguments if type is 'multiinfo' so we don't fetch
|
# Remove duplicate arguments if type is 'info' or 'multiinfo' so we don't
|
||||||
# results for a package multiple times.
|
# fetch results for a package multiple times.
|
||||||
#
|
if type in ("info", "multiinfo"):
|
||||||
# Note that the type is set to 'multiinfo' when 'type=info' is passed.
|
|
||||||
if type == "multiinfo":
|
|
||||||
args = set(args)
|
args = set(args)
|
||||||
|
|
||||||
# Set request type to run.
|
# Set request type to run.
|
||||||
type_actions = {
|
type_actions = {
|
||||||
|
"info": run_info,
|
||||||
"multiinfo": run_info
|
"multiinfo": run_info
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,8 +180,19 @@ def RPC(**function_args):
|
||||||
# specified type was valid in aurweb/routers/rpc.py.
|
# specified type was valid in aurweb/routers/rpc.py.
|
||||||
if type in type_actions:
|
if type in type_actions:
|
||||||
run_request = type_actions.get(type)
|
run_request = type_actions.get(type)
|
||||||
|
|
||||||
for i in args:
|
for i in args:
|
||||||
returned_data = run_request(returned_data, i, snapshot_uri)
|
returned_data = run_request(returned_data, i, snapshot_uri)
|
||||||
|
|
||||||
|
elif type is None:
|
||||||
|
returned_data["type"] = "error"
|
||||||
|
returned_data["error"] = "No request type/data specified."
|
||||||
|
return returned_data
|
||||||
|
|
||||||
|
else:
|
||||||
|
returned_data["type"] = "error"
|
||||||
|
returned_data["error"] = "Incorrect request type specified."
|
||||||
|
return returned_data
|
||||||
|
|
||||||
|
|
||||||
return returned_data
|
return returned_data
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue