many changes
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import type { QualityPreset } from "./quality-presets";
|
||||
import { QUALITY_PRESETS } from "./quality-presets";
|
||||
import { validateItemId, validateImageType, validateMediaSourceId, validateNumericParam, validateQueryParamValue } from "$lib/utils/validation";
|
||||
import type {
|
||||
Library,
|
||||
MediaItem,
|
||||
@@ -229,79 +228,40 @@ export class RepositoryClient {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get subtitle URL - constructs URL synchronously (no server call)
|
||||
* Get subtitle URL from backend
|
||||
* The Rust backend constructs and returns the URL with proper credentials handling
|
||||
*/
|
||||
getSubtitleUrl(itemId: string, mediaSourceId: string, streamIndex: number, format: string = "vtt"): string {
|
||||
if (!this._serverUrl || !this._accessToken) {
|
||||
throw new Error("Repository not initialized - call create() first");
|
||||
}
|
||||
|
||||
// Validate inputs to prevent injection attacks
|
||||
validateItemId(itemId);
|
||||
validateMediaSourceId(mediaSourceId);
|
||||
const index = validateNumericParam(streamIndex, 0, 1000, "streamIndex");
|
||||
|
||||
// Validate format - only allow safe subtitle formats
|
||||
if (!/^[a-z]+$/.test(format)) {
|
||||
throw new Error("Invalid subtitle format");
|
||||
}
|
||||
|
||||
return `${this._serverUrl}/Videos/${itemId}/${mediaSourceId}/Subtitles/${index}/Stream.${format}?api_key=${this._accessToken}`;
|
||||
async getSubtitleUrl(
|
||||
itemId: string,
|
||||
mediaSourceId: string,
|
||||
streamIndex: number,
|
||||
format: string = "vtt"
|
||||
): Promise<string> {
|
||||
return invoke<string>("repository_get_subtitle_url", {
|
||||
handle: this.ensureHandle(),
|
||||
itemId,
|
||||
mediaSourceId,
|
||||
streamIndex,
|
||||
format,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get video download URL with quality preset - constructs URL synchronously
|
||||
* Used for offline downloads
|
||||
* Get video download URL with quality preset from backend
|
||||
* The Rust backend constructs and returns the URL with proper credentials handling
|
||||
* Used for offline downloads and transcoding
|
||||
*/
|
||||
getVideoDownloadUrl(
|
||||
async getVideoDownloadUrl(
|
||||
itemId: string,
|
||||
quality: QualityPreset = "original",
|
||||
mediaSourceId?: string
|
||||
): string {
|
||||
if (!this._serverUrl || !this._accessToken) {
|
||||
throw new Error("Repository not initialized - call create() first");
|
||||
}
|
||||
|
||||
// Validate itemId and mediaSourceId
|
||||
validateItemId(itemId);
|
||||
if (mediaSourceId) {
|
||||
validateMediaSourceId(mediaSourceId);
|
||||
}
|
||||
|
||||
const preset = QUALITY_PRESETS[quality];
|
||||
|
||||
if (quality === "original" || !preset.videoBitrate) {
|
||||
// Direct stream for original quality
|
||||
const params = new URLSearchParams({
|
||||
api_key: this._accessToken,
|
||||
Static: "true",
|
||||
audioStreamIndex: "0",
|
||||
});
|
||||
if (mediaSourceId) {
|
||||
params.append("MediaSourceId", mediaSourceId);
|
||||
}
|
||||
return `${this._serverUrl}/Videos/${itemId}/stream?${params.toString()}`;
|
||||
}
|
||||
|
||||
// Transcoded download with quality preset
|
||||
const params = new URLSearchParams({
|
||||
api_key: this._accessToken,
|
||||
DeviceId: localStorage.getItem("jellytau_device_id") || "jellytau",
|
||||
Container: "mp4",
|
||||
VideoCodec: "h264",
|
||||
AudioCodec: "aac",
|
||||
AudioStreamIndex: "0",
|
||||
VideoBitrate: preset.videoBitrate.toString(),
|
||||
AudioBitrate: preset.audioBitrate.toString(),
|
||||
MaxHeight: preset.maxHeight?.toString() ?? "",
|
||||
TranscodingMaxAudioChannels: "2",
|
||||
): Promise<string> {
|
||||
return invoke<string>("repository_get_video_download_url", {
|
||||
handle: this.ensureHandle(),
|
||||
itemId,
|
||||
quality,
|
||||
mediaSourceId: mediaSourceId ?? null,
|
||||
});
|
||||
|
||||
if (mediaSourceId) {
|
||||
params.append("MediaSourceId", mediaSourceId);
|
||||
}
|
||||
|
||||
return `${this._serverUrl}/Videos/${itemId}/stream.mp4?${params.toString()}`;
|
||||
}
|
||||
|
||||
// ===== Favorite Methods (via Rust) =====
|
||||
|
||||
Reference in New Issue
Block a user