Skip to content

Commit

Permalink
Hashes (#357)
Browse files Browse the repository at this point in the history
* Switch back to demo-bucket.protomaps.com

* display md5 and b3 hashes on builds page, if available.
  • Loading branch information
bdon authored Jan 14, 2025
1 parent 53f80de commit 02cd8aa
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Protomaps Basemaps</title>
<link rel="preconnect" href="https://source.coop"/>
<link rel="preconnect" href="https://demo-bucket.protomaps.com"/>
</head>
<body>
<div id="root"></div>
Expand Down
34 changes: 31 additions & 3 deletions app/src/Builds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@ import { render } from "solid-js/web";
import "./index.css";
import Nav from "./Nav";

import { For, createResource, createSignal } from "solid-js";
import { For, Show, createResource, createSignal } from "solid-js";

interface Build {
uploaded: string;
key: string;
size: number;
version: string;
md5sum?: string;
b3sum?: string;
}

function b64ToHex(b64?: string): string {
if (!b64) return "";
const b = atob(b64);
let hex = "";
for (let i = 0; i < b.length; i++) {
const hexByte = b.charCodeAt(i).toString(16).padStart(2, "0");
hex += hexByte;
}
return hex;
}

function toDate(dateStr: string): Date {
Expand Down Expand Up @@ -38,6 +51,21 @@ function formatBytes(bytes: number, decimals = 2) {
return `${Number.parseFloat((bytes / k ** i).toFixed(dm))} ${sizes[i]}`;
}

function Hashes(build: Build) {
return (
<span>
<Show when={build.md5sum}>
<span title={b64ToHex(build.md5sum)}>
md5:{b64ToHex(build.md5sum).substr(0, 8)}
</span>
</Show>
<Show when={build.b3sum}>
<span title={build.b3sum}> b3:{build.b3sum?.substr(0, 8)}</span>
</Show>
</span>
);
}

function BuildComponent(props: {
build: Build;
idx: number;
Expand Down Expand Up @@ -80,10 +108,10 @@ function BuildComponent(props: {
aria-label={`compare later build ${date.toDateString()}`}
/>
</td>
<td>{build.key}</td>
<td title={build.uploaded}>{build.key}</td>
<td>{build.version}</td>
<td class="hidden lg:table-cell">{formatBytes(build.size)}</td>
<td class="hidden lg:table-cell">{build.uploaded}</td>
<td class="hidden lg:table-cell">{Hashes(build)}</td>
<td>
<a class="underline" href={`/#tiles=${link}`}>
map
Expand Down
2 changes: 1 addition & 1 deletion app/src/MapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ function MapView() {
const [theme, setTheme] = createSignal<string>(hash.theme || "light");
const [lang, setLang] = createSignal<string>(hash.lang || "en");
const [tiles, setTiles] = createSignal<string>(
hash.tiles || "https://data.source.coop/protomaps/openstreetmap/v4.pmtiles",
hash.tiles || "https://demo-bucket.protomaps.com/v4.pmtiles",
);
const [localSprites, setLocalSprites] = createSignal<boolean>(
hash.local_sprites === "true",
Expand Down

0 comments on commit 02cd8aa

Please sign in to comment.