@tscircuit/fake-snippets 0.0.94 → 0.0.96

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -153,12 +153,34 @@ export async function handleUserProfile(req, res) {
153
153
  res.status(200).send(html)
154
154
  }
155
155
 
156
+ async function handleDatasheetPage(req, res) {
157
+ const parts = req.url.split("?")[0].split("/")
158
+ if (parts[1] !== "datasheets" || !parts[2]) {
159
+ throw new Error("Not a datasheet page")
160
+ }
161
+ const chipName = parts[2]
162
+
163
+ const html = getHtmlWithModifiedSeoTags({
164
+ title: `${chipName} Datasheet - tscircuit`,
165
+ description: `View the ${chipName} datasheet on tscircuit.`,
166
+ canonicalUrl: `${BASE_URL}/datasheets/${he.encode(chipName)}`,
167
+ })
168
+
169
+ res.setHeader("Content-Type", "text/html; charset=utf-8")
170
+ res.setHeader("Cache-Control", cacheControlHeader)
171
+ res.setHeader("Vary", "Accept-Encoding")
172
+ res.status(200).send(html)
173
+ }
174
+
156
175
  async function handleCustomPackageHtml(req, res) {
157
176
  // Get the author and package name
158
177
  const [_, author, unscopedPackageName] = req.url.split("?")[0].split("/")
159
178
  if (!author || !unscopedPackageName) {
160
179
  throw new Error("Invalid author/package URL")
161
180
  }
181
+ if (author === "datasheets") {
182
+ throw new Error("Datasheet route")
183
+ }
162
184
 
163
185
  const packageNotFoundHtml = getHtmlWithModifiedSeoTags({
164
186
  title: "Package Not Found - tscircuit",
@@ -279,6 +301,16 @@ export default async function handler(req, res) {
279
301
  console.warn(e)
280
302
  }
281
303
 
304
+ const pathParts = req.url.split("?")[0].split("/")
305
+ if (pathParts[1] === "datasheets" && pathParts[2]) {
306
+ try {
307
+ await handleDatasheetPage(req, res)
308
+ return
309
+ } catch (e) {
310
+ console.warn(e)
311
+ }
312
+ }
313
+
282
314
  try {
283
315
  await handleCustomPage(req, res)
284
316
  return
@@ -12,4 +12,5 @@ test("create datasheet", async () => {
12
12
  expect(res.data.datasheet.chip_name).toBe("TestChip")
13
13
  expect(res.data.datasheet.pin_information).toBeNull()
14
14
  expect(res.data.datasheet.datasheet_pdf_urls).toBeNull()
15
+ expect(res.data.datasheet.ai_description).toBeNull()
15
16
  })
@@ -40,3 +40,15 @@ test("get datasheet by chip name 404", async () => {
40
40
  })
41
41
  expect(res.status).toBe(404)
42
42
  })
43
+
44
+ test("get datasheet by chip name case insensitive", async () => {
45
+ const { axios } = await getTestServer()
46
+ await axios.post("/api/datasheets/create", { chip_name: "ChipCase" })
47
+
48
+ const res = await axios.get("/api/datasheets/get", {
49
+ params: { chip_name: "chipcase" },
50
+ })
51
+
52
+ expect(res.status).toBe(200)
53
+ expect(res.data.datasheet.chip_name).toBe("ChipCase")
54
+ })
@@ -18,4 +18,5 @@ test("process datasheets", async () => {
18
18
  })
19
19
  expect(res.data.datasheet.pin_information).not.toBeNull()
20
20
  expect(res.data.datasheet.datasheet_pdf_urls).not.toBeNull()
21
+ expect(res.data.datasheet.ai_description).not.toBeNull()
21
22
  })
@@ -15,4 +15,5 @@ test("run async tasks processes datasheets", async () => {
15
15
  params: { datasheet_id: id },
16
16
  })
17
17
  expect(res.data.datasheet.pin_information).not.toBeNull()
18
+ expect(res.data.datasheet.ai_description).not.toBeNull()
18
19
  })