Skip to content

Instantly share code, notes, and snippets.

View kmaher9's full-sized avatar
🥑
Focusing

Kieran Maher kmaher9

🥑
Focusing
View GitHub Profile
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.
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({
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": {
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)
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"
})
})
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()
// -----------------------------------------------------------------------------------------------------
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"
}
})
}
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": {
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)
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({