Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Wolfgang Knopki
Spacedeck-open-SAML
Commits
c075c562
Commit
c075c562
authored
May 07, 2018
by
Lukas F. Hartmann
Browse files
fix mp4 upload and video conversion progress display; fixes #21
parent
dc986dcc
Changes
2
Hide whitespace changes
Inline
Side-by-side
helpers/artifact_converter.js
View file @
c075c562
...
...
@@ -92,14 +92,14 @@ function createWaveform(fileName, localFilePath, callback){
});
}
function
convertVideo
(
fileName
,
filePath
,
codec
,
callback
,
progress
_c
allback
)
{
function
convertVideo
(
fileName
,
filePath
,
codec
,
callback
,
progress
C
allback
)
{
var
ext
=
path
.
extname
(
fileName
);
var
presetMime
=
mime
.
lookup
(
fileName
);
var
newExt
=
codec
==
"
mp4
"
?
"
mp4
"
:
"
ogv
"
;
var
convertedPath
=
filePath
+
"
.
"
+
newExt
;
console
.
log
(
"
converting
"
,
filePath
,
"
to
"
,
convertedPath
,
"
progress_cb:
"
,
progress_callback
);
console
.
log
(
"
converting
"
,
filePath
,
"
to
"
,
convertedPath
);
var
convertArgs
=
(
codec
==
"
mp4
"
)
?
[
"
-i
"
,
filePath
,
...
...
@@ -134,8 +134,8 @@ function convertVideo(fileName, filePath, codec, callback, progress_callback) {
ff
.
stderr
.
on
(
'
data
'
,
function
(
data
)
{
console
.
log
(
'
[ffmpeg-video] stderr:
'
+
data
);
if
(
progress
_c
allback
)
{
progress
_c
allback
(
data
);
if
(
progress
C
allback
)
{
progress
C
allback
(
data
);
}
});
...
...
@@ -280,7 +280,7 @@ var resizeAndUploadImage = function(a, mimeType, size, fileName, fileNameOrg, im
};
module
.
exports
=
{
convert
:
function
(
a
,
fileName
,
localFilePath
,
payloadCallback
,
progress
_c
allback
)
{
convert
:
function
(
a
,
fileName
,
localFilePath
,
payloadCallback
,
progress
C
allback
)
{
getMime
(
fileName
,
localFilePath
,
function
(
err
,
mimeType
){
console
.
log
(
"
[convert] fn:
"
+
fileName
+
"
local:
"
+
localFilePath
+
"
mimeType:
"
,
mimeType
);
...
...
@@ -311,8 +311,8 @@ module.exports = {
var
s3Key
=
"
s
"
+
a
.
space_id
.
toString
()
+
"
/a
"
+
a
.
_id
.
toString
()
+
"
/
"
+
fileName
;
uploader
.
uploadFile
(
s3Key
,
"
image/gif
"
,
localFilePath
,
function
(
err
,
url
)
{
if
(
err
)
c
allback
(
err
);
else
{
if
(
err
)
payloadC
allback
(
err
);
else
{
console
.
log
(
localFilePath
);
var
stats
=
fs
.
statSync
(
localFilePath
);
...
...
@@ -357,8 +357,8 @@ module.exports = {
thumbnail
:
function
(
callback
)
{
createThumbnailForVideo
(
fileName
,
localFilePath
,
function
(
err
,
created
){
console
.
log
(
"
thumbnail created:
"
,
err
,
created
);
if
(
err
)
callback
(
err
);
else
{
if
(
err
)
callback
(
err
);
else
{
var
keyName
=
"
s
"
+
a
.
space_id
.
toString
()
+
"
/a
"
+
a
.
_id
.
toString
()
+
"
/
"
+
fileName
+
"
.jpg
"
;
uploader
.
uploadFile
(
keyName
,
"
image/jpeg
"
,
created
,
function
(
err
,
url
){
if
(
err
)
callback
(
err
);
...
...
@@ -380,7 +380,7 @@ module.exports = {
else
callback
(
null
,
url
);
});
}
},
progress
_c
allback
);
},
progress
C
allback
);
}
},
mp4
:
function
(
callback
)
{
...
...
@@ -396,7 +396,7 @@ module.exports = {
else
callback
(
null
,
url
);
});
}
},
progress
_c
allback
);
},
progress
C
allback
);
}
},
original
:
function
(
callback
){
...
...
@@ -404,7 +404,7 @@ module.exports = {
callback
(
null
,
url
);
});
}
},
function
(
err
,
results
){
},
function
(
err
,
results
)
{
console
.
log
(
err
,
results
);
if
(
err
)
payloadCallback
(
err
,
a
);
...
...
@@ -438,19 +438,16 @@ module.exports = {
db
.
packArtifact
(
a
);
a
.
updated_at
=
new
Date
();
a
.
save
(
function
(
err
)
{
if
(
err
)
payloadCallback
(
err
,
null
);
else
{
fs
.
unlink
(
localFilePath
,
function
(
err
)
{
if
(
err
){
console
.
error
(
err
);
payloadCallback
(
err
,
null
);
}
else
{
console
.
log
(
'
successfully deleted
'
+
localFilePath
);
payloadCallback
(
null
,
a
);
}
});
}
a
.
save
().
then
(
function
()
{
fs
.
unlink
(
localFilePath
,
function
(
err
)
{
if
(
err
)
{
console
.
error
(
err
);
payloadCallback
(
err
,
null
);
}
else
{
console
.
log
(
'
successfully deleted
'
+
localFilePath
);
payloadCallback
(
null
,
a
);
}
});
});
}
});
...
...
routes/api/space_artifacts.js
View file @
c075c562
...
...
@@ -123,11 +123,11 @@ router.post('/:artifact_id/payload', function(req, res, next) {
var
writeStream
=
fs
.
createWriteStream
(
localFilePath
);
var
stream
=
req
.
pipe
(
writeStream
);
var
progress
_c
allback
=
function
(
progress
_m
sg
)
{
a
.
description
=
progress
_m
sg
.
toString
();
var
progress
C
allback
=
function
(
progress
M
sg
)
{
a
.
description
=
progress
M
sg
.
toString
();
db
.
packArtifact
(
a
);
a
.
save
();
redis
.
sendMessage
(
"
update
"
,
a
,
JSON
.
stringify
(
a
)
,
req
.
channelId
);
redis
.
sendMessage
(
"
update
"
,
"
Artifact
"
,
a
,
req
.
channelId
);
};
stream
.
on
(
'
finish
'
,
function
()
{
...
...
@@ -137,7 +137,7 @@ router.post('/:artifact_id/payload', function(req, res, next) {
db
.
Space
.
update
({
updated_at
:
new
Date
()
},
{
where
:
{
_id
:
req
.
space
.
_id
}});
res
.
distributeUpdate
(
"
Artifact
"
,
artifact
);
}
},
progress
_c
allback
);
},
progress
C
allback
);
});
}
else
{
res
.
status
(
401
).
json
({
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment