2024-04-15 12:53:42 +00:00
|
|
|
import { createMigrationIds, createRecordMigrationSequence } from '@tldraw/store'
|
2023-06-03 08:27:44 +00:00
|
|
|
import { T } from '@tldraw/validate'
|
2024-04-15 12:53:42 +00:00
|
|
|
import { TLAsset } from '../records/TLAsset'
|
|
|
|
import { TLBaseAsset, createAssetValidator } from './TLBaseAsset'
|
2023-04-25 11:01:25 +00:00
|
|
|
|
2023-06-03 20:46:53 +00:00
|
|
|
/**
|
|
|
|
* An asset used for videos, used by the TLVideoShape.
|
|
|
|
*
|
|
|
|
* @public */
|
2023-04-25 11:01:25 +00:00
|
|
|
export type TLVideoAsset = TLBaseAsset<
|
|
|
|
'video',
|
|
|
|
{
|
|
|
|
w: number
|
|
|
|
h: number
|
|
|
|
name: string
|
|
|
|
isAnimated: boolean
|
|
|
|
mimeType: string | null
|
|
|
|
src: string | null
|
|
|
|
}
|
|
|
|
>
|
|
|
|
|
2024-04-25 14:31:26 +00:00
|
|
|
/** @public */
|
2023-06-03 20:46:53 +00:00
|
|
|
export const videoAssetValidator: T.Validator<TLVideoAsset> = createAssetValidator(
|
2023-04-25 11:01:25 +00:00
|
|
|
'video',
|
|
|
|
T.object({
|
|
|
|
w: T.number,
|
|
|
|
h: T.number,
|
|
|
|
name: T.string,
|
|
|
|
isAnimated: T.boolean,
|
|
|
|
mimeType: T.string.nullable(),
|
2024-01-10 10:45:19 +00:00
|
|
|
src: T.srcUrl.nullable(),
|
2023-04-25 11:01:25 +00:00
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2024-04-15 12:53:42 +00:00
|
|
|
const Versions = createMigrationIds('com.tldraw.asset.video', {
|
2023-04-25 11:01:25 +00:00
|
|
|
AddIsAnimated: 1,
|
|
|
|
RenameWidthHeight: 2,
|
2024-01-09 10:49:57 +00:00
|
|
|
MakeUrlsValid: 3,
|
2024-04-15 12:53:42 +00:00
|
|
|
} as const)
|
|
|
|
|
|
|
|
export { Versions as videoAssetVersions }
|
2023-04-25 11:01:25 +00:00
|
|
|
|
2024-04-25 14:31:26 +00:00
|
|
|
/** @public */
|
2024-04-15 12:53:42 +00:00
|
|
|
export const videoAssetMigrations = createRecordMigrationSequence({
|
|
|
|
sequenceId: 'com.tldraw.asset.video',
|
|
|
|
recordType: 'asset',
|
|
|
|
filter: (asset) => (asset as TLAsset).type === 'video',
|
|
|
|
sequence: [
|
|
|
|
{
|
|
|
|
id: Versions.AddIsAnimated,
|
|
|
|
up: (asset: any) => {
|
|
|
|
asset.props.isAnimated = false
|
2023-04-25 11:01:25 +00:00
|
|
|
},
|
2024-04-15 12:53:42 +00:00
|
|
|
down: (asset: any) => {
|
|
|
|
delete asset.props.isAnimated
|
2023-04-25 11:01:25 +00:00
|
|
|
},
|
|
|
|
},
|
2024-04-15 12:53:42 +00:00
|
|
|
{
|
|
|
|
id: Versions.RenameWidthHeight,
|
|
|
|
up: (asset: any) => {
|
|
|
|
asset.props.w = asset.props.width
|
|
|
|
asset.props.h = asset.props.height
|
|
|
|
delete asset.props.width
|
|
|
|
delete asset.props.height
|
2023-04-25 11:01:25 +00:00
|
|
|
},
|
2024-04-15 12:53:42 +00:00
|
|
|
down: (asset: any) => {
|
|
|
|
asset.props.width = asset.props.w
|
|
|
|
asset.props.height = asset.props.h
|
|
|
|
delete asset.props.w
|
|
|
|
delete asset.props.h
|
2023-04-25 11:01:25 +00:00
|
|
|
},
|
|
|
|
},
|
2024-04-15 12:53:42 +00:00
|
|
|
{
|
|
|
|
id: Versions.MakeUrlsValid,
|
|
|
|
up: (asset: any) => {
|
|
|
|
if (!T.srcUrl.isValid(asset.props.src)) {
|
|
|
|
asset.props.src = ''
|
2024-01-09 10:49:57 +00:00
|
|
|
}
|
|
|
|
},
|
2024-04-15 12:53:42 +00:00
|
|
|
down: (_asset) => {
|
|
|
|
// noop
|
|
|
|
},
|
2024-01-09 10:49:57 +00:00
|
|
|
},
|
2024-04-15 12:53:42 +00:00
|
|
|
],
|
2023-04-25 11:01:25 +00:00
|
|
|
})
|