@shocknet/seedsdk
v1.0.20
Published
TypeScript SDK for LN.video file storage with resumable uploads, video transcoding, thumbnail generation, and CDN delivery
Maintainers
Readme
Seed SDK
A TypeScript SDK for uploading, managing, and serving files on LN.video - a simple, fast file storage and CDN service with built-in video transcoding and thumbnail generation.
Features
- 📤 Resumable uploads - Never lose progress on large file uploads
- 🎬 Video transcoding - Automatic conversion to optimized mp4 format
- 🖼️ Thumbnail generation - Create video thumbnails automatically
- 🔒 Private files - Secure files with presigned URLs
- 📊 Upload progress tracking - Real-time progress callbacks
- 🗂️ File management - List and delete files from your bucket
- 🚀 CDN delivery - Fast global content delivery
Installation
npm i @shocknet/seedsdkQuick Start
import SeedSDK from '@shocknet/seedsdk'
// Initialize SDK with your API token and Seed URL
const sdk = new SeedSDK("your_api_token", "https://your-ingest-instance.ln.video")
// Upload a file
const url = await sdk.uploadFilePath("./video.mp4", "my-video.mp4", true)
console.log("File uploaded:", url)API Reference
Constructor
new SeedSDK(apiKey: string, apiUrl: string)Initialize the SDK with your publish token and Seed API URL.
Upload Methods
uploadFilePath(path, finalName, isPrivate?)
Upload a single file from the file system.
const url = await sdk.uploadFilePath(
"./path/to/file.mp4",
"final-name.mp4",
true // isPrivate (default: true)
)Returns: Promise resolving to the file URL
publish(data)
Advanced upload with multiple files, progress tracking, and transcoding.
const file1 = await sdk.readFile("file1.mp4")
const file2 = await sdk.readFile("file2.avi")
const urls = await sdk.publish({
items: [
{
file: file1,
isPrivate: true,
finalName: "video1.mp4"
},
{
file: file2,
isPrivate: false,
finalName: "video2.mp4",
transcode: true // Convert to optimized mp4
}
],
onGlobalProgress: (progress) => {
Object.keys(progress).forEach(key => {
const { sent, total, eta } = progress[key]
console.log(`${key}: ${sent}/${total} bytes (ETA: ${eta}s)`)
})
},
needSeedThumbns: true,
gotThumbnail: (thumbnails) => {
thumbnails.forEach(t => console.log(`Thumbnail: ${t.name} -> ${t.uri}`))
}
})Parameters:
items- Array of files to upload with configurationonGlobalProgress- Callback for upload progressneedSeedThumbns- Generate thumbnails for videosgotThumbnail- Callback when thumbnails are ready
Returns: Promise resolving to array of file URLs
File Management
listFiles()
List all files in your bucket.
const files = await sdk.listFiles()
// Returns: [{ filename: string, src: string }, ...]
files.forEach(file => {
console.log(`${file.filename}: ${file.src}`)
})Returns: Promise resolving to array of file objects with filename and src
deleteFile(filename)
Delete a file from your bucket.
const result = await sdk.deleteFile("video.mp4")
if (result.ok) {
console.log("File deleted successfully")
} else {
console.error("Error:", result.error)
}Returns: Promise resolving to { ok: true } or { error: string }
URL Generation
presignUrl(filename, expiresInSeconds)
Generate a time-limited presigned URL for a private file.
const expiresIn = 60 * 60 * 24 * 30 // 30 days
const presignedUrl = await sdk.presignUrl("private-video.mp4", expiresIn)
console.log("Access URL:", presignedUrl)Returns: Promise resolving to presigned URL string
Utilities
readFile(filename)
Read a file from the file system (used internally for uploads).
const file = await sdk.readFile("./local-file.mp4")
// Returns a File object ready for uploadReturns: Promise resolving to File object
Examples
Video Transcoding
Automatically transcode videos to optimized mp4 format:
const file = await sdk.readFile("source.avi")
await sdk.publish({
items: [
{
file,
isPrivate: false,
finalName: "optimized.mp4",
transcode: true // Converts to 1080p mp4
}
]
})Managing Private Files
Upload private files and generate temporary access URLs:
// Upload private file
await sdk.uploadFilePath("./private.pdf", "document.pdf", true)
// Generate 1-hour access link
const accessUrl = await sdk.presignUrl("document.pdf", 3600)
// Share the temporary URL
console.log("Share this link:", accessUrl)Batch Operations
Upload multiple files with progress tracking:
const files = ["video1.mp4", "video2.mp4", "image.jpg"]
const fileObjects = await Promise.all(
files.map(f => sdk.readFile(f))
)
await sdk.publish({
items: fileObjects.map((file, i) => ({
file,
isPrivate: false,
finalName: `media-${i}.${file.name.split('.').pop()}`
})),
onGlobalProgress: (progress) => {
const totalSent = Object.values(progress).reduce((sum, p) => sum + p.sent, 0)
const totalSize = Object.values(progress).reduce((sum, p) => sum + p.total, 0)
console.log(`Overall: ${(totalSent/totalSize*100).toFixed(1)}%`)
}
})Cleanup Old Files
List and delete files from your bucket:
// Get all files
const files = await sdk.listFiles()
// Delete files
for (const file of files) {
console.log(`Deleting ${file.filename}...`)
await sdk.deleteFile(file.filename)
}TypeScript Support
This package is written in TypeScript and includes full type definitions out of the box.
Module Format
This package is an ES Module. Make sure your project is configured to use ES modules (e.g., "type": "module" in package.json).
License
ISC
