Skip to content

Commit

Permalink
feat: add stop reason
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiteMinds committed Apr 9, 2024
1 parent fc76651 commit 723c32a
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 34 deletions.
8 changes: 4 additions & 4 deletions packages/http-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
"author": "WhiteMind",
"license": "LGPL",
"dependencies": {
"@autorecord/bilibili-recorder": "^1.1.6",
"@autorecord/douyin-recorder": "^1.0.8",
"@autorecord/douyu-recorder": "^1.1.6",
"@autorecord/huya-recorder": "^1.0.6",
"@autorecord/bilibili-recorder": "^1.2.0",
"@autorecord/douyin-recorder": "^1.1.0",
"@autorecord/douyu-recorder": "^1.2.0",
"@autorecord/huya-recorder": "^1.1.0",
"@autorecord/manager": "workspace:^",
"@autorecord/shared": "workspace:^",
"cors": "^2.8.5",
Expand Down
6 changes: 5 additions & 1 deletion packages/http-server/src/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface RecordModel {
savePath: string
startTimestamp: number
stopTimestamp?: number
stopReason?: string
}

export type RecorderModel = SerializedRecorder<RecorderExtra>
Expand Down Expand Up @@ -125,13 +126,16 @@ export function removeRecords(ids: RecordModel['id'][]): void {
scheduleSave()
}

export function updateRecordStopTime(props: Required<Pick<RecordModel, 'id' | 'stopTimestamp'>>): void {
export function updateRecordStopData(
props: Required<Pick<RecordModel, 'id' | 'stopTimestamp'>> & Pick<RecordModel, 'stopReason'>,
): void {
assertDBReady(db)
// TODO: 性能有问题的话可以在 insert 时做个索引表
const record = db.data.records.find((record) => record.id === props.id)
if (record == null) return

record.stopTimestamp = props.stopTimestamp
record.stopReason = props.stopReason
scheduleSave()
}

Expand Down
6 changes: 4 additions & 2 deletions packages/http-server/src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
removeRecord,
removeRecorder,
updateRecorder,
updateRecordStopTime,
updateRecordStopData,
} from './db'
import { ServerOpts } from './types'
import { parseSync, stringifySync } from 'subtitle'
Expand Down Expand Up @@ -105,6 +105,7 @@ export async function initRecorderManager(serverOpts: ServerOpts): Promise<void>

const updateRecordOnceRecordStop: Parameters<typeof recorderManager.on<'RecordStop'>>[1] = async ({
recordHandle,
reason,
}) => {
if (recordHandle.id !== recordId) return
recorderManager.off('RecordStop', updateRecordOnceRecordStop)
Expand All @@ -124,9 +125,10 @@ export async function initRecorderManager(serverOpts: ServerOpts): Promise<void>
return
}

updateRecordStopTime({
updateRecordStopData({
id: recordId,
stopTimestamp: Date.now(),
stopReason: reason,
})

if (autoGenerateSRTOnRecordStop) {
Expand Down
2 changes: 1 addition & 1 deletion packages/http-server/src/routes/recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async function stopRecord(args: API.stopRecord.Args): Promise<API.stopRecord.Res
if (recorder == null) throw new Error('404')

if (recorder.recordHandle != null) {
await recorder.recordHandle.stop()
await recorder.recordHandle.stop('manual stop')
// TODO: 或许还应该自动将 recorder.disableAutoCheck 设置为 true
}
return recorderToClient(recorder)
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@autorecord/manager",
"version": "1.0.5",
"version": "1.1.0",
"description": "Batch scheduling recorders",
"main": "./lib/index.js",
"publishConfig": {
Expand Down
8 changes: 5 additions & 3 deletions packages/manager/src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export interface RecorderManager<
> extends Emitter<{
error: { source: string; err: unknown }
RecordStart: { recorder: Recorder<E>; recordHandle: RecordHandle }
RecordStop: { recorder: Recorder<E>; recordHandle: RecordHandle }
RecordStop: { recorder: Recorder<E>; recordHandle: RecordHandle; reason?: string }
RecorderUpdated: {
recorder: Recorder<E>
keys: ((string & {}) | keyof Recorder<E>)[]
Expand Down Expand Up @@ -151,7 +151,9 @@ export function createRecorderManager<
this.recorders.push(recorder)

recorder.on('RecordStart', (recordHandle) => this.emit('RecordStart', { recorder, recordHandle }))
recorder.on('RecordStop', (recordHandle) => this.emit('RecordStop', { recorder, recordHandle }))
recorder.on('RecordStop', ({ recordHandle, reason }) =>
this.emit('RecordStop', { recorder, recordHandle, reason }),
)
recorder.on('Updated', (keys) => this.emit('RecorderUpdated', { recorder, keys }))
recorder.on('DebugLog', (log) => this.emit('RecorderDebugLog', { recorder, ...log }))

Expand All @@ -162,7 +164,7 @@ export function createRecorderManager<
removeRecorder(recorder) {
const idx = this.recorders.findIndex((item) => item === recorder)
if (idx === -1) return
recorder.recordHandle?.stop()
recorder.recordHandle?.stop('remove recorder')
this.recorders.splice(idx, 1)
this.emit('RecorderRemoved', recorder)
},
Expand Down
4 changes: 2 additions & 2 deletions packages/manager/src/recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface RecordHandle {

savePath: string

stop: (this: RecordHandle) => Promise<void>
stop: (this: RecordHandle, reason?: string) => Promise<void>
}

export interface DebugLog {
Expand All @@ -49,7 +49,7 @@ export interface DebugLog {
export interface Recorder<E extends AnyObject = UnknownObject>
extends Emitter<{
RecordStart: RecordHandle
RecordStop: RecordHandle
RecordStop: { recordHandle: RecordHandle; reason?: string }
Updated: ((string & {}) | keyof Recorder)[]
Message: Message
DebugLog: DebugLog
Expand Down
1 change: 1 addition & 0 deletions packages/web/src/messages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export default {
field_start_time: 'Recording start time',
field_end_time: 'Recording end time',
field_duration: 'Recording duration',
field_stop_reason: 'Stop reason',
field_path: 'Path',
field_action: 'Action',
file_not_exists: 'File not exists',
Expand Down
1 change: 1 addition & 0 deletions packages/web/src/messages/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export default {
field_start_time: 'Время начала записи',
field_end_time: 'Время окончания записи',
field_duration: 'Продолжительность записи',
field_stop_reason: 'Причина остановки',
field_path: 'Путь',
field_action: 'Действие',
file_not_exists: 'Файл не существует',
Expand Down
1 change: 1 addition & 0 deletions packages/web/src/messages/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export default {
field_start_time: '录制开始时间',
field_end_time: '录制终止时间',
field_duration: '录制时长',
field_stop_reason: '终止原因',
field_path: '路径',
field_action: '操作',
file_not_exists: '文件不存在',
Expand Down
7 changes: 7 additions & 0 deletions packages/web/src/views/Records/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@
},
width: 144,
},
{
title: $t('records.field_stop_reason'),
key: 'stopReason',
value: (record: ClientRecord) => record.stopReason ?? '/',
sortable: true,
width: 140,
},
{
title: $t('records.field_path'),
value: 'savePath',
Expand Down
40 changes: 20 additions & 20 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ __metadata:
languageName: node
linkType: hard

"@autorecord/bilibili-recorder@npm:^1.1.6":
version: 1.1.6
resolution: "@autorecord/bilibili-recorder@npm:1.1.6"
"@autorecord/bilibili-recorder@npm:^1.2.0":
version: 1.2.0
resolution: "@autorecord/bilibili-recorder@npm:1.2.0"
dependencies:
axios: ^0.27.2
blive-message-listener: ^0.4.0
mitt: ^3.0.0
ramda: ^0.28.0
peerDependencies:
"@autorecord/manager": "*"
checksum: 00678bd3595316cf816a853efc8c406c4ee88fda8de57c53734940ad087c2731410fcbab6eba1e56a924af66a9552027265c7f10bde4c4b0b828c458ccf90b1d
checksum: 8b377f5e742f8f59470e49da146ac666d6e4796a0072cdcbee019357f0b112339411bbadb8f2879b5ef76a2effec2b54b09eb261032c28d9abe8525d8d74a2fb
languageName: node
linkType: hard

"@autorecord/douyin-recorder@npm:^1.0.8":
version: 1.0.8
resolution: "@autorecord/douyin-recorder@npm:1.0.8"
"@autorecord/douyin-recorder@npm:^1.1.0":
version: 1.1.0
resolution: "@autorecord/douyin-recorder@npm:1.1.0"
dependencies:
axios: ^0.27.2
axios-cookiejar-support: ^4.0.3
Expand All @@ -47,13 +47,13 @@ __metadata:
tough-cookie: ^4.1.2
peerDependencies:
"@autorecord/manager": "*"
checksum: a1c8d449324facc420ad345c0981966afe51decc57b423ec7e0a502cd3211dd07201a119b887d002510634c78ced7502a344a4c92db3769e2553da4b5a59c5f0
checksum: eac88d565003708c11c553f157abdeaf289d424596c74c51802a6652be1c60d732d8e82c9962d43b585250bf54dfba33abf1c6dd6fe752b858e109482ea1e075
languageName: node
linkType: hard

"@autorecord/douyu-recorder@npm:^1.1.6":
version: 1.1.6
resolution: "@autorecord/douyu-recorder@npm:1.1.6"
"@autorecord/douyu-recorder@npm:^1.2.0":
version: 1.2.0
resolution: "@autorecord/douyu-recorder@npm:1.2.0"
dependencies:
axios: ^0.27.2
cheerio: ^1.0.0-rc.12
Expand All @@ -66,7 +66,7 @@ __metadata:
ws: ^8.9.0
peerDependencies:
"@autorecord/manager": "*"
checksum: 011d1c623358d2d3287228c8f7f9064d33acb7d29dbc1df99cfa3ea78c946a85862ddf646df8c5c4f7104ab012061a9cda4bf6d6a11fa77f63dfd73e5b4b6164
checksum: d96191deff444d98cb08f30df3c51eb88a5ef07b41f8af5c2e3c226d7a54e70ccfb99cf492e3d6890f3855b69c256e10b31d617dd15bdb27b7d9ca8799f0e5af
languageName: node
linkType: hard

Expand All @@ -90,10 +90,10 @@ __metadata:
version: 0.0.0-use.local
resolution: "@autorecord/http-server@workspace:packages/http-server"
dependencies:
"@autorecord/bilibili-recorder": ^1.1.6
"@autorecord/douyin-recorder": ^1.0.8
"@autorecord/douyu-recorder": ^1.1.6
"@autorecord/huya-recorder": ^1.0.6
"@autorecord/bilibili-recorder": ^1.2.0
"@autorecord/douyin-recorder": ^1.1.0
"@autorecord/douyu-recorder": ^1.2.0
"@autorecord/huya-recorder": ^1.1.0
"@autorecord/manager": "workspace:^"
"@autorecord/shared": "workspace:^"
"@types/cors": ^2.8.12
Expand All @@ -116,9 +116,9 @@ __metadata:
languageName: unknown
linkType: soft

"@autorecord/huya-recorder@npm:^1.0.6":
version: 1.0.6
resolution: "@autorecord/huya-recorder@npm:1.0.6"
"@autorecord/huya-recorder@npm:^1.1.0":
version: 1.1.0
resolution: "@autorecord/huya-recorder@npm:1.1.0"
dependencies:
axios: ^0.27.2
cheerio: ^1.0.0-rc.12
Expand All @@ -127,7 +127,7 @@ __metadata:
ramda: ^0.28.0
peerDependencies:
"@autorecord/manager": "*"
checksum: 57320a4705fbb49d9c79deee32856de1b3fb307f27da60445577a143437bf2e1fd4e147631414119fb4054a1396cc68ee4fcd838aeb8c098b9b55dfe374fb8a1
checksum: a8eb6b101c506f97130c7ca5e25495cddebc1105c617bf7e9105a06878d7d6f160e6f5834658144dd74833aa16fc599a363617c560f1adb95831ec070019c0d6
languageName: node
linkType: hard

Expand Down

0 comments on commit 723c32a

Please sign in to comment.