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
342345cc
Commit
342345cc
authored
7 years ago
by
otofune
Browse files
Options
Downloads
Patches
Plain Diff
create - バッファを使用しないように
parent
47f98fba
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/api/endpoints/drive/files/create.ts
+7
-15
7 additions, 15 deletions
src/api/endpoints/drive/files/create.ts
with
7 additions
and
15 deletions
src/api/endpoints/drive/files/create.ts
+
7
−
15
View file @
342345cc
/**
* Module dependencies
*/
import
*
as
fs
from
'
fs
'
;
import
$
from
'
cafy
'
;
import
{
validateFileName
}
from
'
../../../models/drive-file
'
;
import
serialize
from
'
../../../serializers/drive-file
'
;
...
...
@@ -15,15 +14,11 @@ import create from '../../../common/add-file-to-drive';
* @param {any} user
* @return {Promise<any>}
*/
module
.
exports
=
(
file
,
params
,
user
)
=>
new
Promise
(
async
(
res
,
rej
)
=>
{
module
.
exports
=
async
(
file
,
params
,
user
)
:
Promise
<
any
>
=>
{
if
(
file
==
null
)
{
return
rej
(
'
file is required
'
)
;
throw
'
file is required
'
;
}
// TODO: 非同期にしたい。Promise対応してないんだろうか...
const
buffer
=
fs
.
readFileSync
(
file
.
path
);
fs
.
unlink
(
file
.
path
,
(
err
)
=>
{
if
(
err
)
console
.
log
(
err
);
});
// Get 'name' parameter
let
name
=
file
.
originalname
;
if
(
name
!==
undefined
&&
name
!==
null
)
{
...
...
@@ -33,7 +28,7 @@ module.exports = (file, params, user) => new Promise(async (res, rej) => {
}
else
if
(
name
===
'
blob
'
)
{
name
=
null
;
}
else
if
(
!
validateFileName
(
name
))
{
return
rej
(
'
invalid name
'
)
;
throw
'
invalid name
'
;
}
}
else
{
name
=
null
;
...
...
@@ -41,14 +36,11 @@ module.exports = (file, params, user) => new Promise(async (res, rej) => {
// Get 'folder_id' parameter
const
[
folderId
=
null
,
folderIdErr
]
=
$
(
params
.
folder_id
).
optional
.
nullable
.
id
().
$
;
if
(
folderIdErr
)
return
rej
(
'
invalid folder_id param
'
)
;
if
(
folderIdErr
)
throw
'
invalid folder_id param
'
;
// Create file
const
driveFile
=
await
create
(
user
,
buffer
,
name
,
null
,
folderId
);
const
driveFile
=
await
create
(
user
,
file
.
path
,
name
,
null
,
folderId
);
// Serialize
const
fileObj
=
await
serialize
(
driveFile
);
// Response
res
(
fileObj
);
});
return
serialize
(
driveFile
);
};
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