脚本多源
This commit is contained in:
+17
-7
@@ -6001,9 +6001,9 @@ const VideoSourceScriptLab = () => {
|
|||||||
enabled: true,
|
enabled: true,
|
||||||
history: [],
|
history: [],
|
||||||
});
|
});
|
||||||
const [testHook, setTestHook] = useState<'search' | 'detail' | 'resolvePlayUrl'>('search');
|
const [testHook, setTestHook] = useState<'getSources' | 'search' | 'recommend' | 'detail' | 'resolvePlayUrl'>('getSources');
|
||||||
const [testPayload, setTestPayload] = useState(
|
const [testPayload, setTestPayload] = useState(
|
||||||
JSON.stringify({ keyword: '凡人修仙传', page: 1 }, null, 2)
|
JSON.stringify({}, null, 2)
|
||||||
);
|
);
|
||||||
const [testOutput, setTestOutput] = useState('');
|
const [testOutput, setTestOutput] = useState('');
|
||||||
const importInputRef = useRef<HTMLInputElement | null>(null);
|
const importInputRef = useRef<HTMLInputElement | null>(null);
|
||||||
@@ -6302,13 +6302,18 @@ const VideoSourceScriptLab = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTestPayload(
|
setTestPayload(
|
||||||
testHook === 'search'
|
testHook === 'getSources'
|
||||||
? JSON.stringify({ keyword: '凡人修仙传', page: 1 }, null, 2)
|
? JSON.stringify({}, null, 2)
|
||||||
|
: testHook === 'search'
|
||||||
|
? JSON.stringify({ keyword: '凡人修仙传', page: 1, sourceId: 'main' }, null, 2)
|
||||||
|
: testHook === 'recommend'
|
||||||
|
? JSON.stringify({ page: 1 }, null, 2)
|
||||||
: testHook === 'detail'
|
: testHook === 'detail'
|
||||||
? JSON.stringify({ id: 'demo-id' }, null, 2)
|
? JSON.stringify({ id: 'demo-id', sourceId: 'main' }, null, 2)
|
||||||
: JSON.stringify(
|
: JSON.stringify(
|
||||||
{
|
{
|
||||||
sourceId: 'demo-id',
|
sourceId: 'main',
|
||||||
|
lineId: 'default',
|
||||||
playUrl: 'https://example.com/video.m3u8',
|
playUrl: 'https://example.com/video.m3u8',
|
||||||
episodeIndex: 0,
|
episodeIndex: 0,
|
||||||
},
|
},
|
||||||
@@ -6488,14 +6493,19 @@ const VideoSourceScriptLab = () => {
|
|||||||
</label>
|
</label>
|
||||||
<select
|
<select
|
||||||
value={testHook}
|
value={testHook}
|
||||||
onChange={(e) => setTestHook(e.target.value as 'search' | 'detail' | 'resolvePlayUrl')}
|
onChange={(e) => setTestHook(e.target.value as 'getSources' | 'search' | 'recommend' | 'detail' | 'resolvePlayUrl')}
|
||||||
className='px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100'
|
className='px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100'
|
||||||
>
|
>
|
||||||
|
<option value='getSources'>getSources</option>
|
||||||
<option value='search'>search</option>
|
<option value='search'>search</option>
|
||||||
|
<option value='recommend'>recommend</option>
|
||||||
<option value='detail'>detail</option>
|
<option value='detail'>detail</option>
|
||||||
<option value='resolvePlayUrl'>resolvePlayUrl</option>
|
<option value='resolvePlayUrl'>resolvePlayUrl</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
<p className='text-xs text-gray-500 dark:text-gray-400'>
|
||||||
|
现在脚本可以自己管理多个源和线路,测试入参可传 `sourceId`、`lineId`。
|
||||||
|
</p>
|
||||||
<textarea
|
<textarea
|
||||||
value={testPayload}
|
value={testPayload}
|
||||||
onChange={(e) => setTestPayload(e.target.value)}
|
onChange={(e) => setTestPayload(e.target.value)}
|
||||||
|
|||||||
@@ -55,9 +55,17 @@ const DEFAULT_SCRIPT_TEMPLATE = `return {
|
|||||||
author: 'admin'
|
author: 'admin'
|
||||||
},
|
},
|
||||||
|
|
||||||
async search(ctx, { keyword, page }) {
|
async getSources(ctx) {
|
||||||
ctx.log.info('search', keyword, page);
|
return [
|
||||||
|
{ id: 'main', name: '主站' },
|
||||||
|
{ id: 'backup', name: '备用站' }
|
||||||
|
];
|
||||||
|
},
|
||||||
|
|
||||||
|
async search(ctx, { keyword, page, sourceId }) {
|
||||||
|
ctx.log.info('search', keyword, page, sourceId);
|
||||||
return {
|
return {
|
||||||
|
sourceId,
|
||||||
list: [],
|
list: [],
|
||||||
page,
|
page,
|
||||||
pageCount: 1,
|
pageCount: 1,
|
||||||
@@ -65,21 +73,40 @@ const DEFAULT_SCRIPT_TEMPLATE = `return {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
async detail(ctx, { id }) {
|
async recommend(ctx, { page }) {
|
||||||
ctx.log.info('detail', id);
|
ctx.log.info('recommend', page);
|
||||||
|
return {
|
||||||
|
list: [],
|
||||||
|
page: page || 1,
|
||||||
|
pageCount: 1,
|
||||||
|
total: 0
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
async detail(ctx, { id, sourceId }) {
|
||||||
|
ctx.log.info('detail', id, sourceId);
|
||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
|
sourceId,
|
||||||
title: '',
|
title: '',
|
||||||
poster: '',
|
poster: '',
|
||||||
year: '',
|
year: '',
|
||||||
desc: '',
|
desc: '',
|
||||||
episodes: [],
|
playbacks: [
|
||||||
episodes_titles: []
|
{
|
||||||
|
sourceId: sourceId || 'main',
|
||||||
|
sourceName: '主站',
|
||||||
|
lineId: 'default',
|
||||||
|
lineName: '默认线路',
|
||||||
|
episodes: [],
|
||||||
|
episodes_titles: []
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
async resolvePlayUrl(ctx, { playUrl, sourceId, episodeIndex }) {
|
async resolvePlayUrl(ctx, { playUrl, sourceId, lineId, episodeIndex }) {
|
||||||
ctx.log.info('resolvePlayUrl', sourceId, episodeIndex, playUrl);
|
ctx.log.info('resolvePlayUrl', sourceId, lineId, episodeIndex, playUrl);
|
||||||
return {
|
return {
|
||||||
url: playUrl,
|
url: playUrl,
|
||||||
type: 'auto',
|
type: 'auto',
|
||||||
@@ -550,7 +577,7 @@ export async function restoreSourceScriptHistory(id: string, version: string) {
|
|||||||
|
|
||||||
export async function testSourceScript(input: {
|
export async function testSourceScript(input: {
|
||||||
code: string;
|
code: string;
|
||||||
hook: 'search' | 'detail' | 'resolvePlayUrl';
|
hook: 'getSources' | 'search' | 'recommend' | 'detail' | 'resolvePlayUrl';
|
||||||
payload: Record<string, any>;
|
payload: Record<string, any>;
|
||||||
name?: string;
|
name?: string;
|
||||||
key?: string;
|
key?: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user