Skip to content

Commit

Permalink
Merge pull request #3 from gptscript-ai/add-nuxt-ui
Browse files Browse the repository at this point in the history
fix: address issue with page load always reindexing
  • Loading branch information
tylerslaton authored Mar 20, 2024
2 parents 5bdf173 + 7661e4c commit 55524ac
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
export default defineNuxtConfig({
srcDir: 'src',
devtools: { enabled: true },
css: ['~/assets/css/main.css'],
css: ['@/assets/css/main.css'],
modules: [
'@nuxt/ui',
'@nuxtjs/tailwindcss'
Expand Down
7 changes: 4 additions & 3 deletions src/server/api/[...slug].post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ export default defineEventHandler(async (event) => {

// if the tool is already indexed and force is not true, return the tool
let entry = await db.getToolsForUrl(url);

// if the tool is already indexed and the last index time is less than 1 hour ago, return the tool
if (entry.tools.length > 0 && entry.lastIndexedAt && (Date.now() - Number(entry.lastIndexedAt)) < 3600000) {

// if the tool is already indexed or if force is not set and the last index time is less than 1 hour ago, return the tool
const forceSetAndReady = getQuery(event).force && entry.lastIndexedAt && (Date.now() - Number(entry.lastIndexedAt)) < 3600000;
if (entry.tools.length > 0 && !forceSetAndReady) {
// add headers to communicate that the response is cached and when it was last indexed
setResponseHeader(event, "Content-Type", "application/json");
setResponseHeader(event, "Cached-Response", "true")
Expand Down

0 comments on commit 55524ac

Please sign in to comment.