-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvedio.js
1 lines (1 loc) · 4.68 KB
/
vedio.js
1
!function(e){var o={};function t(r){if(o[r])return o[r].exports;var s=o[r]={i:r,l:!1,exports:{}};return e[r].call(s.exports,s,s.exports,t),s.l=!0,s.exports}t.m=e,t.c=o,t.d=function(e,o,r){t.o(e,o)||Object.defineProperty(e,o,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,o){if(1&o&&(e=t(e)),8&o)return e;if(4&o&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&o&&"string"!=typeof e)for(var s in e)t.d(r,s,function(o){return e[o]}.bind(null,s));return r},t.n=function(e){var o=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(o,"a",o),o},t.o=function(e,o){return Object.prototype.hasOwnProperty.call(e,o)},t.p="",t(t.s=0)}([function(e,o,t){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0});const s=r(t(1)),n=r(t(2)),i=r(t(3)),l=r(t(4)),d=r(t(5)),u=s.default();try{u.use(i.default());const e=n.default.diskStorage({destination:function(e,o,t){t(null,"./upload")},filename:function(e,o,t){t(null,o.fieldname+"_"+Date.now()+"_"+o.originalname)}}),o=n.default({storage:e});u.post("/vedio_upload",o.single("vedio"),(e,o)=>{try{o.send(e.file)}catch(e){o.send(400)}}),u.get("/video",(async function(e,o){try{const t={};let r,s;const n="upload/"+e.query.videoPath,i=e.headers.range;if(i){const e="bytes=";if(i.startsWith(e)){const o=i.substring(e.length).split("-");if(2===o.length){const e=o[0]&&o[0].trim();e&&e.length>0&&(t.start=r=parseInt(e));const n=o[1]&&o[1].trim();n&&n.length>0&&(t.end=s=parseInt(n))}}}console.log("options"),console.log(t),o.setHeader("content-type","video/mp4"),await d.default.stat(n,(l,u)=>{if(l)return console.error(`File stat error for ${n}.`),console.error(l),void o.sendStatus(500);let a=u.size;if(console.log("contentLength"),console.log(a),"HEAD"===e.method)o.statusCode=200,o.setHeader("accept-ranges","bytes"),o.setHeader("content-length",a),o.end();else{let e;e=void 0!==r&&void 0!==s?s+1-r:void 0!==r?a-r:void 0!==s?s+1:a,o.statusCode=void 0!==r||void 0!==s?206:200,o.setHeader("content-length",e),void 0!==i&&(o.setHeader("content-range",`bytes ${r||0}-${s||a-1}/${a}`),o.setHeader("accept-ranges","bytes"));const l=d.default.createReadStream(n,t);l.on("error",e=>{console.log(`Error reading file ${n}.`),console.log(e),o.sendStatus(500)}),l.pipe(o)}})}catch(e){console.log("error"),console.log(e)}})),u.listen(3001,(function(){console.log("App is listening on port 3001")}))}catch(e){console.log(new l.default(e).send().body)}},function(e,o){e.exports=require("express")},function(e,o){e.exports=require("multer")},function(e,o){e.exports=require("cors")},function(e,o,t){"use strict";Object.defineProperty(o,"__esModule",{value:!0});class r extends Error{constructor(e,o="errCommon"){if(super(),this.isError=!1,Error.captureStackTrace(this,this.constructor),"errServer"==o&&(o="errCommon",console.log(`\n${(new Date).toUTCString()} :-`),console.log(e)),"object"==typeof e){if(void 0!==e.errCommon&&(this.errCommon=e.errCommon),void 0!==e.errModuleWise&&(this.errModuleWise=e.errModuleWise),void 0!==e.HTTP_R_S_Code&&(this.HTTP_R_S_Code=e.HTTP_R_S_Code),void 0!==e.isError&&(this.isError=e.isError),e.errCommon||e.errModuleWise||e.HTTP_R_S_Code)return this;this[o]=[],e instanceof Error?(console.log(`\n${(new Date).toUTCString()} :-`),console.log(e),this[o].push({strMessage:"SOMETHING_WENT_WRONG"})):this[o].push({strMessage:e.strMessage,objDetails:e.objDetails}),this.isError=!0}else e&&(this[o]=[],this[o].push({strMessage:e}),this.isError=!0)}add(e,o="errCommon"){if("errServer"==o&&(o="errCommon",console.log(`\n${(new Date).toUTCString()} :-`),console.log(e)),"object"==typeof e){if(void 0!==e.errCommon&&(this.errCommon=e.errCommon),void 0!==e.errModuleWise&&(this.errModuleWise=e.errModuleWise),void 0!==e.HTTP_R_S_Code&&(this.HTTP_R_S_Code=e.HTTP_R_S_Code),e.errCommon||e.errModuleWise||e.HTTP_R_S_Code)return this;void 0===this[o]&&(this[o]=[]),e instanceof Error?(console.log(`\n${(new Date).toUTCString()} :-`),console.log(e),this[o].push({strMessage:"SOMETHING_WENT_WRONG"})):this[o].push({strMessage:e.strMessage,objDetails:e.objDetails}),this.isError=!0}else void 0===this[o]&&(this[o]=[]),this[o].push({strMessage:e}),this.isError=!0}setStatus(e){return this.HTTP_R_S_Code=e,this}send({statusCode:e=400}={}){let o={errCommon:this.errCommon,errModuleWise:this.errModuleWise};return Object.keys(o).forEach(e=>void 0===o[e]?delete o[e]:""),this.HTTP_R_S_Code&&(e=this.HTTP_R_S_Code),{body:o,statusCode:e}}}o.default=r},function(e,o){e.exports=require("fs")}]);