Fix upload bugs: cap progress at 99%, hide auth row during upload
This commit is contained in:
1 parent
f7c0310c91
commit
6f0ebad75e
2 files changed
+104
-79
No files matched your search
@@ -75,6 +75,8 @@ async def upload(
|
|||||||
)
|
)
|
||||||
object_name = _resolve_object_name(file.filename or "", content_type)
|
object_name = _resolve_object_name(file.filename or "", content_type)
|
||||||
|
|
||||||
|
await file.seek(0)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
url = await upload_file(
|
url = await upload_file(
|
||||||
file_obj=file.file,
|
file_obj=file.file,
|
||||||
|
|||||||
+102
-79
@@ -63,7 +63,10 @@ export default function Home() {
|
|||||||
|
|
||||||
xhr.upload.onprogress = (e) => {
|
xhr.upload.onprogress = (e) => {
|
||||||
if (e.lengthComputable) {
|
if (e.lengthComputable) {
|
||||||
setProgress(Math.round((e.loaded / e.total) * 100));
|
// Cap at 99 — the final 100 is set only once the server responds,
|
||||||
|
// because the file is still being streamed to R2 after the browser
|
||||||
|
// finishes sending bytes.
|
||||||
|
setProgress(Math.min(99, Math.round((e.loaded / e.total) * 100)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -150,7 +153,21 @@ export default function Home() {
|
|||||||
const isAuthenticated = status === "authenticated";
|
const isAuthenticated = status === "authenticated";
|
||||||
const isUploading = status === "uploading";
|
const isUploading = status === "uploading";
|
||||||
const isInteractable = status !== "uploading";
|
const isInteractable = status !== "uploading";
|
||||||
const limitLabel = isAuthenticated ? "250 MB" : "50 MB";
|
|
||||||
|
// Show the auth badge when authenticated, or when uploading/done from an
|
||||||
|
// authenticated session (preUploadStatus tells us what we came from).
|
||||||
|
const showAuthBadge =
|
||||||
|
status === "authenticated" ||
|
||||||
|
((status === "uploading" || status === "done") &&
|
||||||
|
preUploadStatus.current === "authenticated");
|
||||||
|
|
||||||
|
// Show the auth row at all when there is something to render inside it.
|
||||||
|
const showAuthRow = status === "idle" || showAuthBadge;
|
||||||
|
|
||||||
|
const limitLabel =
|
||||||
|
isAuthenticated || preUploadStatus.current === "authenticated"
|
||||||
|
? "250 MB"
|
||||||
|
: "50 MB";
|
||||||
|
|
||||||
// ── Render ────────────────────────────────────────────────────────────────
|
// ── Render ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
@@ -198,84 +215,90 @@ export default function Home() {
|
|||||||
style={{ background: "#32302f", border: "1px solid #504945" }}
|
style={{ background: "#32302f", border: "1px solid #504945" }}
|
||||||
>
|
>
|
||||||
{/* Auth row */}
|
{/* Auth row */}
|
||||||
<div
|
{showAuthRow && (
|
||||||
className="px-5 pt-5 pb-5"
|
<div
|
||||||
style={{ borderBottom: "1px solid #504945" }}
|
className="px-5 pt-5 pb-5"
|
||||||
>
|
style={{ borderBottom: "1px solid #504945" }}
|
||||||
{isAuthenticated ? (
|
>
|
||||||
<div className="flex items-center gap-2.5 py-0.5">
|
{showAuthBadge ? (
|
||||||
<div
|
<div className="flex items-center gap-2.5 py-0.5">
|
||||||
className="w-2 h-2 rounded-full shrink-0"
|
<div
|
||||||
style={{ background: "#b8bb26" }}
|
className="w-2 h-2 rounded-full shrink-0"
|
||||||
/>
|
style={{ background: "#b8bb26" }}
|
||||||
<span
|
/>
|
||||||
className="text-[14px] font-medium"
|
<span
|
||||||
style={{ color: "#b8bb26" }}
|
className="text-[14px] font-medium"
|
||||||
>
|
style={{ color: "#b8bb26" }}
|
||||||
Authenticated · 250 MB limit
|
>
|
||||||
</span>
|
Authenticated · 250 MB limit
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div className="flex flex-col gap-3">
|
|
||||||
<label
|
|
||||||
className="text-[13px] font-medium"
|
|
||||||
style={{ color: "#a89984" }}
|
|
||||||
>
|
|
||||||
Password{" "}
|
|
||||||
<span style={{ color: "#665c54" }} className="font-normal">
|
|
||||||
— optional, unlocks 250 MB
|
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</div>
|
||||||
<input
|
) : (
|
||||||
type="password"
|
/* status === "idle" — show the optional unlock form */
|
||||||
value={password}
|
<div className="flex flex-col gap-3">
|
||||||
onChange={(e) => {
|
<label
|
||||||
setPassword(e.target.value);
|
className="text-[13px] font-medium"
|
||||||
setPasswordError(false);
|
style={{ color: "#a89984" }}
|
||||||
}}
|
>
|
||||||
onKeyDown={(e) => e.key === "Enter" && handleUnlock()}
|
Password{" "}
|
||||||
placeholder="Enter password"
|
<span style={{ color: "#665c54" }} className="font-normal">
|
||||||
className={[
|
— optional, unlocks 250 MB
|
||||||
"w-full h-11 px-3.5 rounded-xl text-[15px] outline-none",
|
</span>
|
||||||
"border transition-all duration-150",
|
</label>
|
||||||
passwordError ? "ring-2" : "",
|
<input
|
||||||
].join(" ")}
|
type="password"
|
||||||
style={{
|
value={password}
|
||||||
background: "#1d2021",
|
onChange={(e) => {
|
||||||
color: "#ebdbb2",
|
setPassword(e.target.value);
|
||||||
caretColor: "#d79921",
|
setPasswordError(false);
|
||||||
borderColor: passwordError ? "#fb4934" : "#504945",
|
}}
|
||||||
boxShadow: passwordError
|
onKeyDown={(e) => e.key === "Enter" && handleUnlock()}
|
||||||
? "0 0 0 2px rgba(251,73,52,0.2)"
|
placeholder="Enter password"
|
||||||
: undefined,
|
className={[
|
||||||
}}
|
"w-full h-11 px-3.5 rounded-xl text-[15px] outline-none",
|
||||||
onFocus={(e) => {
|
"border transition-all duration-150",
|
||||||
if (!passwordError)
|
passwordError ? "ring-2" : "",
|
||||||
(e.target as HTMLInputElement).style.borderColor =
|
].join(" ")}
|
||||||
"#d79921";
|
style={{
|
||||||
}}
|
background: "#1d2021",
|
||||||
onBlur={(e) => {
|
color: "#ebdbb2",
|
||||||
if (!passwordError)
|
caretColor: "#d79921",
|
||||||
(e.target as HTMLInputElement).style.borderColor =
|
borderColor: passwordError ? "#fb4934" : "#504945",
|
||||||
"#504945";
|
boxShadow: passwordError
|
||||||
}}
|
? "0 0 0 2px rgba(251,73,52,0.2)"
|
||||||
/>
|
: undefined,
|
||||||
{passwordError && (
|
}}
|
||||||
<p className="text-[12px] -mt-1" style={{ color: "#fb4934" }}>
|
onFocus={(e) => {
|
||||||
Incorrect password.
|
if (!passwordError)
|
||||||
</p>
|
(e.target as HTMLInputElement).style.borderColor =
|
||||||
)}
|
"#d79921";
|
||||||
<button
|
}}
|
||||||
onClick={handleUnlock}
|
onBlur={(e) => {
|
||||||
className="w-full h-11 rounded-xl text-[15px] font-semibold tracking-tight transition-opacity active:opacity-75 select-none flex items-center justify-center gap-2"
|
if (!passwordError)
|
||||||
style={{ background: "#d79921", color: "#1d2021" }}
|
(e.target as HTMLInputElement).style.borderColor =
|
||||||
>
|
"#504945";
|
||||||
<Lock className="w-3.5 h-3.5" strokeWidth={2.5} />
|
}}
|
||||||
Unlock 250 MB
|
/>
|
||||||
</button>
|
{passwordError && (
|
||||||
</div>
|
<p
|
||||||
)}
|
className="text-[12px] -mt-1"
|
||||||
</div>
|
style={{ color: "#fb4934" }}
|
||||||
|
>
|
||||||
|
Incorrect password.
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
<button
|
||||||
|
onClick={handleUnlock}
|
||||||
|
className="w-full h-11 rounded-xl text-[15px] font-semibold tracking-tight transition-opacity active:opacity-75 select-none flex items-center justify-center gap-2"
|
||||||
|
style={{ background: "#d79921", color: "#1d2021" }}
|
||||||
|
>
|
||||||
|
<Lock className="w-3.5 h-3.5" strokeWidth={2.5} />
|
||||||
|
Unlock 250 MB
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Upload / progress / result */}
|
{/* Upload / progress / result */}
|
||||||
<div className="px-5 py-5 flex flex-col gap-4">
|
<div className="px-5 py-5 flex flex-col gap-4">
|
||||||
|
|||||||
Reference in new issue
Block a user