Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default tseslint.config(
"target",
"convert_to_target",
"job-details-toggle",
"share-btn",
],
},
],
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@elysiajs/static": "^1.4.6",
"@kitajs/html": "^4.2.11",
"elysia": "^1.4.16",
"mime": "^4.1.0",
"sanitize-filename": "^1.6.3",
"tar": "^7.5.2"
},
Expand Down
38 changes: 38 additions & 0 deletions public/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,42 @@ const jobId = window.location.pathname.split("/").pop();
const main = document.querySelector("main");
let progressElem = document.querySelector("progress");

const supportsWebShare = navigator.share && navigator.canShare;

const setupShareButtons = () => {
if (!supportsWebShare) {
return;
}

document.querySelectorAll(".share-btn").forEach((btn) => {
if (btn.dataset.setupComplete) return;

const filename = btn.dataset.filename;
const mimeType = btn.dataset.mimeType;
const fileUrl = btn.dataset.downloadUrl;
const dummyFile = new File([], filename, { type: mimeType });

if (!navigator.canShare({ files: [dummyFile] })) {
return;
}
btn.addEventListener("click", async (e) => {
e.preventDefault();
try {
const response = await fetch(fileUrl);
const blob = await response.blob();
const file = new File([blob], filename, { type: mimeType });
await navigator.share({ files: [file] });
} catch (err) {
if (err.name !== "AbortError") {
console.error("Error sharing:", err);
}
}
});
btn.style.display = "";
btn.dataset.setupComplete = true;
});
};

const refreshData = () => {
// console.log("Refreshing data...", progressElem.value, progressElem.max);
if (progressElem.value !== progressElem.max) {
Expand All @@ -12,6 +48,7 @@ const refreshData = () => {
.then((res) => res.text())
.then((html) => {
main.innerHTML = html;
setupShareButtons();
Comment thread
C4illin marked this conversation as resolved.
})
.catch((err) => console.log(err));

Expand All @@ -21,6 +58,7 @@ const refreshData = () => {
progressElem = document.querySelector("progress");
};

setupShareButtons();
refreshData();

window.downloadAll = function () {
Expand Down
18 changes: 18 additions & 0 deletions src/icons/share.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export function ShareIcon() {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
strokeWidth="1.5"
stroke="currentColor"
class={`size-6`}
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M7.217 10.907a2.25 2.25 0 1 0 0 2.186m0-2.186c.18.324.283.696.283 1.093s-.103.77-.283 1.093m0-2.186 9.566-5.314m-9.566 7.5 9.566 5.314m0 0a2.25 2.25 0 1 0 3.935 2.186 2.25 2.25 0 0 0-3.935-2.186Zm0-12.814a2.25 2.25 0 1 0 3.933-2.185 2.25 2.25 0 0 0-3.933 2.185Z"
/>
</svg>
);
}
14 changes: 14 additions & 0 deletions src/pages/results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { ALLOW_UNAUTHENTICATED, WEBROOT } from "../helpers/env";
import { DownloadIcon } from "../icons/download";
import { DeleteIcon } from "../icons/delete";
import { EyeIcon } from "../icons/eye";
import { ShareIcon } from "../icons/share";
import mime from "mime";
import { userService } from "./user";

function ResultsArticle({
Expand Down Expand Up @@ -119,6 +121,18 @@ function ResultsArticle({
>
<DownloadIcon />
</a>
<button
class={`
share-btn text-accent-500 underline
Comment thread
strawberry-raccoon marked this conversation as resolved.
hover:text-accent-400
`}
data-filename={file.output_file_name}
data-download-url={`${WEBROOT}/download/${outputPath}${file.output_file_name}`}
data-mime-type={mime.getType(file.output_file_name) || "application/octet-stream"}
style="display: none;"
>
<ShareIcon />
</button>
</td>
</tr>
))}
Expand Down