This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const video = './videos/sample.mp4' // source video | |
let stat = fs.statSync(video) | |
let range = request.headers.range // will be undefined on first request | |
if (range) { // if the user is requesting to scrub to a point in the video | |
let [start, end] = range.replace(/bytes=/, '').split('-') // the incoming range typically looks like bytes=3214-5435, so extract the numbers out from the request | |
start = parseInt(start, 10) // check we are dealing with an integer | |
end = end ? parseInt(end, 10) : stat.size - 1 // a request can be for a segment, or could be 'bytes=324-' idicating from here, until the end of the video. Therefore end can be undefined. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const File = require('../models/file') | |
const Busboy = require('busboy') | |
const fs = require('fs') | |
exports.newFile = function (request, response, next) { | |
var busboy = new Busboy({ headers: request.headers }) | |
busboy.on('file', function(fieldname, file, filename, encoding, mimetype) { | |
if (fs.existsSync(`../datum/${filename}`)) { | |
return response.status(400).json({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const File = require('../models/file') | |
const fs = require('fs') | |
exports.getFile = async function (request, response) { | |
let file = null | |
try { file = await File.findById(request.params.id) } catch (err) {} | |
if (!file) { | |
return response.status(404).json({ | |
"data": { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mongoose = require('mongoose') | |
const fileSchema = new mongoose.Schema({ | |
name: { type: String, required: true }, | |
size: { type: Number, required: false }, | |
location: { type: String, required: true }, | |
mime: { type: String, required: true } | |
}, { timestamps: true }) | |
module.exports = mongoose.model('file', fileSchema) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const router = require('express').Router() | |
const uploads = require('../controllers/upload') | |
const serve = require('../controllers/serve') | |
router.get('/', (request, response, next) => { | |
return response.status(200).json({ | |
"message": "API loaded" | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
const session = require('express-session') | |
const mongoose = require('mongoose') | |
const logger = require('morgan') | |
const bodyParser = require('body-parser') | |
const busboy = require('connect-busboy') | |
const MongoStore = require('connect-mongo')(session) | |
const app = express() | |
// ----------------------------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.getFiles = async function (request, response) { | |
let files = await File.find({}) | |
if (!files) { | |
return response.status(404).json({ | |
"data": { | |
"message": "There are no uploaded files" | |
} | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const File = require('../models/file') | |
const fs = require('fs') | |
exports.getFile = async function (request, response) { | |
let file = null | |
try { file = await File.findById(request.params.id) } catch (err) {} | |
if (!file) { | |
return response.status(404).json({ | |
"data": { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mongoose = require('mongoose') | |
const fileSchema = new mongoose.Schema({ | |
name: { type: String, required: true }, | |
size: { type: Number, required: false }, | |
location: { type: String, required: true }, | |
mime: { type: String, required: true } | |
}, { timestamps: true }) | |
module.exports = mongoose.model('file', fileSchema) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const File = require('../models/file') | |
const Busboy = require('busboy') | |
const fs = require('fs') | |
exports.newFile = function (request, response, next) { | |
var busboy = new Busboy({ headers: request.headers }) | |
busboy.on('file', function(fieldname, file, filename, encoding, mimetype) { | |
if (fs.existsSync(`../datum/${filename}`)) { | |
return response.status(400).json({ |
NewerOlder