Request based on filename

This commit is contained in:
2021-12-30 19:57:29 +03:00
parent 9c823eb3a4
commit 5e6a557a44
5 changed files with 16 additions and 4 deletions

View File

@@ -1,2 +1,5 @@
PORT=3000
KEY=w2geth
MOVIES_PORT=3001
DB=mongodb://localhost:27017/w2g
FILES=./files
TEMP_FILES=./temp

4
README.md Normal file
View File

@@ -0,0 +1,4 @@
# W2G API
API for [watch2gether](https://github.com/anatolykopyl/watch2gether-front).
Also contains movie streaming server.

View File

@@ -35,8 +35,11 @@ router.post('/room', async (ctx) => {
const doc = new RoomModel(room);
torrent.on('done', function () {
findInDir(torrent.path, /\.mp4$/, (filename: string) => {
mv(`./${filename}`, `${process.env.FILES}/${room.id}.mp4`, () => {
const extensionsRegEx = /(\.mp4|\.mkv)$/;
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.downloadedAt = new Date();
doc.save();

View File

@@ -5,6 +5,7 @@ export interface Room {
magnet: string;
createdAt: Date;
movie?: string;
filename?: string;
downloaded?: boolean;
downloadedAt?: Date;
position: number;
@@ -15,6 +16,7 @@ export const roomSchema = new Schema<Room>({
magnet: { type: String, required: true },
createdAt: { type: Date, required: true },
movie: { type: String, required: false },
filename: { type: String, required: false },
downloaded: { type: Boolean, required: false },
downloadedAt: { type: Date, required: false },
position: { type: Number, required: true },

View File

@@ -19,7 +19,7 @@ router.get('/', async (ctx) => {
({ 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;
// Parse Range