-
Notifications
You must be signed in to change notification settings - Fork 183
feat: construct resource url from backend #98
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 1 commit
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 |
---|---|---|
|
@@ -17,6 +17,17 @@ export function appendImageData(data: StreamData, imageUrl?: string) { | |
}); | ||
} | ||
|
||
function getNodeUrl(metadata: Metadata) { | ||
const url = metadata["URL"]; | ||
if (url) return url; | ||
const fileName = metadata["file_name"]; | ||
leehuwuj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (fileName) { | ||
const fileServerUrlPrefix = process.env.FILESERVER_URL_PREFIX || ""; | ||
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. if |
||
return `${fileServerUrlPrefix}/data/${fileName}`; | ||
} | ||
return undefined; | ||
} | ||
|
||
export function appendSourceData( | ||
data: StreamData, | ||
sourceNodes?: NodeWithScore<Metadata>[], | ||
|
@@ -29,6 +40,7 @@ export function appendSourceData( | |
...node.node.toMutableJSON(), | ||
id: node.node.id_, | ||
score: node.score ?? null, | ||
url: getNodeUrl(node.node.metadata), | ||
})), | ||
}, | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ import { Check, Copy } from "lucide-react"; | |
import { useMemo } from "react"; | ||
import { Button } from "../button"; | ||
import { HoverCard, HoverCardContent, HoverCardTrigger } from "../hover-card"; | ||
import { getStaticFileDataUrl } from "../lib/url"; | ||
import { SourceData, SourceNode } from "./index"; | ||
import { useCopyToClipboard } from "./use-copy-to-clipboard"; | ||
import PdfDialog from "./widgets/PdfDialog"; | ||
|
@@ -33,12 +32,11 @@ type NodeInfo = { | |
|
||
function getNodeInfo(node: SourceNode): NodeInfo { | ||
if (typeof node.metadata["URL"] === "string") { | ||
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. this code can be simplified as we render NODE_TYPE.URL and NODE_TYPE.FILE the same way, we can merge them - I guess we also don't need to check the metadata here and probably even can remove |
||
const url = node.metadata["URL"]; | ||
return { | ||
id: node.id, | ||
type: NODE_TYPE.URL, | ||
path: url, | ||
url, | ||
path: node.url, | ||
url: node.url, | ||
}; | ||
} | ||
if (typeof node.metadata["file_path"] === "string") { | ||
|
@@ -47,8 +45,8 @@ function getNodeInfo(node: SourceNode): NodeInfo { | |
return { | ||
id: node.id, | ||
type: NODE_TYPE.FILE, | ||
path: node.metadata["file_path"], | ||
url: getStaticFileDataUrl(filePath), | ||
path: filePath, | ||
url: node.url, | ||
}; | ||
} | ||
|
||
|
@@ -125,7 +123,7 @@ function NodeInfo({ nodeInfo }: { nodeInfo: NodeInfo }) { | |
<span>{nodeInfo.path}</span> | ||
</a> | ||
<Button | ||
onClick={() => copyToClipboard(nodeInfo.path!)} | ||
onClick={() => copyToClipboard(nodeInfo.url!)} | ||
leehuwuj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
size="icon" | ||
variant="ghost" | ||
className="h-12 w-12 shrink-0" | ||
|
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.