Repository navigation
fix: Resolve bulk downloads, PostHog crash, and missing file UX #544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
34f4d66
48bfb89
379e6c7
c67274c
7ee69bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,11 @@ | ||
| import { PostHog } from "posthog-node"; | ||
| /* eslint-disable @typescript-eslint/no-require-imports */ | ||
| /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
| /* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
| /* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
| /* eslint-disable @typescript-eslint/no-unsafe-call */ | ||
| /* eslint-disable @typescript-eslint/prefer-nullish-coalescing */ | ||
|
|
||
| import type { PostHog } from "posthog-node"; | ||
|
|
||
| let posthogClient: PostHog | null = null; | ||
|
|
||
|
|
@@ -12,7 +19,11 @@ export function getPostHogClient(): PostHog | null { | |
| } | ||
| return null; | ||
| } | ||
| posthogClient ??= new PostHog(token, { | ||
|
|
||
| const phModule = require("posthog-node"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it gets build on every upload or an api call...may be do something like If(posthogClient)return it ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great catch brooooo You're totally right, it was hitting that require on every single upload(i didnt see tht)
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great! |
||
| const PHClass = phModule.PostHog || phModule.default?.PostHog || phModule.default || phModule; | ||
|
|
||
| posthogClient ??= new PHClass(token, { | ||
| host: process.env.NEXT_PUBLIC_POSTHOG_HOST, | ||
| flushAt: 1, | ||
| flushInterval: 0, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import { type IPaper } from "../../interface"; | ||
| import { extractBracketContent } from "./string"; | ||
| import axios from "axios"; | ||
| import toast from "react-hot-toast"; | ||
|
|
||
| export const getSecureUrl = (url: string): string => | ||
| url.startsWith("http://") ? url.replace("http://", "https://") : url; | ||
|
|
@@ -23,6 +24,7 @@ export const downloadFile = async ( | |
| link.click(); | ||
| window.URL.revokeObjectURL(link.href); | ||
| } catch (error) { | ||
| console.error("Download failed:", error); | ||
| console.error("Download failed (File missing or network error):", error); | ||
| toast.error("This paper is no longer available on the server."); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make sure this error is shown only for a particular error response status, else even for a no internet situation, this might be shown to the uses..kind of misleading
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! If their internet drops, they shouldn't see the "paper is missing" error. I just updated the catch block to check navigator.onLine. Now, if it's an actual network failure, it gives a specific "You are offline" toast instead! |
||
| } | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we already handle that error, still do we need this ? will it delay the paper fetching by any chance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually still need the HEAD request! The issue is that the PDF library's built-in error handler completely fails when GCS returns a 404 (because GCS returns an XML page, and the viewer gets stuck trying to parse it as a PDF, causing an infinite loading spinner). The HEAD request is just a tiny pre-flight check that catches the 404 instantly before the viewer can hang.
And don't worry about delays! Because it's a HEAD request, it only grabs a few bytes of server headers without downloading the actual PDF payload. It takes less than 50ms and happens in the background before the heavy WASM engine even initializes, so there's zero noticeable delay in paper fetching so no worries