lovely. got a couple of partial implementations....
This commit is contained in:
parent
89ca4013fd
commit
89f526e9d9
14 changed files with 180 additions and 154 deletions
|
@ -1,17 +0,0 @@
|
|||
import { Params, useParams } from "@solidjs/router";
|
||||
import { createEffect } from "solid-js";
|
||||
import { Player } from "~/features/player";
|
||||
|
||||
interface ItemParams extends Params {
|
||||
item: string;
|
||||
}
|
||||
|
||||
export default function Item() {
|
||||
const params = useParams<ItemParams>();
|
||||
|
||||
return (
|
||||
<>
|
||||
<Player id={params.item} />
|
||||
</>
|
||||
);
|
||||
}
|
41
src/routes/(shell)/watch/[slug].tsx
Normal file
41
src/routes/(shell)/watch/[slug].tsx
Normal file
|
@ -0,0 +1,41 @@
|
|||
import { json, Params, query, redirect, RouteDefinition, useParams } from "@solidjs/router";
|
||||
import { createSlug, getEntry } from "~/features/content";
|
||||
import { Player } from "~/features/player";
|
||||
import { toSlug } from "~/utilities";
|
||||
|
||||
const healUrl = query(async (slug: string) => {
|
||||
const entry = await getEntry(slug.slice(slug.lastIndexOf('-') + 1));
|
||||
|
||||
if (entry === undefined) {
|
||||
return json(null, { status: 404 });
|
||||
}
|
||||
|
||||
const actualSlug = createSlug(entry);
|
||||
|
||||
if (slug === actualSlug) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw redirect(`/watch/${actualSlug}`);
|
||||
}, 'watch.heal');
|
||||
|
||||
interface ItemParams extends Params {
|
||||
title: string;
|
||||
id: string;
|
||||
}
|
||||
|
||||
export const route = {
|
||||
async preload({ params }) {
|
||||
await healUrl(params.slug);
|
||||
},
|
||||
} satisfies RouteDefinition;
|
||||
|
||||
export default function Item() {
|
||||
const params = useParams<ItemParams>();
|
||||
|
||||
return (
|
||||
<>
|
||||
<Player id={params.id} />
|
||||
</>
|
||||
);
|
||||
}
|
BIN
src/routes/api/stream/SampleVideo_1280x720_10mb.mp4
Normal file
BIN
src/routes/api/stream/SampleVideo_1280x720_10mb.mp4
Normal file
Binary file not shown.
49
src/routes/api/stream/video.ts
Normal file
49
src/routes/api/stream/video.ts
Normal file
|
@ -0,0 +1,49 @@
|
|||
import { APIEvent } from "@solidjs/start/server";
|
||||
// import * as Bun from 'bun';
|
||||
|
||||
const CHUNK_SIZE = 1 * 1e6; // 1MB
|
||||
|
||||
export const GET = async ({ request, ...event }: APIEvent) => {
|
||||
"use server";
|
||||
|
||||
const range = request.headers.get('range');
|
||||
|
||||
if (range === null) {
|
||||
return new Response('Requires Range header', { status: 400 })
|
||||
}
|
||||
|
||||
try {
|
||||
const video = Bun.file(import.meta.dirname + '/SampleVideo_1280x720_10mb.mp4');
|
||||
|
||||
if ((await video.exists()) !== true) {
|
||||
return new Response('File not found', { status: 404 });
|
||||
}
|
||||
|
||||
const videoSize = video.size;
|
||||
|
||||
const start = Number.parseInt(range.replace(/\D/g, ''));
|
||||
const end = Math.min(start + CHUNK_SIZE, videoSize - 1);
|
||||
const contentLength = end - start + 1;
|
||||
|
||||
const view = video.slice(start, end);
|
||||
|
||||
console.log(start, end, videoSize, video, view);
|
||||
|
||||
return new Response(video.stream());
|
||||
|
||||
// return new Response(stream, {
|
||||
// status: 206,
|
||||
// headers: {
|
||||
// 'Accept-Ranges': 'bytes',
|
||||
// 'Content-Range': `bytes ${start}-${end}/${videoSize}`,
|
||||
// 'Content-Length': `${contentLength}`,
|
||||
// 'Content-type': 'video/mp4',
|
||||
// },
|
||||
// });
|
||||
}
|
||||
catch (e) {
|
||||
console.error(e);
|
||||
|
||||
throw e;
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue