Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
337
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
25
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
TransFem.org
Sharkey
Commits
431e24fa
Unverified
Commit
431e24fa
authored
7 years ago
by
syuilo
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request
#915
from syuilo/write-file-use-stream
multer がテンポラリディレクトリにファイルを保存するように変更
parents
c48f3e16
7f2400ae
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+0
-1
0 additions, 1 deletion
.gitignore
src/api/common/add-file-to-drive.ts
+14
-13
14 additions, 13 deletions
src/api/common/add-file-to-drive.ts
src/api/server.ts
+1
-1
1 addition, 1 deletion
src/api/server.ts
with
15 additions
and
15 deletions
.gitignore
+
0
−
1
View file @
431e24fa
...
...
@@ -2,7 +2,6 @@
/.vscode
/node_modules
/built
/uploads
/data
npm-debug.log
*.pem
...
...
This diff is collapsed.
Click to expand it.
src/api/common/add-file-to-drive.ts
+
14
−
13
View file @
431e24fa
...
...
@@ -40,7 +40,7 @@ const addFile = async (
folderId
:
mongodb
.
ObjectID
=
null
,
force
:
boolean
=
false
)
=>
{
log
(
`registering
${
name
}
(user:
${
user
.
username
}
)`
);
log
(
`registering
${
name
}
(user:
${
user
.
username
}
, path:
${
path
}
)`
);
// Calculate hash, get content type and get file size
const
[
hash
,
[
mime
,
ext
],
size
]
=
await
Promise
.
all
([
...
...
@@ -210,18 +210,19 @@ export default (user: any, file: string | stream.Readable, ...args) => new Promi
.
catch
(
rej
);
}
rej
(
new
Error
(
'
un-compatible file.
'
));
}).
then
(([
path
,
remove
]):
Promise
<
any
>
=>
new
Promise
((
res
,
rej
)
=>
{
addFile
(
user
,
path
,
...
args
)
.
then
(
file
=>
{
res
(
file
);
if
(
remove
)
{
fs
.
unlink
(
path
,
(
e
)
=>
{
if
(
e
)
log
(
e
.
stack
);
});
}
})
.
catch
(
rej
);
}))
})
.
then
(([
path
,
remove
]):
Promise
<
any
>
=>
new
Promise
((
res
,
rej
)
=>
{
addFile
(
user
,
path
,
...
args
)
.
then
(
file
=>
{
res
(
file
);
if
(
remove
)
{
fs
.
unlink
(
path
,
(
e
)
=>
{
if
(
e
)
log
(
e
.
stack
);
});
}
})
.
catch
(
rej
);
}))
.
then
(
file
=>
{
log
(
`drive file has been created
${
file
.
_id
}
`
);
resolve
(
file
);
...
...
This diff is collapsed.
Click to expand it.
src/api/server.ts
+
1
−
1
View file @
431e24fa
...
...
@@ -40,7 +40,7 @@ app.get('/', (req, res) => {
endpoints
.
forEach
(
endpoint
=>
endpoint
.
withFile
?
app
.
post
(
`/
${
endpoint
.
name
}
`
,
endpoint
.
withFile
?
multer
({
dest
:
'
uploads/
'
}).
single
(
'
file
'
)
:
null
,
endpoint
.
withFile
?
multer
({
storage
:
multer
.
diskStorage
({})
}).
single
(
'
file
'
)
:
null
,
require
(
'
./api-handler
'
).
default
.
bind
(
null
,
endpoint
))
:
app
.
post
(
`/
${
endpoint
.
name
}
`
,
require
(
'
./api-handler
'
).
default
.
bind
(
null
,
endpoint
))
...
...
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