1
1
import {
2
- ApiItemRequest ,
3
- ApiSourceRequest ,
4
- ApiSubtitleRequest ,
5
2
createWorkerAddon ,
6
- Item ,
3
+ ItemRequest ,
4
+ MainItem ,
5
+ PlayableItem ,
7
6
Source ,
8
- Subtitle
9
- } from "../../../dist" ;
7
+ SourceRequest ,
8
+ Subtitle ,
9
+ SubtitleRequest
10
+ } from "../../../src" ;
10
11
11
- const EXAMPLE_ITEMS : Item [ ] = [
12
+ // Export needed for tests
13
+ export const EXAMPLE_ITEMS : PlayableItem [ ] = [
12
14
{
13
15
type : "movie" ,
14
16
ids : {
@@ -38,7 +40,8 @@ type ExampleSources = {
38
40
[ k : string ] : Source [ ] ;
39
41
} ;
40
42
41
- const EXAMPLE_SOURCES : ExampleSources = {
43
+ // Export needed for tests
44
+ export const EXAMPLE_SOURCES : ExampleSources = {
42
45
id1235 : [
43
46
{
44
47
type : "url" ,
@@ -68,7 +71,8 @@ type ExampleSubtitle = {
68
71
[ k : string ] : Subtitle [ ] ;
69
72
} ;
70
73
71
- const EXAMPLE_SUBTITLES : ExampleSubtitle = {
74
+ // Export needed for tests
75
+ export const EXAMPLE_SUBTITLES : ExampleSubtitle = {
72
76
elephant : [
73
77
{
74
78
id : "vtt" ,
@@ -89,7 +93,7 @@ const EXAMPLE_SUBTITLES: ExampleSubtitle = {
89
93
]
90
94
} ;
91
95
92
- const addon = createWorkerAddon ( {
96
+ export const addon = createWorkerAddon ( {
93
97
id : "example1" ,
94
98
name : "Typescript Example Addon" ,
95
99
version : "1.0.0" ,
@@ -101,22 +105,21 @@ const addon = createWorkerAddon({
101
105
hasMore : false
102
106
} ;
103
107
} )
104
- . registerActionHandler ( "item" , async ( args : ApiItemRequest , ctx ) => {
108
+ . registerActionHandler ( "item" , async ( args : ItemRequest , ctx ) => {
105
109
const id = args . ids [ "example1" ] ;
106
110
const item = EXAMPLE_ITEMS . find ( item => item . ids [ "example1" ] === id ) ;
107
111
if ( ! item ) throw new Error ( "Not found" ) ;
108
112
return item ;
109
113
} )
110
- . registerActionHandler ( "source" , async ( args : ApiSourceRequest , ctx ) => {
114
+ . registerActionHandler ( "source" , async ( args : SourceRequest , ctx ) => {
111
115
const id = args . ids [ "example1" ] ;
112
116
const sources = EXAMPLE_SOURCES [ id ] ;
113
117
return sources ?? [ ] ;
114
118
} )
115
- . registerActionHandler ( "subtitle" , async ( args : ApiSubtitleRequest , ctx ) => {
119
+ . registerActionHandler ( "subtitle" , async ( args : SubtitleRequest , ctx ) => {
116
120
// ids.id is an alias for ids["addon-id"]
117
121
const id = args . ids . id ;
122
+ await ctx . requestCache ( id ) ;
118
123
const subtitles = EXAMPLE_SUBTITLES [ id ] ;
119
124
return subtitles ?? [ ] ;
120
125
} ) ;
121
-
122
- export default addon ;
0 commit comments