async def manifest(manifest_id): storagedb = get_storagedb() if "-" in manifest_id: manifest_data = await storagedb.manifest_v1.load(manifest_id) if manifest_data is None: flask.abort(404) manifest = buildloader.load_manifest_v1(manifest_data) else: manifest_data = await storagedb.manifest_v2.load(manifest_id) if manifest_data is None: flask.abort(404) manifest = buildloader.load_manifest_v2(manifest_data) all_items = manifest.files + manifest.directories + manifest.links tree = {} for item in all_items: add_tree_item(tree, item) output = io.StringIO() print(".", file=output) print_tree(tree, file=output) resp = flask.make_response(output.getvalue()) resp.headers["Content-Type"] = "text/plain; charset=utf-8" return resp
def charts(prod_id): storagedb = get_storagedb() charts_path = storagedb.path_charts() filename = f"{prod_id}.svg.gz" response = flask.send_from_directory(charts_path, filename, mimetype="image/svg+xml") response.headers["Content-Encoding"] = "gzip" return response
async def releasenotes(prod_id): storagedb = get_storagedb() product = await storagedb.product.load(prod_id) if product is None or not product.changelog: flask.abort(404) sanitized_html = flask.Markup( bleach.clean(product.changelog, tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRIBUTES, strip_comments=False)) return flask.render_template("releasenotes.html", product=product, sanitized_html=sanitized_html)
async def build(prod_id, build_id): storagedb = get_storagedb() product = await storagedb.product.load(prod_id) if product is None: flask.abort(404) repository_raw = await storagedb.repository.load(prod_id, build_id) if repository_raw is None: flask.abort(404) build_data = [b for b in product.builds if b.id == build_id][0] if build_data.generation == 1: repository = buildloader.load_repository_v1(repository_raw) return flask.render_template("build_v1.html", product=product, build=build_data, repo=repository) else: repository = buildloader.load_repository_v2(repository_raw) return flask.render_template("build_v2.html", product=product, build=build_data, repo=repository)
async def product_info(prod_id): storagedb = get_storagedb() product = await storagedb.product.load(prod_id) if product is None: flask.abort(404) # Allow loading pre 2019 prices if flask.request.args.get("old"): pricehistory = await storagedb.prices_old.load(prod_id) has_old_prices = True else: pricehistory = await storagedb.prices.load(prod_id) has_old_prices = False if pricehistory: cur_history = pricehistory["US"]["USD"] else: cur_history = [] changelog = await storagedb.changelog.load(prod_id) history_chart = {"labels": [], "values": [], "max": 0} if cur_history: current_price = copy.copy(cur_history[-1]) current_price.date = datetime.datetime.now(datetime.timezone.utc) cur_history.append(current_price) last_price = None for entry in cur_history: if entry.price_final is not None: history_chart["labels"].append(entry.date.isoformat()) history_chart["values"].append(str(entry.price_final_decimal)) history_chart["max"] = max( history_chart["max"], entry.price_final_decimal) elif last_price is not None: history_chart["labels"].append(entry.date.isoformat()) history_chart["values"].append(str(last_price)) history_chart["labels"].append(entry.date.isoformat()) history_chart["values"].append(None) last_price = entry.price_final_decimal history_chart["max"] = float(history_chart["max"]) priceframes = [] for start, end in zip(cur_history[:-1], cur_history[1:]): frame = { "start": start.date, "end": end.date, "discount": start.discount, "price_final": start.price_final_decimal, "price_base": start.price_base_decimal } priceframes.append(frame) # Prefetch referenced products referenced_ids = { "editions": [edition.id for edition in product.editions], "includes_games": product.includes_games, "is_included_in": product.is_included_in, "required_by": product.required_by, "requires": product.requires, "dlcs": product.dlcs } all_references = set(itertools.chain.from_iterable(referenced_ids.values())) all_products = {} if all_references: cur = get_indexdb().cursor() placeholders = ", ".join(itertools.repeat("?", len(all_references))) cur.execute( "SELECT * FROM products WHERE product_id IN ({})".format(placeholders), tuple(all_references) ) for prod_res in cur: idx_prod = model.IndexProduct( id = prod_res["product_id"], title = prod_res["title"], image_logo = prod_res["image_logo"], type = prod_res["product_type"], comp_systems = decompress_systems(prod_res["comp_systems"]), sale_rank = prod_res["sale_rank"], search_title = prod_res["search_title"] ) all_products[idx_prod.id] = idx_prod referenced_products = { key: [all_products.get(ref_id, MockProduct(ref_id)) for ref_id in ref_ids] for key, ref_ids in referenced_ids.items() } response = flask.make_response(flask.render_template( "product_info.html", product=product, referenced_products=referenced_products, pricehistory=history_chart, priceframes=priceframes, has_old_prices=has_old_prices, changelog=changelog )) response.headers["Content-Security-Policy"] = csp_header return response