mirror of
https://github.com/p-stream/backend.git
synced 2026-03-11 17:55:35 +00:00
Created a /discover endpoint, should decrease latency for sites that need to discover as caching is used
This commit is contained in:
parent
96c12982e2
commit
2d44ab8f73
5 changed files with 53 additions and 6 deletions
|
|
@ -4,4 +4,5 @@ META_DESCRIPTION=''
|
||||||
CAPTCHA=false
|
CAPTCHA=false
|
||||||
CAPTCHA_CLIENT_KEY=''
|
CAPTCHA_CLIENT_KEY=''
|
||||||
# USE A RANDOM PASSWORD GENERATOR LIKE THIS: https://bitwarden.com/password-generator/ NEVER SHARE
|
# USE A RANDOM PASSWORD GENERATOR LIKE THIS: https://bitwarden.com/password-generator/ NEVER SHARE
|
||||||
CRYPTO_SECRET=''
|
CRYPTO_SECRET=''
|
||||||
|
TMDB_API_KEY=''
|
||||||
|
|
@ -13,6 +13,7 @@ export default defineNitroConfig({
|
||||||
captchaClientKey: process.env.CAPTCHA_CLIENT_KEY || ''
|
captchaClientKey: process.env.CAPTCHA_CLIENT_KEY || ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
cyrptoSecret: process.env.CRYPTO_SECRET
|
cyrptoSecret: process.env.CRYPTO_SECRET,
|
||||||
|
tmdbApiKey: process.env.TMDB_API_KEY,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
23
package-lock.json
generated
23
package-lock.json
generated
|
|
@ -8,6 +8,7 @@
|
||||||
"@prisma/client": "^6.4.1",
|
"@prisma/client": "^6.4.1",
|
||||||
"bs58": "^6.0.0",
|
"bs58": "^6.0.0",
|
||||||
"jsonwebtoken": "^9.0.2",
|
"jsonwebtoken": "^9.0.2",
|
||||||
|
"tmdb-ts": "^2.0.1",
|
||||||
"tweetnacl": "^1.0.3",
|
"tweetnacl": "^1.0.3",
|
||||||
"zod": "^3.24.2"
|
"zod": "^3.24.2"
|
||||||
},
|
},
|
||||||
|
|
@ -2474,6 +2475,15 @@
|
||||||
"node": ">=18.0"
|
"node": ">=18.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/cross-fetch": {
|
||||||
|
"version": "4.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-4.1.0.tgz",
|
||||||
|
"integrity": "sha512-uKm5PU+MHTootlWEY+mZ4vvXoCn4fLQxT9dSc1sXVMSFkINTJVN8cAQROpwcKm8bJ/c7rgZVIBWzH5T78sNZZw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"node-fetch": "^2.7.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/cross-spawn": {
|
"node_modules/cross-spawn": {
|
||||||
"version": "7.0.6",
|
"version": "7.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
|
||||||
|
|
@ -4123,7 +4133,6 @@
|
||||||
"version": "2.7.0",
|
"version": "2.7.0",
|
||||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz",
|
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz",
|
||||||
"integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==",
|
"integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"whatwg-url": "^5.0.0"
|
"whatwg-url": "^5.0.0"
|
||||||
|
|
@ -5441,6 +5450,15 @@
|
||||||
"url": "https://github.com/sponsors/SuperchupuDev"
|
"url": "https://github.com/sponsors/SuperchupuDev"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/tmdb-ts": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/tmdb-ts/-/tmdb-ts-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-T3OnICnxOARYPrRoTuuPpmaoQ1mUL5AgWz3N5RT1WjLmlNA4h0H+j2yho3KTp4tm8V6sfwJRbzQaSCwGIzxuRQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"cross-fetch": "^4.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/to-regex-range": {
|
"node_modules/to-regex-range": {
|
||||||
"version": "5.0.1",
|
"version": "5.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
|
||||||
|
|
@ -5468,7 +5486,6 @@
|
||||||
"version": "0.0.3",
|
"version": "0.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
|
||||||
"integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==",
|
"integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/tweetnacl": {
|
"node_modules/tweetnacl": {
|
||||||
|
|
@ -5905,7 +5922,6 @@
|
||||||
"version": "3.0.1",
|
"version": "3.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
|
||||||
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==",
|
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==",
|
||||||
"dev": true,
|
|
||||||
"license": "BSD-2-Clause"
|
"license": "BSD-2-Clause"
|
||||||
},
|
},
|
||||||
"node_modules/webpack-virtual-modules": {
|
"node_modules/webpack-virtual-modules": {
|
||||||
|
|
@ -5919,7 +5935,6 @@
|
||||||
"version": "5.0.0",
|
"version": "5.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
|
||||||
"integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
|
"integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tr46": "~0.0.3",
|
"tr46": "~0.0.3",
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
"@prisma/client": "^6.4.1",
|
"@prisma/client": "^6.4.1",
|
||||||
"bs58": "^6.0.0",
|
"bs58": "^6.0.0",
|
||||||
"jsonwebtoken": "^9.0.2",
|
"jsonwebtoken": "^9.0.2",
|
||||||
|
"tmdb-ts": "^2.0.1",
|
||||||
"tweetnacl": "^1.0.3",
|
"tweetnacl": "^1.0.3",
|
||||||
"zod": "^3.24.2"
|
"zod": "^3.24.2"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
29
server/routes/discover.ts
Normal file
29
server/routes/discover.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
import { TMDB } from "tmdb-ts";
|
||||||
|
const tmdb = new TMDB(useRuntimeConfig().tmdbApiKey)
|
||||||
|
export default defineCachedEventHandler(async (event) => {
|
||||||
|
const popular = { movies: [], shows: [] }
|
||||||
|
popular.movies.push(...((data) => (data.results.sort((a, b) => b.vote_average - a.vote_average), data.results))(await tmdb.movies.popular())); // Sorts by vote average
|
||||||
|
popular.shows.push(...((data) => (data.results.sort((a, b) => b.vote_average - a.vote_average), data.results))(await tmdb.tvShows.popular())); // Sorts by vote average
|
||||||
|
|
||||||
|
const genres = {
|
||||||
|
movies: await tmdb.genres.movies(),
|
||||||
|
shows: await tmdb.genres.tvShows()
|
||||||
|
}
|
||||||
|
const topRated = {
|
||||||
|
movies: await tmdb.movies.topRated(),
|
||||||
|
shows: await tmdb.tvShows.topRated()
|
||||||
|
}
|
||||||
|
const nowPlaying = {
|
||||||
|
movies: (await tmdb.movies.nowPlaying()).results.sort((a, b) => b.vote_average - a.vote_average),
|
||||||
|
shows: (await tmdb.tvShows.onTheAir()).results.sort((a, b) => b.vote_average - a.vote_average)
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
popular,
|
||||||
|
topRated,
|
||||||
|
nowPlaying,
|
||||||
|
genres
|
||||||
|
};
|
||||||
|
}, {
|
||||||
|
maxAge: process.env.NODE_ENV === 'production' ? 20 * 60 : 0 // 20 Minutes for prod, no cache for dev. Customize to your liking
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue