11import { Action } from "../../internal/Action.js" ;
22import { toFloatAsString } from "../../internal/utils/toFloatAsString.js" ;
3+ import { IPreviewActionModel } from "../../internal/models/IPreviewActionModel.js" ;
4+ import { IActionModel } from "../../internal/models/IActionModel.js" ;
35
46/**
57 * @description Class for creating a preview of a video
@@ -8,12 +10,16 @@ import {toFloatAsString} from "../../internal/utils/toFloatAsString.js";
810 * @see Visit {@link Actions.VideoEdit|VideoEdit} for an example
911 */
1012class PreviewAction extends Action {
13+ protected _actionModel : IPreviewActionModel ;
1114 private _minSeg : string | number ;
1215 private _maxSeg : string | number ;
1316 private _duration : string | number ;
1417
1518 constructor ( ) {
1619 super ( ) ;
20+ this . _actionModel = {
21+ actionType : 'preview'
22+ } ;
1723 }
1824
1925 /**
@@ -22,6 +28,7 @@ class PreviewAction extends Action {
2228 * @return {this }
2329 */
2430 minimumSegmentDuration ( minSegDuration : string | number ) : this {
31+ this . _actionModel . minimumSegmentDuration = + minSegDuration ;
2532 this . _minSeg = minSegDuration ;
2633 return this ;
2734 }
@@ -32,6 +39,7 @@ class PreviewAction extends Action {
3239 * @return {this }
3340 */
3441 maximumSegments ( maxSeg : string | number ) : this {
42+ this . _actionModel . maximumSegments = + maxSeg ;
3543 this . _maxSeg = maxSeg ;
3644 return this ;
3745 }
@@ -42,6 +50,7 @@ class PreviewAction extends Action {
4250 * @return {this }
4351 */
4452 duration ( duration : string | number ) : this {
53+ this . _actionModel . duration = + duration ;
4554 this . _duration = duration ;
4655 return this ;
4756 }
@@ -54,6 +63,26 @@ class PreviewAction extends Action {
5463 this . _minSeg && `min_seg_dur_${ toFloatAsString ( this . _minSeg ) } `
5564 ] . filter ( ( a ) => a ) . join ( ':' ) ;
5665 }
66+
67+ static fromJson ( actionModel : IActionModel ) : PreviewAction {
68+ const { duration, maximumSegments, minimumSegmentDuration} = ( actionModel as IPreviewActionModel ) ;
69+ // We are using this() to allow inheriting classes to use super.fromJson.apply(this, [actionModel])
70+ // This allows the inheriting classes to determine the class to be created
71+ const result = new this ( ) ;
72+ if ( duration != null ) {
73+ result . duration ( duration ) ;
74+ }
75+
76+ if ( maximumSegments != null ) {
77+ result . maximumSegments ( maximumSegments ) ;
78+ }
79+
80+ if ( minimumSegmentDuration != null ) {
81+ result . minimumSegmentDuration ( minimumSegmentDuration ) ;
82+ }
83+
84+ return result ;
85+ }
5786}
5887
5988export { PreviewAction } ;
0 commit comments