mirror of
https://github.com/Nezumi-2711/onedrive-vercel-index.git
synced 2026-09-22 13:38:45 +00:00
setup edge caching
This commit is contained in:
@@ -131,6 +131,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
// If method is GET, then the API is a normal request to the OneDrive API for files or folders
|
// If method is GET, then the API is a normal request to the OneDrive API for files or folders
|
||||||
const { path = '/', raw = false, next = '' } = req.query
|
const { path = '/', raw = false, next = '' } = req.query
|
||||||
|
|
||||||
|
// Set edge function caching for faster load times, check docs:
|
||||||
|
// https://vercel.com/docs/concepts/functions/edge-caching
|
||||||
|
res.setHeader('Cache-Control', 'max-age=60, s-maxage=3600, stale-while-revalidate')
|
||||||
|
|
||||||
// Sometimes the path parameter is defaulted to '[...path]' which we need to handle
|
// Sometimes the path parameter is defaulted to '[...path]' which we need to handle
|
||||||
if (path === '[...path]') {
|
if (path === '[...path]') {
|
||||||
res.status(400).json({ error: 'No path specified.' })
|
res.status(400).json({ error: 'No path specified.' })
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
// Get item details (specifically, its path) by its unique ID in OneDrive
|
// Get item details (specifically, its path) by its unique ID in OneDrive
|
||||||
const { id = '' } = req.query
|
const { id = '' } = req.query
|
||||||
|
|
||||||
|
// Set edge function caching for faster load times, check docs:
|
||||||
|
// https://vercel.com/docs/concepts/functions/edge-caching
|
||||||
|
res.setHeader('Cache-Control', 'max-age=60, s-maxage=3600, stale-while-revalidate')
|
||||||
|
|
||||||
if (typeof id === 'string') {
|
if (typeof id === 'string') {
|
||||||
const itemApi = `${apiConfig.driveApi}/items/${id}`
|
const itemApi = `${apiConfig.driveApi}/items/${id}`
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
// Query parameter from request
|
// Query parameter from request
|
||||||
const { q: searchQuery = '' } = req.query
|
const { q: searchQuery = '' } = req.query
|
||||||
|
|
||||||
|
// Set edge function caching for faster load times, check docs:
|
||||||
|
// https://vercel.com/docs/concepts/functions/edge-caching
|
||||||
|
res.setHeader('Cache-Control', 'max-age=60, s-maxage=3600, stale-while-revalidate')
|
||||||
|
|
||||||
if (typeof searchQuery === 'string') {
|
if (typeof searchQuery === 'string') {
|
||||||
// Construct Microsoft Graph Search API URL, and perform search only under the base directory
|
// Construct Microsoft Graph Search API URL, and perform search only under the base directory
|
||||||
const searchRootPath = encodePath('/')
|
const searchRootPath = encodePath('/')
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
// Get item thumbnails by its path since we will later check if it is protected
|
// Get item thumbnails by its path since we will later check if it is protected
|
||||||
const { path = '', size = 'medium' } = req.query
|
const { path = '', size = 'medium' } = req.query
|
||||||
|
|
||||||
|
// Set edge function caching for faster load times, check docs:
|
||||||
|
// https://vercel.com/docs/concepts/functions/edge-caching
|
||||||
|
res.setHeader('Cache-Control', 'max-age=60, s-maxage=3600, stale-while-revalidate')
|
||||||
|
|
||||||
// Check whether the size is valid - must be one of 'large', 'medium', or 'small'
|
// Check whether the size is valid - must be one of 'large', 'medium', or 'small'
|
||||||
if (size !== 'large' && size !== 'medium' && size !== 'small') {
|
if (size !== 'large' && size !== 'medium' && size !== 'small') {
|
||||||
res.status(400).json({ error: 'Invalid size' })
|
res.status(400).json({ error: 'Invalid size' })
|
||||||
|
|||||||
Reference in New Issue
Block a user