mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-10-18 09:23:26 -05:00
fix: resolve api catalog links from the catalog
This commit is contained in:
1 parent
5cc45794f4
commit
36dda46ddd
2 files changed
+22
-4
No files matched your search
@@ -959,6 +959,7 @@ def generate_data_exports(
|
||||
(downloads / "retrobios.sqlite", "SQLite snapshot", "application/vnd.sqlite3", None),
|
||||
]
|
||||
catalog_items: list[dict] = []
|
||||
published: list[dict] = []
|
||||
for path, title, media_type, schema in assets:
|
||||
relative = path.relative_to(docs).as_posix()
|
||||
item = {
|
||||
@@ -971,12 +972,19 @@ def generate_data_exports(
|
||||
if schema:
|
||||
item["schema"] = schema
|
||||
catalog_items.append(item)
|
||||
# In the catalog both references resolve against the catalog's own
|
||||
# URL, as RFC 3986 clients do: `url` was relative to the site root
|
||||
# and `schema` to api/v1/, so no single base resolved both.
|
||||
published.append({
|
||||
**item,
|
||||
"url": os.path.relpath(path, api).replace(os.sep, "/"),
|
||||
})
|
||||
catalog = {
|
||||
"schema_version": 1,
|
||||
"generated_at": generated_at,
|
||||
"kind": "catalog",
|
||||
"count": len(catalog_items),
|
||||
"items": catalog_items,
|
||||
"count": len(published),
|
||||
"items": published,
|
||||
}
|
||||
write_if_changed(
|
||||
str(api / "catalog.json"),
|
||||
|
||||
@@ -183,9 +183,19 @@ class SiteReferenceContracts(unittest.TestCase):
|
||||
)
|
||||
catalog = json.loads((self.docs / "api/v1/catalog.json").read_text())
|
||||
self.assertEqual(catalog["count"], len(exports))
|
||||
# Every reference resolves against the catalog's own URL, as an
|
||||
# RFC 3986 client resolves it: the url was relative to the site root
|
||||
# and the schema to api/v1/, so neither base resolved both.
|
||||
import urllib.parse # noqa: PLC0415
|
||||
|
||||
site = "https://example.org/site/"
|
||||
base = site + "api/v1/catalog.json"
|
||||
for item in catalog["items"]:
|
||||
path = self.docs / item["url"]
|
||||
self.assertTrue(path.is_file())
|
||||
for key in ("url", "schema"):
|
||||
if key in item:
|
||||
target = urllib.parse.urljoin(base, item[key]).removeprefix(site)
|
||||
self.assertTrue((self.docs / target).is_file(), (key, item[key]))
|
||||
path = self.docs / urllib.parse.urljoin(base, item["url"]).removeprefix(site)
|
||||
self.assertEqual(hashlib.sha256(path.read_bytes()).hexdigest(), item["sha256"])
|
||||
|
||||
with sqlite3.connect(self.docs / "downloads/retrobios.sqlite") as connection:
|
||||
|
||||
Reference in new issue
Block a user