Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dima Krasner
Sharkey
Commits
efe2a6be
Unverified
Commit
efe2a6be
authored
6 years ago
by
syuilo
Browse files
Options
Downloads
Patches
Plain Diff
Better logging
parent
75558add
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/services/drive/upload-from-url.ts
+9
-6
9 additions, 6 deletions
src/services/drive/upload-from-url.ts
with
9 additions
and
6 deletions
src/services/drive/upload-from-url.ts
+
9
−
6
View file @
efe2a6be
...
...
@@ -9,6 +9,7 @@ import config from '../../config';
import
{
IUser
}
from
'
../../models/user
'
;
import
*
as
mongodb
from
'
mongodb
'
;
import
{
driveLogger
}
from
'
./logger
'
;
import
chalk
from
'
chalk
'
;
const
logger
=
driveLogger
.
createSubLogger
(
'
downloader
'
);
...
...
@@ -21,15 +22,11 @@ export default async (
force
=
false
,
link
=
false
):
Promise
<
IDriveFile
>
=>
{
logger
.
info
(
`REQUESTED:
${
url
}
`
);
let
name
=
URL
.
parse
(
url
).
pathname
.
split
(
'
/
'
).
pop
();
if
(
!
validateFileName
(
name
))
{
name
=
null
;
}
logger
.
info
(
`name:
${
name
}
`
);
// Create temp file
const
[
path
,
cleanup
]
=
await
new
Promise
<
[
string
,
any
]
>
((
res
,
rej
)
=>
{
tmp
.
file
((
e
,
path
,
fd
,
cleanup
)
=>
{
...
...
@@ -40,13 +37,17 @@ export default async (
// write content at URL to temp file
await
new
Promise
((
res
,
rej
)
=>
{
logger
.
info
(
`Downloading
${
chalk
.
cyan
(
url
)}
...`
);
const
writable
=
fs
.
createWriteStream
(
path
);
writable
.
on
(
'
finish
'
,
()
=>
{
logger
.
succ
(
`Download succeeded:
${
chalk
.
cyan
(
url
)}
`
);
res
();
});
writable
.
on
(
'
error
'
,
error
=>
{
logger
.
error
(
error
);
rej
(
error
);
});
...
...
@@ -65,12 +66,14 @@ export default async (
req
.
on
(
'
response
'
,
response
=>
{
if
(
response
.
statusCode
!==
200
)
{
logger
.
error
(
`Got
${
response
.
statusCode
}
(
${
url
}
)`
);
writable
.
close
();
rej
(
response
.
statusCode
);
}
});
req
.
on
(
'
error
'
,
error
=>
{
logger
.
error
(
error
);
writable
.
close
();
rej
(
error
);
});
...
...
@@ -81,10 +84,10 @@ export default async (
try
{
driveFile
=
await
create
(
user
,
path
,
name
,
null
,
folderId
,
force
,
link
,
url
,
uri
,
sensitive
);
logger
.
succ
(
`
g
ot:
${
driveFile
.
_id
}
`
);
logger
.
succ
(
`
G
ot:
${
driveFile
.
_id
}
`
);
}
catch
(
e
)
{
error
=
e
;
logger
.
error
(
`
f
ailed:
${
e
}
`
);
logger
.
error
(
`
F
ailed:
${
e
}
`
);
}
// clean-up
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment