mirror of
https://github.com/Nezumi-2711/onedrive-vercel-index.git
synced 2026-09-22 05:32:01 +00:00
update deps including useSWR 1.0
This commit is contained in:
+12
-11
@@ -16,10 +16,11 @@
|
|||||||
"@fortawesome/react-fontawesome": "^0.1.14",
|
"@fortawesome/react-fontawesome": "^0.1.14",
|
||||||
"@headlessui/react": "^1.4.0",
|
"@headlessui/react": "^1.4.0",
|
||||||
"awesome-debounce-promise": "^2.1.0",
|
"awesome-debounce-promise": "^2.1.0",
|
||||||
"axios": "^0.21.1",
|
"axios": "^0.25.0",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"crypto-js": "^4.1.1",
|
"crypto-js": "^4.1.1",
|
||||||
"emoji-regex": "^9.2.2",
|
"csstype": "^3.0.10",
|
||||||
|
"emoji-regex": "^10.0.0",
|
||||||
"ioredis": "^4.28.2",
|
"ioredis": "^4.28.2",
|
||||||
"jszip": "^3.7.1",
|
"jszip": "^3.7.1",
|
||||||
"next": "^12.0.10",
|
"next": "^12.0.10",
|
||||||
@@ -32,15 +33,15 @@
|
|||||||
"react-dom": "^17.0.2",
|
"react-dom": "^17.0.2",
|
||||||
"react-hot-toast": "^2.0.0",
|
"react-hot-toast": "^2.0.0",
|
||||||
"react-hotkeys-hook": "^3.4.4",
|
"react-hotkeys-hook": "^3.4.4",
|
||||||
"react-markdown": "^6.0.2",
|
"react-markdown": "^8.0.0",
|
||||||
"react-player": "^2.9.0",
|
"react-player": "^2.9.0",
|
||||||
"react-reader": "^0.20.4",
|
"react-reader": "^0.20.4",
|
||||||
"react-viewer": "^3.2.2",
|
"react-viewer": "^3.2.2",
|
||||||
"rehype-katex": "^5.0.0",
|
"rehype-katex": "^6.0.2",
|
||||||
"rehype-raw": "^6.0.0",
|
"rehype-raw": "^6.0.0",
|
||||||
"remark-gfm": "^1.0.0",
|
"remark-gfm": "^3.0.1",
|
||||||
"remark-math": "^4.0.0",
|
"remark-math": "^5.1.1",
|
||||||
"swr": "^0.5.6",
|
"swr": "^1.2.0",
|
||||||
"use-clipboard-copy": "^0.2.0",
|
"use-clipboard-copy": "^0.2.0",
|
||||||
"use-constant": "^1.1.0"
|
"use-constant": "^1.1.0"
|
||||||
},
|
},
|
||||||
@@ -49,16 +50,16 @@
|
|||||||
"@types/crypto-js": "^4.0.2",
|
"@types/crypto-js": "^4.0.2",
|
||||||
"@types/ioredis": "^4.28.5",
|
"@types/ioredis": "^4.28.5",
|
||||||
"@types/prismjs": "^1.16.5",
|
"@types/prismjs": "^1.16.5",
|
||||||
"@types/react": "17.0.11",
|
"@types/react": "17.0.38",
|
||||||
"@types/react-copy-to-clipboard": "^5.0.0",
|
"@types/react-copy-to-clipboard": "^5.0.0",
|
||||||
"@types/react-dom": "^17.0.8",
|
"@types/react-dom": "^17.0.8",
|
||||||
"@types/react-pdf": "^5.0.4",
|
"@types/react-pdf": "^5.0.4",
|
||||||
"@types/react-syntax-highlighter": "^13.5.1",
|
"@types/react-syntax-highlighter": "^13.5.1",
|
||||||
"autoprefixer": "^10.4.0",
|
"autoprefixer": "^10.4.0",
|
||||||
"eslint": "7.29.0",
|
"eslint": "8.8.0",
|
||||||
"eslint-config-next": "11.0.0",
|
"eslint-config-next": "12.0.10",
|
||||||
"postcss": "^8.4.5",
|
"postcss": "^8.4.5",
|
||||||
"tailwindcss": "^3.0.18",
|
"tailwindcss": "^3.0.18",
|
||||||
"typescript": "4.3.4"
|
"typescript": "4.5.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+703
-609
File diff suppressed because it is too large
Load Diff
+2
-1
@@ -17,7 +17,8 @@
|
|||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"isolatedModules": true,
|
"isolatedModules": true,
|
||||||
"jsx": "preserve",
|
"jsx": "preserve",
|
||||||
"noImplicitAny": false
|
"noImplicitAny": false,
|
||||||
|
"incremental": true
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"next-env.d.ts",
|
"next-env.d.ts",
|
||||||
|
|||||||
+7
-20
@@ -1,5 +1,7 @@
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import useSWR, { cache, Key, useSWRInfinite } from 'swr'
|
import useSWRInfinite from 'swr/infinite'
|
||||||
|
|
||||||
|
import type { OdAPIResponse } from '../types'
|
||||||
|
|
||||||
import { getStoredToken } from './protectedRouteHandler'
|
import { getStoredToken } from './protectedRouteHandler'
|
||||||
|
|
||||||
@@ -17,22 +19,6 @@ export async function fetcher(url: string, token?: string): Promise<any> {
|
|||||||
throw { status: err.response.status, message: err.response.data }
|
throw { status: err.response.status, message: err.response.data }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Use stale SWR instead of revalidating on each request. Not ideal for this scenario but have to do
|
|
||||||
* if fetching serverside props from component instead of pages.
|
|
||||||
* @param url request url
|
|
||||||
* @returns useSWR instance
|
|
||||||
*/
|
|
||||||
export function useStaleSWR({ url, path = '' }: { url: Key; path?: string }) {
|
|
||||||
const revalidationOptions = {
|
|
||||||
revalidateOnMount: !(cache.has(`arg@"${url}"@null`) || cache.has(url)),
|
|
||||||
revalidateOnFocus: false,
|
|
||||||
revalidateOnReconnect: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
const hashedToken = getStoredToken(path)
|
|
||||||
return useSWR([url, hashedToken], fetcher, revalidationOptions)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Paging with useSWRInfinite + protected token support
|
* Paging with useSWRInfinite + protected token support
|
||||||
@@ -49,7 +35,7 @@ export function useProtectedSWRInfinite(path: string = '') {
|
|||||||
* @param path Directory path
|
* @param path Directory path
|
||||||
* @returns API to the next page
|
* @returns API to the next page
|
||||||
*/
|
*/
|
||||||
function getNextKey(pageIndex, previousPageData): (string | null)[] | null {
|
function getNextKey(pageIndex: number, previousPageData: OdAPIResponse): (string | null)[] | null {
|
||||||
// Reached the end of the collection
|
// Reached the end of the collection
|
||||||
if (previousPageData && !previousPageData.folder) return null
|
if (previousPageData && !previousPageData.folder) return null
|
||||||
|
|
||||||
@@ -60,11 +46,12 @@ export function useProtectedSWRInfinite(path: string = '') {
|
|||||||
return [`/api?path=${path}&next=${previousPageData.next}`, hashedToken]
|
return [`/api?path=${path}&next=${previousPageData.next}`, hashedToken]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Disable auto-revalidate, these options are equivalent to useSWRImmutable
|
||||||
|
// https://swr.vercel.app/docs/revalidation#disable-automatic-revalidations
|
||||||
const revalidationOptions = {
|
const revalidationOptions = {
|
||||||
revalidateOnMount: !(cache.has(`arg@"/api?path=${path}"@null`) || cache.has(`/api?path=${path}`)),
|
revalidateIfStale: false,
|
||||||
revalidateOnFocus: false,
|
revalidateOnFocus: false,
|
||||||
revalidateOnReconnect: true,
|
revalidateOnReconnect: true,
|
||||||
}
|
}
|
||||||
// return useSWRInfinite(getNextKey, fetcher)
|
|
||||||
return useSWRInfinite(getNextKey, fetcher, revalidationOptions)
|
return useSWRInfinite(getNextKey, fetcher, revalidationOptions)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user