Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyiya committed May 15, 2024
1 parent dabcfd6 commit 586991e
Show file tree
Hide file tree
Showing 5 changed files with 5,404 additions and 3,930 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"@babel/core": "^7.24.5",
"@babel/preset-env": "^7.24.5",
"@babel/preset-react": "^7.24.1",
"@types/node": "^20.12.11",
"@types/react": "^18.3.1",
"@types/node": "^20.12.12",
"@types/react": "^18.3.2",
"@types/react-dom": "^18.3.0",
"babel-loader": "^9.1.3",
"bulma": "^0.9.4",
Expand All @@ -31,7 +31,7 @@
"react-hot-toast": "^2.4.1",
"ts-loader": "^9.5.1",
"typescript": "^5.4.5",
"wouter": "^3.1.2"
"wouter": "^3.1.3"
},
"devDependencies": {
"@svgr/webpack": "^8.1.0",
Expand All @@ -49,9 +49,9 @@
"postcss": "^8.4.38",
"postcss-flexbugs-fixes": "^5.0.2",
"postcss-loader": "^8.1.1",
"postcss-preset-env": "^9.5.11",
"postcss-preset-env": "^9.5.13",
"resolve-url-loader": "^5.0.0",
"sass": "^1.77.0",
"sass": "^1.77.1",
"sass-loader": "^14.2.1",
"style-loader": "^4.0.0",
"terser-webpack-plugin": "^5.3.10",
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/components/player/OPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import hls from '@oplayer/hls'
import ReactPlayer from '@oplayer/react'
import ui from '@oplayer/ui'
import React, { useImperativeHandle, useMemo, useRef } from 'react'
import { PlaylistPlugin, Chromecast } from '@oplayer/plugins'
import { Playlist, Chromecast } from '@oplayer/plugins'
// import Anime4kPlugin from './ainme4k'

interface OPlayerProps extends PlayerOptions {
Expand Down Expand Up @@ -93,7 +93,7 @@ const OPlayer = React.forwardRef(({ playerIsPlaying, duration, onEvent, autoplay
],
}),
hls({ forceHLS: true }),
new PlaylistPlugin({ sources: [] }),
new Playlist({ sources: [] }),
new Chromecast(),
// new Anime4kPlugin(),
],
Expand Down
19 changes: 15 additions & 4 deletions packages/shared/http.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { LRUCache } from 'lru-cache'

interface HeadersInit {
'Content-Type'?: string
[key: string]: any
Expand Down Expand Up @@ -27,6 +29,8 @@ class Interceptor<S = any, F = any> {
}
}

const cache = new LRUCache({ max: 10 })

export default class Http<R = any> {
private baseUrl: string
private headers: HeadersInit
Expand Down Expand Up @@ -74,6 +78,11 @@ export default class Http<R = any> {

//TODO: Return Promise<R<T>>
private _send<T>(url: string, method: string, headers: HeadersInit = {}, data: any = {}): Promise<T> {
const lruKey = JSON.stringify({ url, method, headers, data })
if (cache.has(lruKey)) {
return cache.get(lruKey) as any
}

const config: any = this.interceptors.request.resolve?.({
...this.headers,
...headers,
Expand All @@ -96,15 +105,17 @@ export default class Http<R = any> {
.then(
(res: Response) => {
rawResponse = res
const json = res.json()
cache.set(lruKey, json)
try {
return res.json()
return json
} catch (error) {
throw error
}
},
(reson: any) => {
console.error('<--- request error' + reson)
return this.interceptors.request.reject?.(reson)
(reason: any) => {
console.error('<--- request error' + reason)
return this.interceptors.request.reject?.(reason)
}
)
.then((response) => {
Expand Down
5 changes: 3 additions & 2 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"@oplayer/core": "latest",
"@oplayer/hls": "latest",
"@oplayer/plugins": "1.0.13-chromecast.1",
"@oplayer/plugins": "latest",
"@oplayer/react": "^1.2.10",
"@oplayer/ui": "latest",
"anime4k.js": "^0.0.4",
Expand All @@ -30,6 +30,7 @@
"remark-gfm": "^4.0.0",
"remark-parse": "^11.0.0",
"remark-rehype": "^11.1.0",
"unified": "^11.0.4"
"unified": "^11.0.4",
"lru-cache": "^10.2.2"
}
}
Loading

0 comments on commit 586991e

Please sign in to comment.