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
1 change: 1 addition & 0 deletions src/components/modals/add-source-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const CONTENT_TYPE_BY_SOURCE: Partial<Record<SourceType, string>> = {
[SOURCE_TYPES.YOUTUBE_SHORT]: "audio_video",
[SOURCE_TYPES.WEB_PAGE]: "webpage",
[SOURCE_TYPES.DOCUMENT]: "document",
[SOURCE_TYPES.ARXIV_PAPER]: "arxiv_paper",
}

const IN_PROGRESS_STATUSES = ["in_progress", "running", "pending"]
Expand Down
18 changes: 18 additions & 0 deletions src/lib/__tests__/source-detection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,22 @@ describe("detectSourceType", () => {
})
})
})

describe("arXiv Paper URLs", () => {
it("detects arxiv.org/abs/<id> as ARXIV_PAPER", async () => {
expect(await detectSourceType("https://arxiv.org/abs/2301.00001")).toBe(SOURCE_TYPES.ARXIV_PAPER)
})

it("detects arxiv.org/pdf/<id> as ARXIV_PAPER", async () => {
expect(await detectSourceType("https://arxiv.org/pdf/2301.00001")).toBe(SOURCE_TYPES.ARXIV_PAPER)
})

it("detects arxiv.org/abs/<id> with http as ARXIV_PAPER", async () => {
expect(await detectSourceType("http://arxiv.org/abs/2301.00001")).toBe(SOURCE_TYPES.ARXIV_PAPER)
})

it("does NOT detect a non-arXiv HTTPS URL as ARXIV_PAPER (regression guard)", async () => {
expect(await detectSourceType("https://example.com/paper")).toBe(SOURCE_TYPES.WEB_PAGE)
})
})
})
4 changes: 4 additions & 0 deletions src/lib/source-detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const SOURCE_TYPES = {
WEB_PAGE: "web_page",
DOCUMENT: "document",
LINK: "link",
ARXIV_PAPER: "arxiv_paper",
} as const

export type SourceType = (typeof SOURCE_TYPES)[keyof typeof SOURCE_TYPES]
Expand All @@ -36,6 +37,7 @@ const rssRegex =
const youtubeChannelPattern =
/https?:\/\/(www\.)?youtube\.com\/(user\/)?(@)?([\w-]+)/
const githubRepoPattern = /https:\/\/github\.com\/[\w-]+\/[\w-]+/
const arxivPattern = /https?:\/\/arxiv\.org\/(abs|pdf)\/[\d.]+/
const genericUrlRegex = /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/

async function checkIfRSS(url: string): Promise<boolean> {
Expand Down Expand Up @@ -71,6 +73,7 @@ export async function detectSourceType(source: string): Promise<SourceType> {
if (twitterHandlePattern.test(source)) return SOURCE_TYPES.TWITTER_HANDLE
if (rssRegex.test(source)) return SOURCE_TYPES.RSS
if (githubRepoPattern.test(source)) return SOURCE_TYPES.GITHUB_REPOSITORY
if (arxivPattern.test(source)) return SOURCE_TYPES.ARXIV_PAPER

if (genericUrlRegex.test(source)) {
const isRSS = await checkIfRSS(source)
Expand Down Expand Up @@ -105,6 +108,7 @@ export const SOURCE_TYPE_LABELS: Record<string, string> = {
[SOURCE_TYPES.WEB_PAGE]: "Web Page",
[SOURCE_TYPES.DOCUMENT]: "Document",
[SOURCE_TYPES.LINK]: "Link",
[SOURCE_TYPES.ARXIV_PAPER]: "arXiv Paper",
}

const SUBSCRIPTION_TYPES: string[] = [
Expand Down
Loading