feat: support video file drag-drop and paste (#9154)

This commit is contained in:
Dante
2026-02-25 07:59:26 +09:00
committed by GitHub
parent 2ff14fadc2
commit 9108b7535a
6 changed files with 359 additions and 25 deletions

View File

@@ -1,5 +1,10 @@
import { describe, expect, it } from 'vitest'
import { hasAudioType, hasImageType } from './eventUtils'
import {
hasAudioType,
hasImageType,
hasVideoType,
isMediaFile
} from './eventUtils'
describe('hasImageType', () => {
it('should return true for image types', () => {
@@ -24,3 +29,28 @@ describe('hasAudioType', () => {
expect(hasAudioType({ type: 'video/mp4' } as File)).toBe(false)
})
})
describe('hasVideoType', () => {
it('should return true for video types', () => {
expect(hasVideoType({ type: 'video/mp4' } as File)).toBe(true)
expect(hasVideoType({ type: 'video/webm' } as File)).toBe(true)
})
it('should return false for non-video types', () => {
expect(hasVideoType({ type: 'audio/mpeg' } as File)).toBe(false)
expect(hasVideoType({ type: 'image/png' } as File)).toBe(false)
})
})
describe('isMediaFile', () => {
it('should return true for image, audio, and video types', () => {
expect(isMediaFile({ type: 'image/png' } as File)).toBe(true)
expect(isMediaFile({ type: 'audio/mpeg' } as File)).toBe(true)
expect(isMediaFile({ type: 'video/mp4' } as File)).toBe(true)
})
it('should return false for non-media types', () => {
expect(isMediaFile({ type: 'text/plain' } as File)).toBe(false)
expect(isMediaFile({ type: 'application/json' } as File)).toBe(false)
})
})

View File

@@ -32,3 +32,11 @@ export function hasImageType({ type }: File): boolean {
export function hasAudioType({ type }: File): boolean {
return type.startsWith('audio')
}
export function hasVideoType({ type }: File): boolean {
return type.startsWith('video')
}
export function isMediaFile(file: File): boolean {
return hasImageType(file) || hasAudioType(file) || hasVideoType(file)
}