2015-09-15 12:34:50 -04:00
var express = require ( 'express' ) ;
var router = express . Router ( ) ;
2015-09-23 18:17:03 -04:00
function humanFileSize ( bytes , si ) {
var thresh = si ? 1000 : 1024 ;
if ( Math . abs ( bytes ) < thresh ) {
return bytes + ' B' ;
}
var units = si
? [ 'kB' , 'MB' , 'GB' , 'TB' , 'PB' , 'EB' , 'ZB' , 'YB' ]
: [ 'KiB' , 'MiB' , 'GiB' , 'TiB' , 'PiB' , 'EiB' , 'ZiB' , 'YiB' ] ;
var u = - 1 ;
do {
bytes /= thresh ;
++ u ;
} while ( Math . abs ( bytes ) >= thresh && u < units . length - 1 ) ;
return bytes . toFixed ( 1 ) + ' ' + units [ u ] ;
}
2015-09-15 12:34:50 -04:00
/* GET home page. */
router . get ( '/:id' , function ( req , res , next ) {
2015-09-29 17:04:17 -04:00
var config = res . locals . config ;
2015-09-15 12:34:50 -04:00
var db = config . init _db ( ) ;
var data ;
db . get ( "SELECT id,title,original_title,studio,rating,summary,duration,tags_genre,tags_star,year FROM metadata_items WHERE id = ?" , req . params . id , function ( err , row ) {
row . tags _genre = row . tags _genre . split ( '|' ) ;
row . tags _star = row . tags _star . split ( '|' ) ;
row . rating = Math . round ( row . rating , 2 ) ;
2015-09-23 18:02:59 -04:00
row . file = [ ] ;
2015-09-23 18:08:51 -04:00
db . each ( "SELECT id,file,size,hash,duration FROM media_parts where media_item_id IN (SELECT id FROM media_items WHERE metadata_item_id = ? )" , req . params . id , function ( error , ligne ) {
2015-09-23 18:02:59 -04:00
var tab = ligne . file . split ( '/' ) ;
var tab2 = tab [ tab . length - 1 ] . split ( '\\' ) ;
var filename = tab2 [ tab2 . length - 1 ] ;
ligne . filename = filename ;
2015-09-23 18:17:03 -04:00
ligne . size = humanFileSize ( ligne . size , true ) ;
2015-09-23 18:02:59 -04:00
row . file . push ( ligne ) ;
} , function ( ) {
2017-09-27 08:11:26 -04:00
res . render ( 'movie' , { title : 'Video Detail' , movie : row } ) ;
2015-09-23 18:02:59 -04:00
} ) ;
2015-09-15 12:34:50 -04:00
} ) ;
db . close ( ) ;
} ) ;
module . exports = router ;