mirror of
https://github.com/anatolykopyl/movieroom-core.git
synced 2026-03-26 12:54:51 +00:00
Request based on filename
This commit is contained in:
@@ -1,2 +1,5 @@
|
|||||||
PORT=3000
|
PORT=3000
|
||||||
KEY=w2geth
|
MOVIES_PORT=3001
|
||||||
|
DB=mongodb://localhost:27017/w2g
|
||||||
|
FILES=./files
|
||||||
|
TEMP_FILES=./temp
|
||||||
|
|||||||
4
README.md
Normal file
4
README.md
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# W2G API
|
||||||
|
|
||||||
|
API for [watch2gether](https://github.com/anatolykopyl/watch2gether-front).
|
||||||
|
Also contains movie streaming server.
|
||||||
@@ -35,8 +35,11 @@ router.post('/room', async (ctx) => {
|
|||||||
const doc = new RoomModel(room);
|
const doc = new RoomModel(room);
|
||||||
|
|
||||||
torrent.on('done', function () {
|
torrent.on('done', function () {
|
||||||
findInDir(torrent.path, /\.mp4$/, (filename: string) => {
|
const extensionsRegEx = /(\.mp4|\.mkv)$/;
|
||||||
mv(`./${filename}`, `${process.env.FILES}/${room.id}.mp4`, () => {
|
findInDir(torrent.path, extensionsRegEx, (filename: string) => {
|
||||||
|
const extension = filename.split('.').pop();
|
||||||
|
mv(`./${filename}`, `${process.env.FILES}/${room.id}.${extension}`, () => {
|
||||||
|
doc.filename = room.id + '.' + extension;
|
||||||
doc.downloaded = true;
|
doc.downloaded = true;
|
||||||
doc.downloadedAt = new Date();
|
doc.downloadedAt = new Date();
|
||||||
doc.save();
|
doc.save();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ export interface Room {
|
|||||||
magnet: string;
|
magnet: string;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
movie?: string;
|
movie?: string;
|
||||||
|
filename?: string;
|
||||||
downloaded?: boolean;
|
downloaded?: boolean;
|
||||||
downloadedAt?: Date;
|
downloadedAt?: Date;
|
||||||
position: number;
|
position: number;
|
||||||
@@ -15,6 +16,7 @@ export const roomSchema = new Schema<Room>({
|
|||||||
magnet: { type: String, required: true },
|
magnet: { type: String, required: true },
|
||||||
createdAt: { type: Date, required: true },
|
createdAt: { type: Date, required: true },
|
||||||
movie: { type: String, required: false },
|
movie: { type: String, required: false },
|
||||||
|
filename: { type: String, required: false },
|
||||||
downloaded: { type: Boolean, required: false },
|
downloaded: { type: Boolean, required: false },
|
||||||
downloadedAt: { type: Date, required: false },
|
downloadedAt: { type: Date, required: false },
|
||||||
position: { type: Number, required: true },
|
position: { type: Number, required: true },
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ router.get('/', async (ctx) => {
|
|||||||
({ status: ctx.status, body: ctx.body } = errorResponse('stream-01', 'Requires range header'));
|
({ status: ctx.status, body: ctx.body } = errorResponse('stream-01', 'Requires range header'));
|
||||||
}
|
}
|
||||||
|
|
||||||
const videoPath = './files/' + ctx.request.query.id + '.mp4';
|
const videoPath = './files/' + ctx.request.query.filename;
|
||||||
const videoSize = fs.statSync(videoPath).size;
|
const videoSize = fs.statSync(videoPath).size;
|
||||||
|
|
||||||
// Parse Range
|
// Parse Range
|
||||||
|
|||||||
Reference in New Issue
Block a user